kernels/linux-2.4.0/arch/arm/mm/consistent.c
/*
 * This allocates one page of cache-coherent memory space and returns
 * both the virtual and a "dma" address to that space.  It is not clear
 * whether this could be called from an interrupt context or not.  For
 * now, we expressly forbid it, especially as some of the stuff we do
 * here is not interrupt context safe.
 *
 * Note that this does *not* zero the allocated area!
 */
This allocates one page of cache-coherent memory space and returns
both the virtual and a "dma" address to that space.  It is not clear
whether this could be called from an interrupt context or not.  For
now, we expressly forbid it, especially as some of the stuff we do
here is not interrupt context safe.

Note that this does *not* zero the allocated area!
This allocates one page of cache - coherent memory space and returns both the virtual and a " dma " address to that space . It is not clear whether this could be called from an interrupt context or not . For now we expressly forbid it especially as some of the stuff we do here is not interrupt context safe . Note that this does * not * zero the allocated area!
void *consistent_alloc(int gfp, size_t size, dma_addr_t *dma_handle)
{
	int order;
	unsigned long page;
	void *ret;
	if (in_interrupt())
		BUG();
	size = PAGE_ALIGN(size);
	order = get_order(size);
	page = __get_free_pages(gfp, order);
	if (!page)
		goto no_page;
	ret = __ioremap(virt_to_phys((void *)page), size, 0);
	if (ret) {
		unsigned long end;
		invalidate_dcache_range(page, page + size);
		invalidate_dcache_range((unsigned long)ret, (unsigned long)ret + size);
		*dma_handle = __virt_to_bus(page);
		end = page + (PAGE_SIZE << order);
		page += size;
		while (page < end) {
			free_page(page);
			page += PAGE_SIZE;
		}
		return ret;
	}
	free_pages(page, order);
no_page:
	BUG();
	return NULL;
}
void * consistent_alloc ( int gfp , size_t size , dma_addr_t * dma_handle ) { int order ; unsigned long page ; void * ret ; if ( in_interrupt ( ) ) BUG ( ) ; size = PAGE_ALIGN ( size ) ; order = get_order ( size ) ; page = __get_free_pages ( gfp , order ) ; if ( ! page ) goto no_page ; ret = __ioremap ( virt_to_phys ( ( void * ) page ) , size , 0 ) ; if ( ret ) { unsigned long end ; invalidate_dcache_range ( page , page + size ) ; invalidate_dcache_range ( ( unsigned long ) ret , ( unsigned long ) ret + size ) ; * dma_handle = __virt_to_bus ( page ) ; end = page + ( PAGE_SIZE << order ) ; page += size ; while ( page < end ) { free_page ( page ) ; page += PAGE_SIZE ; } return ret ; } free_pages ( page , order ) ; no_page : BUG ( ) ; return NULL ; }
This allocates one page of cache-coherent memory space and returns
 both the virtual and a "dma" address to that space.
This allocates one page of cache - coherent memory space and returns both the virtual and a " dma " address to that space .
/* free wasted pages */ /*
		 * we need to ensure that there are no
		 * cachelines in use, or worse dirty in
		 * this area.
		 */