static void init_triton_dma (ide_hwif_t *hwif, unsigned short base) { static unsigned long dmatable = 0; printk(" %s: BusMaster DMA at 0x%04x-0x%04x", hwif->name, base, base+7); if (check_region(base, 8)) { printk(" -- ERROR, PORTS ALREADY IN USE"); } else { request_region(base, 8, "triton DMA"); hwif->dma_base = base; if (!dmatable) { /* * Since we know we are on a PCI bus, we could * actually use __get_free_pages() here instead * of __get_dma_pages() -- no ISA limitations. */ dmatable = __get_dma_pages(GFP_KERNEL, 0); } if (dmatable) { hwif->dmatable = (unsigned long *) dmatable; dmatable += (PRD_ENTRIES * PRD_BYTES); outl(virt_to_bus(hwif->dmatable), base + 4); hwif->dmaproc = &triton_dmaproc; } } printk("\n"); }
/* * This is main public interface: somehow allocate a ST-RAM block * * - If we're before mem_init(), we have to make a static allocation. The * region is taken in the kernel data area (if the kernel is in ST-RAM) or * from the start of ST-RAM (if the kernel is in TT-RAM) and added to the * rsvd_stram_* region. The ST-RAM is somewhere in the middle of kernel * address space in the latter case. * * - If mem_init() already has been called, try with __get_dma_pages(). * This has the disadvantage that it's very hard to get more than 1 page, * and it is likely to fail :-( * */ void *atari_stram_alloc(long size, const char *owner) { void *addr = NULL; BLOCK *block; int flags; DPRINTK("atari_stram_alloc(size=%08lx,owner=%s)\n", size, owner); if (!mem_init_done) return alloc_bootmem_low(size); else { /* After mem_init(): can only resort to __get_dma_pages() */ addr = (void *)__get_dma_pages(GFP_KERNEL, get_order(size)); flags = BLOCK_GFP; DPRINTK( "atari_stram_alloc: after mem_init, " "get_pages=%p\n", addr ); } if (addr) { if (!(block = add_region( addr, size ))) { /* out of memory for BLOCK structure :-( */ DPRINTK( "atari_stram_alloc: out of mem for BLOCK -- " "freeing again\n" ); free_pages((unsigned long)addr, get_order(size)); return( NULL ); } block->owner = owner; block->flags |= flags; } return( addr ); }
static int dma_init(void) { int ret; /* Request DMA channel */ ret = request_dma(CH_PPI, DRIVER_NAME); if(ret < 0) { printk(KERN_WARNING DRIVER_NAME ": Could not allocate DMA channel\n"); return ret; } /* Disable channel while it is being configured */ disable_dma(CH_PPI); /* Allocate buffer space for the DMA engine to use */ dma_buffer = __get_dma_pages(GFP_KERNEL, page_alloc_order(BUFFER_SIZE * BUFFER_COUNT)); if(dma_buffer == 0) { printk(KERN_WARNING DRIVER_NAME ": Could not allocate dma_pages\n"); free_dma(CH_PPI); return -ENOMEM; } /* Invalid caching on the DMA buffer */ invalidate_dcache_range(dma_buffer, dma_buffer + (BUFFER_SIZE * BUFFER_COUNT)); /* Set DMA configuration */ set_dma_start_addr(CH_PPI, dma_buffer); set_dma_config(CH_PPI, (DMAFLOW_AUTO | WNR | RESTART | DI_EN | WDSIZE_16 | DMA2D | DI_SEL)); set_dma_x_count(CH_PPI, SAMPLES_PER_BUFFER * CHANNELS); set_dma_x_modify(CH_PPI, SAMPLE_SIZE); set_dma_y_count(CH_PPI, BUFFER_COUNT); set_dma_y_modify(CH_PPI, SAMPLE_SIZE); set_dma_callback(CH_PPI, &buffer_full_handler, NULL); return 0; }
static void* camif_alloc_image_buffer(int size) { #ifndef DMA_TO_SRAM return (void*)__get_dma_pages(GFP_KERNEL, get_order(size)); #else return (void*)OMAP1510_SRAM_BASE; #endif }
static unsigned long jazz_fd_dma_mem_alloc(unsigned long size) { unsigned long mem; mem = __get_dma_pages(GFP_KERNEL, get_order(size)); if(!mem) return 0; vdma_alloc(PHYSADDR(mem), size); /* XXX error checking */ return mem; }
static inline void *dmaalloc(size_t size) { unsigned long addr; if (size == 0) { return NULL; } addr = __get_dma_pages(GFP_KERNEL, get_order(size)); if (addr) { struct page *page; for (page = virt_to_page(addr); page < virt_to_page(addr+size); page++) SetPageReserved(page); } return (void *)addr; }
static inline void *dmaalloc(size_t size) { unsigned long addr; if (size == 0) { return NULL; } addr = __get_dma_pages(GFP_KERNEL, __get_order(size)); if (addr) { int i; for (i = MAP_NR(addr); i < MAP_NR(addr+size); i++) { mem_map_reserve(i); } } return (void *)addr; }
static int omap2_mmu_startup(struct omap_mmu *mmu) { u32 rev = omap_mmu_read_reg(mmu, OMAP_MMU_REVISION); pr_info("MMU: OMAP %s MMU initialized (HW v%d.%d)\n", mmu->name, (rev >> 4) & 0xf, rev & 0xf); dspvect_page = (void *)__get_dma_pages(GFP_KERNEL, 0); if (dspvect_page == NULL) { dev_err(mmu->dev, "MMU %s: failed to allocate memory " "for vector table\n", mmu->name); return -ENOMEM; } mmu->nr_exmap_preserved = exmap_setup_preserved_entries(mmu); omap_mmu_write_reg(mmu, MMU_IRQ_MASK, OMAP_MMU_IRQENABLE); return 0; }
static int alloc_slots_buf_dma(struct slots_buf *sb, int order) { u32 *b; DENTER(); b = (u32 *) __get_dma_pages(GFP_KERNEL, order); if (!b) { dev_dbg(TEST_DEV, "speech: cannot allocate the buffer " "(order=%d)\n", order); DLEAVE(-ENOMEM); return -ENOMEM; } sb->buffer = b; sb->num_write = 0; sb->num_read = 0; sb->dma_running = 0; DLEAVE(0); return 0; }
__shimcall__ BOOL OsMemDMAAllocate(UINT32 nPages,PUINT16* ppPhysAddr, PHANDLE pMemHandle, PUINT16* ppBuffer) { int count; unsigned long allocs[256]; for ( count = 0 ; count < 256 ; count++ ) { allocs[count] = __get_dma_pages(OsContextAllowsSleeping() ? GFP_KERNEL : GFP_ATOMIC, nPages); if ( !allocs[count] ) { break; } if ( 0x0 == (((UINT32)(allocs[count])) & 0x0000FFFF) ) { *ppBuffer = (PUINT16)allocs[count]; if(pMemHandle) *pMemHandle = (PVOID) allocs[count]; *ppPhysAddr = (PUINT16)virt_to_bus(*ppBuffer); //printk(KERN_DEBUG"%s: success - 0x%lx(%p) after %d attempts\n", __FUNCTION__, allocs[count], *ppPhysAddr, count); for ( count--; count >= 0; count-- ) { free_pages(allocs[count], nPages); } return (TRUE); } } printk(KERN_ERR "%s: failed (attempt=%d, npages=%u)\n", __FUNCTION__, count, nPages); for ( count--; count >= 0; count-- ) free_pages(allocs[count], nPages); return (FALSE); }
static unsigned long dma_mem_alloc(int size) { int order = get_order(size); return __get_dma_pages(GFP_KERNEL, order); }
static inline void *dmaalloc(int order) { return (void *) __get_dma_pages(GFP_KERNEL, order); }
int sound_alloc_dmap (int dev, struct dma_buffparms *dmap, int chan) { char *start_addr, *end_addr; int i, dma_pagesize; dmap->mapping_flags &= ~DMA_MAP_MAPPED; if (dmap->raw_buf != NULL) return 0; /* Already done */ if (dma_buffsize < 4096) dma_buffsize = 4096; if (chan < 4) dma_pagesize = 64 * 1024; else dma_pagesize = 128 * 1024; dmap->raw_buf = NULL; if (debugmem) printk ("sound: buffsize[%d] = %lu\n", dev, audio_devs[dev]->buffsize); audio_devs[dev]->buffsize = dma_buffsize; if (audio_devs[dev]->buffsize > dma_pagesize) audio_devs[dev]->buffsize = dma_pagesize; start_addr = NULL; /* * Now loop until we get a free buffer. Try to get smaller buffer if * it fails. */ while (start_addr == NULL && audio_devs[dev]->buffsize > PAGE_SIZE) { int sz, size; for (sz = 0, size = PAGE_SIZE; size < audio_devs[dev]->buffsize; sz++, size <<= 1); audio_devs[dev]->buffsize = PAGE_SIZE * (1 << sz); if ((start_addr = (char *) __get_dma_pages (GFP_ATOMIC, sz)) == NULL) audio_devs[dev]->buffsize /= 2; } if (start_addr == NULL) { printk ("Sound error: Couldn't allocate DMA buffer\n"); return -(ENOMEM); } else { /* make some checks */ end_addr = start_addr + audio_devs[dev]->buffsize - 1; if (debugmem) printk ("sound: start 0x%lx, end 0x%lx\n", (long) start_addr, (long) end_addr); /* now check if it fits into the same dma-pagesize */ if (((long) start_addr & ~(dma_pagesize - 1)) != ((long) end_addr & ~(dma_pagesize - 1)) || end_addr >= (char *) (MAX_DMA_ADDRESS)) { printk ( "sound: Got invalid address 0x%lx for %ldb DMA-buffer\n", (long) start_addr, audio_devs[dev]->buffsize); return -(EFAULT); } } dmap->raw_buf = start_addr; dmap->raw_buf_phys = virt_to_bus (start_addr); for (i = MAP_NR (start_addr); i <= MAP_NR (end_addr); i++) { mem_map_reserve (i); } return 0; }
/* * This is main public interface: somehow allocate a ST-RAM block * There are three strategies: * * - If we're before mem_init(), we have to make a static allocation. The * region is taken in the kernel data area (if the kernel is in ST-RAM) or * from the start of ST-RAM (if the kernel is in TT-RAM) and added to the * rsvd_stram_* region. The ST-RAM is somewhere in the middle of kernel * address space in the latter case. * * - If mem_init() already has been called and ST-RAM swapping is enabled, * try to get the memory from the (pseudo) swap-space, either free already * or by moving some other pages out of the swap. * * - If mem_init() already has been called, and ST-RAM swapping is not * enabled, the only possibility is to try with __get_dma_pages(). This has * the disadvantage that it's very hard to get more than 1 page, and it is * likely to fail :-( * */ void *atari_stram_alloc( long size, unsigned long *start_mem, const char *owner ) { void *addr = NULL; BLOCK *block; int flags; DPRINTK( "atari_stram_alloc(size=%08lx,*start_mem=%08lx,owner=%s)\n", size, start_mem ? *start_mem : 0xffffffff, owner ); if (start_mem && mem_init_done) { printk( KERN_ERR "atari_stram_alloc called with start_mem!=NULL " "after mem_init() from %p\n", __builtin_return_address(0) ); return( NULL ); } if (!start_mem && !mem_init_done) { printk( KERN_ERR "atari_stram_alloc called with start_mem==NULL " "before mem_init() from %p\n", __builtin_return_address(0) ); return( NULL ); } size = ALIGN_IF_SWAP(size); DPRINTK( "atari_stram_alloc: rounded size = %08lx\n", size ); if (!mem_init_done) { /* before mem_init(): allocate "statically", i.e. either in the kernel * data space (current end in *start_mem), or at the end of currently * reserved ST-RAM. */ if (kernel_in_stram) { /* Get memory from kernel data space */ *start_mem = ALIGN_IF_SWAP(*start_mem); addr = (void *)*start_mem; *start_mem += size; DPRINTK( "atari_stram_alloc: pre-mem_init and k/ST: " "shifted start_mem to %08lx, addr=%p\n", *start_mem, addr ); } else { /* Get memory from rsvd_stram_beg */ if (rsvd_stram_end + size < stram_end) { addr = (void *) rsvd_stram_end; rsvd_stram_end += size; DPRINTK( "atari_stram_alloc: pre-mem_init and k/TT: " "shifted rsvd_stram_end to %08lx, addr=%p\n", rsvd_stram_end, addr ); } } flags = BLOCK_STATIC; } #ifdef CONFIG_STRAM_SWAP else if (max_swap_size) { /* If swapping is active (can only be the case after mem_init()!): * make some free space in the swap "device". */ DPRINTK( "atari_stram_alloc: after mem_init, swapping ok, " "calling get_region\n" ); addr = get_stram_region( N_PAGES(size) ); flags = BLOCK_INSWAP; } #endif else { /* After mem_init() and no swapping: can only resort to * __get_dma_pages() */ addr = (void *)__get_dma_pages(GFP_KERNEL, get_gfp_order(size)); flags = BLOCK_GFP; DPRINTK( "atari_stram_alloc: after mem_init, swapping off, " "get_pages=%p\n", addr ); } if (addr) { if (!(block = add_region( addr, size ))) { /* out of memory for BLOCK structure :-( */ DPRINTK( "atari_stram_alloc: out of mem for BLOCK -- " "freeing again\n" ); if (flags == BLOCK_STATIC) rsvd_stram_end -= size; #ifdef CONFIG_STRAM_SWAP else if (flags == BLOCK_INSWAP) free_stram_region( SWAP_NR(addr), N_PAGES(size) ); #endif else free_pages( (unsigned long)addr, get_gfp_order(size)); return( NULL ); } block->owner = owner; block->flags |= flags; } return( addr ); }