Index: pci_dma.c =================================================================== RCS file: /cvs/linuxppc64/linuxppc64_2_5/arch/ppc64/kernel/pci_dma.c,v retrieving revision 1.14 diff -u -r1.14 pci_dma.c --- pci_dma.c 22 Oct 2003 15:36:10 -0000 1.14 +++ pci_dma.c 31 Oct 2003 23:12:34 -0000 @@ -994,50 +994,24 @@ void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size, dma_addr_t *dma_handle) { - struct TceTable * tbl; - void *ret = NULL; - unsigned order, nPages; - dma_addr_t tce; + void *ret; PPCDBG(PPCDBG_TCE, "pci_alloc_consistent:\n"); PPCDBG(PPCDBG_TCE, "\thwdev = 0x%16.16lx\n", hwdev); PPCDBG(PPCDBG_TCE, "\tsize = 0x%16.16lx\n", size); PPCDBG(PPCDBG_TCE, "\tdma_handle = 0x%16.16lx\n", dma_handle); - size = PAGE_ALIGN(size); - order = get_order(size); - nPages = 1 << order; - - /* Client asked for way to much space. This is checked later anyway */ - /* It is easier to debug here for the drivers than in the tce tables.*/ - if(order >= NUM_TCE_LEVELS) { - printk("PCI_DMA: pci_alloc_consistent size to large: 0x%lx \n",size); - return (void *)NO_TCE; - } - - tbl = get_tce_table(hwdev); - - if ( tbl ) { - /* Alloc enough pages (and possibly more) */ - ret = (void *)__get_free_pages( GFP_ATOMIC, order ); - if ( ret ) { - /* Page allocation succeeded */ - memset(ret, 0, nPages << PAGE_SHIFT); - /* Set up tces to cover the allocated range */ - tce = get_tces( tbl, order, ret, nPages, PCI_DMA_BIDIRECTIONAL ); - if ( tce == NO_TCE ) { - PPCDBG(PPCDBG_TCE, "pci_alloc_consistent: get_tces failed\n" ); - free_pages( (unsigned long)ret, order ); - ret = NULL; - } - else - { - *dma_handle = tce; - } + ret = kmalloc(size, GFP_ATOMIC); + + if (ret) { + *dma_handle = pci_map_single(hwdev, ret, size, PCI_DMA_BIDIRECTIONAL); + + if (*dma_handle == NO_TCE) { + kfree(ret); + ret = NULL; } - else PPCDBG(PPCDBG_TCE, "pci_alloc_consistent: __get_free_pages failed for order = %d\n", order); } - else PPCDBG(PPCDBG_TCE, "pci_alloc_consistent: get_tce_table failed for 0x%016lx\n", hwdev); + else PPCDBG(PPCDBG_TCE, "pci_alloc_consistent: kmalloc failed for size = %d\n", size); PPCDBG(PPCDBG_TCE, "\tpci_alloc_consistent: dma_handle = 0x%16.16lx\n", *dma_handle); PPCDBG(PPCDBG_TCE, "\tpci_alloc_consistent: return = 0x%16.16lx\n", ret); @@ -1047,29 +1021,14 @@ void pci_free_consistent(struct pci_dev *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle) { - struct TceTable * tbl; - unsigned order, nPages; - + if (!vaddr) + return; + PPCDBG(PPCDBG_TCE, "pci_free_consistent:\n"); PPCDBG(PPCDBG_TCE, "\thwdev = 0x%16.16lx, size = 0x%16.16lx, dma_handle = 0x%16.16lx, vaddr = 0x%16.16lx\n", hwdev, size, dma_handle, vaddr); - size = PAGE_ALIGN(size); - order = get_order(size); - nPages = 1 << order; - - /* Client asked for way to much space. This is checked later anyway */ - /* It is easier to debug here for the drivers than in the tce tables.*/ - if(order >= NUM_TCE_LEVELS) { - printk("PCI_DMA: pci_free_consistent size to large: 0x%lx \n",size); - return; - } - - tbl = get_tce_table(hwdev); - - if ( tbl ) { - tce_free(tbl, dma_handle, order, nPages); - free_pages( (unsigned long)vaddr, order ); - } + pci_unmap_single(hwdev, dma_handle, size, PCI_DMA_BIDIRECTIONAL); + kfree(vaddr); } /* Creates TCEs for a user provided buffer. The user buffer must be