RK3368 GPU: Rogue N Init.
[firefly-linux-kernel-4.4.55.git] / drivers / staging / imgtec / rogue / osfunc_x86.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          x86 specific OS functions
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    OS functions who's implementation are processor specific
6 @License        Dual MIT/GPLv2
7
8 The contents of this file are subject to the MIT license as set out below.
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 ("GPL") in which case the provisions
22 of GPL are applicable instead of those above.
23
24 If you wish to allow use of your version of this file only under the terms of
25 GPL, and not to allow others to use your version of this file under the terms
26 of the MIT license, indicate your decision by deleting the provisions above
27 and replace them with the notice and other provisions required by GPL as set
28 out in the file called "GPL-COPYING" included in this distribution. If you do
29 not delete the provisions above, a recipient may use your version of this file
30 under the terms of either the MIT license or GPL.
31
32 This License is also included in this distribution in the file called
33 "MIT-COPYING".
34
35 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
36 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
37 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
39 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
40 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
41 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */ /**************************************************************************/
43
44 #include <linux/smp.h>
45
46 #include "pvrsrv_error.h"
47 #include "img_types.h"
48 #include "img_defs.h"
49 #include "osfunc.h"
50 #include "pvr_debug.h"
51
52
53 static void per_cpu_cache_flush(void *arg)
54 {
55     PVR_UNREFERENCED_PARAMETER(arg);
56     wbinvd();
57 }
58
59 PVRSRV_ERROR OSCPUOperation(PVRSRV_CACHE_OP uiCacheOp)
60 {
61         PVRSRV_ERROR eError = PVRSRV_OK;
62
63         switch(uiCacheOp)
64         {
65                 /* Fall-through */
66                 case PVRSRV_CACHE_OP_CLEAN:
67                 case PVRSRV_CACHE_OP_FLUSH:
68                 case PVRSRV_CACHE_OP_INVALIDATE:
69                         on_each_cpu(per_cpu_cache_flush, NULL, 1);
70                         break;
71
72                 case PVRSRV_CACHE_OP_NONE:
73                         break;
74
75                 default:
76                         PVR_DPF((PVR_DBG_ERROR,
77                                         "%s: Global cache operation type %d is invalid",
78                                         __FUNCTION__, uiCacheOp));
79                         eError = PVRSRV_ERROR_INVALID_PARAMS;
80                         PVR_ASSERT(0);
81                         break;
82         }
83
84         return eError;
85 }
86
87 static void x86_flush_cache_range(const void *pvStart, const void *pvEnd)
88 {
89         IMG_BYTE *pbStart = (IMG_BYTE *)pvStart;
90         IMG_BYTE *pbEnd = (IMG_BYTE *)pvEnd;
91         IMG_BYTE *pbBase;
92
93         pbEnd = (IMG_BYTE *)PVR_ALIGN((uintptr_t)pbEnd,
94                                       (uintptr_t)boot_cpu_data.x86_clflush_size);
95
96         mb();
97         for(pbBase = pbStart; pbBase < pbEnd; pbBase += boot_cpu_data.x86_clflush_size)
98         {
99                 clflush(pbBase);
100         }
101         mb();
102 }
103
104 void OSFlushCPUCacheRangeKM(PVRSRV_DEVICE_NODE *psDevNode,
105                             void *pvVirtStart,
106                             void *pvVirtEnd,
107                             IMG_CPU_PHYADDR sCPUPhysStart,
108                             IMG_CPU_PHYADDR sCPUPhysEnd)
109 {
110         PVR_UNREFERENCED_PARAMETER(psDevNode);
111         PVR_UNREFERENCED_PARAMETER(sCPUPhysStart);
112         PVR_UNREFERENCED_PARAMETER(sCPUPhysEnd);
113
114         x86_flush_cache_range(pvVirtStart, pvVirtEnd);
115 }
116
117
118 void OSCleanCPUCacheRangeKM(PVRSRV_DEVICE_NODE *psDevNode,
119                             void *pvVirtStart,
120                             void *pvVirtEnd,
121                             IMG_CPU_PHYADDR sCPUPhysStart,
122                             IMG_CPU_PHYADDR sCPUPhysEnd)
123 {
124         PVR_UNREFERENCED_PARAMETER(psDevNode);
125         PVR_UNREFERENCED_PARAMETER(sCPUPhysStart);
126         PVR_UNREFERENCED_PARAMETER(sCPUPhysEnd);
127
128         /* No clean feature on x86 */
129         x86_flush_cache_range(pvVirtStart, pvVirtEnd);
130 }
131
132 void OSInvalidateCPUCacheRangeKM(PVRSRV_DEVICE_NODE *psDevNode,
133                                  void *pvVirtStart,
134                                  void *pvVirtEnd,
135                                  IMG_CPU_PHYADDR sCPUPhysStart,
136                                  IMG_CPU_PHYADDR sCPUPhysEnd)
137 {
138         PVR_UNREFERENCED_PARAMETER(psDevNode);
139         PVR_UNREFERENCED_PARAMETER(sCPUPhysStart);
140         PVR_UNREFERENCED_PARAMETER(sCPUPhysEnd);
141
142         /* No invalidate-only support */
143         x86_flush_cache_range(pvVirtStart, pvVirtEnd);
144 }
145
146 PVRSRV_CACHE_OP_ADDR_TYPE OSCPUCacheOpAddressType(PVRSRV_CACHE_OP uiCacheOp)
147 {
148         PVR_UNREFERENCED_PARAMETER(uiCacheOp);
149         return PVRSRV_CACHE_OP_ADDR_TYPE_VIRTUAL;
150 }
151
152 void OSUserModeAccessToPerfCountersEn(void)
153 {
154         /* Not applicable to x86 architecture. */
155 }