dma_64.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2004 IBM Corporation
  3. *
  4. * Implements the generic device dma API for ppc64. Handles
  5. * the pci and vio busses
  6. */
  7. #include <linux/device.h>
  8. #include <linux/dma-mapping.h>
  9. /* Include the busses we support */
  10. #include <linux/pci.h>
  11. #include <asm/vio.h>
  12. #include <asm/ibmebus.h>
  13. #include <asm/scatterlist.h>
  14. #include <asm/bug.h>
  15. static struct dma_mapping_ops *get_dma_ops(struct device *dev)
  16. {
  17. #ifdef CONFIG_PCI
  18. if (dev->bus == &pci_bus_type)
  19. return &pci_dma_ops;
  20. #endif
  21. #ifdef CONFIG_IBMVIO
  22. if (dev->bus == &vio_bus_type)
  23. return &vio_dma_ops;
  24. #endif
  25. #ifdef CONFIG_IBMEBUS
  26. if (dev->bus == &ibmebus_bus_type)
  27. return &ibmebus_dma_ops;
  28. #endif
  29. return NULL;
  30. }
  31. int dma_supported(struct device *dev, u64 mask)
  32. {
  33. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  34. BUG_ON(!dma_ops);
  35. return dma_ops->dma_supported(dev, mask);
  36. }
  37. EXPORT_SYMBOL(dma_supported);
  38. int dma_set_mask(struct device *dev, u64 dma_mask)
  39. {
  40. #ifdef CONFIG_PCI
  41. if (dev->bus == &pci_bus_type)
  42. return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
  43. #endif
  44. #ifdef CONFIG_IBMVIO
  45. if (dev->bus == &vio_bus_type)
  46. return -EIO;
  47. #endif /* CONFIG_IBMVIO */
  48. #ifdef CONFIG_IBMEBUS
  49. if (dev->bus == &ibmebus_bus_type)
  50. return -EIO;
  51. #endif
  52. BUG();
  53. return 0;
  54. }
  55. EXPORT_SYMBOL(dma_set_mask);
  56. void *dma_alloc_coherent(struct device *dev, size_t size,
  57. dma_addr_t *dma_handle, gfp_t flag)
  58. {
  59. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  60. BUG_ON(!dma_ops);
  61. return dma_ops->alloc_coherent(dev, size, dma_handle, flag);
  62. }
  63. EXPORT_SYMBOL(dma_alloc_coherent);
  64. void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
  65. dma_addr_t dma_handle)
  66. {
  67. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  68. BUG_ON(!dma_ops);
  69. dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
  70. }
  71. EXPORT_SYMBOL(dma_free_coherent);
  72. dma_addr_t dma_map_single(struct device *dev, void *cpu_addr, size_t size,
  73. enum dma_data_direction direction)
  74. {
  75. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  76. BUG_ON(!dma_ops);
  77. return dma_ops->map_single(dev, cpu_addr, size, direction);
  78. }
  79. EXPORT_SYMBOL(dma_map_single);
  80. void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  81. enum dma_data_direction direction)
  82. {
  83. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  84. BUG_ON(!dma_ops);
  85. dma_ops->unmap_single(dev, dma_addr, size, direction);
  86. }
  87. EXPORT_SYMBOL(dma_unmap_single);
  88. dma_addr_t dma_map_page(struct device *dev, struct page *page,
  89. unsigned long offset, size_t size,
  90. enum dma_data_direction direction)
  91. {
  92. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  93. BUG_ON(!dma_ops);
  94. return dma_ops->map_single(dev, page_address(page) + offset, size,
  95. direction);
  96. }
  97. EXPORT_SYMBOL(dma_map_page);
  98. void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  99. enum dma_data_direction direction)
  100. {
  101. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  102. BUG_ON(!dma_ops);
  103. dma_ops->unmap_single(dev, dma_address, size, direction);
  104. }
  105. EXPORT_SYMBOL(dma_unmap_page);
  106. int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  107. enum dma_data_direction direction)
  108. {
  109. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  110. BUG_ON(!dma_ops);
  111. return dma_ops->map_sg(dev, sg, nents, direction);
  112. }
  113. EXPORT_SYMBOL(dma_map_sg);
  114. void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  115. enum dma_data_direction direction)
  116. {
  117. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  118. BUG_ON(!dma_ops);
  119. dma_ops->unmap_sg(dev, sg, nhwentries, direction);
  120. }
  121. EXPORT_SYMBOL(dma_unmap_sg);