Add Unisoc iommu basic driver
Subsystems (3)
Chunyan Zhang
reviewerv2 cover Add Unisoc iommu basic driver
From: Chunyan Zhang <[email protected]>
Changes since v1:
* Fixed compile errors reported by kernel test robot <[email protected]>.
* Changed to use syscon to get mapped registers for iommu and media devices to avoid double map issue.
* Addressed Robin's comments:
- Added including offset in the returned physical address if the input virtual address isn't page-aligned;
- Added platform_device_put() after calling of_find_device_by_node();
- Removed iommu register offset from driver, it will be defined as the cell of DT reference to syscon phandle;
- Removed multi compatible strings which are not needed;
- Added comments for the function sprd_iommu_clk_enable();
- Added clocks property in bindings;
- Set device_driver.suppress_bind_attrs to disable unbind the devices via sysfs;
- A few trivial fixes.
Changes since RFC v2:
* Addressed Robin's comments:
- Add COMPILE_TEST support;
- Use DMA allocator for PTE;
- Revised to avoid resource leak issue;
- Added ->iotlb_sync implemented;
- Moved iommu group allocation to probe;
- Changed some function names to make them sprd specific;
* Added support for more iommu instance;
Changes since RFC v1:
* Rebased on v5.11-rc1;
* Changed sprd-iommu to tristate;
* Removed check for args_count of iommu OF node, since there's no args for sprd-iommu device node;
* Added another IP version (i.e. vau);
* Removed unnecessary configs selection from CONFIG_SPRD_IOMMU;
* Changed to get zeroed pages.
Chunyan Zhang (2):
dt-bindings: iommu: add bindings for sprd iommu
iommu: add Unisoc iommu basic driver
.../devicetree/bindings/iommu/sprd,iommu.yaml | 72 +++ drivers/iommu/Kconfig | 12 + drivers/iommu/Makefile | 1 + drivers/iommu/sprd-iommu.c | 581 ++++++++++++++++++ 4 files changed, 666 insertions(+) create mode 100644 Documentation/devicetree/bindings/iommu/sprd,iommu.yaml create mode 100644 drivers/iommu/sprd-iommu.c
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Chunyan Zhang
reviewerPATCH v2 1/2 dt-bindings: iommu: add bindings for sprd iommu
From: Chunyan Zhang <[email protected]>
This iommu module can be used by Unisoc's multimedia devices, such as display, Image codec(jpeg) and a few signal processors, including VSP(video), GSP(graphic), ISP(image), and CPP(camera pixel processor), etc.
--- .../devicetree/bindings/iommu/sprd,iommu.yaml | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Documentation/devicetree/bindings/iommu/sprd,iommu.yaml
Documentation/devicetree/bindings/iommu/sprd,iommu.yaml new file +72 -0
@@ -0,0 +1,72 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2020 Unisoc Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iommu/sprd,iommu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Unisoc IOMMU and Multi-media MMU + +maintainers: + - Chunyan Zhang <[email protected]> + +properties: + compatible: + enum: + - sprd,iommu-v1 + + "#iommu-cells": + const: 0 + description: + Unisoc IOMMUs are all single-master IOMMU devices, therefore no + additional information needs to associate with its master device. + Please refer to the generic bindings document for more details, + Documentation/devicetree/bindings/iommu/iommu.txt + + reg: + maxItems: 1 + description: + Not required if 'sprd,iommu-regs' is defined. + + clocks: + description: + Reference to a gate clock phandle, since access to some of IOMMUs are + controlled by gate clock, but this is not required. + + sprd,iommu-regs: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: + Reference to a syscon phandle plus 1 cell, the syscon defines the + register range used by the iommu and the media device, the cell + defines the offset for iommu registers. Since iommu module shares + the same register range with the media device which uses it. + +required: + - compatible + - "#iommu-cells" + +oneOf: + - required: + - reg + - required: + - sprd,iommu-regs + +additionalProperties: false + +examples: + - | + iommu_disp: iommu-disp { + compatible = "sprd,iommu-v1"; + sprd,iommu-regs = <&dpu_regs 0x800>; + #iommu-cells = <0>; + }; + + - | + iommu_jpg: iommu-jpg { + compatible = "sprd,iommu-v1"; + sprd,iommu-regs = <&jpg_regs 0x300>; + #iommu-cells = <0>; + clocks = <&mm_gate 1>; + }; + +...
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Chunyan Zhang
reviewerPATCH v2 2/2 iommu: add Unisoc iommu basic driver
In reply to Chunyan ZhangFrom: Chunyan Zhang <[email protected]>
This iommu module can be used by Unisoc's multimedia devices, such as display, Image codec(jpeg) and a few signal processors, including VSP(video), GSP(graphic), ISP(image), and CPP(camera pixel processor), etc.
--- drivers/iommu/Kconfig | 12 + drivers/iommu/Makefile | 1 + drivers/iommu/sprd-iommu.c | 581 +++++++++++++++++++++++++++++++++++++ 3 files changed, 594 insertions(+) create mode 100644 drivers/iommu/sprd-iommu.c
drivers/iommu/Kconfig +12 -0
@@ -408,4 +408,16 @@ config VIRTIO_IOMMU Say Y here if you intend to run this kernel as a guest. +config SPRD_IOMMU + tristate "Unisoc IOMMU Support" + depends on ARCH_SPRD || COMPILE_TEST + select IOMMU_API + help + Support for IOMMU on Unisoc's SoCs on which multi-media subsystems + need IOMMU, such as DPU, Image codec(jpeg) processor, and a few + signal processors, including VSP(video), GSP(graphic), ISP(image), and + CPP, etc. + + Say Y here if you want multi-media functions. + endif # IOMMU_SUPPORT
drivers/iommu/Makefile +1 -0
@@ -28,3 +28,4 @@ obj-$(CONFIG_S390_IOMMU) += s390-iommu.o obj-$(CONFIG_HYPERV_IOMMU) += hyperv-iommu.o obj-$(CONFIG_VIRTIO_IOMMU) += virtio-iommu.o obj-$(CONFIG_IOMMU_SVA_LIB) += iommu-sva-lib.o +obj-$(CONFIG_SPRD_IOMMU) += sprd-iommu.o
drivers/iommu/sprd-iommu.c new file +581 -0
581 lines not on this page · raw message
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Chunyan Zhang
reviewerPATCH v2 2/2 iommu: add Unisoc iommu basic driver
From: Chunyan Zhang <[email protected]>
This iommu module can be used by Unisoc's multimedia devices, such as display, Image codec(jpeg) and a few signal processors, including VSP(video), GSP(graphic), ISP(image), and CPP(camera pixel processor), etc.
--- drivers/iommu/Kconfig | 12 + drivers/iommu/Makefile | 1 + drivers/iommu/sprd-iommu.c | 598 +++++++++++++++++++++++++++++++++++++ 3 files changed, 611 insertions(+) create mode 100644 drivers/iommu/sprd-iommu.c
drivers/iommu/Kconfig +12 -0
@@ -408,4 +408,16 @@ config VIRTIO_IOMMU Say Y here if you intend to run this kernel as a guest. +config SPRD_IOMMU + tristate "Unisoc IOMMU Support" + depends on ARCH_SPRD || COMPILE_TEST + select IOMMU_API + help + Support for IOMMU on Unisoc's SoCs on which multi-media subsystems + need IOMMU, such as DPU, Image codec(jpeg) processor, and a few + signal processors, including VSP(video), GSP(graphic), ISP(image), and + CPP, etc. + + Say Y here if you want multi-media functions. + endif # IOMMU_SUPPORT
drivers/iommu/Makefile +1 -0
@@ -28,3 +28,4 @@ obj-$(CONFIG_S390_IOMMU) += s390-iommu.o obj-$(CONFIG_HYPERV_IOMMU) += hyperv-iommu.o obj-$(CONFIG_VIRTIO_IOMMU) += virtio-iommu.o obj-$(CONFIG_IOMMU_SVA_LIB) += iommu-sva-lib.o +obj-$(CONFIG_SPRD_IOMMU) += sprd-iommu.o
drivers/iommu/sprd-iommu.c new file +598 -0
598 lines not on this page · raw message
Signature · 6 lines
2.25.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerRe: [PATCH 2/2] iommu: add Unisoc iommu basic driver
Quoted 11 lines · Chunyan Zhang
From: Chunyan Zhang <[email protected]>
This iommu module can be used by Unisoc's multimedia devices, such as display, Image codec(jpeg) and a few signal processors, including VSP(video), GSP(graphic), ISP(image), and CPP(camera pixel processor), etc.
Signed-off-by Chunyan Zhang <[email protected]>--- drivers/iommu/Kconfig | 12 + drivers/iommu/Makefile | 1 + drivers/iommu/sprd-iommu.c | 598 +++++++++++++++++++++++++++++++++++++
This looks like it actually belongs under drivers/iommu/arm/, no?
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Robin Murphy
reviewerRe: [PATCH 2/2] iommu: add Unisoc iommu basic driver
Quoted 7 lines · Joerg Roedel
Quoted 6 lines · Chunyan Zhang
From: Chunyan Zhang <[email protected]>
This iommu module can be used by Unisoc's multimedia devices, such as display, Image codec(jpeg) and a few signal processors, including VSP(video), GSP(graphic), ISP(image), and CPP(camera pixel processor), etc.
Quoted 7 lines
Quoted 5 lines
Signed-off-by Chunyan Zhang <[email protected]>--- drivers/iommu/Kconfig | 12 + drivers/iommu/Makefile | 1 + drivers/iommu/sprd-iommu.c | 598 +++++++++++++++++++++++++++++++++++++This looks like it actually belongs under
drivers/iommu/arm/, no?
Nope, I believe if Arm Ltd. had any involvement in this I'd know about it :)
Robin.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerRe: [PATCH 2/2] iommu: add Unisoc iommu basic driver
Quoted 1 line · Robin Murphy
Nope, I believe if Arm Ltd. had any involvement in this I'd know about it :)
Okay, got confused by thinking of ARM as the CPU architecture, not the company :)
But given the intel/ and amd/ subdirectories refer to company names as well, the same is true for arm/.
Regards,
Joerg
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Robin Murphy
reviewerRe: [PATCH 2/2] iommu: add Unisoc iommu basic driver
Quoted 7 lines · Joerg Roedel
Quoted 1 line · Robin Murphy
Nope, I believe if Arm Ltd. had any involvement in this I'd know about it :)
Okay, got confused by thinking of ARM as the CPU architecture, not the company :)
But given the intel/ and amd/ subdirectories refer to company names as well, the same is true for arm/.
Right, trying to group IOMMU drivers by supposed CPU architecture is already a demonstrable non-starter; does intel-iommu count as x86, or IA-64, or do you want two copies? :P
I somehow doubt anyone would license one of Arm's SMMUs to go in a RISC-V/MIPS/etc. based SoC, but in principle, they *could*. In fact it's precisely cases like this one - where silicon vendors come up with their own little scatter-gather unit to go with their own display controller etc. - that I imagine are most likely to get reused if the vendor decides to experiment with different CPUs to reach new market segments.
Robin.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Chunyan Zhang
reviewerRe: [PATCH 2/2] iommu: add Unisoc iommu basic driver
Quoted 14 lines · Robin Murphy
Quoted 7 lines · Joerg Roedel
Quoted 1 line · Robin Murphy
Nope, I believe if Arm Ltd. had any involvement in this I'd know about it :)
Okay, got confused by thinking of ARM as the CPU architecture, not the company :)
But given the intel/ and amd/ subdirectories refer to company names as well, the same is true for arm/.Right, trying to group IOMMU drivers by supposed CPU architecture is already a demonstrable non-starter; does intel-iommu count as x86, or IA-64, or do you want two copies? :P
Quoted 6 lines
I somehow doubt anyone would license one of Arm's SMMUs to go in a RISC-V/MIPS/etc. based SoC, but in principle, they *could*. In fact it's precisely cases like this one - where silicon vendors come up with their own little scatter-gather unit to go with their own display controller etc. - that I imagine are most likely to get reused if the vendor decides to experiment with different CPUs to reach new market segments.
Yes, I agree, I believe this iommu unit along with Unisoc's multi-media modules can be used on other architecture SoCs, not only ARM based.
Quoted 2 lines
Robin.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerRe: [PATCH 2/2] iommu: add Unisoc iommu basic driver
In reply to Chunyan Zhangdrivers/iommu/sprd-iommu.c line 375
Quoted 12 lines · Chunyan Zhang
drivers/iommu/sprd-iommu.c new file +12
-0+static phys_addr_t sprd_iommu_iova_to_phys (struct iommu_domain *domain, +dma_addr_t iova) +{ +struct sprd_iommu_domain *dom =to_sprd_domain (domain); +unsigned long flags; +phys_addr_t pa; +unsigned long start = domain->geometry.aperture_start; +unsigned long end = domain->geometry.aperture_end; + +if (iova < start || iova > end) +pr_err ("iova (0x%llx) exceed the vpn range[0x%lx-0x%lx]!\n" , + iova, start, end);
It is not a good idea to continue here with an out-of-range iova. The code below might access random memory for its checks. Better do a WARN_ON here and return an invalid physical address.
drivers/iommu/sprd-iommu.c line 384
Quoted 9 lines
drivers/iommu/sprd-iommu.c new file +9
-0+ +spin_lock_irqsave (&dom->pgtlock, flags); + pa = *(dom->pgt_va + ((iova - start) >>SPRD_IOMMU_PAGE_SHIFT )); + pa = (pa <<SPRD_IOMMU_PAGE_SHIFT ) + ((iova - start) & (SPRD_IOMMU_PAGE_SIZE -1 )); +spin_unlock_irqrestore (&dom->pgtlock, flags); + +return pa; +} +
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Chunyan Zhang
reviewerRe: [PATCH 2/2] iommu: add Unisoc iommu basic driver
Quoted 18 lines · Joerg Roedel
drivers/iommu/sprd-iommu.c line 375
Quoted 12 lines · Chunyan Zhang
drivers/iommu/sprd-iommu.c new file +12
-0+static phys_addr_t sprd_iommu_iova_to_phys (struct iommu_domain *domain, +dma_addr_t iova) +{ +struct sprd_iommu_domain *dom =to_sprd_domain (domain); +unsigned long flags; +phys_addr_t pa; +unsigned long start = domain->geometry.aperture_start; +unsigned long end = domain->geometry.aperture_end; + +if (iova < start || iova > end) +pr_err ("iova (0x%llx) exceed the vpn range[0x%lx-0x%lx]!\n" , + iova, start, end);It is not a good idea to continue here with an out-of-range iova. The code below might access random memory for its checks. Better do a
WARN_ONhere and return an invalid physical address.
Yes, I will fix this.
Thanks,
Chunyan
Quoted 10 lines
drivers/iommu/sprd-iommu.c line 384
Quoted 10 lines
drivers/iommu/sprd-iommu.c new file +9
-0+ +spin_lock_irqsave (&dom->pgtlock, flags); + pa = *(dom->pgt_va + ((iova - start) >>SPRD_IOMMU_PAGE_SHIFT )); + pa = (pa <<SPRD_IOMMU_PAGE_SHIFT ) + ((iova - start) & (SPRD_IOMMU_PAGE_SIZE -1 )); +spin_unlock_irqrestore (&dom->pgtlock, flags); + +return pa; +} +
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu