]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel.h
ENGR00284988 gpu:Sync gpu kernel driver code
[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     VidMem;
739
740     /* Allocated from gckOS. */
741     struct _gcsVIDMEM_NODE_VIRTUAL
742     {
743         /* Pointer to gckKERNEL object. */
744         gckKERNEL               kernel;
745
746         /* Information for this node. */
747         /* Contiguously allocated? */
748         gctBOOL                 contiguous;
749         /* mdl record pointer... a kmalloc address. Process agnostic. */
750         gctPHYS_ADDR            physical;
751         gctSIZE_T               bytes;
752         /* do_mmap_pgoff address... mapped per-process. */
753         gctPOINTER              logical;
754
755         /* Page table information. */
756         /* Used only when node is not contiguous */
757         gctSIZE_T               pageCount;
758
759         /* Used only when node is not contiguous */
760         gctPOINTER              pageTables[gcdMAX_GPU_COUNT];
761         /* Pointer to gckKERNEL object who lock this. */
762         gckKERNEL               lockKernels[gcdMAX_GPU_COUNT];
763         /* Actual physical address */
764         gctUINT32               addresses[gcdMAX_GPU_COUNT];
765
766         /* Mutex. */
767         gctPOINTER              mutex;
768
769         /* Locked counter. */
770         gctINT32                lockeds[gcdMAX_GPU_COUNT];
771
772 #ifdef __QNXNTO__
773         /* Single linked list of nodes. */
774         gcuVIDMEM_NODE_PTR      next;
775
776         /* Unlock pending flag. */
777         gctBOOL                 unlockPendings[gcdMAX_GPU_COUNT];
778
779         /* Free pending flag. */
780         gctBOOL                 freePending;
781 #endif
782
783         /* Process ID owning this memory. */
784         gctUINT32               processID;
785
786         /* Owner process sets freed to true
787          * when it trys to free a locked
788          * node */
789         gctBOOL                 freed;
790
791         /* */
792         gcsVIDMEM_NODE_SHARED_INFO sharedInfo;
793     }
794     Virtual;
795 }
796 gcuVIDMEM_NODE;
797
798 /* gckVIDMEM object. */
799 struct _gckVIDMEM
800 {
801     /* Object. */
802     gcsOBJECT                   object;
803
804     /* Pointer to gckOS object. */
805     gckOS                       os;
806
807     /* Information for this video memory heap. */
808     gctUINT32                   baseAddress;
809     gctSIZE_T                   bytes;
810     gctSIZE_T                   freeBytes;
811
812     /* Mapping for each type of surface. */
813     gctINT                      mapping[gcvSURF_NUM_TYPES];
814
815     /* Sentinel nodes for up to 8 banks. */
816     gcuVIDMEM_NODE              sentinel[8];
817
818     /* Allocation threshold. */
819     gctSIZE_T                   threshold;
820
821     /* The heap mutex. */
822     gctPOINTER                  mutex;
823
824 #if gcdUSE_VIDMEM_PER_PID
825     /* The Pid this VidMem belongs to. */
826     gctUINT32                   pid;
827
828     struct _gckVIDMEM*          next;
829 #endif
830 };
831
832 /* gckMMU object. */
833 struct _gckMMU
834 {
835     /* The object. */
836     gcsOBJECT                   object;
837
838     /* Pointer to gckOS object. */
839     gckOS                       os;
840
841     /* Pointer to gckHARDWARE object. */
842     gckHARDWARE                 hardware;
843
844     /* The page table mutex. */
845     gctPOINTER                  pageTableMutex;
846
847     /* Page table information. */
848     gctSIZE_T                   pageTableSize;
849     gctPHYS_ADDR                pageTablePhysical;
850     gctUINT32_PTR               pageTableLogical;
851     gctUINT32                   pageTableEntries;
852
853     /* Master TLB information. */
854     gctSIZE_T                   mtlbSize;
855     gctPHYS_ADDR                mtlbPhysical;
856     gctUINT32_PTR               mtlbLogical;
857     gctUINT32                   mtlbEntries;
858
859     /* Free entries. */
860     gctUINT32                   heapList;
861     gctBOOL                     freeNodes;
862
863     gctPOINTER                  staticSTLB;
864     gctBOOL                     enabled;
865
866     gctUINT32                   dynamicMappingStart;
867
868 #ifdef __QNXNTO__
869     /* Single linked list of all allocated nodes. */
870     gctPOINTER                  nodeMutex;
871     gcuVIDMEM_NODE_PTR          nodeList;
872 #endif
873 };
874
875 #if gcdVIRTUAL_COMMAND_BUFFER
876 gceSTATUS
877 gckOS_CreateKernelVirtualMapping(
878     IN gctPHYS_ADDR Physical,
879     OUT gctSIZE_T * PageCount,
880     OUT gctPOINTER * Logical
881     );
882
883 gceSTATUS
884 gckOS_DestroyKernelVirtualMapping(
885     IN gctPOINTER Logical
886     );
887
888 gceSTATUS
889 gckKERNEL_AllocateVirtualCommandBuffer(
890     IN gckKERNEL Kernel,
891     IN gctBOOL InUserSpace,
892     IN OUT gctSIZE_T * Bytes,
893     OUT gctPHYS_ADDR * Physical,
894     OUT gctPOINTER * Logical
895     );
896
897 gceSTATUS
898 gckKERNEL_DestroyVirtualCommandBuffer(
899     IN gckKERNEL Kernel,
900     IN gctSIZE_T Bytes,
901     IN gctPHYS_ADDR Physical,
902     IN gctPOINTER Logical
903     );
904
905 gceSTATUS
906 gckKERNEL_GetGPUAddress(
907     IN gckKERNEL Kernel,
908     IN gctPOINTER Logical,
909     OUT gctUINT32 * Address
910     );
911
912 gceSTATUS
913 gckKERNEL_QueryGPUAddress(
914     IN gckKERNEL Kernel,
915     IN gctUINT32 GpuAddress,
916     OUT gckVIRTUAL_COMMAND_BUFFER_PTR * Buffer
917     );
918 #endif
919
920 gceSTATUS
921 gckKERNEL_AttachProcess(
922     IN gckKERNEL Kernel,
923     IN gctBOOL Attach
924     );
925
926 gceSTATUS
927 gckKERNEL_AttachProcessEx(
928     IN gckKERNEL Kernel,
929     IN gctBOOL Attach,
930     IN gctUINT32 PID
931     );
932
933 #if gcdSECURE_USER
934 gceSTATUS
935 gckKERNEL_MapLogicalToPhysical(
936     IN gckKERNEL Kernel,
937     IN gcskSECURE_CACHE_PTR Cache,
938     IN OUT gctPOINTER * Data
939     );
940
941 gceSTATUS
942 gckKERNEL_FlushTranslationCache(
943     IN gckKERNEL Kernel,
944     IN gcskSECURE_CACHE_PTR Cache,
945     IN gctPOINTER Logical,
946     IN gctSIZE_T Bytes
947     );
948 #endif
949
950 gceSTATUS
951 gckHARDWARE_QueryIdle(
952     IN gckHARDWARE Hardware,
953     OUT gctBOOL_PTR IsIdle
954     );
955
956 /******************************************************************************\
957 ******************************* gckCONTEXT Object *******************************
958 \******************************************************************************/
959
960 gceSTATUS
961 gckCONTEXT_Construct(
962     IN gckOS Os,
963     IN gckHARDWARE Hardware,
964     IN gctUINT32 ProcessID,
965     OUT gckCONTEXT * Context
966     );
967
968 gceSTATUS
969 gckCONTEXT_Destroy(
970     IN gckCONTEXT Context
971     );
972
973 gceSTATUS
974 gckCONTEXT_Update(
975     IN gckCONTEXT Context,
976     IN gctUINT32 ProcessID,
977     IN gcsSTATE_DELTA_PTR StateDelta
978     );
979
980 #if gcdLINK_QUEUE_SIZE
981 void
982 gckLINKQUEUE_Enqueue(
983     IN gckLINKQUEUE LinkQueue,
984     IN gctUINT32 start,
985     IN gctUINT32 end
986     );
987
988 void
989 gckLINKQUEUE_GetData(
990     IN gckLINKQUEUE LinkQueue,
991     IN gctUINT32 Index,
992     OUT gckLINKDATA * Data
993     );
994 #endif
995
996
997 #ifdef __cplusplus
998 }
999 #endif
1000
1001 #endif /* __gc_hal_kernel_h_ */