dma.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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/scatterlist.h>
  13. #include <asm/bug.h>
  14. static struct dma_mapping_ops *get_dma_ops(struct device *dev)
  15. {
  16. if (dev->bus == &pci_bus_type)
  17. return &pci_dma_ops;
  18. #ifdef CONFIG_IBMVIO
  19. if (dev->bus == &vio_bus_type)
  20. return &vio_dma_ops;
  21. #endif
  22. return NULL;
  23. }
  24. int dma_supported(struct device *dev, u64 mask)
  25. {
  26. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  27. if (dma_ops)
  28. return dma_ops->dma_supported(dev, mask);
  29. BUG();
  30. return 0;
  31. }
  32. EXPORT_SYMBOL(dma_supported);
  33. int dma_set_mask(struct device *dev, u64 dma_mask)
  34. {
  35. if (dev->bus == &pci_bus_type)
  36. return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
  37. #ifdef CONFIG_IBMVIO
  38. if (dev->bus == &vio_bus_type)
  39. return -EIO;
  40. #endif /* CONFIG_IBMVIO */
  41. BUG();
  42. return 0;
  43. }
  44. EXPORT_SYMBOL(dma_set_mask);
  45. void *dma_alloc_coherent(struct device *dev, size_t size,
  46. dma_addr_t *dma_handle, unsigned int __nocast flag)
  47. {
  48. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  49. if (dma_ops)
  50. return dma_ops->alloc_coherent(dev, size, dma_handle, flag);
  51. BUG();
  52. return NULL;
  53. }
  54. EXPORT_SYMBOL(dma_alloc_coherent);
  55. void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
  56. dma_addr_t dma_handle)
  57. {
  58. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  59. if (dma_ops)
  60. dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
  61. else
  62. BUG();
  63. }
  64. EXPORT_SYMBOL(dma_free_coherent);
  65. dma_addr_t dma_map_single(struct device *dev, void *cpu_addr, size_t size,
  66. enum dma_data_direction direction)
  67. {
  68. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  69. if (dma_ops)
  70. return dma_ops->map_single(dev, cpu_addr, size, direction);
  71. BUG();
  72. return (dma_addr_t)0;
  73. }
  74. EXPORT_SYMBOL(dma_map_single);
  75. void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
  76. enum dma_data_direction direction)
  77. {
  78. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  79. if (dma_ops)
  80. dma_ops->unmap_single(dev, dma_addr, size, direction);
  81. else
  82. BUG();
  83. }
  84. EXPORT_SYMBOL(dma_unmap_single);
  85. dma_addr_t dma_map_page(struct device *dev, struct page *page,
  86. unsigned long offset, size_t size,
  87. enum dma_data_direction direction)
  88. {
  89. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  90. if (dma_ops)
  91. return dma_ops->map_single(dev,
  92. (page_address(page) + offset), size, direction);
  93. BUG();
  94. return (dma_addr_t)0;
  95. }
  96. EXPORT_SYMBOL(dma_map_page);
  97. void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
  98. enum dma_data_direction direction)
  99. {
  100. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  101. if (dma_ops)
  102. dma_ops->unmap_single(dev, dma_address, size, direction);
  103. else
  104. BUG();
  105. }
  106. EXPORT_SYMBOL(dma_unmap_page);
  107. int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
  108. enum dma_data_direction direction)
  109. {
  110. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  111. if (dma_ops)
  112. return dma_ops->map_sg(dev, sg, nents, direction);
  113. BUG();
  114. return 0;
  115. }
  116. EXPORT_SYMBOL(dma_map_sg);
  117. void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
  118. enum dma_data_direction direction)
  119. {
  120. struct dma_mapping_ops *dma_ops = get_dma_ops(dev);
  121. if (dma_ops)
  122. dma_ops->unmap_sg(dev, sg, nhwentries, direction);
  123. else
  124. BUG();
  125. }
  126. EXPORT_SYMBOL(dma_unmap_sg);