1/* 2 * Dynamic DMA mapping support. 3 * 4 * On i386 there is no hardware dynamic DMA address translation, 5 * so consistent alloc/free are merely page allocation/freeing. 6 * The rest of the dynamic DMA mapping interface is implemented 7 * in asm/pci.h. 8 */ 9 10#include <linux/types.h> 11#include <linux/mm.h> 12#include <linux/string.h> 13#include <linux/pci.h> 14#include <asm/io.h> 15 16void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size, 17 dma_addr_t *dma_handle) 18{ 19 void *ret; 20 int gfp = GFP_ATOMIC; 21 22 if (hwdev == NULL || ((u32)hwdev->dma_mask < 0xffffffff)) 23 gfp |= GFP_DMA; 24 ret = (void *)__get_free_pages(gfp, get_order(size)); 25 26 if (ret != NULL) { 27 memset(ret, 0, size); 28 *dma_handle = virt_to_bus(ret); 29 } 30 return ret; 31} 32 33void pci_free_consistent(struct pci_dev *hwdev, size_t size, 34 void *vaddr, dma_addr_t dma_handle) 35{ 36 free_pages((unsigned long)vaddr, get_order(size)); 37} 38