Skip to contentSkip to conversation

iommu/exynos: Add iommu driver for Exynos4 Platforms

PATCH Superseded 조경호 2 participants 12 messages Sep 24, 2011 – Sep 27, 2011

Subsystems (2)

v1 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

조경호

author
#0 lore raw

PATCH 3/4 iommu/exynos: Add iommu driver for Exynos4 Platforms

This is the System MMU driver and IOMMU API implementation for Exynos4 SOC platforms. Exynos4 platforms has more than 10 System MMUs dedicated for each multimedia accellerators.

---
 drivers/iommu/Kconfig        |   14 +
 drivers/iommu/Makefile       |    1 +
 drivers/iommu/exynos_iommu.c |  859 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 874 insertions(+), 0 deletions(-)
 create mode 100644 drivers/iommu/exynos_iommu.c
drivers/iommu/Kconfig +14 -0
index b57b3fa..1c754cd 100644
@@ -107,4 +107,18 @@ config INTR_REMAP
 	  To use x2apic mode in the CPU's which support x2APIC enhancements or
 	  to support platforms with CPU's having > 8 bit APIC ID, say Y.
 
+# EXYNOS IOMMU support
+config EXYNOS_IOMMU
+	bool "Exynos IOMMU Support"
+	depends on ARCH_EXYNOS4
+	select IOMMU_API
+	select EXYNOS4_DEV_SYSMMU
+	help
+	  Support for the IOMMUs (System MMUs) Samsung Exynos application
+	  processor family. This enables H/W multimedia accellerators to view
+	  non-linear physical memory chunks as a linear memory in their virtual
+	  address spaces.
+
+	  If unsure, say N here.
+
 endif # IOMMU_SUPPORT
drivers/iommu/Makefile +1 -0
index 4d4d77d..1eb924f 100644
@@ -3,3 +3,4 @@ obj-$(CONFIG_MSM_IOMMU) += msm_iommu.o msm_iommu_dev.o
 obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o amd_iommu_init.o
 obj-$(CONFIG_DMAR) += dmar.o iova.o intel-iommu.o
 obj-$(CONFIG_INTR_REMAP) += dmar.o intr_remapping.o
+obj-$(CONFIG_EXYNOS_IOMMU) += exynos_iommu.o
drivers/iommu/exynos_iommu.c new file +859 -0

859 lines not on this page · raw message

Signature · 1 line
1.7.1
#1 lore raw

2011/9/24 ??? <[email protected]>:

Quoted 5 lines

This is the System MMU driver and IOMMU API implementation for Exynos4 SOC platforms. Exynos4 platforms has more than 10 System MMUs dedicated for each multimedia accellerators.

...

