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 static struct dma_mapping_ops
*get_dma_ops(struct device
*dev
)
19 if (dev
->bus
== &pci_bus_type
)
23 if (dev
->bus
== &vio_bus_type
)
29 int dma_supported(struct device
*dev
, u64 mask
)
31 struct dma_mapping_ops
*dma_ops
= get_dma_ops(dev
);
34 return dma_ops
->dma_supported(dev
, mask
);
38 EXPORT_SYMBOL(dma_supported
);
40 int dma_set_mask(struct device
*dev
, u64 dma_mask
)
43 if (dev
->bus
== &pci_bus_type
)
44 return pci_set_dma_mask(to_pci_dev(dev
), dma_mask
);
47 if (dev
->bus
== &vio_bus_type
)
49 #endif /* CONFIG_IBMVIO */
53 EXPORT_SYMBOL(dma_set_mask
);
55 void *dma_alloc_coherent(struct device
*dev
, size_t size
,
56 dma_addr_t
*dma_handle
, unsigned int __nocast flag
)
58 struct dma_mapping_ops
*dma_ops
= get_dma_ops(dev
);
61 return dma_ops
->alloc_coherent(dev
, size
, dma_handle
, flag
);
65 EXPORT_SYMBOL(dma_alloc_coherent
);
67 void dma_free_coherent(struct device
*dev
, size_t size
, void *cpu_addr
,
68 dma_addr_t dma_handle
)
70 struct dma_mapping_ops
*dma_ops
= get_dma_ops(dev
);
73 dma_ops
->free_coherent(dev
, size
, cpu_addr
, dma_handle
);
77 EXPORT_SYMBOL(dma_free_coherent
);
79 dma_addr_t
dma_map_single(struct device
*dev
, void *cpu_addr
, size_t size
,
80 enum dma_data_direction direction
)
82 struct dma_mapping_ops
*dma_ops
= get_dma_ops(dev
);
85 return dma_ops
->map_single(dev
, cpu_addr
, size
, direction
);
89 EXPORT_SYMBOL(dma_map_single
);
91 void dma_unmap_single(struct device
*dev
, dma_addr_t dma_addr
, size_t size
,
92 enum dma_data_direction direction
)
94 struct dma_mapping_ops
*dma_ops
= get_dma_ops(dev
);
97 dma_ops
->unmap_single(dev
, dma_addr
, size
, direction
);
101 EXPORT_SYMBOL(dma_unmap_single
);
103 dma_addr_t
dma_map_page(struct device
*dev
, struct page
*page
,
104 unsigned long offset
, size_t size
,
105 enum dma_data_direction direction
)
107 struct dma_mapping_ops
*dma_ops
= get_dma_ops(dev
);
110 return dma_ops
->map_single(dev
,
111 (page_address(page
) + offset
), size
, direction
);
113 return (dma_addr_t
)0;
115 EXPORT_SYMBOL(dma_map_page
);
117 void dma_unmap_page(struct device
*dev
, dma_addr_t dma_address
, size_t size
,
118 enum dma_data_direction direction
)
120 struct dma_mapping_ops
*dma_ops
= get_dma_ops(dev
);
123 dma_ops
->unmap_single(dev
, dma_address
, size
, direction
);
127 EXPORT_SYMBOL(dma_unmap_page
);
129 int dma_map_sg(struct device
*dev
, struct scatterlist
*sg
, int nents
,
130 enum dma_data_direction direction
)
132 struct dma_mapping_ops
*dma_ops
= get_dma_ops(dev
);
135 return dma_ops
->map_sg(dev
, sg
, nents
, direction
);
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 struct dma_mapping_ops
*dma_ops
= get_dma_ops(dev
);
147 dma_ops
->unmap_sg(dev
, sg
, nhwentries
, direction
);
151 EXPORT_SYMBOL(dma_unmap_sg
);