Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[linux-drm-fsl-dcu.git] / arch / mips / pci / pci-dac.c
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, 06  Ralf Baechle <ralf@linux-mips.org>
8  * swiped from i386, and cloned for MIPS by Geert, polished by Ralf.
9  */
10
11 #include <linux/types.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/mm.h>
14 #include <linux/module.h>
15 #include <linux/string.h>
16
17 #include <asm/cache.h>
18 #include <asm/io.h>
19
20 #include <dma-coherence.h>
21
22 #include <linux/pci.h>
23
24 dma64_addr_t pci_dac_page_to_dma(struct pci_dev *pdev,
25         struct page *page, unsigned long offset, int direction)
26 {
27         struct device *dev = &pdev->dev;
28
29         BUG_ON(direction == DMA_NONE);
30
31         if (!plat_device_is_coherent(dev)) {
32                 unsigned long addr;
33
34                 addr = (unsigned long) page_address(page) + offset;
35                 dma_cache_wback_inv(addr, PAGE_SIZE);
36         }
37
38         return plat_map_dma_mem_page(dev, page) + offset;
39 }
40
41 EXPORT_SYMBOL(pci_dac_page_to_dma);
42
43 struct page *pci_dac_dma_to_page(struct pci_dev *pdev,
44         dma64_addr_t dma_addr)
45 {
46         return pfn_to_page(plat_dma_addr_to_phys(dma_addr) >> PAGE_SHIFT);
47 }
48
49 EXPORT_SYMBOL(pci_dac_dma_to_page);
50
51 unsigned long pci_dac_dma_to_offset(struct pci_dev *pdev,
52         dma64_addr_t dma_addr)
53 {
54         return dma_addr & ~PAGE_MASK;
55 }
56
57 EXPORT_SYMBOL(pci_dac_dma_to_offset);
58
59 void pci_dac_dma_sync_single_for_cpu(struct pci_dev *pdev,
60         dma64_addr_t dma_addr, size_t len, int direction)
61 {
62         BUG_ON(direction == PCI_DMA_NONE);
63
64         if (!plat_device_is_coherent(&pdev->dev))
65                 dma_cache_wback_inv(dma_addr + PAGE_OFFSET, len);
66 }
67
68 EXPORT_SYMBOL(pci_dac_dma_sync_single_for_cpu);
69
70 void pci_dac_dma_sync_single_for_device(struct pci_dev *pdev,
71         dma64_addr_t dma_addr, size_t len, int direction)
72 {
73         BUG_ON(direction == PCI_DMA_NONE);
74
75         if (!plat_device_is_coherent(&pdev->dev))
76                 dma_cache_wback_inv(dma_addr + PAGE_OFFSET, len);
77 }
78
79 EXPORT_SYMBOL(pci_dac_dma_sync_single_for_device);