]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/device-ti-proprietary-open.git/blob - jacinto6/sgx_src/eurasia_km/services4/srvkm/include/ra.h
proprietary-open: jacinto6: add graphics kernel module sources
[android-sdk/device-ti-proprietary-open.git] / jacinto6 / sgx_src / eurasia_km / services4 / srvkm / include / ra.h
1 /*************************************************************************/ /*!
2 @Title          Resource Allocator API
3 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 @License        Dual MIT/GPLv2
6 The contents of this file are subject to the MIT license as set out below.
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 Alternatively, the contents of this file may be used under the terms of
19 the GNU General Public License Version 2 ("GPL") in which case the provisions
20 of GPL are applicable instead of those above.
22 If you wish to allow use of your version of this file only under the terms of
23 GPL, and not to allow others to use your version of this file under the terms
24 of the MIT license, indicate your decision by deleting the provisions above
25 and replace them with the notice and other provisions required by GPL as set
26 out in the file called "GPL-COPYING" included in this distribution. If you do
27 not delete the provisions above, a recipient may use your version of this file
28 under the terms of either the MIT license or GPL.
30 This License is also included in this distribution in the file called
31 "MIT-COPYING".
33 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
34 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
35 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
37 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 */ /**************************************************************************/
42 #ifndef _RA_H_
43 #define _RA_H_
45 #include "img_types.h"
46 #include "hash.h"
47 #include "osfunc.h"
49 /** Resource arena.
50  *  struct _RA_ARENA_ deliberately opaque
51  */
52 typedef struct _RA_ARENA_ RA_ARENA;                     //PRQA S 3313
53 typedef struct _BM_MAPPING_ BM_MAPPING;
57 /** Enable support for arena statistics. */
58 #define RA_STATS 
61 /** Resource arena statistics. */
62 struct _RA_STATISTICS_
63 {
64     /** total number of segments add to the arena */
65     IMG_SIZE_T uSpanCount;
67     /** number of current live segments within the arena */
68     IMG_SIZE_T uLiveSegmentCount;
70     /** number of current free segments within the arena */
71     IMG_SIZE_T uFreeSegmentCount;
73     /** total number of resource within the arena */
74     IMG_SIZE_T uTotalResourceCount;
75     
76     /** number of free resource within the arena */
77     IMG_SIZE_T uFreeResourceCount;
79     /** total number of resources allocated from the arena */
80     IMG_SIZE_T uCumulativeAllocs;
82     /** total number of resources returned to the arena */
83     IMG_SIZE_T uCumulativeFrees;
85     /** total number of spans allocated by the callback mechanism */
86     IMG_SIZE_T uImportCount;
88     /** total number of spans deallocated by the callback mechanism */
89     IMG_SIZE_T uExportCount;
91     IMG_SIZE_T uFailedAllocCount;
93 };
94 typedef struct _RA_STATISTICS_ RA_STATISTICS;
96 struct _RA_SEGMENT_DETAILS_
97 {
98         IMG_SIZE_T      uiSize;
99         IMG_CPU_PHYADDR sCpuPhyAddr;
100         IMG_HANDLE      hSegment;
101 };
102 typedef struct _RA_SEGMENT_DETAILS_ RA_SEGMENT_DETAILS;
104 /**
105  *  @Function   RA_Create
106  *
107  *  @Description
108  *
109  *  To create a resource arena.
110  *
111  *  @Input name - the name of the arena for diagnostic purposes.
112  *  @Input base - the base of an initial resource span or 0.
113  *  @Input uSize - the size of an initial resource span or 0.
114  *  @Input pRef - the reference to return for the initial resource or 0.
115  *  @Input uQuantum - the arena allocation quantum.
116  *  @Input alloc - a resource allocation callback or 0.
117  *  @Input free - a resource de-allocation callback or 0.
118  *  @Input import_handle - handle passed to alloc and free or 0.
119  *  @Return arena handle, or IMG_NULL.
120  */
121 RA_ARENA *
122 RA_Create (IMG_CHAR *name,
123            IMG_UINTPTR_T base,
124            IMG_SIZE_T uSize,
125            BM_MAPPING *psMapping,
126            IMG_SIZE_T uQuantum, 
127            IMG_BOOL (*imp_alloc)(IMG_VOID *_h,
128                                 IMG_SIZE_T uSize,
129                                 IMG_SIZE_T *pActualSize,
130                                 BM_MAPPING **ppsMapping,
131                                 IMG_UINT32 uFlags,
132                                                                 IMG_PVOID pvPrivData,
133                                                                 IMG_UINT32 ui32PrivDataLength,
134                                 IMG_UINTPTR_T *pBase),
135            IMG_VOID (*imp_free) (IMG_VOID *,
136                                 IMG_UINTPTR_T,
137                                 BM_MAPPING *),
138            IMG_VOID (*backingstore_free) (IMG_VOID *,
139                                           IMG_SIZE_T,
140                                           IMG_SIZE_T,
141                                           IMG_HANDLE),
142            IMG_VOID *import_handle);
144 /**
145  *  @Function   RA_Delete
146  *
147  *  @Description
148  *
149  *  To delete a resource arena. All resources allocated from the arena
150  *  must be freed before deleting the arena.
151  *                  
152  *  @Input  pArena - the arena to delete.
153  *  @Return None
154  */
155 IMG_VOID
156 RA_Delete (RA_ARENA *pArena);
158 /**
159  *  @Function   RA_TestDelete
160  *
161  *  @Description
162  *
163  *  To test whether it is safe to delete a resource arena. If any allocations
164  *      have not been freed, the RA must not be deleted.
165  *                  
166  *  @Input  pArena - the arena to test.
167  *  @Return IMG_BOOL - IMG_TRUE if is safe to go on and call RA_Delete.
168  */
169 IMG_BOOL
170 RA_TestDelete (RA_ARENA *pArena);
172 /**
173  *  @Function   RA_Add
174  *
175  *  @Description
176  *
177  *  To add a resource span to an arena. The span must not overlap with
178  *  any span previously added to the arena.
179  *
180  *  @Input pArena - the arena to add a span into.
181  *  @Input base - the base of the span.
182  *  @Input uSize - the extent of the span.
183  *  @Return IMG_TRUE - success, IMG_FALSE - failure
184  */
185 IMG_BOOL
186 RA_Add (RA_ARENA *pArena, IMG_UINTPTR_T base, IMG_SIZE_T uSize);
188 /**
189  *  @Function   RA_Alloc
190  *
191  *  @Description
192  *
193  *  To allocate resource from an arena.
194  *
195  *  @Input  pArena - the arena
196  *  @Input  uRequestSize - the size of resource segment requested.
197  *  @Output pActualSize - the actual_size of resource segment allocated,
198  *          typcially rounded up by quantum.
199  *  @Output ppsMapping - the user reference associated with allocated
200  *          resource span.
201  *  @Input  uFlags - flags influencing allocation policy.
202  *  @Input  uAlignment - the alignment constraint required for the
203  *          allocated segment, use 0 if alignment not required.
204  *      @Input  uAlignmentOffset - the required alignment offset
205  *  @Input  pvPrivData - private data passed to OS allocator
206  *  @Input  ui32PrivData - length of private data
207  *
208  *  @Output pBase - allocated base resource
209  *  @Return IMG_TRUE - success, IMG_FALSE - failure
210  */
211 IMG_BOOL
212 RA_Alloc (RA_ARENA *pArena, 
213           IMG_SIZE_T uSize,
214           IMG_SIZE_T *pActualSize,
215           BM_MAPPING **ppsMapping, 
216           IMG_UINT32 uFlags,
217           IMG_UINT32 uAlignment,
218                   IMG_UINT32 uAlignmentOffset,
219                   IMG_PVOID pvPrivData,
220                   IMG_UINT32 ui32PrivDataLength,
221           IMG_UINTPTR_T *pBase);
223 /**
224  *  @Function   RA_Free
225  *
226  *  @Description    To free a resource segment.
227  *  
228  *  @Input  pArena - the arena the segment was originally allocated from.
229  *  @Input  base - the base of the resource span to free.
230  *      @Input  bFreeBackingStore - Should backing store memory be freed?
231  *
232  *  @Return None
233  */
234 IMG_VOID 
235 RA_Free (RA_ARENA *pArena, IMG_UINTPTR_T base, IMG_BOOL bFreeBackingStore);
238 #ifdef RA_STATS
240 #define CHECK_SPACE(total)                                      \
241 {                                                                                       \
242         if((total)<100)                                                         \
243                 return PVRSRV_ERROR_INVALID_PARAMS;     \
246 #define UPDATE_SPACE(str, count, total)         \
247 {                                                                                       \
248         if((count) == -1)                                                       \
249                 return PVRSRV_ERROR_INVALID_PARAMS;     \
250         else                                                                    \
251         {                                                                               \
252                 (str) += (count);                                               \
253                 (total) -= (count);                                             \
254         }                                                                               \
258 /**
259  * @Function    RA_GetNextLiveSegment
260  * 
261  * @Description Returns details of the next live resource segments
262  * 
263  * @Input       pArena - the arena the segment was originally allocated from.
264  * @Output      psSegDetails - rtn details of segments
265  * 
266  * @Return      IMG_TRUE if operation succeeded
267  */
268 IMG_BOOL RA_GetNextLiveSegment(IMG_HANDLE hArena, RA_SEGMENT_DETAILS *psSegDetails);
271 /**
272  *  @Function   RA_GetStats
273  *
274  *  @Description    gets stats on a given arena
275  *  
276  *  @Input  pArena - the arena the segment was originally allocated from.
277  *  @Input  ppszStr - string to write stats to 
278  *      @Input  pui32StrLen - length of string
279  *
280  *  @Return PVRSRV_ERROR
281  */
282 PVRSRV_ERROR RA_GetStats(RA_ARENA *pArena,
283                                                         IMG_CHAR **ppszStr, 
284                                                         IMG_UINT32 *pui32StrLen);
286 PVRSRV_ERROR RA_GetStatsFreeMem(RA_ARENA *pArena,
287                                                                 IMG_CHAR **ppszStr, 
288                                                                 IMG_UINT32 *pui32StrLen);
290 #endif /* #ifdef RA_STATS */
292 #endif