char: xillybus: Eliminate redundant wrappers to DMA related calls
Subsystems (2)
[email protected]
maintainerPATCH 1/1 char: xillybus: Eliminate redundant wrappers to DMA related calls
From: Eli Billauer <[email protected]>
The driver was originally written with the assumption that a different API must be used for DMA-related functions if the device is PCIe based or if not. Since Xillybus' driver supports devices on a PCIe bus (with xillybus_pcie) as well as connected directly to the processor (with xillybus_of), it originally used wrapper functions that ensure that a different API is used for each.
This patch eliminates the said wrapper functions, as all use the same dma_* API now. This is most notable by the code deleted in xillybus_pcie.c and xillybus_of.c.
There is still need for some wrapper functions however, which are merged from xillybus_pcie.c and xillybus_of.c into xillybus_core.c:
(1) The two xilly_sync_for_*() functions are necessary, because the calls to the respective dma_sync_single_for_*() must be avoided on Xilinx Zynq-7000 chips iff the Xillybus device is connected through the ACP port, hence performing the device's DMA operations coherently. Since it's also possible to connect the device to a non-coherent port, the choice is conveyed to the driver through the device tree.
(2) The call to dma_map_single() is wrapped by a function that uses the Managed Device (devres) framework, in the absence of a relevant function in the current kernel's API.
--- drivers/char/xillybus/xillybus.h | 24 +--- drivers/char/xillybus/xillybus_core.c | 156 +++++++++++++++++--------- drivers/char/xillybus/xillybus_of.c | 88 +-------------- drivers/char/xillybus/xillybus_pcie.c | 91 +-------------- 4 files changed, 117 insertions(+), 242 deletions(-)
drivers/char/xillybus/xillybus.h +3 -21
@@ -88,7 +88,8 @@ struct xilly_channel {struct xilly_endpoint {struct device *dev; -struct xilly_endpoint_hardware *ephw; +struct module *owner; +bool make_sync_calls;int dma_using_dac;/* =1 if 64-bit DMA is used, =0 otherwise. */ __iomem void *registers;
@@ -108,23 +109,6 @@ struct xilly_endpoint {unsigned int msg_buf_size; }; -struct xilly_endpoint_hardware { -struct module *owner; -void (*hw_sync_sgl_for_cpu)(struct xilly_endpoint *, -dma_addr_t , -size_t , -int ); -void (*hw_sync_sgl_for_device)(struct xilly_endpoint *, -dma_addr_t , -size_t , -int ); -int (*map_single)(struct xilly_endpoint *, -void *, -size_t , -int , -dma_addr_t *); -}; -struct xilly_mapping {struct device *device;dma_addr_t dma_addr;
@@ -134,9 +118,7 @@ struct xilly_mapping {irqreturn_t xillybus_isr (int irq,void *data); -struct xilly_endpoint *xillybus_init_endpoint (struct device *dev, -struct xilly_endpoint_hardware - *ephw); +struct xilly_endpoint *xillybus_init_endpoint (struct device *dev);int xillybus_endpoint_discovery (struct xilly_endpoint *endpoint);
drivers/char/xillybus/xillybus_core.c +105 -51
246 lines not on this page · raw message
drivers/char/xillybus/xillybus_of.c +5 -83
107 lines not on this page · raw message
drivers/char/xillybus/xillybus_pcie.c +4 -87
109 lines not on this page · raw message
Signature · 1 line
2.17.1
Arnd Bergmann
maintainerQuoted 25 lines · On Sun, Sep 26, 2021 at 9:31 AM <[email protected]> wrote:
From: Eli Billauer <[email protected]>
The driver was originally written with the assumption that a different API must be used for DMA-related functions if the device is PCIe based or if not. Since Xillybus' driver supports devices on a PCIe bus (with
xillybus_pcie) as well as connected directly to the processor (withxillybus_of), it originally used wrapper functions that ensure that a different API is used for each.This patch eliminates the said wrapper functions, as all use the same dma_* API now. This is most notable by the code deleted in
xillybus_pcie.candxillybus_of.c.There is still need for some wrapper functions however, which are merged from
xillybus_pcie.candxillybus_of.cintoxillybus_core.c:(1) The two xilly_sync_for_*() functions are necessary, because the calls to the respective dma_sync_single_for_*() must be avoided on Xilinx Zynq-7000 chips iff the Xillybus device is connected through the ACP port, hence performing the device's DMA operations coherently. Since it's also possible to connect the device to a non-coherent port, the choice is conveyed to the driver through the device tree.
Quoted 6 lines
(2) The call to
dma_map_single()is wrapped by a function that uses the Managed Device (devres) framework, in the absence of a relevant function in the current kernel's API.Suggested-by Christophe JAILLET <[email protected]>Signed-off-by Eli Billauer <[email protected]>
Very nice cleanup, just one comment:
Quoted 16 lines
drivers/char/xillybus/xillybus_core.c +16
-0+/* +* Xilinx' Zynq-7000 allows connecting the device through a coherent DMA +* port as well as non-coherent ports. The @make_sync_calls entry is therefore +* used to keep track of whether cache synchronization is required. Hence the +* two wrapper functions below. +*/ + +static void xilly_sync_for_cpu (struct xilly_endpoint *ep, +dma_addr_t dma_handle, +size_t size, +int direction) +{ +if (ep->make_sync_calls) +dma_sync_single_for_cpu (ep->dev, dma_handle, + size, direction); +}
drivers/char/xillybus/xillybus_core.c static void malformed_message(struct xilly_endpoint *endpoint, u32 *buf) · line 131
Quoted 10 lines
drivers/char/xillybus/xillybus_core.c +10
-0+ +static void xilly_sync_for_device (struct xilly_endpoint *ep, +dma_addr_t dma_handle, +size_t size, +int direction) +{ +if (ep->make_sync_calls) +dma_sync_single_for_device (ep->dev, dma_handle, + size, direction); +}
These wrappers should not even be needed. When the device is marked as coherent in DT, the dma_sync_*() calls are supposed to do nothing, in a relatively efficient way. I would not expect the extra conditional to give you any measurable performance benefit over what you get normally, and it should not make a functional difference either.
Can you remove the inlines and the ->make_sync_calls flag?
Arnd
Eli Billauer
maintainerQuoted 10 lines · Arnd Bergmann
Quoted 10 lines
+static void xilly_sync_for_device(struct
xilly_endpoint*ep,Quoted 8 lines
+ dma_addr_t dma_handle, + size_t size, + int direction)+{
+ if (ep->make_sync_calls)
+ dma_sync_single_for_device(ep->dev,dma_handle,
+ size, direction);
+}
Quoted 10 lines
These wrappers should not even be needed. When the device is marked as coherent in DT, the dma_sync_*() calls are supposed to do nothing, in a relatively efficient way. I would not expect the extra conditional to give you any measurable performance benefit over what you get normally, and it should not make a functional difference either.
Can you remove the inlines and the ->make_sync_calls flag?
Thanks, I had no idea that the sync functions neutralize themselves this way. That is, since commit 591c1ee465ce ("of: configure the platform device dma parameters") from back in April 2014.
So indeed, I shall remove the the @make_sync_calls entry and related wrapper functions, and resubmit an second version of this patch.
Thanks again,
Eli