linux/arch/sparc/kernel/ioport.c
/* Allocate and map kernel buffer using consistent mode DMA for a device.
 * hwdev should be valid struct pci_dev pointer for PCI devices.
 */
Allocate and map kernel buffer using consistent mode DMA for a device.
hwdev should be valid struct pci_dev pointer for PCI devices.
Allocate and map kernel buffer using consistent mode DMA for a device . hwdev should be valid struct pci_dev pointer for PCI devices .
void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
		gfp_t gfp, unsigned long attrs)
{
	unsigned long len_total = PAGE_ALIGN(size);
	void *va;
	struct resource *res;
	int order;
	if (size == 0) {
		return NULL;
	}
	if (size > 256*1024) {			
		return NULL;
	}
	order = get_order(len_total);
	va = (void *) __get_free_pages(gfp, order);
	if (va == NULL) {
		printk("%s: no %ld pages\n", __func__, len_total>>PAGE_SHIFT);
		goto err_nopages;
	}
	if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) {
		printk("%s: no core\n", __func__);
		goto err_nomem;
	}
	if (allocate_resource(&_sparc_dvma, res, len_total,
	    _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
		printk("%s: cannot occupy 0x%lx", __func__, len_total);
		goto err_nova;
	}
	srmmu_mapiorange(0, virt_to_phys(va), res->start, len_total);
	*dma_handle = virt_to_phys(va);
	return (void *) res->start;
err_nova:
	kfree(res);
err_nomem:
	free_pages((unsigned long)va, order);
err_nopages:
	return NULL;
}
void * arch_dma_alloc ( struct device * dev , size_t size , dma_addr_t * dma_handle , gfp_t gfp , unsigned long attrs ) { unsigned long len_total = PAGE_ALIGN ( size ) ; void * va ; struct resource * res ; int order ; if ( size == 0 ) { return NULL ; } if ( size > 256 * 1024 ) { return NULL ; } order = get_order ( len_total ) ; va = ( void * ) __get_free_pages ( gfp , order ) ; if ( va == NULL ) { printk ( " \n " , __func__ , len_total >> PAGE_SHIFT ) ; goto err_nopages ; } if ( ( res = kzalloc ( sizeof ( struct resource ) , GFP_KERNEL ) ) == NULL ) { printk ( " \n " , __func__ ) ; goto err_nomem ; } if ( allocate_resource ( & _sparc_dvma , res , len_total , _sparc_dvma . start , _sparc_dvma . end , PAGE_SIZE , NULL , NULL ) != 0 ) { printk ( " " , __func__ , len_total ) ; goto err_nova ; } srmmu_mapiorange ( 0 , virt_to_phys ( va ) , res -> start , len_total ) ; * dma_handle = virt_to_phys ( va ) ; return ( void * ) res -> start ; err_nova : kfree ( res ) ; err_nomem : free_pages ( ( unsigned long ) va , order ) ; err_nopages : return NULL ; }
Allocate and map kernel buffer using consistent mode DMA for a device.
Allocate and map kernel buffer using consistent mode DMA for a device .
/* __get_free_pages() limit */