iommu/exynos: Add iommu driver for Exynos Platforms
Subsystems (5)
PATCH v8 2/2 iommu/exynos: Add iommu driver for Exynos Platforms
wBAAHMAYQBtAHMAdQBuAGcALgBjAG8AbQA=;Thu,
29 Dec 2011 12:25:50 GMT;WwBQAEEAVABDAEgAIAB2ADgAIAAyAC8AMgBdACAAaQBvAG0AbQB1AC8AZQB4AHkAbgBvAHMAOgAgAEEAZABkACAAaQBvAG0AbQB1ACAAZAByAGkAdgBlAHIAIABmAG8AcgAgAEUAeAB5AG4AbwBzACAAUABsAGEAdABmAG8AcgBtAHMA
x-cr-puzzleid: {1B837C06-BFD9-4E35-93D7-D8A3554D486A}
This is the System MMU driver and IOMMU API implementation for Exynos SOC platforms. Exynos platforms has more than 10 System MMUs dedicated for each multimedia accelerators.
The System MMU driver is already in arc/arm/plat-s5p but it is moved to drivers/iommu due to Ohad Ben-Cohen gathered IOMMU drivers there
This patch also includes fault handling feature in IOMMU driver suggested by Ohad.
Users of IOMMU API can register its own fault handler with iommu_set_fault_handler() and the handler is called by IRQ handler of System MMU.
If no user installs fault handler, IOMMU driver prints debugging message and generates kernel oops.
This IOMMU driver calls bus_set_iommu() instead of register_iommu() since Joerg suggested that installing iommu_ops in bus_type.
--- arch/arm/plat-s5p/Kconfig | 8 - arch/arm/plat-s5p/Makefile | 1 - arch/arm/plat-s5p/sysmmu.c | 313 --------- arch/arm/plat-samsung/include/plat/sysmmu.h | 95 --- drivers/iommu/Kconfig | 12 + drivers/iommu/Makefile | 1 + drivers/iommu/exynos-iommu.c | 1008 +++++++++++++++++++++++++++ 7 files changed, 1021 insertions(+), 417 deletions(-) delete mode 100644 arch/arm/plat-s5p/sysmmu.c delete mode 100644 arch/arm/plat-samsung/include/plat/sysmmu.h create mode 100644 drivers/iommu/exynos-iommu.c
arch/arm/plat-s5p/Kconfig +0 -8
@@ -45,14 +45,6 @@ config S5P_PM Common code for power management support on S5P and newer SoCs Note: Do not select this for S5P6440 and S5P6450. -comment "System MMU" - -config S5P_SYSTEM_MMU - bool "S5P SYSTEM MMU" - depends on ARCH_EXYNOS4 - help - Say Y here if you want to enable System MMU - config S5P_SLEEP bool help
arch/arm/plat-s5p/Makefile +0 -1
@@ -18,7 +18,6 @@ obj-y += clock.o obj-y += irq.o obj-$(CONFIG_S5P_EXT_INT) += irq-eint.o obj-$(CONFIG_S5P_GPIO_INT) += irq-gpioint.o -obj-$(CONFIG_S5P_SYSTEM_MMU) += sysmmu.o obj-$(CONFIG_S5P_PM) += pm.o irq-pm.o obj-$(CONFIG_S5P_SLEEP) += sleep.o obj-$(CONFIG_S5P_HRT) += s5p-time.o
arch/arm/plat-s5p/sysmmu.c deleted +0 -313
313 lines not on this page · raw message
arch/arm/plat-samsung/include/plat/sysmmu.h deleted +0 -95
95 lines not on this page · raw message
drivers/iommu/Kconfig +12 -0
@@ -131,4 +131,16 @@ config OMAP_IOMMU_DEBUG Say N unless you know you need this. +config EXYNOS_IOMMU + bool "Exynos IOMMU Support" + depends on ARCH_EXYNOS && EXYNOS4_DEV_SYSMMU + select IOMMU_API + help + Support for the IOMMU(System MMU) of Samsung Exynos application + processor family. This enables H/W multimedia accellerators to see + non-linear physical memory chunks as a linear memory in their + address spaces + + If unsure, say N here. + endif # IOMMU_SUPPORT
drivers/iommu/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_IRQ_REMAP) += intr_remapping.o obj-$(CONFIG_OMAP_IOMMU) += omap-iommu.o obj-$(CONFIG_OMAP_IOVMM) += omap-iovmm.o obj-$(CONFIG_OMAP_IOMMU_DEBUG) += omap-iommu-debug.o +obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o
drivers/iommu/exynos-iommu.c new file +1008 -0
1,008 lines not on this page · raw message
Signature · 1 line
1.7.1
'Joerg Roedel'
maintainerHi,
please also get and inclue Acks from the Exynos maintainer for the next post.
Since I have a compiling config for exynos now I will merge the patches when you have the Acks and addressed or explained the issues I pointed out below.
drivers/iommu/exynos-iommu.c line 629
Quoted 8 lines · KyongHo Cho
drivers/iommu/exynos-iommu.c new file +8
-0+static void exynos_iommu_domain_destroy (struct iommu_domain *domain) +{ +struct exynos_iommu_domain *priv = domain->priv; +struct list_head *pos, *n; +unsigned long flags; +int i; + +WARN_ON (!list_empty (&priv->clients));
This isn't really a problem. We allow destroying a domain with devices attached. So this WARN_ON is not necessary.
Quoted 7 lines
drivers/iommu/exynos-iommu.c new file +7
-0+static int exynos_iommu_map (struct iommu_domain *domain,unsigned long iova, +phys_addr_t paddr,size_t size,int prot) +{ +struct exynos_iommu_domain *priv = domain->priv; +unsigned long *entry; +unsigned long flags; +int ret = -ENOMEM ;
drivers/iommu/exynos-iommu.c line 868
Quoted 10 lines
drivers/iommu/exynos-iommu.c new file +10
-0+ +BUG_ON (priv->pgtable ==NULL ); + +spin_lock_irqsave (&priv->pgtablelock, flags); + + entry =section_entry (priv->pgtable, iova); + +if (size >=SECT_SIZE ) { + ret =lv1set_section (entry, paddr, size >>SECT_ORDER , + &priv->lv2entcnt[lv1ent_offset (iova)]);
This looks like you are partially re-implementing behavior of generic code because you are mapping multiple sections at once. The generic map code already splits up the address range correctly, so no need to do this in the driver (unless there is some benefit in the hardware, like an IOTLB entry that can cover multiple sections or something similar).
Quoted 4 lines
drivers/iommu/exynos-iommu.c new file +4
-0+static size_t exynos_iommu_unmap (struct iommu_domain *domain, +unsigned long iova,size_t size) +{ +struct exynos_iommu_domain *priv = domain->priv;
drivers/iommu/exynos-iommu.c line 901
Quoted 10 lines
drivers/iommu/exynos-iommu.c new file +10
-0+struct iommu_client *client; +unsigned long flags; + +BUG_ON (priv->pgtable ==NULL ); + +spin_lock_irqsave (&priv->pgtablelock, flags); + +while (size !=0 ) { +int i, nent, order; +unsigned long *pent, *sent;
Same with this while-loop. This looks like it re-implements behavior from the generic code.
Regards,
Joerg
Hi,
Quoted 8 lines · Joerg Roedel
Hi,
please also get and inclue Acks from the Exynos maintainer for the next post.
Since I have a compiling config for exynos now I will merge the patches when you have the Acks and addressed or explained the issues I pointed out below.
Thanks for review!
I will include the Acks in the next patchset.
I will post the next patchset with corrections by the day after tomorrow.
And sorry for late reply.
I had holidays for the new year's day based on Lunar system.
Quoted 13 lines · KyongHo Cho
Review
Quoted 8 lines
(quoted diff) +8
-0+static void exynos_iommu_domain_destroy(struct iommu_domain *domain) +{ + ? ? struct exynos_iommu_domain *priv = domain->priv; + ? ? struct list_head *pos, *n; + ? ? unsigned long flags; + ? ? int i; + + ? ? WARN_ON(!list_empty(&priv->clients));This isn't really a problem. We allow destroying a domain with devices attached. So this
WARN_ONis not necessary.
OK.
BTW, Isn't it a problem when a device driver does not know that its iommu domain is destroyed?
Can we regards that it is the faulty use of iommu API?
Quoted 15 lines
Quoted 15 lines
(quoted diff) +15
-0+static int exynos_iommu_map(struct iommu_domain *domain, unsigned long iova, + ? ? ? ? ? ? ? ? ? ? ?phys_addr_t paddr, size_t size, int prot) +{ + ? ? struct exynos_iommu_domain *priv = domain->priv; + ? ? unsigned long *entry; + ? ? unsigned long flags; + ? ? int ret = -ENOMEM; + + ? ? BUG_ON(priv->pgtable == NULL); + + ? ? spin_lock_irqsave(&priv->pgtablelock, flags); + + ? ? entry = section_entry(priv->pgtable, iova); + + ? ? if (size >= SECT_SIZE) {
Quoted 9 lines
Quoted 2 lines
+ ? ? ? ? ? ? ret = lv1set_section(entry, paddr, size >>
SECT_ORDER,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &priv->lv2entcnt[lv1ent_offset(iova)]);This looks like you are partially re-implementing behavior of generic code because you are mapping multiple sections at once. The generic map code already splits up the address range correctly, so no need to do this in the driver (unless there is some benefit in the hardware, like an IOTLB entry that can cover multiple sections or something similar).
Yes, I wanted to avoid repeated function call by iommu_map(). s5p_iommu_map() maps once for the same page size since it is efficient and simple.
That's why this driver initializes domain->pgsize_bitmap with 0xFFFFF000 even though our IOMMU driver just supports 3 different page sizes including 4KB, 64KB and 1MB.
Do you think it is better for s5p_iommu_map() to map just one page at once?
Quoted 9 lines
Quoted 9 lines
(quoted diff) +9
-0+static size_t exynos_iommu_unmap(struct iommu_domain *domain, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?unsigned long iova, size_t size) +{ + ? ? struct exynos_iommu_domain *priv = domain->priv; + ? ? struct iommu_client *client; + ? ? unsigned long flags; + + ? ? BUG_ON(priv->pgtable == NULL); +
Quoted 9 lines
Quoted 5 lines
+ ? ?
spin_lock_irqsave(&priv->pgtablelock, flags); +
+ ? ? while (size != 0) {
+ ? ? ? ? ? ? int i, nent, order;
+ ? ? ? ? ? ? unsigned long *pent, *sent;Same with this while-loop. This looks like it re-implements behavior from the generic code.
If a region to unmap consists of tens of pages there is no way to avoid flushing IOTLB repeatedly.
Out iommu driver doesn't need to flush IOTLB more than once for a region to unmap.
Do you think the driver is better to unmaps just one page at once though flushing IOTLB repeatedly?
Thank you.
KyongHo
Quoted 6 lines · KyongHo Cho
Quoted 3 lines
This isn't really a problem. We allow destroying a domain with devices attached. So this
WARN_ONis not necessary.BTW, Isn't it a problem when a device driver does not know that its iommu domain is destroyed?
Can we regards that it is the faulty use of iommu API?
Yes we could, but we don't ;) The domain_destroy path has to take care of this anyway to be robust, so we can also take away the need to unattach everything from a domain from the iommu-api user.
Quoted 6 lines
Quoted 6 lines
This looks like you are partially re-implementing behavior of generic code because you are mapping multiple sections at once. The generic map code already splits up the address range correctly, so no need to do this in the driver (unless there is some benefit in the hardware, like an IOTLB entry that can cover multiple sections or something similar).
Quoted 6 lines
Yes, I wanted to avoid repeated function call by
iommu_map().s5p_iommu_map()maps once for the same page size since it is efficient and simple.
That's why this driver initializesdomain->pgsize_bitmapwith0xFFFFF000even though our IOMMU driver just supports 3 different page sizes including 4KB, 64KB and 1MB.
Repeated function calls are not a real performance problem in the iommu-code in my experience. The overhead is usualle somewhere else.
Quoted 1 line
Do you think it is better for
s5p_iommu_map()to map just one page at once?
In general I think we should not duplicate code. This logic was moved to the generic part for a reason and iommu drivers should use it unless there is a very good reason not to do so.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
(quoted diff) +9
-0+static size_t exynos_iommu_unmap(struct iommu_domain *domain, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?unsigned long iova, size_t size) +{ + ? ? struct exynos_iommu_domain *priv = domain->priv; + ? ? struct iommu_client *client; + ? ? unsigned long flags; + + ? ? BUG_ON(priv->pgtable == NULL); +Quoted 9 lines
Quoted 5 lines
+ ? ?
spin_lock_irqsave(&priv->pgtablelock, flags); +
+ ? ? while (size != 0) {
+ ? ? ? ? ? ? int i, nent, order;
+ ? ? ? ? ? ? unsigned long *pent, *sent;Same with this while-loop. This looks like it re-implements behavior from the generic code.
Quoted 8 lines
If a region to unmap consists of tens of pages there is no way to avoid flushing IOTLB repeatedly.
Out iommu driver doesn't need to flush IOTLB more than once for a region to unmap.
Do you think the driver is better to unmaps just one page at once though flushing IOTLB repeatedly?
Is I/O-TLB flushing an expensive operation?
Joerg
Signature · 5 lines
AMD Operating System Research Center Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach General Managers: Alberto Bozzo Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632
Quoted 5 lines · KyongHo Cho
Hi,
Quoted 2 lines · Joerg Roedel
Hi,
Quoted 8 lines
Quoted 6 lines
please also get and inclue Acks from the Exynos maintainer for the next post.
Since I have a compiling config for exynos now I will merge the patches when you have the Acks and addressed or explained the issues I pointed out below.Thanks for review!
I will include the Acks in the next patchset.
If his updated patch is ok to me, let me reply then.
As a note, I'm preparing for new EXYNOS SoC and so some exynos stuff such as clock can be modified. So would be better if KyongHo could update regarding arch/arm/ part based on that. Maybe in the beginning of Feb.?
Joerg, as I said, I need a topic branch for this to avoid conflict and I think, now you can provide it for samsung tree.
If any problems, please let me know.
Thanks.
Best regards,
Kgene.
--
Kukjin Kim <[email protected]>, Senior Engineer, SW Solution Development Team, Samsung Electronics Co., Ltd.
Quoted 49 lines
I will post the next patchset with corrections by the day after tomorrow.
And sorry for late reply.
I had holidays for the new year's day based on Lunar system.Quoted 13 lines · KyongHo Cho
Review
Quoted 8 lines
(quoted diff) +8
-0+static void exynos_iommu_domain_destroy(struct iommu_domain *domain) +{ + ? ? struct exynos_iommu_domain *priv = domain->priv; + ? ? struct list_head *pos, *n; + ? ? unsigned long flags; + ? ? int i; + + ? ? WARN_ON(!list_empty(&priv->clients));This isn't really a problem. We allow destroying a domain with devices attached. So this
WARN_ONis not necessary.OK.
BTW, Isn't it a problem when a device driver does not know that its iommu domain is destroyed?
Can we regards that it is the faulty use of iommu API?Quoted 1 line
Quoted 1 line
+static int exynos_iommu_map(struct
iommu_domain*domain, unsigned longiova,
Quoted 18 lines
Quoted 6 lines
+ ? ? ? ? ? ? ? ? ? ? ?phys_addr_t paddr,
size_tsize, int prot)(quoted diff) +5
-0+{ + ? ? struct exynos_iommu_domain *priv = domain->priv; + ? ? unsigned long *entry; + ? ? unsigned long flags; + ? ? int ret = -ENOMEM;Review
Quoted 10 lines
(quoted diff) +10
-0+ + ? ? BUG_ON(priv->pgtable == NULL); + + ? ? spin_lock_irqsave(&priv->pgtablelock, flags); + + ? ? entry = section_entry(priv->pgtable, iova); + + ? ? if (size >= SECT_SIZE) { + ? ? ? ? ? ? ret = lv1set_section(entry, paddr, size >> SECT_ORDER, + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? &priv-lv2entcnt[lv1ent_offset(iova)]);
Quoted 6 lines
This looks like you are partially re-implementing behavior of generic code because you are mapping multiple sections at once. The generic map code already splits up the address range correctly, so no need to do this in the driver (unless there is some benefit in the hardware, like an IOTLB entry that can cover multiple sections or something similar).
Quoted 8 lines
Yes, I wanted to avoid repeated function call by
iommu_map().s5p_iommu_map()maps once for the same page size since it is efficient and simple.
That's why this driver initializesdomain->pgsize_bitmapwith0xFFFFF000even though our IOMMU driver just supports 3 different page sizes including 4KB, 64KB and 1MB.Do you think it is better for
s5p_iommu_map()to map just one page at
once?
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
+static
size_texynos_iommu_unmap(structiommu_domain*domain,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?unsigned long iova,size_t
size)
Quoted 29 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +7
-0+{ + ? ? struct exynos_iommu_domain *priv = domain->priv; + ? ? struct iommu_client *client; + ? ? unsigned long flags; + + ? ? BUG_ON(priv->pgtable == NULL); +Quoted 9 lines
Quoted 5 lines
+ ? ?
spin_lock_irqsave(&priv->pgtablelock, flags); +
+ ? ? while (size != 0) {
+ ? ? ? ? ? ? int i, nent, order;
+ ? ? ? ? ? ? unsigned long *pent, *sent;Same with this while-loop. This looks like it re-implements behavior from the generic code.
If a region to unmap consists of tens of pages there is no way to avoid flushing IOTLB repeatedly.
Out iommu driver doesn't need to flush IOTLB more than once for a region to unmap.
Do you think the driver is better to unmaps just one page at once though flushing IOTLB repeatedly?
Thank you.
KyongHo
Quoted 12 lines · Kukjin Kim
Quoted 11 lines · KyongHo Cho
Hi,
Quoted 8 lines · Joerg Roedel
Hi,
please also get and inclue Acks from the Exynos maintainer for the next post.
Since I have a compiling config for exynos now I will merge the patches when you have the Acks and addressed or explained the issues I pointed out below.
Quoted 9 lines
Quoted 2 lines
Thanks for review!
I will include the Acks in the next patchset.If his updated patch is ok to me, let me reply then.
As a note, I'm preparing for new EXYNOS SoC and so some exynos stuff such as clock can be modified. So would be better if KyongHo could update regarding
arch/arm/part based on that. Maybe in the beginning of Feb.?
Thanks.
I will post new patchset when Kukjin completes his job about EXYNOS SoC because my patchset changes clock definitions of EXYNOS tree.
Quoted 7 lines
Joerg, as I said, I need a topic branch for this to avoid conflict and I think, now you can provide it for samsung tree.
If any problems, please let me know.
Thanks.
Thank you.
KyongHo.