blob: 473a3fc7ab5b40823a40108112e5dc470e5436e7 [file] [log] [blame]
David S. Miller944c67df2008-08-27 18:01:36 -07001/* dma.c: PCI and SBUS DMA accessors for 32-bit sparc.
2 *
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
4 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/dma-mapping.h>
9#include <linux/scatterlist.h>
10#include <linux/mm.h>
11
12#ifdef CONFIG_PCI
13#include <linux/pci.h>
14#endif
15
16#include "dma.h"
17
18int dma_supported(struct device *dev, u64 mask)
19{
20#ifdef CONFIG_PCI
21 if (dev->bus == &pci_bus_type)
22 return pci_dma_supported(to_pci_dev(dev), mask);
23#endif
24 return 0;
25}
26EXPORT_SYMBOL(dma_supported);
27
28int dma_set_mask(struct device *dev, u64 dma_mask)
29{
30#ifdef CONFIG_PCI
31 if (dev->bus == &pci_bus_type)
32 return pci_set_dma_mask(to_pci_dev(dev), dma_mask);
33#endif
34 return -EOPNOTSUPP;
35}
36EXPORT_SYMBOL(dma_set_mask);
37
FUJITA Tomonorid6986412009-05-14 16:23:11 +000038static void *dma32_alloc_coherent(struct device *dev, size_t size,
39 dma_addr_t *dma_handle, gfp_t flag)
David S. Miller944c67df2008-08-27 18:01:36 -070040{
41#ifdef CONFIG_PCI
42 if (dev->bus == &pci_bus_type)
43 return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
44#endif
45 return sbus_alloc_consistent(dev, size, dma_handle);
46}
David S. Miller944c67df2008-08-27 18:01:36 -070047
FUJITA Tomonorid6986412009-05-14 16:23:11 +000048static void dma32_free_coherent(struct device *dev, size_t size,
49 void *cpu_addr, dma_addr_t dma_handle)
David S. Miller944c67df2008-08-27 18:01:36 -070050{
51#ifdef CONFIG_PCI
52 if (dev->bus == &pci_bus_type) {
53 pci_free_consistent(to_pci_dev(dev), size,
54 cpu_addr, dma_handle);
55 return;
56 }
57#endif
58 sbus_free_consistent(dev, size, cpu_addr, dma_handle);
59}
David S. Miller944c67df2008-08-27 18:01:36 -070060
FUJITA Tomonorid6986412009-05-14 16:23:11 +000061static dma_addr_t dma32_map_page(struct device *dev, struct page *page,
62 unsigned long offset, size_t size,
FUJITA Tomonoribc0a14f2009-08-10 11:53:12 +090063 enum dma_data_direction direction,
64 struct dma_attrs *attrs)
David S. Miller944c67df2008-08-27 18:01:36 -070065{
66#ifdef CONFIG_PCI
67 if (dev->bus == &pci_bus_type)
68 return pci_map_page(to_pci_dev(dev), page, offset,
69 size, (int)direction);
70#endif
71 return sbus_map_single(dev, page_address(page) + offset,
72 size, (int)direction);
73}
David S. Miller944c67df2008-08-27 18:01:36 -070074
FUJITA Tomonorid6986412009-05-14 16:23:11 +000075static void dma32_unmap_page(struct device *dev, dma_addr_t dma_address,
FUJITA Tomonoribc0a14f2009-08-10 11:53:12 +090076 size_t size, enum dma_data_direction direction,
77 struct dma_attrs *attrs)
David S. Miller944c67df2008-08-27 18:01:36 -070078{
79#ifdef CONFIG_PCI
80 if (dev->bus == &pci_bus_type) {
81 pci_unmap_page(to_pci_dev(dev), dma_address,
82 size, (int)direction);
83 return;
84 }
85#endif
86 sbus_unmap_single(dev, dma_address, size, (int)direction);
87}
David S. Miller944c67df2008-08-27 18:01:36 -070088
FUJITA Tomonorid6986412009-05-14 16:23:11 +000089static int dma32_map_sg(struct device *dev, struct scatterlist *sg,
FUJITA Tomonoribc0a14f2009-08-10 11:53:12 +090090 int nents, enum dma_data_direction direction,
91 struct dma_attrs *attrs)
David S. Miller944c67df2008-08-27 18:01:36 -070092{
93#ifdef CONFIG_PCI
94 if (dev->bus == &pci_bus_type)
95 return pci_map_sg(to_pci_dev(dev), sg, nents, (int)direction);
96#endif
97 return sbus_map_sg(dev, sg, nents, direction);
98}
David S. Miller944c67df2008-08-27 18:01:36 -070099
FUJITA Tomonorid6986412009-05-14 16:23:11 +0000100void dma32_unmap_sg(struct device *dev, struct scatterlist *sg,
FUJITA Tomonoribc0a14f2009-08-10 11:53:12 +0900101 int nents, enum dma_data_direction direction,
102 struct dma_attrs *attrs)
David S. Miller944c67df2008-08-27 18:01:36 -0700103{
104#ifdef CONFIG_PCI
105 if (dev->bus == &pci_bus_type) {
106 pci_unmap_sg(to_pci_dev(dev), sg, nents, (int)direction);
107 return;
108 }
109#endif
110 sbus_unmap_sg(dev, sg, nents, (int)direction);
111}
David S. Miller944c67df2008-08-27 18:01:36 -0700112
FUJITA Tomonorid6986412009-05-14 16:23:11 +0000113static void dma32_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
114 size_t size,
115 enum dma_data_direction direction)
David S. Miller944c67df2008-08-27 18:01:36 -0700116{
117#ifdef CONFIG_PCI
118 if (dev->bus == &pci_bus_type) {
119 pci_dma_sync_single_for_cpu(to_pci_dev(dev), dma_handle,
120 size, (int)direction);
121 return;
122 }
123#endif
124 sbus_dma_sync_single_for_cpu(dev, dma_handle, size, (int) direction);
125}
David S. Miller944c67df2008-08-27 18:01:36 -0700126
FUJITA Tomonorid6986412009-05-14 16:23:11 +0000127static void dma32_sync_single_for_device(struct device *dev,
128 dma_addr_t dma_handle, size_t size,
129 enum dma_data_direction direction)
David S. Miller944c67df2008-08-27 18:01:36 -0700130{
131#ifdef CONFIG_PCI
132 if (dev->bus == &pci_bus_type) {
133 pci_dma_sync_single_for_device(to_pci_dev(dev), dma_handle,
134 size, (int)direction);
135 return;
136 }
137#endif
138 sbus_dma_sync_single_for_device(dev, dma_handle, size, (int) direction);
139}
David S. Miller944c67df2008-08-27 18:01:36 -0700140
FUJITA Tomonorid6986412009-05-14 16:23:11 +0000141static void dma32_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
142 int nelems, enum dma_data_direction direction)
David S. Miller944c67df2008-08-27 18:01:36 -0700143{
144#ifdef CONFIG_PCI
145 if (dev->bus == &pci_bus_type) {
146 pci_dma_sync_sg_for_cpu(to_pci_dev(dev), sg,
147 nelems, (int)direction);
148 return;
149 }
150#endif
151 BUG();
152}
David S. Miller944c67df2008-08-27 18:01:36 -0700153
FUJITA Tomonorid6986412009-05-14 16:23:11 +0000154static void dma32_sync_sg_for_device(struct device *dev,
155 struct scatterlist *sg, int nelems,
156 enum dma_data_direction direction)
David S. Miller944c67df2008-08-27 18:01:36 -0700157{
158#ifdef CONFIG_PCI
159 if (dev->bus == &pci_bus_type) {
160 pci_dma_sync_sg_for_device(to_pci_dev(dev), sg,
161 nelems, (int)direction);
162 return;
163 }
164#endif
165 BUG();
166}
FUJITA Tomonorid6986412009-05-14 16:23:11 +0000167
FUJITA Tomonoribc0a14f2009-08-10 11:53:12 +0900168static const struct dma_map_ops dma32_dma_ops = {
FUJITA Tomonorid6986412009-05-14 16:23:11 +0000169 .alloc_coherent = dma32_alloc_coherent,
170 .free_coherent = dma32_free_coherent,
171 .map_page = dma32_map_page,
172 .unmap_page = dma32_unmap_page,
173 .map_sg = dma32_map_sg,
174 .unmap_sg = dma32_unmap_sg,
175 .sync_single_for_cpu = dma32_sync_single_for_cpu,
176 .sync_single_for_device = dma32_sync_single_for_device,
177 .sync_sg_for_cpu = dma32_sync_sg_for_cpu,
178 .sync_sg_for_device = dma32_sync_sg_for_device,
179};
180
FUJITA Tomonoribc0a14f2009-08-10 11:53:12 +0900181const struct dma_map_ops *dma_ops = &dma32_dma_ops;
FUJITA Tomonorid6986412009-05-14 16:23:11 +0000182EXPORT_SYMBOL(dma_ops);