void* bmalloc(unsigned long size) { void* mem; #ifdef CONFIG_BIGPHYS_AREA mem = bigphysarea_alloc_pages(size/PAGE_SIZE, 1, GFP_KERNEL); #else /* * The following function got a lot of memory at boottime, * so we know its always there... */ mem = (void*)__get_free_pages(GFP_USER|GFP_DMA,get_order(size)); #endif if (mem) { unsigned long adr = (unsigned long)mem; while (size > 0) { mem_map_reserve(virt_to_page(phys_to_virt(adr))); adr += PAGE_SIZE; size -= PAGE_SIZE; } } return mem; }
caddr_t bigphysarea_alloc(int size) { int pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; return bigphysarea_alloc_pages(pages, 1, GFP_KERNEL); }
/** ============================================================================ * @func MEM_Alloc * * @desc Allocates the specified number of bytes. * * @modif None * ============================================================================ */ EXPORT_API DSP_STATUS MEM_Alloc (OUT Void ** ptr, IN Uint32 cBytes, IN OUT Pvoid arg) { DSP_STATUS status = DSP_SOK ; MemAllocAttrs * allocArg = NULL ; #if ( (defined (DM6437_PHYINTERFACE) && (DM6437_PHYINTERFACE == PCI_INTERFACE)) \ ||(defined (DM642_PHYINTERFACE) && (DM642_PHYINTERFACE == PCI_INTERFACE)) \ ||(defined (DM648_PHYINTERFACE) && (DM648_PHYINTERFACE == PCI_INTERFACE))) Uint32 pages = 0 ; #endif /* if (DM6437_PHYINTERFACE == PCI)... */ TRC_3ENTER ("MEM_Alloc", ptr, cBytes, arg) ; DBC_Require (ptr != NULL) ; DBC_Require (MEM_IsInitialized == TRUE) ; DBC_Require (cBytes != 0) ; /* ------------------------------------------------------------------------ * Validate arguments * ------------------------------------------------------------------------ */ if (ptr == NULL) { status = DSP_EINVALIDARG ; SET_FAILURE_REASON ; } else if (cBytes == 0) { status = DSP_EINVALIDARG ; SET_FAILURE_REASON ; *ptr = NULL ; } else { if (arg == MEM_DEFAULT) { /* ---------------------------------------------------------------- * Allocations from 'default' memory area * ---------------------------------------------------------------- */ *ptr = vmalloc (cBytes) ; if (*ptr == NULL) { status = DSP_EMEMORY ; SET_FAILURE_REASON ; } #if defined (DDSP_DEBUG) else { MEM_DefaultAlloc++ ; } #endif /* if defined (DDSP_DEBUG) */ } else { /* ---------------------------------------------------------------- * OS dependent allocation from 'special' memory area(s). * ---------------------------------------------------------------- */ allocArg = (MemAllocAttrs *) arg ; if (allocArg->bigArea == TRUE) { #if ( (defined (DM6437_PHYINTERFACE) && (DM6437_PHYINTERFACE == PCI_INTERFACE)) \ ||(defined (DM642_PHYINTERFACE) && (DM642_PHYINTERFACE == PCI_INTERFACE)) \ ||(defined (DM648_PHYINTERFACE) && (DM648_PHYINTERFACE == PCI_INTERFACE)) ) pages = (cBytes + PAGE_SIZE - 1) / PAGE_SIZE ; *ptr = (Void *) bigphysarea_alloc_pages (pages, 0, GFP_KERNEL) ; if (*ptr != NULL) { allocArg->physicalAddress = (Uint32 *) virt_to_bus (*ptr) ; } #elif (defined (DM6437_PHYINTERFACE) && (DM6437_PHYINTERFACE == VLYNQ_INTERFACE)) #else TRC_0PRINT ( TRC_LEVEL4, "BigPhys allocation is supported on this platform") ; #endif /* if (DM6437_PHYINTERFACE == PCI)... */ } else { *ptr = (void *) dma_alloc_coherent ( NULL, cBytes, (dma_addr_t *) &(allocArg->physicalAddress), GFP_KERNEL) ; } if (*ptr == NULL) { status = DSP_EMEMORY ; SET_FAILURE_REASON ; } #if defined (DDSP_DEBUG) else { MEM_SpecialAlloc++ ; } #endif /* if defined (DDSP_DEBUG) */ } } DBC_Ensure ( ((ptr == NULL) && DSP_FAILED (status)) || ((ptr != NULL) && (*ptr != NULL) && DSP_SUCCEEDED (status)) || ((ptr != NULL) && (*ptr == NULL) && DSP_FAILED (status))) ; TRC_1LEAVE ("MEM_Alloc", status) ; return status ; }