1 /* dma.c: PCI and SBUS DMA accessors for 32-bit sparc.
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/dma-mapping.h>
9 #include <linux/scatterlist.h>
13 #include <linux/pci.h>
18 int dma_supported(struct device *dev, u64 mask)
21 if (dev->bus == &pci_bus_type)
22 return pci_dma_supported(to_pci_dev(dev), mask);
26 EXPORT_SYMBOL(dma_supported);
28 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);
36 EXPORT_SYMBOL(dma_set_mask);
38 static void *dma32_alloc_coherent(struct device *dev, size_t size,
39 dma_addr_t *dma_handle, gfp_t flag)
42 if (dev->bus == &pci_bus_type)
43 return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
45 return sbus_alloc_consistent(dev, size, dma_handle);
48 static void dma32_free_coherent(struct device *dev, size_t size,
49 void *cpu_addr, dma_addr_t dma_handle)
52 if (dev->bus == &pci_bus_type) {
53 pci_free_consistent(to_pci_dev(dev), size,
54 cpu_addr, dma_handle);
58 sbus_free_consistent(dev, size, cpu_addr, dma_handle);
61 static dma_addr_t dma32_map_page(struct device *dev, struct page *page,
62 unsigned long offset, size_t size,
63 enum dma_data_direction direction,
64 struct dma_attrs *attrs)
67 if (dev->bus == &pci_bus_type)
68 return pci_map_page(to_pci_dev(dev), page, offset,
69 size, (int)direction);
71 return sbus_map_page(dev, page, offset, size, (int)direction);
74 static void dma32_unmap_page(struct device *dev, dma_addr_t dma_address,
75 size_t size, enum dma_data_direction direction,
76 struct dma_attrs *attrs)
79 if (dev->bus == &pci_bus_type) {
80 pci_unmap_page(to_pci_dev(dev), dma_address,
81 size, (int)direction);
85 sbus_unmap_page(dev, dma_address, size, (int)direction);
88 static int dma32_map_sg(struct device *dev, struct scatterlist *sg,
89 int nents, enum dma_data_direction direction,
90 struct dma_attrs *attrs)
93 if (dev->bus == &pci_bus_type)
94 return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
96 return sbus_map_sg(dev, sg, nents, direction);
99 void dma32_unmap_sg(struct device *dev, struct scatterlist *sg,
100 int nents, enum dma_data_direction direction,
101 struct dma_attrs *attrs)
104 if (dev->bus == &pci_bus_type) {
105 pci_unmap_sg(to_pci_dev(dev), sg, nents, (int)direction);
109 sbus_unmap_sg(dev, sg, nents, (int)direction);
112 static void dma32_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
114 enum dma_data_direction direction)
117 if (dev->bus == &pci_bus_type) {
118 pci_dma_sync_single_for_cpu(to_pci_dev(dev), dma_handle,
119 size, (int)direction);
123 sbus_dma_sync_single_for_cpu(dev, dma_handle, size, (int) direction);
126 static void dma32_sync_single_for_device(struct device *dev,
127 dma_addr_t dma_handle, size_t size,
128 enum dma_data_direction direction)
131 if (dev->bus == &pci_bus_type) {
132 pci_dma_sync_single_for_device(to_pci_dev(dev), dma_handle,
133 size, (int)direction);
137 sbus_dma_sync_single_for_device(dev, dma_handle, size, (int) direction);
140 static void dma32_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
141 int nelems, enum dma_data_direction direction)
144 if (dev->bus == &pci_bus_type) {
145 pci_dma_sync_sg_for_cpu(to_pci_dev(dev), sg,
146 nelems, (int)direction);
153 static void dma32_sync_sg_for_device(struct device *dev,
154 struct scatterlist *sg, int nelems,
155 enum dma_data_direction direction)
158 if (dev->bus == &pci_bus_type) {
159 pci_dma_sync_sg_for_device(to_pci_dev(dev), sg,
160 nelems, (int)direction);
167 static struct dma_map_ops dma32_dma_ops = {
168 .alloc_coherent = dma32_alloc_coherent,
169 .free_coherent = dma32_free_coherent,
170 .map_page = dma32_map_page,
171 .unmap_page = dma32_unmap_page,
172 .map_sg = dma32_map_sg,
173 .unmap_sg = dma32_unmap_sg,
174 .sync_single_for_cpu = dma32_sync_single_for_cpu,
175 .sync_single_for_device = dma32_sync_single_for_device,
176 .sync_sg_for_cpu = dma32_sync_sg_for_cpu,
177 .sync_sg_for_device = dma32_sync_sg_for_device,
180 struct dma_map_ops *dma_ops = &dma32_dma_ops;
181 EXPORT_SYMBOL(dma_ops);