Quoted 21 lines
drivers/iommu/exynos_iommu.c new file +21 -0
+static int exynos_iommu_fault_handler(struct iommu_domain *domain,
+                       struct device *dev, unsigned long iova, int flags)
+{
+       struct exynos_iommu_domain *priv = domain->priv;
+
+       dev_err(priv->dev, "%s occured at %p(Page table base: %p)\n",
+                               sysmmu_fault_name[flags], (void *)iova,
+                               (void *)(__pa(priv->pgtable)));
+       dev_err(priv->dev, "\t\tGenerating Kernel OOPS...\n");
+       dev_err(priv->dev, "\t\tbecause it is unrecoverable.\n");
+       dev_err(priv->dev,
+               "\t\tSet Fault handler with iommu_set_fault_handler().\n");
+       dev_err(priv->dev, "\t\tto handle System MMU fault.\n");
+
+       BUG();
+
+       return 0;
+}
+
+static int exynos_iommu_domain_init(struct iommu_domain *domain)
+{

...

Quoted 1 line

+ iommu_set_fault_handler(domain, &exynos_iommu_fault_handler);

It doesn't make a lot of sense to set an iommu fault handler here; the intention of iommu_set_fault_handler() is to allow upper layers to do that.

Moreover, exynos_sysmmu_irq() anyway knows whenever a fault occurs, so calling report_iommu_fault() just to have it call into the driver again seems redundant.

If you want an exynos-specific behavior to occur whenever there's an iommu fault, you should do that in exynos_sysmmu_irq itself. If you just want a generic default logging behavior to occur whenever there's no other fault handler installed, you might even want to consider adding it to the IOMMU core.

#2 lore raw

Hi.

Quoted 29 lines · Ohad Ben-Cohen

2011/9/24 ??? <[email protected]>:

Quoted 5 lines

This is the System MMU driver and IOMMU API implementation for Exynos4 SOC platforms. Exynos4 platforms has more than 10 System MMUs dedicated for each multimedia accellerators.

...

Quoted 21 lines
(quoted diff) +21 -0
+static int exynos_iommu_fault_handler(struct iommu_domain *domain,
+ ? ? ? ? ? ? ? ? ? ? ? struct device *dev, unsigned long iova, int flags)
+{
+ ? ? ? struct exynos_iommu_domain *priv = domain->priv;
+
+ ? ? ? dev_err(priv->dev, "%s occured at %p(Page table base: %p)\n",
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? sysmmu_fault_name[flags], (void *)iova,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (void *)(__pa(priv->pgtable)));
+ ? ? ? dev_err(priv->dev, "\t\tGenerating Kernel OOPS...\n");
+ ? ? ? dev_err(priv->dev, "\t\tbecause it is unrecoverable.\n");
+ ? ? ? dev_err(priv->dev,
+ ? ? ? ? ? ? ? "\t\tSet Fault handler with iommu_set_fault_handler().\n");
+ ? ? ? dev_err(priv->dev, "\t\tto handle System MMU fault.\n");
+
+ ? ? ? BUG();
+
+ ? ? ? return 0;
+}
+
+static int exynos_iommu_domain_init(struct iommu_domain *domain)
+{

...

Quoted 5 lines
Quoted 1 line

+ ? ? ? iommu_set_fault_handler(domain, &exynos_iommu_fault_handler);

It doesn't make a lot of sense to set an iommu fault handler here; the intention of iommu_set_fault_handler() is to allow upper layers to do that.

As you've noticed, it is default behavior for iommu fault. If an upper layer calls iommu_set_fault_handler(), it is replaced with the new one.

Quoted 5 lines

Moreover, exynos_sysmmu_irq() anyway knows whenever a fault occurs, so calling report_iommu_fault() just to have it call into the driver again seems redundant.

I think calling report_iommu_fault() in exynos_sysmmu_irq() is rather simple. To do the default behavior in exynos_sysmmu_irq(),
it must check if domain->handler is NULL or not.
But the checking is also performed in report_iommu_fault() also.

I think just calling report_iommu_fault() reduces redundancy.

Quoted 5 lines

If you want an exynos-specific behavior to occur whenever there's an iommu fault, you should do that in exynos_sysmmu_irq itself. If you just want a generic default logging behavior to occur whenever there's no other fault handler installed, you might even want to consider adding it to the IOMMU core.

It is neither a specific behavior nor a generic logging.

Just a default MMU fault report that can be replaceable with a fault handler that a device driver provides.

Regards,
Cho KyongHo.

#3 lore raw
Quoted 1 line · KyongHo Cho

As you've noticed, it is default behavior for iommu fault.

Then why not add it to the IOMMU core ? it's quite generic and can be useful for others, too.

Thanks,
Ohad.

#4 lore raw
Quoted 6 lines · Ohad Ben-Cohen
Quoted 1 line · KyongHo Cho

As you've noticed, it is default behavior for iommu fault.

Then why not add it to the IOMMU core ? it's quite generic and can be useful for others, too.

Every fault in IOMMU (System MMU) is an error logically and must not happen in our multimedia device drivers because, our device drivers always construct page table completely before address translation in System MMU
and TLB loads translation information automatically when TLB miss.

I am not sure if the default behavior of MMU fault in our IOMMU driver is also correct for other IOMMU drivers.

BTW,
I think we need more fault type than IOMMU_FAULT_READ and IOMMU_FAULT_WRITE. We have page fault, access fault(read, write), security fault and bus error (translated physical address is not available)

Quoted 2 lines

Thanks,
Ohad.

Thank you.
Cho KyongHo.

#5 lore raw

Hi,

Quoted 5 lines · KyongHo Cho

Every fault in IOMMU (System MMU) is an error logically and must not happen in our multimedia device drivers because, our device drivers always construct page table completely before address translation in System MMU
and TLB loads translation information automatically when TLB miss.

Yeah, this is pretty much the same for OMAP too.

Quoted 2 lines

I am not sure if the default behavior of MMU fault in our IOMMU driver is also correct for other IOMMU drivers.

It seems your default behavior just prints an error message with the details of the fault (addresses, flags, etc..). We can probably have this unified.

In case you want to print exonys-specific info when the fault is not handled by upper layers, we can change report_iommu_fault() to return an error whenever a handler is not installed. This way exynos_sysmmu_irq() can easily tell whether to proceed with the default behavior or not, without installing a fault handler in the driver:

include/linux/iommu.h +1 -1
index 297893f..dc4b282 100644
@@ -103,7 +103,7 @@ extern void iommu_set_fault_handler(struct iommu_domain *dom
 static inline int report_iommu_fault(struct iommu_domain *domain,
                struct device *dev, unsigned long iova, int flags)
 {
-       int ret = 0;
+       int ret = -EFAULT;
 
 
Quoted 4 lines

BTW,
I think we need more fault type than IOMMU_FAULT_READ and IOMMU_FAULT_WRITE. We have page fault, access fault(read, write), security fault and bus error (translated physical address is not available)

Initially we had a argument for the type of the fault, but dropped it because it was not used. Feel free to add it back if you need it.

Thanks,
Ohad.

#6 lore raw
Quoted 16 lines · Ohad Ben-Cohen

It seems your default behavior just prints an error message with the details of the fault (addresses, flags, etc..). We can probably have this unified.

In case you want to print exonys-specific info when the fault is not handled by upper layers, we can change report_iommu_fault() to return an error whenever a handler is not installed. This way exynos_sysmmu_irq() can easily tell whether to proceed with the default behavior or not, without installing a fault handler in the driver:

include/linux/iommu.h +0 -0
index 297893f..dc4b282 100644

include/linux/iommu.h extern void iommu_set_fault_handler(struct iommu_domain *dom · line 107

Quoted 6 lines
include/linux/iommu.h +1 -1
@@ -103,7 +103,7 @@ extern void iommu_set_fault_handler(struct iommu_domain *dom
 ?static inline int report_iommu_fault(struct iommu_domain *domain,
 ? ? ? ? ? ? ? ?struct device *dev, unsigned long iova, int flags)
 ?{
- ? ? ? int ret = 0;
+ ? ? ? int ret = -EFAULT;
 

That looks better for me :)
However, I think the irq handler need to identify if the return value is an error
returned by a fault handler or a notice that no fault handler is installed.

I am sorry but I still think that
installing default fault handler is quite simple and straightforward.

Providing generic default behavior for all architectures is also good if it is available for other architectures.
My intention with the default behavior for unrecoverable fault from IOMMU is to show what the problem is, where the problem caused and
thus, providing a hint to solve or catch the problem
for the device drivers and the developers.

Quoted 8 lines
include/linux/iommu.h +0 -0
 > BTW,
Quoted 3 lines

I think we need more fault type than IOMMU_FAULT_READ and IOMMU_FAULT_WRITE. We have page fault, access fault(read, write), security fault and bus error (translated physical address is not available)

Initially we had a argument for the type of the fault, but dropped it because it was not used. Feel free to add it back if you need it.

OK. thanks.

Quoted 2 lines

Thanks,
Ohad.

Thank you.
Cho KyongHo.

#7 lore raw
Quoted 2 lines · KyongHo Cho

I am sorry but I still think that
installing default fault handler is quite simple and straightforward.

... and abusing the IOMMU API.

Please don't do that. Interfaces are written for specific goals, and this one was added for IOMMU users, not drivers. Just like all the other map/unmap/attach/... APIs.

By using this from the IOMMU driver itself, you are adding burden on future development and evolution of this API. As use cases materialize, we will have to change it to support them, while considering existing use cases. Using this API inappropriately will make our life harder later on.

Moreover, I'm really not sure how exactly are you going to use this.

If you're having an IOMMU user which installs its own fault handler, then this is all moot since the default behavior you provide here will be overridden.
If you're not having an IOMMU user which installs its own fault handler, then just provide the default behavior in your irq handler, regardless whether you report the fault to the IOMMU core or not. Or only when it fails. and yes, we can provide different error values for different scenarios. it's not rocket science :).

Really, there's a myriad of ways to do this right. Please explain your exact settings/use-case and I'll gladly help you find a clean solution.

Thanks,
Ohad.

#8 lore raw
Quoted 10 lines · Ohad Ben-Cohen
Quoted 2 lines · KyongHo Cho

I am sorry but I still think that
installing default fault handler is quite simple and straightforward.

... and abusing the IOMMU API.

Please don't do that. Interfaces are written for specific goals, and this one was added for IOMMU users, not drivers. Just like all the other map/unmap/attach/... APIs.

Quoted 5 lines

By using this from the IOMMU driver itself, you are adding burden on future development and evolution of this API. As use cases materialize, we will have to change it to support them, while considering existing use cases. Using this API inappropriately will make our life harder later on.

I didn't think about this case.
It can be a problem if IOMMU driver is dependent upon the change of IOMMU API as you told above.

Quoted 6 lines

Moreover, I'm really not sure how exactly are you going to use this.

If you're having an IOMMU user which installs its own fault handler, then this is all moot since the default behavior you provide here will be overridden.

Yes, this is what I really want.
I wanted the IOMMU driver to provide default fault handler to its users that does not provide fault handler for debugging purpose. If a user want to handle MMU fault, IOMMU driver welcomes to overwrite the existing 'default' fault handler.

Quoted 10 lines

If you're not having an IOMMU user which installs its own fault handler, then just provide the default behavior in your irq handler, regardless whether you report the fault to the IOMMU core or not. Or only when it fails. and yes, we can provide different error values for different scenarios. it's not rocket science :).

Really, there's a myriad of ways to do this right. Please explain your exact settings/use-case and I'll gladly help you find a clean solution.

Thank you.

As I explained before, MMU fault in our system is abnormal and the situation cannot be recovered because mapping information is set up completely before System MMU starts address translation with the mapping information.
However we have to capture the MMU fault for debugging purpose. That's why our fault handler just prints debugging messages and generates kernel OOPS

A user of IOMMU may handle MMU faults due to the following reason:
- Its IOMMU sees the virtual address space of the user process (IOMMU
refers the page table of CPU)
and virtual memory region allocated by userspace is not filled with
physical memory.
Device driver which is user of IOMMU does not call get_user_pages()
for the region but
handle page fault generated by IOMMU.
- A device driver working in the Monitor mode in ARM processors need
to protect a memory region
from access in the Normal mode. If it happens, the device driver
must catch the situation,
stop the current operation and inform the problem to the userspace.

For the above reasons, some user of IOMMU may override the default fault handler.

Quoted 2 lines

Thanks,
Ohad.

Thanks and regards,
Cho KyongHo.

#9 lore raw
Quoted 4 lines · KyongHo Cho

I wanted the IOMMU driver to provide default fault handler to its users that does not provide fault handler for debugging purpose. If a user want to handle MMU fault, IOMMU driver welcomes to overwrite the existing 'default' fault handler.

Ok, this one patch below should allow you to do that. report_iommu_fault() will now reliably tell you if a fault handler failed or not, or if one isn't even installed.

This way your IOMMU driver doesn't need to define a fault handler of its own, and instead, can do everything directly in exynos_sysmmu_irq() where all the required information is now available.

Thanks,
Ohad.

#10 lore raw
Quoted 17 lines · Ohad Ben-Cohen
include/linux/iommu.h +0 -0
index d084e87..2987199 100644
@@ -98,11 +98,12 @@ extern void iommu_set_fault_handler(struct
 iommu_domain *domain,

?* Returns 0 on success and an appropriate error code otherwise (if dynamic ?* PTE/TLB loading will one day be supported, implementations will be able ?* to tell whether it succeeded or not according to this return value).
+ * If a fault handler isn't installed, -ENOSYS is returned. ?*/
?static inline int report_iommu_fault(struct iommu_domain *domain, ? ? ? ? ? ? ? ?struct device *dev, unsigned long iova, int flags) ?{
- ? ? ? int ret = 0;
+ ? ? ? int ret = -ENOSYS;

Quoted 2 lines

? ? ? ?/*
? ? ? ? * if upper layers showed interest and installed a fault handler,

It looks good for me.

I will prepare new patches with the changed API.

Thank you.
Cho KyongHo.

#11 lore raw
Quoted 3 lines · KyongHo Cho

It looks good for me.

I will prepare new patches with the changed API.

Ok, thanks.

(I've just submitted it to the iommu ML too)

Ohad.