Add iommu support for hi6220 HiKey board
Subsystems (3)
v5 cover Add iommu support for hi6220 HiKey board
The patch sets add iommu support for Hi6220 SoC. Current testing and support board is Hikey which is one of 96boards.
It is an arm64 open source board. For more information about this board, please access https://www.96boards.org.
The Architecture of SMMU on Hi6220 SoC:
+------------------------------------------------------------------+
| |
| +---------+ +--------+ +-------------+ +-------+ |
| | ADE | | ISP | | V/J codec | | G3D | |
| +----|----+ +---|----+ +------|------+ +---|---| |
| | | | | |
| ---------v-----------v--------------v--------------v----- |
| Media Bus |
| --------------------------------|---------------|-------- |
| | | |
| +---v---------------v--------+ |
| | SMMU | |
| +----------|---------|-------+ |
| | | |
+--------------------------------------------|---------|-----------+
| |
+------------v---------v-----------+
| DDRC |
+----------------------------------+Note:
The media system share the same smmu IP to access DDR memory. And all media IP use the same page table. The hi6220 iommu driver also uses the iova api to manage an iova allocator to ensure that the caller get different iova address.
The caller can use the follow sample code to map phy and iova address.
eg:
struct iommu_domain *domain = iommu_domain_alloc(bus); iommu_attach_device(domain, dev);
struct iova_domain *iovad = (struct iova_domain *)m_dev->archdata.iommu; struct iova * t_iova = alloc_iova(iovad, size, limit_pfn, align); iommu_map(domain, t_iova->pfn_lo << 12, phy_addr, size, port);
The patch sets are based on 4.4-RC1
V2: Fix tlb flush when unmap
V3: Fix format issue and iova address range
V5: Add cover-letter and resend to dt maillist
Chen Feng (3):
docs: iommu: Documentation for iommu in hi6220 SoC iommu/hisilicon: Add hi6220-SoC smmu driver
arm64: dts: Add dts node for hi6220 smmu driver
.../bindings/iommu/hisi,hi6220-iommu.txt | 32 ++ arch/arm64/boot/dts/hisilicon/hi6220.dtsi | 13 + drivers/iommu/Kconfig | 11 + drivers/iommu/Makefile | 1 + drivers/iommu/hi6220_iommu.c | 492 +++++++++++++++++++++ 5 files changed, 549 insertions(+) create mode 100644 Documentation/devicetree/bindings/iommu/hisi,hi6220-iommu.txt create mode 100644 drivers/iommu/hi6220_iommu.c
Signature · 1 line
1.9.1
PATCH RESEND v5 1/3 docs: iommu: Documentation for iommu in hi6220 SoC
Documentation for hi6220 iommu driver.
--- .../bindings/iommu/hisi,hi6220-iommu.txt | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Documentation/devicetree/bindings/iommu/hisi,hi6220-iommu.txt
Documentation/devicetree/bindings/iommu/hisi,hi6220-iommu.txt new file +32 -0
@@ -0,0 +1,32 @@ +Hi6220 SoC SMMU Device Driver devicetree document +The media system shared the same smmu IP to access DDR memory. And all +media IP used the same page table. + +Below binding describes the system mmu for media system in hi6220 platform + +Required properties: +- compatible: should contain "hisilicon,hi6220-smmu". +- reg: A tuple of base address and size of System MMU registers. +- clocks: a list of phandle + clock-specifier pairs, one for each entry + in clock-names. +- clock-names: should contain: + * "smmu" + * "media-sc" + * "smmu-peri" +- interrupts: An interrupt specifier for interrupt signal of System MMU. +- #iommu-cells: The iommu-cells should be 0. Because no additional information + needs to be encoded in the specifier. + +Examples: + iommu@f4210000 { + compatible = "hisilicon,hi6220-smmu"; + reg = <0x0 0xf4210000 0x0 0x1000>; + interrupts = <GIC_SPI 113 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&sys_ctrl HI6220_MMU_CLK>, + <&media_ctrl HI6220_MED_MMU>, + <&sys_ctrl HI6220_MEDIA_PLL_SRC>; + clock-names = "smmu", + "media-sc", + "smmu-peri"; + #iommu-cells = <0>; + };
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH V5 RESEND 1/3] docs: iommu: Documentation for iommu in hi6220 SoC
Quoted 3 lines · Chen Feng
Documentation for hi6220 iommu driver.
Signed-off-by Chen Feng <puck.chen-C8/M+/[email protected]>
Quoted 50 lines
--- .../bindings/iommu/hisi,hi6220-iommu.txt | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Documentation/devicetree/bindings/iommu/hisi,hi6220-iommu.txtDocumentation/devicetree/bindings/iommu/hisi,hi6220-iommu.txt new file +32
-0@@ -0,0 +1,32 @@ +Hi6220 SoC SMMU Device Driver devicetree document +The media system shared the same smmu IP to access DDR memory. And all +media IP used the same page table. + +Below binding describes the system mmu for media system in hi6220 platform + +Required properties: +- compatible: should contain "hisilicon,hi6220-smmu". +- reg: A tuple of base address and size of System MMU registers. +- clocks: a list of phandle + clock-specifier pairs, one for each entry + in clock-names. +- clock-names: should contain: + * "smmu" + * "media-sc" + * "smmu-peri" +- interrupts: An interrupt specifier for interrupt signal of System MMU. +- #iommu-cells: The iommu-cells should be 0. Because no additional information + needs to be encoded in the specifier. + +Examples: + iommu@f4210000 { + compatible = "hisilicon,hi6220-smmu"; + reg = <0x0 0xf4210000 0x0 0x1000>; + interrupts = <GIC_SPI 113 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&sys_ctrl HI6220_MMU_CLK>, + <&media_ctrl HI6220_MED_MMU>, + <&sys_ctrl HI6220_MEDIA_PLL_SRC>; + clock-names = "smmu", + "media-sc", + "smmu-peri"; + #iommu-cells = <0>; + };Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH RESEND v5 2/3 iommu/hisilicon: Add hi6220-SoC smmu driver
In reply to Chen FengAdd iommu driver for hi6220 SoC platform.The smmu on hi6220 SoC is for media system.And the media IP use the same page-table. It supports only one-to-one mapping from iova to phys address.
--- drivers/iommu/Kconfig | 11 + drivers/iommu/Makefile | 1 + drivers/iommu/hi6220_iommu.c | 492 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 504 insertions(+) create mode 100644 drivers/iommu/hi6220_iommu.c
drivers/iommu/Kconfig +11 -0
@@ -84,6 +84,17 @@ config IOMMU_PGTABLES_L2 def_bool y depends on MSM_IOMMU && MMU && SMP && CPU_DCACHE_DISABLE=n +config HI6220_IOMMU + bool "Hi6220 IOMMU Support" + depends on ARM64 + select IOMMU_API + select IOMMU_IOVA + help + Enable IOMMU Driver for hi6220 SoC. The IOMMU API and IOMMU IOVA + is also selected. + + If unsure, say N. + # AMD IOMMU support config AMD_IOMMU bool "AMD IOMMU support"
drivers/iommu/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_AMD_IOMMU_V2) += amd_iommu_v2.o obj-$(CONFIG_ARM_SMMU) += arm-smmu.o obj-$(CONFIG_ARM_SMMU_V3) += arm-smmu-v3.o obj-$(CONFIG_DMAR_TABLE) += dmar.o +obj-$(CONFIG_HI6220_IOMMU) += hi6220_iommu.o obj-$(CONFIG_INTEL_IOMMU) += intel-iommu.o obj-$(CONFIG_INTEL_IOMMU_SVM) += intel-svm.o obj-$(CONFIG_IPMMU_VMSA) += ipmmu-vmsa.o
drivers/iommu/hi6220_iommu.c new file +492 -0
492 lines not on this page · raw message
Signature · 1 line
1.9.1
Joerg Roedel
maintainerRe: [PATCH V5 RESEND 2/3] iommu/hisilicon: Add hi6220-SoC smmu driver
drivers/iommu/Kconfig config IOMMU_PGTABLES_L2 · line 94
Quoted 8 lines · Chen Feng
drivers/iommu/Kconfig +8
-0+config HI6220_IOMMU + bool "Hi6220 IOMMU Support" + depends on ARM64 + select IOMMU_API + select IOMMU_IOVA + help + Enable IOMMU Driver for hi6220 SoC. The IOMMU API and IOMMU IOVA + is also selected.
The last sentence is of little help for the user. Better put the reasons in here when a user should select this option.
drivers/iommu/hi6220_iommu.c line 207
Quoted 1 line
drivers/iommu/hi6220_iommu.c new file +1
-0+/*set axi id*/
Coding style nit: Please write these oneline comments with spaces, like this:
/* set axi id */
drivers/iommu/hi6220_iommu.c line 334
Quoted 13 lines
drivers/iommu/hi6220_iommu.c new file +13
-0+static int hi6220_smmu_attach_dev (struct iommu_domain *domain, +struct device *dev) +{ + dev->archdata.iommu = &iova_allocator; + +return 0 ; +} + +static void hi6220_smmu_detach_dev (struct iommu_domain *domain, +struct device *dev) +{ + dev->archdata.iommu =NULL ; +}
This basically means that this driver only supports one domain, right? That is not compatible with the iommu-api requirements.
You need to create an iommu-group per smmu in your system and put all devices translated by this smmu in that group. And then you must change your code to allow attaching/detaching this iommu-group to different domains.
Joerg
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH V5 RESEND 2/3] iommu/hisilicon: Add hi6220-SoC smmu driver
Quoted 13 lines · Joerg Roedel
drivers/iommu/Kconfig config IOMMU_PGTABLES_L2 · line 94
Quoted 8 lines · Chen Feng
drivers/iommu/Kconfig +8
-0+config HI6220_IOMMU + bool "Hi6220 IOMMU Support" + depends on ARM64 + select IOMMU_API + select IOMMU_IOVA + help + Enable IOMMU Driver for hi6220 SoC. The IOMMU API and IOMMU IOVA + is also selected.The last sentence is of little help for the user. Better put the reasons in here when a user should select this option.
Quoted 7 lines
drivers/iommu/hi6220_iommu.c line 207
Quoted 1 line
drivers/iommu/hi6220_iommu.c new file +1
-0+/*set axi id*/ Coding style nit: Please write these oneline comments with spaces, like this:
/* set axi id */
learned,Thanks.
Quoted 7 lines
Quoted 7 lines
drivers/iommu/hi6220_iommu.c new file +7
-0+static int hi6220_smmu_attach_dev (struct iommu_domain *domain, +struct device *dev) +{ + dev->archdata.iommu = &iova_allocator; + +return 0 ; +}
Quoted 8 lines
drivers/iommu/hi6220_iommu.c line 334
Quoted 6 lines
drivers/iommu/hi6220_iommu.c new file +6
-0+ +static void hi6220_smmu_detach_dev (struct iommu_domain *domain, +struct device *dev) +{ + dev->archdata.iommu =NULL ; +}This basically means that this driver only supports one domain, right?
yes.
Quoted 7 lines
That is not compatible with the iommu-api requirements.
You need to create an iommu-group per smmu in your system and put all devices translated by this smmu in that group. And then you must change your code to allow attaching/detaching this iommu-group to different domains.
I read the code,I am confused about these concepts.
In my opinion,
IOMMU-Domain: The masters in one domain share the same iova space. Is that right?
IOMMU-GROUP: As you mentioned up,all devices translated by this smmu should be into one group. I can do this. But if there is only on domain in the system, how can I attaching/detaching the group to different domains.
I think I have something wrong with these concepts.
Could you help to give me some suggestions.
Quoted 6 lines
Joerg
.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Joerg Roedel
maintainerRe: [PATCH V5 RESEND 2/3] iommu/hisilicon: Add hi6220-SoC smmu driver
Quoted 9 lines · chenfeng
Quoted 5 lines · Joerg Roedel
You need to create an iommu-group per smmu in your system and put all devices translated by this smmu in that group. And then you must change your code to allow attaching/detaching this iommu-group to different domains.
I read the code,I am confused about these concepts.
In my opinion,
IOMMU-Domain: The masters in one domain share the same iova space. Is that right?
Yes, an iommu-domain is an abstraction of a single page-table and describes one iova address space. The SMMU in your hardware supports only on page-table, so all devices behind it share a single iova address space, und must be in the same domain.
But the way you implemented it there could be only one domain per SMMU. With the IOMMU-API we must support to change the domain of an SMMU. Think of one domain for DMA-API usage and another for VFIO, for example.
Quoted 4 lines
IOMMU-GROUP: As you mentioned up,all devices translated by this smmu should be into one group. I can do this. But if there is only on domain in the system, how can I attaching/detaching the group to different domains.
IOMMU-groups describe the isolation capabilities of the IOMMU between devices. If devices are in a different IOMMU-group, this means that the hardware can isolate them from each other.
Attaching the devices in a group to a new domain means in your case, that you set a different page-table for them. Since you can only do that for all devices behind a SMMU, these devices must be in on IOMMU-group.
Joerg
PATCH RESEND v5 3/3 arm64: dts: Add dts node for hi6220 smmu driver
In reply to Chen FengAdd iommu node for hi6220 SoC platform
--- arch/arm64/boot/dts/hisilicon/hi6220.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm64/boot/dts/hisilicon/hi6220.dtsi +13 -0
@@ -208,5 +208,18 @@ clock-names = "uartclk", "apb_pclk"; status = "disabled"; }; + + iommu: iommu@f4210000 { + compatible = "hisilicon,hi6220-smmu"; + reg = <0x0 0xf4210000 0x0 0x1000>; + interrupts = <GIC_SPI 113 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&sys_ctrl HI6220_MMU_CLK>, + <&media_ctrl HI6220_MED_MMU>, + <&sys_ctrl HI6220_MEDIA_PLL_SRC>; + clock-names = "smmu", + "media-sc", + "smmu-peri"; + #iommu-cells = <0>; + }; }; };
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Joerg Roedel
maintainerQuoted 6 lines · Chen Feng
eg:
structiommu_domain*domain =iommu_domain_alloc(bus);iommu_attach_device(domain, dev);
structiova_domain*iovad = (structiova_domain*)m_dev->archdata.iommu; struct iova *t_iova=alloc_iova(iovad, size, limit_pfn, align);iommu_map(domain, t_iova->pfn_lo << 12, phy_addr, size, port);
Any reason the media subsystem should use the iommu-api directly, and not the dma-api? You can make your iommu available by adapting the common dma-iommu implementation from Robin Murphy to your iommu to make it usable through the dma-api.
Joerg
Quoted 8 lines · Joerg Roedel
Quoted 6 lines · Chen Feng
eg:
structiommu_domain*domain =iommu_domain_alloc(bus);iommu_attach_device(domain, dev);
structiova_domain*iovad = (structiova_domain*)m_dev->archdata.iommu; struct iova *t_iova=alloc_iova(iovad, size, limit_pfn, align);iommu_map(domain, t_iova->pfn_lo << 12, phy_addr, size, port);
Quoted 5 lines
Any reason the media subsystem should use the iommu-api directly, and not the dma-api? You can make your iommu available by adapting the common dma-iommu implementation from Robin Murphy to your iommu to make it usable through the dma-api.
ok, I will change this to dma-api. Since v1 version, the dma-api was not ok for arm64. I will do this with dma-api function.
Quoted 6 lines
Joerg
.