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
19void *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
25#ifdef CONFIG_ISA
26	if (hwdev == NULL || hwdev->dma_mask != 0xffffffff)
27		gfp |= GFP_DMA;
28#endif
29	ret = (void *) __get_free_pages(gfp, get_order(size));
30
31	if (ret != NULL) {
32		memset(ret, 0, size);
33		*dma_handle = bus_to_baddr(hwdev->bus, __pa(ret));
34#ifdef CONFIG_NONCOHERENT_IO
35		dma_cache_wback_inv((unsigned long) ret, size);
36		ret = UNCAC_ADDR(ret);
37#endif
38	}
39
40	return ret;
41}
42
43void pci_free_consistent(struct pci_dev *hwdev, size_t size,
44			 void *vaddr, dma_addr_t dma_handle)
45{
46	unsigned long addr = (unsigned long) vaddr;
47
48#ifdef CONFIG_NONCOHERENT_IO
49	addr = CAC_ADDR(addr);
50#endif
51	free_pages(addr, get_order(size));
52}
53
54EXPORT_SYMBOL(pci_alloc_consistent);
55EXPORT_SYMBOL(pci_free_consistent);
56