Bool VIV2DGPUCtxInit(GALINFOPTR galInfo) { TRACE_ENTER(); static gctBOOL inited = gcvFALSE; gctBOOL ret = gcvFALSE; gctPOINTER mHandle = gcvNULL; VIVGPUPtr gpuctx = NULL; gceSTATUS status = gcvSTATUS_OK; if (inited) { TRACE_EXIT(TRUE); } if (galInfo->mGpu != NULL) { TRACE_ERROR("UNDEFINED GPU CTX\n"); TRACE_EXIT(FALSE); } status = gcoOS_Allocate(gcvNULL, sizeof (VIVGPU), &mHandle); if (status < 0) { TRACE_ERROR("Unable to allocate driver, status = %d\n", status); TRACE_EXIT(FALSE); } gpuctx = (VIVGPUPtr) (mHandle); ret = SetupDriver(&gpuctx->mDriver); if (ret != gcvTRUE) { TRACE_ERROR("GPU DRIVER FAILED\n"); TRACE_EXIT(FALSE); } ret = SetupDevice(&(gpuctx->mDevice), gpuctx->mDriver); if (ret != gcvTRUE) { TRACE_ERROR("GPU DEVICE INIT FAILED\n"); TRACE_EXIT(FALSE); } inited = gcvTRUE; galInfo->mGpu = gpuctx; TRACE_EXIT(TRUE); }
/** * * @param device - to be created * @param driver - driver to use the device * @return - status of creation */ static gctBOOL SetupDevice ( OUT Viv2DDevicePtr * device, IN Viv2DDriverPtr driver ) { TRACE_ENTER(); gceSTATUS status = gcvSTATUS_OK; Viv2DDevicePtr pDeviceHandle; gctPOINTER mHandle = gcvNULL; /*assertions*/ gcmASSERT(driver != gcvNULL); gcmASSERT(*device == gcvNULL); /*Allocation*/ status = gcoOS_Allocate(gcvNULL, sizeof (Viv2DDevice), &mHandle); if (status < 0) { TRACE_ERROR("Unable to allocate driver, status = %d\n", status); TRACE_EXIT(gcvFALSE); } pDeviceHandle = (Viv2DDevicePtr) mHandle; /*Query*/ status = gcoHAL_QueryChipIdentity(driver->mHal, &pDeviceHandle->mChipModel, &pDeviceHandle->mChipRevision, &pDeviceHandle->mChipFeatures, &pDeviceHandle->mChipMinorFeatures); if (status != gcvSTATUS_OK) { TRACE_ERROR("Unable to query chip Info, status = %d\n", status); TRACE_EXIT(gcvFALSE); } *device = pDeviceHandle; TRACE_EXIT(gcvTRUE); }
gceSTATUS vgsMEMORYMANAGER_Construct( IN gcoOS Os, IN gctUINT ItemSize, IN gctUINT Granularity, OUT vgsMEMORYMANAGER_PTR * Manager ) { gceSTATUS status; vgsMEMORYMANAGER_PTR manager = gcvNULL; gcmHEADER_ARG("Os=0x%x ItemSize=0x%x Granularity=0x%x Manager=0x%x", Os, ItemSize, Granularity, Manager); gcmVERIFY_ARGUMENT(ItemSize > 0); gcmVERIFY_ARGUMENT(Granularity > 0); gcmVERIFY_ARGUMENT(Manager != gcvNULL); do { gctUINT itemSize; gctUINT allocationSize; /* Allocate the memory manager structure. */ gcmERR_BREAK(gcoOS_Allocate( Os, gcmSIZEOF(vgsMEMORYMANAGER), (gctPOINTER *) &manager )); /* Determine the size of the item. */ itemSize = gcmSIZEOF(vgsMEMORYITEM) + ItemSize; /* Determine the allocation size. */ allocationSize = gcmSIZEOF(vgsMEMORYITEM) + Granularity * itemSize; /* Initialize the structure. */ manager->os = Os; manager->allocationSize = allocationSize; manager->itemCount = Granularity; manager->itemSize = itemSize; manager->firstAllocated = gcvNULL; manager->firstFree = gcvNULL; #if vgvVALIDATE_MEMORY_MANAGER manager->allocatedCount = 0; manager->maximumAllocated = 0; manager->allocatedBufferCount = 0; #endif /* Set the result pointer. */ * Manager = manager; } while (gcvNULL); gcmFOOTER(); /* Return status. */ return status; }
static gctBOOL ReadSource( IN gcoOS Os, IN gctCONST_STRING FileName, OUT gctSIZE_T * SourceSize, OUT gctSTRING * Source ) { gceSTATUS status; gctFILE file; gctUINT32 count; gctSIZE_T byteRead; gctSTRING source; gcmASSERT(FileName); status = gcoOS_Open(Os, FileName, gcvFILE_READ, &file); if (gcmIS_ERROR(status)) { printf("*ERROR* Failed to open input file: %s\n", FileName); return gcvFALSE; } gcmVERIFY_OK(gcoOS_Seek(Os, file, 0, gcvFILE_SEEK_END)); gcmVERIFY_OK(gcoOS_GetPos(Os, file, &count)); status = gcoOS_Allocate(Os, count + 1, (gctPOINTER *) &source); if (!gcmIS_SUCCESS(status)) { printf("*ERROR* Not enough memory\n"); gcmVERIFY_OK(gcoOS_Close(Os, file)); return gcvFALSE; } gcmVERIFY_OK(gcoOS_SetPos(Os, file, 0)); status = gcoOS_Read(Os, file, count, source, &byteRead); if (!gcmIS_SUCCESS(status) || byteRead != count) { printf("*ERROR* Failed to open input file: %s\n", FileName); gcmVERIFY_OK(gcoOS_Close(Os, file)); return gcvFALSE; } source[count] = '\0'; gcmVERIFY_OK(gcoOS_Close(Os, file)); *SourceSize = count; *Source = source; return gcvTRUE; }
static gctBOOL OutputShaderData( IN gcoOS Os, IN gctCONST_STRING FileName, IN gctSIZE_T Size, IN gctCONST_STRING Data ) { gceSTATUS status; gctSTRING dataFileName; gctSIZE_T length; gctFILE file; gcmASSERT(FileName); gcmVERIFY_OK(gcoOS_StrLen(FileName, &length)); length += 6; gcmVERIFY_OK(gcoOS_Allocate(Os, length, (gctPOINTER *) &dataFileName)); gcmVERIFY_OK(gcoOS_StrCopySafe(dataFileName, length, FileName)); gcmVERIFY_OK(gcoOS_StrCatSafe(dataFileName, length, ".gcSL")); status = gcoOS_Open(Os, dataFileName, gcvFILE_CREATE, &file); if (gcmIS_ERROR(status)) { gcoOS_Free(Os, dataFileName); printf("*ERROR* Failed to open the data file: %s\n", dataFileName); return gcvFALSE; } gcoOS_Free(Os, dataFileName); gcmASSERT(file); status = gcoOS_Write(Os, file, Size, Data); if (!gcmIS_SUCCESS(status)) { printf("*ERROR* Failed to write the data file: %s\n", dataFileName); goto ErrorExit; } gcmVERIFY_OK(gcoOS_Close(Os, file)); return gcvTRUE; ErrorExit: gcmVERIFY_OK(gcoOS_Close(Os, file)); return gcvFALSE; }
/******************************************************************************* ** ** gcoDUMP_Construct ** ** Construct a new gcoDUMP object. ** ** INPUT: ** ** gcoOS Os ** Pointer to an gcoOS object. ** ** gcoOS Hal ** Pointer to an gcoHAL object. ** ** OUTPUT: ** ** gcoDUMP * Dump ** Pointer to a variable receiving the gcoDUMP object pointer. */ gceSTATUS gcoDUMP_Construct( IN gcoOS Os, IN gcoHAL Hal, OUT gcoDUMP * Dump ) { gceSTATUS status; gcoDUMP dump; gctPOINTER pointer = gcvNULL; gcmHEADER_ARG("Os=0x%x Dump=0x%x", Os, Dump); /* Verify the arguments. */ gcmVERIFY_ARGUMENT(Dump != gcvNULL); do { /* Allocate the gcoDUMP structure. */ gcmERR_BREAK(gcoOS_Allocate(Os, sizeof(struct _gcoDUMP), &pointer)); dump = pointer; /* Initialize the gcoDUMP object. */ dump->object.type = gcvOBJ_DUMP; dump->file = gcvNULL; /* Return pointer to the object. */ *Dump = dump; } while (gcvFALSE); /* Return the status. */ gcmFOOTER_ARG("*Dump=0x%x", *Dump); return status; }
Bool WrapSurface(PixmapPtr pPixmap, void * logical, unsigned int physical, Viv2DPixmapPtr pPix) { gceSTATUS status = gcvSTATUS_OK; gctUINT alignedWidth, alignedHeight; gctUINT bytesPerPixel; GenericSurfacePtr surf = gcvNULL; gctPOINTER mHandle = gcvNULL; status = gcoOS_Allocate(gcvNULL, sizeof (GenericSurface), &mHandle); if (status != gcvSTATUS_OK) { TRACE_ERROR("Unable to allocate generic surface\n"); TRACE_EXIT(FALSE); } memset(mHandle, 0, sizeof (GenericSurface)); surf = (GenericSurfacePtr) mHandle; alignedWidth = gcmALIGN(pPixmap->drawable.width, WIDTH_ALIGNMENT); alignedHeight = gcmALIGN(pPixmap->drawable.height, HEIGHT_ALIGNMENT); bytesPerPixel = BITSTOBYTES(pPixmap->drawable.bitsPerPixel); surf->mVideoNode.mSizeInBytes = alignedWidth * bytesPerPixel * alignedHeight; surf->mVideoNode.mPool = gcvPOOL_USER; surf->mVideoNode.mPhysicalAddr = physical; surf->mVideoNode.mLogicalAddr = (gctPOINTER) logical; surf->mBytesPerPixel = bytesPerPixel; surf->mTiling = gcvLINEAR; surf->mAlignedWidth = alignedWidth; surf->mAlignedHeight = alignedHeight; surf->mStride = alignedWidth * bytesPerPixel; surf->mRotation = gcvSURF_0_DEGREE; surf->mLogicalAddr = surf->mVideoNode.mLogicalAddr; surf->mIsWrapped = gcvTRUE; pPix->mVidMemInfo = surf; TRACE_EXIT(TRUE); }
/******************************************************************************* ** ** gcoCMDBUF_Construct ** ** Construct a new gcoCMDBUF object. ** ** INPUT: ** ** gcoOS Os ** Pointer to a gcoOS object. ** ** gcoHARDWARE Hardware ** Pointer to a gcoHARDWARE object. ** ** gctSIZE_T Bytes ** Number of bytes for the buffer. ** ** gcsCOMMAND_BUFFER_PTR Info ** Alignment and head/tail information. ** ** OUTPUT: ** ** gcoCMDBUF * CommandBuffer ** Pointer to a variable that will hold the the gcoCMDBUF object ** pointer. */ gceSTATUS gcoCMDBUF_Construct( IN gcoOS Os, IN gcoHARDWARE Hardware, IN gctSIZE_T Bytes, IN gcsCOMMAND_INFO_PTR Info, OUT gcoCMDBUF * CommandBuffer ) { gceSTATUS status; gcoCMDBUF commandBuffer = gcvNULL; gctSIZE_T objectSize; #ifdef __QNXNTO__ gctPHYS_ADDR physical; #else gctPOINTER pointer = gcvNULL; #endif gcmHEADER_ARG("Bytes=%lu Info=0x%x", Bytes, Info); /* Verify the arguments. */ gcmDEBUG_VERIFY_ARGUMENT(Bytes > 0); gcmDEBUG_VERIFY_ARGUMENT(CommandBuffer != gcvNULL); /* Set the size of the object. */ objectSize = gcmSIZEOF(struct _gcoCMDBUF); /* Allocate the gcoCMDBUF object. */ #ifdef __QNXNTO__ /* gcoCMDBUF object needs to be accessible from the kernel; to avoid copying of the data for each access, allocate the object from the kernel non-paged memory. */ gcmONERROR(gcoOS_AllocateNonPagedMemory( gcvNULL, gcvTRUE, &objectSize, &physical, (gctPOINTER *) &commandBuffer )); #else /* Currently in most OS we are able to access the user-side data from the kernel by simple memory mapping, therefore here we allocate the object from the cached user memory. */ gcmONERROR(gcoOS_Allocate(gcvNULL, objectSize, &pointer)); commandBuffer = pointer; #endif /* Reset the command buffer object. */ gcmONERROR(gcoOS_ZeroMemory(commandBuffer, objectSize)); /* Initialize the gcoCMDBUF object. */ commandBuffer->object.type = gcvOBJ_COMMANDBUFFER; commandBuffer->bytes = Bytes; /* Allocate the physical buffer for the command. */ gcmONERROR(gcoOS_AllocateContiguous( gcvNULL, gcvTRUE, &commandBuffer->bytes, &commandBuffer->physical, &commandBuffer->logical )); /* Initialize command buffer. */ commandBuffer->free = commandBuffer->bytes; #if gcdSECURE_USER /* Determine the size of the state array. */ commandBuffer->hintArraySize = Bytes; /* Allocate the state array. */ #ifdef __QNXNTO__ gcmONERROR(gcoOS_AllocateNonPagedMemory( gcvNULL, gcvTRUE, &commandBuffer->hintArraySize, &physical, (gctPOINTER *) &commandBuffer->hintArray )); #else gcmONERROR(gcoOS_Allocate( gcvNULL, commandBuffer->hintArraySize, &pointer )); commandBuffer->hintArray = pointer; #endif /* Initialize the state array tail pointer. */ commandBuffer->hintArrayTail = commandBuffer->hintArray; #endif /* Return pointer to the gcoCMDBUF object. */ *CommandBuffer = commandBuffer; /* Success. */ gcmFOOTER_ARG("*CommandBuffer=0x%x", *CommandBuffer); return gcvSTATUS_OK; OnError: /* Roll back. */ if (commandBuffer != gcvNULL) { if (commandBuffer->logical != gcvNULL) { gcmVERIFY_OK(gcoOS_FreeContiguous( gcvNULL, commandBuffer->physical, commandBuffer->logical, commandBuffer->bytes )); } #if gcdSECURE_USER if (commandBuffer->hintArray != gcvNULL) { #ifdef __QNXNTO__ gcmVERIFY_OK(gcoOS_FreeNonPagedMemory( gcvNULL, commandBuffer->hintArraySize, gcvNULL, commandBuffer->hintArray )); #else gcmVERIFY_OK(gcmOS_SAFE_FREE(gcvNULL, commandBuffer->hintArray)); #endif } #endif #ifdef __QNXNTO__ gcmVERIFY_OK(gcoOS_FreeNonPagedMemory( gcvNULL, objectSize, gcvNULL, commandBuffer )); #else gcmVERIFY_OK(gcmOS_SAFE_FREE(gcvNULL, commandBuffer)); #endif } /* Return the status. */ gcmFOOTER(); return status; }
gceSTATUS glfCreateNamedObject( IN glsCONTEXT_PTR Context, IN glsNAMEDOBJECTLIST_PTR List, IN gctUINT32 Name, IN glfNAMEDOBJECTDESTRUCTOR ObjectDestructor, OUT glsNAMEDOBJECT_PTR * ObjectWrapper ) { gceSTATUS status = gcvSTATUS_OK; gcmHEADER_ARG("Context=0x%x List=0x%x Name=%u ObjectDestructor=0x%x ObjectWrapper=0x%x", Context, List, Name, ObjectDestructor, ObjectWrapper); do { glsNAMEDOBJECT_PTR wrapper; glsNAMEDOBJECT_PTR* entry; gctUINT32 index; /* Are there available wrappers in the free list? */ wrapper = List->freeList; if ((Name == 0) && (wrapper != gcvNULL)) { /* Remove the first wrapper from the list. */ List->freeList = wrapper->next; } /* Create a new wrapper. */ else { /* Create a new wrapper. */ wrapper = gcvNULL; /* Generate a name if not specified. */ if (Name == 0) { if (List->nextName == 0) { /* No more names. */ status = gcvSTATUS_OUT_OF_RESOURCES; break; } Name = List->nextName++; } else if (Name > List->nextName) { /* Name for the object has been explicitly specified by the application and it is greater then the next automatic would-be name. Update the next name with the value from the application; this creates a hole in the name range. */ List->nextName = Name + 1; } else if (List->freeList != gcvNULL) { /* Name for the object has been explicitly specified by the application and it is less then or equal to the next automatic would-be name. This means the name most likely lives inside the free list. */ if (List->freeList->name == Name) { wrapper = List->freeList; List->freeList = wrapper->next; } else { glsNAMEDOBJECT_PTR previous = List->freeList; for (wrapper = List->freeList; wrapper != gcvNULL; wrapper = wrapper->next) { if (wrapper->name == Name) { previous->next = wrapper->next; break; } previous = wrapper; } } } if (wrapper == gcvNULL) { /* Allocate wrapper and the user object. */ gcmERR_BREAK(gcoOS_Allocate( gcvNULL, gcmALIGN(sizeof(glsNAMEDOBJECT), 4) + List->objectSize, (gctPOINTER) &wrapper )); /* Set the objects's name. */ wrapper->name = Name; /* Set the object pointer. */ wrapper->object = ((gctUINT8_PTR) wrapper) + gcmALIGN(sizeof(glsNAMEDOBJECT), 4); wrapper->referenceCount = 0; wrapper->listBelonged = List; } } /* Set the destructor. */ wrapper->deleteObject = ObjectDestructor; /* Determine the hash table index. */ index = wrapper->name % glvNAMEDOBJECT_HASHTABLE_SIZE; /* Shortcut to the table entry. */ entry = &List->hashTable[index]; /* Insert into the chain. */ wrapper->next = *entry; *entry = wrapper; glfReferenceNamedObject(wrapper); /* Set the result. */ *ObjectWrapper = wrapper; } while (gcvFALSE); gcmFOOTER(); return status; }
static gcSHADER CompileFile( IN gcoOS Os, IN gctCONST_STRING FileName, IN gcoHAL Hal, IN gctUINT Option, IN gctBOOL DumpLog, IN gctBOOL DumpCompiledShader ) { gceSTATUS status; gctINT shaderType; gctSIZE_T sourceSize; gctSTRING source = gcvNULL; gcSHADER binary; gctSTRING log = gcvNULL; gctSIZE_T bufferSize; gctSTRING buffer; gctSTRING dataFileName = gcvNULL; gctSIZE_T length; gctFILE logFile = gcvNULL; gcmASSERT(FileName); shaderType = GetShaderType(FileName); if (!ReadSource(Os, FileName, &sourceSize, &source)) return gcvNULL; status = gcCompileShader(Hal, shaderType, sourceSize, source, &binary, &log); if (log != gcvNULL) { printf("<LOG>\n"); printf("%s", log); printf("</LOG>\n"); } if (gcmIS_ERROR(status)) { gcmASSERT(binary == gcvNULL); binary = gcvNULL; printf("*ERROR* Failed to compile %s (error: %d)\n", FileName, status); goto Exit; } gcmASSERT(binary != gcvNULL); if (DumpLog) { gcmVERIFY_OK(gcoOS_StrLen(FileName, &length)); length += 5; gcmVERIFY_OK(gcoOS_Allocate(Os, length, (gctPOINTER *) &dataFileName)); gcmVERIFY_OK(gcoOS_StrCopySafe(dataFileName, length, FileName)); gcmVERIFY_OK(gcoOS_StrCatSafe(dataFileName, length, ".log")); status = gcoOS_Open(Os, dataFileName, gcvFILE_CREATETEXT, &logFile); if (gcmIS_ERROR(status)) { logFile = gcvNULL; printf("*ERROR* Failed to open the log file: %s\n", dataFileName); } gcoOS_Free(Os, dataFileName); } gcmVERIFY_OK(gcSHADER_SetOptimizationOption(binary, Option)); status = gcOptimizeShader(binary, logFile); if (!gcmIS_SUCCESS(status)) { printf("*ERROR* Failed to optimize %s (error: %d)\n", FileName, status); } if (logFile != gcvNULL) { gcmVERIFY_OK(gcoOS_Close(Os, logFile)); } if (DumpCompiledShader) { status = gcSHADER_Save(binary, gcvNULL, &bufferSize); if (gcmIS_ERROR(status)) { printf("*ERROR* Failed to get the buffer size of the shader\n"); goto Exit; } status = gcoOS_Allocate(Os, bufferSize, (gctPOINTER *) &buffer); if (!gcmIS_SUCCESS(status)) { printf("*ERROR* Not enough memory\n"); goto Exit; } status = gcSHADER_Save(binary, buffer, &bufferSize); if (status != gcvSTATUS_OK) { printf("*ERROR* Failed to get the buffer size of the shader\n"); gcoOS_Free(Os, buffer); goto Exit; } OutputShaderData(Os, FileName, bufferSize, buffer); gcoOS_Free(Os, buffer); } Exit: if (DumpLog && log != gcvNULL) { printf("**************** Compile Log ****************"); printf("%s", log); printf("*********************************************"); } if (log != gcvNULL) gcoOS_Free(Os, log); if (source != gcvNULL) gcoOS_Free(Os, source); return binary; }
gceSTATUS gcoQUEUE_AppendEvent( IN gcoQUEUE Queue, IN gcsHAL_INTERFACE * Interface ) { gceSTATUS status; gcsQUEUE_PTR record = gcvNULL; #ifdef __QNXNTO__ gctSIZE_T allocationSize; gctPHYS_ADDR physAddr; #else gctPOINTER pointer = gcvNULL; #endif gcmHEADER_ARG("Queue=0x%x Interface=0x%x", Queue, Interface); /* Verify the arguments. */ gcmVERIFY_OBJECT(Queue, gcvOBJ_QUEUE); gcmVERIFY_ARGUMENT(Interface != gcvNULL); /* Allocate record. */ #ifdef __QNXNTO__ allocationSize = gcmSIZEOF(gcsQUEUE); if (Queue->freeBytes < allocationSize) { gctSIZE_T recordsSize = BUFFER_SIZE; gcsQUEUE_PTR prevRecords = Queue->records; gcsHAL_INTERFACE iface; /* Allocate new set of records. */ gcmONERROR( gcoOS_AllocateNonPagedMemory(gcvNULL, gcvTRUE, &recordsSize, &physAddr, (gctPOINTER *) &Queue->records)); Queue->freeBytes = recordsSize; Queue->offset = 0; if ( Queue->freeBytes < allocationSize ) { gcmFOOTER_ARG("status=%d", gcvSTATUS_DATA_TOO_LARGE); return gcvSTATUS_DATA_TOO_LARGE; } /* Schedule to free Queue->records, * hence not unmapping currently scheduled events immediately. */ iface.command = gcvHAL_FREE_NON_PAGED_MEMORY; iface.u.FreeNonPagedMemory.bytes = BUFFER_SIZE; iface.u.FreeNonPagedMemory.physical = 0; iface.u.FreeNonPagedMemory.logical = prevRecords; gcmONERROR( gcoQUEUE_AppendEvent(Queue, &iface)); } record = (gcsQUEUE_PTR)((gctUINT32)Queue->records + Queue->offset); Queue->offset += allocationSize; Queue->freeBytes -= allocationSize; #else /* Check if we have records on the free list. */ if (Queue->freeList != gcvNULL) { /* Allocate from hte free list. */ record = Queue->freeList; Queue->freeList = record->next; } else { gcmONERROR(gcoOS_Allocate(gcvNULL, gcmSIZEOF(gcsQUEUE), &pointer)); record = pointer; } #endif /* Initialize record. */ record->next = gcvNULL; gcoOS_MemCopy(&record->iface, Interface, gcmSIZEOF(record->iface)); if (Queue->head == gcvNULL) { /* Initialize queue. */ Queue->head = record; } else { /* Append record to end of queue. */ Queue->tail->next = record; } /* Mark end of queue. */ Queue->tail = record; /* update count */ Queue->recordCount++; /* Success. */ gcmFOOTER_NO(); return gcvSTATUS_OK; OnError: #ifndef __QNXNTO__ if (pointer != gcvNULL) { /* Put record on free list. */ record->next = Queue->freeList; Queue->freeList = record; } #endif /* Return the status. */ gcmFOOTER(); return status; }
/** * * @param driver - Driver object to be returned * @return the status of the initilization */ static gctBOOL SetupDriver ( OUT Viv2DDriverPtr * driver ) { TRACE_ENTER(); gceSTATUS status = gcvSTATUS_OK; Viv2DDriverPtr pDrvHandle = gcvNULL; gctPOINTER mHandle = gcvNULL; /*Allocating the driver*/ gcmASSERT(*driver == gcvNULL); status = gcoOS_Allocate(gcvNULL, sizeof (Viv2DDriver), &mHandle); if (status < 0) { TRACE_ERROR("Unable to allocate driver, status = %d\n", status); TRACE_EXIT(gcvFALSE); } pDrvHandle = (Viv2DDriverPtr) mHandle; status = gcoOS_Construct(gcvNULL, &(pDrvHandle->mOs)); if (status < 0) { TRACE_ERROR("Unable to construct OS object, status = %d\n", status); TRACE_EXIT(gcvFALSE); } status = gcoHAL_Construct(gcvNULL, pDrvHandle->mOs, &(pDrvHandle->mHal)); if (status < 0) { TRACE_ERROR("Unable to construct HAL object, status = %d\n", status); TRACE_EXIT(gcvFALSE); } /*If Seperated*/ pDrvHandle->mIsSeperated = gcoHAL_QuerySeparated3D2D(pDrvHandle->mHal) == gcvSTATUS_TRUE; if (pDrvHandle->mIsSeperated) { status = gcoHAL_SetHardwareType(pDrvHandle->mHal, gcvHARDWARE_2D); if (status < 0) { TRACE_ERROR("Unable to gcoHAL_SetHardwareType, status = %d\n", status); TRACE_EXIT(gcvFALSE); } } if (!gcoHAL_IsFeatureAvailable(pDrvHandle->mHal, gcvFEATURE_PIPE_2D)) { TRACE_ERROR("2D PIPE IS NOT AVAIBLE"); TRACE_EXIT(gcvFALSE); } /* Query the amount of video memory. */ status = gcoHAL_QueryVideoMemory (pDrvHandle->mHal, &pDrvHandle->g_InternalPhysical, &pDrvHandle->g_InternalSize, &pDrvHandle->g_ExternalPhysical, &pDrvHandle->g_ExternalSize, &pDrvHandle->g_ContiguousPhysical, &pDrvHandle->g_ContiguousSize ); if (status < 0) { TRACE_ERROR("gcoHAL_QueryVideoMemory failed, status = %d\n", status); TRACE_EXIT(gcvFALSE); } /* Map the local internal memory. */ if (pDrvHandle->g_InternalSize > 0) { status = gcoHAL_MapMemory( pDrvHandle->mHal, pDrvHandle->g_InternalPhysical, pDrvHandle-> g_InternalSize, &pDrvHandle->g_Internal ); if (status < 0) { TRACE_ERROR("gcoHAL_MapMemory failed, status = %d\n", status); TRACE_EXIT(gcvFALSE); } } /* Map the local external memory. */ if (pDrvHandle->g_ExternalSize > 0) { status = gcoHAL_MapMemory( pDrvHandle->mHal, pDrvHandle->g_ExternalPhysical, pDrvHandle->g_ExternalSize, &pDrvHandle->g_External ); if (status < 0) { TRACE_ERROR("gcoHAL_MapMemory failed, status = %d\n", status); TRACE_EXIT(gcvFALSE); } } /* Map the contiguous memory. */ if (pDrvHandle->g_ContiguousSize > 0) { status = gcoHAL_MapMemory (pDrvHandle->mHal, pDrvHandle->g_ContiguousPhysical, pDrvHandle->g_ContiguousSize, &pDrvHandle->g_Contiguous ); TRACE_INFO("Physcal : %d LOGICAL ADDR = %p SIZE = %d\n", pDrvHandle->g_ContiguousPhysical, pDrvHandle->g_Contiguous, pDrvHandle->g_ContiguousSize); if (status < 0) { TRACE_ERROR("gcoHAL_MapMemory failed, status = %d\n", status); TRACE_EXIT(gcvFALSE); } } /* Determine whether PE 2.0 is present. */ pDrvHandle->mIsPe20Supported = gcoHAL_IsFeatureAvailable(pDrvHandle ->mHal, gcvFEATURE_2DPE20) == gcvSTATUS_TRUE; /*Multi source options*/ pDrvHandle->mIsMultiSrcBltSupported = gcoHAL_IsFeatureAvailable(pDrvHandle->mHal, gcvFEATURE_2D_MULTI_SOURCE_BLT) == gcvSTATUS_TRUE; pDrvHandle->mIsMultiSrcBltExSupported = gcoHAL_IsFeatureAvailable(pDrvHandle->mHal, gcvFEATURE_2D_MULTI_SOURCE_BLT_EX) == gcvSTATUS_TRUE; pDrvHandle->mMaxSourceForMultiSrcOpt = pDrvHandle->mIsMultiSrcBltExSupported ? 8 : (pDrvHandle->mIsMultiSrcBltSupported ? 4 : 1); /*Getting the 2d engine*/ status = gcoHAL_Get2DEngine(pDrvHandle->mHal, &(pDrvHandle->m2DEngine)); if (status < 0) { TRACE_ERROR("Unable to construct 2DEngine object, status = %d\n", status); TRACE_EXIT(gcvFALSE); } *driver = pDrvHandle; TRACE_EXIT(gcvTRUE); }
static gctBOOL VIV2DGPUSurfaceAlloc(VIVGPUPtr gpuctx, gctUINT alignedWidth, gctUINT alignedHeight, gctUINT bytesPerPixel, GenericSurfacePtr * surface) { TRACE_ENTER(); gceSTATUS status = gcvSTATUS_OK; GenericSurfacePtr surf = gcvNULL; gctPOINTER mHandle = gcvNULL; gceSURF_TYPE surftype; Bool cacheable; surf = GrabSurfFromPool(alignedWidth, alignedHeight, bytesPerPixel); if ( surf ==NULL ) { status = gcoOS_Allocate(gcvNULL, sizeof (GenericSurface), &mHandle); if (status != gcvSTATUS_OK) { TRACE_ERROR("Unable to allocate generic surface\n"); TRACE_EXIT(FALSE); } memset(mHandle, 0, sizeof (GenericSurface)); surf = (GenericSurfacePtr) mHandle; surf->mVideoNode.mSizeInBytes = alignedWidth * bytesPerPixel * alignedHeight; surf->mVideoNode.mPool = gcvPOOL_DEFAULT; if ( alignedWidth >= IMX_EXA_NONCACHESURF_WIDTH && alignedHeight >= IMX_EXA_NONCACHESURF_HEIGHT ) { surftype = gcvSURF_BITMAP; cacheable = FALSE; } else { surftype = SURFACE_TYPE; cacheable = SURFACE_CACHEABLE; } status = AllocVideoNode(gpuctx->mDriver->mHal, &surf->mVideoNode.mSizeInBytes, &surf->mVideoNode.mPool, surftype, &surf->mVideoNode.mNode); if (status != gcvSTATUS_OK) { TRACE_ERROR("Unable to allocate video node\n"); TRACE_EXIT(FALSE); } status = LockVideoNode(gpuctx->mDriver->mHal, surf->mVideoNode.mNode, cacheable, &surf->mVideoNode.mPhysicalAddr, &surf->mVideoNode.mLogicalAddr); if (status != gcvSTATUS_OK) { TRACE_ERROR("Unable to Lock video node\n"); TRACE_EXIT(FALSE); } TRACE_INFO("VIDEO NODE CREATED => LOGICAL = %d PHYSICAL = %d SIZE = %d\n", surf->mVideoNode.mLogicalAddr, surf->mVideoNode.mPhysicalAddr, surf->mVideoNode.mSizeInBytes); } surf->mTiling = gcvLINEAR; surf->mAlignedWidth = alignedWidth; surf->mAlignedHeight = alignedHeight; surf->mBytesPerPixel = bytesPerPixel; surf->mStride = alignedWidth * bytesPerPixel; surf->mRotation = gcvSURF_0_DEGREE; surf->mLogicalAddr = surf->mVideoNode.mLogicalAddr; surf->mIsWrapped = gcvFALSE; surf->mData = gcvNULL; *surface = surf; TRACE_EXIT(TRUE); }
static gceSTATUS _ReferenceObjectCache( vgsCONTEXT_PTR Context, vgsOBJECT_CACHE_PTR * ObjectCache ) { gceSTATUS status, last; vgsOBJECT_CACHE_PTR objectCache = gcvNULL; do { /* Has the object cache been created? */ if (*ObjectCache == gcvNULL) { static vgtSET_OBJECT_LIST initList[] = { vgfSetPathObjectList, vgfSetImageObjectList, vgfSetMaskObjectList, vgfSetFontObjectList, vgfSetPaintObjectList }; gctUINT i; /* Allocate the context structure. */ gcmERR_BREAK(gcoOS_Allocate( Context->os, gcmSIZEOF(vgsOBJECT_CACHE), (gctPOINTER *) &objectCache )); gcmERR_BREAK(gcoOS_ZeroMemory( objectCache, gcmSIZEOF(vgsOBJECT_CACHE))); /* Initialize the object. */ objectCache->loHandle = ~0; objectCache->hiHandle = 0; objectCache->referenceCount = 0; /* Initialize object arrays. */ for (i = 0; i < gcmCOUNTOF(initList); i++) { initList[i] (&objectCache->cache[i]); } /* Set the result pointer. */ *ObjectCache = objectCache; } /* Increment the counter. */ (*ObjectCache)->referenceCount++; /* Success. */ return gcvSTATUS_OK; } while (gcvFALSE); /* Roll back. */ if (objectCache != gcvNULL) { gcmCHECK_STATUS(gcoOS_Free(Context->os, objectCache)); } /* Return status. */ return status; }
gceSTATUS vgsMEMORYMANAGER_Allocate( IN vgsMEMORYMANAGER_PTR Manager, OUT gctPOINTER * Pointer ) { gceSTATUS status; vgsMEMORYITEM_PTR firstFree; gcmHEADER_ARG("Manager=0x%x Pointer=0x%x", Manager, Pointer); /* Verify arguments. */ gcmVERIFY_ARGUMENT(Manager != gcvNULL); gcmVERIFY_ARGUMENT(Pointer != gcvNULL); /* Get the first free. */ firstFree = Manager->firstFree; /* Are there free items? */ if (firstFree != gcvNULL) { /* Set the result. */ * Pointer = firstFree + 1; /* Remove from the free list. */ Manager->firstFree = firstFree->next; /* Update allocated items count. */ #if vgvVALIDATE_MEMORY_MANAGER Manager->allocatedCount += 1; if ((gctUINT) Manager->allocatedCount > Manager->maximumAllocated) { Manager->maximumAllocated = Manager->allocatedCount; } #endif /* Success. */ gcmFOOTER_ARG("*Pointer=0x%x", *Pointer); return gcvSTATUS_OK; } /* No free items available. */ do { vgsMEMORYITEM_PTR newBuffer; gctUINT i, itemCount; gctUINT itemSize; /* Allocate a new buffer. */ gcmERR_BREAK(gcoOS_Allocate( Manager->os, Manager->allocationSize, (gctPOINTER) &newBuffer )); /* Link in. */ newBuffer->next = Manager->firstAllocated; Manager->firstAllocated = newBuffer; /* Set the result. */ * Pointer = newBuffer + 2; /* Update allocated items count. */ #if vgvVALIDATE_MEMORY_MANAGER Manager->allocatedCount += 1; Manager->allocatedBufferCount += 1; if ((gctUINT) Manager->allocatedCount > Manager->maximumAllocated) { Manager->maximumAllocated = Manager->allocatedCount; } #endif /* Get the number of items per allocation. */ itemCount = Manager->itemCount; /* Get the item size. */ itemSize = Manager->itemSize; /* Determine the first free item. */ firstFree = (vgsMEMORYITEM_PTR) ( (gctUINT8_PTR) (newBuffer + 1) + itemSize ); /* Populate the new buffer. */ for (i = 1; i < itemCount; i++) { /* Add to the free item list. */ firstFree->next = Manager->firstFree; Manager->firstFree = firstFree; /* Advance to the next item. */ firstFree = (vgsMEMORYITEM_PTR) ( (gctUINT8_PTR) firstFree + itemSize ); } } while (gcvFALSE); gcmFOOTER(); /* Return status. */ return status; }