RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / interrupt_support.c
1 /*************************************************************************/ /*!
2 @File
3 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 @License        Dual MIT/GPLv2
5
6 The contents of this file are subject to the MIT license as set out below.
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 Alternatively, the contents of this file may be used under the terms of
19 the GNU General Public License Version 2 ("GPL") in which case the provisions
20 of GPL are applicable instead of those above.
21
22 If you wish to allow use of your version of this file only under the terms of
23 GPL, and not to allow others to use your version of this file under the terms
24 of the MIT license, indicate your decision by deleting the provisions above
25 and replace them with the notice and other provisions required by GPL as set
26 out in the file called "GPL-COPYING" included in this distribution. If you do
27 not delete the provisions above, a recipient may use your version of this file
28 under the terms of either the MIT license or GPL.
29
30 This License is also included in this distribution in the file called
31 "MIT-COPYING".
32
33 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
34 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
35 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
37 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 */ /**************************************************************************/
41
42 #include <linux/interrupt.h>
43
44 #include "pvr_debug.h"
45 #include "allocmem.h"
46 #include "interrupt_support.h"
47
48 typedef struct LISR_DATA_TAG
49 {
50         IMG_UINT32      ui32IRQ;
51         PFN_SYS_LISR    pfnLISR;
52         void            *pvData;
53 } LISR_DATA;
54
55 static irqreturn_t SystemISRWrapper(int irq, void *dev_id)
56 {
57         LISR_DATA *psLISRData = (LISR_DATA *)dev_id;
58
59         PVR_UNREFERENCED_PARAMETER(irq);
60
61         if (psLISRData)
62         {
63                 if (psLISRData->pfnLISR(psLISRData->pvData))
64                 {
65                         return IRQ_HANDLED;
66                 }
67         }
68         else
69         {
70                 PVR_DPF((PVR_DBG_ERROR, "%s: Missing interrupt data", __FUNCTION__));
71         }
72
73         return IRQ_NONE;
74 }
75
76 PVRSRV_ERROR OSInstallSystemLISR(IMG_HANDLE *phLISR,
77                                  IMG_UINT32 ui32IRQ,
78                                  const IMG_CHAR *pszDevName,
79                                  PFN_SYS_LISR pfnLISR,
80                                  void *pvData,
81                                  IMG_UINT32 ui32Flags)
82 {
83         LISR_DATA *psLISRData;
84         unsigned long ulIRQFlags = 0;
85
86         if (pfnLISR == NULL || pvData == NULL)
87         {
88                 return PVRSRV_ERROR_INVALID_PARAMS;
89         }
90
91         if (ui32Flags & ~SYS_IRQ_FLAG_MASK)
92         {
93                 return PVRSRV_ERROR_INVALID_PARAMS;
94         }
95
96         switch (ui32Flags & SYS_IRQ_FLAG_TRIGGER_MASK)
97         {
98                 case SYS_IRQ_FLAG_TRIGGER_DEFAULT:
99                         break;
100                 case SYS_IRQ_FLAG_TRIGGER_LOW:
101                         ulIRQFlags |= IRQF_TRIGGER_LOW;
102                         break;
103                 case SYS_IRQ_FLAG_TRIGGER_HIGH:
104                         ulIRQFlags |= IRQF_TRIGGER_HIGH;
105                         break;
106                 default:
107                         return PVRSRV_ERROR_INVALID_PARAMS;
108         }
109
110         if (ui32Flags & SYS_IRQ_FLAG_SHARED)
111         {
112                 ulIRQFlags |= IRQF_SHARED;
113         }
114
115         psLISRData = OSAllocMem(sizeof *psLISRData);
116         if (psLISRData == NULL)
117         {
118                 return PVRSRV_ERROR_OUT_OF_MEMORY;
119         }
120
121         psLISRData->ui32IRQ = ui32IRQ;
122         psLISRData->pfnLISR = pfnLISR;
123         psLISRData->pvData = pvData;
124
125         if (request_irq(ui32IRQ, SystemISRWrapper, ulIRQFlags, pszDevName, psLISRData))
126         {
127                 OSFreeMem(psLISRData);
128
129                 return PVRSRV_ERROR_UNABLE_TO_REGISTER_ISR_HANDLER;
130         }
131
132         *phLISR = (IMG_HANDLE)psLISRData;
133
134         return PVRSRV_OK;
135 }
136
137 PVRSRV_ERROR OSUninstallSystemLISR(IMG_HANDLE hLISR)
138 {
139         LISR_DATA *psLISRData = (LISR_DATA *)hLISR;
140
141         if (psLISRData == NULL)
142         {
143                 return PVRSRV_ERROR_INVALID_PARAMS;
144         }
145
146         free_irq(psLISRData->ui32IRQ, psLISRData);
147
148         OSFreeMem(psLISRData);
149
150         return PVRSRV_OK;
151 }