ENGR00156850 gpu-viv: add gpu-viv driver source
[wandboard.git] / drivers / mxc / gpu-viv / hal / kernel / gc_hal_kernel.h
blobbd701b7b9af63642a9db57a0e6fe8034cb5825ea
1 /****************************************************************************
3 * Copyright (C) 2005 - 2011 by Vivante Corp.
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.
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.
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.
19 *****************************************************************************/
24 #ifndef __gc_hal_kernel_h_
25 #define __gc_hal_kernel_h_
27 #include "gc_hal.h"
28 #include "gc_hal_kernel_hardware.h"
29 #include "gc_hal_driver.h"
31 #if gcdENABLE_VG
32 #include "gc_hal_kernel_vg.h"
33 #endif
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
39 /*******************************************************************************
40 ***** Process Secure Cache ****************************************************/
42 #define gcdSECURE_CACHE_LRU 1
43 #define gcdSECURE_CACHE_LINEAR 2
44 #define gcdSECURE_CACHE_HASH 3
45 #define gcdSECURE_CACHE_TABLE 4
47 typedef struct _gcskLOGICAL_CACHE * gcskLOGICAL_CACHE_PTR;
48 typedef struct _gcskLOGICAL_CACHE gcskLOGICAL_CACHE;
49 struct _gcskLOGICAL_CACHE
51 /* Logical address. */
52 gctPOINTER logical;
54 /* DMAable address. */
55 gctUINT32 dma;
57 #if gcdSECURE_CACHE_METHOD == gcdSECURE_CACHE_HASH
58 /* Pointer to the previous and next hash tables. */
59 gcskLOGICAL_CACHE_PTR nextHash;
60 gcskLOGICAL_CACHE_PTR prevHash;
61 #endif
63 #if gcdSECURE_CACHE_METHOD != gcdSECURE_CACHE_TABLE
64 /* Pointer to the previous and next slot. */
65 gcskLOGICAL_CACHE_PTR next;
66 gcskLOGICAL_CACHE_PTR prev;
67 #endif
69 #if gcdSECURE_CACHE_METHOD == gcdSECURE_CACHE_LINEAR
70 /* Time stamp. */
71 gctUINT64 stamp;
72 #endif
75 typedef struct _gcskSECURE_CACHE * gcskSECURE_CACHE_PTR;
76 typedef struct _gcskSECURE_CACHE
78 /* Cache memory. */
79 gcskLOGICAL_CACHE cache[1 + gcdSECURE_CACHE_SLOTS];
81 /* Last known index for LINEAR mode. */
82 gcskLOGICAL_CACHE_PTR cacheIndex;
84 /* Current free slot for LINEAR mode. */
85 gctUINT32 cacheFree;
87 /* Time stamp for LINEAR mode. */
88 gctUINT64 cacheStamp;
90 #if gcdSECURE_CACHE_METHOD == gcdSECURE_CACHE_HASH
91 /* Hash table for HASH mode. */
92 gcskLOGICAL_CACHE hash[256];
93 #endif
95 gcskSECURE_CACHE;
97 /*******************************************************************************
98 ***** Process Database Management *********************************************/
100 typedef enum _gceDATABASE_TYPE
102 gcvDB_VIDEO_MEMORY = 1, /* Video memory created. */
103 gcvDB_NON_PAGED, /* Non paged memory. */
104 gcvDB_CONTIGUOUS, /* Contiguous memory. */
105 gcvDB_SIGNAL, /* Signal. */
106 gcvDB_VIDEO_MEMORY_LOCKED, /* Video memory locked. */
107 gcvDB_CONTEXT, /* Context */
108 gcvDB_IDLE, /* GPU idle. */
109 gcvDB_MAP_MEMORY, /* Map memory */
110 gcvDB_SHARED_INFO, /* Private data */
111 gcvDB_MAP_USER_MEMORY /* Map user memory */
113 gceDATABASE_TYPE;
115 typedef struct _gcsDATABASE_RECORD * gcsDATABASE_RECORD_PTR;
116 typedef struct _gcsDATABASE_RECORD
118 /* Pointer to kernel. */
119 gckKERNEL kernel;
121 /* Pointer to next database record. */
122 gcsDATABASE_RECORD_PTR next;
124 /* Type of record. */
125 gceDATABASE_TYPE type;
127 /* Data for record. */
128 gctPOINTER data;
129 gctPHYS_ADDR physical;
130 gctSIZE_T bytes;
132 gcsDATABASE_RECORD;
134 typedef struct _gcsDATABASE * gcsDATABASE_PTR;
135 typedef struct _gcsDATABASE
137 /* Pointer to next entry is hash list. */
138 gcsDATABASE_PTR next;
139 gctSIZE_T slot;
141 /* Process ID. */
142 gctUINT32 processID;
144 /* Sizes to query. */
145 gcsDATABASE_COUNTERS vidMem;
146 gcsDATABASE_COUNTERS nonPaged;
147 gcsDATABASE_COUNTERS contiguous;
148 gcsDATABASE_COUNTERS mapUserMemory;
149 gcsDATABASE_COUNTERS mapMemory;
151 /* Idle time management. */
152 gctUINT64 lastIdle;
153 gctUINT64 idle;
155 /* Pointer to database. */
156 gcsDATABASE_RECORD_PTR list;
158 #if gcdSECURE_USER
159 /* Secure cache. */
160 gcskSECURE_CACHE cache;
161 #endif
163 gcsDATABASE;
165 /* Create a process database that will contain all its allocations. */
166 gceSTATUS
167 gckKERNEL_CreateProcessDB(
168 IN gckKERNEL Kernel,
169 IN gctUINT32 ProcessID
172 /* Add a record to the process database. */
173 gceSTATUS
174 gckKERNEL_AddProcessDB(
175 IN gckKERNEL Kernel,
176 IN gctUINT32 ProcessID,
177 IN gceDATABASE_TYPE Type,
178 IN gctPOINTER Pointer,
179 IN gctPHYS_ADDR Physical,
180 IN gctSIZE_T Size
183 /* Remove a record to the process database. */
184 gceSTATUS
185 gckKERNEL_RemoveProcessDB(
186 IN gckKERNEL Kernel,
187 IN gctUINT32 ProcessID,
188 IN gceDATABASE_TYPE Type,
189 IN gctPOINTER Pointer
192 /* Destroy the process database. */
193 gceSTATUS
194 gckKERNEL_DestroyProcessDB(
195 IN gckKERNEL Kernel,
196 IN gctUINT32 ProcessID
199 /* Find a record to the process database. */
200 gceSTATUS
201 gckKERNEL_FindProcessDB(
202 IN gckKERNEL Kernel,
203 IN gctUINT32 ProcessID,
204 IN gctUINT32 ThreadID,
205 IN gceDATABASE_TYPE Type,
206 IN gctPOINTER Pointer,
207 OUT gcsDATABASE_RECORD_PTR Record
210 /* Query the process database. */
211 gceSTATUS
212 gckKERNEL_QueryProcessDB(
213 IN gckKERNEL Kernel,
214 IN gctUINT32 ProcessID,
215 IN gctBOOL LastProcessID,
216 IN gceDATABASE_TYPE Type,
217 OUT gcuDATABASE_INFO * Info
220 #if gcdSECURE_USER
221 /* Get secure cache from the process database. */
222 gceSTATUS
223 gckKERNEL_GetProcessDBCache(
224 IN gckKERNEL Kernel,
225 IN gctUINT32 ProcessID,
226 OUT gcskSECURE_CACHE_PTR * Cache
228 #endif
230 /*******************************************************************************
231 ********* Timer Management ****************************************************/
232 typedef struct _gcsTIMER * gcsTIMER_PTR;
233 typedef struct _gcsTIMER
235 /* Start and Stop time holders. */
236 gctUINT64 startTime;
237 gctUINT64 stopTime;
239 gcsTIMER;
241 /******************************************************************************\
242 ********************************** Structures **********************************
243 \******************************************************************************/
245 /* gckDB object. */
246 struct _gckDB
248 /* Database management. */
249 gcsDATABASE_PTR db[16];
250 gctPOINTER dbMutex;
251 gcsDATABASE_PTR freeDatabase;
252 gcsDATABASE_RECORD_PTR freeRecord;
253 gcsDATABASE_PTR lastDatabase;
254 gctUINT32 lastProcessID;
255 gctUINT64 lastIdle;
256 gctUINT64 idleTime;
257 gctUINT64 lastSlowdown;
258 gctUINT64 lastSlowdownIdle;
261 /* gckKERNEL object. */
262 struct _gckKERNEL
264 /* Object. */
265 gcsOBJECT object;
267 /* Pointer to gckOS object. */
268 gckOS os;
270 /* Core */
271 gceCORE core;
273 /* Pointer to gckHARDWARE object. */
274 gckHARDWARE hardware;
276 /* Pointer to gckCOMMAND object. */
277 gckCOMMAND command;
279 /* Pointer to gckEVENT object. */
280 gckEVENT eventObj;
282 /* Pointer to context. */
283 gctPOINTER context;
285 /* Pointer to gckMMU object. */
286 gckMMU mmu;
288 /* Arom holding number of clients. */
289 gctPOINTER atomClients;
291 #if VIVANTE_PROFILER
292 /* Enable profiling */
293 gctBOOL profileEnable;
295 /* The profile file name */
296 gctCHAR profileFileName[gcdMAX_PROFILE_FILE_NAME];
297 #endif
299 #ifdef QNX_SINGLE_THREADED_DEBUGGING
300 gctPOINTER debugMutex;
301 #endif
303 /* Database management. */
304 gckDB db;
305 gctBOOL dbCreated;
307 /* Pointer to gckEVENT object. */
308 gcsTIMER timers[8];
309 gctUINT32 timeOut;
311 #if gcdENABLE_VG
312 gckVGKERNEL vg;
313 #endif
316 /* gckCOMMAND object. */
317 struct _gckCOMMAND
319 /* Object. */
320 gcsOBJECT object;
322 /* Pointer to required object. */
323 gckKERNEL kernel;
324 gckOS os;
326 /* Number of bytes per page. */
327 gctSIZE_T pageSize;
329 /* Current pipe select. */
330 gcePIPE_SELECT pipeSelect;
332 /* Command queue running flag. */
333 gctBOOL running;
335 /* Idle flag and commit stamp. */
336 gctBOOL idle;
337 gctUINT64 commitStamp;
339 /* Command queue mutex. */
340 gctPOINTER mutexQueue;
342 /* Context switching mutex. */
343 gctPOINTER mutexContext;
345 /* Command queue power semaphore. */
346 gctPOINTER powerSemaphore;
348 /* Current command queue. */
349 struct _gcskCOMMAND_QUEUE
351 gctSIGNAL signal;
352 gctPHYS_ADDR physical;
353 gctPOINTER logical;
355 queues[gcdCOMMAND_QUEUES];
357 gctPHYS_ADDR physical;
358 gctPOINTER logical;
359 gctUINT32 offset;
360 gctINT index;
361 #if gcmIS_DEBUG(gcdDEBUG_TRACE)
362 gctUINT wrapCount;
363 #endif
365 /* The command queue is new. */
366 gctBOOL newQueue;
368 /* Context management. */
369 gckCONTEXT currContext;
371 /* Pointer to last WAIT command. */
372 gctPHYS_ADDR waitPhysical;
373 gctPOINTER waitLogical;
374 gctSIZE_T waitSize;
376 /* Command buffer alignment. */
377 gctSIZE_T alignment;
378 gctSIZE_T reservedHead;
379 gctSIZE_T reservedTail;
381 /* Commit counter. */
382 gctPOINTER atomCommit;
384 /* Kernel process ID. */
385 gctUINT32 kernelProcessID;
387 /* End Event signal. */
388 gctSIGNAL endEventSignal;
390 #if gcdSECURE_USER
391 /* Hint array copy buffer. */
392 gctBOOL hintArrayAllocated;
393 gctUINT hintArraySize;
394 gctUINT32_PTR hintArray;
395 #endif
398 typedef struct _gcsEVENT * gcsEVENT_PTR;
400 /* Structure holding one event to be processed. */
401 typedef struct _gcsEVENT
403 /* Pointer to next event in queue. */
404 gcsEVENT_PTR next;
406 /* Event information. */
407 gcsHAL_INTERFACE info;
409 /* Process ID owning the event. */
410 gctUINT32 processID;
412 #ifdef __QNXNTO__
413 /* Kernel. */
414 gckKERNEL kernel;
415 #endif
417 gcsEVENT;
419 /* Structure holding a list of events to be processed by an interrupt. */
420 typedef struct _gcsEVENT_QUEUE * gcsEVENT_QUEUE_PTR;
421 typedef struct _gcsEVENT_QUEUE
423 /* Time stamp. */
424 gctUINT64 stamp;
426 /* Source of the event. */
427 gceKERNEL_WHERE source;
429 /* Pointer to head of event queue. */
430 gcsEVENT_PTR head;
432 /* Pointer to tail of event queue. */
433 gcsEVENT_PTR tail;
435 /* Next list of events. */
436 gcsEVENT_QUEUE_PTR next;
438 gcsEVENT_QUEUE;
441 gcdREPO_LIST_COUNT defines the maximum number of event queues with different
442 hardware module sources that may coexist at the same time. Only two sources
443 are supported - gcvKERNEL_COMMAND and gcvKERNEL_PIXEL. gcvKERNEL_COMMAND
444 source is used only for managing the kernel command queue and is only issued
445 when the current command queue gets full. Since we commit event queues every
446 time we commit command buffers, in the worst case we can have up to three
447 pending event queues:
448 - gcvKERNEL_PIXEL
449 - gcvKERNEL_COMMAND (queue overflow)
450 - gcvKERNEL_PIXEL
452 #define gcdREPO_LIST_COUNT 3
454 /* gckEVENT object. */
455 struct _gckEVENT
457 /* The object. */
458 gcsOBJECT object;
460 /* Pointer to required objects. */
461 gckOS os;
462 gckKERNEL kernel;
464 /* Time stamp. */
465 gctUINT64 stamp;
466 gctUINT64 lastCommitStamp;
468 /* Queue mutex. */
469 gctPOINTER eventQueueMutex;
471 /* Array of event queues. */
472 gcsEVENT_QUEUE queues[31];
473 gctUINT8 lastID;
474 gctPOINTER freeAtom;
476 /* Pending events. */
477 volatile gctUINT pending;
479 /* List of free event structures and its mutex. */
480 gcsEVENT_PTR freeEventList;
481 gctSIZE_T freeEventCount;
482 gctPOINTER freeEventMutex;
484 /* Event queues. */
485 gcsEVENT_QUEUE_PTR queueHead;
486 gcsEVENT_QUEUE_PTR queueTail;
487 gcsEVENT_QUEUE_PTR freeList;
488 gcsEVENT_QUEUE repoList[gcdREPO_LIST_COUNT];
489 gctPOINTER eventListMutex;
492 /* Free all events belonging to a process. */
493 gceSTATUS
494 gckEVENT_FreeProcess(
495 IN gckEVENT Event,
496 IN gctUINT32 ProcessID
499 gceSTATUS
500 gckEVENT_Stop(
501 IN gckEVENT Event,
502 IN gctUINT32 ProcessID,
503 IN gctPHYS_ADDR Handle,
504 IN gctPOINTER Logical,
505 IN gctSIGNAL Signal,
506 IN OUT gctSIZE_T * waitSize
509 /* gcuVIDMEM_NODE structure. */
510 typedef union _gcuVIDMEM_NODE
512 /* Allocated from gckVIDMEM. */
513 struct _gcsVIDMEM_NODE_VIDMEM
515 /* Owner of this node. */
516 gckVIDMEM memory;
518 /* Dual-linked list of nodes. */
519 gcuVIDMEM_NODE_PTR next;
520 gcuVIDMEM_NODE_PTR prev;
522 /* Dual linked list of free nodes. */
523 gcuVIDMEM_NODE_PTR nextFree;
524 gcuVIDMEM_NODE_PTR prevFree;
526 /* Information for this node. */
527 gctUINT32 offset;
528 gctSIZE_T bytes;
529 gctUINT32 alignment;
531 #ifdef __QNXNTO__
532 /* Client/server vaddr (mapped using mmap_join). */
533 gctPOINTER logical;
534 #endif
536 /* Locked counter. */
537 gctINT32 locked;
539 /* Memory pool. */
540 gcePOOL pool;
541 gctUINT32 physical;
543 /* Process ID owning this memory. */
544 gctUINT32 processID;
546 /* Prevent compositor from freeing until client unlocks. */
547 gctBOOL freePending;
549 /* */
550 gcsVIDMEM_NODE_SHARED_INFO sharedInfo;
552 VidMem;
554 /* Allocated from gckOS. */
555 struct _gcsVIDMEM_NODE_VIRTUAL
557 /* Pointer to gckKERNEL object. */
558 gckKERNEL kernel;
560 /* Information for this node. */
561 /* Contiguously allocated? */
562 gctBOOL contiguous;
563 /* mdl record pointer... a kmalloc address. Process agnostic. */
564 gctPHYS_ADDR physical;
565 gctSIZE_T bytes;
566 /* do_mmap_pgoff address... mapped per-process. */
567 gctPOINTER logical;
569 /* Page table information. */
570 /* Used only when node is not contiguous */
571 gctSIZE_T pageCount;
573 /* Used only when node is not contiguous */
574 gctPOINTER pageTables[gcdCORE_COUNT];
575 /* Pointer to gckKERNEL object who lock this. */
576 gckKERNEL lockKernels[gcdCORE_COUNT];
577 /* Actual physical address */
578 gctUINT32 addresses[gcdCORE_COUNT];
580 /* Mutex. */
581 gctPOINTER mutex;
583 /* Locked counter. */
584 gctINT32 lockeds[gcdCORE_COUNT];
586 #ifdef __QNXNTO__
587 /* Single linked list of nodes. */
588 gcuVIDMEM_NODE_PTR next;
590 /* Unlock pending flag. */
591 gctBOOL unlockPendings[gcdCORE_COUNT];
593 /* Free pending flag. */
594 gctBOOL freePending;
595 #endif
597 /* Process ID owning this memory. */
598 gctUINT32 processID;
600 /* Owner process sets freed to true
601 * when it trys to free a locked
602 * node */
603 gctBOOL freed;
605 /* */
606 gcsVIDMEM_NODE_SHARED_INFO sharedInfo;
608 Virtual;
610 gcuVIDMEM_NODE;
612 /* gckVIDMEM object. */
613 struct _gckVIDMEM
615 /* Object. */
616 gcsOBJECT object;
618 /* Pointer to gckOS object. */
619 gckOS os;
621 /* Information for this video memory heap. */
622 gctUINT32 baseAddress;
623 gctSIZE_T bytes;
624 gctSIZE_T freeBytes;
626 /* Mapping for each type of surface. */
627 gctINT mapping[gcvSURF_NUM_TYPES];
629 /* Sentinel nodes for up to 8 banks. */
630 gcuVIDMEM_NODE sentinel[8];
632 /* Allocation threshold. */
633 gctSIZE_T threshold;
635 /* The heap mutex. */
636 gctPOINTER mutex;
638 #if gcdUSE_VIDMEM_PER_PID
639 /* The Pid this VidMem belongs to. */
640 gctUINT32 pid;
642 struct _gckVIDMEM* next;
643 #endif
646 /* gckMMU object. */
647 struct _gckMMU
649 /* The object. */
650 gcsOBJECT object;
652 /* Pointer to gckOS object. */
653 gckOS os;
655 /* Pointer to gckHARDWARE object. */
656 gckHARDWARE hardware;
658 /* The page table mutex. */
659 gctPOINTER pageTableMutex;
661 /* Page table information. */
662 gctSIZE_T pageTableSize;
663 gctPHYS_ADDR pageTablePhysical;
664 gctUINT32_PTR pageTableLogical;
665 gctUINT32 pageTableEntries;
667 /* Free entries. */
668 gctUINT32 heapList;
669 gctBOOL freeNodes;
671 gctPOINTER staticSTLB;
672 gctBOOL enabled;
674 #ifdef __QNXNTO__
675 /* Single linked list of all allocated nodes. */
676 gctPOINTER nodeMutex;
677 gcuVIDMEM_NODE_PTR nodeList;
678 #endif
681 gceSTATUS
682 gckKERNEL_AttachProcess(
683 IN gckKERNEL Kernel,
684 IN gctBOOL Attach
687 gceSTATUS
688 gckKERNEL_AttachProcessEx(
689 IN gckKERNEL Kernel,
690 IN gctBOOL Attach,
691 IN gctUINT32 PID
694 #if gcdSECURE_USER
695 gceSTATUS
696 gckKERNEL_MapLogicalToPhysical(
697 IN gckKERNEL Kernel,
698 IN gcskSECURE_CACHE_PTR Cache,
699 IN OUT gctPOINTER * Data
702 gceSTATUS
703 gckKERNEL_FlushTranslationCache(
704 IN gckKERNEL Kernel,
705 IN gcskSECURE_CACHE_PTR Cache,
706 IN gctPOINTER Logical,
707 IN gctSIZE_T Bytes
709 #endif
711 gceSTATUS
712 gckHARDWARE_QueryIdle(
713 IN gckHARDWARE Hardware,
714 OUT gctBOOL_PTR IsIdle
717 /******************************************************************************\
718 ******************************* gckCONTEXT Object *******************************
719 \******************************************************************************/
721 gceSTATUS
722 gckCONTEXT_Construct(
723 IN gckOS Os,
724 IN gckHARDWARE Hardware,
725 IN gctUINT32 ProcessID,
726 OUT gckCONTEXT * Context
729 gceSTATUS
730 gckCONTEXT_Destroy(
731 IN gckCONTEXT Context
734 gceSTATUS
735 gckCONTEXT_Update(
736 IN gckCONTEXT Context,
737 IN gctUINT32 ProcessID,
738 IN gcsSTATE_DELTA_PTR StateDelta
741 #ifdef __cplusplus
743 #endif
745 #endif /* __gc_hal_kernel_h_ */