]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel.h
ENGR00240988: gpu: copy gpu-viv driver from 3.5.7 kernel
[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 }
146 gceDATABASE_TYPE;
147
148 typedef struct _gcsDATABASE_RECORD *    gcsDATABASE_RECORD_PTR;
149 typedef struct _gcsDATABASE_RECORD
150 {
151     /* Pointer to kernel. */
152     gckKERNEL                           kernel;
153
154     /* Pointer to next database record. */
155     gcsDATABASE_RECORD_PTR              next;
156
157     /* Type of record. */
158     gceDATABASE_TYPE                    type;
159
160     /* Data for record. */
161     gctPOINTER                          data;
162     gctPHYS_ADDR                        physical;
163     gctSIZE_T                           bytes;
164 }
165 gcsDATABASE_RECORD;
166
167 typedef struct _gcsDATABASE *           gcsDATABASE_PTR;
168 typedef struct _gcsDATABASE
169 {
170     /* Pointer to next entry is hash list. */
171     gcsDATABASE_PTR                     next;
172     gctSIZE_T                           slot;
173
174     /* Process ID. */
175     gctUINT32                           processID;
176
177     /* Sizes to query. */
178     gcsDATABASE_COUNTERS                vidMem;
179     gcsDATABASE_COUNTERS                nonPaged;
180     gcsDATABASE_COUNTERS                contiguous;
181     gcsDATABASE_COUNTERS                mapUserMemory;
182     gcsDATABASE_COUNTERS                mapMemory;
183
184     /* Idle time management. */
185     gctUINT64                           lastIdle;
186     gctUINT64                           idle;
187
188     /* Pointer to database. */
189     gcsDATABASE_RECORD_PTR              list[48];
190
191 #if gcdSECURE_USER
192     /* Secure cache. */
193     gcskSECURE_CACHE                    cache;
194 #endif
195
196     gctPOINTER                          handleDatabase;
197     gctPOINTER                          handleDatabaseMutex;
198 }
199 gcsDATABASE;
200
201 /* Create a process database that will contain all its allocations. */
202 gceSTATUS
203 gckKERNEL_CreateProcessDB(
204     IN gckKERNEL Kernel,
205     IN gctUINT32 ProcessID
206     );
207
208 /* Add a record to the process database. */
209 gceSTATUS
210 gckKERNEL_AddProcessDB(
211     IN gckKERNEL Kernel,
212     IN gctUINT32 ProcessID,
213     IN gceDATABASE_TYPE Type,
214     IN gctPOINTER Pointer,
215     IN gctPHYS_ADDR Physical,
216     IN gctSIZE_T Size
217     );
218
219 /* Remove a record to the process database. */
220 gceSTATUS
221 gckKERNEL_RemoveProcessDB(
222     IN gckKERNEL Kernel,
223     IN gctUINT32 ProcessID,
224     IN gceDATABASE_TYPE Type,
225     IN gctPOINTER Pointer
226     );
227
228 /* Destroy the process database. */
229 gceSTATUS
230 gckKERNEL_DestroyProcessDB(
231     IN gckKERNEL Kernel,
232     IN gctUINT32 ProcessID
233     );
234
235 /* Find a record to the process database. */
236 gceSTATUS
237 gckKERNEL_FindProcessDB(
238     IN gckKERNEL Kernel,
239     IN gctUINT32 ProcessID,
240     IN gctUINT32 ThreadID,
241     IN gceDATABASE_TYPE Type,
242     IN gctPOINTER Pointer,
243     OUT gcsDATABASE_RECORD_PTR Record
244     );
245
246 /* Query the process database. */
247 gceSTATUS
248 gckKERNEL_QueryProcessDB(
249     IN gckKERNEL Kernel,
250     IN gctUINT32 ProcessID,
251     IN gctBOOL LastProcessID,
252     IN gceDATABASE_TYPE Type,
253     OUT gcuDATABASE_INFO * Info
254     );
255
256 /* Dump the process database. */
257 gceSTATUS
258 gckKERNEL_DumpProcessDB(
259     IN gckKERNEL Kernel
260     );
261
262 /* ID database */
263 gceSTATUS
264 gckKERNEL_CreateIntegerDatabase(
265     IN gckKERNEL Kernel,
266     OUT gctPOINTER * Database
267     );
268
269 gceSTATUS
270 gckKERNEL_DestroyIntegerDatabase(
271     IN gckKERNEL Kernel,
272     IN gctPOINTER Database
273     );
274
275 gceSTATUS
276 gckKERNEL_AllocateIntegerId(
277     IN gctPOINTER Database,
278     IN gctPOINTER Pointer,
279     OUT gctUINT32 * Id
280     );
281
282 gceSTATUS
283 gckKERNEL_FreeIntegerId(
284     IN gctPOINTER Database,
285     IN gctUINT32 Id
286     );
287
288 gceSTATUS
289 gckKERNEL_QueryIntegerId(
290     IN gctPOINTER Database,
291     IN gctUINT32 Id,
292     OUT gctPOINTER * Pointer
293     );
294
295 gctUINT32
296 gckKERNEL_AllocateNameFromPointer(
297     IN gckKERNEL Kernel,
298     IN gctPOINTER Pointer
299     );
300
301 gctPOINTER
302 gckKERNEL_QueryPointerFromName(
303     IN gckKERNEL Kernel,
304     IN gctUINT32 Name
305     );
306
307 gceSTATUS
308 gckKERNEL_DeleteName(
309     IN gckKERNEL Kernel,
310     IN gctUINT32 Name
311     );
312
313 #if gcdSECURE_USER
314 /* Get secure cache from the process database. */
315 gceSTATUS
316 gckKERNEL_GetProcessDBCache(
317     IN gckKERNEL Kernel,
318     IN gctUINT32 ProcessID,
319     OUT gcskSECURE_CACHE_PTR * Cache
320     );
321 #endif
322
323 /*******************************************************************************
324 ********* Timer Management ****************************************************/
325 typedef struct _gcsTIMER *           gcsTIMER_PTR;
326 typedef struct _gcsTIMER
327 {
328     /* Start and Stop time holders. */
329     gctUINT64                           startTime;
330     gctUINT64                           stopTime;
331 }
332 gcsTIMER;
333
334 /******************************************************************************\
335 ********************************** Structures **********************************
336 \******************************************************************************/
337
338 /* gckDB object. */
339 struct _gckDB
340 {
341     /* Database management. */
342     gcsDATABASE_PTR             db[16];
343     gctPOINTER                  dbMutex;
344     gcsDATABASE_PTR             freeDatabase;
345     gcsDATABASE_RECORD_PTR      freeRecord;
346     gcsDATABASE_PTR             lastDatabase;
347     gctUINT32                   lastProcessID;
348     gctUINT64                   lastIdle;
349     gctUINT64                   idleTime;
350     gctUINT64                   lastSlowdown;
351     gctUINT64                   lastSlowdownIdle;
352     /* ID - Pointer database*/
353     gctPOINTER                  pointerDatabase;
354     gctPOINTER                  pointerDatabaseMutex;
355 };
356
357 #if gcdVIRTUAL_COMMAND_BUFFER
358 typedef struct _gckVIRTUAL_COMMAND_BUFFER * gckVIRTUAL_COMMAND_BUFFER_PTR;
359 typedef struct _gckVIRTUAL_COMMAND_BUFFER
360 {
361     gctPHYS_ADDR                physical;
362     gctPOINTER                  userLogical;
363     gctPOINTER                  kernelLogical;
364     gctSIZE_T                   pageCount;
365     gctPOINTER                  pageTable;
366     gctUINT32                   gpuAddress;
367     gctUINT                     pid;
368     gckVIRTUAL_COMMAND_BUFFER_PTR   next;
369     gckVIRTUAL_COMMAND_BUFFER_PTR   prev;
370     gckKERNEL                   kernel;
371 }
372 gckVIRTUAL_COMMAND_BUFFER;
373 #endif
374
375 /* gckKERNEL object. */
376 struct _gckKERNEL
377 {
378     /* Object. */
379     gcsOBJECT                   object;
380
381     /* Pointer to gckOS object. */
382     gckOS                       os;
383
384     /* Core */
385     gceCORE                     core;
386
387     /* Pointer to gckHARDWARE object. */
388     gckHARDWARE                 hardware;
389
390     /* Pointer to gckCOMMAND object. */
391     gckCOMMAND                  command;
392
393     /* Pointer to gckEVENT object. */
394     gckEVENT                    eventObj;
395
396     /* Pointer to context. */
397     gctPOINTER                  context;
398
399     /* Pointer to gckMMU object. */
400     gckMMU                      mmu;
401
402     /* Arom holding number of clients. */
403     gctPOINTER                  atomClients;
404
405 #if VIVANTE_PROFILER
406     /* Enable profiling */
407     gctBOOL                     profileEnable;
408
409     /* The profile file name */
410     gctCHAR                     profileFileName[gcdMAX_PROFILE_FILE_NAME];
411
412     /* Clear profile register or not*/
413     gctBOOL                     profileCleanRegister;
414
415 #endif
416
417 #ifdef QNX_SINGLE_THREADED_DEBUGGING
418     gctPOINTER                  debugMutex;
419 #endif
420
421     /* Database management. */
422     gckDB                       db;
423     gctBOOL                     dbCreated;
424
425 #if gcdENABLE_RECOVERY
426     gctPOINTER                  resetFlagClearTimer;
427     gctPOINTER                  resetAtom;
428     gctUINT64                   resetTimeStamp;
429 #endif
430
431     /* Pointer to gckEVENT object. */
432     gcsTIMER                    timers[8];
433     gctUINT32                   timeOut;
434
435 #if gcdENABLE_VG
436     gckVGKERNEL                 vg;
437 #endif
438
439 #if gcdVIRTUAL_COMMAND_BUFFER
440     gckVIRTUAL_COMMAND_BUFFER_PTR virtualBufferHead;
441     gckVIRTUAL_COMMAND_BUFFER_PTR virtualBufferTail;
442     gctPOINTER                    virtualBufferLock;
443 #endif
444
445 #if gcdDVFS
446     gckDVFS                     dvfs;
447 #endif
448 };
449
450 struct _FrequencyHistory
451 {
452     gctUINT32                   frequency;
453     gctUINT32                   count;
454 };
455
456 /* gckDVFS object. */
457 struct _gckDVFS
458 {
459     gckOS                       os;
460     gckHARDWARE                 hardware;
461     gctPOINTER                  timer;
462     gctUINT32                   pollingTime;
463     gctBOOL                     stop;
464     gctUINT32                   totalConfig;
465     gctUINT32                   loads[8];
466     gctUINT8                    currentScale;
467     struct _FrequencyHistory    frequencyHistory[16];
468 };
469
470 /* gckCOMMAND object. */
471 struct _gckCOMMAND
472 {
473     /* Object. */
474     gcsOBJECT                   object;
475
476     /* Pointer to required object. */
477     gckKERNEL                   kernel;
478     gckOS                       os;
479
480     /* Number of bytes per page. */
481     gctSIZE_T                   pageSize;
482
483     /* Current pipe select. */
484     gcePIPE_SELECT              pipeSelect;
485
486     /* Command queue running flag. */
487     gctBOOL                     running;
488
489     /* Idle flag and commit stamp. */
490     gctBOOL                     idle;
491     gctUINT64                   commitStamp;
492
493     /* Command queue mutex. */
494     gctPOINTER                  mutexQueue;
495
496     /* Context switching mutex. */
497     gctPOINTER                  mutexContext;
498
499     /* Command queue power semaphore. */
500     gctPOINTER                  powerSemaphore;
501
502     /* Current command queue. */
503     struct _gcskCOMMAND_QUEUE
504     {
505         gctSIGNAL               signal;
506         gctPHYS_ADDR            physical;
507         gctPOINTER              logical;
508     }
509     queues[gcdCOMMAND_QUEUES];
510
511     gctPHYS_ADDR                physical;
512     gctPOINTER                  logical;
513     gctUINT32                   offset;
514     gctINT                      index;
515 #if gcmIS_DEBUG(gcdDEBUG_TRACE)
516     gctUINT                     wrapCount;
517 #endif
518
519     /* The command queue is new. */
520     gctBOOL                     newQueue;
521
522     /* Context management. */
523     gckCONTEXT                  currContext;
524
525     /* Pointer to last WAIT command. */
526     gctPHYS_ADDR                waitPhysical;
527     gctPOINTER                  waitLogical;
528     gctSIZE_T                   waitSize;
529
530     /* Command buffer alignment. */
531     gctSIZE_T                   alignment;
532     gctSIZE_T                   reservedHead;
533     gctSIZE_T                   reservedTail;
534
535     /* Commit counter. */
536     gctPOINTER                  atomCommit;
537
538     /* Kernel process ID. */
539     gctUINT32                   kernelProcessID;
540
541     /* End Event signal. */
542     gctSIGNAL                   endEventSignal;
543
544 #if gcdSECURE_USER
545     /* Hint array copy buffer. */
546     gctBOOL                     hintArrayAllocated;
547     gctUINT                     hintArraySize;
548     gctUINT32_PTR               hintArray;
549 #endif
550 };
551
552 typedef struct _gcsEVENT *      gcsEVENT_PTR;
553
554 /* Structure holding one event to be processed. */
555 typedef struct _gcsEVENT
556 {
557     /* Pointer to next event in queue. */
558     gcsEVENT_PTR                next;
559
560     /* Event information. */
561     gcsHAL_INTERFACE            info;
562
563     /* Process ID owning the event. */
564     gctUINT32                   processID;
565
566 #ifdef __QNXNTO__
567     /* Kernel. */
568     gckKERNEL                   kernel;
569 #endif
570
571     gctBOOL                     fromKernel;
572 }
573 gcsEVENT;
574
575 /* Structure holding a list of events to be processed by an interrupt. */
576 typedef struct _gcsEVENT_QUEUE * gcsEVENT_QUEUE_PTR;
577 typedef struct _gcsEVENT_QUEUE
578 {
579     /* Time stamp. */
580     gctUINT64                   stamp;
581
582     /* Source of the event. */
583     gceKERNEL_WHERE             source;
584
585     /* Pointer to head of event queue. */
586     gcsEVENT_PTR                head;
587
588     /* Pointer to tail of event queue. */
589     gcsEVENT_PTR                tail;
590
591     /* Next list of events. */
592     gcsEVENT_QUEUE_PTR          next;
593 }
594 gcsEVENT_QUEUE;
595
596 /*
597     gcdREPO_LIST_COUNT defines the maximum number of event queues with different
598     hardware module sources that may coexist at the same time. Only two sources
599     are supported - gcvKERNEL_COMMAND and gcvKERNEL_PIXEL. gcvKERNEL_COMMAND
600     source is used only for managing the kernel command queue and is only issued
601     when the current command queue gets full. Since we commit event queues every
602     time we commit command buffers, in the worst case we can have up to three
603     pending event queues:
604         - gcvKERNEL_PIXEL
605         - gcvKERNEL_COMMAND (queue overflow)
606         - gcvKERNEL_PIXEL
607 */
608 #define gcdREPO_LIST_COUNT      3
609
610 /* gckEVENT object. */
611 struct _gckEVENT
612 {
613     /* The object. */
614     gcsOBJECT                   object;
615
616     /* Pointer to required objects. */
617     gckOS                       os;
618     gckKERNEL                   kernel;
619
620     /* Time stamp. */
621     gctUINT64                   stamp;
622     gctUINT64                   lastCommitStamp;
623
624     /* Queue mutex. */
625     gctPOINTER                  eventQueueMutex;
626
627     /* Array of event queues. */
628     gcsEVENT_QUEUE              queues[30];
629     gctUINT8                    lastID;
630     gctPOINTER                  freeAtom;
631
632     /* Pending events. */
633 #if gcdSMP
634     gctPOINTER                  pending;
635 #else
636     volatile gctUINT            pending;
637 #endif
638
639     /* List of free event structures and its mutex. */
640     gcsEVENT_PTR                freeEventList;
641     gctSIZE_T                   freeEventCount;
642     gctPOINTER                  freeEventMutex;
643
644     /* Event queues. */
645     gcsEVENT_QUEUE_PTR          queueHead;
646     gcsEVENT_QUEUE_PTR          queueTail;
647     gcsEVENT_QUEUE_PTR          freeList;
648     gcsEVENT_QUEUE              repoList[gcdREPO_LIST_COUNT];
649     gctPOINTER                  eventListMutex;
650
651     gctPOINTER                  submitTimer;
652 };
653
654 /* Free all events belonging to a process. */
655 gceSTATUS
656 gckEVENT_FreeProcess(
657     IN gckEVENT Event,
658     IN gctUINT32 ProcessID
659     );
660
661 gceSTATUS
662 gckEVENT_Stop(
663     IN gckEVENT Event,
664     IN gctUINT32 ProcessID,
665     IN gctPHYS_ADDR Handle,
666     IN gctPOINTER Logical,
667     IN gctSIGNAL Signal,
668         IN OUT gctSIZE_T * waitSize
669     );
670
671 /* gcuVIDMEM_NODE structure. */
672 typedef union _gcuVIDMEM_NODE
673 {
674     /* Allocated from gckVIDMEM. */
675     struct _gcsVIDMEM_NODE_VIDMEM
676     {
677         /* Owner of this node. */
678         gckVIDMEM               memory;
679
680         /* Dual-linked list of nodes. */
681         gcuVIDMEM_NODE_PTR      next;
682         gcuVIDMEM_NODE_PTR      prev;
683
684         /* Dual linked list of free nodes. */
685         gcuVIDMEM_NODE_PTR      nextFree;
686         gcuVIDMEM_NODE_PTR      prevFree;
687
688         /* Information for this node. */
689         gctUINT32               offset;
690         gctSIZE_T               bytes;
691         gctUINT32               alignment;
692
693 #ifdef __QNXNTO__
694         /* Client/server vaddr (mapped using mmap_join). */
695         gctPOINTER              logical;
696 #endif
697
698         /* Locked counter. */
699         gctINT32                locked;
700
701         /* Memory pool. */
702         gcePOOL                 pool;
703         gctUINT32               physical;
704
705         /* Process ID owning this memory. */
706         gctUINT32               processID;
707
708         /* Prevent compositor from freeing until client unlocks. */
709         gctBOOL                 freePending;
710
711         /* */
712         gcsVIDMEM_NODE_SHARED_INFO sharedInfo;
713
714 #if gcdDYNAMIC_MAP_RESERVED_MEMORY && gcdENABLE_VG
715         gctPOINTER              kernelVirtual;
716 #endif
717     }
718     VidMem;
719
720     /* Allocated from gckOS. */
721     struct _gcsVIDMEM_NODE_VIRTUAL
722     {
723         /* Pointer to gckKERNEL object. */
724         gckKERNEL               kernel;
725
726         /* Information for this node. */
727         /* Contiguously allocated? */
728         gctBOOL                 contiguous;
729         /* mdl record pointer... a kmalloc address. Process agnostic. */
730         gctPHYS_ADDR            physical;
731         gctSIZE_T               bytes;
732         /* do_mmap_pgoff address... mapped per-process. */
733         gctPOINTER              logical;
734
735         /* Page table information. */
736         /* Used only when node is not contiguous */
737         gctSIZE_T               pageCount;
738
739         /* Used only when node is not contiguous */
740         gctPOINTER              pageTables[gcdMAX_GPU_COUNT];
741         /* Pointer to gckKERNEL object who lock this. */
742         gckKERNEL               lockKernels[gcdMAX_GPU_COUNT];
743         /* Actual physical address */
744         gctUINT32               addresses[gcdMAX_GPU_COUNT];
745
746         /* Mutex. */
747         gctPOINTER              mutex;
748
749         /* Locked counter. */
750         gctINT32                lockeds[gcdMAX_GPU_COUNT];
751
752 #ifdef __QNXNTO__
753         /* Single linked list of nodes. */
754         gcuVIDMEM_NODE_PTR      next;
755
756         /* Unlock pending flag. */
757         gctBOOL                 unlockPendings[gcdMAX_GPU_COUNT];
758
759         /* Free pending flag. */
760         gctBOOL                 freePending;
761 #endif
762
763         /* Process ID owning this memory. */
764         gctUINT32               processID;
765
766         /* Owner process sets freed to true
767          * when it trys to free a locked
768          * node */
769         gctBOOL                 freed;
770
771         /* */
772         gcsVIDMEM_NODE_SHARED_INFO sharedInfo;
773     }
774     Virtual;
775 }
776 gcuVIDMEM_NODE;
777
778 /* gckVIDMEM object. */
779 struct _gckVIDMEM
780 {
781     /* Object. */
782     gcsOBJECT                   object;
783
784     /* Pointer to gckOS object. */
785     gckOS                       os;
786
787     /* Information for this video memory heap. */
788     gctUINT32                   baseAddress;
789     gctSIZE_T                   bytes;
790     gctSIZE_T                   freeBytes;
791
792     /* Mapping for each type of surface. */
793     gctINT                      mapping[gcvSURF_NUM_TYPES];
794
795     /* Sentinel nodes for up to 8 banks. */
796     gcuVIDMEM_NODE              sentinel[8];
797
798     /* Allocation threshold. */
799     gctSIZE_T                   threshold;
800
801     /* The heap mutex. */
802     gctPOINTER                  mutex;
803
804 #if gcdUSE_VIDMEM_PER_PID
805     /* The Pid this VidMem belongs to. */
806     gctUINT32                   pid;
807
808     struct _gckVIDMEM*          next;
809 #endif
810 };
811
812 /* gckMMU object. */
813 struct _gckMMU
814 {
815     /* The object. */
816     gcsOBJECT                   object;
817
818     /* Pointer to gckOS object. */
819     gckOS                       os;
820
821     /* Pointer to gckHARDWARE object. */
822     gckHARDWARE                 hardware;
823
824     /* The page table mutex. */
825     gctPOINTER                  pageTableMutex;
826
827     /* Page table information. */
828     gctSIZE_T                   pageTableSize;
829     gctPHYS_ADDR                pageTablePhysical;
830     gctUINT32_PTR               pageTableLogical;
831     gctUINT32                   pageTableEntries;
832
833     /* Master TLB information. */
834     gctSIZE_T                   mtlbSize;
835     gctPHYS_ADDR                mtlbPhysical;
836     gctUINT32_PTR               mtlbLogical;
837     gctUINT32                   mtlbEntries;
838
839     /* Free entries. */
840     gctUINT32                   heapList;
841     gctBOOL                     freeNodes;
842
843     gctPOINTER                  staticSTLB;
844     gctBOOL                     enabled;
845
846     gctUINT32                   dynamicMappingStart;
847
848 #ifdef __QNXNTO__
849     /* Single linked list of all allocated nodes. */
850     gctPOINTER                  nodeMutex;
851     gcuVIDMEM_NODE_PTR          nodeList;
852 #endif
853 };
854
855 #if gcdVIRTUAL_COMMAND_BUFFER
856 gceSTATUS
857 gckOS_CreateKernelVirtualMapping(
858     IN gctPHYS_ADDR Physical,
859     OUT gctSIZE_T * PageCount,
860     OUT gctPOINTER * Logical
861     );
862
863 gceSTATUS
864 gckOS_DestroyKernelVirtualMapping(
865     IN gctPOINTER Logical
866     );
867
868 gceSTATUS
869 gckKERNEL_AllocateVirtualCommandBuffer(
870     IN gckKERNEL Kernel,
871     IN gctBOOL InUserSpace,
872     IN OUT gctSIZE_T * Bytes,
873     OUT gctPHYS_ADDR * Physical,
874     OUT gctPOINTER * Logical
875     );
876
877 gceSTATUS
878 gckKERNEL_DestroyVirtualCommandBuffer(
879     IN gckKERNEL Kernel,
880     IN gctSIZE_T Bytes,
881     IN gctPHYS_ADDR Physical,
882     IN gctPOINTER Logical
883     );
884
885 gceSTATUS
886 gckKERNEL_GetGPUAddress(
887     IN gckKERNEL Kernel,
888     IN gctPOINTER Logical,
889     OUT gctUINT32 * Address
890     );
891
892 gceSTATUS
893 gckKERNEL_QueryGPUAddress(
894     IN gckKERNEL Kernel,
895     IN gctUINT32 GpuAddress,
896     OUT gckVIRTUAL_COMMAND_BUFFER_PTR * Buffer
897     );
898 #endif
899
900 gceSTATUS
901 gckKERNEL_AttachProcess(
902     IN gckKERNEL Kernel,
903     IN gctBOOL Attach
904     );
905
906 gceSTATUS
907 gckKERNEL_AttachProcessEx(
908     IN gckKERNEL Kernel,
909     IN gctBOOL Attach,
910     IN gctUINT32 PID
911     );
912
913 #if gcdSECURE_USER
914 gceSTATUS
915 gckKERNEL_MapLogicalToPhysical(
916     IN gckKERNEL Kernel,
917     IN gcskSECURE_CACHE_PTR Cache,
918     IN OUT gctPOINTER * Data
919     );
920
921 gceSTATUS
922 gckKERNEL_FlushTranslationCache(
923     IN gckKERNEL Kernel,
924     IN gcskSECURE_CACHE_PTR Cache,
925     IN gctPOINTER Logical,
926     IN gctSIZE_T Bytes
927     );
928 #endif
929
930 gceSTATUS
931 gckHARDWARE_QueryIdle(
932     IN gckHARDWARE Hardware,
933     OUT gctBOOL_PTR IsIdle
934     );
935
936 /******************************************************************************\
937 ******************************* gckCONTEXT Object *******************************
938 \******************************************************************************/
939
940 gceSTATUS
941 gckCONTEXT_Construct(
942     IN gckOS Os,
943     IN gckHARDWARE Hardware,
944     IN gctUINT32 ProcessID,
945     OUT gckCONTEXT * Context
946     );
947
948 gceSTATUS
949 gckCONTEXT_Destroy(
950     IN gckCONTEXT Context
951     );
952
953 gceSTATUS
954 gckCONTEXT_Update(
955     IN gckCONTEXT Context,
956     IN gctUINT32 ProcessID,
957     IN gcsSTATE_DELTA_PTR StateDelta
958     );
959
960 #if gcdLINK_QUEUE_SIZE
961 void
962 gckLINKQUEUE_Enqueue(
963     IN gckLINKQUEUE LinkQueue,
964     IN gctUINT32 start,
965     IN gctUINT32 end
966     );
967
968 void
969 gckLINKQUEUE_GetData(
970     IN gckLINKQUEUE LinkQueue,
971     IN gctUINT32 Index,
972     OUT gckLINKDATA * Data
973     );
974 #endif
975
976
977 #ifdef __cplusplus
978 }
979 #endif
980
981 #endif /* __gc_hal_kernel_h_ */