]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel.h
ENGR00294354 gpu:Using vitural memory cause AXI bus error
[karo-tx-linux.git] / drivers / mxc / gpu-viv / hal / kernel / gc_hal_kernel.h
1 /****************************************************************************
2 *
3 *    Copyright (C) 2005 - 2013 by Vivante Corp.
4 *
5 *    This program is free software; you can redistribute it and/or modify
6 *    it under the terms of the GNU General Public License as published by
7 *    the Free Software Foundation; either version 2 of the license, or
8 *    (at your option) any later version.
9 *
10 *    This program is distributed in the hope that it will be useful,
11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *    GNU General Public License for more details.
14 *
15 *    You should have received a copy of the GNU General Public License
16 *    along with this program; if not write to the Free Software
17 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 *****************************************************************************/
20
21
22 #ifndef __gc_hal_kernel_h_
23 #define __gc_hal_kernel_h_
24
25 #include "gc_hal.h"
26 #include "gc_hal_kernel_hardware.h"
27 #include "gc_hal_driver.h"
28
29 #if gcdENABLE_VG
30 #include "gc_hal_kernel_vg.h"
31 #endif
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37
38 /*******************************************************************************
39 ***** New MMU Defination *******************************************************/
40 #define gcdMMU_MTLB_SHIFT           22
41 #define gcdMMU_STLB_4K_SHIFT        12
42 #define gcdMMU_STLB_64K_SHIFT       16
43
44 #define gcdMMU_MTLB_BITS            (32 - gcdMMU_MTLB_SHIFT)
45 #define gcdMMU_PAGE_4K_BITS         gcdMMU_STLB_4K_SHIFT
46 #define gcdMMU_STLB_4K_BITS         (32 - gcdMMU_MTLB_BITS - gcdMMU_PAGE_4K_BITS)
47 #define gcdMMU_PAGE_64K_BITS        gcdMMU_STLB_64K_SHIFT
48 #define gcdMMU_STLB_64K_BITS        (32 - gcdMMU_MTLB_BITS - gcdMMU_PAGE_64K_BITS)
49
50 #define gcdMMU_MTLB_ENTRY_NUM       (1 << gcdMMU_MTLB_BITS)
51 #define gcdMMU_MTLB_SIZE            (gcdMMU_MTLB_ENTRY_NUM << 2)
52 #define gcdMMU_STLB_4K_ENTRY_NUM    (1 << gcdMMU_STLB_4K_BITS)
53 #define gcdMMU_STLB_4K_SIZE         (gcdMMU_STLB_4K_ENTRY_NUM << 2)
54 #define gcdMMU_PAGE_4K_SIZE         (1 << gcdMMU_STLB_4K_SHIFT)
55 #define gcdMMU_STLB_64K_ENTRY_NUM   (1 << gcdMMU_STLB_64K_BITS)
56 #define gcdMMU_STLB_64K_SIZE        (gcdMMU_STLB_64K_ENTRY_NUM << 2)
57 #define gcdMMU_PAGE_64K_SIZE        (1 << gcdMMU_STLB_64K_SHIFT)
58
59 #define gcdMMU_MTLB_MASK            (~((1U << gcdMMU_MTLB_SHIFT)-1))
60 #define gcdMMU_STLB_4K_MASK         ((~0U << gcdMMU_STLB_4K_SHIFT) ^ gcdMMU_MTLB_MASK)
61 #define gcdMMU_PAGE_4K_MASK         (gcdMMU_PAGE_4K_SIZE - 1)
62 #define gcdMMU_STLB_64K_MASK        ((~((1U << gcdMMU_STLB_64K_SHIFT)-1)) ^ gcdMMU_MTLB_MASK)
63 #define gcdMMU_PAGE_64K_MASK        (gcdMMU_PAGE_64K_SIZE - 1)
64
65 /* Page offset definitions. */
66 #define gcdMMU_OFFSET_4K_BITS       (32 - gcdMMU_MTLB_BITS - gcdMMU_STLB_4K_BITS)
67 #define gcdMMU_OFFSET_4K_MASK       ((1U << gcdMMU_OFFSET_4K_BITS) - 1)
68 #define gcdMMU_OFFSET_16K_BITS      (32 - gcdMMU_MTLB_BITS - gcdMMU_STLB_16K_BITS)
69 #define gcdMMU_OFFSET_16K_MASK      ((1U << gcdMMU_OFFSET_16K_BITS) - 1)
70
71 /*******************************************************************************
72 ***** Process Secure Cache ****************************************************/
73
74 #define gcdSECURE_CACHE_LRU         1
75 #define gcdSECURE_CACHE_LINEAR      2
76 #define gcdSECURE_CACHE_HASH        3
77 #define gcdSECURE_CACHE_TABLE       4
78
79 typedef struct _gcskLOGICAL_CACHE * gcskLOGICAL_CACHE_PTR;
80 typedef struct _gcskLOGICAL_CACHE   gcskLOGICAL_CACHE;
81 struct _gcskLOGICAL_CACHE
82 {
83     /* Logical address. */
84     gctPOINTER                      logical;
85
86     /* DMAable address. */
87     gctUINT32                       dma;
88
89 #if gcdSECURE_CACHE_METHOD == gcdSECURE_CACHE_HASH
90     /* Pointer to the previous and next hash tables. */
91     gcskLOGICAL_CACHE_PTR           nextHash;
92     gcskLOGICAL_CACHE_PTR           prevHash;
93 #endif
94
95 #if gcdSECURE_CACHE_METHOD != gcdSECURE_CACHE_TABLE
96     /* Pointer to the previous and next slot. */
97     gcskLOGICAL_CACHE_PTR           next;
98     gcskLOGICAL_CACHE_PTR           prev;
99 #endif
100
101 #if gcdSECURE_CACHE_METHOD == gcdSECURE_CACHE_LINEAR
102     /* Time stamp. */
103     gctUINT64                       stamp;
104 #endif
105 };
106
107 typedef struct _gcskSECURE_CACHE * gcskSECURE_CACHE_PTR;
108 typedef struct _gcskSECURE_CACHE
109 {
110     /* Cache memory. */
111     gcskLOGICAL_CACHE               cache[1 + gcdSECURE_CACHE_SLOTS];
112
113     /* Last known index for LINEAR mode. */
114     gcskLOGICAL_CACHE_PTR           cacheIndex;
115
116     /* Current free slot for LINEAR mode. */
117     gctUINT32                       cacheFree;
118
119     /* Time stamp for LINEAR mode. */
120     gctUINT64                       cacheStamp;
121
122 #if gcdSECURE_CACHE_METHOD == gcdSECURE_CACHE_HASH
123     /* Hash table for HASH mode. */
124     gcskLOGICAL_CACHE              hash[256];
125 #endif
126 }
127 gcskSECURE_CACHE;
128
129 /*******************************************************************************
130 ***** Process Database Management *********************************************/
131
132 typedef enum _gceDATABASE_TYPE
133 {
134     gcvDB_VIDEO_MEMORY = 1,             /* Video memory created. */
135     gcvDB_COMMAND_BUFFER,               /* Command Buffer. */
136     gcvDB_NON_PAGED,                    /* Non paged memory. */
137     gcvDB_CONTIGUOUS,                   /* Contiguous memory. */
138     gcvDB_SIGNAL,                       /* Signal. */
139     gcvDB_VIDEO_MEMORY_LOCKED,          /* Video memory locked. */
140     gcvDB_CONTEXT,                      /* Context */
141     gcvDB_IDLE,                         /* GPU idle. */
142     gcvDB_MAP_MEMORY,                   /* Map memory */
143     gcvDB_SHARED_INFO,                  /* Private data */
144     gcvDB_MAP_USER_MEMORY,              /* Map user memory */
145     gcvDB_SYNC_POINT,                   /* Sync point. */
146     gcvDB_VIDEO_MEMORY_RESERVED,        /* Reserved video memory */
147     gcvDB_VIDEO_MEMORY_CONTIGUOUS,      /* Contiguous video memory */
148     gcvDB_VIDEO_MEMORY_VIRTUAL,         /* Virtual video memory */
149 }
150 gceDATABASE_TYPE;
151
152 typedef struct _gcsDATABASE_RECORD *    gcsDATABASE_RECORD_PTR;
153 typedef struct _gcsDATABASE_RECORD
154 {
155     /* Pointer to kernel. */
156     gckKERNEL                           kernel;
157
158     /* Pointer to next database record. */
159     gcsDATABASE_RECORD_PTR              next;
160
161     /* Type of record. */
162     gceDATABASE_TYPE                    type;
163
164     /* Data for record. */
165     gctPOINTER                          data;
166     gctPHYS_ADDR                        physical;
167     gctSIZE_T                           bytes;
168 }
169 gcsDATABASE_RECORD;
170
171 typedef struct _gcsDATABASE *           gcsDATABASE_PTR;
172 typedef struct _gcsDATABASE
173 {
174     /* Pointer to next entry is hash list. */
175     gcsDATABASE_PTR                     next;
176     gctSIZE_T                           slot;
177
178     /* Process ID. */
179     gctUINT32                           processID;
180
181     /* Sizes to query. */
182     gcsDATABASE_COUNTERS                vidMem;
183     gcsDATABASE_COUNTERS                nonPaged;
184     gcsDATABASE_COUNTERS                contiguous;
185     gcsDATABASE_COUNTERS                mapUserMemory;
186     gcsDATABASE_COUNTERS                mapMemory;
187     gcsDATABASE_COUNTERS                vidMemResv;
188     gcsDATABASE_COUNTERS                vidMemCont;
189     gcsDATABASE_COUNTERS                vidMemVirt;
190
191     /* Idle time management. */
192     gctUINT64                           lastIdle;
193     gctUINT64                           idle;
194
195     /* Pointer to database. */
196     gcsDATABASE_RECORD_PTR              list[48];
197
198 #if gcdSECURE_USER
199     /* Secure cache. */
200     gcskSECURE_CACHE                    cache;
201 #endif
202
203     gctPOINTER                          handleDatabase;
204     gctPOINTER                          handleDatabaseMutex;
205 }
206 gcsDATABASE;
207
208 /* Create a process database that will contain all its allocations. */
209 gceSTATUS
210 gckKERNEL_CreateProcessDB(
211     IN gckKERNEL Kernel,
212     IN gctUINT32 ProcessID
213     );
214
215 /* Add a record to the process database. */
216 gceSTATUS
217 gckKERNEL_AddProcessDB(
218     IN gckKERNEL Kernel,
219     IN gctUINT32 ProcessID,
220     IN gceDATABASE_TYPE Type,
221     IN gctPOINTER Pointer,
222     IN gctPHYS_ADDR Physical,
223     IN gctSIZE_T Size
224     );
225
226 /* Remove a record to the process database. */
227 gceSTATUS
228 gckKERNEL_RemoveProcessDB(
229     IN gckKERNEL Kernel,
230     IN gctUINT32 ProcessID,
231     IN gceDATABASE_TYPE Type,
232     IN gctPOINTER Pointer
233     );
234
235 /* Destroy the process database. */
236 gceSTATUS
237 gckKERNEL_DestroyProcessDB(
238     IN gckKERNEL Kernel,
239     IN gctUINT32 ProcessID
240     );
241
242 /* Find a record to the process database. */
243 gceSTATUS
244 gckKERNEL_FindProcessDB(
245     IN gckKERNEL Kernel,
246     IN gctUINT32 ProcessID,
247     IN gctUINT32 ThreadID,
248     IN gceDATABASE_TYPE Type,
249     IN gctPOINTER Pointer,
250     OUT gcsDATABASE_RECORD_PTR Record
251     );
252
253 /* Query the process database. */
254 gceSTATUS
255 gckKERNEL_QueryProcessDB(
256     IN gckKERNEL Kernel,
257     IN gctUINT32 ProcessID,
258     IN gctBOOL LastProcessID,
259     IN gceDATABASE_TYPE Type,
260     OUT gcuDATABASE_INFO * Info
261     );
262
263 /* Dump the process database. */
264 gceSTATUS
265 gckKERNEL_DumpProcessDB(
266     IN gckKERNEL Kernel
267     );
268
269 /* ID database */
270 gceSTATUS
271 gckKERNEL_CreateIntegerDatabase(
272     IN gckKERNEL Kernel,
273     OUT gctPOINTER * Database
274     );
275
276 gceSTATUS
277 gckKERNEL_DestroyIntegerDatabase(
278     IN gckKERNEL Kernel,
279     IN gctPOINTER Database
280     );
281
282 gceSTATUS
283 gckKERNEL_AllocateIntegerId(
284     IN gctPOINTER Database,
285     IN gctPOINTER Pointer,
286     OUT gctUINT32 * Id
287     );
288
289 gceSTATUS
290 gckKERNEL_FreeIntegerId(
291     IN gctPOINTER Database,
292     IN gctUINT32 Id
293     );
294
295 gceSTATUS
296 gckKERNEL_QueryIntegerId(
297     IN gctPOINTER Database,
298     IN gctUINT32 Id,
299     OUT gctPOINTER * Pointer
300     );
301
302 gctUINT32
303 gckKERNEL_AllocateNameFromPointer(
304     IN gckKERNEL Kernel,
305     IN gctPOINTER Pointer
306     );
307
308 gctPOINTER
309 gckKERNEL_QueryPointerFromName(
310     IN gckKERNEL Kernel,
311     IN gctUINT32 Name
312     );
313
314 gceSTATUS
315 gckKERNEL_DeleteName(
316     IN gckKERNEL Kernel,
317     IN gctUINT32 Name
318     );
319
320 #if gcdSECURE_USER
321 /* Get secure cache from the process database. */
322 gceSTATUS
323 gckKERNEL_GetProcessDBCache(
324     IN gckKERNEL Kernel,
325     IN gctUINT32 ProcessID,
326     OUT gcskSECURE_CACHE_PTR * Cache
327     );
328 #endif
329
330 /*******************************************************************************
331 ********* Timer Management ****************************************************/
332 typedef struct _gcsTIMER *           gcsTIMER_PTR;
333 typedef struct _gcsTIMER
334 {
335     /* Start and Stop time holders. */
336     gctUINT64                           startTime;
337     gctUINT64                           stopTime;
338 }
339 gcsTIMER;
340
341 /******************************************************************************\
342 ********************************** Structures **********************************
343 \******************************************************************************/
344
345 /* gckDB object. */
346 struct _gckDB
347 {
348     /* Database management. */
349     gcsDATABASE_PTR             db[16];
350     gctPOINTER                  dbMutex;
351     gcsDATABASE_PTR             freeDatabase;
352     gcsDATABASE_RECORD_PTR      freeRecord;
353     gcsDATABASE_PTR             lastDatabase;
354     gctUINT32                   lastProcessID;
355     gctUINT64                   lastIdle;
356     gctUINT64                   idleTime;
357     gctUINT64                   lastSlowdown;
358     gctUINT64                   lastSlowdownIdle;
359     /* ID - Pointer database*/
360     gctPOINTER                  pointerDatabase;
361     gctPOINTER                  pointerDatabaseMutex;
362 };
363
364 #if gcdVIRTUAL_COMMAND_BUFFER
365 typedef struct _gckVIRTUAL_COMMAND_BUFFER * gckVIRTUAL_COMMAND_BUFFER_PTR;
366 typedef struct _gckVIRTUAL_COMMAND_BUFFER
367 {
368     gctPHYS_ADDR                physical;
369     gctPOINTER                  userLogical;
370     gctPOINTER                  kernelLogical;
371     gctSIZE_T                   pageCount;
372     gctPOINTER                  pageTable;
373     gctUINT32                   gpuAddress;
374     gctUINT                     pid;
375     gckVIRTUAL_COMMAND_BUFFER_PTR   next;
376     gckVIRTUAL_COMMAND_BUFFER_PTR   prev;
377     gckKERNEL                   kernel;
378 }
379 gckVIRTUAL_COMMAND_BUFFER;
380 #endif
381
382 /* gckKERNEL object. */
383 struct _gckKERNEL
384 {
385     /* Object. */
386     gcsOBJECT                   object;
387
388     /* Pointer to gckOS object. */
389     gckOS                       os;
390
391     /* Core */
392     gceCORE                     core;
393
394     /* Pointer to gckHARDWARE object. */
395     gckHARDWARE                 hardware;
396
397     /* Pointer to gckCOMMAND object. */
398     gckCOMMAND                  command;
399
400     /* Pointer to gckEVENT object. */
401     gckEVENT                    eventObj;
402
403     /* Pointer to context. */
404     gctPOINTER                  context;
405
406     /* Pointer to gckMMU object. */
407     gckMMU                      mmu;
408
409     /* Arom holding number of clients. */
410     gctPOINTER                  atomClients;
411
412 #if VIVANTE_PROFILER
413     /* Enable profiling */
414     gctBOOL                     profileEnable;
415
416     /* Clear profile register or not*/
417     gctBOOL                     profileCleanRegister;
418
419 #endif
420
421 #ifdef QNX_SINGLE_THREADED_DEBUGGING
422     gctPOINTER                  debugMutex;
423 #endif
424
425     /* Database management. */
426     gckDB                       db;
427     gctBOOL                     dbCreated;
428
429 #if gcdENABLE_RECOVERY
430     gctPOINTER                  resetFlagClearTimer;
431     gctPOINTER                  resetAtom;
432     gctUINT64                   resetTimeStamp;
433 #endif
434
435     /* Pointer to gckEVENT object. */
436     gcsTIMER                    timers[8];
437     gctUINT32                   timeOut;
438
439 #if gcdENABLE_VG
440     gckVGKERNEL                 vg;
441 #endif
442
443 #if gcdVIRTUAL_COMMAND_BUFFER
444     gckVIRTUAL_COMMAND_BUFFER_PTR virtualBufferHead;
445     gckVIRTUAL_COMMAND_BUFFER_PTR virtualBufferTail;
446     gctPOINTER                    virtualBufferLock;
447 #endif
448
449 #if gcdDVFS
450     gckDVFS                     dvfs;
451 #endif
452
453 #if gcdANDROID_NATIVE_FENCE_SYNC
454     gctHANDLE                   timeline;
455 #endif
456 };
457
458 struct _FrequencyHistory
459 {
460     gctUINT32                   frequency;
461     gctUINT32                   count;
462 };
463
464 /* gckDVFS object. */
465 struct _gckDVFS
466 {
467     gckOS                       os;
468     gckHARDWARE                 hardware;
469     gctPOINTER                  timer;
470     gctUINT32                   pollingTime;
471     gctBOOL                     stop;
472     gctUINT32                   totalConfig;
473     gctUINT32                   loads[8];
474     gctUINT8                    currentScale;
475     struct _FrequencyHistory    frequencyHistory[16];
476 };
477
478 /* gckCOMMAND object. */
479 struct _gckCOMMAND
480 {
481     /* Object. */
482     gcsOBJECT                   object;
483
484     /* Pointer to required object. */
485     gckKERNEL                   kernel;
486     gckOS                       os;
487
488     /* Number of bytes per page. */
489     gctSIZE_T                   pageSize;
490
491     /* Current pipe select. */
492     gcePIPE_SELECT              pipeSelect;
493
494     /* Command queue running flag. */
495     gctBOOL                     running;
496
497     /* Idle flag and commit stamp. */
498     gctBOOL                     idle;
499     gctUINT64                   commitStamp;
500
501     /* Command queue mutex. */
502     gctPOINTER                  mutexQueue;
503
504     /* Context switching mutex. */
505     gctPOINTER                  mutexContext;
506
507 #if VIVANTE_PROFILER_CONTEXT
508     /* Context sequence mutex. */
509     gctPOINTER                  mutexContextSeq;
510 #endif
511
512     /* Command queue power semaphore. */
513     gctPOINTER                  powerSemaphore;
514
515     /* Current command queue. */
516     struct _gcskCOMMAND_QUEUE
517     {
518         gctSIGNAL               signal;
519         gctPHYS_ADDR            physical;
520         gctPOINTER              logical;
521     }
522     queues[gcdCOMMAND_QUEUES];
523
524     gctPHYS_ADDR                physical;
525     gctPOINTER                  logical;
526     gctUINT32                   offset;
527     gctINT                      index;
528 #if gcmIS_DEBUG(gcdDEBUG_TRACE)
529     gctUINT                     wrapCount;
530 #endif
531
532     /* The command queue is new. */
533     gctBOOL                     newQueue;
534
535     /* Context management. */
536     gckCONTEXT                  currContext;
537
538     /* Pointer to last WAIT command. */
539     gctPHYS_ADDR                waitPhysical;
540     gctPOINTER                  waitLogical;
541     gctSIZE_T                   waitSize;
542
543     /* Command buffer alignment. */
544     gctSIZE_T                   alignment;
545     gctSIZE_T                   reservedHead;
546     gctSIZE_T                   reservedTail;
547
548     /* Commit counter. */
549     gctPOINTER                  atomCommit;
550
551     /* Kernel process ID. */
552     gctUINT32                   kernelProcessID;
553
554     /* End Event signal. */
555     gctSIGNAL                   endEventSignal;
556
557 #if gcdSECURE_USER
558     /* Hint array copy buffer. */
559     gctBOOL                     hintArrayAllocated;
560     gctUINT                     hintArraySize;
561     gctUINT32_PTR               hintArray;
562 #endif
563 };
564
565 typedef struct _gcsEVENT *      gcsEVENT_PTR;
566
567 /* Structure holding one event to be processed. */
568 typedef struct _gcsEVENT
569 {
570     /* Pointer to next event in queue. */
571     gcsEVENT_PTR                next;
572
573     /* Event information. */
574     gcsHAL_INTERFACE            info;
575
576     /* Process ID owning the event. */
577     gctUINT32                   processID;
578
579 #ifdef __QNXNTO__
580     /* Kernel. */
581     gckKERNEL                   kernel;
582 #endif
583
584     gctBOOL                     fromKernel;
585 }
586 gcsEVENT;
587
588 /* Structure holding a list of events to be processed by an interrupt. */
589 typedef struct _gcsEVENT_QUEUE * gcsEVENT_QUEUE_PTR;
590 typedef struct _gcsEVENT_QUEUE
591 {
592     /* Time stamp. */
593     gctUINT64                   stamp;
594
595     /* Source of the event. */
596     gceKERNEL_WHERE             source;
597
598     /* Pointer to head of event queue. */
599     gcsEVENT_PTR                head;
600
601     /* Pointer to tail of event queue. */
602     gcsEVENT_PTR                tail;
603
604     /* Next list of events. */
605     gcsEVENT_QUEUE_PTR          next;
606 }
607 gcsEVENT_QUEUE;
608
609 /*
610     gcdREPO_LIST_COUNT defines the maximum number of event queues with different
611     hardware module sources that may coexist at the same time. Only two sources
612     are supported - gcvKERNEL_COMMAND and gcvKERNEL_PIXEL. gcvKERNEL_COMMAND
613     source is used only for managing the kernel command queue and is only issued
614     when the current command queue gets full. Since we commit event queues every
615     time we commit command buffers, in the worst case we can have up to three
616     pending event queues:
617         - gcvKERNEL_PIXEL
618         - gcvKERNEL_COMMAND (queue overflow)
619         - gcvKERNEL_PIXEL
620 */
621 #define gcdREPO_LIST_COUNT      3
622
623 /* gckEVENT object. */
624 struct _gckEVENT
625 {
626     /* The object. */
627     gcsOBJECT                   object;
628
629     /* Pointer to required objects. */
630     gckOS                       os;
631     gckKERNEL                   kernel;
632
633     /* Time stamp. */
634     gctUINT64                   stamp;
635     gctUINT64                   lastCommitStamp;
636
637     /* Queue mutex. */
638     gctPOINTER                  eventQueueMutex;
639
640     /* Array of event queues. */
641     gcsEVENT_QUEUE              queues[30];
642     gctUINT8                    lastID;
643     gctPOINTER                  freeAtom;
644
645     /* Pending events. */
646 #if gcdSMP
647     gctPOINTER                  pending;
648 #else
649     volatile gctUINT            pending;
650 #endif
651
652     /* List of free event structures and its mutex. */
653     gcsEVENT_PTR                freeEventList;
654     gctSIZE_T                   freeEventCount;
655     gctPOINTER                  freeEventMutex;
656
657     /* Event queues. */
658     gcsEVENT_QUEUE_PTR          queueHead;
659     gcsEVENT_QUEUE_PTR          queueTail;
660     gcsEVENT_QUEUE_PTR          freeList;
661     gcsEVENT_QUEUE              repoList[gcdREPO_LIST_COUNT];
662     gctPOINTER                  eventListMutex;
663
664     gctPOINTER                  submitTimer;
665
666     volatile gctBOOL            inNotify;
667 };
668
669 /* Free all events belonging to a process. */
670 gceSTATUS
671 gckEVENT_FreeProcess(
672     IN gckEVENT Event,
673     IN gctUINT32 ProcessID
674     );
675
676 gceSTATUS
677 gckEVENT_Stop(
678     IN gckEVENT Event,
679     IN gctUINT32 ProcessID,
680     IN gctPHYS_ADDR Handle,
681     IN gctPOINTER Logical,
682     IN gctSIGNAL Signal,
683         IN OUT gctSIZE_T * waitSize
684     );
685
686 gceSTATUS
687 gckEVENT_WaitEmpty(
688     IN gckEVENT Event
689     );
690
691 /* gcuVIDMEM_NODE structure. */
692 typedef union _gcuVIDMEM_NODE
693 {
694     /* Allocated from gckVIDMEM. */
695     struct _gcsVIDMEM_NODE_VIDMEM
696     {
697         /* Owner of this node. */
698         gckVIDMEM               memory;
699
700         /* Dual-linked list of nodes. */
701         gcuVIDMEM_NODE_PTR      next;
702         gcuVIDMEM_NODE_PTR      prev;
703
704         /* Dual linked list of free nodes. */
705         gcuVIDMEM_NODE_PTR      nextFree;
706         gcuVIDMEM_NODE_PTR      prevFree;
707
708         /* Information for this node. */
709         gctUINT32               offset;
710         gctSIZE_T               bytes;
711         gctUINT32               alignment;
712
713 #ifdef __QNXNTO__
714         /* Client/server vaddr (mapped using mmap_join). */
715         gctPOINTER              logical;
716 #endif
717
718         /* Locked counter. */
719         gctINT32                locked;
720
721         /* Memory pool. */
722         gcePOOL                 pool;
723         gctUINT32               physical;
724
725         /* Process ID owning this memory. */
726         gctUINT32               processID;
727
728         /* Prevent compositor from freeing until client unlocks. */
729         gctBOOL                 freePending;
730
731         /* */
732         gcsVIDMEM_NODE_SHARED_INFO sharedInfo;
733
734 #if gcdDYNAMIC_MAP_RESERVED_MEMORY && gcdENABLE_VG
735         gctPOINTER              kernelVirtual;
736 #endif
737
738         /* Surface type. */
739         gceSURF_TYPE            type;
740     }
741     VidMem;
742
743     /* Allocated from gckOS. */
744     struct _gcsVIDMEM_NODE_VIRTUAL
745     {
746         /* Pointer to gckKERNEL object. */
747         gckKERNEL               kernel;
748
749         /* Information for this node. */
750         /* Contiguously allocated? */
751         gctBOOL                 contiguous;
752         /* mdl record pointer... a kmalloc address. Process agnostic. */
753         gctPHYS_ADDR            physical;
754         gctSIZE_T               bytes;
755         /* do_mmap_pgoff address... mapped per-process. */
756         gctPOINTER              logical;
757
758         /* Page table information. */
759         /* Used only when node is not contiguous */
760         gctSIZE_T               pageCount;
761
762         /* Used only when node is not contiguous */
763         gctPOINTER              pageTables[gcdMAX_GPU_COUNT];
764         /* Pointer to gckKERNEL object who lock this. */
765         gckKERNEL               lockKernels[gcdMAX_GPU_COUNT];
766         /* Actual physical address */
767         gctUINT32               addresses[gcdMAX_GPU_COUNT];
768
769         /* Mutex. */
770         gctPOINTER              mutex;
771
772         /* Locked counter. */
773         gctINT32                lockeds[gcdMAX_GPU_COUNT];
774
775 #ifdef __QNXNTO__
776         /* Single linked list of nodes. */
777         gcuVIDMEM_NODE_PTR      next;
778
779         /* Unlock pending flag. */
780         gctBOOL                 unlockPendings[gcdMAX_GPU_COUNT];
781
782         /* Free pending flag. */
783         gctBOOL                 freePending;
784 #endif
785
786         /* Process ID owning this memory. */
787         gctUINT32               processID;
788
789         /* Owner process sets freed to true
790          * when it trys to free a locked
791          * node */
792         gctBOOL                 freed;
793
794         /* */
795         gcsVIDMEM_NODE_SHARED_INFO sharedInfo;
796
797         /* Surface type. */
798         gceSURF_TYPE            type;
799     }
800     Virtual;
801 }
802 gcuVIDMEM_NODE;
803
804 /* gckVIDMEM object. */
805 struct _gckVIDMEM
806 {
807     /* Object. */
808     gcsOBJECT                   object;
809
810     /* Pointer to gckOS object. */
811     gckOS                       os;
812
813     /* Information for this video memory heap. */
814     gctUINT32                   baseAddress;
815     gctSIZE_T                   bytes;
816     gctSIZE_T                   freeBytes;
817
818     /* Mapping for each type of surface. */
819     gctINT                      mapping[gcvSURF_NUM_TYPES];
820
821     /* Sentinel nodes for up to 8 banks. */
822     gcuVIDMEM_NODE              sentinel[8];
823
824     /* Allocation threshold. */
825     gctSIZE_T                   threshold;
826
827     /* The heap mutex. */
828     gctPOINTER                  mutex;
829
830 #if gcdUSE_VIDMEM_PER_PID
831     /* The Pid this VidMem belongs to. */
832     gctUINT32                   pid;
833
834     struct _gckVIDMEM*          next;
835 #endif
836 };
837
838 /* gckMMU object. */
839 struct _gckMMU
840 {
841     /* The object. */
842     gcsOBJECT                   object;
843
844     /* Pointer to gckOS object. */
845     gckOS                       os;
846
847     /* Pointer to gckHARDWARE object. */
848     gckHARDWARE                 hardware;
849
850     /* The page table mutex. */
851     gctPOINTER                  pageTableMutex;
852
853     /* Page table information. */
854     gctSIZE_T                   pageTableSize;
855     gctPHYS_ADDR                pageTablePhysical;
856     gctUINT32_PTR               pageTableLogical;
857     gctUINT32                   pageTableEntries;
858
859     /* Master TLB information. */
860     gctSIZE_T                   mtlbSize;
861     gctPHYS_ADDR                mtlbPhysical;
862     gctUINT32_PTR               mtlbLogical;
863     gctUINT32                   mtlbEntries;
864
865     /* Free entries. */
866     gctUINT32                   heapList;
867     gctBOOL                     freeNodes;
868
869     gctPOINTER                  staticSTLB;
870     gctBOOL                     enabled;
871
872     gctUINT32                   dynamicMappingStart;
873
874 #ifdef __QNXNTO__
875     /* Single linked list of all allocated nodes. */
876     gctPOINTER                  nodeMutex;
877     gcuVIDMEM_NODE_PTR          nodeList;
878 #endif
879 };
880
881 #if gcdVIRTUAL_COMMAND_BUFFER
882 gceSTATUS
883 gckOS_CreateKernelVirtualMapping(
884     IN gctPHYS_ADDR Physical,
885     OUT gctSIZE_T * PageCount,
886     OUT gctPOINTER * Logical
887     );
888
889 gceSTATUS
890 gckOS_DestroyKernelVirtualMapping(
891     IN gctPOINTER Logical
892     );
893
894 gceSTATUS
895 gckKERNEL_AllocateVirtualCommandBuffer(
896     IN gckKERNEL Kernel,
897     IN gctBOOL InUserSpace,
898     IN OUT gctSIZE_T * Bytes,
899     OUT gctPHYS_ADDR * Physical,
900     OUT gctPOINTER * Logical
901     );
902
903 gceSTATUS
904 gckKERNEL_DestroyVirtualCommandBuffer(
905     IN gckKERNEL Kernel,
906     IN gctSIZE_T Bytes,
907     IN gctPHYS_ADDR Physical,
908     IN gctPOINTER Logical
909     );
910
911 gceSTATUS
912 gckKERNEL_GetGPUAddress(
913     IN gckKERNEL Kernel,
914     IN gctPOINTER Logical,
915     OUT gctUINT32 * Address
916     );
917
918 gceSTATUS
919 gckKERNEL_QueryGPUAddress(
920     IN gckKERNEL Kernel,
921     IN gctUINT32 GpuAddress,
922     OUT gckVIRTUAL_COMMAND_BUFFER_PTR * Buffer
923     );
924 #endif
925
926 gceSTATUS
927 gckKERNEL_AttachProcess(
928     IN gckKERNEL Kernel,
929     IN gctBOOL Attach
930     );
931
932 gceSTATUS
933 gckKERNEL_AttachProcessEx(
934     IN gckKERNEL Kernel,
935     IN gctBOOL Attach,
936     IN gctUINT32 PID
937     );
938
939 #if gcdSECURE_USER
940 gceSTATUS
941 gckKERNEL_MapLogicalToPhysical(
942     IN gckKERNEL Kernel,
943     IN gcskSECURE_CACHE_PTR Cache,
944     IN OUT gctPOINTER * Data
945     );
946
947 gceSTATUS
948 gckKERNEL_FlushTranslationCache(
949     IN gckKERNEL Kernel,
950     IN gcskSECURE_CACHE_PTR Cache,
951     IN gctPOINTER Logical,
952     IN gctSIZE_T Bytes
953     );
954 #endif
955
956 gceSTATUS
957 gckHARDWARE_QueryIdle(
958     IN gckHARDWARE Hardware,
959     OUT gctBOOL_PTR IsIdle
960     );
961
962 /******************************************************************************\
963 ******************************* gckCONTEXT Object *******************************
964 \******************************************************************************/
965
966 gceSTATUS
967 gckCONTEXT_Construct(
968     IN gckOS Os,
969     IN gckHARDWARE Hardware,
970     IN gctUINT32 ProcessID,
971     OUT gckCONTEXT * Context
972     );
973
974 gceSTATUS
975 gckCONTEXT_Destroy(
976     IN gckCONTEXT Context
977     );
978
979 gceSTATUS
980 gckCONTEXT_Update(
981     IN gckCONTEXT Context,
982     IN gctUINT32 ProcessID,
983     IN gcsSTATE_DELTA_PTR StateDelta
984     );
985
986 #if gcdLINK_QUEUE_SIZE
987 void
988 gckLINKQUEUE_Enqueue(
989     IN gckLINKQUEUE LinkQueue,
990     IN gctUINT32 start,
991     IN gctUINT32 end
992     );
993
994 void
995 gckLINKQUEUE_GetData(
996     IN gckLINKQUEUE LinkQueue,
997     IN gctUINT32 Index,
998     OUT gckLINKDATA * Data
999     );
1000 #endif
1001
1002
1003 #ifdef __cplusplus
1004 }
1005 #endif
1006
1007 #endif /* __gc_hal_kernel_h_ */