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_
28 #include "gc_hal_kernel_hardware.h"
29 #include "gc_hal_driver.h"
32 #include "gc_hal_kernel_vg.h"
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. */
54 /* DMAable address. */
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
;
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
;
69 #if gcdSECURE_CACHE_METHOD == gcdSECURE_CACHE_LINEAR
75 typedef struct _gcskSECURE_CACHE
* gcskSECURE_CACHE_PTR
;
76 typedef struct _gcskSECURE_CACHE
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. */
87 /* Time stamp for LINEAR mode. */
90 #if gcdSECURE_CACHE_METHOD == gcdSECURE_CACHE_HASH
91 /* Hash table for HASH mode. */
92 gcskLOGICAL_CACHE hash
[256];
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 */
115 typedef struct _gcsDATABASE_RECORD
* gcsDATABASE_RECORD_PTR
;
116 typedef struct _gcsDATABASE_RECORD
118 /* Pointer to kernel. */
121 /* Pointer to next database record. */
122 gcsDATABASE_RECORD_PTR next
;
124 /* Type of record. */
125 gceDATABASE_TYPE type
;
127 /* Data for record. */
129 gctPHYS_ADDR physical
;
134 typedef struct _gcsDATABASE
* gcsDATABASE_PTR
;
135 typedef struct _gcsDATABASE
137 /* Pointer to next entry is hash list. */
138 gcsDATABASE_PTR next
;
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. */
155 /* Pointer to database. */
156 gcsDATABASE_RECORD_PTR list
;
160 gcskSECURE_CACHE cache
;
165 /* Create a process database that will contain all its allocations. */
167 gckKERNEL_CreateProcessDB(
169 IN gctUINT32 ProcessID
172 /* Add a record to the process database. */
174 gckKERNEL_AddProcessDB(
176 IN gctUINT32 ProcessID
,
177 IN gceDATABASE_TYPE Type
,
178 IN gctPOINTER Pointer
,
179 IN gctPHYS_ADDR Physical
,
183 /* Remove a record to the process database. */
185 gckKERNEL_RemoveProcessDB(
187 IN gctUINT32 ProcessID
,
188 IN gceDATABASE_TYPE Type
,
189 IN gctPOINTER Pointer
192 /* Destroy the process database. */
194 gckKERNEL_DestroyProcessDB(
196 IN gctUINT32 ProcessID
199 /* Find a record to the process database. */
201 gckKERNEL_FindProcessDB(
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. */
212 gckKERNEL_QueryProcessDB(
214 IN gctUINT32 ProcessID
,
215 IN gctBOOL LastProcessID
,
216 IN gceDATABASE_TYPE Type
,
217 OUT gcuDATABASE_INFO
* Info
221 /* Get secure cache from the process database. */
223 gckKERNEL_GetProcessDBCache(
225 IN gctUINT32 ProcessID
,
226 OUT gcskSECURE_CACHE_PTR
* Cache
230 /*******************************************************************************
231 ********* Timer Management ****************************************************/
232 typedef struct _gcsTIMER
* gcsTIMER_PTR
;
233 typedef struct _gcsTIMER
235 /* Start and Stop time holders. */
241 /******************************************************************************\
242 ********************************** Structures **********************************
243 \******************************************************************************/
248 /* Database management. */
249 gcsDATABASE_PTR db
[16];
251 gcsDATABASE_PTR freeDatabase
;
252 gcsDATABASE_RECORD_PTR freeRecord
;
253 gcsDATABASE_PTR lastDatabase
;
254 gctUINT32 lastProcessID
;
257 gctUINT64 lastSlowdown
;
258 gctUINT64 lastSlowdownIdle
;
261 /* gckKERNEL object. */
267 /* Pointer to gckOS object. */
273 /* Pointer to gckHARDWARE object. */
274 gckHARDWARE hardware
;
276 /* Pointer to gckCOMMAND object. */
279 /* Pointer to gckEVENT object. */
282 /* Pointer to context. */
285 /* Pointer to gckMMU object. */
288 /* Arom holding number of clients. */
289 gctPOINTER atomClients
;
292 /* Enable profiling */
293 gctBOOL profileEnable
;
295 /* The profile file name */
296 gctCHAR profileFileName
[gcdMAX_PROFILE_FILE_NAME
];
299 #ifdef QNX_SINGLE_THREADED_DEBUGGING
300 gctPOINTER debugMutex
;
303 /* Database management. */
307 /* Pointer to gckEVENT object. */
316 /* gckCOMMAND object. */
322 /* Pointer to required object. */
326 /* Number of bytes per page. */
329 /* Current pipe select. */
330 gcePIPE_SELECT pipeSelect
;
332 /* Command queue running flag. */
335 /* Idle flag and commit stamp. */
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
352 gctPHYS_ADDR physical
;
355 queues
[gcdCOMMAND_QUEUES
];
357 gctPHYS_ADDR physical
;
361 #if gcmIS_DEBUG(gcdDEBUG_TRACE)
365 /* The command queue is new. */
368 /* Context management. */
369 gckCONTEXT currContext
;
371 /* Pointer to last WAIT command. */
372 gctPHYS_ADDR waitPhysical
;
373 gctPOINTER waitLogical
;
376 /* Command buffer 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
;
391 /* Hint array copy buffer. */
392 gctBOOL hintArrayAllocated
;
393 gctUINT hintArraySize
;
394 gctUINT32_PTR hintArray
;
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. */
406 /* Event information. */
407 gcsHAL_INTERFACE info
;
409 /* Process ID owning the event. */
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
426 /* Source of the event. */
427 gceKERNEL_WHERE source
;
429 /* Pointer to head of event queue. */
432 /* Pointer to tail of event queue. */
435 /* Next list of events. */
436 gcsEVENT_QUEUE_PTR next
;
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:
449 - gcvKERNEL_COMMAND (queue overflow)
452 #define gcdREPO_LIST_COUNT 3
454 /* gckEVENT object. */
460 /* Pointer to required objects. */
466 gctUINT64 lastCommitStamp
;
469 gctPOINTER eventQueueMutex
;
471 /* Array of event queues. */
472 gcsEVENT_QUEUE queues
[31];
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
;
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. */
494 gckEVENT_FreeProcess(
496 IN gctUINT32 ProcessID
502 IN gctUINT32 ProcessID
,
503 IN gctPHYS_ADDR Handle
,
504 IN gctPOINTER Logical
,
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. */
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. */
532 /* Client/server vaddr (mapped using mmap_join). */
536 /* Locked counter. */
543 /* Process ID owning this memory. */
546 /* Prevent compositor from freeing until client unlocks. */
550 gcsVIDMEM_NODE_SHARED_INFO sharedInfo
;
554 /* Allocated from gckOS. */
555 struct _gcsVIDMEM_NODE_VIRTUAL
557 /* Pointer to gckKERNEL object. */
560 /* Information for this node. */
561 /* Contiguously allocated? */
563 /* mdl record pointer... a kmalloc address. Process agnostic. */
564 gctPHYS_ADDR physical
;
566 /* do_mmap_pgoff address... mapped per-process. */
569 /* Page table information. */
570 /* Used only when node is not contiguous */
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
];
583 /* Locked counter. */
584 gctINT32 lockeds
[gcdCORE_COUNT
];
587 /* Single linked list of nodes. */
588 gcuVIDMEM_NODE_PTR next
;
590 /* Unlock pending flag. */
591 gctBOOL unlockPendings
[gcdCORE_COUNT
];
593 /* Free pending flag. */
597 /* Process ID owning this memory. */
600 /* Owner process sets freed to true
601 * when it trys to free a locked
606 gcsVIDMEM_NODE_SHARED_INFO sharedInfo
;
612 /* gckVIDMEM object. */
618 /* Pointer to gckOS object. */
621 /* Information for this video memory heap. */
622 gctUINT32 baseAddress
;
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. */
635 /* The heap mutex. */
638 #if gcdUSE_VIDMEM_PER_PID
639 /* The Pid this VidMem belongs to. */
642 struct _gckVIDMEM
* next
;
652 /* Pointer to gckOS object. */
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
;
671 gctPOINTER staticSTLB
;
675 /* Single linked list of all allocated nodes. */
676 gctPOINTER nodeMutex
;
677 gcuVIDMEM_NODE_PTR nodeList
;
682 gckKERNEL_AttachProcess(
688 gckKERNEL_AttachProcessEx(
696 gckKERNEL_MapLogicalToPhysical(
698 IN gcskSECURE_CACHE_PTR Cache
,
699 IN OUT gctPOINTER
* Data
703 gckKERNEL_FlushTranslationCache(
705 IN gcskSECURE_CACHE_PTR Cache
,
706 IN gctPOINTER Logical
,
712 gckHARDWARE_QueryIdle(
713 IN gckHARDWARE Hardware
,
714 OUT gctBOOL_PTR IsIdle
717 /******************************************************************************\
718 ******************************* gckCONTEXT Object *******************************
719 \******************************************************************************/
722 gckCONTEXT_Construct(
724 IN gckHARDWARE Hardware
,
725 IN gctUINT32 ProcessID
,
726 OUT gckCONTEXT
* Context
731 IN gckCONTEXT Context
736 IN gckCONTEXT Context
,
737 IN gctUINT32 ProcessID
,
738 IN gcsSTATE_DELTA_PTR StateDelta
745 #endif /* __gc_hal_kernel_h_ */