Re: [PATCH v5 3/9] dma-mapping: add dma_{map,unmap}_resource
Please add some documentation on where/how this should be used. It's not a very obvious interface. ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v5 9/9] ARM: dts: r8a7791: add iommus to dmac0 and dmac1
A unconfirmed hardware bug prevents channel 0 and 15 to be used by the DMAC together with the IPMMU. The DMAC driver will disable the channels reducing the effective number of channels to 14 per DMAC. Signed-off-by: Niklas SöderlundAcked-by: Laurent Pinchart --- arch/arm/boot/dts/r8a7791.dtsi | 30 ++ 1 file changed, 30 insertions(+) diff --git a/arch/arm/boot/dts/r8a7791.dtsi b/arch/arm/boot/dts/r8a7791.dtsi index c6bee4a..341c460 100644 --- a/arch/arm/boot/dts/r8a7791.dtsi +++ b/arch/arm/boot/dts/r8a7791.dtsi @@ -283,6 +283,21 @@ power-domains = <_clocks>; #dma-cells = <1>; dma-channels = <15>; + iommus = <_ds 0>, +<_ds 1>, +<_ds 2>, +<_ds 3>, +<_ds 4>, +<_ds 5>, +<_ds 6>, +<_ds 7>, +<_ds 8>, +<_ds 9>, +<_ds 10>, +<_ds 11>, +<_ds 12>, +<_ds 13>, +<_ds 14>; }; dmac1: dma-controller@e672 { @@ -314,6 +329,21 @@ power-domains = <_clocks>; #dma-cells = <1>; dma-channels = <15>; + iommus = <_ds 15>, +<_ds 16>, +<_ds 17>, +<_ds 18>, +<_ds 19>, +<_ds 20>, +<_ds 21>, +<_ds 22>, +<_ds 23>, +<_ds 24>, +<_ds 25>, +<_ds 26>, +<_ds 27>, +<_ds 28>, +<_ds 29>; }; audma0: dma-controller@ec70 { -- 2.7.2 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v5 4/9] arm: dma-mapping: add {map, unmap}_resource for iommu ops
Add methods to map/unmap device resources addresses for dma_map_ops that are IOMMU aware. This is needed to map a device MMIO register from a physical address. Signed-off-by: Niklas SöderlundReviewed-by: Laurent Pinchart --- arch/arm/mm/dma-mapping.c | 63 +++ 1 file changed, 63 insertions(+) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 0eca381..ae2b175 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1814,6 +1814,63 @@ static void arm_iommu_unmap_page(struct device *dev, dma_addr_t handle, __free_iova(mapping, iova, len); } +/** + * arm_iommu_map_resource - map a device resource for DMA + * @dev: valid struct device pointer + * @phys_addr: physical address of resource + * @size: size of resource to map + * @dir: DMA transfer direction + */ +static dma_addr_t arm_iommu_map_resource(struct device *dev, + phys_addr_t phys_addr, size_t size, + enum dma_data_direction dir, struct dma_attrs *attrs) +{ + struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); + dma_addr_t dma_addr; + int ret, prot; + phys_addr_t addr = phys_addr & PAGE_MASK; + int offset = phys_addr & ~PAGE_MASK; + int len = PAGE_ALIGN(size + offset); + + dma_addr = __alloc_iova(mapping, size); + if (dma_addr == DMA_ERROR_CODE) + return dma_addr; + + prot = __dma_direction_to_prot(dir) | IOMMU_MMIO; + + ret = iommu_map(mapping->domain, dma_addr, addr, len, prot); + if (ret < 0) + goto fail; + + return dma_addr + offset; +fail: + __free_iova(mapping, dma_addr, size); + return DMA_ERROR_CODE; +} + +/** + * arm_iommu_unmap_resource - unmap a device DMA resource + * @dev: valid struct device pointer + * @dma_handle: DMA address to resource + * @size: size of resource to map + * @dir: DMA transfer direction + */ +static void arm_iommu_unmap_resource(struct device *dev, dma_addr_t dma_handle, + size_t size, enum dma_data_direction dir, + struct dma_attrs *attrs) +{ + struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); + dma_addr_t iova = dma_handle & PAGE_MASK; + int offset = dma_handle & ~PAGE_MASK; + int len = PAGE_ALIGN(size + offset); + + if (!iova) + return; + + iommu_unmap(mapping->domain, iova, len); + __free_iova(mapping, iova, len); +} + static void arm_iommu_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { @@ -1858,6 +1915,9 @@ struct dma_map_ops iommu_ops = { .sync_sg_for_cpu= arm_iommu_sync_sg_for_cpu, .sync_sg_for_device = arm_iommu_sync_sg_for_device, + .map_resource = arm_iommu_map_resource, + .unmap_resource = arm_iommu_unmap_resource, + .set_dma_mask = arm_dma_set_mask, }; @@ -1873,6 +1933,9 @@ struct dma_map_ops iommu_coherent_ops = { .map_sg = arm_coherent_iommu_map_sg, .unmap_sg = arm_coherent_iommu_unmap_sg, + .map_resource = arm_iommu_map_resource, + .unmap_resource = arm_iommu_unmap_resource, + .set_dma_mask = arm_dma_set_mask, }; -- 2.7.2 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v5 1/9] iommu: Add MMIO mapping type
From: Robin MurphyOn some platforms, MMIO regions might need slightly different treatment compared to mapping regular memory; add the notion of MMIO mappings to the IOMMU API's memory type flags, so that callers can let the IOMMU drivers know to do the right thing. Signed-off-by: Robin Murphy Signed-off-by: Niklas Söderlund --- drivers/iommu/io-pgtable-arm.c | 9 +++-- include/linux/iommu.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 381ca5a..9c19989 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -355,7 +355,10 @@ static arm_lpae_iopte arm_lpae_prot_to_pte(struct arm_lpae_io_pgtable *data, if (!(prot & IOMMU_WRITE) && (prot & IOMMU_READ)) pte |= ARM_LPAE_PTE_AP_RDONLY; - if (prot & IOMMU_CACHE) + if (prot & IOMMU_MMIO) + pte |= (ARM_LPAE_MAIR_ATTR_IDX_DEV + << ARM_LPAE_PTE_ATTRINDX_SHIFT); + else if (prot & IOMMU_CACHE) pte |= (ARM_LPAE_MAIR_ATTR_IDX_CACHE << ARM_LPAE_PTE_ATTRINDX_SHIFT); } else { @@ -364,7 +367,9 @@ static arm_lpae_iopte arm_lpae_prot_to_pte(struct arm_lpae_io_pgtable *data, pte |= ARM_LPAE_PTE_HAP_READ; if (prot & IOMMU_WRITE) pte |= ARM_LPAE_PTE_HAP_WRITE; - if (prot & IOMMU_CACHE) + if (prot & IOMMU_MMIO) + pte |= ARM_LPAE_PTE_MEMATTR_DEV; + else if (prot & IOMMU_CACHE) pte |= ARM_LPAE_PTE_MEMATTR_OIWB; else pte |= ARM_LPAE_PTE_MEMATTR_NC; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index a5c539f..34b6432 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -30,6 +30,7 @@ #define IOMMU_WRITE(1 << 1) #define IOMMU_CACHE(1 << 2) /* DMA cache coherency */ #define IOMMU_NOEXEC (1 << 3) +#define IOMMU_MMIO (1 << 4) /* e.g. things like MSI doorbells */ struct iommu_ops; struct iommu_group; -- 2.7.2 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v5 8/9] ARM: dts: r8a7790: add iommus to dmac0 and dmac1
A unconfirmed hardware bug prevents channel 0 and 15 to be used by the DMAC together with the IPMMU. The DMAC driver will disable the channels reducing the effective number of channels to 14 per DMAC. Signed-off-by: Niklas SöderlundAcked-by: Laurent Pinchart --- arch/arm/boot/dts/r8a7790.dtsi | 30 ++ 1 file changed, 30 insertions(+) diff --git a/arch/arm/boot/dts/r8a7790.dtsi b/arch/arm/boot/dts/r8a7790.dtsi index 26772f7..c600daa 100644 --- a/arch/arm/boot/dts/r8a7790.dtsi +++ b/arch/arm/boot/dts/r8a7790.dtsi @@ -294,6 +294,21 @@ power-domains = <_clocks>; #dma-cells = <1>; dma-channels = <15>; + iommus = <_ds 0>, +<_ds 1>, +<_ds 2>, +<_ds 3>, +<_ds 4>, +<_ds 5>, +<_ds 6>, +<_ds 7>, +<_ds 8>, +<_ds 9>, +<_ds 10>, +<_ds 11>, +<_ds 12>, +<_ds 13>, +<_ds 14>; }; dmac1: dma-controller@e672 { @@ -325,6 +340,21 @@ power-domains = <_clocks>; #dma-cells = <1>; dma-channels = <15>; + iommus = <_ds 15>, +<_ds 16>, +<_ds 17>, +<_ds 18>, +<_ds 19>, +<_ds 20>, +<_ds 21>, +<_ds 22>, +<_ds 23>, +<_ds 24>, +<_ds 25>, +<_ds 26>, +<_ds 27>, +<_ds 28>, +<_ds 29>; }; audma0: dma-controller@ec70 { -- 2.7.2 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v5 7/9] dmaengine: rcar-dmac: add iommu support for slave transfers
Enable slave transfers to a device behind a IPMMU by mapping the slave addresses using the dma-mapping API. Signed-off-by: Niklas Söderlund--- drivers/dma/sh/rcar-dmac.c | 82 +- 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index b3911fe..56816e3 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -128,6 +128,18 @@ struct rcar_dmac_chan_slave { }; /* + * struct rcar_dmac_chan_map - Map of slave device phys to dma address + * @addr: slave dma address + * @dir: direction of mapping + * @slave: slave configuration that is mapped + */ +struct rcar_dmac_chan_map { + dma_addr_t addr; + enum dma_data_direction dir; + struct rcar_dmac_chan_slave slave; +}; + +/* * struct rcar_dmac_chan - R-Car Gen2 DMA Controller Channel * @chan: base DMA channel object * @iomem: channel I/O memory base @@ -152,6 +164,7 @@ struct rcar_dmac_chan { struct rcar_dmac_chan_slave src; struct rcar_dmac_chan_slave dst; + struct rcar_dmac_chan_map map; int mid_rid; spinlock_t lock; @@ -1027,13 +1040,65 @@ rcar_dmac_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dma_dest, DMA_MEM_TO_MEM, flags, false); } +static int rcar_dmac_map_slave_addr(struct dma_chan *chan, + enum dma_transfer_direction dir) +{ + struct rcar_dmac_chan *rchan = to_rcar_dmac_chan(chan); + struct rcar_dmac_chan_map *map = >map; + phys_addr_t dev_addr; + size_t dev_size; + enum dma_data_direction dev_dir; + + if (dir == DMA_DEV_TO_MEM) { + dev_addr = rchan->src.slave_addr; + dev_size = rchan->src.xfer_size; + dev_dir = DMA_TO_DEVICE; + } else { + dev_addr = rchan->dst.slave_addr; + dev_size = rchan->dst.xfer_size; + dev_dir = DMA_FROM_DEVICE; + } + + /* Reuse current map if possible. */ + if (dev_addr == map->slave.slave_addr && + dev_size == map->slave.xfer_size && + dev_dir == map->dir) + return 0; + + /* Remove old mapping if present. */ + if (map->slave.xfer_size) + dma_unmap_resource(chan->device->dev, map->addr, + map->slave.xfer_size, map->dir, NULL); + map->slave.xfer_size = 0; + + /* Create new slave address map. */ + map->addr = dma_map_resource(chan->device->dev, dev_addr, dev_size, +dev_dir, NULL); + + if (dma_mapping_error(chan->device->dev, map->addr)) { + dev_err(chan->device->dev, + "chan%u: failed to map %zx@%pap", rchan->index, + dev_size, _addr); + return -EIO; + } + + dev_dbg(chan->device->dev, "chan%u: map %zx@%pap to %pad dir: %s\n", + rchan->index, dev_size, _addr, >addr, + dev_dir == DMA_TO_DEVICE ? "DMA_TO_DEVICE" : "DMA_FROM_DEVICE"); + + map->slave.slave_addr = dev_addr; + map->slave.xfer_size = dev_size; + map->dir = dev_dir; + + return 0; +} + static struct dma_async_tx_descriptor * rcar_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, enum dma_transfer_direction dir, unsigned long flags, void *context) { struct rcar_dmac_chan *rchan = to_rcar_dmac_chan(chan); - dma_addr_t dev_addr; /* Someone calling slave DMA on a generic channel? */ if (rchan->mid_rid < 0 || !sg_len) { @@ -1043,9 +1108,10 @@ rcar_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, return NULL; } - dev_addr = dir == DMA_DEV_TO_MEM -? rchan->src.slave_addr : rchan->dst.slave_addr; - return rcar_dmac_chan_prep_sg(rchan, sgl, sg_len, dev_addr, + if (rcar_dmac_map_slave_addr(chan, dir)) + return NULL; + + return rcar_dmac_chan_prep_sg(rchan, sgl, sg_len, rchan->map.addr, dir, flags, false); } @@ -1059,7 +1125,6 @@ rcar_dmac_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, struct rcar_dmac_chan *rchan = to_rcar_dmac_chan(chan); struct dma_async_tx_descriptor *desc; struct scatterlist *sgl; - dma_addr_t dev_addr; unsigned int sg_len; unsigned int i; @@ -1071,6 +1136,9 @@ rcar_dmac_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, return NULL; } + if (rcar_dmac_map_slave_addr(chan, dir)) + return NULL; + sg_len = buf_len / period_len; if (sg_len > RCAR_DMAC_MAX_SG_LEN) { dev_err(chan->device->dev, @@ -1098,9 +1166,7 @@
[PATCH v5 0/9] dmaengine: rcar-dmac: add iommu support for slave transfers
Hi, This series add iommu support to rcar-dmac. It's tested on Koelsch with CONFIG_IPMMU_VMSA and by enabling the ipmmu_ds node in r8a7791.dtsi. I verified operation by interacting with /dev/mmcblk1 and the serial console which both are devices behind the iommu. The series depends patch '[PATCH] dmaengine: use phys_addr_t for slave configuration'. * Changes since v4 - Move the mapping from phys_addr_t to dma_addr_t from slave_config to the prepare calls. This way we know the direction of the mapping and don't have to use DMA_BIDIRECTIONAL. Thanks Vinod for suggesting this. - To be clear that the data type for slave addresses are changed add a patch that only changes the data type to phys_addr_t. - Fixed up commit messages. * Changes since v3 - Folded in a fix from Robin to his patch. - Added a check to make sure dma_map_resource can not be used to map RAM as pointed out by Robin. I use BUG_ON to enforce this. It might not be the best method but I saw no other good way since DMA_ERROR_CODE might not be defined on all platforms. - Added comment about that DTS changes will disable 2 DMA channels due to a HW (?) but in the DMAC. - Dropped the use of dma_attrs, no longer needed. - Collected Acked-by and Reviewed-by from Laurent. - Various indentation fix ups. * Changes since v2 - Drop patch to add dma_{map,unmap}_page_attrs. - Add dma_{map,unmap}_resource to handle the mapping without involving a 'struct page'. Thanks Laurent and Robin for pointing this out. - Use size instead of address to keep track of if a mapping exist or not since addr == 0 is valid. Thanks Laurent. - Pick up patch from Robin with Laurents ack (hope it's OK for me to attach the ack?) to add IOMMU_MMIO. - Fix bug in rcar_dmac_device_config where the error check where inverted. - Use DMA_BIDIRECTIONAL in rcar_dmac_device_config since we at that point can't be sure what direction the mapping is going to be used. * Changes since v1 - Add and use a dma_{map,unmap}_page_attrs to be able to map the page using attributes DMA_ATTR_NO_KERNEL_MAPPING and DMA_ATTR_SKIP_CPU_SYNC. Thanks Laurent. - Drop check if dmac is part of a iommu group or not, let the DMA mapping api handle it. - Move slave configuration data around in rcar-dmac to avoid code duplication. - Fix build issue reported by 'kbuild test robot' regarding phys_to_page not availability on some configurations. - Add DT information for r8a7791. * Changes since RFC - Switch to use the dma-mapping api instead of using the iommu_map() directly. Turns out the dma-mapper is much smarter then me... - Dropped the patch to expose domain->ops->pgsize_bitmap from within the iommu api. - Dropped the patch showing how I tested the RFC. Niklas Söderlund (8): dma-mapping: add {map,unmap}_resource to dma_map_ops dma-mapping: add dma_{map,unmap}_resource arm: dma-mapping: add {map,unmap}_resource for iommu ops dmaengine: rcar-dmac: slave address are physical dmaengine: rcar-dmac: group slave configuration dmaengine: rcar-dmac: add iommu support for slave transfers ARM: dts: r8a7790: add iommus to dmac0 and dmac1 ARM: dts: r8a7791: add iommus to dmac0 and dmac1 Robin Murphy (1): iommu: Add MMIO mapping type arch/arm/boot/dts/r8a7790.dtsi | 30 +++ arch/arm/boot/dts/r8a7791.dtsi | 30 +++ arch/arm/mm/dma-mapping.c | 63 ++ drivers/dma/sh/rcar-dmac.c | 116 + drivers/iommu/io-pgtable-arm.c | 9 +++- include/linux/dma-mapping.h| 38 ++ include/linux/iommu.h | 1 + 7 files changed, 263 insertions(+), 24 deletions(-) -- 2.7.2 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v5 5/9] dmaengine: rcar-dmac: slave address are physical
Slave addresses coming from a client is physical not dma. Store the address using the correct data type. This is in preparation for hooking up the dma-mapping API to the slave addresses. Signed-off-by: Niklas Söderlund--- drivers/dma/sh/rcar-dmac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 7820d07..01cf82f 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -144,8 +144,8 @@ struct rcar_dmac_chan { unsigned int src_xfer_size; unsigned int dst_xfer_size; - dma_addr_t src_slave_addr; - dma_addr_t dst_slave_addr; + phys_addr_t src_slave_addr; + phys_addr_t dst_slave_addr; int mid_rid; spinlock_t lock; -- 2.7.2 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v5 3/9] dma-mapping: add dma_{map,unmap}_resource
Map/Unmap a device 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--- include/linux/dma-mapping.h | 32 1 file changed, 32 insertions(+) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index e3aba4e..cc305d1 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -216,6 +216,38 @@ static inline void dma_unmap_page(struct device *dev, dma_addr_t addr, debug_dma_unmap_page(dev, addr, size, dir, false); } +static inline dma_addr_t dma_map_resource(struct device *dev, + phys_addr_t phys_addr, + size_t size, + enum dma_data_direction dir, + struct dma_attrs *attrs) +{ + struct dma_map_ops *ops = get_dma_ops(dev); + unsigned long pfn = __phys_to_pfn(phys_addr); + + BUG_ON(!valid_dma_direction(dir)); + + /* Don't allow RAM to be mapped */ + BUG_ON(pfn_valid(pfn)); + + if (ops->map_resource) + return ops->map_resource(dev, phys_addr, size, dir, attrs); + + return phys_addr; +} + +static inline void dma_unmap_resource(struct device *dev, dma_addr_t addr, + size_t size, enum dma_data_direction dir, + struct dma_attrs *attrs) +{ + struct dma_map_ops *ops = get_dma_ops(dev); + + BUG_ON(!valid_dma_direction(dir)); + if (ops->unmap_resource) + ops->unmap_resource(dev, addr, size, dir, attrs); + +} + static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr, size_t size, enum dma_data_direction dir) -- 2.7.2 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH v5 6/9] dmaengine: rcar-dmac: group slave configuration
Group slave address and transfer size in own structs for source and destination. This is in preparation for hooking up the dma-mapping API to the slave addresses. Signed-off-by: Niklas Söderlund--- drivers/dma/sh/rcar-dmac.c | 38 ++ 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 01cf82f..b3911fe 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -118,14 +118,22 @@ struct rcar_dmac_desc_page { sizeof(struct rcar_dmac_xfer_chunk)) /* + * struct rcar_dmac_chan_slave - Slave configuration + * @slave_addr: slave memory address + * @xfer_size: size (in bytes) of hardware transfers + */ +struct rcar_dmac_chan_slave { + phys_addr_t slave_addr; + unsigned int xfer_size; +}; + +/* * struct rcar_dmac_chan - R-Car Gen2 DMA Controller Channel * @chan: base DMA channel object * @iomem: channel I/O memory base * @index: index of this channel in the controller - * @src_xfer_size: size (in bytes) of hardware transfers on the source side - * @dst_xfer_size: size (in bytes) of hardware transfers on the destination side - * @src_slave_addr: slave source memory address - * @dst_slave_addr: slave destination memory address + * @src: slave memory address and size on the source side + * @dst: slave memory address and size on the destination side * @mid_rid: hardware MID/RID for the DMA client using this channel * @lock: protects the channel CHCR register and the desc members * @desc.free: list of free descriptors @@ -142,10 +150,8 @@ struct rcar_dmac_chan { void __iomem *iomem; unsigned int index; - unsigned int src_xfer_size; - unsigned int dst_xfer_size; - phys_addr_t src_slave_addr; - phys_addr_t dst_slave_addr; + struct rcar_dmac_chan_slave src; + struct rcar_dmac_chan_slave dst; int mid_rid; spinlock_t lock; @@ -793,13 +799,13 @@ static void rcar_dmac_chan_configure_desc(struct rcar_dmac_chan *chan, case DMA_DEV_TO_MEM: chcr = RCAR_DMACHCR_DM_INC | RCAR_DMACHCR_SM_FIXED | RCAR_DMACHCR_RS_DMARS; - xfer_size = chan->src_xfer_size; + xfer_size = chan->src.xfer_size; break; case DMA_MEM_TO_DEV: chcr = RCAR_DMACHCR_DM_FIXED | RCAR_DMACHCR_SM_INC | RCAR_DMACHCR_RS_DMARS; - xfer_size = chan->dst_xfer_size; + xfer_size = chan->dst.xfer_size; break; case DMA_MEM_TO_MEM: @@ -1038,7 +1044,7 @@ rcar_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, } dev_addr = dir == DMA_DEV_TO_MEM -? rchan->src_slave_addr : rchan->dst_slave_addr; +? rchan->src.slave_addr : rchan->dst.slave_addr; return rcar_dmac_chan_prep_sg(rchan, sgl, sg_len, dev_addr, dir, flags, false); } @@ -1093,7 +1099,7 @@ rcar_dmac_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, } dev_addr = dir == DMA_DEV_TO_MEM -? rchan->src_slave_addr : rchan->dst_slave_addr; +? rchan->src.slave_addr : rchan->dst.slave_addr; desc = rcar_dmac_chan_prep_sg(rchan, sgl, sg_len, dev_addr, dir, flags, true); @@ -1110,10 +1116,10 @@ static int rcar_dmac_device_config(struct dma_chan *chan, * We could lock this, but you shouldn't be configuring the * channel, while using it... */ - rchan->src_slave_addr = cfg->src_addr; - rchan->dst_slave_addr = cfg->dst_addr; - rchan->src_xfer_size = cfg->src_addr_width; - rchan->dst_xfer_size = cfg->dst_addr_width; + rchan->src.slave_addr = cfg->src_addr; + rchan->dst.slave_addr = cfg->dst_addr; + rchan->src.xfer_size = cfg->src_addr_width; + rchan->dst.xfer_size = cfg->dst_addr_width; return 0; } -- 2.7.2 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
[PATCH 1/7] iommu/fsl: Fix most checkpatch warnings and typos
Signed-off-by: Codrin Ciubotariu--- drivers/iommu/fsl_pamu.c| 92 + drivers/iommu/fsl_pamu.h| 29 +++-- drivers/iommu/fsl_pamu_domain.c | 41 +++--- drivers/iommu/fsl_pamu_domain.h | 2 +- 4 files changed, 109 insertions(+), 55 deletions(-) diff --git a/drivers/iommu/fsl_pamu.c b/drivers/iommu/fsl_pamu.c index a34355f..c64cdef 100644 --- a/drivers/iommu/fsl_pamu.c +++ b/drivers/iommu/fsl_pamu.c @@ -128,6 +128,10 @@ int pamu_enable_liodn(int liodn) mb(); set_bf(ppaace->addr_bitfields, PAACE_AF_V, PAACE_V_VALID); + /* +* Ensure that I/O devices use the new PAACE entry +* right after this function returns +*/ mb(); return 0; @@ -150,6 +154,10 @@ int pamu_disable_liodn(int liodn) } set_bf(ppaace->addr_bitfields, PAACE_AF_V, PAACE_V_INVALID); + /* +* Ensure that I/O devices no longer use this PAACE entry +* right after this function returns +*/ mb(); return 0; @@ -226,16 +234,17 @@ static struct paace *pamu_get_spaace(struct paace *paace, u32 wnum) * function returns the index of the first SPAACE entry. The remaining * SPAACE entries are reserved contiguously from that index. * - * Returns a valid fspi index in the range of 0 - SPAACE_NUMBER_ENTRIES on success. - * If no SPAACE entry is available or the allocator can not reserve the required - * number of contiguous entries function returns ULONG_MAX indicating a failure. - * + * Returns a valid fspi index in the range of 0 - SPAACE_NUMBER_ENTRIES on + * success. If no SPAACE entry is available or the allocator can not reserve + * the required number of contiguous entries function returns ULONG_MAX + * indicating a failure. */ static unsigned long pamu_get_fspi_and_allocate(u32 subwin_cnt) { unsigned long spaace_addr; - spaace_addr = gen_pool_alloc(spaace_pool, subwin_cnt * sizeof(struct paace)); + spaace_addr = gen_pool_alloc(spaace_pool, subwin_cnt * + sizeof(struct paace)); if (!spaace_addr) return ULONG_MAX; @@ -257,16 +266,17 @@ void pamu_free_subwins(int liodn) if (get_bf(ppaace->addr_bitfields, PPAACE_AF_MW)) { subwin_cnt = 1UL << (get_bf(ppaace->impl_attr, PAACE_IA_WCE) + 1); size = (subwin_cnt - 1) * sizeof(struct paace); - gen_pool_free(spaace_pool, (unsigned long)[ppaace->fspi], size); + gen_pool_free(spaace_pool, + (unsigned long)[ppaace->fspi], size); set_bf(ppaace->addr_bitfields, PPAACE_AF_MW, 0); } } /* - * Function used for updating stash destination for the coressponding + * Function used for updating stash destination for the corresponding * LIODN. */ -int pamu_update_paace_stash(int liodn, u32 subwin, u32 value) +int pamu_update_paace_stash(int liodn, u32 subwin, u32 value) { struct paace *paace; @@ -282,6 +292,10 @@ int pamu_update_paace_stash(int liodn, u32 subwin, u32 value) } set_bf(paace->impl_attr, PAACE_IA_CID, value); + /* +* Ensure that I/O devices see the new stash id +* just after this function returns +*/ mb(); return 0; @@ -307,6 +321,10 @@ int pamu_disable_spaace(int liodn, u32 subwin) PAACE_AP_PERMS_DENIED); } + /* +* Ensure that I/O devices no longer use this PAACE entry +* right after this function returns +*/ mb(); return 0; @@ -399,6 +417,10 @@ int pamu_config_ppaace(int liodn, phys_addr_t win_addr, phys_addr_t win_size, set_bf(ppaace->impl_attr, PAACE_IA_WCE, 0); set_bf(ppaace->addr_bitfields, PPAACE_AF_MW, 0); } + /* +* Ensure that I/O devices see the updated PPAACE entry +* right after this function returns +*/ mb(); return 0; @@ -483,11 +505,16 @@ int pamu_config_spaace(int liodn, u32 subwin_cnt, u32 subwin, if (~stashid != 0) set_bf(paace->impl_attr, PAACE_IA_CID, stashid); + /* Ensure that this SPAACE entry updates before we enable it */ smp_wmb(); if (enable) set_bf(paace->addr_bitfields, PAACE_AF_V, PAACE_V_VALID); + /* +* Ensure that I/O devices use this PAACE entry +* right after this function returns +*/ mb(); return 0; @@ -553,7 +580,8 @@ u32 get_stash_id(u32 stash_dest_hint, u32 vcpu) found_cpu_node: /* find the hwnode that represents the cache */ - for (cache_level = PAMU_ATTR_CACHE_L1; (cache_level < PAMU_ATTR_CACHE_L3) && found; cache_level++) { + for (cache_level = PAMU_ATTR_CACHE_L1; +(cache_level < PAMU_ATTR_CACHE_L3) && found;
[PATCH 0/7] PAMU driver update
This patchset addresses a few issues found on PAMU IOMMU and small changes to enable power management and to support the L3 cache controller on some newer boards. The series starts with a clean-up patch, followed by two errata fixes: A-007907 and A-005982. It continues with two fixes for PCIe support. The last two patches add support for power management and compatible strings for new L3 controller device-tree nodes. Codrin Ciubotariu (2): iommu/fsl: Fix most checkpatch warnings and typos iommu/fsl: Work around erratum A-007907 Varun Sethi (5): iommu/fsl: Enable OMT cache, before invalidating PAACT and SPAACT cache iommu/fsl: Factor out PCI specific code iommu/fsl: Enable default DMA window for PCIe devices once detached from domain iommu/fsl: PAMU power management support iommu/fsl: Added cache controller compatible strings for SOCs drivers/iommu/fsl_pamu.c| 322 drivers/iommu/fsl_pamu.h| 30 ++-- drivers/iommu/fsl_pamu_domain.c | 160 +--- drivers/iommu/fsl_pamu_domain.h | 2 +- 4 files changed, 381 insertions(+), 133 deletions(-) -- 1.9.3 ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu