1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 2000  Ani Joshi <ajoshi@unixbox.com>
7  * Copyright (C) 2000, 2001  Ralf Baechle <ralf@gnu.org>
8  * swiped from i386, and cloned for MIPS by Geert, polished by Ralf.
9  */
10 #include <linux/config.h>
11 #include <linux/types.h>
12 #include <linux/mm.h>
13 #include <linux/module.h>
14 #include <linux/string.h>
15 #include <linux/pci.h>
16 
17 #include <asm/io.h>
18 
pci_alloc_consistent(struct pci_dev * hwdev,size_t size,dma_addr_t * dma_handle)19 void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
20 			   dma_addr_t * dma_handle)
21 {
22 	void *ret;
23 	int gfp = GFP_ATOMIC;
24 	struct pci_bus *bus = NULL;
25 
26 #ifdef CONFIG_ISA
27 	if (hwdev == NULL || hwdev->dma_mask != 0xffffffff)
28 		gfp |= GFP_DMA;
29 #endif
30 	ret = (void *) __get_free_pages(gfp, get_order(size));
31 
32 	if (ret != NULL) {
33 		memset(ret, 0, size);
34 		if (hwdev)
35 			bus = hwdev->bus;
36 		*dma_handle = bus_to_baddr(bus, __pa(ret));
37 #ifdef CONFIG_NONCOHERENT_IO
38 		dma_cache_wback_inv((unsigned long) ret, size);
39 		ret = UNCAC_ADDR(ret);
40 #endif
41 	}
42 
43 	return ret;
44 }
45 
pci_free_consistent(struct pci_dev * hwdev,size_t size,void * vaddr,dma_addr_t dma_handle)46 void pci_free_consistent(struct pci_dev *hwdev, size_t size,
47 			 void *vaddr, dma_addr_t dma_handle)
48 {
49 	unsigned long addr = (unsigned long) vaddr;
50 
51 #ifdef CONFIG_NONCOHERENT_IO
52 	addr = CAC_ADDR(addr);
53 #endif
54 	free_pages(addr, get_order(size));
55 }
56 
57 EXPORT_SYMBOL(pci_alloc_consistent);
58 EXPORT_SYMBOL(pci_free_consistent);
59