1 /*************************************************************************/ /*!
3 @Title arm 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
8 The contents of this file are subject to the MIT license as set out below.
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:
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
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.
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.
32 This License is also included in this distribution in the file called
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/platform_device.h>
44 #include <linux/version.h>
45 #include <linux/cpumask.h>
46 #include <linux/dma-mapping.h>
47 #include <asm/cacheflush.h>
49 #include "pvrsrv_error.h"
50 #include "img_types.h"
52 #include "pvr_debug.h"
54 #if defined(CONFIG_OUTER_CACHE)
55 /* If you encounter a 64-bit ARM system with an outer cache, you'll need
56 * to add the necessary code to manage that cache. See osfunc_arm.c
57 * for an example of how to do so.
59 #error "CONFIG_OUTER_CACHE not supported on arm64."
62 static void per_cpu_cache_flush(void *arg)
64 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0))
65 static IMG_BOOL bLog = IMG_TRUE;
67 NOTE: Regarding arm64 global flush support on >= Linux v4.2:
68 - Global cache flush support is deprecated from v4.2 onwards
69 - Cache maintenance is done using UM/KM VA maintenance _only_
70 - If you find that more time is spent in VA cache maintenance
71 - Implement arm64 assembly sequence for global flush here
73 - If you do not want to implement the global cache assembly
74 - Disable KM cache maintenance support in UM cache.c
75 - Remove this PVR_LOG message
79 PVR_LOG(("Global d-cache flush assembly not implemented, using rangebased flush"));
85 PVR_UNREFERENCED_PARAMETER(arg);
88 PVRSRV_ERROR OSCPUOperation(PVRSRV_CACHE_OP uiCacheOp)
90 PVRSRV_ERROR eError = PVRSRV_OK;
94 case PVRSRV_CACHE_OP_CLEAN:
95 case PVRSRV_CACHE_OP_FLUSH:
96 case PVRSRV_CACHE_OP_INVALIDATE:
97 on_each_cpu(per_cpu_cache_flush, NULL, 1);
98 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0))
99 eError = PVRSRV_ERROR_NOT_IMPLEMENTED;
103 case PVRSRV_CACHE_OP_NONE:
107 PVR_DPF((PVR_DBG_ERROR,
108 "%s: Global cache operation type %d is invalid",
109 __FUNCTION__, uiCacheOp));
110 eError = PVRSRV_ERROR_INVALID_PARAMS;
118 void OSFlushCPUCacheRangeKM(PVRSRV_DEVICE_NODE *psDevNode,
121 IMG_CPU_PHYADDR sCPUPhysStart,
122 IMG_CPU_PHYADDR sCPUPhysEnd)
124 struct dma_map_ops *dma_ops = get_dma_ops(psDevNode->psDevConfig->pvOSDevice);
126 PVR_UNREFERENCED_PARAMETER(pvVirtStart);
127 PVR_UNREFERENCED_PARAMETER(pvVirtEnd);
129 dma_ops->sync_single_for_device(NULL, sCPUPhysStart.uiAddr, sCPUPhysEnd.uiAddr - sCPUPhysStart.uiAddr, DMA_TO_DEVICE);
130 dma_ops->sync_single_for_cpu(NULL, sCPUPhysStart.uiAddr, sCPUPhysEnd.uiAddr - sCPUPhysStart.uiAddr, DMA_FROM_DEVICE);
133 void OSCleanCPUCacheRangeKM(PVRSRV_DEVICE_NODE *psDevNode,
136 IMG_CPU_PHYADDR sCPUPhysStart,
137 IMG_CPU_PHYADDR sCPUPhysEnd)
139 struct dma_map_ops *dma_ops = get_dma_ops(psDevNode->psDevConfig->pvOSDevice);
141 PVR_UNREFERENCED_PARAMETER(pvVirtStart);
142 PVR_UNREFERENCED_PARAMETER(pvVirtEnd);
144 dma_ops->sync_single_for_device(NULL, sCPUPhysStart.uiAddr, sCPUPhysEnd.uiAddr - sCPUPhysStart.uiAddr, DMA_TO_DEVICE);
147 void OSInvalidateCPUCacheRangeKM(PVRSRV_DEVICE_NODE *psDevNode,
150 IMG_CPU_PHYADDR sCPUPhysStart,
151 IMG_CPU_PHYADDR sCPUPhysEnd)
153 struct dma_map_ops *dma_ops = get_dma_ops(psDevNode->psDevConfig->pvOSDevice);
155 PVR_UNREFERENCED_PARAMETER(pvVirtStart);
156 PVR_UNREFERENCED_PARAMETER(pvVirtEnd);
158 dma_ops->sync_single_for_cpu(NULL, sCPUPhysStart.uiAddr, sCPUPhysEnd.uiAddr - sCPUPhysStart.uiAddr, DMA_FROM_DEVICE);
161 PVRSRV_CACHE_OP_ADDR_TYPE OSCPUCacheOpAddressType(PVRSRV_CACHE_OP uiCacheOp)
163 PVR_UNREFERENCED_PARAMETER(uiCacheOp);
164 return PVRSRV_CACHE_OP_ADDR_TYPE_PHYSICAL;
167 void OSUserModeAccessToPerfCountersEn(void)
169 /* FIXME: implement similarly to __arm__ */