gpu: pvr: pdump: review use of PDumpSuspended
[sgx.git] / pvr / buffer_manager.h
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 _BUFFER_MANAGER_H_
28 #define _BUFFER_MANAGER_H_
29
30 #include "img_types.h"
31 #include "ra.h"
32 #include "perproc.h"
33
34
35 struct BM_HEAP;
36
37 struct BM_MAPPING {
38         enum {
39                 hm_wrapped = 1,
40                 hm_wrapped_scatter,
41                 hm_wrapped_virtaddr,
42                 hm_wrapped_scatter_virtaddr,
43                 hm_env,
44                 hm_contiguous
45         } eCpuMemoryOrigin;
46
47         struct BM_HEAP *pBMHeap;
48         struct RA_ARENA *pArena;
49
50         void *CpuVAddr;
51         struct IMG_CPU_PHYADDR CpuPAddr;
52         struct IMG_DEV_VIRTADDR DevVAddr;
53         struct IMG_SYS_PHYADDR *psSysAddr;
54         size_t uSize;
55         void *hOSMemHandle;
56         u32 ui32Flags;
57 };
58
59 struct BM_BUF {
60         void **CpuVAddr;
61         void *hOSMemHandle;
62         struct IMG_CPU_PHYADDR CpuPAddr;
63         struct IMG_DEV_VIRTADDR DevVAddr;
64
65         struct BM_MAPPING *pMapping;
66         u32 ui32RefCount;
67 };
68
69 struct BM_HEAP {
70         u32 ui32Attribs;
71         struct BM_CONTEXT *pBMContext;
72         struct RA_ARENA *pImportArena;
73         struct RA_ARENA *pLocalDevMemArena;
74         struct RA_ARENA *pVMArena;
75         struct DEV_ARENA_DESCRIPTOR sDevArena;
76         struct MMU_HEAP *pMMUHeap;
77
78         struct BM_HEAP *psNext;
79 };
80
81 struct BM_CONTEXT {
82         struct MMU_CONTEXT *psMMUContext;
83         struct BM_HEAP *psBMHeap;
84         struct BM_HEAP *psBMSharedHeap;
85         struct PVRSRV_DEVICE_NODE *psDeviceNode;
86         struct HASH_TABLE *pBufferHash;
87         void *hResItem;
88         u32 ui32RefCount;
89         struct BM_CONTEXT *psNext;
90 };
91
92 #define BP_POOL_MASK     0x7
93
94 #define BP_CONTIGUOUS                   (1 << 3)
95 #define BP_PARAMBUFFER                  (1 << 4)
96
97 #define BM_MAX_DEVMEM_ARENAS  2
98
99 void *BM_CreateContext(struct PVRSRV_DEVICE_NODE *psDeviceNode,
100                 struct IMG_DEV_PHYADDR *psPDDevPAddr,
101                 struct PVRSRV_PER_PROCESS_DATA *psPerProc,
102                 IMG_BOOL *pbCreated);
103
104 void BM_DestroyContext(void *hBMContext);
105
106 static inline void pvr_get_ctx(struct BM_CONTEXT *ctx)
107 {
108         WARN_ON(!ctx->ui32RefCount);
109         ctx->ui32RefCount++;
110 }
111
112 static inline bool pvr_put_ctx(struct BM_CONTEXT *ctx)
113 {
114         BUG_ON(!ctx->ui32RefCount);
115         ctx->ui32RefCount--;
116         if (!ctx->ui32RefCount) {
117                 BM_DestroyContext(ctx);
118
119                 return true;
120         }
121
122         return false;
123 }
124
125 void *BM_CreateHeap(void *hBMContext,
126                     struct DEVICE_MEMORY_HEAP_INFO *psDevMemHeapInfo);
127 void BM_DestroyHeap(void *hDevMemHeap);
128 IMG_BOOL BM_Reinitialise(struct PVRSRV_DEVICE_NODE *psDeviceNode);
129
130 IMG_BOOL BM_Alloc(void *hDevMemHeap,
131          struct IMG_DEV_VIRTADDR *psDevVAddr,
132          size_t uSize, u32 *pui32Flags, u32 uDevVAddrAlignment, void **phBuf);
133
134 IMG_BOOL BM_Wrap(void *hDevMemHeap,
135         u32 ui32Size,
136         u32 ui32Offset,
137         IMG_BOOL bPhysContig,
138         struct IMG_SYS_PHYADDR *psSysAddr,
139         void *pvCPUVAddr, u32 *pui32Flags, void **phBuf);
140
141 void BM_Free(void *hBuf, u32 ui32Flags);
142 void *BM_HandleToCpuVaddr(void *hBuf);
143 struct IMG_DEV_VIRTADDR BM_HandleToDevVaddr(void *hBuf);
144
145 struct IMG_SYS_PHYADDR BM_HandleToSysPaddr(void *hBuf);
146
147 void *BM_HandleToOSMemHandle(void *hBuf);
148
149 IMG_BOOL BM_ContiguousStatistics(u32 uFlags, u32 *pTotalBytes,
150                 u32 *pAvailableBytes);
151
152 enum PVRSRV_ERROR BM_GetPhysPageAddr(struct PVRSRV_KERNEL_MEM_INFO *psMemInfo,
153                 struct IMG_DEV_VIRTADDR sDevVPageAddr,
154                 struct IMG_DEV_PHYADDR *psDevPAddr);
155
156 enum PVRSRV_ERROR BM_GetHeapInfo(void *hDevMemHeap,
157                             struct PVRSRV_HEAP_INFO *psHeapInfo);
158
159 struct MMU_CONTEXT *BM_GetMMUContext(void *hDevMemHeap);
160
161 struct MMU_CONTEXT *BM_GetMMUContextFromMemContext(void *hDevMemContext);
162
163 void *BM_GetMMUHeap(void *hDevMemHeap);
164
165 struct PVRSRV_DEVICE_NODE *BM_GetDeviceNode(void *hDevMemContext);
166
167 void *BM_GetMappingHandle(struct PVRSRV_KERNEL_MEM_INFO *psMemInfo);
168
169 struct BM_CONTEXT *bm_find_context(struct BM_CONTEXT *head_context,
170                                     u32 page_dir);
171 #endif