2 * Copyright (C) 2004 IBM Corporation
4 * Implements the generic device dma API for ppc64. Handles
5 * the pci and vio busses
8 #include <linux/device.h>
9 #include <linux/dma-mapping.h>
10 /* Include the busses we support */
11 #include <linux/pci.h>
13 #include <asm/scatterlist.h>
16 int dma_supported(struct device *dev, u64 mask)
18 if (dev->bus == &pci_bus_type)
19 return pci_dma_supported(to_pci_dev(dev), mask);
21 if (dev->bus == &vio_bus_type)
22 return vio_dma_supported(to_vio_dev(dev), mask);
23 #endif /* CONFIG_IBMVIO */
27 EXPORT_SYMBOL(dma_supported);
29 int dma_set_mask(struct device *dev, u64 dma_mask)
31 if (dev->bus == &pci_bus_type)
32 return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
34 if (dev->bus == &vio_bus_type)
35 return vio_set_dma_mask(to_vio_dev(dev), dma_mask);
36 #endif /* CONFIG_IBMVIO */
40 EXPORT_SYMBOL(dma_set_mask);
42 void *dma_alloc_coherent(struct device *dev, size_t size,
43 dma_addr_t *dma_handle, int flag)
45 if (dev->bus == &pci_bus_type)
46 return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
48 if (dev->bus == &vio_bus_type)
49 return vio_alloc_consistent(to_vio_dev(dev), size, dma_handle);
50 #endif /* CONFIG_IBMVIO */
54 EXPORT_SYMBOL(dma_alloc_coherent);
56 void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
57 dma_addr_t dma_handle)
59 if (dev->bus == &pci_bus_type)
60 pci_free_consistent(to_pci_dev(dev), size, cpu_addr, dma_handle);
62 else if (dev->bus == &vio_bus_type)
63 vio_free_consistent(to_vio_dev(dev), size, cpu_addr, dma_handle);
64 #endif /* CONFIG_IBMVIO */
68 EXPORT_SYMBOL(dma_free_coherent);
70 dma_addr_t dma_map_single(struct device *dev, void *cpu_addr, size_t size,
71 enum dma_data_direction direction)
73 if (dev->bus == &pci_bus_type)
74 return pci_map_single(to_pci_dev(dev), cpu_addr, size, (int)direction);
76 if (dev->bus == &vio_bus_type)
77 return vio_map_single(to_vio_dev(dev), cpu_addr, size, direction);
78 #endif /* CONFIG_IBMVIO */
82 EXPORT_SYMBOL(dma_map_single);
84 void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
85 enum dma_data_direction direction)
87 if (dev->bus == &pci_bus_type)
88 pci_unmap_single(to_pci_dev(dev), dma_addr, size, (int)direction);
90 else if (dev->bus == &vio_bus_type)
91 vio_unmap_single(to_vio_dev(dev), dma_addr, size, direction);
92 #endif /* CONFIG_IBMVIO */
96 EXPORT_SYMBOL(dma_unmap_single);
98 dma_addr_t dma_map_page(struct device *dev, struct page *page,
99 unsigned long offset, size_t size,
100 enum dma_data_direction direction)
102 if (dev->bus == &pci_bus_type)
103 return pci_map_page(to_pci_dev(dev), page, offset, size, (int)direction);
105 if (dev->bus == &vio_bus_type)
106 return vio_map_page(to_vio_dev(dev), page, offset, size, direction);
107 #endif /* CONFIG_IBMVIO */
109 return (dma_addr_t)0;
111 EXPORT_SYMBOL(dma_map_page);
113 void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
114 enum dma_data_direction direction)
116 if (dev->bus == &pci_bus_type)
117 pci_unmap_page(to_pci_dev(dev), dma_address, size, (int)direction);
119 else if (dev->bus == &vio_bus_type)
120 vio_unmap_page(to_vio_dev(dev), dma_address, size, direction);
121 #endif /* CONFIG_IBMVIO */
125 EXPORT_SYMBOL(dma_unmap_page);
127 int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
128 enum dma_data_direction direction)
130 if (dev->bus == &pci_bus_type)
131 return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
133 if (dev->bus == &vio_bus_type)
134 return vio_map_sg(to_vio_dev(dev), sg, nents, direction);
135 #endif /* CONFIG_IBMVIO */
139 EXPORT_SYMBOL(dma_map_sg);
141 void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
142 enum dma_data_direction direction)
144 if (dev->bus == &pci_bus_type)
145 pci_unmap_sg(to_pci_dev(dev), sg, nhwentries, (int)direction);
147 else if (dev->bus == &vio_bus_type)
148 vio_unmap_sg(to_vio_dev(dev), sg, nhwentries, direction);
149 #endif /* CONFIG_IBMVIO */
153 EXPORT_SYMBOL(dma_unmap_sg);