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);
20 if (dev->bus == &vio_bus_type)
21 return vio_dma_supported(to_vio_dev(dev), mask);
25 EXPORT_SYMBOL(dma_supported);
27 int dma_set_mask(struct device *dev, u64 dma_mask)
29 if (dev->bus == &pci_bus_type)
30 return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
31 if (dev->bus == &vio_bus_type)
32 return vio_set_dma_mask(to_vio_dev(dev), dma_mask);
36 EXPORT_SYMBOL(dma_set_mask);
38 void *dma_alloc_coherent(struct device *dev, size_t size,
39 dma_addr_t *dma_handle, int flag)
41 if (dev->bus == &pci_bus_type)
42 return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
43 if (dev->bus == &vio_bus_type)
44 return vio_alloc_consistent(to_vio_dev(dev), size, dma_handle);
48 EXPORT_SYMBOL(dma_alloc_coherent);
50 void dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
51 dma_addr_t dma_handle)
53 if (dev->bus == &pci_bus_type)
54 pci_free_consistent(to_pci_dev(dev), size, cpu_addr, dma_handle);
55 else if (dev->bus == &vio_bus_type)
56 vio_free_consistent(to_vio_dev(dev), size, cpu_addr, dma_handle);
60 EXPORT_SYMBOL(dma_free_coherent);
62 dma_addr_t dma_map_single(struct device *dev, void *cpu_addr, size_t size,
63 enum dma_data_direction direction)
65 if (dev->bus == &pci_bus_type)
66 return pci_map_single(to_pci_dev(dev), cpu_addr, size, (int)direction);
67 if (dev->bus == &vio_bus_type)
68 return vio_map_single(to_vio_dev(dev), cpu_addr, size, direction);
72 EXPORT_SYMBOL(dma_map_single);
74 void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
75 enum dma_data_direction direction)
77 if (dev->bus == &pci_bus_type)
78 pci_unmap_single(to_pci_dev(dev), dma_addr, size, (int)direction);
79 else if (dev->bus == &vio_bus_type)
80 vio_unmap_single(to_vio_dev(dev), dma_addr, size, direction);
84 EXPORT_SYMBOL(dma_unmap_single);
86 dma_addr_t dma_map_page(struct device *dev, struct page *page,
87 unsigned long offset, size_t size,
88 enum dma_data_direction direction)
90 if (dev->bus == &pci_bus_type)
91 return pci_map_page(to_pci_dev(dev), page, offset, size, (int)direction);
92 if (dev->bus == &vio_bus_type)
93 return vio_map_page(to_vio_dev(dev), page, offset, size, direction);
97 EXPORT_SYMBOL(dma_map_page);
99 void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
100 enum dma_data_direction direction)
102 if (dev->bus == &pci_bus_type)
103 pci_unmap_page(to_pci_dev(dev), dma_address, size, (int)direction);
104 else if (dev->bus == &vio_bus_type)
105 vio_unmap_page(to_vio_dev(dev), dma_address, size, direction);
109 EXPORT_SYMBOL(dma_unmap_page);
111 int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
112 enum dma_data_direction direction)
114 if (dev->bus == &pci_bus_type)
115 return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
116 if (dev->bus == &vio_bus_type)
117 return vio_map_sg(to_vio_dev(dev), sg, nents, direction);
121 EXPORT_SYMBOL(dma_map_sg);
123 void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
124 enum dma_data_direction direction)
126 if (dev->bus == &pci_bus_type)
127 pci_unmap_sg(to_pci_dev(dev), sg, nhwentries, (int)direction);
128 else if (dev->bus == &vio_bus_type)
129 vio_unmap_sg(to_vio_dev(dev), sg, nhwentries, direction);
133 EXPORT_SYMBOL(dma_unmap_sg);