struct LinuxMemArea *NewVMallocLinuxMemArea(u32 ui32Bytes, u32 ui32AreaFlags) { struct LinuxMemArea *psLinuxMemArea; void *pvCpuVAddr; psLinuxMemArea = LinuxMemAreaStructAlloc(); if (!psLinuxMemArea) goto failed; pvCpuVAddr = VMallocWrapper(ui32Bytes, ui32AreaFlags); if (!pvCpuVAddr) goto failed; psLinuxMemArea->eAreaType = LINUX_MEM_AREA_VMALLOC; psLinuxMemArea->uData.sVmalloc.pvVmallocAddress = pvCpuVAddr; psLinuxMemArea->ui32ByteSize = ui32Bytes; psLinuxMemArea->ui32AreaFlags = ui32AreaFlags; psLinuxMemArea->bMMapRegistered = IMG_FALSE; INIT_LIST_HEAD(&psLinuxMemArea->sMMapOffsetStructList); #if defined(DEBUG_LINUX_MEM_AREAS) DebugLinuxMemAreaRecordAdd(psLinuxMemArea, ui32AreaFlags); #endif return psLinuxMemArea; failed: PVR_DPF(PVR_DBG_ERROR, "%s: failed!", __func__); if (psLinuxMemArea) LinuxMemAreaStructFree(psLinuxMemArea); return NULL; }
struct LinuxMemArea *NewAllocPagesLinuxMemArea(u32 ui32Bytes, u32 ui32AreaFlags) { struct LinuxMemArea *psLinuxMemArea; u32 ui32PageCount; struct page **pvPageList; u32 i; psLinuxMemArea = LinuxMemAreaStructAlloc(); if (!psLinuxMemArea) goto failed_area_alloc; ui32PageCount = RANGE_TO_PAGES(ui32Bytes); pvPageList = VMallocWrapper(sizeof(void *) * ui32PageCount, PVRSRV_HAP_CACHED); if (!pvPageList) goto failed_vmalloc; for (i = 0; i < ui32PageCount; i++) { pvPageList[i] = alloc_pages(GFP_KERNEL, 0); if (!pvPageList[i]) goto failed_alloc_pages; } #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS) DebugMemAllocRecordAdd(DEBUG_MEM_ALLOC_TYPE_ALLOC_PAGES, pvPageList, NULL, 0, NULL, PAGE_ALIGN(ui32Bytes), "unknown", 0); #endif psLinuxMemArea->eAreaType = LINUX_MEM_AREA_ALLOC_PAGES; psLinuxMemArea->uData.sPageList.pvPageList = pvPageList; psLinuxMemArea->ui32ByteSize = ui32Bytes; #if defined(DEBUG_LINUX_MEM_AREAS) DebugLinuxMemAreaRecordAdd(psLinuxMemArea, ui32AreaFlags); #endif return psLinuxMemArea; failed_alloc_pages: for (i--; i >= 0; i--) __free_pages(pvPageList[i], 0); VFreeWrapper(pvPageList); failed_vmalloc: LinuxMemAreaStructFree(psLinuxMemArea); failed_area_alloc: PVR_DPF(PVR_DBG_ERROR, "%s: failed", __func__); return NULL; }