dma: document dma_{un}map_{single|sg}_attrs() interface
PATCH v4 1/4 dma: document dma_{un}map_{single|sg}_attrs() interface
Document the new dma_{un}map_{single|sg}_attrs() functions.
Signed-off-by Arthur Kepner <[email protected]>
Acked-by Jesse Barnes <[email protected]>
---
DMA-API.txt | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ DMA-attributes.txt | 24 +++++++++++++++++++ 2 files changed, 89 insertions(+)
Documentation/DMA-API.txt +65 -0
@@ -395,6 +395,71 @@ Notes: You must do this: See also dma_map_single(). +dma_addr_t +dma_map_single_attrs(struct device *dev, void *cpu_addr, size_t size, + enum dma_data_direction dir, + struct dma_attrs *attrs) + +void +dma_unmap_single_attrs(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir, + struct dma_attrs *attrs) + +int +dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl, + int nents, enum dma_data_direction dir, + struct dma_attrs *attrs) + +void +dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sgl, + int nents, enum dma_data_direction dir, + struct dma_attrs *attrs) + +The four functions above are just like the counterpart functions +without the _attrs suffixes, except that they pass an optional +struct dma_attrs*. + +struct dma_attrs encapsulates a set of "dma attributes". For the +definition of struct dma_attrs see linux/dma-attrs.h. + +The interpretation of dma attributes is architecture-specific, and +each attribute should be documented in Documentation/DMA-attributes.txt. + +If struct dma_attrs* is NULL, the semantics of each of these +functions is identical to those of the corresponding function +without the _attrs suffix. As a result dma_map_single_attrs() +can generally replace dma_map_single(), etc. + +As an example of the use of the *_attrs functions, here's how +you could pass an attribute DMA_ATTR_FOO when mapping memory +for DMA: + +#include <linux/dma-attrs.h> +/* DMA_ATTR_FOO should be defined in linux/dma-attrs.h and + * documented in Documentation/DMA-attributes.txt */ +... + + DECLARE_DMA_ATTRS(attrs); + dma_set_attr(&attrs, DMA_ATTR_FOO); + .... + n = dma_map_sg_attrs(dev, sg, nents, DMA_TO_DEVICE, &attr); + .... + +Architectures that care about DMA_ATTR_FOO would check for its +presence in their implementations of the mapping and unmapping +routines, e.g.: + +void whizco_dma_map_sg_attrs(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir, + struct dma_attrs *attrs) +{ + .... + int foo = dma_get_attr(attrs, DMA_ATTR_FOO); + .... + if (foo) + /* twizzle the frobnozzle */ + .... + Part II - Advanced dma_ usage -----------------------------
Documentation/DMA-attributes.txt +24 -0
@@ -0,0 +1,24 @@ + DMA attributes + ============== + +This document describes the semantics of the DMA attributes that are +defined in linux/dma-attrs.h. + +DMA_ATTR_BARRIER +---------------- + +DMA_ATTR_BARRIER is a barrier attribute for DMA. DMA to a memory +region with the DMA_ATTR_BARRIER attribute forces all pending DMA +writes to complete, and thus provides a mechanism to strictly order +DMA from a device across all intervening busses and bridges. This +barrier is not specific to a particular type of interconnect, it +applies to the system as a whole, and so its implementation must +account for the idiosyncracies of the system all the way from the +DMA device to memory. + +As an example of a situation where DMA_ATTR_BARRIER would be useful, +suppose that a device does a DMA write to indicate that data is ready +and available in memory. The DMA of the "completion indication" could +race with data DMA. Mapping the memory used for completion indications +with DMA_ATTR_BARRIER would prevent the race. +
Quoted 5 lines · On Wed, Mar 12, 2008 at 09:01:17PM -0700, [email protected] wrote:
Document the new dma_{un}map_{single|sg}_attrs() functions.
Signed-off-by Arthur Kepner <[email protected]>Acked-by Jesse Barnes <[email protected]>
Acked-by Grant Grundler <[email protected]>
thanks,
grant
Quoted 111 lines
---
DMA-API.txt | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++ DMA-attributes.txt | 24 +++++++++++++++++++ 2 files changed, 89 insertions(+)Documentation/DMA-API.txt +65
-0@@ -395,6 +395,71 @@ Notes: You must do this: See also dma_map_single(). +dma_addr_t +dma_map_single_attrs(struct device *dev, void *cpu_addr, size_t size, + enum dma_data_direction dir, + struct dma_attrs *attrs) + +void +dma_unmap_single_attrs(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir, + struct dma_attrs *attrs) + +int +dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl, + int nents, enum dma_data_direction dir, + struct dma_attrs *attrs) + +void +dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sgl, + int nents, enum dma_data_direction dir, + struct dma_attrs *attrs) + +The four functions above are just like the counterpart functions +without the _attrs suffixes, except that they pass an optional +struct dma_attrs*. + +struct dma_attrs encapsulates a set of "dma attributes". For the +definition of struct dma_attrs see linux/dma-attrs.h. + +The interpretation of dma attributes is architecture-specific, and +each attribute should be documented in Documentation/DMA-attributes.txt. + +If struct dma_attrs* is NULL, the semantics of each of these +functions is identical to those of the corresponding function +without the _attrs suffix. As a result dma_map_single_attrs() +can generally replace dma_map_single(), etc. + +As an example of the use of the *_attrs functions, here's how +you could pass an attribute DMA_ATTR_FOO when mapping memory +for DMA: + +#include <linux/dma-attrs.h> +/* DMA_ATTR_FOO should be defined in linux/dma-attrs.h and + * documented in Documentation/DMA-attributes.txt */ +... + + DECLARE_DMA_ATTRS(attrs); + dma_set_attr(&attrs, DMA_ATTR_FOO); + .... + n = dma_map_sg_attrs(dev, sg, nents, DMA_TO_DEVICE, &attr); + .... + +Architectures that care about DMA_ATTR_FOO would check for its +presence in their implementations of the mapping and unmapping +routines, e.g.: + +void whizco_dma_map_sg_attrs(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir, + struct dma_attrs *attrs) +{ + .... + int foo = dma_get_attr(attrs, DMA_ATTR_FOO); + .... + if (foo) + /* twizzle the frobnozzle */ + .... + Part II - Advanced dma_ usage -----------------------------Documentation/DMA-attributes.txt +24
-0@@ -0,0 +1,24 @@ + DMA attributes + ============== + +This document describes the semantics of the DMA attributes that are +defined in linux/dma-attrs.h. + +DMA_ATTR_BARRIER +---------------- + +DMA_ATTR_BARRIER is a barrier attribute for DMA. DMA to a memory +region with the DMA_ATTR_BARRIER attribute forces all pending DMA +writes to complete, and thus provides a mechanism to strictly order +DMA from a device across all intervening busses and bridges. This +barrier is not specific to a particular type of interconnect, it +applies to the system as a whole, and so its implementation must +account for the idiosyncracies of the system all the way from the +DMA device to memory. + +As an example of a situation where DMA_ATTR_BARRIER would be useful, +suppose that a device does a DMA write to indicate that data is ready +and available in memory. The DMA of the "completion indication" could +race with data DMA. Mapping the memory used for completion indications +with DMA_ATTR_BARRIER would prevent the race. +