dmaengine: Add per descriptor metadata support
Subsystems (2)
v3 cover dmaengine: Add per descriptor metadata support
Hi,
Changes since v2:
- EXPORT_SYMBOL_GPL() for the metadata functions
- Added note to Documentation to not mix the two defined metadata modes
- Fixed the typos in Documentation
Changes since v1:
- Move code from header to dmaengine.c
- Fix spelling
- Use BIT() macro for bit definition
- Update both provider and client documentation
Changes since rfc:
- DESC_METADATA_EMBEDDED renamed to DESC_METADATA_ENGINE
- Use flow is added for both CLIENT and ENGINE metadata modes
Some data movement architecure (DMA controller and peripherals) uses metadata associated with a transaction. The DMA controller role is to transfer the payload and the metadata alongside.
The metadata itself is not used by the DMA engine itself, but it contains parameters, keys, vectors, etc for peripheral or from the peripheral.
The DMAengine framework provides a generic ways to facilitate the metadata for descriptors. Depending on the architecture the DMA driver can implment either or both of the methods and it is up to the client driver to choose which one to use.
If the DMA supports per descriptor metadata it can implement the attach, get_ptr/set_len callbacks.
Client drivers must only use either attach or get_ptr/set_len to avoid miss configuration.
Client driver can check if a given metadata mode is supported by the channel during probe time with dmaengine_is_metadata_mode_supported(chan, DESC_METADATA_CLIENT); dmaengine_is_metadata_mode_supported(chan, DESC_METADATA_ENGINE);
and based on this information can use either mode.
Wrappers are also added for the metadata_ops.
To be used in DESC_METADATA_CLIENT mode:dmaengine_desc_attach_metadata()
To be used in DESC_METADATA_ENGINE mode:dmaengine_desc_get_metadata_ptr()dmaengine_desc_set_metadata_len()
Regards,
Peter
---
Peter Ujfalusi (2):
dmaengine: doc: Add sections for per descriptor metadata support
dmaengine: Add metadata_ops for dma_async_tx_descriptor
Documentation/driver-api/dmaengine/client.rst | 75 ++++++++++++ .../driver-api/dmaengine/provider.rst | 46 ++++++++ drivers/dma/dmaengine.c | 73 ++++++++++++ include/linux/dmaengine.h | 108 ++++++++++++++++++ 4 files changed, 302 insertions(+)
Signature · 4 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
PATCH v3 1/2 dmaengine: doc: Add sections for per descriptor metadata support
Update the provider and client documentation with details about the metadata support.
--- Documentation/driver-api/dmaengine/client.rst | 75 +++++++++++++++++++ .../driver-api/dmaengine/provider.rst | 46 ++++++++++++ 2 files changed, 121 insertions(+)
Documentation/driver-api/dmaengine/client.rst +75 -0
@@ -151,6 +151,81 @@ The details of these operations are: Note that callbacks will always be invoked from the DMA engines tasklet, never from interrupt context. + Optional: per descriptor metadata + --------------------------------- + DMAengine provides two ways for metadata support. + + DESC_METADATA_CLIENT + + The metadata buffer is allocated/provided by the client driver and it is + attached to the descriptor. + + .. code-block:: c + + int dmaengine_desc_attach_metadata(struct dma_async_tx_descriptor *desc, + void *data, size_t len); + + DESC_METADATA_ENGINE + + The metadata buffer is allocated/managed by the DMA driver. The client + driver can ask for the pointer, maximum size and the currently used size of + the metadata and can directly update or read it. + + .. code-block:: c + + void *dmaengine_desc_get_metadata_ptr(struct dma_async_tx_descriptor *desc, + size_t *payload_len, size_t *max_len); + + int dmaengine_desc_set_metadata_len(struct dma_async_tx_descriptor *desc, + size_t payload_len); + + Client drivers can query if a given mode is supported with: + + .. code-block:: c + + bool dmaengine_is_metadata_mode_supported(struct dma_chan *chan, + enum dma_desc_metadata_mode mode); + + Depending on the used mode client drivers must follow different flow. + + DESC_METADATA_CLIENT + + - DMA_MEM_TO_DEV / DEV_MEM_TO_MEM: + 1. prepare the descriptor (dmaengine_prep_*) + construct the metadata in the client's buffer + 2. use dmaengine_desc_attach_metadata() to attach the buffer to the + descriptor + 3. submit the transfer + - DMA_DEV_TO_MEM: + 1. prepare the descriptor (dmaengine_prep_*) + 2. use dmaengine_desc_attach_metadata() to attach the buffer to the + descriptor + 3. submit the transfer + 4. when the transfer is completed, the metadata should be available in the + attached buffer + + DESC_METADATA_ENGINE + + - DMA_MEM_TO_DEV / DEV_MEM_TO_MEM: + 1. prepare the descriptor (dmaengine_prep_*) + 2. use dmaengine_desc_get_metadata_ptr() to get the pointer to the + engine's metadata area + 3. update the metadata at the pointer + 4. use dmaengine_desc_set_metadata_len() to tell the DMA engine the + amount of data the client has placed into the metadata buffer + 5. submit the transfer + - DMA_DEV_TO_MEM: + 1. prepare the descriptor (dmaengine_prep_*) + 2. submit the transfer + 3. on transfer completion, use dmaengine_desc_get_metadata_ptr() to get the + pointer to the engine's metadata are + 4. Read out the metadate from the pointer + + .. note:: + + Mixed use of DESC_METADATA_CLIENT / DESC_METADATA_ENGINE is not allowed, + client drivers must use either of the modes per descriptor. + 4. Submit the transaction Once the descriptor has been prepared and the callback information
Documentation/driver-api/dmaengine/provider.rst +46 -0
52 lines not on this page · raw message
Signature · 4 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
PATCH v3 2/2 dmaengine: Add metadata_ops for dma_async_tx_descriptor
In reply to Peter UjfalusiThe metadata is best described as side band data or parameters traveling alongside the data DMAd by the DMA engine. It is data
which is understood by the peripheral and the peripheral driver only, the DMA engine see it only as data block and it is not interpreting it in any way.
The metadata can be different per descriptor as it is a parameter for the data being transferred.
If the DMA supports per descriptor metadata it can implement the attach, get_ptr/set_len callbacks.
Client drivers must only use either attach or get_ptr/set_len to avoid misconfiguration.
Client driver can check if a given metadata mode is supported by the channel during probe time with dmaengine_is_metadata_mode_supported(chan, DESC_METADATA_CLIENT); dmaengine_is_metadata_mode_supported(chan, DESC_METADATA_ENGINE);
and based on this information can use either mode.
Wrappers are also added for the metadata_ops.
To be used in DESC_METADATA_CLIENT mode:dmaengine_desc_attach_metadata()
To be used in DESC_METADATA_ENGINE mode:dmaengine_desc_get_metadata_ptr()dmaengine_desc_set_metadata_len()
--- drivers/dma/dmaengine.c | 73 ++++++++++++++++++++++++++ include/linux/dmaengine.h | 108 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+)
drivers/dma/dmaengine.c +73 -0
@@ -1306,6 +1306,79 @@ void dma_async_tx_descriptor_init(struct dma_async_tx_descriptor *tx, }EXPORT_SYMBOL (dma_async_tx_descriptor_init); +static inline int desc_check_and_set_metadata_mode ( +struct dma_async_tx_descriptor *desc,enum dma_desc_metadata_mode mode) +{ +/* Make sure that the metadata mode is not mixed */ +if (!desc->desc_metadata_mode) { +if (dmaengine_is_metadata_mode_supported (desc->chan, mode)) + desc->desc_metadata_mode = mode; +else +return -ENOTSUPP ; + }else if (desc->desc_metadata_mode != mode) { +return -EINVAL ; + } + +return 0 ; +} + +int dmaengine_desc_attach_metadata (struct dma_async_tx_descriptor *desc, +void *data,size_t len) +{ +int ret; + +if (!desc) +return -EINVAL ; + + ret =desc_check_and_set_metadata_mode (desc,DESC_METADATA_CLIENT ); +if (ret) +return ret; + +if (!desc->metadata_ops || !desc->metadata_ops->attach) +return -ENOTSUPP ; + +return desc->metadata_ops->attach (desc, data, len); +} +EXPORT_SYMBOL_GPL (dmaengine_desc_attach_metadata); + +void *dmaengine_desc_get_metadata_ptr (struct dma_async_tx_descriptor *desc, +size_t *payload_len,size_t *max_len) +{ +int ret; + +if (!desc) +return ERR_PTR (-EINVAL ); + + ret =desc_check_and_set_metadata_mode (desc,DESC_METADATA_ENGINE ); +if (ret) +return ERR_PTR (ret); + +if (!desc->metadata_ops || !desc->metadata_ops->get_ptr) +return ERR_PTR (-ENOTSUPP ); + +return desc->metadata_ops->get_ptr (desc, payload_len, max_len); +} +EXPORT_SYMBOL_GPL (dmaengine_desc_get_metadata_ptr); + +int dmaengine_desc_set_metadata_len (struct dma_async_tx_descriptor *desc, +size_t payload_len) +{ +int ret; + +if (!desc) +return -EINVAL ; + + ret =desc_check_and_set_metadata_mode (desc,DESC_METADATA_ENGINE ); +if (ret) +return ret; + +if (!desc->metadata_ops || !desc->metadata_ops->set_len) +return -ENOTSUPP ; + +return desc->metadata_ops->set_len (desc, payload_len); +} +EXPORT_SYMBOL_GPL (dmaengine_desc_set_metadata_len); +/* dma_wait_for_async_tx - spin wait for a transaction to complete * @tx: in-flight transaction to wait on */
include/linux/dmaengine.h +108 -0
150 lines not on this page · raw message
Signature · 4 lines
Peter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki