diff options
author | r80085 <thomas.peng@freescale.com> | 2010-07-19 18:00:16 -0500 |
---|---|---|
committer | r80085 <thomas.peng@freescale.com> | 2010-07-19 19:29:54 -0500 |
commit | 2b34200909be46c705414b43588eea070e7b7bee (patch) | |
tree | 0249648af8a697fe044c81589eee0f6dcde90bc7 | |
parent | e79cae38523757bcd33c89b1a4d7f67548ef9097 (diff) |
ENGR00125256 Integrate AMD Rc16/EA VG/GL fix to GPU kernel module
Fix the VG/GL issue in GPU kernel module when running VG/GL at the same time
Signed-off-by: Gene Chouiniere <Gene.Chouiniere@amd.com>
Signed-off-by: r80085 <thomas.peng@freescale.com>
Acked-by: Rob Herring <r.herring@freescale.com>
25 files changed, 517 insertions, 1040 deletions
diff --git a/drivers/mxc/amd-gpu/common/gsl_cmdstream.c b/drivers/mxc/amd-gpu/common/gsl_cmdstream.c index 3c587281427b..338192c7ba32 100644 --- a/drivers/mxc/amd-gpu/common/gsl_cmdstream.c +++ b/drivers/mxc/amd-gpu/common/gsl_cmdstream.c @@ -20,20 +20,6 @@ #include "gsl_hal.h" #include "gsl_cmdstream.h" -#ifdef GSL_LOCKING_FINEGRAIN -#define GSL_CMDSTREAM_MUTEX_CREATE() device->cmdstream_mutex = kos_mutex_create("gsl_cmdstream"); \ - if (!device->cmdstream_mutex) return (GSL_FAILURE); -#define GSL_CMDSTREAM_MUTEX_LOCK() kos_mutex_lock(device->cmdstream_mutex) -#define GSL_CMDSTREAM_MUTEX_UNLOCK() kos_mutex_unlock(device->cmdstream_mutex) -#define GSL_CMDSTREAM_MUTEX_FREE() kos_mutex_free(device->cmdstream_mutex); device->cmdstream_mutex = 0; -#else -#define GSL_CMDSTREAM_MUTEX_CREATE() (void) device // unreferenced formal parameter -#define GSL_CMDSTREAM_MUTEX_LOCK() -#define GSL_CMDSTREAM_MUTEX_UNLOCK() -#define GSL_CMDSTREAM_MUTEX_FREE() (void) device // unreferenced formal parameter -#endif - - ////////////////////////////////////////////////////////////////////////////// // functions ////////////////////////////////////////////////////////////////////////////// @@ -41,8 +27,6 @@ int kgsl_cmdstream_init(gsl_device_t *device) { - GSL_CMDSTREAM_MUTEX_CREATE(); - return GSL_SUCCESS; } @@ -51,29 +35,21 @@ kgsl_cmdstream_init(gsl_device_t *device) int kgsl_cmdstream_close(gsl_device_t *device) { - GSL_CMDSTREAM_MUTEX_FREE(); - return GSL_SUCCESS; } //---------------------------------------------------------------------------- -KGSL_API gsl_timestamp_t -kgsl_cmdstream_readtimestamp(gsl_deviceid_t device_id, gsl_timestamp_type_t type) +gsl_timestamp_t +kgsl_cmdstream_readtimestamp0(gsl_deviceid_t device_id, gsl_timestamp_type_t type) { gsl_timestamp_t timestamp = -1; gsl_device_t* device = &gsl_driver.device[device_id-1]; - kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_TRACE, "--> gsl_timestamp_t kgsl_cmdstream_readtimestamp(gsl_deviceid_t device_id=%d gsl_timestamp_type_t type=%d)\n", device_id, type ); - - GSL_API_MUTEX_LOCK(); - #if (defined(GSL_BLD_G12) && defined(IRQTHREAD_POLL)) kos_event_signal(device->irqthread_event); #endif - - if (type == GSL_TIMESTAMP_CONSUMED) { // start-of-pipeline timestamp @@ -81,38 +57,40 @@ kgsl_cmdstream_readtimestamp(gsl_deviceid_t device_id, gsl_timestamp_type_t type } else if (type == GSL_TIMESTAMP_RETIRED) { - // end-of-pipeline timestamp - GSL_CMDSTREAM_GET_EOP_TIMESTAMP(device, (unsigned int*)×tamp); - } - - GSL_API_MUTEX_UNLOCK(); - + // end-of-pipeline timestamp + GSL_CMDSTREAM_GET_EOP_TIMESTAMP(device, (unsigned int*)×tamp); + } kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_ringbuffer_readtimestamp. Return value %d\n", timestamp ); - return (timestamp); } //---------------------------------------------------------------------------- +KGSL_API gsl_timestamp_t +kgsl_cmdstream_readtimestamp(gsl_deviceid_t device_id, gsl_timestamp_type_t type) +{ + gsl_timestamp_t timestamp = -1; + GSL_API_MUTEX_LOCK(); + timestamp = kgsl_cmdstream_readtimestamp0(device_id, type); + GSL_API_MUTEX_UNLOCK(); + return timestamp; +} + +//---------------------------------------------------------------------------- + KGSL_API int kgsl_cmdstream_issueibcmds(gsl_deviceid_t device_id, int drawctxt_index, gpuaddr_t ibaddr, int sizedwords, gsl_timestamp_t *timestamp, unsigned int flags) { gsl_device_t* device = &gsl_driver.device[device_id-1]; - int status; - + int status = GSL_FAILURE; GSL_API_MUTEX_LOCK(); - + kgsl_device_active(device); - + if (device->ftbl.cmdstream_issueibcmds) { status = device->ftbl.cmdstream_issueibcmds(device, drawctxt_index, ibaddr, sizedwords, timestamp, flags); } - else - { - status = GSL_FAILURE; - } - GSL_API_MUTEX_UNLOCK(); return status; } @@ -123,19 +101,12 @@ KGSL_API int kgsl_add_timestamp(gsl_deviceid_t device_id, gsl_timestamp_t *timestamp) { gsl_device_t* device = &gsl_driver.device[device_id-1]; - int status; - + int status = GSL_FAILURE; GSL_API_MUTEX_LOCK(); - if (device->ftbl.device_addtimestamp) { status = device->ftbl.device_addtimestamp(device, timestamp); } - else - { - status = GSL_FAILURE; - } - GSL_API_MUTEX_UNLOCK(); return status; } @@ -147,7 +118,6 @@ int kgsl_cmdstream_waittimestamp(gsl_deviceid_t device_id, gsl_timestamp_t times { gsl_device_t* device = &gsl_driver.device[device_id-1]; int status = GSL_FAILURE; - if (device->ftbl.device_waittimestamp) { status = device->ftbl.device_waittimestamp(device, timestamp, timeout); @@ -163,36 +133,25 @@ kgsl_cmdstream_memqueue_drain(gsl_device_t *device) gsl_memnode_t *memnode, *nextnode, *freehead; gsl_timestamp_t timestamp, ts_processed; gsl_memqueue_t *memqueue = &device->memqueue; - - GSL_CMDSTREAM_MUTEX_LOCK(); - // check head if (memqueue->head == NULL) { - GSL_CMDSTREAM_MUTEX_UNLOCK(); return; } - // get current EOP timestamp - ts_processed = kgsl_cmdstream_readtimestamp(device->id, GSL_TIMESTAMP_RETIRED); - + ts_processed = kgsl_cmdstream_readtimestamp0(device->id, GSL_TIMESTAMP_RETIRED); timestamp = memqueue->head->timestamp; - // check head timestamp if (!(((ts_processed - timestamp) >= 0) || ((ts_processed - timestamp) < -20000))) { - GSL_CMDSTREAM_MUTEX_UNLOCK(); return; } - memnode = memqueue->head; freehead = memqueue->head; - // get node list to free for(;;) { nextnode = memnode->next; - if (nextnode == NULL) { // entire queue drained @@ -200,9 +159,7 @@ kgsl_cmdstream_memqueue_drain(gsl_device_t *device) memqueue->tail = NULL; break; } - timestamp = nextnode->timestamp; - if (!(((ts_processed - timestamp) >= 0) || ((ts_processed - timestamp) < -20000))) { // drained up to a point @@ -210,12 +167,8 @@ kgsl_cmdstream_memqueue_drain(gsl_device_t *device) memnode->next = NULL; break; } - memnode = nextnode; } - - GSL_CMDSTREAM_MUTEX_UNLOCK(); - // free nodes while (freehead) { @@ -231,17 +184,21 @@ kgsl_cmdstream_memqueue_drain(gsl_device_t *device) int kgsl_cmdstream_freememontimestamp(gsl_deviceid_t device_id, gsl_memdesc_t *memdesc, gsl_timestamp_t timestamp, gsl_timestamp_type_t type) { - gsl_memnode_t *memnode; - gsl_device_t* device = &gsl_driver.device[device_id-1]; - gsl_memqueue_t *memqueue = &device->memqueue; + gsl_memnode_t *memnode; + gsl_device_t *device = &gsl_driver.device[device_id-1]; + gsl_memqueue_t *memqueue; + (void)type; // unref. For now just use EOP timestamp + + GSL_API_MUTEX_LOCK(); - (void) type; // unref. For now just use EOP timestamp + memqueue = &device->memqueue; memnode = kos_malloc(sizeof(gsl_memnode_t)); if (!memnode) { // other solution is to idle and free which given that the upper level driver probably wont check, probably a better idea + GSL_API_MUTEX_UNLOCK(); return (GSL_FAILURE); } @@ -250,8 +207,6 @@ kgsl_cmdstream_freememontimestamp(gsl_deviceid_t device_id, gsl_memdesc_t *memde memnode->next = NULL; kos_memcpy(&memnode->memdesc, memdesc, sizeof(gsl_memdesc_t)); - GSL_CMDSTREAM_MUTEX_LOCK(); - // add to end of queue if (memqueue->tail != NULL) { @@ -265,7 +220,7 @@ kgsl_cmdstream_freememontimestamp(gsl_deviceid_t device_id, gsl_memdesc_t *memde memqueue->tail = memnode; } - GSL_CMDSTREAM_MUTEX_UNLOCK(); + GSL_API_MUTEX_UNLOCK(); return (GSL_SUCCESS); } @@ -279,6 +234,6 @@ static int kgsl_cmdstream_timestamp_cmp(gsl_timestamp_t ts_new, gsl_timestamp_t int kgsl_cmdstream_check_timestamp(gsl_deviceid_t device_id, gsl_timestamp_t timestamp) { gsl_timestamp_t ts_processed; - ts_processed = kgsl_cmdstream_readtimestamp(device_id, GSL_TIMESTAMP_RETIRED); + ts_processed = kgsl_cmdstream_readtimestamp0(device_id, GSL_TIMESTAMP_RETIRED); return kgsl_cmdstream_timestamp_cmp(ts_processed, timestamp); } diff --git a/drivers/mxc/amd-gpu/common/gsl_cmdwindow.c b/drivers/mxc/amd-gpu/common/gsl_cmdwindow.c index ea106a2735af..4d70da5b25c8 100644 --- a/drivers/mxc/amd-gpu/common/gsl_cmdwindow.c +++ b/drivers/mxc/amd-gpu/common/gsl_cmdwindow.c @@ -31,31 +31,12 @@ ////////////////////////////////////////////////////////////////////////////// -// macros -////////////////////////////////////////////////////////////////////////////// -#ifdef GSL_LOCKING_FINEGRAIN -#define GSL_CMDWINDOW_MUTEX_CREATE() device->cmdwindow_mutex = kos_mutex_create("gsl_cmdwindow"); \ - if (!device->cmdwindow_mutex) return (GSL_FAILURE); -#define GSL_CMDWINDOW_MUTEX_LOCK() kos_mutex_lock(device->cmdwindow_mutex) -#define GSL_CMDWINDOW_MUTEX_UNLOCK() kos_mutex_unlock(device->cmdwindow_mutex) -#define GSL_CMDWINDOW_MUTEX_FREE() kos_mutex_free(device->cmdwindow_mutex); device->cmdwindow_mutex = 0; -#else -#define GSL_CMDWINDOW_MUTEX_CREATE() (void) device // unreferenced formal parameter -#define GSL_CMDWINDOW_MUTEX_LOCK() -#define GSL_CMDWINDOW_MUTEX_UNLOCK() -#define GSL_CMDWINDOW_MUTEX_FREE() (void) device // unreferenced formal parameter -#endif - - -////////////////////////////////////////////////////////////////////////////// // functions ////////////////////////////////////////////////////////////////////////////// int kgsl_cmdwindow_init(gsl_device_t *device) { - GSL_CMDWINDOW_MUTEX_CREATE(); - return (GSL_SUCCESS); } @@ -64,8 +45,6 @@ kgsl_cmdwindow_init(gsl_device_t *device) int kgsl_cmdwindow_close(gsl_device_t *device) { - GSL_CMDWINDOW_MUTEX_FREE(); - return (GSL_SUCCESS); } @@ -73,8 +52,8 @@ kgsl_cmdwindow_close(gsl_device_t *device) //---------------------------------------------------------------------------- -KGSL_API int -kgsl_cmdwindow_write(gsl_deviceid_t device_id, gsl_cmdwindow_t target, unsigned int addr, unsigned int data) +int +kgsl_cmdwindow_write0(gsl_deviceid_t device_id, gsl_cmdwindow_t target, unsigned int addr, unsigned int data) { #ifdef GSL_BLD_G12 gsl_device_t *device; @@ -84,14 +63,10 @@ kgsl_cmdwindow_write(gsl_deviceid_t device_id, gsl_cmdwindow_t target, unsigned kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_TRACE, "--> int kgsl_cmdwindow_write( gsl_device_id_t device_id=%d, gsl_cmdwindow_t target=%d, unsigned int addr=0x%08x, unsigned int data=0x%08x)\n", device_id, target, addr, data ); - GSL_API_MUTEX_LOCK(); - device = &gsl_driver.device[device_id-1]; // device_id is 1 based if (target < GSL_CMDWINDOW_MIN || target > GSL_CMDWINDOW_MAX) { - GSL_API_MUTEX_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_ERROR, "ERROR: Invalid target.\n" ); kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_cmdwindow_write. Return value %B\n", GSL_FAILURE ); return (GSL_FAILURE); @@ -100,7 +75,6 @@ kgsl_cmdwindow_write(gsl_deviceid_t device_id, gsl_cmdwindow_t target, unsigned if ((!(device->flags & GSL_FLAGS_INITIALIZED) && target == GSL_CMDWINDOW_MMU) || (!(device->flags & GSL_FLAGS_STARTED) && target != GSL_CMDWINDOW_MMU)) { - GSL_API_MUTEX_UNLOCK(); kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_ERROR, "ERROR: Invalid device state to write to selected targer.\n" ); kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_cmdwindow_write. Return value %B\n", GSL_FAILURE ); return (GSL_FAILURE); @@ -110,7 +84,6 @@ kgsl_cmdwindow_write(gsl_deviceid_t device_id, gsl_cmdwindow_t target, unsigned if (target == GSL_CMDWINDOW_MMU) { #ifdef GSL_NO_MMU - GSL_API_MUTEX_UNLOCK(); return (GSL_SUCCESS); #endif cmdstream = ADDR_VGC_MMUCOMMANDSTREAM; @@ -125,21 +98,16 @@ kgsl_cmdwindow_write(gsl_deviceid_t device_id, gsl_cmdwindow_t target, unsigned cmdwinaddr = ((target << GSL_CMDWINDOW_TARGET_SHIFT) & GSL_CMDWINDOW_TARGET_MASK); cmdwinaddr |= ((addr << GSL_CMDWINDOW_ADDR_SHIFT) & GSL_CMDWINDOW_ADDR_MASK); - GSL_CMDWINDOW_MUTEX_LOCK(); - #ifndef GSL_NO_MMU // set mmu pagetable kgsl_mmu_setpagetable(device, GSL_CALLER_PROCESSID_GET()); #endif // write command window address - kgsl_device_regwrite(device_id, (cmdstream)>>2, cmdwinaddr); + device->ftbl.device_regwrite(device, (cmdstream)>>2, cmdwinaddr); // write data - kgsl_device_regwrite(device_id, (cmdstream)>>2, data); - - GSL_CMDWINDOW_MUTEX_UNLOCK(); - GSL_API_MUTEX_UNLOCK(); + device->ftbl.device_regwrite(device, (cmdstream)>>2, data); kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_cmdwindow_write. Return value %B\n", GSL_SUCCESS ); @@ -154,3 +122,15 @@ kgsl_cmdwindow_write(gsl_deviceid_t device_id, gsl_cmdwindow_t target, unsigned return (GSL_FAILURE); #endif // GSL_BLD_G12 } + +//---------------------------------------------------------------------------- + +KGSL_API int +kgsl_cmdwindow_write(gsl_deviceid_t device_id, gsl_cmdwindow_t target, unsigned int addr, unsigned int data) +{ + int status = GSL_SUCCESS; + GSL_API_MUTEX_LOCK(); + status = kgsl_cmdwindow_write0(device_id, target, addr, data); + GSL_API_MUTEX_UNLOCK(); + return status; +} diff --git a/drivers/mxc/amd-gpu/common/gsl_device.c b/drivers/mxc/amd-gpu/common/gsl_device.c index b748acb9d0d4..9ebe2abe78b0 100644 --- a/drivers/mxc/amd-gpu/common/gsl_device.c +++ b/drivers/mxc/amd-gpu/common/gsl_device.c @@ -15,7 +15,7 @@ * 02110-1301, USA. * */ - + #include "gsl.h" #include "gsl_hal.h" @@ -96,13 +96,13 @@ kgsl_device_init(gsl_device_t *device, gsl_deviceid_t device_id) } // allocate memory store - status = kgsl_sharedmem_alloc(device->id, GSL_MEMFLAGS_ALIGNPAGE | GSL_MEMFLAGS_CONPHYS, sizeof(gsl_devmemstore_t), &device->memstore); + status = kgsl_sharedmem_alloc0(device->id, GSL_MEMFLAGS_ALIGNPAGE | GSL_MEMFLAGS_CONPHYS, sizeof(gsl_devmemstore_t), &device->memstore); KGSL_DEBUG(GSL_DBGFLAGS_DUMPX, { // dumpx needs this to be in EMEM0 aperture - kgsl_sharedmem_free(&device->memstore); - status = kgsl_sharedmem_alloc(device->id, GSL_MEMFLAGS_ALIGNPAGE, sizeof(gsl_devmemstore_t), &device->memstore); + kgsl_sharedmem_free0(&device->memstore, GSL_CALLER_PROCESSID_GET()); + status = kgsl_sharedmem_alloc0(device->id, GSL_MEMFLAGS_ALIGNPAGE, sizeof(gsl_devmemstore_t), &device->memstore); }); if (status != GSL_SUCCESS) @@ -110,7 +110,7 @@ kgsl_device_init(gsl_device_t *device, gsl_deviceid_t device_id) kgsl_device_stop(device->id); return (status); } - kgsl_sharedmem_set(&device->memstore, 0, 0, device->memstore.size); + kgsl_sharedmem_set0(&device->memstore, 0, 0, device->memstore.size); // init memqueue device->memqueue.head = NULL; @@ -174,7 +174,7 @@ kgsl_device_close(gsl_device_t *device) // DumpX allocates memstore from MMU aperture if (device->memstore.hostptr && !(gsl_driver.flags_debug & GSL_DBGFLAGS_DUMPX)) { - kgsl_sharedmem_free(&device->memstore); + kgsl_sharedmem_free0(&device->memstore, GSL_CALLER_PROCESSID_GET()); } #ifndef _LINUX @@ -418,9 +418,9 @@ kgsl_device_start(gsl_deviceid_t device_id, gsl_flags_t flags) GSL_API_MUTEX_LOCK(); device = &gsl_driver.device[device_id-1]; // device_id is 1 based - + kgsl_device_active(device); - + if (!(device->flags & GSL_FLAGS_INITIALIZED)) { GSL_API_MUTEX_UNLOCK(); @@ -515,7 +515,7 @@ kgsl_device_idle(gsl_deviceid_t device_id, unsigned int timeout) device = &gsl_driver.device[device_id-1]; // device_id is 1 based kgsl_device_active(device); - + if (device->ftbl.device_idle) { status = device->ftbl.device_idle(device, timeout); @@ -646,3 +646,4 @@ kgsl_device_runpending(gsl_device_t *device) return (status); } + diff --git a/drivers/mxc/amd-gpu/common/gsl_drawctxt.c b/drivers/mxc/amd-gpu/common/gsl_drawctxt.c index 14c413e8e908..afa44e618794 100644 --- a/drivers/mxc/amd-gpu/common/gsl_drawctxt.c +++ b/drivers/mxc/amd-gpu/common/gsl_drawctxt.c @@ -117,23 +117,6 @@ #define CONTEXT_SIZE (SHADER_OFFSET + 3 * SHADER_SHADOW_SIZE) -///////////////////////////////////////////////////////////////////////////// -// macros -////////////////////////////////////////////////////////////////////////////// -#ifdef GSL_LOCKING_FINEGRAIN -#define GSL_CONTEXT_MUTEX_CREATE() device->drawctxt_mutex = kos_mutex_create("gsl_drawctxt"); \ - if (!device->drawctxt_mutex) {return (GSL_FAILURE);} -#define GSL_CONTEXT_MUTEX_LOCK() kos_mutex_lock(device->drawctxt_mutex) -#define GSL_CONTEXT_MUTEX_UNLOCK() kos_mutex_unlock(device->drawctxt_mutex) -#define GSL_CONTEXT_MUTEX_FREE() kos_mutex_free(device->drawctxt_mutex); device->drawctxt_mutex = 0; -#else -#define GSL_CONTEXT_MUTEX_CREATE() (void) device // unreferenced formal parameter -#define GSL_CONTEXT_MUTEX_LOCK() -#define GSL_CONTEXT_MUTEX_UNLOCK() -#define GSL_CONTEXT_MUTEX_FREE() (void) device // unreferenced formal parameter -#endif - - ////////////////////////////////////////////////////////////////////////////// // temporary work structure ////////////////////////////////////////////////////////////////////////////// @@ -1279,13 +1262,13 @@ create_gpustate_shadow(gsl_device_t *device, gsl_drawctxt_t *drawctxt, ctx_t *ct KGSL_DEBUG(GSL_DBGFLAGS_DUMPX, flags = (GSL_MEMFLAGS_EMEM | GSL_MEMFLAGS_ALIGN8K)); // allocate memory to allow HW to save sub-blocks for efficient context save/restore - if (kgsl_sharedmem_alloc(device->id, flags, CONTEXT_SIZE, &drawctxt->gpustate) != GSL_SUCCESS) + if (kgsl_sharedmem_alloc0(device->id, flags, CONTEXT_SIZE, &drawctxt->gpustate) != GSL_SUCCESS) return GSL_FAILURE; drawctxt->flags |= CTXT_FLAGS_STATE_SHADOW; // Blank out h/w register, constant, and command buffer shadows. - kgsl_sharedmem_set(&drawctxt->gpustate, 0, 0, CONTEXT_SIZE); + kgsl_sharedmem_set0(&drawctxt->gpustate, 0, 0, CONTEXT_SIZE); // set-up command and vertex buffer pointers ctx->cmd = ctx->start = (unsigned int *) ((char *)drawctxt->gpustate.hostptr + CMD_OFFSET); @@ -1307,12 +1290,12 @@ static int allocate_gmem_shadow_buffer(gsl_device_t *device, gsl_drawctxt_t *drawctxt) { // allocate memory for GMEM shadow - if (kgsl_sharedmem_alloc(device->id, (GSL_MEMFLAGS_EMEM | GSL_MEMFLAGS_ALIGN8K), + if (kgsl_sharedmem_alloc0(device->id, (GSL_MEMFLAGS_CONPHYS | GSL_MEMFLAGS_ALIGN8K), drawctxt->context_gmem_shadow.size, &drawctxt->context_gmem_shadow.gmemshadow) != GSL_SUCCESS) return GSL_FAILURE; // blank out gmem shadow. - kgsl_sharedmem_set(&drawctxt->context_gmem_shadow.gmemshadow, 0, 0, drawctxt->context_gmem_shadow.size); + kgsl_sharedmem_set0(&drawctxt->context_gmem_shadow.gmemshadow, 0, 0, drawctxt->context_gmem_shadow.size); return GSL_SUCCESS; } @@ -1375,8 +1358,6 @@ create_gmem_shadow(gsl_device_t *device, gsl_drawctxt_t *drawctxt, ctx_t *ctx) int kgsl_drawctxt_init(gsl_device_t *device) { - GSL_CONTEXT_MUTEX_CREATE(); - return (GSL_SUCCESS); } @@ -1388,8 +1369,6 @@ kgsl_drawctxt_init(gsl_device_t *device) int kgsl_drawctxt_close(gsl_device_t *device) { - GSL_CONTEXT_MUTEX_FREE(); - return (GSL_SUCCESS); } @@ -1405,14 +1384,10 @@ kgsl_drawctxt_create(gsl_device_t* device, gsl_context_type_t type, unsigned int int index; ctx_t ctx; - GSL_CONTEXT_MUTEX_LOCK(); - kgsl_device_active(device); - + if (device->drawctxt_count >= GSL_CONTEXT_MAX) { - GSL_CONTEXT_MUTEX_UNLOCK(); - GSL_API_MUTEX_UNLOCK(); return (GSL_FAILURE); } @@ -1428,7 +1403,6 @@ kgsl_drawctxt_create(gsl_device_t* device, gsl_context_type_t type, unsigned int if (index >= GSL_CONTEXT_MAX) { - GSL_CONTEXT_MUTEX_UNLOCK(); return (GSL_FAILURE); } @@ -1448,7 +1422,6 @@ kgsl_drawctxt_create(gsl_device_t* device, gsl_context_type_t type, unsigned int if (create_gpustate_shadow(device, drawctxt, &ctx) != GSL_SUCCESS) { kgsl_drawctxt_destroy(device, index); - GSL_CONTEXT_MUTEX_UNLOCK(); return (GSL_FAILURE); } @@ -1465,7 +1438,6 @@ kgsl_drawctxt_create(gsl_device_t* device, gsl_context_type_t type, unsigned int if (create_gmem_shadow(device, drawctxt, &ctx) != GSL_SUCCESS) { kgsl_drawctxt_destroy(device, index); - GSL_CONTEXT_MUTEX_UNLOCK(); return (GSL_FAILURE); } @@ -1475,7 +1447,6 @@ kgsl_drawctxt_create(gsl_device_t* device, gsl_context_type_t type, unsigned int *drawctxt_id = index; - GSL_CONTEXT_MUTEX_UNLOCK(); return (GSL_SUCCESS); } @@ -1489,8 +1460,6 @@ kgsl_drawctxt_destroy(gsl_device_t* device, unsigned int drawctxt_id) { gsl_drawctxt_t *drawctxt; - GSL_CONTEXT_MUTEX_LOCK(); - drawctxt = &device->drawctxt[drawctxt_id]; if (drawctxt->flags != CTXT_FLAGS_NOT_IN_USE) @@ -1504,17 +1473,17 @@ kgsl_drawctxt_destroy(gsl_device_t* device, unsigned int drawctxt_id) kgsl_drawctxt_switch(device, GSL_CONTEXT_NONE, 0); } - kgsl_device_idle(device->id, GSL_TIMEOUT_DEFAULT); + device->ftbl.device_idle(device, GSL_TIMEOUT_DEFAULT); // destroy state shadow, if allocated if (drawctxt->flags & CTXT_FLAGS_STATE_SHADOW) - kgsl_sharedmem_free(&drawctxt->gpustate); + kgsl_sharedmem_free0(&drawctxt->gpustate, GSL_CALLER_PROCESSID_GET()); // destroy gmem shadow, if allocated if (drawctxt->context_gmem_shadow.gmemshadow.size > 0) { - kgsl_sharedmem_free(&drawctxt->context_gmem_shadow.gmemshadow); + kgsl_sharedmem_free0(&drawctxt->context_gmem_shadow.gmemshadow, GSL_CALLER_PROCESSID_GET()); drawctxt->context_gmem_shadow.gmemshadow.size = 0; } @@ -1525,8 +1494,6 @@ kgsl_drawctxt_destroy(gsl_device_t* device, unsigned int drawctxt_id) KOS_ASSERT(device->drawctxt_count >= 0); } - GSL_CONTEXT_MUTEX_UNLOCK(); - return (GSL_SUCCESS); } @@ -1561,11 +1528,8 @@ KGSL_API int kgsl_drawctxt_bind_gmem_shadow(gsl_deviceid_t device_id, unsigned i GSL_API_MUTEX_LOCK(); - device = &gsl_driver.device[device_id-1]; // device_id is 1 based - GSL_CONTEXT_MUTEX_LOCK(); - drawctxt = &device->drawctxt[drawctxt_id]; shadow = &drawctxt->user_gmem_shadow[buffer_id]; @@ -1650,7 +1614,7 @@ KGSL_API int kgsl_drawctxt_bind_gmem_shadow(gsl_deviceid_t device_id, unsigned i // Release context GMEM shadow if found if (drawctxt->context_gmem_shadow.gmemshadow.size > 0) { - kgsl_sharedmem_free(&drawctxt->context_gmem_shadow.gmemshadow); + kgsl_sharedmem_free0(&drawctxt->context_gmem_shadow.gmemshadow, GSL_CALLER_PROCESSID_GET()); drawctxt->context_gmem_shadow.gmemshadow.size = 0; } } @@ -1665,7 +1629,6 @@ KGSL_API int kgsl_drawctxt_bind_gmem_shadow(gsl_deviceid_t device_id, unsigned i } } - GSL_CONTEXT_MUTEX_UNLOCK(); GSL_API_MUTEX_UNLOCK(); return (GSL_SUCCESS); @@ -1803,8 +1766,6 @@ kgsl_drawctxt_destroyall(gsl_device_t *device) int i; gsl_drawctxt_t *drawctxt; - GSL_CONTEXT_MUTEX_LOCK(); - for (i = 0; i < GSL_CONTEXT_MAX; i++) { drawctxt = &device->drawctxt[i]; @@ -1813,12 +1774,12 @@ kgsl_drawctxt_destroyall(gsl_device_t *device) { // destroy state shadow, if allocated if (drawctxt->flags & CTXT_FLAGS_STATE_SHADOW) - kgsl_sharedmem_free(&drawctxt->gpustate); + kgsl_sharedmem_free0(&drawctxt->gpustate, GSL_CALLER_PROCESSID_GET()); // destroy gmem shadow, if allocated if (drawctxt->context_gmem_shadow.gmemshadow.size > 0) { - kgsl_sharedmem_free(&drawctxt->context_gmem_shadow.gmemshadow); + kgsl_sharedmem_free0(&drawctxt->context_gmem_shadow.gmemshadow, GSL_CALLER_PROCESSID_GET()); drawctxt->context_gmem_shadow.gmemshadow.size = 0; } @@ -1829,8 +1790,6 @@ kgsl_drawctxt_destroyall(gsl_device_t *device) } } - GSL_CONTEXT_MUTEX_UNLOCK(); - return (GSL_SUCCESS); } diff --git a/drivers/mxc/amd-gpu/common/gsl_g12.c b/drivers/mxc/amd-gpu/common/gsl_g12.c index 922f0d8a94a5..7c85e39941c3 100644 --- a/drivers/mxc/amd-gpu/common/gsl_g12.c +++ b/drivers/mxc/amd-gpu/common/gsl_g12.c @@ -21,7 +21,6 @@ #include "kos_libapi.h" #include "gsl_cmdstream.h" #ifdef _LINUX -#include <linux/kthread.h> #include <linux/sched.h> #endif @@ -133,7 +132,7 @@ kgsl_g12_intrcallback(gsl_intrid_t id, void *cookie) // error condition interrupt case GSL_INTR_G12_FIFO: - kgsl_device_destroy(device); + device->ftbl.device_destroy(device); break; case GSL_INTR_G12_MH: @@ -157,7 +156,7 @@ kgsl_g12_isr(gsl_device_t *device) #endif // DEBUG // determine if G12 is interrupting - kgsl_device_regread(device->id, (ADDR_VGC_IRQSTATUS >> 2), &status); + device->ftbl.device_regread(device, (ADDR_VGC_IRQSTATUS >> 2), &status); if (status) { @@ -166,8 +165,8 @@ kgsl_g12_isr(gsl_device_t *device) { #ifdef _DEBUG // obtain mh error information - kgsl_device_regread(device->id, ADDR_MH_MMU_PAGE_FAULT, (unsigned int *)&page_fault); - kgsl_device_regread(device->id, ADDR_MH_AXI_ERROR, (unsigned int *)&axi_error); + device->ftbl.device_regread(device, ADDR_MH_MMU_PAGE_FAULT, (unsigned int *)&page_fault); + device->ftbl.device_regread(device, ADDR_MH_AXI_ERROR, (unsigned int *)&axi_error); #endif // DEBUG kgsl_intr_decode(device, GSL_INTR_BLOCK_G12_MH); @@ -193,7 +192,7 @@ kgsl_g12_tlbinvalidate(gsl_device_t *device, unsigned int reg_invalidate, unsign mh_mmu_invalidate.INVALIDATE_ALL = 1; mh_mmu_invalidate.INVALIDATE_TC = 1; - kgsl_device_regwrite(device->id, reg_invalidate, *(unsigned int *) &mh_mmu_invalidate); + device->ftbl.device_regwrite(device, reg_invalidate, *(unsigned int *) &mh_mmu_invalidate); #else (void)device; (void)reg_invalidate; @@ -206,13 +205,11 @@ kgsl_g12_tlbinvalidate(gsl_device_t *device, unsigned int reg_invalidate, unsign int kgsl_g12_setpagetable(gsl_device_t *device, unsigned int reg_ptbase, gpuaddr_t ptbase, unsigned int pid) { -#ifndef GSL_NO_MMU - // unreferenced formal parameter + // unreferenced formal parameter (void) pid; - - kgsl_device_idle(device->id, GSL_TIMEOUT_DEFAULT); - - kgsl_device_regwrite(device->id, reg_ptbase, ptbase); +#ifndef GSL_NO_MMU + device->ftbl.device_idle(device, GSL_TIMEOUT_DEFAULT); + device->ftbl.device_regwrite(device, reg_ptbase, ptbase); #else (void)device; (void)reg_ptbase; @@ -227,11 +224,11 @@ kgsl_g12_setpagetable(gsl_device_t *device, unsigned int reg_ptbase, gpuaddr_t p static void kgsl_g12_updatetimestamp(gsl_device_t *device) { unsigned int count = 0; - kgsl_device_regread(device->id, (ADDR_VGC_IRQ_ACTIVE_CNT >> 2), &count); + device->ftbl.device_regread(device, (ADDR_VGC_IRQ_ACTIVE_CNT >> 2), &count); count >>= 8; count &= 255; device->timestamp += count; - kgsl_sharedmem_write(&device->memstore, GSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp), &device->timestamp, 4, 0); + kgsl_sharedmem_write0(&device->memstore, GSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp), &device->timestamp, 4, 0); } //---------------------------------------------------------------------------- @@ -256,18 +253,18 @@ kgsl_g12_init(gsl_device_t *device) kgsl_hal_setpowerstate(device->id, GSL_PWRFLAGS_POWER_ON, 100); // setup MH arbiter - MH offsets are considered to be dword based, therefore no down shift - kgsl_device_regwrite(device->id, ADDR_MH_ARBITER_CONFIG, *(unsigned int *) &gsl_cfg_g12_mharb); + device->ftbl.device_regwrite(device, ADDR_MH_ARBITER_CONFIG, *(unsigned int *) &gsl_cfg_g12_mharb); // init interrupt status = kgsl_intr_init(device); if (status != GSL_SUCCESS) { - kgsl_device_stop(device->id); + device->ftbl.device_stop(device); return (status); } // enable irq - kgsl_device_regwrite(device->id, (ADDR_VGC_IRQENABLE >> 2), 0x3); + device->ftbl.device_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0x3); #ifndef GSL_NO_MMU // enable master interrupt for G12 MH @@ -278,7 +275,7 @@ kgsl_g12_init(gsl_device_t *device) status = kgsl_mmu_init(device); if (status != GSL_SUCCESS) { - kgsl_device_stop(device->id); + device->ftbl.device_stop(device); return (status); } #endif @@ -318,20 +315,15 @@ kgsl_g12_init(gsl_device_t *device) int kgsl_g12_close(gsl_device_t *device) { -#if defined(_LINUX) - int status; -// printk(KERN_INFO "\npid=%u, %s\n", current->pid, __func__); -#endif + int status = GSL_FAILURE; if (device->refcnt == 0) { // wait pending interrupts before shutting down G12 intr thread to // empty irq counters. Otherwise there's a possibility to have them in // registers next time systems starts up and this results in a hang. -#ifndef _WIN32_WCE - status = kgsl_g12_idle(device, 1000); + status = device->ftbl.device_idle(device, 1000); KOS_ASSERT(status == GSL_SUCCESS); -#endif #ifndef _LINUX kos_thread_destroy(device->irq_thread_handle); @@ -359,7 +351,7 @@ kgsl_g12_close(gsl_device_t *device) kgsl_hal_setpowerstate(device->id, GSL_PWRFLAGS_POWER_OFF, 0); - kgsl_device_idle(device->id, GSL_TIMEOUT_NONE); + device->ftbl.device_idle(device, GSL_TIMEOUT_NONE); device->flags &= ~GSL_FLAGS_INITIALIZED; #if defined(__SYMBIAN32__) @@ -396,7 +388,7 @@ kgsl_g12_destroy(gsl_device_t *device) pid = device->callerprocess[i]; if (pid) { - kgsl_device_stop(device->id); + device->ftbl.device_stop(device); kgsl_driver_destroy(pid); // todo: terminate client process? @@ -421,7 +413,7 @@ kgsl_g12_start(gsl_device_t *device, gsl_flags_t flags) status = kgsl_cmdwindow_init(device); if (status != GSL_SUCCESS) { - kgsl_device_stop(device->id); + device->ftbl.device_stop(device); return (status); } @@ -442,7 +434,7 @@ kgsl_g12_stop(gsl_device_t *device) KOS_ASSERT(device->refcnt == 0); /* wait for device to idle before setting it's clock off */ - status = kgsl_g12_idle(device, 1000); + status = device->ftbl.device_idle(device, 1000); KOS_ASSERT(status == GSL_SUCCESS); status = kgsl_hal_setpowerstate(device->id, GSL_PWRFLAGS_CLK_OFF, 0); @@ -509,21 +501,18 @@ kgsl_g12_setproperty(gsl_device_t *device, gsl_property_type_t type, void *value int kgsl_g12_idle(gsl_device_t *device, unsigned int timeout) { - unsigned int timestamp; - int deltaTimestamp = 0; - // unreferenced formal parameters - (void) timeout; + if ( device->flags & GSL_FLAGS_STARTED ) + { + for ( ; ; ) + { + gsl_timestamp_t retired = kgsl_cmdstream_readtimestamp0( device->id, GSL_TIMESTAMP_RETIRED ); + gsl_timestamp_t ts_diff = retired - device->current_timestamp; + if ( ts_diff >= 0 || ts_diff < -GSL_TIMESTAMP_EPSILON ) + break; + kos_sleep(10); + } + } - if ((device->flags & GSL_FLAGS_STARTED)) - { - do - { - timestamp = kgsl_cmdstream_readtimestamp( device->id, GSL_TIMESTAMP_RETIRED ); - kos_sleep( 0 ); - deltaTimestamp = timestamp - device->current_timestamp; - } - while(!((deltaTimestamp >= 0) || (deltaTimestamp < -GSL_TIMESTAMP_EPSILON))); - } return (GSL_SUCCESS); } @@ -537,10 +526,10 @@ kgsl_g12_regread(gsl_device_t *device, unsigned int offsetwords, unsigned int *v (offsetwords >= ADDR_MH_MMU_CONFIG && offsetwords <= ADDR_MH_MMU_MPU_END)) { #ifdef _Z180 - kgsl_device_regwrite(device->id, (ADDR_VGC_MH_READ_ADDR >> 2), offsetwords); + device->ftbl.device_regwrite(device, (ADDR_VGC_MH_READ_ADDR >> 2), offsetwords); GSL_HAL_REG_READ(device->id, (unsigned int) device->regspace.mmio_virt_base, (ADDR_VGC_MH_READ_ADDR >> 2), value); #else - kgsl_device_regwrite(device->id, (ADDR_MMU_READ_ADDR >> 2), offsetwords); + device->ftbl.device_regwrite(device, (ADDR_MMU_READ_ADDR >> 2), offsetwords); GSL_HAL_REG_READ(device->id, (unsigned int) device->regspace.mmio_virt_base, (ADDR_MMU_READ_DATA >> 2), value); #endif } @@ -561,7 +550,7 @@ kgsl_g12_regwrite(gsl_device_t *device, unsigned int offsetwords, unsigned int v if ((offsetwords >= ADDR_MH_ARBITER_CONFIG && offsetwords <= ADDR_MH_AXI_HALT_CONTROL) || (offsetwords >= ADDR_MH_MMU_CONFIG && offsetwords <= ADDR_MH_MMU_MPU_END)) { - kgsl_cmdwindow_write(device->id, GSL_CMDWINDOW_MMU, offsetwords, value); + kgsl_cmdwindow_write0(device->id, GSL_CMDWINDOW_MMU, offsetwords, value); } else { @@ -571,7 +560,7 @@ kgsl_g12_regwrite(gsl_device_t *device, unsigned int offsetwords, unsigned int v // idle device when running in safe mode if (device->flags & GSL_FLAGS_SAFEMODE) { - kgsl_device_idle(device->id, GSL_TIMEOUT_DEFAULT); + device->ftbl.device_idle(device, GSL_TIMEOUT_DEFAULT); } return (GSL_SUCCESS); @@ -607,12 +596,12 @@ kgsl_g12_waitirq(gsl_device_t *device, gsl_intrid_t intr_id, unsigned int *count { unsigned int cntrs; int i; - kgsl_device_active(device); + kgsl_device_active(device); #ifndef VG_HDK kos_event_reset(device->intr.evnt[intr_id]); - kgsl_device_regread(device->id, (ADDR_VGC_IRQ_ACTIVE_CNT >> 2), &cntrs); + device->ftbl.device_regread(device, (ADDR_VGC_IRQ_ACTIVE_CNT >> 2), &cntrs); #else - kgsl_device_regread(device->id, (0x38 >> 2), &cntrs); + device->ftbl.device_regread(device, (0x38 >> 2), &cntrs); #endif for (i = 0; i < GSL_G12_INTR_COUNT; i++) @@ -763,10 +752,7 @@ kgsl_g12_issueibcmds(gsl_device_t* device, int drawctxt_index, gpuaddr_t ibaddr, GSL_CMDSTREAM_GET_EOP_TIMESTAMP(device, (int *)&processed_timestamp); } - device->current_timestamp++; - g_z1xx.timestamp[nextbuf] = device->current_timestamp; - - *timestamp = device->current_timestamp; + *timestamp = g_z1xx.timestamp[nextbuf] = device->current_timestamp + 1; /* context switch */ if (drawctxt_index != (int)g_z1xx.prevctx) @@ -780,18 +766,21 @@ kgsl_g12_issueibcmds(gsl_device_t* device, int drawctxt_index, gpuaddr_t ibaddr, beginpacket(&g_z1xx, cmd+ofs, cnt); tmp.gpuaddr=ibaddr+(sizedwords*sizeof(unsigned int)); - kgsl_sharedmem_write(&tmp, 4, &nextaddr, 4, false); - kgsl_sharedmem_write(&tmp, 8, &nextcnt, 4, false); + kgsl_sharedmem_write0(&tmp, 4, &nextaddr, 4, false); + kgsl_sharedmem_write0(&tmp, 8, &nextcnt, 4, false); /* sync mem */ - kgsl_sharedmem_write((const gsl_memdesc_t *)&g_z1xx.cmdbufdesc[g_z1xx.curr], 0, g_z1xx.cmdbuf[g_z1xx.curr], (512 + 13) * sizeof(unsigned int), false); + kgsl_sharedmem_write0((const gsl_memdesc_t *)&g_z1xx.cmdbufdesc[g_z1xx.curr], 0, g_z1xx.cmdbuf[g_z1xx.curr], (512 + 13) * sizeof(unsigned int), false); g_z1xx.offs = 0; g_z1xx.curr = nextbuf; - // quick & dirty hack --- note mark count is transferred through flags argument for now!!! FIX API - kgsl_cmdwindow_write(2, GSL_CMDWINDOW_2D, ADDR_VGV3_CONTROL, flags); - kgsl_cmdwindow_write(2, GSL_CMDWINDOW_2D, ADDR_VGV3_CONTROL, 0); + /* increment mark counter */ + kgsl_cmdwindow_write0(2, GSL_CMDWINDOW_2D, ADDR_VGV3_CONTROL, flags); + kgsl_cmdwindow_write0(2, GSL_CMDWINDOW_2D, ADDR_VGV3_CONTROL, 0); + + /* increment consumed timestamp */ + device->current_timestamp++; return (GSL_SUCCESS); } @@ -804,14 +793,14 @@ kgsl_g12_context_create(gsl_device_t* device, gsl_context_type_t type, unsigned int status = 0; int i; int cmd; - gsl_flags_t gslflags = (GSL_MEMFLAGS_ALIGN4K); + gsl_flags_t gslflags = (GSL_MEMFLAGS_CONPHYS | GSL_MEMFLAGS_ALIGNPAGE); // unreferenced formal parameters (void) device; (void) type; //(void) drawctxt_id; (void) flags; - + kgsl_device_active(device); if (g_z1xx.numcontext==0) @@ -819,7 +808,7 @@ kgsl_g12_context_create(gsl_device_t* device, gsl_context_type_t type, unsigned /* todo: move this to device create or start. Error checking!! */ for (i=0;i<GSL_HAL_NUMCMDBUFFERS;i++) { - status = kgsl_sharedmem_alloc(GSL_DEVICE_ANY, gslflags, GSL_HAL_CMDBUFFERSIZE, &g_z1xx.cmdbufdesc[i]); + status = kgsl_sharedmem_alloc0(GSL_DEVICE_ANY, gslflags, GSL_HAL_CMDBUFFERSIZE, &g_z1xx.cmdbufdesc[i]); KOS_ASSERT(status == GSL_SUCCESS); g_z1xx.cmdbuf[i]=kos_malloc(GSL_HAL_CMDBUFFERSIZE); KOS_ASSERT(g_z1xx.cmdbuf[i]); @@ -828,33 +817,33 @@ kgsl_g12_context_create(gsl_device_t* device, gsl_context_type_t type, unsigned g_z1xx.curr = i; g_z1xx.offs = 0; addmarker(&g_z1xx); - status = kgsl_sharedmem_write(&g_z1xx.cmdbufdesc[i],0, g_z1xx.cmdbuf[i], (512 + 13) * sizeof(unsigned int), false); + status = kgsl_sharedmem_write0(&g_z1xx.cmdbufdesc[i],0, g_z1xx.cmdbuf[i], (512 + 13) * sizeof(unsigned int), false); KOS_ASSERT(status == GSL_SUCCESS); } g_z1xx.curr = 0; cmd = (int)(((VGV3_NEXTCMD_JUMP) & VGV3_NEXTCMD_NEXTCMD_FMASK)<< VGV3_NEXTCMD_NEXTCMD_FSHIFT); /* set cmd stream buffer to hw */ - status |= kgsl_cmdwindow_write(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, ADDR_VGV3_MODE, 4); - status |= kgsl_cmdwindow_write(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, ADDR_VGV3_NEXTADDR, g_z1xx.cmdbufdesc[0].gpuaddr ); - status |= kgsl_cmdwindow_write(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, ADDR_VGV3_NEXTCMD, cmd | 5); + status |= kgsl_cmdwindow_write0(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, ADDR_VGV3_MODE, 4); + status |= kgsl_cmdwindow_write0(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, ADDR_VGV3_NEXTADDR, g_z1xx.cmdbufdesc[0].gpuaddr ); + status |= kgsl_cmdwindow_write0(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, ADDR_VGV3_NEXTCMD, cmd | 5); KOS_ASSERT(status == GSL_SUCCESS); /* Edge buffer setup todo: move register setup to own function. This function can be then called, if power managemnet is used and clocks are turned off and then on. */ - status |= kgsl_sharedmem_alloc(GSL_DEVICE_ANY, gslflags, GSL_HAL_EDGE0BUFSIZE, &g_z1xx.e0); - status |= kgsl_sharedmem_alloc(GSL_DEVICE_ANY, gslflags, GSL_HAL_EDGE1BUFSIZE, &g_z1xx.e1); - status |= kgsl_sharedmem_set(&g_z1xx.e0, 0, 0, GSL_HAL_EDGE0BUFSIZE); - status |= kgsl_sharedmem_set(&g_z1xx.e1, 0, 0, GSL_HAL_EDGE1BUFSIZE); + status |= kgsl_sharedmem_alloc0(GSL_DEVICE_ANY, gslflags, GSL_HAL_EDGE0BUFSIZE, &g_z1xx.e0); + status |= kgsl_sharedmem_alloc0(GSL_DEVICE_ANY, gslflags, GSL_HAL_EDGE1BUFSIZE, &g_z1xx.e1); + status |= kgsl_sharedmem_set0(&g_z1xx.e0, 0, 0, GSL_HAL_EDGE0BUFSIZE); + status |= kgsl_sharedmem_set0(&g_z1xx.e1, 0, 0, GSL_HAL_EDGE1BUFSIZE); - status |= kgsl_cmdwindow_write(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, GSL_HAL_EDGE0REG, g_z1xx.e0.gpuaddr); - status |= kgsl_cmdwindow_write(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, GSL_HAL_EDGE1REG, g_z1xx.e1.gpuaddr); + status |= kgsl_cmdwindow_write0(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, GSL_HAL_EDGE0REG, g_z1xx.e0.gpuaddr); + status |= kgsl_cmdwindow_write0(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, GSL_HAL_EDGE1REG, g_z1xx.e1.gpuaddr); #ifdef _Z180 - kgsl_sharedmem_alloc(GSL_DEVICE_ANY, gslflags, GSL_HAL_EDGE2BUFSIZE, &g_z1xx.e2); - kgsl_sharedmem_set(&g_z1xx.e2, 0, 0, GSL_HAL_EDGE2BUFSIZE); - kgsl_cmdwindow_write(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, GSL_HAL_EDGE2REG, g_z1xx.e2.gpuaddr); + kgsl_sharedmem_alloc0(GSL_DEVICE_ANY, gslflags, GSL_HAL_EDGE2BUFSIZE, &g_z1xx.e2); + kgsl_sharedmem_set0(&g_z1xx.e2, 0, 0, GSL_HAL_EDGE2BUFSIZE); + kgsl_cmdwindow_write0(GSL_DEVICE_G12, GSL_CMDWINDOW_2D, GSL_HAL_EDGE2REG, g_z1xx.e2.gpuaddr); #endif KOS_ASSERT(status == GSL_SUCCESS); } @@ -895,13 +884,13 @@ kgsl_g12_context_destroy(gsl_device_t* device, unsigned int drawctxt_id) int i; for (i=0;i<GSL_HAL_NUMCMDBUFFERS;i++) { - kgsl_sharedmem_free(&g_z1xx.cmdbufdesc[i]); + kgsl_sharedmem_free0(&g_z1xx.cmdbufdesc[i], GSL_CALLER_PROCESSID_GET()); kos_free(g_z1xx.cmdbuf[i]); } - kgsl_sharedmem_free(&g_z1xx.e0); - kgsl_sharedmem_free(&g_z1xx.e1); + kgsl_sharedmem_free0(&g_z1xx.e0, GSL_CALLER_PROCESSID_GET()); + kgsl_sharedmem_free0(&g_z1xx.e1, GSL_CALLER_PROCESSID_GET()); #ifdef _Z180 - kgsl_sharedmem_free(&g_z1xx.e2); + kgsl_sharedmem_free0(&g_z1xx.e2, GSL_CALLER_PROCESSID_GET()); #endif kos_memset(&g_z1xx,0,sizeof(gsl_z1xx_t)); } @@ -957,7 +946,7 @@ static void irq_thread(void) #ifdef VG_HDK device->timestamp = timestamp; #else - kgsl_sharedmem_write(&device->memstore, GSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp), ×tamp, 4, false); + kgsl_sharedmem_write0(&device->memstore, GSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp), ×tamp, 4, false); #endif /* Notify timestamp event */ @@ -967,29 +956,14 @@ static void irq_thread(void) { /* Timeout */ - /* Read a timestamp value */ -#ifdef VG_HDK - timestamp = device->timestamp; -#else - GSL_CMDSTREAM_GET_EOP_TIMESTAMP(device, (int *)×tamp); -#endif - - /* TODO Add power management code */ - - if(timestamp < device->current_timestamp) + + if(!(device->flags&GSL_FLAGS_INITIALIZED)) { - /* There is still pending IRQ's from HW */ - } - else - { - if(!(device->flags&GSL_FLAGS_INITIALIZED)) - { - /* if device is closed -> thread exit */ + /* if device is closed -> thread exit */ #if defined(__SYMBIAN32__) - device->irq_thread = 0; + device->irq_thread = 0; #endif - return; - } + return; } } } diff --git a/drivers/mxc/amd-gpu/common/gsl_intrmgr.c b/drivers/mxc/amd-gpu/common/gsl_intrmgr.c index 8914e5752d7b..2c8b278dfe7a 100644 --- a/drivers/mxc/amd-gpu/common/gsl_intrmgr.c +++ b/drivers/mxc/amd-gpu/common/gsl_intrmgr.c @@ -58,13 +58,13 @@ kgsl_intr_decode(gsl_device_t *device, gsl_intrblock_t block_id) unsigned int status; // read the block's interrupt status bits - kgsl_device_regread(device->id, block->status_reg, &status); + device->ftbl.device_regread(device, block->status_reg, &status); // mask off any interrupts which are disabled status &= device->intr.enabled[block->id]; // acknowledge the block's interrupts - kgsl_device_regwrite(device->id, block->clear_reg, status); + device->ftbl.device_regwrite(device, block->clear_reg, status); // loop through the block's masks, determine which interrupt bits are active, and call callback (or TODO queue DPC) for (id = block->first_id; id <= block->last_id; id++) @@ -91,7 +91,7 @@ kgsl_intr_isr() if (device->intr.flags & GSL_FLAGS_INITIALIZED) { - kgsl_device_active(device); + kgsl_device_active(device); device->ftbl.intr_isr(device); } } @@ -186,7 +186,7 @@ int kgsl_intr_enable(gsl_intr_t *intr, gsl_intrid_t id) enabled |= mask; intr->enabled[block->id] = enabled; - kgsl_device_regwrite(intr->device->id, block->mask_reg, enabled); + intr->device->ftbl.device_regwrite(intr->device, block->mask_reg, enabled); } return (GSL_SUCCESS); @@ -223,7 +223,7 @@ int kgsl_intr_disable(gsl_intr_t *intr, gsl_intrid_t id) { enabled &= ~mask; intr->enabled[block->id] = enabled; - kgsl_device_regwrite(intr->device->id, block->mask_reg, enabled); + intr->device->ftbl.device_regwrite(intr->device, block->mask_reg, enabled); kos_event_signal(intr->evnt[id]); // wake up waiting threads before destroying the event kos_event_destroy(intr->evnt[id]); diff --git a/drivers/mxc/amd-gpu/common/gsl_memmgr.c b/drivers/mxc/amd-gpu/common/gsl_memmgr.c index c506ba81dee3..75f250ae59b1 100644 --- a/drivers/mxc/amd-gpu/common/gsl_memmgr.c +++ b/drivers/mxc/amd-gpu/common/gsl_memmgr.c @@ -18,10 +18,6 @@ #include "gsl.h" #include "gsl_hal.h" -#if defined(_LINUX) && !defined(PAGE_SIZE) -#define PAGE_SIZE (1<<12) -#define PAGE_SHIFT (12) -#endif ////////////////////////////////////////////////////////////////////////////// // defines diff --git a/drivers/mxc/amd-gpu/common/gsl_mmu.c b/drivers/mxc/amd-gpu/common/gsl_mmu.c index 2b0b110790a0..310677d926f0 100644 --- a/drivers/mxc/amd-gpu/common/gsl_mmu.c +++ b/drivers/mxc/amd-gpu/common/gsl_mmu.c @@ -18,10 +18,6 @@ #include "gsl.h" #include "gsl_hal.h" -#if defined(_LINUX) && !defined(PAGE_SIZE) -#define PAGE_SIZE (1<<12) -#define PAGE_SHIFT (12) -#endif ////////////////////////////////////////////////////////////////////////////// @@ -67,18 +63,6 @@ const unsigned int GSL_PT_PAGE_AP[4] = {(GSL_PT_PAGE_READ | GSL_PT_PAGE_WRITE), ///////////////////////////////////////////////////////////////////////////// // macros ////////////////////////////////////////////////////////////////////////////// -#ifdef GSL_LOCKING_FINEGRAIN -#define GSL_MMU_MUTEX_CREATE() mmu->mutex = kos_mutex_create("gsl_mmu"); \ - if (!mmu->mutex) {return (GSL_FAILURE);} -#define GSL_MMU_LOCK() kos_mutex_lock(mmu->mutex) -#define GSL_MMU_UNLOCK() kos_mutex_unlock(mmu->mutex) -#define GSL_MMU_MUTEX_FREE() kos_mutex_free(mmu->mutex); mmu->mutex = 0; -#else -#define GSL_MMU_MUTEX_CREATE() -#define GSL_MMU_LOCK() -#define GSL_MMU_UNLOCK() -#define GSL_MMU_MUTEX_FREE() -#endif #define GSL_PT_ENTRY_GET(va) ((va - pagetable->va_base) >> GSL_PAGESIZE_SHIFT) #define GSL_PT_VIRT_GET(pte) (pagetable->va_base + (pte * GSL_PAGESIZE)) @@ -160,7 +144,7 @@ kgsl_mh_intrcallback(gsl_intrid_t id, void *cookie) id == gsl_cfg_mh_intr[devindex].AXI_WRITE_ERROR || id == gsl_cfg_mh_intr[devindex].MMU_PAGE_FAULT) { - kgsl_device_destroy(mmu->device); + mmu->device->ftbl.device_destroy(mmu->device); } kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_mh_intrcallback.\n" ); @@ -176,14 +160,14 @@ kgsl_mmu_debug(gsl_mmu_t *mmu, gsl_mmu_debug_t *regs) kos_memset(regs, 0, sizeof(gsl_mmu_debug_t)); - kgsl_device_regread(mmu->device->id, gsl_cfg_mmu_reg[devindex].CONFIG, ®s->config); - kgsl_device_regread(mmu->device->id, gsl_cfg_mmu_reg[devindex].MPU_BASE, ®s->mpu_base); - kgsl_device_regread(mmu->device->id, gsl_cfg_mmu_reg[devindex].MPU_END, ®s->mpu_end); - kgsl_device_regread(mmu->device->id, gsl_cfg_mmu_reg[devindex].VA_RANGE, ®s->va_range); - kgsl_device_regread(mmu->device->id, gsl_cfg_mmu_reg[devindex].PT_BASE, ®s->pt_base); - kgsl_device_regread(mmu->device->id, gsl_cfg_mmu_reg[devindex].PAGE_FAULT, ®s->page_fault); - kgsl_device_regread(mmu->device->id, gsl_cfg_mmu_reg[devindex].TRAN_ERROR, ®s->trans_error); - kgsl_device_regread(mmu->device->id, gsl_cfg_mmu_reg[devindex].INVALIDATE, ®s->invalidate); + mmu->device->ftbl.device_regread(mmu->device, gsl_cfg_mmu_reg[devindex].CONFIG, ®s->config); + mmu->device->ftbl.device_regread(mmu->device, gsl_cfg_mmu_reg[devindex].MPU_BASE, ®s->mpu_base); + mmu->device->ftbl.device_regread(mmu->device, gsl_cfg_mmu_reg[devindex].MPU_END, ®s->mpu_end); + mmu->device->ftbl.device_regread(mmu->device, gsl_cfg_mmu_reg[devindex].VA_RANGE, ®s->va_range); + mmu->device->ftbl.device_regread(mmu->device, gsl_cfg_mmu_reg[devindex].PT_BASE, ®s->pt_base); + mmu->device->ftbl.device_regread(mmu->device, gsl_cfg_mmu_reg[devindex].PAGE_FAULT, ®s->page_fault); + mmu->device->ftbl.device_regread(mmu->device, gsl_cfg_mmu_reg[devindex].TRAN_ERROR, ®s->trans_error); + mmu->device->ftbl.device_regread(mmu->device, gsl_cfg_mmu_reg[devindex].INVALIDATE, ®s->invalidate); } #endif @@ -269,7 +253,7 @@ kgsl_mmu_destroypagetableobject(gsl_mmu_t *mmu, unsigned int pid) if (pagetable->base.gpuaddr) { - kgsl_sharedmem_free(&pagetable->base); + kgsl_sharedmem_free0(&pagetable->base, GSL_CALLER_PROCESSID_GET()); } kos_free(pagetable); @@ -365,12 +349,12 @@ kgsl_mmu_createpagetableobject(gsl_mmu_t *mmu, unsigned int pid) // allocate page table memory flags = (GSL_MEMFLAGS_ALIGN4K | GSL_MEMFLAGS_CONPHYS | GSL_MEMFLAGS_STRICTREQUEST); - status = kgsl_sharedmem_alloc(mmu->device->id, flags, mmu->pagetable[pindex]->max_entries * GSL_PT_ENTRY_SIZEBYTES, &mmu->pagetable[pindex]->base); + status = kgsl_sharedmem_alloc0(mmu->device->id, flags, mmu->pagetable[pindex]->max_entries * GSL_PT_ENTRY_SIZEBYTES, &mmu->pagetable[pindex]->base); if (status == GSL_SUCCESS) { // reset page table entries - kgsl_sharedmem_set(&mmu->pagetable[pindex]->base, 0, 0, mmu->pagetable[pindex]->base.size); + kgsl_sharedmem_set0(&mmu->pagetable[pindex]->base, 0, 0, mmu->pagetable[pindex]->base.size); KGSL_DEBUG(GSL_DBGFLAGS_DUMPX, KGSL_DEBUG_DUMPX(BB_DUMP_MMU_TBLADDR, mmu->pagetable[pindex]->base.gpuaddr, 0, mmu->pagetable[pindex]->base.size, "kgsl_mmu_init")); } @@ -401,8 +385,6 @@ kgsl_mmu_setpagetable(gsl_device_t *device, unsigned int pid) kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "--> gsl_pagetable_t* kgsl_mmu_setpagetable(gsl_device_t *device=0x%08x)\n", device ); - GSL_MMU_LOCK(); - if (mmu->flags & GSL_FLAGS_STARTED) { #ifdef GSL_MMU_PAGETABLE_PERPROCESS @@ -441,8 +423,6 @@ kgsl_mmu_setpagetable(gsl_device_t *device, unsigned int pid) } } - GSL_MMU_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_mmu_setpagetable. Return value %B\n", status ); return (status); @@ -494,7 +474,7 @@ kgsl_mmu_init(gsl_device_t *device) } // setup MMU and sub-client behavior - kgsl_device_regwrite(device->id, gsl_cfg_mmu_reg[devindex].CONFIG, mmu->config); + device->ftbl.device_regwrite(device, gsl_cfg_mmu_reg[devindex].CONFIG, mmu->config); // enable axi interrupts kgsl_intr_attach(&device->intr, gsl_cfg_mh_intr[devindex].AXI_READ_ERROR, kgsl_mh_intrcallback, (void *) mmu); @@ -509,15 +489,15 @@ kgsl_mmu_init(gsl_device_t *device) if (mmu->config & 0x1) { // idle device - kgsl_device_idle(device->id, GSL_TIMEOUT_DEFAULT); + device->ftbl.device_idle(device, GSL_TIMEOUT_DEFAULT); // make sure aligned to pagesize KOS_ASSERT((mmu->mpu_base & ((1 << GSL_PAGESIZE_SHIFT)-1)) == 0); KOS_ASSERT(((mmu->mpu_base + mmu->mpu_range) & ((1 << GSL_PAGESIZE_SHIFT)-1)) == 0); // define physical memory range accessible by the core - kgsl_device_regwrite(device->id, gsl_cfg_mmu_reg[devindex].MPU_BASE, mmu->mpu_base); - kgsl_device_regwrite(device->id, gsl_cfg_mmu_reg[devindex].MPU_END, mmu->mpu_base + mmu->mpu_range); + device->ftbl.device_regwrite(device, gsl_cfg_mmu_reg[devindex].MPU_BASE, mmu->mpu_base); + device->ftbl.device_regwrite(device, gsl_cfg_mmu_reg[devindex].MPU_END, mmu->mpu_base + mmu->mpu_range); // enable page fault interrupt kgsl_intr_attach(&device->intr, gsl_cfg_mh_intr[devindex].MMU_PAGE_FAULT, kgsl_mh_intrcallback, (void *) mmu); @@ -528,8 +508,6 @@ kgsl_mmu_init(gsl_device_t *device) // sub-client MMU lookups require address translation if ((mmu->config & ~0x1) > 0) { - GSL_MMU_MUTEX_CREATE(); - // make sure virtual address range is a multiple of 64Kb KOS_ASSERT((mmu->va_range & ((1 << 16)-1)) == 0); @@ -557,14 +535,14 @@ kgsl_mmu_init(gsl_device_t *device) GSL_TLBFLUSH_FILTER_RESET(); // set page table base - kgsl_device_regwrite(device->id, gsl_cfg_mmu_reg[devindex].PT_BASE, mmu->hwpagetable->base.gpuaddr); + device->ftbl.device_regwrite(device, gsl_cfg_mmu_reg[devindex].PT_BASE, mmu->hwpagetable->base.gpuaddr); // define virtual address range - kgsl_device_regwrite(device->id, gsl_cfg_mmu_reg[devindex].VA_RANGE, (mmu->hwpagetable->va_base | (mmu->hwpagetable->va_range >> 16))); + device->ftbl.device_regwrite(device, gsl_cfg_mmu_reg[devindex].VA_RANGE, (mmu->hwpagetable->va_base | (mmu->hwpagetable->va_range >> 16))); // allocate memory used for completing r/w operations that cannot be mapped by the MMU flags = (GSL_MEMFLAGS_ALIGN32 | GSL_MEMFLAGS_CONPHYS | GSL_MEMFLAGS_STRICTREQUEST); - status = kgsl_sharedmem_alloc(device->id, flags, 32, &mmu->dummyspace); + status = kgsl_sharedmem_alloc0(device->id, flags, 32, &mmu->dummyspace); if (status != GSL_SUCCESS) { kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_ERROR, "ERROR: Unable to allocate dummy space memory.\n" ); @@ -573,7 +551,7 @@ kgsl_mmu_init(gsl_device_t *device) return (status); } - kgsl_device_regwrite(device->id, gsl_cfg_mmu_reg[devindex].TRAN_ERROR, mmu->dummyspace.gpuaddr); + device->ftbl.device_regwrite(device, gsl_cfg_mmu_reg[devindex].TRAN_ERROR, mmu->dummyspace.gpuaddr); // call device specific tlb invalidate device->ftbl.mmu_tlbinvalidate(device, gsl_cfg_mmu_reg[devindex].INVALIDATE, mmu->hwpagetable->pid); @@ -622,12 +600,9 @@ kgsl_mmu_map(gsl_mmu_t *mmu, gpuaddr_t gpubaseaddr, const gsl_scatterlist_t *sca // get gpu access permissions ap = GSL_PT_PAGE_AP[((flags & GSL_MEMFLAGS_GPUAP_MASK) >> GSL_MEMFLAGS_GPUAP_SHIFT)]; - GSL_MMU_LOCK(); - pagetable = kgsl_mmu_getpagetableobject(mmu, pid); if (!pagetable) { - GSL_MMU_UNLOCK(); return (GSL_FAILURE); } @@ -702,8 +677,6 @@ kgsl_mmu_map(gsl_mmu_t *mmu, gpuaddr_t gpubaseaddr, const gsl_scatterlist_t *sca status = GSL_FAILURE; } - GSL_MMU_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_mmu_map. Return value %B\n", GSL_SUCCESS ); return (status); @@ -740,12 +713,9 @@ kgsl_mmu_unmap(gsl_mmu_t *mmu, gpuaddr_t gpubaseaddr, int range, unsigned int pi numpages++; } - GSL_MMU_LOCK(); - pagetable = kgsl_mmu_getpagetableobject(mmu, pid); if (!pagetable) { - GSL_MMU_UNLOCK(); return (GSL_FAILURE); } @@ -797,8 +767,6 @@ kgsl_mmu_unmap(gsl_mmu_t *mmu, gpuaddr_t gpubaseaddr, int range, unsigned int pi // invalidate tlb, debug only KGSL_DEBUG(GSL_DBGFLAGS_MMU, mmu->device->ftbl.mmu_tlbinvalidate(mmu->device, gsl_cfg_mmu_reg[mmu->device->id-1].INVALIDATE, pagetable->pid)); - GSL_MMU_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_mmu_unmap. Return value %B\n", GSL_SUCCESS ); return (status); @@ -833,12 +801,9 @@ kgsl_mmu_getmap(gsl_mmu_t *mmu, gpuaddr_t gpubaseaddr, int range, gsl_scatterlis return (GSL_FAILURE); } - GSL_MMU_LOCK(); - pagetable = kgsl_mmu_getpagetableobject(mmu, pid); if (!pagetable) { - GSL_MMU_UNLOCK(); return (GSL_FAILURE); } @@ -872,8 +837,6 @@ kgsl_mmu_getmap(gsl_mmu_t *mmu, gpuaddr_t gpubaseaddr, int range, gsl_scatterlis scatterlist->pages[0] = GSL_PT_MAP_GETADDR(ptefirst); } - GSL_MMU_UNLOCK(); - scatterlist->contiguous = contiguous; return (GSL_SUCCESS); @@ -931,7 +894,7 @@ kgsl_mmu_close(gsl_device_t *device) kgsl_intr_detach(&device->intr, gsl_cfg_mh_intr[devindex].MMU_PAGE_FAULT); // disable MMU - kgsl_device_regwrite(device->id, gsl_cfg_mmu_reg[devindex].CONFIG, 0x00000000); + device->ftbl.device_regwrite(device, gsl_cfg_mmu_reg[devindex].CONFIG, 0x00000000); if (mmu->tlbflushfilter.base) { @@ -940,11 +903,9 @@ kgsl_mmu_close(gsl_device_t *device) if (mmu->dummyspace.gpuaddr) { - kgsl_sharedmem_free(&mmu->dummyspace); + kgsl_sharedmem_free0(&mmu->dummyspace, GSL_CALLER_PROCESSID_GET()); } - GSL_MMU_MUTEX_FREE(); - mmu->flags &= ~GSL_FLAGS_STARTED; mmu->flags &= ~GSL_FLAGS_INITIALIZED; mmu->flags &= ~GSL_FLAGS_INITIALIZED0; @@ -971,8 +932,6 @@ kgsl_mmu_attachcallback(gsl_mmu_t *mmu, unsigned int pid) kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "--> int kgsl_mmu_attachcallback(gsl_mmu_t *mmu=0x%08x, unsigned int pid=0x%08x)\n", mmu, pid ); - GSL_MMU_LOCK(); - if (mmu->flags & GSL_FLAGS_INITIALIZED0) { // attach to current device mmu @@ -993,8 +952,6 @@ kgsl_mmu_attachcallback(gsl_mmu_t *mmu, unsigned int pid) } } - GSL_MMU_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_mmu_attachcallback. Return value %B\n", status ); return (status); @@ -1013,8 +970,6 @@ kgsl_mmu_detachcallback(gsl_mmu_t *mmu, unsigned int pid) kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "--> int kgsl_mmu_detachcallback(gsl_mmu_t *mmu=0x%08x, unsigned int pid=0x%08x)\n", mmu, pid ); - GSL_MMU_LOCK(); - if (mmu->flags & GSL_FLAGS_INITIALIZED0) { // detach from current device mmu @@ -1035,8 +990,6 @@ kgsl_mmu_detachcallback(gsl_mmu_t *mmu, unsigned int pid) } } - GSL_MMU_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_mmu_detachcallback. Return value %B\n", status ); return (status); @@ -1052,8 +1005,6 @@ kgsl_mmu_querystats(gsl_mmu_t *mmu, gsl_mmustats_t *stats) KOS_ASSERT(stats); - GSL_MMU_LOCK(); - if (mmu->flags & GSL_FLAGS_STARTED) { kos_memcpy(stats, &mmu->stats, sizeof(gsl_mmustats_t)); @@ -1063,8 +1014,6 @@ kgsl_mmu_querystats(gsl_mmu_t *mmu, gsl_mmustats_t *stats) kos_memset(stats, 0, sizeof(gsl_mmustats_t)); } - GSL_MMU_UNLOCK(); - return (status); #else // unreferenced formal parameters diff --git a/drivers/mxc/amd-gpu/common/gsl_ringbuffer.c b/drivers/mxc/amd-gpu/common/gsl_ringbuffer.c index 2ccf58c5f2bc..c4b62b0174d2 100644 --- a/drivers/mxc/amd-gpu/common/gsl_ringbuffer.c +++ b/drivers/mxc/amd-gpu/common/gsl_ringbuffer.c @@ -87,7 +87,7 @@ kgsl_cp_intrcallback(gsl_intrid_t id, void *cookie) case GSL_INTR_YDX_CP_RESERVED_BIT_ERROR: case GSL_INTR_YDX_CP_IB_ERROR: - kgsl_device_destroy(rb->device); + rb->device->ftbl.device_destroy(rb->device); break; // non-error condition interrupt @@ -120,8 +120,6 @@ kgsl_ringbuffer_watchdog() if (rb->flags & GSL_FLAGS_STARTED) { - GSL_RB_MUTEX_LOCK(); - GSL_RB_GET_READPTR(rb, &rb->rptr); // ringbuffer is currently not empty @@ -137,7 +135,7 @@ kgsl_ringbuffer_watchdog() kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_FATAL, "ERROR: Watchdog detected core hung.\n" ); - kgsl_device_destroy(rb->device); + rb->device->ftbl.device_destroy(rb->device); return; } } @@ -152,7 +150,6 @@ kgsl_ringbuffer_watchdog() rb->watchdog.flags &= ~GSL_FLAGS_ACTIVE; } - GSL_RB_MUTEX_UNLOCK(); } kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_ringbuffer_watchdog.\n" ); @@ -350,16 +347,16 @@ kgsl_ringbuffer_submit(gsl_ringbuffer_t *rb) KOS_ASSERT(rb->wptr != 0); kgsl_device_active(rb->device); - + GSL_RB_UPDATE_WPTR_POLLING(rb); // send the wptr to the hw - kgsl_device_regwrite(rb->device->id, mmCP_RB_WPTR, rb->wptr); + rb->device->ftbl.device_regwrite(rb->device, mmCP_RB_WPTR, rb->wptr); // force wptr register to be updated do { - kgsl_device_regread(rb->device->id, mmCP_RB_WPTR, &value); + rb->device->ftbl.device_regread(rb->device, mmCP_RB_WPTR, &value); } while (value != rb->wptr); rb->flags |= GSL_FLAGS_ACTIVE; @@ -497,66 +494,66 @@ kgsl_ringbuffer_start(gsl_ringbuffer_t *rb) } // clear memptrs values - kgsl_sharedmem_set(&rb->memptrs_desc, 0, 0, sizeof(gsl_rbmemptrs_t)); + kgsl_sharedmem_set0(&rb->memptrs_desc, 0, 0, sizeof(gsl_rbmemptrs_t)); // clear ringbuffer - kgsl_sharedmem_set(&rb->buffer_desc, 0, 0x12341234, (rb->sizedwords << 2)); + kgsl_sharedmem_set0(&rb->buffer_desc, 0, 0x12341234, (rb->sizedwords << 2)); // setup WPTR polling address - kgsl_device_regwrite(device->id, mmCP_RB_WPTR_BASE, (rb->memptrs_desc.gpuaddr + GSL_RB_MEMPTRS_WPTRPOLL_OFFSET)); + device->ftbl.device_regwrite(device, mmCP_RB_WPTR_BASE, (rb->memptrs_desc.gpuaddr + GSL_RB_MEMPTRS_WPTRPOLL_OFFSET)); // setup WPTR delay - kgsl_device_regwrite(device->id, mmCP_RB_WPTR_DELAY, 0/*0x70000010*/); + device->ftbl.device_regwrite(device, mmCP_RB_WPTR_DELAY, 0/*0x70000010*/); // setup RB_CNTL - kgsl_device_regread(device->id, mmCP_RB_CNTL, (unsigned int *)&cp_rb_cntl); + device->ftbl.device_regread(device, mmCP_RB_CNTL, (unsigned int *)&cp_rb_cntl); cp_rb_cntl.f.rb_bufsz = gsl_ringbuffer_sizelog2quadwords(rb->sizedwords); // size of ringbuffer cp_rb_cntl.f.rb_blksz = rb->blksizequadwords; // quadwords to read before updating mem RPTR cp_rb_cntl.f.rb_poll_en = GSL_RB_CNTL_POLL_EN; // WPTR polling cp_rb_cntl.f.rb_no_update = GSL_RB_CNTL_NO_UPDATE; // mem RPTR writebacks - kgsl_device_regwrite(device->id, mmCP_RB_CNTL, cp_rb_cntl.val); + device->ftbl.device_regwrite(device, mmCP_RB_CNTL, cp_rb_cntl.val); // setup RB_BASE - kgsl_device_regwrite(device->id, mmCP_RB_BASE, rb->buffer_desc.gpuaddr); + device->ftbl.device_regwrite(device, mmCP_RB_BASE, rb->buffer_desc.gpuaddr); // setup RPTR_ADDR - kgsl_device_regwrite(device->id, mmCP_RB_RPTR_ADDR, rb->memptrs_desc.gpuaddr + GSL_RB_MEMPTRS_RPTR_OFFSET); + device->ftbl.device_regwrite(device, mmCP_RB_RPTR_ADDR, rb->memptrs_desc.gpuaddr + GSL_RB_MEMPTRS_RPTR_OFFSET); // explicitly clear all cp interrupts when running in safe mode if (rb->device->flags & GSL_FLAGS_SAFEMODE) { - kgsl_device_regwrite(device->id, mmCP_INT_ACK, 0xFFFFFFFF); + device->ftbl.device_regwrite(device, mmCP_INT_ACK, 0xFFFFFFFF); } // setup scratch/timestamp addr - kgsl_device_regwrite(device->id, mmSCRATCH_ADDR, device->memstore.gpuaddr + GSL_DEVICE_MEMSTORE_OFFSET(soptimestamp)); + device->ftbl.device_regwrite(device, mmSCRATCH_ADDR, device->memstore.gpuaddr + GSL_DEVICE_MEMSTORE_OFFSET(soptimestamp)); // setup scratch/timestamp mask - kgsl_device_regwrite(device->id, mmSCRATCH_UMSK, GSL_RB_MEMPTRS_SCRATCH_MASK); + device->ftbl.device_regwrite(device, mmSCRATCH_UMSK, GSL_RB_MEMPTRS_SCRATCH_MASK); // load the CP ucode - kgsl_device_regwrite(device->id, mmCP_DEBUG, 0x02000000); - kgsl_device_regwrite(device->id, mmCP_ME_RAM_WADDR, 0); + device->ftbl.device_regwrite(device, mmCP_DEBUG, 0x02000000); + device->ftbl.device_regwrite(device, mmCP_ME_RAM_WADDR, 0); for (i = 0; i < PM4_MICROCODE_SIZE; i++ ) { - kgsl_device_regwrite(device->id, mmCP_ME_RAM_DATA, aPM4_Microcode[i][0]); - kgsl_device_regwrite(device->id, mmCP_ME_RAM_DATA, aPM4_Microcode[i][1]); - kgsl_device_regwrite(device->id, mmCP_ME_RAM_DATA, aPM4_Microcode[i][2]); + device->ftbl.device_regwrite(device, mmCP_ME_RAM_DATA, aPM4_Microcode[i][0]); + device->ftbl.device_regwrite(device, mmCP_ME_RAM_DATA, aPM4_Microcode[i][1]); + device->ftbl.device_regwrite(device, mmCP_ME_RAM_DATA, aPM4_Microcode[i][2]); } // load the prefetch parser ucode - kgsl_device_regwrite(device->id, mmCP_PFP_UCODE_ADDR, 0); + device->ftbl.device_regwrite(device, mmCP_PFP_UCODE_ADDR, 0); for ( i = 0; i < PFP_MICROCODE_SIZE_NRT; i++ ) { - kgsl_device_regwrite(device->id, mmCP_PFP_UCODE_DATA, aPFP_Microcode_nrt[i]); + device->ftbl.device_regwrite(device, mmCP_PFP_UCODE_DATA, aPFP_Microcode_nrt[i]); } // queue thresholds ??? - kgsl_device_regwrite(device->id, mmCP_QUEUE_THRESHOLDS, 0x000C0804); + device->ftbl.device_regwrite(device, mmCP_QUEUE_THRESHOLDS, 0x000C0804); // reset pointers rb->rptr = 0; @@ -567,7 +564,7 @@ kgsl_ringbuffer_start(gsl_ringbuffer_t *rb) GSL_RB_INIT_TIMESTAMP(rb); // clear ME_HALT to start micro engine - kgsl_device_regwrite(device->id, mmCP_ME_CNTL, 0); + device->ftbl.device_regwrite(device, mmCP_ME_CNTL, 0); // ME_INIT cmds = kgsl_ringbuffer_addcmds(rb, 19); @@ -598,7 +595,7 @@ kgsl_ringbuffer_start(gsl_ringbuffer_t *rb) kgsl_ringbuffer_submit(rb); // idle device to validate ME INIT - status = kgsl_device_idle(device->id, GSL_TIMEOUT_DEFAULT); + status = device->ftbl.device_idle(device, GSL_TIMEOUT_DEFAULT); if (status == GSL_SUCCESS) { @@ -652,7 +649,7 @@ kgsl_ringbuffer_stop(gsl_ringbuffer_t *rb) kgsl_intr_detach(&rb->device->intr, GSL_INTR_YDX_CP_RING_BUFFER); // ME_HALT - kgsl_device_regwrite(rb->device->id, mmCP_ME_CNTL, 0x10000000); + rb->device->ftbl.device_regwrite(rb->device, mmCP_ME_CNTL, 0x10000000); rb->flags &= ~GSL_FLAGS_STARTED; } @@ -678,14 +675,12 @@ kgsl_ringbuffer_init(gsl_device_t *device) rb->sizedwords = (2 << gsl_cfg_rb_sizelog2quadwords); rb->blksizequadwords = gsl_cfg_rb_blksizequadwords; - GSL_RB_MUTEX_CREATE(); - // allocate memory for ringbuffer, needs to be double octword aligned // align on page from contiguous physical memory flags = (GSL_MEMFLAGS_ALIGNPAGE | GSL_MEMFLAGS_CONPHYS | GSL_MEMFLAGS_STRICTREQUEST); KGSL_DEBUG(GSL_DBGFLAGS_DUMPX, flags = (GSL_MEMFLAGS_ALIGNPAGE | GSL_MEMFLAGS_STRICTREQUEST)); /* set MMU table for ringbuffer */ - status = kgsl_sharedmem_alloc(device->id, flags, (rb->sizedwords << 2), &rb->buffer_desc); + status = kgsl_sharedmem_alloc0(device->id, flags, (rb->sizedwords << 2), &rb->buffer_desc); KGSL_DEBUG(GSL_DBGFLAGS_DUMPX, KGSL_DEBUG_DUMPX(BB_DUMP_RINGBUF_SET, (unsigned int)rb->buffer_desc.gpuaddr, (unsigned int)rb->buffer_desc.hostptr, 0, "kgsl_ringbuffer_init")); @@ -700,7 +695,7 @@ kgsl_ringbuffer_init(gsl_device_t *device) flags = (GSL_MEMFLAGS_ALIGN32 | GSL_MEMFLAGS_CONPHYS); KGSL_DEBUG(GSL_DBGFLAGS_DUMPX, flags = GSL_MEMFLAGS_ALIGN32); - status = kgsl_sharedmem_alloc(device->id, flags, sizeof(gsl_rbmemptrs_t), &rb->memptrs_desc); + status = kgsl_sharedmem_alloc0(device->id, flags, sizeof(gsl_rbmemptrs_t), &rb->memptrs_desc); if (status != GSL_SUCCESS) { @@ -742,29 +737,23 @@ kgsl_ringbuffer_close(gsl_ringbuffer_t *rb) kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_TRACE, "--> int kgsl_ringbuffer_close(gsl_ringbuffer_t *rb=0x%08x)\n", rb ); - GSL_RB_MUTEX_LOCK(); - // stop ringbuffer kgsl_ringbuffer_stop(rb); // free buffer if (rb->buffer_desc.hostptr) { - kgsl_sharedmem_free(&rb->buffer_desc); + kgsl_sharedmem_free0(&rb->buffer_desc, GSL_CALLER_PROCESSID_GET()); } // free memory pointers if (rb->memptrs_desc.hostptr) { - kgsl_sharedmem_free(&rb->memptrs_desc); + kgsl_sharedmem_free0(&rb->memptrs_desc, GSL_CALLER_PROCESSID_GET()); } rb->flags &= ~GSL_FLAGS_INITIALIZED; - GSL_RB_MUTEX_UNLOCK(); - - GSL_RB_MUTEX_FREE(); - kos_memset(rb, 0, sizeof(gsl_ringbuffer_t)); kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_ringbuffer_close. Return value %B\n", GSL_SUCCESS ); @@ -787,11 +776,8 @@ kgsl_ringbuffer_issuecmds(gsl_device_t *device, int pmodeoff, unsigned int *cmds "--> gsl_timestamp_t kgsl_ringbuffer_issuecmds(gsl_device_t *device=0x%08x, int pmodeoff=%d, unsigned int *cmds=0x%08x, int sizedwords=%d, unsigned int pid=0x%08x)\n", device, pmodeoff, cmds, sizedwords, pid ); - GSL_RB_MUTEX_LOCK(); - if (!(device->ringbuffer.flags & GSL_FLAGS_STARTED)) { - GSL_RB_MUTEX_UNLOCK(); return (0); } @@ -859,8 +845,6 @@ kgsl_ringbuffer_issuecmds(gsl_device_t *device, int pmodeoff, unsigned int *cmds GSL_RB_STATS(rb->stats.wordstotal += sizedwords); GSL_RB_STATS(rb->stats.issues++); - GSL_RB_MUTEX_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_COMMAND | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_ringbuffer_issuecmds. Return value %d\n", timestamp ); // return timestamp of issued commands @@ -890,7 +874,6 @@ kgsl_ringbuffer_issueibcmds(gsl_device_t *device, int drawctxt_index, gpuaddr_t KGSL_DEBUG(GSL_DBGFLAGS_DUMPX, dumpx_swap = kgsl_dumpx_parse_ibs(ibaddr, sizedwords)); - GSL_RB_MUTEX_LOCK(); // context switch if needed kgsl_drawctxt_switch(device, &device->drawctxt[drawctxt_index], flags); @@ -903,7 +886,7 @@ kgsl_ringbuffer_issueibcmds(gsl_device_t *device, int drawctxt_index, gpuaddr_t // idle device when running in safe mode if (device->flags & GSL_FLAGS_SAFEMODE) { - kgsl_device_idle(device->id, GSL_TIMEOUT_DEFAULT); + device->ftbl.device_idle(device, GSL_TIMEOUT_DEFAULT); } else { @@ -911,10 +894,9 @@ kgsl_ringbuffer_issueibcmds(gsl_device_t *device, int drawctxt_index, gpuaddr_t { // insert wait for idle after every IB1 // this is conservative but works reliably and is ok even for performance simulations - kgsl_device_idle(device->id, GSL_TIMEOUT_DEFAULT); + device->ftbl.device_idle(device, GSL_TIMEOUT_DEFAULT); }); } - GSL_RB_MUTEX_UNLOCK(); KGSL_DEBUG(GSL_DBGFLAGS_DUMPX, { if(dumpx_swap) @@ -940,19 +922,19 @@ kgsl_ringbuffer_debug(gsl_ringbuffer_t *rb, gsl_rb_debug_t *rb_debug) rb_debug->pm4_ucode_rel = PM4_MICROCODE_VERSION; rb_debug->pfp_ucode_rel = PFP_MICROCODE_VERSION; - kgsl_device_regread(rb->device->id, mmCP_RB_BASE, (unsigned int *)&rb_debug->cp_rb_base); - kgsl_device_regread(rb->device->id, mmCP_RB_CNTL, (unsigned int *)&rb_debug->cp_rb_cntl); - kgsl_device_regread(rb->device->id, mmCP_RB_RPTR_ADDR, (unsigned int *)&rb_debug->cp_rb_rptr_addr); - kgsl_device_regread(rb->device->id, mmCP_RB_RPTR, (unsigned int *)&rb_debug->cp_rb_rptr); - kgsl_device_regread(rb->device->id, mmCP_RB_WPTR, (unsigned int *)&rb_debug->cp_rb_wptr); - kgsl_device_regread(rb->device->id, mmCP_RB_WPTR_BASE, (unsigned int *)&rb_debug->cp_rb_wptr_base); - kgsl_device_regread(rb->device->id, mmSCRATCH_UMSK, (unsigned int *)&rb_debug->scratch_umsk); - kgsl_device_regread(rb->device->id, mmSCRATCH_ADDR, (unsigned int *)&rb_debug->scratch_addr); - kgsl_device_regread(rb->device->id, mmCP_ME_CNTL, (unsigned int *)&rb_debug->cp_me_cntl); - kgsl_device_regread(rb->device->id, mmCP_ME_STATUS, (unsigned int *)&rb_debug->cp_me_status); - kgsl_device_regread(rb->device->id, mmCP_DEBUG, (unsigned int *)&rb_debug->cp_debug); - kgsl_device_regread(rb->device->id, mmCP_STAT, (unsigned int *)&rb_debug->cp_stat); - kgsl_device_regread(rb->device->id, mmRBBM_STATUS, (unsigned int *)&rb_debug->rbbm_status); + rb->device->ftbl.device_regread(rb->device, mmCP_RB_BASE, (unsigned int *)&rb_debug->cp_rb_base); + rb->device->ftbl.device_regread(rb->device, mmCP_RB_CNTL, (unsigned int *)&rb_debug->cp_rb_cntl); + rb->device->ftbl.device_regread(rb->device, mmCP_RB_RPTR_ADDR, (unsigned int *)&rb_debug->cp_rb_rptr_addr); + rb->device->ftbl.device_regread(rb->device, mmCP_RB_RPTR, (unsigned int *)&rb_debug->cp_rb_rptr); + rb->device->ftbl.device_regread(rb->device, mmCP_RB_WPTR, (unsigned int *)&rb_debug->cp_rb_wptr); + rb->device->ftbl.device_regread(rb->device, mmCP_RB_WPTR_BASE, (unsigned int *)&rb_debug->cp_rb_wptr_base); + rb->device->ftbl.device_regread(rb->device, mmSCRATCH_UMSK, (unsigned int *)&rb_debug->scratch_umsk); + rb->device->ftbl.device_regread(rb->device, mmSCRATCH_ADDR, (unsigned int *)&rb_debug->scratch_addr); + rb->device->ftbl.device_regread(rb->device, mmCP_ME_CNTL, (unsigned int *)&rb_debug->cp_me_cntl); + rb->device->ftbl.device_regread(rb->device, mmCP_ME_STATUS, (unsigned int *)&rb_debug->cp_me_status); + rb->device->ftbl.device_regread(rb->device, mmCP_DEBUG, (unsigned int *)&rb_debug->cp_debug); + rb->device->ftbl.device_regread(rb->device, mmCP_STAT, (unsigned int *)&rb_debug->cp_stat); + rb->device->ftbl.device_regread(rb->device, mmRBBM_STATUS, (unsigned int *)&rb_debug->rbbm_status); rb_debug->sop_timestamp = kgsl_cmdstream_readtimestamp(rb->device->id, GSL_TIMESTAMP_CONSUMED); rb_debug->eop_timestamp = kgsl_cmdstream_readtimestamp(rb->device->id, GSL_TIMESTAMP_RETIRED); } @@ -1022,7 +1004,7 @@ kgsl_ringbuffer_bist(gsl_ringbuffer_t *rb) kgsl_ringbuffer_submit(rb); - status = kgsl_device_idle(rb->device->id, GSL_TIMEOUT_DEFAULT); + status = rb->device->ftbl.device_idle(rb->device, GSL_TIMEOUT_DEFAULT); if (status != GSL_SUCCESS) { @@ -1049,7 +1031,7 @@ kgsl_ringbuffer_bist(gsl_ringbuffer_t *rb) kgsl_ringbuffer_submit(rb); - status = kgsl_device_idle(rb->device->id, GSL_TIMEOUT_DEFAULT); + status = rb->device->ftbl.device_idle(rb->device, GSL_TIMEOUT_DEFAULT); if (status != GSL_SUCCESS) { @@ -1060,7 +1042,7 @@ kgsl_ringbuffer_bist(gsl_ringbuffer_t *rb) return (status); } - kgsl_device_regread(rb->device->id, mmSCRATCH_REG7, &temp); + rb->device->ftbl.device_regread(rb->device, mmSCRATCH_REG7, &temp); if (temp != 0xFEEDF00D) { @@ -1097,7 +1079,7 @@ kgsl_ringbuffer_bist(gsl_ringbuffer_t *rb) kgsl_ringbuffer_submit(rb); - status = kgsl_device_idle(rb->device->id, GSL_TIMEOUT_DEFAULT); + status = rb->device->ftbl.device_idle(rb->device, GSL_TIMEOUT_DEFAULT); if (status != GSL_SUCCESS) { @@ -1108,7 +1090,7 @@ kgsl_ringbuffer_bist(gsl_ringbuffer_t *rb) return (status); } - kgsl_device_regread(rb->device->id, mmSCRATCH_REG7, &temp); + rb->device->ftbl.device_regread(rb->device, mmSCRATCH_REG7, &temp); if (temp != k) { @@ -1137,7 +1119,7 @@ kgsl_ringbuffer_bist(gsl_ringbuffer_t *rb) kgsl_ringbuffer_submit(rb); - status = kgsl_device_idle(rb->device->id, GSL_TIMEOUT_DEFAULT); + status = rb->device->ftbl.device_idle(rb->device, GSL_TIMEOUT_DEFAULT); if (status != GSL_SUCCESS) { diff --git a/drivers/mxc/amd-gpu/common/gsl_sharedmem.c b/drivers/mxc/amd-gpu/common/gsl_sharedmem.c index 21835ed8d062..2892668d7c45 100644 --- a/drivers/mxc/amd-gpu/common/gsl_sharedmem.c +++ b/drivers/mxc/amd-gpu/common/gsl_sharedmem.c @@ -18,10 +18,6 @@ #include "gsl.h" #include "gsl_hal.h" -#if defined(_LINUX) && !defined(PAGE_SIZE) -#define PAGE_SIZE (1<<12) -#define PAGE_SHIFT (12) -#endif ///////////////////////////////////////////////////////////////////////////// // macros @@ -204,8 +200,8 @@ kgsl_sharedmem_close(gsl_sharedmem_t *shmem) //---------------------------------------------------------------------------- -KGSL_API int -kgsl_sharedmem_alloc(gsl_deviceid_t device_id, gsl_flags_t flags, int sizebytes, gsl_memdesc_t *memdesc) +int +kgsl_sharedmem_alloc0(gsl_deviceid_t device_id, gsl_flags_t flags, int sizebytes, gsl_memdesc_t *memdesc) { gsl_apertureid_t aperture_id; gsl_channelid_t channel_id; @@ -227,12 +223,9 @@ kgsl_sharedmem_alloc(gsl_deviceid_t device_id, gsl_flags_t flags, int sizebytes, kos_memset(memdesc, 0, sizeof(gsl_memdesc_t)); - GSL_API_MUTEX_LOCK(); - if (!(shmem->flags & GSL_FLAGS_INITIALIZED)) { kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_ERROR, "ERROR: Shared memory not initialized.\n" ); - GSL_API_MUTEX_UNLOCK(); kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_sharedmem_alloc. Return value %B\n", GSL_FAILURE ); return (GSL_FAILURE); } @@ -269,7 +262,6 @@ kgsl_sharedmem_alloc(gsl_deviceid_t device_id, gsl_flags_t flags, int sizebytes, else { kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_ERROR, "ERROR: Invalid device.\n" ); - GSL_API_MUTEX_UNLOCK(); kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_sharedmem_alloc. Return value %B\n", GSL_FAILURE ); return (GSL_FAILURE); } @@ -338,8 +330,6 @@ kgsl_sharedmem_alloc(gsl_deviceid_t device_id, gsl_flags_t flags, int sizebytes, } } - GSL_API_MUTEX_UNLOCK(); - if (result == GSL_SUCCESS) { GSL_MEMDESC_APERTURE_SET(memdesc, aperture_index); @@ -394,6 +384,18 @@ kgsl_sharedmem_alloc(gsl_deviceid_t device_id, gsl_flags_t flags, int sizebytes, //---------------------------------------------------------------------------- +KGSL_API int +kgsl_sharedmem_alloc(gsl_deviceid_t device_id, gsl_flags_t flags, int sizebytes, gsl_memdesc_t *memdesc) +{ + int status = GSL_SUCCESS; + GSL_API_MUTEX_LOCK(); + status = kgsl_sharedmem_alloc0(device_id, flags, sizebytes, memdesc); + GSL_API_MUTEX_UNLOCK(); + return status; +} + +//---------------------------------------------------------------------------- + int kgsl_sharedmem_free0(gsl_memdesc_t *memdesc, unsigned int pid) { @@ -407,8 +409,6 @@ kgsl_sharedmem_free0(gsl_memdesc_t *memdesc, unsigned int pid) GSL_MEMDESC_APERTURE_GET(memdesc, aperture_index); GSL_MEMDESC_DEVICE_GET(memdesc, device_id); - GSL_API_MUTEX_LOCK(); - shmem = &gsl_driver.shmem; if (shmem->flags & GSL_FLAGS_INITIALIZED) @@ -433,8 +433,6 @@ kgsl_sharedmem_free0(gsl_memdesc_t *memdesc, unsigned int pid) status = GSL_FAILURE; } - GSL_API_MUTEX_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_sharedmem_free. Return value %B\n", status ); return (status); @@ -445,13 +443,17 @@ kgsl_sharedmem_free0(gsl_memdesc_t *memdesc, unsigned int pid) KGSL_API int kgsl_sharedmem_free(gsl_memdesc_t *memdesc) { - return (kgsl_sharedmem_free0(memdesc, GSL_CALLER_PROCESSID_GET())); + int status = GSL_SUCCESS; + GSL_API_MUTEX_LOCK(); + status = kgsl_sharedmem_free0(memdesc, GSL_CALLER_PROCESSID_GET()); + GSL_API_MUTEX_UNLOCK(); + return status; } //---------------------------------------------------------------------------- -KGSL_API int -kgsl_sharedmem_read(const gsl_memdesc_t *memdesc, void *dst, unsigned int offsetbytes, unsigned int sizebytes, unsigned int touserspace) +int +kgsl_sharedmem_read0(const gsl_memdesc_t *memdesc, void *dst, unsigned int offsetbytes, unsigned int sizebytes, unsigned int touserspace) { int aperture_index; gsl_sharedmem_t *shmem; @@ -469,14 +471,11 @@ kgsl_sharedmem_read(const gsl_memdesc_t *memdesc, void *dst, unsigned int offset return (GSL_FAILURE_BADPARAM); } - GSL_API_MUTEX_LOCK(); - shmem = &gsl_driver.shmem; if (!(shmem->flags & GSL_FLAGS_INITIALIZED)) { kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_ERROR, "ERROR: Shared memory not initialized.\n" ); - GSL_API_MUTEX_UNLOCK(); kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_sharedmem_read. Return value %B\n", GSL_FAILURE ); return (GSL_FAILURE); } @@ -490,8 +489,6 @@ kgsl_sharedmem_read(const gsl_memdesc_t *memdesc, void *dst, unsigned int offset GSL_HAL_MEM_READ(dst, shmem->apertures[aperture_index].memarena->hostbaseaddr, gpuoffsetbytes, sizebytes, touserspace); - GSL_API_MUTEX_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_sharedmem_read. Return value %B\n", GSL_SUCCESS ); return (GSL_SUCCESS); @@ -500,7 +497,19 @@ kgsl_sharedmem_read(const gsl_memdesc_t *memdesc, void *dst, unsigned int offset //---------------------------------------------------------------------------- KGSL_API int -kgsl_sharedmem_write(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, void *src, unsigned int sizebytes, unsigned int fromuserspace) +kgsl_sharedmem_read(const gsl_memdesc_t *memdesc, void *dst, unsigned int offsetbytes, unsigned int sizebytes, unsigned int touserspace) +{ + int status = GSL_SUCCESS; + GSL_API_MUTEX_LOCK(); + status = kgsl_sharedmem_read0(memdesc, dst, offsetbytes, sizebytes, touserspace); + GSL_API_MUTEX_UNLOCK(); + return status; +} + +//---------------------------------------------------------------------------- + +int +kgsl_sharedmem_write0(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, void *src, unsigned int sizebytes, unsigned int fromuserspace) { int aperture_index; gsl_sharedmem_t *shmem; @@ -518,14 +527,11 @@ kgsl_sharedmem_write(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, voi return (GSL_FAILURE_BADPARAM); } - GSL_API_MUTEX_LOCK(); - shmem = &gsl_driver.shmem; if (!(shmem->flags & GSL_FLAGS_INITIALIZED)) { kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_ERROR, "ERROR: Shared memory not initialized.\n" ); - GSL_API_MUTEX_UNLOCK(); kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_sharedmem_write. Return value %B\n", GSL_FAILURE ); return (GSL_FAILURE); } @@ -543,8 +549,6 @@ kgsl_sharedmem_write(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, voi KGSL_DEBUG_TBDUMP_SYNCMEM( (memdesc->gpuaddr + offsetbytes), src, sizebytes ); - GSL_API_MUTEX_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_sharedmem_write. Return value %B\n", GSL_SUCCESS ); return (GSL_SUCCESS); @@ -553,7 +557,19 @@ kgsl_sharedmem_write(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, voi //---------------------------------------------------------------------------- KGSL_API int -kgsl_sharedmem_set(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, unsigned int value, unsigned int sizebytes) +kgsl_sharedmem_write(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, void *src, unsigned int sizebytes, unsigned int fromuserspace) +{ + int status = GSL_SUCCESS; + GSL_API_MUTEX_LOCK(); + status = kgsl_sharedmem_write0(memdesc, offsetbytes, src, sizebytes, fromuserspace); + GSL_API_MUTEX_UNLOCK(); + return status; +} + +//---------------------------------------------------------------------------- + +int +kgsl_sharedmem_set0(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, unsigned int value, unsigned int sizebytes) { int aperture_index; gsl_sharedmem_t *shmem; @@ -571,14 +587,11 @@ kgsl_sharedmem_set(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, unsig return (GSL_FAILURE_BADPARAM); } - GSL_API_MUTEX_LOCK(); - shmem = &gsl_driver.shmem; if (!(shmem->flags & GSL_FLAGS_INITIALIZED)) { kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_ERROR, "ERROR: Shared memory not initialized.\n" ); - GSL_API_MUTEX_UNLOCK(); kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_sharedmem_set. Return value %B\n", GSL_FAILURE ); return (GSL_FAILURE); } @@ -595,8 +608,6 @@ kgsl_sharedmem_set(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, unsig KGSL_DEBUG_TBDUMP_SETMEM( (memdesc->gpuaddr + offsetbytes), value, sizebytes ); - GSL_API_MUTEX_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_sharedmem_set. Return value %B\n", GSL_SUCCESS ); return (GSL_SUCCESS); @@ -604,6 +615,18 @@ kgsl_sharedmem_set(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, unsig //---------------------------------------------------------------------------- +KGSL_API int +kgsl_sharedmem_set(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, unsigned int value, unsigned int sizebytes) +{ + int status = GSL_SUCCESS; + GSL_API_MUTEX_LOCK(); + status = kgsl_sharedmem_set0(memdesc, offsetbytes, value, sizebytes); + GSL_API_MUTEX_UNLOCK(); + return status; +} + +//---------------------------------------------------------------------------- + KGSL_API unsigned int kgsl_sharedmem_largestfreeblock(gsl_deviceid_t device_id, gsl_flags_t flags) { @@ -665,8 +688,6 @@ kgsl_sharedmem_map(gsl_deviceid_t device_id, gsl_flags_t flags, const gsl_scatte "--> int kgsl_sharedmem_map(gsl_deviceid_t device_id=%D, gsl_flags_t flags=0x%08x, gsl_scatterlist_t scatterlist=%M, gsl_memdesc_t *memdesc=%M)\n", device_id, flags, memdesc, scatterlist ); - GSL_API_MUTEX_LOCK(); - // execute pending device action tmp_id = (device_id != GSL_DEVICE_ANY) ? device_id : device_id+1; for ( ; tmp_id <= GSL_DEVICE_MAX; tmp_id++) @@ -699,7 +720,6 @@ kgsl_sharedmem_map(gsl_deviceid_t device_id, gsl_flags_t flags, const gsl_scatte else { kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_ERROR, "ERROR: Invalid device.\n" ); - GSL_API_MUTEX_UNLOCK(); kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_sharedmem_map. Return value %B\n", GSL_FAILURE ); return (GSL_FAILURE); } @@ -735,8 +755,6 @@ kgsl_sharedmem_map(gsl_deviceid_t device_id, gsl_flags_t flags, const gsl_scatte } } - GSL_API_MUTEX_UNLOCK(); - kgsl_log_write( KGSL_LOG_GROUP_MEMORY | KGSL_LOG_LEVEL_TRACE, "<-- kgsl_sharedmem_map. Return value %B\n", status ); return (status); diff --git a/drivers/mxc/amd-gpu/common/gsl_yamato.c b/drivers/mxc/amd-gpu/common/gsl_yamato.c index 965220408060..d74c9efe2f36 100644 --- a/drivers/mxc/amd-gpu/common/gsl_yamato.c +++ b/drivers/mxc/amd-gpu/common/gsl_yamato.c @@ -52,7 +52,7 @@ kgsl_yamato_gmeminit(gsl_device_t *device) rb_edram_info.f.edram_mapping_mode = 0; // EDRAM_MAP_UPPER rb_edram_info.f.edram_range = (device->gmemspace.gpu_base >> 14); // must be aligned to size - kgsl_device_regwrite(device->id, mmRB_EDRAM_INFO, (unsigned int)rb_edram_info.val); + device->ftbl.device_regwrite(device, mmRB_EDRAM_INFO, (unsigned int)rb_edram_info.val); return (GSL_SUCCESS); } @@ -62,7 +62,7 @@ kgsl_yamato_gmeminit(gsl_device_t *device) static int kgsl_yamato_gmemclose(gsl_device_t *device) { - kgsl_device_regwrite(device->id, mmRB_EDRAM_INFO, 0x00000000); + device->ftbl.device_regwrite(device, mmRB_EDRAM_INFO, 0x00000000); return (GSL_SUCCESS); } @@ -79,7 +79,7 @@ kgsl_yamato_rbbmintrcallback(gsl_intrid_t id, void *cookie) // error condition interrupt case GSL_INTR_YDX_RBBM_READ_ERROR: - kgsl_device_destroy(device); + device->ftbl.device_destroy(device); break; // non-error condition interrupt @@ -189,15 +189,15 @@ kgsl_yamato_isr(gsl_device_t *device) #endif // DEBUG // determine if yamato is interrupting, and if so, which block - kgsl_device_regread(device->id, mmMASTER_INT_SIGNAL, &status); + device->ftbl.device_regread(device, mmMASTER_INT_SIGNAL, &status); if (status & MASTER_INT_SIGNAL__MH_INT_STAT) { #ifdef _DEBUG // obtain mh error information - kgsl_device_regread(device->id, mmMH_MMU_PAGE_FAULT, (unsigned int *)&page_fault); - kgsl_device_regread(device->id, mmMH_AXI_ERROR, (unsigned int *)&axi_error); - kgsl_device_regread(device->id, mmMH_CLNT_AXI_ID_REUSE, (unsigned int *)&clnt_axi_id_reuse); + device->ftbl.device_regread(device, mmMH_MMU_PAGE_FAULT, (unsigned int *)&page_fault); + device->ftbl.device_regread(device, mmMH_AXI_ERROR, (unsigned int *)&axi_error); + device->ftbl.device_regread(device, mmMH_CLNT_AXI_ID_REUSE, (unsigned int *)&clnt_axi_id_reuse); #endif // DEBUG kgsl_intr_decode(device, GSL_INTR_BLOCK_YDX_MH); @@ -212,7 +212,7 @@ kgsl_yamato_isr(gsl_device_t *device) { #ifdef _DEBUG // obtain rbbm error information - kgsl_device_regread(device->id, mmRBBM_READ_ERROR, (unsigned int *)&read_error); + device->ftbl.device_regread(device, mmRBBM_READ_ERROR, (unsigned int *)&read_error); #endif // DEBUG kgsl_intr_decode(device, GSL_INTR_BLOCK_YDX_RBBM); @@ -248,7 +248,7 @@ kgsl_yamato_tlbinvalidate(gsl_device_t *device, unsigned int reg_invalidate, uns else { - kgsl_device_regwrite(device->id, reg_invalidate, mh_mmu_invalidate.val); + device->ftbl.device_regwrite(device, reg_invalidate, mh_mmu_invalidate.val); } return (GSL_SUCCESS); @@ -307,9 +307,8 @@ kgsl_yamato_setpagetable(gsl_device_t *device, unsigned int reg_ptbase, gpuaddr_ } else { - kgsl_device_idle(device->id, GSL_TIMEOUT_DEFAULT); - - kgsl_device_regwrite(device->id, reg_ptbase, ptbase); + device->ftbl.device_idle(device, GSL_TIMEOUT_DEFAULT); + device->ftbl.device_regwrite(device, reg_ptbase, ptbase); } return (GSL_SUCCESS); @@ -329,29 +328,29 @@ kgsl_yamato_init(gsl_device_t *device) //We need to make sure all blocks are powered up and clocked before //issuing a soft reset. The overrides will be turned off (set to 0) //later in kgsl_yamato_start. - kgsl_device_regwrite(device->id, mmRBBM_PM_OVERRIDE1, 0xfffffffe); - kgsl_device_regwrite(device->id, mmRBBM_PM_OVERRIDE2, 0xffffffff); + device->ftbl.device_regwrite(device, mmRBBM_PM_OVERRIDE1, 0xfffffffe); + device->ftbl.device_regwrite(device, mmRBBM_PM_OVERRIDE2, 0xffffffff); // soft reset - kgsl_device_regwrite(device->id, mmRBBM_SOFT_RESET, 0xFFFFFFFF); + device->ftbl.device_regwrite(device, mmRBBM_SOFT_RESET, 0xFFFFFFFF); kos_sleep(50); - kgsl_device_regwrite(device->id, mmRBBM_SOFT_RESET, 0x00000000); + device->ftbl.device_regwrite(device, mmRBBM_SOFT_RESET, 0x00000000); // RBBM control - kgsl_device_regwrite(device->id, mmRBBM_CNTL, 0x00004442); + device->ftbl.device_regwrite(device, mmRBBM_CNTL, 0x00004442); // setup MH arbiter - kgsl_device_regwrite(device->id, mmMH_ARBITER_CONFIG, *(unsigned int *) &gsl_cfg_yamato_mharb); + device->ftbl.device_regwrite(device, mmMH_ARBITER_CONFIG, *(unsigned int *) &gsl_cfg_yamato_mharb); // SQ_*_PROGRAM - kgsl_device_regwrite(device->id, mmSQ_VS_PROGRAM, 0x00000000); - kgsl_device_regwrite(device->id, mmSQ_PS_PROGRAM, 0x00000000); + device->ftbl.device_regwrite(device, mmSQ_VS_PROGRAM, 0x00000000); + device->ftbl.device_regwrite(device, mmSQ_PS_PROGRAM, 0x00000000); // init interrupt status = kgsl_intr_init(device); if (status != GSL_SUCCESS) { - kgsl_device_stop(device->id); + device->ftbl.device_stop(device); return (status); } @@ -359,7 +358,7 @@ kgsl_yamato_init(gsl_device_t *device) status = kgsl_mmu_init(device); if (status != GSL_SUCCESS) { - kgsl_device_stop(device->id); + device->ftbl.device_stop(device); return (status); } @@ -409,7 +408,7 @@ kgsl_yamato_destroy(gsl_device_t *device) pid = device->callerprocess[i]; if (pid) { - kgsl_device_stop(device->id); + device->ftbl.device_stop(device); kgsl_driver_destroy(pid); // todo: terminate client process? @@ -436,8 +435,8 @@ kgsl_yamato_start(gsl_device_t *device, gsl_flags_t flags) // default power management override when running in safe mode pm1 = (device->flags & GSL_FLAGS_SAFEMODE) ? 0xFFFFFFFE : 0x00000000; pm2 = (device->flags & GSL_FLAGS_SAFEMODE) ? 0x000000FF : 0x00000000; - kgsl_device_regwrite(device->id, mmRBBM_PM_OVERRIDE1, pm1); - kgsl_device_regwrite(device->id, mmRBBM_PM_OVERRIDE2, pm2); + device->ftbl.device_regwrite(device, mmRBBM_PM_OVERRIDE1, pm1); + device->ftbl.device_regwrite(device, mmRBBM_PM_OVERRIDE2, pm2); // enable rbbm interrupts kgsl_intr_attach(&device->intr, GSL_INTR_YDX_RBBM_READ_ERROR, kgsl_yamato_rbbmintrcallback, (void *) device); @@ -465,7 +464,7 @@ kgsl_yamato_start(gsl_device_t *device, gsl_flags_t flags) status = kgsl_ringbuffer_init(device); if (status != GSL_SUCCESS) { - kgsl_device_stop(device->id); + device->ftbl.device_stop(device); return (status); } @@ -473,7 +472,7 @@ kgsl_yamato_start(gsl_device_t *device, gsl_flags_t flags) status = kgsl_drawctxt_init(device); if (status != GSL_SUCCESS) { - kgsl_device_stop(device->id); + device->ftbl.device_stop(device); return (status); } @@ -570,13 +569,13 @@ kgsl_yamato_setproperty(gsl_device_t *device, gsl_property_type_t type, void *va { if (power->flags & GSL_PWRFLAGS_OVERRIDE_ON) { - kgsl_device_regwrite(device->id, mmRBBM_PM_OVERRIDE1, 0xfffffffe); - kgsl_device_regwrite(device->id, mmRBBM_PM_OVERRIDE2, 0xffffffff); + device->ftbl.device_regwrite(device, mmRBBM_PM_OVERRIDE1, 0xfffffffe); + device->ftbl.device_regwrite(device, mmRBBM_PM_OVERRIDE2, 0xffffffff); } else if (power->flags & GSL_PWRFLAGS_OVERRIDE_OFF) { - kgsl_device_regwrite(device->id, mmRBBM_PM_OVERRIDE1, 0x00000000); - kgsl_device_regwrite(device->id, mmRBBM_PM_OVERRIDE2, 0x00000000); + device->ftbl.device_regwrite(device, mmRBBM_PM_OVERRIDE1, 0x00000000); + device->ftbl.device_regwrite(device, mmRBBM_PM_OVERRIDE2, 0x00000000); } else { @@ -730,10 +729,7 @@ kgsl_yamato_idle(gsl_device_t *device, unsigned int timeout) (void) timeout; // unreferenced formal parameter - KGSL_DEBUG(GSL_DBGFLAGS_DUMPX, KGSL_DEBUG_DUMPX(BB_DUMP_REGPOLL, device->id, mmRBBM_STATUS, 0x80000000, "kgsl_device_idle")); - - GSL_RB_MUTEX_LOCK(); - GSL_API_MUTEX_UNLOCK(); + KGSL_DEBUG(GSL_DBGFLAGS_DUMPX, KGSL_DEBUG_DUMPX(BB_DUMP_REGPOLL, device->id, mmRBBM_STATUS, 0x80000000, "kgsl_yamato_idle")); // first, wait until the CP has consumed all the commands in the ring buffer if (rb->flags & GSL_FLAGS_STARTED) @@ -748,7 +744,7 @@ kgsl_yamato_idle(gsl_device_t *device, unsigned int timeout) // now, wait for the GPU to finish its operations for ( ; ; ) { - kgsl_device_regread(device->id, mmRBBM_STATUS, (unsigned int *)&rbbm_status); + device->ftbl.device_regread(device, mmRBBM_STATUS, (unsigned int *)&rbbm_status); if (!(rbbm_status.val & 0x80000000)) { @@ -758,9 +754,6 @@ kgsl_yamato_idle(gsl_device_t *device, unsigned int timeout) } - GSL_API_MUTEX_LOCK(); - GSL_RB_MUTEX_UNLOCK(); - return (status); } @@ -798,7 +791,7 @@ kgsl_yamato_regwrite(gsl_device_t *device, unsigned int offsetwords, unsigned in // idle device when running in safe mode if (device->flags & GSL_FLAGS_SAFEMODE) { - kgsl_device_idle(device->id, GSL_TIMEOUT_DEFAULT); + device->ftbl.device_idle(device, GSL_TIMEOUT_DEFAULT); } return (GSL_SUCCESS); @@ -816,18 +809,14 @@ kgsl_yamato_waitirq(gsl_device_t *device, gsl_intrid_t intr_id, unsigned int *co { if (kgsl_intr_isenabled(&device->intr, intr_id) == GSL_SUCCESS) { - GSL_API_MUTEX_UNLOCK(); - // wait until intr completion event is received if (kos_event_wait(device->intr.evnt[intr_id], timeout) == OS_SUCCESS) { - GSL_API_MUTEX_LOCK(); *count = 1; status = GSL_SUCCESS; } else { - GSL_API_MUTEX_LOCK(); status = GSL_FAILURE_TIMEOUT; } } diff --git a/drivers/mxc/amd-gpu/include/gsl_cmdstream.h b/drivers/mxc/amd-gpu/include/gsl_cmdstream.h index 652b3750f193..550d5d0005ab 100644 --- a/drivers/mxc/amd-gpu/include/gsl_cmdstream.h +++ b/drivers/mxc/amd-gpu/include/gsl_cmdstream.h @@ -37,13 +37,13 @@ #ifdef VG_HDK #define GSL_CMDSTREAM_GET_SOP_TIMESTAMP(device, data) #else -#define GSL_CMDSTREAM_GET_SOP_TIMESTAMP(device, data) kgsl_sharedmem_read(&device->memstore, (data), GSL_DEVICE_MEMSTORE_OFFSET(soptimestamp), 4, false) +#define GSL_CMDSTREAM_GET_SOP_TIMESTAMP(device, data) kgsl_sharedmem_read0(&device->memstore, (data), GSL_DEVICE_MEMSTORE_OFFSET(soptimestamp), 4, false) #endif #ifdef VG_HDK #define GSL_CMDSTREAM_GET_EOP_TIMESTAMP(device, data) (*((int*)data) = (gsl_driver.device[GSL_DEVICE_G12-1]).timestamp) #else -#define GSL_CMDSTREAM_GET_EOP_TIMESTAMP(device, data) kgsl_sharedmem_read(&device->memstore, (data), GSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp), 4, false) +#define GSL_CMDSTREAM_GET_EOP_TIMESTAMP(device, data) kgsl_sharedmem_read0(&device->memstore, (data), GSL_DEVICE_MEMSTORE_OFFSET(eoptimestamp), 4, false) #endif @@ -54,6 +54,7 @@ ////////////////////////////////////////////////////////////////////////////// // functions ////////////////////////////////////////////////////////////////////////////// +gsl_timestamp_t kgsl_cmdstream_readtimestamp0(gsl_deviceid_t device_id, gsl_timestamp_type_t type); void kgsl_cmdstream_memqueue_drain(gsl_device_t *device); int kgsl_cmdstream_init(gsl_device_t *device); int kgsl_cmdstream_close(gsl_device_t *device); diff --git a/drivers/mxc/amd-gpu/include/gsl_cmdwindow.h b/drivers/mxc/amd-gpu/include/gsl_cmdwindow.h index 93ecf8220244..0152dd75a631 100644 --- a/drivers/mxc/amd-gpu/include/gsl_cmdwindow.h +++ b/drivers/mxc/amd-gpu/include/gsl_cmdwindow.h @@ -46,5 +46,6 @@ ////////////////////////////////////////////////////////////////////////////// int kgsl_cmdwindow_init(gsl_device_t *device); int kgsl_cmdwindow_close(gsl_device_t *device); +int kgsl_cmdwindow_write0(gsl_deviceid_t device_id, gsl_cmdwindow_t target, unsigned int addr, unsigned int data); #endif // __GSL_CMDWINDOW_H diff --git a/drivers/mxc/amd-gpu/include/gsl_device.h b/drivers/mxc/amd-gpu/include/gsl_device.h index 3276e6ffb717..433dc6963dfd 100644 --- a/drivers/mxc/amd-gpu/include/gsl_device.h +++ b/drivers/mxc/amd-gpu/include/gsl_device.h @@ -91,14 +91,12 @@ struct _gsl_device_t { #ifdef GSL_BLD_YAMATO gsl_memregion_t gmemspace; gsl_ringbuffer_t ringbuffer; - oshandle_t drawctxt_mutex; unsigned int drawctxt_count; gsl_drawctxt_t *drawctxt_active; gsl_drawctxt_t drawctxt[GSL_CONTEXT_MAX]; #endif // GSL_BLD_YAMATO #ifdef GSL_BLD_G12 - oshandle_t cmdwindow_mutex; unsigned int intrcnt[GSL_G12_INTR_COUNT]; gsl_timestamp_t current_timestamp; gsl_timestamp_t timestamp; @@ -110,7 +108,6 @@ struct _gsl_device_t { oshandle_t irqthread_event; #endif #endif // GSL_BLD_G12 - oshandle_t cmdstream_mutex; #ifndef _LINUX oshandle_t timestamp_event; #else diff --git a/drivers/mxc/amd-gpu/include/gsl_mmu.h b/drivers/mxc/amd-gpu/include/gsl_mmu.h index e894cb7dc822..868c5156f290 100644 --- a/drivers/mxc/amd-gpu/include/gsl_mmu.h +++ b/drivers/mxc/amd-gpu/include/gsl_mmu.h @@ -135,7 +135,6 @@ typedef struct _gsl_tlbflushfilter_t { // mmu object // ---------- typedef struct _gsl_mmu_t { - oshandle_t mutex; unsigned int refcnt; gsl_flags_t flags; gsl_device_t *device; diff --git a/drivers/mxc/amd-gpu/include/gsl_ringbuffer.h b/drivers/mxc/amd-gpu/include/gsl_ringbuffer.h index d4bdf34c0bae..6081c396f6e4 100644 --- a/drivers/mxc/amd-gpu/include/gsl_ringbuffer.h +++ b/drivers/mxc/amd-gpu/include/gsl_ringbuffer.h @@ -137,8 +137,6 @@ typedef struct _gsl_ringbuffer_t { gsl_device_t *device; gsl_flags_t flags; - oshandle_t mutex; - gsl_memdesc_t buffer_desc; // allocated memory descriptor gsl_memdesc_t memptrs_desc; @@ -165,19 +163,6 @@ typedef struct _gsl_ringbuffer_t { // macros ////////////////////////////////////////////////////////////////////////////// -#ifdef GSL_LOCKING_FINEGRAIN -#define GSL_RB_MUTEX_CREATE() rb->mutex = kos_mutex_create("gsl_ringbuffer"); \ - if (!rb->mutex) {return (GSL_FAILURE);} -#define GSL_RB_MUTEX_LOCK() kos_mutex_lock(rb->mutex) -#define GSL_RB_MUTEX_UNLOCK() kos_mutex_unlock(rb->mutex) -#define GSL_RB_MUTEX_FREE() kos_mutex_free(rb->mutex); rb->mutex = 0; -#else -#define GSL_RB_MUTEX_CREATE() -#define GSL_RB_MUTEX_LOCK() -#define GSL_RB_MUTEX_UNLOCK() -#define GSL_RB_MUTEX_FREE() -#endif - // ---------- // ring write // ---------- @@ -206,10 +191,10 @@ typedef struct _gsl_ringbuffer_t { // -------- #ifdef GSL_RB_USE_MEM_RPTR #define GSL_RB_CNTL_NO_UPDATE 0x0 // enable -#define GSL_RB_GET_READPTR(rb, data) kgsl_sharedmem_read(&(rb)->memptrs_desc, (data), GSL_RB_MEMPTRS_RPTR_OFFSET, 4, false) +#define GSL_RB_GET_READPTR(rb, data) kgsl_sharedmem_read0(&(rb)->memptrs_desc, (data), GSL_RB_MEMPTRS_RPTR_OFFSET, 4, false) #else #define GSL_RB_CNTL_NO_UPDATE 0x1 // disable -#define GSL_RB_GET_READPTR(rb, data) kgsl_device_regread((rb)->device->id, mmCP_RB_RPTR,(data)) +#define GSL_RB_GET_READPTR(rb, data) (rb)->device->fbtl.device_regread((rb)->device, mmCP_RB_RPTR,(data)) #endif // GSL_RB_USE_MEMRPTR // ------------ diff --git a/drivers/mxc/amd-gpu/include/gsl_sharedmem.h b/drivers/mxc/amd-gpu/include/gsl_sharedmem.h index 1cb2d659d9e1..bb9692cc1e44 100644 --- a/drivers/mxc/amd-gpu/include/gsl_sharedmem.h +++ b/drivers/mxc/amd-gpu/include/gsl_sharedmem.h @@ -48,7 +48,6 @@ #define GSL_APERTURE_GETHOSTADDR(shmem, aperture_index) \ shmem.apertures[aperture_index].memarena->hostbaseaddr; - ////////////////////////////////////////////////////////////////////////////// // types ////////////////////////////////////////////////////////////////////////////// @@ -100,7 +99,11 @@ typedef struct _gsl_sharedmem_t ////////////////////////////////////////////////////////////////////////////// int kgsl_sharedmem_init(gsl_sharedmem_t *shmem); int kgsl_sharedmem_close(gsl_sharedmem_t *shmem); +int kgsl_sharedmem_alloc0(gsl_deviceid_t device_id, gsl_flags_t flags, int sizebytes, gsl_memdesc_t *memdesc); int kgsl_sharedmem_free0(gsl_memdesc_t *memdesc, unsigned int pid); +int kgsl_sharedmem_read0(const gsl_memdesc_t *memdesc, void *dst, unsigned int offsetbytes, unsigned int sizebytes, unsigned int touserspace); +int kgsl_sharedmem_write0(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, void *src, unsigned int sizebytes, unsigned int fromuserspace); +int kgsl_sharedmem_set0(const gsl_memdesc_t *memdesc, unsigned int offsetbytes, unsigned int value, unsigned int sizebytes); int kgsl_sharedmem_querystats(gsl_sharedmem_t *shmem, gsl_sharedmem_stats_t *stats); unsigned int kgsl_sharedmem_convertaddr(unsigned int addr, int type); diff --git a/drivers/mxc/amd-gpu/os/kernel/include/kos_libapi.h b/drivers/mxc/amd-gpu/os/kernel/include/kos_libapi.h index 6042b25765f7..a02c396c22a9 100644 --- a/drivers/mxc/amd-gpu/os/kernel/include/kos_libapi.h +++ b/drivers/mxc/amd-gpu/os/kernel/include/kos_libapi.h @@ -57,9 +57,9 @@ extern "C" { // KOS lib entrypoints ////////////////////////////////////////////////////////////////////////////// #ifdef __KOSLIB_EXPORTS -#define KOS_API extern //KOS_DLLEXPORT +#define KOS_API KOS_DLLEXPORT #else -#define KOS_API extern //KOS_DLLIMPORT +#define KOS_API KOS_DLLIMPORT #endif // __KOSLIB_EXPORTS ////////////////////////////////////////////////////////////////////////////// @@ -79,16 +79,12 @@ KOS_API void kos_assert_hook(const char* file, int line, int //#include <assert.h> //#define KOS_ASSERT(expression) assert(expression) #define KOS_ASSERT(expression) /**/ -#elif defined(_LINUX) -#include <assert.h> -#define KOS_ASSERT(expression) //BUG_ON(!(expression)); -#error KOS_ASSERT DEFINED, FINALLY! #elif defined(__ARM__) #define KOS_ASSERT(expression) -#endif // _WIN32 _WIN32_WCE - #elif defined(_LINUX) - #define KOS_ASSERT(expression) //kos_assert_hook(__FILE__, __LINE__, (int)(expression)); +#define KOS_ASSERT(expression) //kos_assert_hook(__FILE__, __LINE__, (int)(expression)) +#endif + #else #define KOS_ASSERT(expression) @@ -381,7 +377,7 @@ KOS_API unsigned int kos_strtoul(const char* nptr, char** endptr, int base); * \param void* name Name string for the new mutex. * \return Returns a handle to the mutex. *//*-------------------------------------------------------------------*/ -KOS_API oshandle_t kos_mutex_create(char* name); +KOS_API oshandle_t kos_mutex_create(const char* name); /*-------------------------------------------------------------------*//*! * \external * \brief Get a handle to an already existing mutex. @@ -390,7 +386,7 @@ KOS_API oshandle_t kos_mutex_create(char* name); * \param void* name Name string for the new mutex. * \return Returns a handle to the mutex. *//*-------------------------------------------------------------------*/ -KOS_API oshandle_t kos_mutex_open(char* name); +KOS_API oshandle_t kos_mutex_open(const char* name); /*-------------------------------------------------------------------*//*! * \external * \brief Free the given mutex. diff --git a/drivers/mxc/amd-gpu/os/kernel/src/linux/kos_lib.c b/drivers/mxc/amd-gpu/os/kernel/src/linux/kos_lib.c index f3271ddcad37..4ead84ffe0dc 100644 --- a/drivers/mxc/amd-gpu/os/kernel/src/linux/kos_lib.c +++ b/drivers/mxc/amd-gpu/os/kernel/src/linux/kos_lib.c @@ -23,7 +23,8 @@ #include <linux/limits.h> #include <linux/delay.h> #include <linux/dma-mapping.h> -#include <linux/semaphore.h> +#include <linux/mutex.h> +#include <asm/atomic.h> #include <asm/current.h> #include <linux/sched.h> #include <linux/jiffies.h> @@ -33,40 +34,26 @@ ////////////////////////////////////////////////////////////////////////////// // defines ////////////////////////////////////////////////////////////////////////////// -#define KOS_STATS_ENABLE -#define _CRT_SECURE_NO_DEPRECATE - +//#define KOS_STATS_ENABLE ////////////////////////////////////////////////////////////////////////////// -// includes +// macros ////////////////////////////////////////////////////////////////////////////// -#define __KOSLIB_EXPORTS - - #define KOS_MALLOC(s) kmalloc(s, GFP_KERNEL) #define KOS_CALLOC(num, size) kcalloc(num, size, GFP_KERNEL) #define KOS_REALLOC(p, s) krealloc(p, s, GFP_KERNEL) #define KOS_FREE(p) kfree(p); p = 0 #define KOS_DBGFLAGS_SET(flag) - ////////////////////////////////////////////////////////////////////////////// // stats ////////////////////////////////////////////////////////////////////////////// - #ifdef KOS_STATS_ENABLE - os_stats_t kos_stats = {0, 0, 0, 0, 0, 0, 0, 0}; - #define KOS_STATS(x) x - #else #define KOS_STATS(x) -#endif // KOS_STATS_ENABLE - - -extern unsigned int get_current_fd(void); // QUICK HACK - +#endif ////////////////////////////////////////////////////////////////////////////// // assert API @@ -242,10 +229,7 @@ KOS_API int kos_alloc_physical(void** virt_addr, void** phys_addr, int pages) { *virt_addr = dma_alloc_coherent(NULL, pages*PAGE_SIZE, (dma_addr_t*)*phys_addr, GFP_DMA | GFP_KERNEL); - if(*virt_addr == NULL) - printk(KERN_ERR "%s:dma_alloc_coherent error:pages=%d\n", __func__, pages); - - return OS_SUCCESS; + return *virt_addr ? OS_SUCCESS : OS_FAILURE; } //---------------------------------------------------------------------------- @@ -359,77 +343,39 @@ kos_strlen(const char* string) return strlen(string); } -//---------------------------------------------------------------------------- -#if 0 -KOS_API int -kos_atoi(const char* string) -{ - return atoi(string); -} - -//---------------------------------------------------------------------------- - -KOS_API unsigned int -kos_strtoul(const char* nptr, char** endptr, int base) -{ - return (unsigned int)strtoul(nptr, endptr, base); -} -#endif - - ////////////////////////////////////////////////////////////////////////////// // sync API ////////////////////////////////////////////////////////////////////////////// -#define kos_mutex_get(mutexhandle, mutex) \ - if (!mutexhandle) return (OS_FAILURE); \ - mutex = (struct mutex *)mutexhandle; - -//---------------------------------------------------------------------------- - -oshandle_t -kos_mutex_create(char* name) +KOS_API oshandle_t +kos_mutex_create(const char *name) { - struct mutex *mutex; - - mutex = kos_malloc(sizeof(struct mutex)); - KOS_ASSERT(mutex); - if (!mutex) return (OS_HANDLE_NULL); - - mutex_init(mutex); - - KOS_STATS(kos_stats.objects_alloc++); - - return (oshandle_t)mutex; + struct mutex *mutex = KOS_MALLOC(sizeof(struct mutex)); + if (!mutex) + return 0; + mutex_init(mutex); + return mutex; } //---------------------------------------------------------------------------- -/* + KOS_API oshandle_t -kos_mutex_open(char* name) +kos_mutex_open(const char *name) { - // only for inter-process mutexes - if (name == NULL) - return (OS_HANDLE_NULL); - - return (kos_mutex_create(name)); + // not implemented + return 0; } -*/ //---------------------------------------------------------------------------- KOS_API int kos_mutex_free(oshandle_t mutexhandle) { - struct mutex *mutex; - kos_mutex_get(mutexhandle, mutex); - - KOS_ASSERT(mutex); - kos_free(mutex); - - KOS_STATS(kos_stats.objects_free++); - - return (OS_SUCCESS); + struct mutex *mutex = (struct mutex *)mutexhandle; + if (!mutex) + return OS_FAILURE; + KOS_FREE(mutex); + return OS_SUCCESS; } //---------------------------------------------------------------------------- @@ -437,13 +383,12 @@ kos_mutex_free(oshandle_t mutexhandle) KOS_API int kos_mutex_lock(oshandle_t mutexhandle) { - struct mutex *mutex; - kos_mutex_get(mutexhandle, mutex); - - KOS_ASSERT(mutex); - mutex_lock(mutex); - - return (OS_SUCCESS); + struct mutex *mutex = (struct mutex *)mutexhandle; + if (!mutex) + return OS_FAILURE; + if (mutex_lock_interruptible(mutex) == -EINTR) + return OS_FAILURE; + return OS_SUCCESS; } //---------------------------------------------------------------------------- @@ -451,125 +396,37 @@ kos_mutex_lock(oshandle_t mutexhandle) KOS_API int kos_mutex_locktry(oshandle_t mutexhandle) { - struct mutex *mutex; - kos_mutex_get(mutexhandle, mutex); - - KOS_ASSERT(mutex); - return mutex_trylock(mutex); + struct mutex *mutex = (struct mutex *)mutexhandle; + if (!mutex) + return OS_FAILURE; + if (!mutex_trylock(mutex)) + return OS_FAILURE; + return OS_SUCCESS; } //---------------------------------------------------------------------------- -#if 0 -KOS_API int -kos_mutex_lockwait(oshandle_t mutexhandle, int millisecondstowait) -{ - struct mutex *mutex; - kos_mutex_get(mutexhandle, mutex); - - if (mutex->named) - { - DWORD result; - - if (millisecondstowait == OS_INFINITE) millisecondstowait = INFINITE; - - result = WaitForSingleObject(mutex->handle, millisecondstowait); - - if (result != WAIT_OBJECT_0) return (OS_FAILURE); - } - else - { - // WTF???? windows does not have this but wince50 does?? - //BOOL result; - //result = TryEnterCriticalSection(mutex->critical_section); - //if (!result) return (OS_FAILURE); - EnterCriticalSection(&mutex->critical_section); - } - - return (OS_SUCCESS); -} -#endif -//---------------------------------------------------------------------------- KOS_API int kos_mutex_unlock(oshandle_t mutexhandle) { - struct mutex *mutex; - kos_mutex_get(mutexhandle, mutex); - - KOS_ASSERT(mutex); - mutex_unlock(mutex); - - return (OS_SUCCESS); -} - -KOS_API unsigned int -kos_process_getid(void) -{ -return get_current_fd(); -// return current->pid; -} - -//---------------------------------------------------------------------------- -#if 0 -KOS_API int -kos_interlock_incr(int* ptr) -{ - int retval; - - retval = InterlockedIncrement((LONG*)ptr); - - return (retval); -} - -//---------------------------------------------------------------------------- - -KOS_API int -kos_interlock_decr(int* ptr) -{ - int retval; - - retval = InterlockedDecrement((LONG*)ptr); - - return (retval); -} - -//---------------------------------------------------------------------------- - -KOS_API int -kos_interlock_xchg(int* ptr, int value) -{ - int retval; - - retval = InterlockedExchange((LONG*)ptr, value); - - return (retval); + struct mutex *mutex = (struct mutex *)mutexhandle; + if (!mutex) + return OS_FAILURE; + KOS_ASSERT(mutex_is_locked(mutex)); + mutex_unlock(mutex); + return OS_SUCCESS; } //---------------------------------------------------------------------------- -KOS_API int -kos_interlock_compxchg(int* ptr, int value, int compvalue) +KOS_API unsigned int +kos_process_getid(void) { - int retval; - - retval = InterlockedCompareExchange((LONG*)ptr, value, compvalue); - - return ((int)retval); + return current->tgid; } //---------------------------------------------------------------------------- -KOS_API int -kos_interlock_xchgadd(int* ptr, int value) -{ - int retval; - - retval = InterlockedExchangeAdd((LONG*)ptr, value); - - return (retval); -} -#endif - /* ------------------------------------------------------------------- *//* * \brief Creates new event semaphore * \param uint32 a_manualReset @@ -667,114 +524,6 @@ kos_event_wait(oshandle_t a_event, int a_milliSeconds) return (OS_SUCCESS); } -#if 0 -////////////////////////////////////////////////////////////////////////////// -// interrupt handler API -////////////////////////////////////////////////////////////////////////////// -KOS_API int -kos_interrupt_enable(int interrupt) -{ - (void) interrupt; // unreferenced formal parameter - KOS_ASSERT(0); // not implemented - - return (OS_SUCCESS); -} - -//---------------------------------------------------------------------------- - -KOS_API int -kos_interrupt_disable(int interrupt) -{ - (void) interrupt; // unreferenced formal parameter - KOS_ASSERT(0); // not implemented - - return (OS_SUCCESS); -} - -//---------------------------------------------------------------------------- - -KOS_API int -kos_interrupt_setcallback(int interrupt, void* handler) -{ - - KOS_ASSERT(handler); - - (void) interrupt; // unreferenced formal parameter - (void) handler; // unreferenced formal parameter - KOS_ASSERT(0); // not implemented - - return (OS_SUCCESS); -} - -//---------------------------------------------------------------------------- - -KOS_API int -kos_interrupt_clearcallback(int interrupt, void* handler) -{ - KOS_ASSERT(handler); - - (void) interrupt; // unreferenced formal parameter - (void) handler; // unreferenced formal parameter - KOS_ASSERT(0); // not implemented - - return (OS_SUCCESS); -} - - -////////////////////////////////////////////////////////////////////////////// -// thread and process API -////////////////////////////////////////////////////////////////////////////// -KOS_API unsigned int -kos_tls_alloc(void) -{ - DWORD index; - index = TlsAlloc(); - - if (index == TLS_OUT_OF_INDEXES) return (OS_TLS_OUTOFINDEXES); - - return (index); -} - -//---------------------------------------------------------------------------- - -KOS_API int -kos_tls_free(unsigned int tlsindex) -{ - BOOL result; - - result = TlsFree(tlsindex); - - if (!result) return (OS_FAILURE); - return (OS_SUCCESS); -} - -//---------------------------------------------------------------------------- - -KOS_API void* -kos_tls_read(unsigned int tlsindex) -{ - void* value; - - value = TlsGetValue(tlsindex); - - return (value); -} - -//---------------------------------------------------------------------------- - -KOS_API int -kos_tls_write(unsigned int tlsindex, void* tlsvalue) -{ - BOOL result; - - result = TlsSetValue(tlsindex, tlsvalue); - - if (!result) return (OS_FAILURE); - return (OS_SUCCESS); -} - -#endif - //---------------------------------------------------------------------------- KOS_API void @@ -783,112 +532,6 @@ kos_sleep(unsigned int milliseconds) msleep(milliseconds); } -#if 0 -//---------------------------------------------------------------------------- - -KOS_API unsigned int -kos_process_getid(void) -{ - DWORD id; - - id = GetCurrentProcessId(); - - return(id); -} - -//---------------------------------------------------------------------------- - -KOS_API unsigned int -kos_thread_getid(void) -{ - DWORD id; - - id = GetCurrentThreadId(); - - return (id); -} - - -////////////////////////////////////////////////////////////////////////////// -// timing API -////////////////////////////////////////////////////////////////////////////// -KOS_API unsigned int -kos_timestamp(void) -{ - unsigned int milliseconds; - - milliseconds = GetTickCount(); - - return (milliseconds); -} - - -////////////////////////////////////////////////////////////////////////////// -// libary API -////////////////////////////////////////////////////////////////////////////// -KOS_API oshandle_t -kos_lib_map(char* libraryname) -{ - kos_library_t* lib; - HMODULE module; - - KOS_ASSERT(libraryname); - - module = LoadLibrary(libraryname); - - if (!module) return (OS_HANDLE_NULL); - - lib = (kos_library_t*)kos_malloc(sizeof(kos_library_t)); - - if (!lib) - { - FreeLibrary(module); - return (OS_HANDLE_NULL); - } - - lib->module = module; - - KOS_STATS(kos_stats.objects_alloc++); - - return (oshandle_t) lib; -} - -//---------------------------------------------------------------------------- - -KOS_API int -kos_lib_unmap(oshandle_t libhandle) -{ - BOOL result; - kos_library_t* lib = (kos_library_t*)libhandle; - - KOS_ASSERT(lib); - - result = FreeLibrary(lib->module); - - kos_free(lib); - - KOS_STATS(kos_stats.objects_free++); - - if (!result) return (OS_FAILURE); - return (OS_SUCCESS); -} - -//---------------------------------------------------------------------------- - -KOS_API void* -kos_lib_getaddr(oshandle_t libhandle, char* procname) -{ - FARPROC procaddr; - kos_library_t* lib = (kos_library_t*)libhandle; - - KOS_ASSERT(lib); - - procaddr = GetProcAddress(lib->module, procname); - - return (void*)procaddr; -} -#endif - ////////////////////////////////////////////////////////////////////////////// // query API ////////////////////////////////////////////////////////////////////////////// @@ -932,7 +575,7 @@ kos_get_sysinfo(os_sysinfo_t* sysinfo) //---------------------------------------------------------------------------- -#ifdef KOS_STATS +#ifdef KOS_STATS_ENABLE KOS_API int kos_get_stats(os_stats_t* stats) { @@ -943,7 +586,7 @@ kos_get_stats(os_stats_t* stats) KOS_API int kos_get_stats(os_stats_t* stats) { - return (KOS_NOTSUPPORTED); + return (OS_FAILURE); } #endif // KOS_STATS diff --git a/drivers/mxc/amd-gpu/platform/hal/MX35/gsl_buildconfig.h b/drivers/mxc/amd-gpu/platform/hal/MX35/gsl_buildconfig.h index 49e61b527191..9cfe9fe5b3b8 100644 --- a/drivers/mxc/amd-gpu/platform/hal/MX35/gsl_buildconfig.h +++ b/drivers/mxc/amd-gpu/platform/hal/MX35/gsl_buildconfig.h @@ -31,7 +31,7 @@ #define GSL_BLD_G12 -//#define GSL_LOCKING_COURSEGRAIN +#define GSL_LOCKING_COURSEGRAIN #define GSL_MMU_TRANSLATION_ENABLED //#define GSL_MMU_PAGETABLE_PERPROCESS diff --git a/drivers/mxc/amd-gpu/platform/hal/MX35/linux/gsl_hal.c b/drivers/mxc/amd-gpu/platform/hal/MX35/linux/gsl_hal.c index dbe52501b25a..294cd9eb5af9 100644 --- a/drivers/mxc/amd-gpu/platform/hal/MX35/linux/gsl_hal.c +++ b/drivers/mxc/amd-gpu/platform/hal/MX35/linux/gsl_hal.c @@ -453,6 +453,7 @@ kgsl_hal_getplatformtype(char *platform) KGSLHAL_API int kgsl_hal_setpowerstate(gsl_deviceid_t device_id, int state, unsigned int value) { + gsl_device_t *device = &gsl_driver.device[device_id-1]; // device_id is 1 based struct clk *gpu_clk = 0; // unreferenced formal parameters @@ -473,15 +474,15 @@ kgsl_hal_setpowerstate(gsl_deviceid_t device_id, int state, unsigned int value) switch (state) { case GSL_PWRFLAGS_CLK_ON: - break; + break; case GSL_PWRFLAGS_POWER_ON: clk_enable(gpu_clk); kgsl_device_autogate_init(&gsl_driver.device[device_id-1]); break; case GSL_PWRFLAGS_CLK_OFF: - break; + break; case GSL_PWRFLAGS_POWER_OFF: - if (kgsl_device_idle(device_id, GSL_TIMEOUT_DEFAULT) != GSL_SUCCESS) + if (device->ftbl.device_idle(device, GSL_TIMEOUT_DEFAULT) != GSL_SUCCESS) { return (GSL_FAILURE_DEVICEERROR); } diff --git a/drivers/mxc/amd-gpu/platform/hal/MX51/gsl_buildconfig.h b/drivers/mxc/amd-gpu/platform/hal/MX51/gsl_buildconfig.h index 4b1ff9445e83..82824f511d5e 100644 --- a/drivers/mxc/amd-gpu/platform/hal/MX51/gsl_buildconfig.h +++ b/drivers/mxc/amd-gpu/platform/hal/MX51/gsl_buildconfig.h @@ -32,7 +32,7 @@ #define GSL_BLD_YAMATO #define GSL_BLD_G12 -//#define GSL_LOCKING_COURSEGRAIN +#define GSL_LOCKING_COURSEGRAIN #define GSL_STATS_MEM #define GSL_STATS_RINGBUFFER diff --git a/drivers/mxc/amd-gpu/platform/hal/MX51/linux/gsl_hal.c b/drivers/mxc/amd-gpu/platform/hal/MX51/linux/gsl_hal.c index e39c2b4d6fba..965416b59ec1 100644 --- a/drivers/mxc/amd-gpu/platform/hal/MX51/linux/gsl_hal.c +++ b/drivers/mxc/amd-gpu/platform/hal/MX51/linux/gsl_hal.c @@ -462,18 +462,19 @@ kgsl_hal_getdevconfig(gsl_deviceid_t device_id, gsl_devconfig_t *config) KGSLHAL_API gsl_chipid_t kgsl_hal_getchipid(gsl_deviceid_t device_id) { + gsl_device_t *device = &gsl_driver.device[device_id-1]; gsl_chipid_t chipid; unsigned int coreid, majorid, minorid, patchid, revid; // YDX - kgsl_device_regread(device_id, mmRBBM_PERIPHID1, &coreid); + device->ftbl.device_regread(device, mmRBBM_PERIPHID1, &coreid); coreid &= 0xF; // 2. - kgsl_device_regread(device_id, mmRBBM_PERIPHID2, &majorid); + device->ftbl.device_regread(device, mmRBBM_PERIPHID2, &majorid); majorid = (majorid >> 4) & 0xF; - kgsl_device_regread(device_id, mmRBBM_PATCH_RELEASE, &revid); + device->ftbl.device_regread(device, mmRBBM_PATCH_RELEASE, &revid); // 2. minorid = ((revid >> 0) & 0xFF); // this is a 16bit field, but extremely unlikely it would ever get this high @@ -507,6 +508,7 @@ kgsl_hal_getplatformtype(char *platform) KGSLHAL_API int kgsl_hal_setpowerstate(gsl_deviceid_t device_id, int state, unsigned int value) { + gsl_device_t *device = &gsl_driver.device[device_id-1]; struct clk *gpu_clk = 0; struct clk *garb_clk = clk_get(0, "garb_clk"); struct clk *emi_garb_clk = clk_get(0, "emi_garb_clk"); @@ -542,7 +544,7 @@ kgsl_hal_setpowerstate(gsl_deviceid_t device_id, int state, unsigned int value) case GSL_PWRFLAGS_CLK_OFF: break; case GSL_PWRFLAGS_POWER_OFF: - if (kgsl_device_idle(device_id, GSL_TIMEOUT_DEFAULT) != GSL_SUCCESS) + if (device->ftbl.device_idle(device, GSL_TIMEOUT_DEFAULT) != GSL_SUCCESS) { return (GSL_FAILURE_DEVICEERROR); } diff --git a/drivers/mxc/amd-gpu/platform/hal/linux/gsl_kmod.c b/drivers/mxc/amd-gpu/platform/hal/linux/gsl_kmod.c index 28339699f7d5..8af59c77b381 100644 --- a/drivers/mxc/amd-gpu/platform/hal/linux/gsl_kmod.c +++ b/drivers/mxc/amd-gpu/platform/hal/linux/gsl_kmod.c @@ -15,7 +15,7 @@ * 02110-1301, USA. * */ - + #include "gsl_types.h" #include "gsl.h" #include "gsl_buildconfig.h" @@ -34,12 +34,10 @@ #include <asm/uaccess.h> #include <linux/mm.h> #include <linux/mutex.h> -#include <linux/platform_device.h>
-#include <linux/vmalloc.h>
+#include <linux/cdev.h> -static int gsl_kmod_major; // TODO: move to gsl_kmod_data -static struct vm_operations_struct gsl_kmod_vmops = {0}; -DEFINE_MUTEX(gsl_mutex); // TODO: move to gsl_kmod_data? +#include <linux/platform_device.h> +#include <linux/vmalloc.h> static int gpu_2d_irq, gpu_3d_irq; @@ -51,27 +49,133 @@ int gmem_size; phys_addr_t gpu_reserved_mem; int gpu_reserved_mem_size; -/* structure to hold kernel module specific data. */ -struct gsl_kmod_data +static ssize_t gsl_kmod_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr); +static ssize_t gsl_kmod_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr); +static int gsl_kmod_ioctl(struct inode *inode, struct file *fd, unsigned int cmd, unsigned long arg); +static int gsl_kmod_mmap(struct file *fd, struct vm_area_struct *vma); +static int gsl_kmod_fault(struct vm_area_struct *vma, struct vm_fault *vmf); +static int gsl_kmod_open(struct inode *inode, struct file *fd); +static int gsl_kmod_release(struct inode *inode, struct file *fd); +static irqreturn_t z160_irq_handler(int irq, void *dev_id); +#if defined(MX51) +static irqreturn_t z430_irq_handler(int irq, void *dev_id); +#endif + +static int gsl_kmod_major; +static struct class *gsl_kmod_class; +DEFINE_MUTEX(gsl_mutex); + +static const struct file_operations gsl_kmod_fops = +{ + .owner = THIS_MODULE, + .read = gsl_kmod_read, + .write = gsl_kmod_write, + .ioctl = gsl_kmod_ioctl, + .mmap = gsl_kmod_mmap, + .open = gsl_kmod_open, + .release = gsl_kmod_release +}; + +static struct vm_operations_struct gsl_kmod_vmops = { -// unsigned int major; - struct device *device; - /* stores the current open file descriptor during user process calls. - * It's a hack but in Linux the upper level driver cannot track processes - * as they are unique in Linux and not represent thread group as in WinCE. - */ - struct file *current_fd; + .fault = gsl_kmod_fault, }; -static struct gsl_kmod_data gsl_kmod_data = {0}; +static int __init gsl_kmod_init(void) +{ + struct device *dev; + + if (kgsl_driver_init() != GSL_SUCCESS) + { + printk(KERN_ERR "%s: kgsl_driver_init error\n", __func__); + goto kgsl_driver_init_error; + } + +#if defined(MX51) + if (request_irq(MX51_YDX_INTERRUPT, z430_irq_handler, 0, "ydx", NULL) < 0) + { + printk(KERN_ERR "%s: request_irq error\n", __func__); + goto request_irq_error; + } +#endif + +#if defined(MX51) + if (request_irq(MX51_G12_INTERRUPT, z160_irq_handler, 0, "g12", NULL) < 0) +#elif defined(MX35) + if (request_irq(MX35_G12_INTERRUPT, z160_irq_handler, 0, "g12", NULL) < 0) +#endif + { + printk(KERN_ERR "%s: request_irq error\n", __func__); + goto request_irq_error; + } + + gsl_kmod_major = register_chrdev(0, "gsl_kmod", &gsl_kmod_fops); + gsl_kmod_vmops.fault = gsl_kmod_fault; + + if (gsl_kmod_major <= 0) + { + pr_err("%s: register_chrdev error\n", __func__); + goto register_chrdev_error; + } + + gsl_kmod_class = class_create(THIS_MODULE, "gsl_kmod"); + + if (IS_ERR(gsl_kmod_class)) + { + pr_err("%s: class_create error\n", __func__); + goto class_create_error; + } + + #if(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)) + dev = device_create(gsl_kmod_class, NULL, MKDEV(gsl_kmod_major, 0), "gsl_kmod"); + #else + dev = device_create(gsl_kmod_class, NULL, MKDEV(gsl_kmod_major, 0), NULL,"gsl_kmod"); + #endif + + if (!IS_ERR(dev)) + { + return 0; + } + + pr_err("%s: device_create error\n", __func__); + +class_create_error: + class_destroy(gsl_kmod_class); + +register_chrdev_error: + unregister_chrdev(gsl_kmod_major, "gsl_kmod"); -static unsigned int current_fd; +request_irq_error: +kgsl_driver_init_error: + kgsl_driver_close(); + return 0; // TODO: return proper error code +} -unsigned int get_current_fd(void) +static void __exit gsl_kmod_exit(void) { - return current_fd; + device_destroy(gsl_kmod_class, MKDEV(gsl_kmod_major, 0)); + class_destroy(gsl_kmod_class); + unregister_chrdev(gsl_kmod_major, "gsl_kmod"); +#if defined(MX51) + free_irq(MX51_YDX_INTERRUPT, NULL); + free_irq(MX51_G12_INTERRUPT, NULL); +#elif defined(MX35) + free_irq(MX35_G12_INTERRUPT, NULL); +#endif + kgsl_driver_close(); } +module_init(gsl_kmod_init); +module_exit(gsl_kmod_exit); + +MODULE_AUTHOR("Advanced Micro Devices"); +#if defined(MX51) +MODULE_DESCRIPTION("AMD 2D/3D graphics core driver for i.MX51"); +#elif defined(MX35) +MODULE_DESCRIPTION("AMD 2D graphics core driver for i.MX35"); +#endif +MODULE_LICENSE("GPL v2"); + static ssize_t gsl_kmod_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr) { return 0; @@ -86,12 +190,6 @@ static int gsl_kmod_ioctl(struct inode *inode, struct file *fd, unsigned int cmd { int kgslStatus = GSL_FAILURE; - if(mutex_lock_interruptible(&gsl_mutex)) - { - return -EINTR; - } - current_fd = (unsigned int)fd; - switch (cmd) { case IOCTL_KGSL_DEVICE_START: { @@ -502,7 +600,7 @@ static int gsl_kmod_ioctl(struct inode *inode, struct file *fd, unsigned int cmd { printk(KERN_ERR "%s: kgsl_sharedmem_write failed\n", __func__); } - + break; } case IOCTL_KGSL_SHAREDMEM_SET: @@ -603,6 +701,7 @@ static int gsl_kmod_ioctl(struct inode *inode, struct file *fd, unsigned int cmd kgslStatus = GSL_SUCCESS; break; } + case IOCTL_KGSL_DEVICE_CLOCK: { kgsl_device_clock_t param; @@ -620,10 +719,6 @@ static int gsl_kmod_ioctl(struct inode *inode, struct file *fd, unsigned int cmd break; } - current_fd = 0; - - mutex_unlock(&gsl_mutex); - return kgslStatus; } @@ -639,13 +734,6 @@ static int gsl_kmod_mmap(struct file *fd, struct vm_area_struct *vma) void *va; #endif - if(mutex_lock_interruptible(&gsl_mutex)) - { - return -EINTR; - } - - current_fd = (unsigned int)fd; - #ifdef GSL_MMU_TRANSLATION_ENABLED if (addr < GSL_LINUX_MAP_RANGE_END && addr >= GSL_LINUX_MAP_RANGE_START) { @@ -654,8 +742,6 @@ static int gsl_kmod_mmap(struct file *fd, struct vm_area_struct *vma) { if (remap_pfn_range(vma, start, vmalloc_to_pfn(va), PAGE_SIZE, prot)) { - current_fd = 0; - mutex_unlock(&gsl_mutex); return -EAGAIN; } start += PAGE_SIZE; @@ -674,16 +760,9 @@ static int gsl_kmod_mmap(struct file *fd, struct vm_area_struct *vma) vma->vm_ops = &gsl_kmod_vmops; - current_fd = 0; - - mutex_unlock(&gsl_mutex); - return status; } -/* we install fault handler here to signal bus error if user tries to access - * outside of VMA. - */ static int gsl_kmod_fault(struct vm_area_struct *vma, struct vm_fault *vmf) { return VM_FAULT_SIGBUS; @@ -700,8 +779,6 @@ static int gsl_kmod_open(struct inode *inode, struct file *fd) return -EINTR; } - current_fd = (unsigned int)fd; - if (kgsl_driver_entry(flags) != GSL_SUCCESS) { printk(KERN_INFO "%s: kgsl_driver_entry error\n", __func__); @@ -726,8 +803,6 @@ static int gsl_kmod_open(struct inode *inode, struct file *fd) } } - current_fd = 0; - mutex_unlock(&gsl_mutex); return err; @@ -743,8 +818,6 @@ static int gsl_kmod_release(struct inode *inode, struct file *fd) return -EINTR; } - current_fd = (unsigned int)fd; - /* make sure contexts are destroyed */ del_all_devices_contexts(fd); @@ -762,8 +835,6 @@ static int gsl_kmod_release(struct inode *inode, struct file *fd) fd->private_data = 0; } - current_fd = 0; - mutex_unlock(&gsl_mutex); return err; @@ -771,17 +842,6 @@ static int gsl_kmod_release(struct inode *inode, struct file *fd) static struct class *gsl_kmod_class; -static const struct file_operations gsl_kmod_fops = -{ - .owner = THIS_MODULE, - .read = gsl_kmod_read, - .write = gsl_kmod_write, - .ioctl = gsl_kmod_ioctl, - .mmap = gsl_kmod_mmap, - .open = gsl_kmod_open, - .release = gsl_kmod_release -}; - static irqreturn_t z160_irq_handler(int irq, void *dev_id) { kgsl_intr_isr(); @@ -891,7 +951,7 @@ static int gpu_probe(struct platform_device *pdev) if (!IS_ERR(dev)) { - gsl_kmod_data.device = dev; + // gsl_kmod_data.device = dev; return 0; } @@ -987,20 +1047,6 @@ static struct platform_driver gpu_driver = { .resume = gpu_resume, }; -static int __init gsl_kmod_init(void) -{ - int ret = platform_driver_register(&gpu_driver); - - return ret; -} - -static void __exit gsl_kmod_exit(void) -{ - platform_driver_unregister(&gpu_driver); -} - -module_init(gsl_kmod_init); -module_exit(gsl_kmod_exit); MODULE_AUTHOR("Advanced Micro Devices Inc."); #if defined(MX51) diff --git a/drivers/mxc/amd-gpu/platform/hal/linux/gsl_kmod_cleanup.c b/drivers/mxc/amd-gpu/platform/hal/linux/gsl_kmod_cleanup.c index 3947aa38795f..3685a5756baf 100644 --- a/drivers/mxc/amd-gpu/platform/hal/linux/gsl_kmod_cleanup.c +++ b/drivers/mxc/amd-gpu/platform/hal/linux/gsl_kmod_cleanup.c @@ -15,7 +15,7 @@ * 02110-1301, USA. * */ - + #include "gsl.h" #include "gsl_kmod_cleanup.h" @@ -173,8 +173,8 @@ int del_all_memblocks_from_allocated_list(struct file *fd) printk(KERN_INFO "Not all allocated memory blocks were freed. Doing it now.\n"); list_for_each_entry_safe(cursor, next, head, node) { + printk(KERN_INFO "Freeing list entry #%u, gpuaddr=%x\n", (u32)cursor->allocation_number, cursor->allocated_block.gpuaddr); kgsl_sharedmem_free(&cursor->allocated_block); - printk(KERN_INFO "Freeing list entry #%u\n", (u32)cursor->allocation_number); list_del(&cursor->node); kfree(cursor); } |