pci_direct_iommu.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Support for DMA from PCI devices to main memory on
  3. * machines without an iommu or with directly addressable
  4. * RAM (typically a pmac with 2Gb of RAM or less)
  5. *
  6. * Copyright (C) 2003 Benjamin Herrenschmidt (benh@kernel.crashing.org)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/pci.h>
  15. #include <linux/delay.h>
  16. #include <linux/string.h>
  17. #include <linux/init.h>
  18. #include <linux/bootmem.h>
  19. #include <linux/mm.h>
  20. #include <linux/dma-mapping.h>
  21. #include <asm/sections.h>
  22. #include <asm/io.h>
  23. #include <asm/prom.h>
  24. #include <asm/pci-bridge.h>
  25. #include <asm/machdep.h>
  26. #include <asm/pmac_feature.h>
  27. #include <asm/abs_addr.h>
  28. #include <asm/ppc-pci.h>
  29. static void *pci_direct_alloc_coherent(struct device *hwdev, size_t size,
  30. dma_addr_t *dma_handle, gfp_t flag)
  31. {
  32. void *ret;
  33. ret = (void *)__get_free_pages(flag, get_order(size));
  34. if (ret != NULL) {
  35. memset(ret, 0, size);
  36. *dma_handle = virt_to_abs(ret);
  37. }
  38. return ret;
  39. }
  40. static void pci_direct_free_coherent(struct device *hwdev, size_t size,
  41. void *vaddr, dma_addr_t dma_handle)
  42. {
  43. free_pages((unsigned long)vaddr, get_order(size));
  44. }
  45. static dma_addr_t pci_direct_map_single(struct device *hwdev, void *ptr,
  46. size_t size, enum dma_data_direction direction)
  47. {
  48. return virt_to_abs(ptr);
  49. }
  50. static void pci_direct_unmap_single(struct device *hwdev, dma_addr_t dma_addr,
  51. size_t size, enum dma_data_direction direction)
  52. {
  53. }
  54. static int pci_direct_map_sg(struct device *hwdev, struct scatterlist *sg,
  55. int nents, enum dma_data_direction direction)
  56. {
  57. int i;
  58. for (i = 0; i < nents; i++, sg++) {
  59. sg->dma_address = page_to_phys(sg->page) + sg->offset;
  60. sg->dma_length = sg->length;
  61. }
  62. return nents;
  63. }
  64. static void pci_direct_unmap_sg(struct device *hwdev, struct scatterlist *sg,
  65. int nents, enum dma_data_direction direction)
  66. {
  67. }
  68. static int pci_direct_dma_supported(struct device *dev, u64 mask)
  69. {
  70. return mask < 0x100000000ull;
  71. }
  72. void __init pci_direct_iommu_init(void)
  73. {
  74. pci_dma_ops.alloc_coherent = pci_direct_alloc_coherent;
  75. pci_dma_ops.free_coherent = pci_direct_free_coherent;
  76. pci_dma_ops.map_single = pci_direct_map_single;
  77. pci_dma_ops.unmap_single = pci_direct_unmap_single;
  78. pci_dma_ops.map_sg = pci_direct_map_sg;
  79. pci_dma_ops.unmap_sg = pci_direct_unmap_sg;
  80. pci_dma_ops.dma_supported = pci_direct_dma_supported;
  81. }