aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/pvr/mm.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/pvr/mm.h')
-rw-r--r--drivers/gpu/pvr/mm.h333
1 files changed, 333 insertions, 0 deletions
diff --git a/drivers/gpu/pvr/mm.h b/drivers/gpu/pvr/mm.h
new file mode 100644
index 00000000000..047b3ad540c
--- /dev/null
+++ b/drivers/gpu/pvr/mm.h
@@ -0,0 +1,333 @@
1/**********************************************************************
2 *
3 * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful but, except
10 * as otherwise stated in writing, without any warranty; without even the
11 * implied warranty of merchantability or fitness for a particular purpose.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * Imagination Technologies Ltd. <gpl-support@imgtec.com>
23 * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
24 *
25 ******************************************************************************/
26
27#ifndef __IMG_LINUX_MM_H__
28#define __IMG_LINUX_MM_H__
29
30#ifndef AUTOCONF_INCLUDED
31 #include <linux/config.h>
32#endif
33
34#include <linux/version.h>
35#include <linux/slab.h>
36#include <linux/mm.h>
37#include <linux/list.h>
38
39#include <asm/io.h>
40
41#define PHYS_TO_PFN(phys) ((phys) >> PAGE_SHIFT)
42#define PFN_TO_PHYS(pfn) ((pfn) << PAGE_SHIFT)
43
44#define RANGE_TO_PAGES(range) (((range) + (PAGE_SIZE - 1)) >> PAGE_SHIFT)
45
46#define ADDR_TO_PAGE_OFFSET(addr) (((unsigned long)(addr)) & (PAGE_SIZE - 1))
47
48#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10))
49#define REMAP_PFN_RANGE(vma, addr, pfn, size, prot) remap_pfn_range(vma, addr, pfn, size, prot)
50#else
51#define REMAP_PFN_RANGE(vma, addr, pfn, size, prot) remap_page_range(vma, addr, PFN_TO_PHYS(pfn), size, prot)
52#endif
53
54#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
55#define IO_REMAP_PFN_RANGE(vma, addr, pfn, size, prot) io_remap_pfn_range(vma, addr, pfn, size, prot)
56#else
57#define IO_REMAP_PFN_RANGE(vma, addr, pfn, size, prot) io_remap_page_range(vma, addr, PFN_TO_PHYS(pfn), size, prot)
58#endif
59
60#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
61#define VM_INSERT_PAGE(vma, addr, page) vm_insert_page(vma, addr, page)
62#else
63#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10))
64#define VM_INSERT_PAGE(vma, addr, page) remap_pfn_range(vma, addr, page_to_pfn(page), PAGE_SIZE, vma->vm_page_prot);
65#else
66#define VM_INSERT_PAGE(vma, addr, page) remap_page_range(vma, addr, page_to_phys(page), PAGE_SIZE, vma->vm_page_prot);
67#endif
68#endif
69
70static inline IMG_UINT32 VMallocToPhys(IMG_VOID *pCpuVAddr)
71{
72 return (page_to_phys(vmalloc_to_page(pCpuVAddr)) + ADDR_TO_PAGE_OFFSET(pCpuVAddr));
73
74}
75
76typedef enum {
77 LINUX_MEM_AREA_IOREMAP,
78 LINUX_MEM_AREA_EXTERNAL_KV,
79 LINUX_MEM_AREA_IO,
80 LINUX_MEM_AREA_VMALLOC,
81 LINUX_MEM_AREA_ALLOC_PAGES,
82 LINUX_MEM_AREA_SUB_ALLOC,
83 LINUX_MEM_AREA_TYPE_COUNT
84}LINUX_MEM_AREA_TYPE;
85
86typedef struct _LinuxMemArea LinuxMemArea;
87
88
89struct _LinuxMemArea {
90 LINUX_MEM_AREA_TYPE eAreaType;
91 union _uData
92 {
93 struct _sIORemap
94 {
95
96 IMG_CPU_PHYADDR CPUPhysAddr;
97 IMG_VOID *pvIORemapCookie;
98 }sIORemap;
99 struct _sExternalKV
100 {
101
102 IMG_BOOL bPhysContig;
103 union {
104
105 IMG_SYS_PHYADDR SysPhysAddr;
106 IMG_SYS_PHYADDR *pSysPhysAddr;
107 } uPhysAddr;
108 IMG_VOID *pvExternalKV;
109 }sExternalKV;
110 struct _sIO
111 {
112
113 IMG_CPU_PHYADDR CPUPhysAddr;
114 }sIO;
115 struct _sVmalloc
116 {
117
118 IMG_VOID *pvVmallocAddress;
119 }sVmalloc;
120 struct _sPageList
121 {
122
123 struct page **pvPageList;
124 IMG_HANDLE hBlockPageList;
125 }sPageList;
126 struct _sSubAlloc
127 {
128
129 LinuxMemArea *psParentLinuxMemArea;
130 IMG_UINT32 ui32ByteOffset;
131 }sSubAlloc;
132 }uData;
133
134 IMG_UINT32 ui32ByteSize;
135
136 IMG_UINT32 ui32AreaFlags;
137
138 IMG_BOOL bMMapRegistered;
139
140 IMG_BOOL bNeedsCacheInvalidate;
141
142
143 struct list_head sMMapItem;
144
145
146 struct list_head sMMapOffsetStructList;
147};
148
149#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17))
150typedef kmem_cache_t LinuxKMemCache;
151#else
152typedef struct kmem_cache LinuxKMemCache;
153#endif
154
155
156PVRSRV_ERROR LinuxMMInit(IMG_VOID);
157
158
159IMG_VOID LinuxMMCleanup(IMG_VOID);
160
161
162#if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
163#define KMallocWrapper(ui32ByteSize) _KMallocWrapper(ui32ByteSize, __FILE__, __LINE__)
164#else
165#define KMallocWrapper(ui32ByteSize) _KMallocWrapper(ui32ByteSize, NULL, 0)
166#endif
167IMG_VOID *_KMallocWrapper(IMG_UINT32 ui32ByteSize, IMG_CHAR *szFileName, IMG_UINT32 ui32Line);
168
169
170#if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
171#define KFreeWrapper(pvCpuVAddr) _KFreeWrapper(pvCpuVAddr, __FILE__, __LINE__)
172#else
173#define KFreeWrapper(pvCpuVAddr) _KFreeWrapper(pvCpuVAddr, NULL, 0)
174#endif
175IMG_VOID _KFreeWrapper(IMG_VOID *pvCpuVAddr, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line);
176
177
178#if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
179#define VMallocWrapper(ui32Bytes, ui32AllocFlags) _VMallocWrapper(ui32Bytes, ui32AllocFlags, __FILE__, __LINE__)
180#else
181#define VMallocWrapper(ui32Bytes, ui32AllocFlags) _VMallocWrapper(ui32Bytes, ui32AllocFlags, NULL, 0)
182#endif
183IMG_VOID *_VMallocWrapper(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AllocFlags, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line);
184
185
186#if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
187#define VFreeWrapper(pvCpuVAddr) _VFreeWrapper(pvCpuVAddr, __FILE__, __LINE__)
188#else
189#define VFreeWrapper(pvCpuVAddr) _VFreeWrapper(pvCpuVAddr, NULL, 0)
190#endif
191IMG_VOID _VFreeWrapper(IMG_VOID *pvCpuVAddr, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line);
192
193
194LinuxMemArea *NewVMallocLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags);
195
196
197IMG_VOID FreeVMallocLinuxMemArea(LinuxMemArea *psLinuxMemArea);
198
199
200#if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
201#define IORemapWrapper(BasePAddr, ui32Bytes, ui32MappingFlags) \
202 _IORemapWrapper(BasePAddr, ui32Bytes, ui32MappingFlags, __FILE__, __LINE__)
203#else
204#define IORemapWrapper(BasePAddr, ui32Bytes, ui32MappingFlags) \
205 _IORemapWrapper(BasePAddr, ui32Bytes, ui32MappingFlags, NULL, 0)
206#endif
207IMG_VOID *_IORemapWrapper(IMG_CPU_PHYADDR BasePAddr,
208 IMG_UINT32 ui32Bytes,
209 IMG_UINT32 ui32MappingFlags,
210 IMG_CHAR *pszFileName,
211 IMG_UINT32 ui32Line);
212
213
214LinuxMemArea *NewIORemapLinuxMemArea(IMG_CPU_PHYADDR BasePAddr, IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags);
215
216
217IMG_VOID FreeIORemapLinuxMemArea(LinuxMemArea *psLinuxMemArea);
218
219LinuxMemArea *NewExternalKVLinuxMemArea(IMG_SYS_PHYADDR *pBasePAddr, IMG_VOID *pvCPUVAddr, IMG_UINT32 ui32Bytes, IMG_BOOL bPhysContig, IMG_UINT32 ui32AreaFlags);
220
221
222IMG_VOID FreeExternalKVLinuxMemArea(LinuxMemArea *psLinuxMemArea);
223
224
225#if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
226#define IOUnmapWrapper(pvIORemapCookie) \
227 _IOUnmapWrapper(pvIORemapCookie, __FILE__, __LINE__)
228#else
229#define IOUnmapWrapper(pvIORemapCookie) \
230 _IOUnmapWrapper(pvIORemapCookie, NULL, 0)
231#endif
232IMG_VOID _IOUnmapWrapper(IMG_VOID *pvIORemapCookie, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line);
233
234
235struct page *LinuxMemAreaOffsetToPage(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32ByteOffset);
236
237
238LinuxKMemCache *KMemCacheCreateWrapper(IMG_CHAR *pszName, size_t Size, size_t Align, IMG_UINT32 ui32Flags);
239
240
241IMG_VOID KMemCacheDestroyWrapper(LinuxKMemCache *psCache);
242
243
244#if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
245#define KMemCacheAllocWrapper(psCache, Flags) _KMemCacheAllocWrapper(psCache, Flags, __FILE__, __LINE__)
246#else
247#define KMemCacheAllocWrapper(psCache, Flags) _KMemCacheAllocWrapper(psCache, Flags, NULL, 0)
248#endif
249
250#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14))
251IMG_VOID *_KMemCacheAllocWrapper(LinuxKMemCache *psCache, gfp_t Flags, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line);
252#else
253IMG_VOID *_KMemCacheAllocWrapper(LinuxKMemCache *psCache, int Flags, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line);
254#endif
255
256#if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS)
257#define KMemCacheFreeWrapper(psCache, pvObject) _KMemCacheFreeWrapper(psCache, pvObject, __FILE__, __LINE__)
258#else
259#define KMemCacheFreeWrapper(psCache, pvObject) _KMemCacheFreeWrapper(psCache, pvObject, NULL, 0)
260#endif
261IMG_VOID _KMemCacheFreeWrapper(LinuxKMemCache *psCache, IMG_VOID *pvObject, IMG_CHAR *pszFileName, IMG_UINT32 ui32Line);
262
263
264const IMG_CHAR *KMemCacheNameWrapper(LinuxKMemCache *psCache);
265
266
267LinuxMemArea *NewIOLinuxMemArea(IMG_CPU_PHYADDR BasePAddr, IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags);
268
269
270IMG_VOID FreeIOLinuxMemArea(LinuxMemArea *psLinuxMemArea);
271
272
273LinuxMemArea *NewAllocPagesLinuxMemArea(IMG_UINT32 ui32Bytes, IMG_UINT32 ui32AreaFlags);
274
275
276IMG_VOID FreeAllocPagesLinuxMemArea(LinuxMemArea *psLinuxMemArea);
277
278
279LinuxMemArea *NewSubLinuxMemArea(LinuxMemArea *psParentLinuxMemArea,
280 IMG_UINT32 ui32ByteOffset,
281 IMG_UINT32 ui32Bytes);
282
283
284IMG_VOID LinuxMemAreaDeepFree(LinuxMemArea *psLinuxMemArea);
285
286
287#if defined(LINUX_MEM_AREAS_DEBUG)
288IMG_VOID LinuxMemAreaRegister(LinuxMemArea *psLinuxMemArea);
289#else
290#define LinuxMemAreaRegister(X)
291#endif
292
293
294IMG_VOID *LinuxMemAreaToCpuVAddr(LinuxMemArea *psLinuxMemArea);
295
296
297IMG_CPU_PHYADDR LinuxMemAreaToCpuPAddr(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32ByteOffset);
298
299
300#define LinuxMemAreaToCpuPFN(psLinuxMemArea, ui32ByteOffset) PHYS_TO_PFN(LinuxMemAreaToCpuPAddr(psLinuxMemArea, ui32ByteOffset).uiAddr)
301
302IMG_BOOL LinuxMemAreaPhysIsContig(LinuxMemArea *psLinuxMemArea);
303
304static inline LinuxMemArea *
305LinuxMemAreaRoot(LinuxMemArea *psLinuxMemArea)
306{
307 if(psLinuxMemArea->eAreaType == LINUX_MEM_AREA_SUB_ALLOC)
308 {
309 return psLinuxMemArea->uData.sSubAlloc.psParentLinuxMemArea;
310 }
311 else
312 {
313 return psLinuxMemArea;
314 }
315}
316
317
318static inline LINUX_MEM_AREA_TYPE
319LinuxMemAreaRootType(LinuxMemArea *psLinuxMemArea)
320{
321 return LinuxMemAreaRoot(psLinuxMemArea)->eAreaType;
322}
323
324
325const IMG_CHAR *LinuxMemAreaTypeToString(LINUX_MEM_AREA_TYPE eMemAreaType);
326
327
328#if defined(DEBUG) || defined(DEBUG_LINUX_MEM_AREAS)
329const IMG_CHAR *HAPFlagsToString(IMG_UINT32 ui32Flags);
330#endif
331
332#endif
333