drm/GPU: Add support Imagination PowerVR GPU driver v1.17
[platform/kernel/linux-starfive.git] / drivers / gpu / drm / img / img-rogue / services / server / env / linux / osfunc_arm.c
1 /*************************************************************************/ /*!
2 @File
3 @Title          arm specific OS functions
4 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description    Processor specific OS functions
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 #include <linux/version.h>
44 #include <linux/dma-mapping.h>
45 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,15,0))
46  #include <asm/system.h>
47 #endif
48 #include <asm/cacheflush.h>
49
50 #include "pvrsrv_error.h"
51 #include "img_types.h"
52 #include "img_defs.h"
53 #include "osfunc.h"
54 #include "pvr_debug.h"
55
56
57 static inline size_t pvr_dmac_range_len(const void *pvStart, const void *pvEnd)
58 {
59         return (size_t)((char *)pvEnd - (char *)pvStart);
60 }
61
62 void OSCPUCacheFlushRangeKM(PVRSRV_DEVICE_NODE *psDevNode,
63                             void *pvVirtStart,
64                             void *pvVirtEnd,
65                             IMG_CPU_PHYADDR sCPUPhysStart,
66                             IMG_CPU_PHYADDR sCPUPhysEnd)
67 {
68         PVR_UNREFERENCED_PARAMETER(psDevNode);
69
70 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0))
71         arm_dma_ops.sync_single_for_device(psDevNode->psDevConfig->pvOSDevice, sCPUPhysStart.uiAddr, sCPUPhysEnd.uiAddr - sCPUPhysStart.uiAddr, DMA_TO_DEVICE);
72         arm_dma_ops.sync_single_for_cpu(psDevNode->psDevConfig->pvOSDevice, sCPUPhysStart.uiAddr, sCPUPhysEnd.uiAddr - sCPUPhysStart.uiAddr, DMA_FROM_DEVICE);
73 #else   /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)) */
74         /* Inner cache */
75         dmac_flush_range(pvVirtStart, pvVirtEnd);
76
77         /* Outer cache */
78         outer_flush_range(sCPUPhysStart.uiAddr, sCPUPhysEnd.uiAddr);
79 #endif  /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)) */
80 }
81
82 void OSCPUCacheCleanRangeKM(PVRSRV_DEVICE_NODE *psDevNode,
83                             void *pvVirtStart,
84                             void *pvVirtEnd,
85                             IMG_CPU_PHYADDR sCPUPhysStart,
86                             IMG_CPU_PHYADDR sCPUPhysEnd)
87 {
88         PVR_UNREFERENCED_PARAMETER(psDevNode);
89
90 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0))
91         arm_dma_ops.sync_single_for_device(psDevNode->psDevConfig->pvOSDevice, sCPUPhysStart.uiAddr, sCPUPhysEnd.uiAddr - sCPUPhysStart.uiAddr, DMA_TO_DEVICE);
92 #else   /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)) */
93         /* Inner cache */
94         dmac_map_area(pvVirtStart, pvr_dmac_range_len(pvVirtStart, pvVirtEnd), DMA_TO_DEVICE);
95
96         /* Outer cache */
97         outer_clean_range(sCPUPhysStart.uiAddr, sCPUPhysEnd.uiAddr);
98 #endif  /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)) */
99 }
100
101 void OSCPUCacheInvalidateRangeKM(PVRSRV_DEVICE_NODE *psDevNode,
102                                  void *pvVirtStart,
103                                  void *pvVirtEnd,
104                                  IMG_CPU_PHYADDR sCPUPhysStart,
105                                  IMG_CPU_PHYADDR sCPUPhysEnd)
106 {
107         PVR_UNREFERENCED_PARAMETER(psDevNode);
108
109 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0))
110         arm_dma_ops.sync_single_for_cpu(psDevNode->psDevConfig->pvOSDevice, sCPUPhysStart.uiAddr, sCPUPhysEnd.uiAddr - sCPUPhysStart.uiAddr, DMA_FROM_DEVICE);
111 #else   /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)) */
112         /* Inner cache */
113         dmac_map_area(pvVirtStart, pvr_dmac_range_len(pvVirtStart, pvVirtEnd), DMA_FROM_DEVICE);
114
115         /* Outer cache */
116         outer_inv_range(sCPUPhysStart.uiAddr, sCPUPhysEnd.uiAddr);
117 #endif  /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)) */
118 }
119
120 OS_CACHE_OP_ADDR_TYPE OSCPUCacheOpAddressType(void)
121 {
122 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0))
123         return OS_CACHE_OP_ADDR_TYPE_PHYSICAL;
124 #else
125         return OS_CACHE_OP_ADDR_TYPE_BOTH;
126 #endif
127 }
128
129 /* User Enable Register */
130 #define PMUSERENR_EN      0x00000001 /* enable user access to the counters */
131
132 static void per_cpu_perf_counter_user_access_en(void *data)
133 {
134         PVR_UNREFERENCED_PARAMETER(data);
135         /* Enable user-mode access to counters. */
136         asm volatile("mcr p15, 0, %0, c9, c14, 0" :: "r"(PMUSERENR_EN));
137 }
138
139 void OSUserModeAccessToPerfCountersEn(void)
140 {
141         on_each_cpu(per_cpu_perf_counter_user_access_en, NULL, 1);
142 }
143
144 IMG_BOOL OSIsWriteCombineUnalignedSafe(void)
145 {
146         /*
147          * The kernel looks to have always used normal memory under ARM32.
148          * See osfunc_arm64.c implementation for more details.
149          */
150         return IMG_TRUE;
151 }