diff options
author | Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> | 2016-08-10 07:22:16 -0400 |
---|---|---|
committer | Vinod Koul <vinod.koul@intel.com> | 2016-09-26 12:46:41 -0400 |
commit | 6f3d87968f9c8b529bc81eff5a1f45e92553493d (patch) | |
tree | 977a550789b14f198154488a9c105cc2049c6b50 | |
parent | 0e74b34dfc3318bf4c7e51349d453d49fb8e9e16 (diff) |
dma-mapping: add dma_{map,unmap}_resource
Map/Unmap a device MMIO resource from a physical address. If no dma_map_ops
method is available the operation is a no-op.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
-rw-r--r-- | Documentation/DMA-API.txt | 22 | ||||
-rw-r--r-- | include/linux/dma-mapping.h | 36 |
2 files changed, 53 insertions, 5 deletions
diff --git a/Documentation/DMA-API.txt b/Documentation/DMA-API.txt index 1d26eeb6b5f6..6b20128fab8a 100644 --- a/Documentation/DMA-API.txt +++ b/Documentation/DMA-API.txt | |||
@@ -277,14 +277,26 @@ and <size> parameters are provided to do partial page mapping, it is | |||
277 | recommended that you never use these unless you really know what the | 277 | recommended that you never use these unless you really know what the |
278 | cache width is. | 278 | cache width is. |
279 | 279 | ||
280 | dma_addr_t | ||
281 | dma_map_resource(struct device *dev, phys_addr_t phys_addr, size_t size, | ||
282 | enum dma_data_direction dir, unsigned long attrs) | ||
283 | |||
284 | void | ||
285 | dma_unmap_resource(struct device *dev, dma_addr_t addr, size_t size, | ||
286 | enum dma_data_direction dir, unsigned long attrs) | ||
287 | |||
288 | API for mapping and unmapping for MMIO resources. All the notes and | ||
289 | warnings for the other mapping APIs apply here. The API should only be | ||
290 | used to map device MMIO resources, mapping of RAM is not permitted. | ||
291 | |||
280 | int | 292 | int |
281 | dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | 293 | dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
282 | 294 | ||
283 | In some circumstances dma_map_single() and dma_map_page() will fail to create | 295 | In some circumstances dma_map_single(), dma_map_page() and dma_map_resource() |
284 | a mapping. A driver can check for these errors by testing the returned | 296 | will fail to create a mapping. A driver can check for these errors by testing |
285 | DMA address with dma_mapping_error(). A non-zero return value means the mapping | 297 | the returned DMA address with dma_mapping_error(). A non-zero return value |
286 | could not be created and the driver should take appropriate action (e.g. | 298 | means the mapping could not be created and the driver should take appropriate |
287 | reduce current DMA mapping usage or delay and try again later). | 299 | action (e.g. reduce current DMA mapping usage or delay and try again later). |
288 | 300 | ||
289 | int | 301 | int |
290 | dma_map_sg(struct device *dev, struct scatterlist *sg, | 302 | dma_map_sg(struct device *dev, struct scatterlist *sg, |
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 673b7be85f7a..6e00c7fdbbd3 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h | |||
@@ -264,6 +264,42 @@ static inline void dma_unmap_page(struct device *dev, dma_addr_t addr, | |||
264 | debug_dma_unmap_page(dev, addr, size, dir, false); | 264 | debug_dma_unmap_page(dev, addr, size, dir, false); |
265 | } | 265 | } |
266 | 266 | ||
267 | static inline dma_addr_t dma_map_resource(struct device *dev, | ||
268 | phys_addr_t phys_addr, | ||
269 | size_t size, | ||
270 | enum dma_data_direction dir, | ||
271 | unsigned long attrs) | ||
272 | { | ||
273 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
274 | unsigned long pfn = __phys_to_pfn(phys_addr); | ||
275 | dma_addr_t addr; | ||
276 | |||
277 | BUG_ON(!valid_dma_direction(dir)); | ||
278 | |||
279 | /* Don't allow RAM to be mapped */ | ||
280 | BUG_ON(pfn_valid(pfn)); | ||
281 | |||
282 | addr = phys_addr; | ||
283 | if (ops->map_resource) | ||
284 | addr = ops->map_resource(dev, phys_addr, size, dir, attrs); | ||
285 | |||
286 | debug_dma_map_resource(dev, phys_addr, size, dir, addr); | ||
287 | |||
288 | return addr; | ||
289 | } | ||
290 | |||
291 | static inline void dma_unmap_resource(struct device *dev, dma_addr_t addr, | ||
292 | size_t size, enum dma_data_direction dir, | ||
293 | unsigned long attrs) | ||
294 | { | ||
295 | struct dma_map_ops *ops = get_dma_ops(dev); | ||
296 | |||
297 | BUG_ON(!valid_dma_direction(dir)); | ||
298 | if (ops->unmap_resource) | ||
299 | ops->unmap_resource(dev, addr, size, dir, attrs); | ||
300 | debug_dma_unmap_resource(dev, addr, size, dir); | ||
301 | } | ||
302 | |||
267 | static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, | 303 | static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, |
268 | size_t size, | 304 | size_t size, |
269 | enum dma_data_direction dir) | 305 | enum dma_data_direction dir) |