pci-dac.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include <linux/types.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/mm.h>
  13. #include <linux/module.h>
  14. #include <linux/string.h>
  15. #include <asm/cache.h>
  16. #include <asm/io.h>
  17. #include <dma-coherence.h>
  18. #include <linux/pci.h>
  19. dma64_addr_t pci_dac_page_to_dma(struct pci_dev *pdev,
  20. struct page *page, unsigned long offset, int direction)
  21. {
  22. struct device *dev = &pdev->dev;
  23. BUG_ON(direction == DMA_NONE);
  24. if (!plat_device_is_coherent(dev)) {
  25. unsigned long addr;
  26. addr = (unsigned long) page_address(page) + offset;
  27. dma_cache_wback_inv(addr, PAGE_SIZE);
  28. }
  29. return plat_map_dma_mem_page(dev, page) + offset;
  30. }
  31. EXPORT_SYMBOL(pci_dac_page_to_dma);
  32. struct page *pci_dac_dma_to_page(struct pci_dev *pdev,
  33. dma64_addr_t dma_addr)
  34. {
  35. return pfn_to_page(plat_dma_addr_to_phys(dma_addr) >> PAGE_SHIFT);
  36. }
  37. EXPORT_SYMBOL(pci_dac_dma_to_page);
  38. unsigned long pci_dac_dma_to_offset(struct pci_dev *pdev,
  39. dma64_addr_t dma_addr)
  40. {
  41. return dma_addr & ~PAGE_MASK;
  42. }
  43. EXPORT_SYMBOL(pci_dac_dma_to_offset);
  44. void pci_dac_dma_sync_single_for_cpu(struct pci_dev *pdev,
  45. dma64_addr_t dma_addr, size_t len, int direction)
  46. {
  47. BUG_ON(direction == PCI_DMA_NONE);
  48. if (!plat_device_is_coherent(&pdev->dev))
  49. dma_cache_wback_inv(dma_addr + PAGE_OFFSET, len);
  50. }
  51. EXPORT_SYMBOL(pci_dac_dma_sync_single_for_cpu);
  52. void pci_dac_dma_sync_single_for_device(struct pci_dev *pdev,
  53. dma64_addr_t dma_addr, size_t len, int direction)
  54. {
  55. BUG_ON(direction == PCI_DMA_NONE);
  56. if (!plat_device_is_coherent(&pdev->dev))
  57. dma_cache_wback_inv(dma_addr + PAGE_OFFSET, len);
  58. }
  59. EXPORT_SYMBOL(pci_dac_dma_sync_single_for_device);