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
6 * Copyright (C) 2000 Ani Joshi <ajoshi@unixbox.com>
7 * Copyright (C) 2000, 2001, 06 Ralf Baechle <ralf@linux-mips.org>
8 * swiped from i386, and cloned for MIPS by Geert, polished by Ralf.
11 #include <linux/types.h>
12 #include <linux/dma-mapping.h>
14 #include <linux/module.h>
15 #include <linux/string.h>
17 #include <asm/cache.h>
20 #include <dma-coherence.h>
22 #include <linux/pci.h>
24 dma64_addr_t pci_dac_page_to_dma(struct pci_dev *pdev,
25 struct page *page, unsigned long offset, int direction)
27 struct device *dev = &pdev->dev;
29 BUG_ON(direction == DMA_NONE);
31 if (!plat_device_is_coherent(dev)) {
34 addr = (unsigned long) page_address(page) + offset;
35 dma_cache_wback_inv(addr, PAGE_SIZE);
38 return plat_map_dma_mem_page(dev, page) + offset;
41 EXPORT_SYMBOL(pci_dac_page_to_dma);
43 struct page *pci_dac_dma_to_page(struct pci_dev *pdev,
44 dma64_addr_t dma_addr)
46 return pfn_to_page(plat_dma_addr_to_phys(dma_addr) >> PAGE_SHIFT);
49 EXPORT_SYMBOL(pci_dac_dma_to_page);
51 unsigned long pci_dac_dma_to_offset(struct pci_dev *pdev,
52 dma64_addr_t dma_addr)
54 return dma_addr & ~PAGE_MASK;
57 EXPORT_SYMBOL(pci_dac_dma_to_offset);
59 void pci_dac_dma_sync_single_for_cpu(struct pci_dev *pdev,
60 dma64_addr_t dma_addr, size_t len, int direction)
62 BUG_ON(direction == PCI_DMA_NONE);
64 if (!plat_device_is_coherent(&pdev->dev))
65 dma_cache_wback_inv(dma_addr + PAGE_OFFSET, len);
68 EXPORT_SYMBOL(pci_dac_dma_sync_single_for_cpu);
70 void pci_dac_dma_sync_single_for_device(struct pci_dev *pdev,
71 dma64_addr_t dma_addr, size_t len, int direction)
73 BUG_ON(direction == PCI_DMA_NONE);
75 if (!plat_device_is_coherent(&pdev->dev))
76 dma_cache_wback_inv(dma_addr + PAGE_OFFSET, len);
79 EXPORT_SYMBOL(pci_dac_dma_sync_single_for_device);