OMAP: IOMMU fault callback support
Subsystems (3)
v2 cover OMAP: IOMMU fault callback support
Hi,
v2:
Previous patch 1/2 on v1 was dropped.
---
v1:
This patch set adds fault callback support to allow IOMMU users to debug or react when a fault happens.
IOMMU faults might be very difficult to reproduce and then to figure out the source of the problem. Currently IOMMU driver prints not so useful debug message and does not notice user about such issue.
With a fault callback, IOMMU user may debug much more useful information and/or react to go back to a valid state.
Br,
David
---
David Cohen (1):
OMAP: IOMMU: add support to callback during fault handling
arch/arm/mach-omap2/iommu2.c | 21 +++++++++++++-- arch/arm/plat-omap/include/plat/iommu.h | 15 ++++++++++- arch/arm/plat-omap/iommu.c | 41 ++++++++++++++++++++++++++++--- 3 files changed, 69 insertions(+), 8 deletions(-)
Signature · 1 line
1.7.2.3
PATCH v2 1/1 OMAP: IOMMU: add support to callback during fault handling
Add support to register a callback for IOMMU fault situations. Drivers using IOMMU module might want to be informed when such errors happen in order to debug it or react.
--- arch/arm/mach-omap2/iommu2.c | 21 +++++++++++++-- arch/arm/plat-omap/include/plat/iommu.h | 15 ++++++++++- arch/arm/plat-omap/iommu.c | 41 ++++++++++++++++++++++++++++--- 3 files changed, 69 insertions(+), 8 deletions(-)
arch/arm/mach-omap2/iommu2.c +18 -3
@@ -143,10 +143,10 @@ static void omap2_iommu_set_twl(struct iommu *obj, bool on)__iommu_set_twl (obj, false); } -static u32 omap2_iommu_fault_isr (struct iommu *obj,u32 *ra) +static u32 omap2_iommu_fault_isr (struct iommu *obj,u32 *ra,u32 *iommu_errs) {int i; -u32 stat, da; +u32 stat, da, errs;const char *err_msg[] = {"tlb miss" ,"translation fault" ,
@@ -157,8 +157,10 @@ static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra) stat =iommu_read_reg (obj,MMU_IRQSTATUS ); stat &=MMU_IRQ_MASK ; -if (!stat) +if (!stat) { + *iommu_errs =0 ;return 0 ; + } da =iommu_read_reg (obj,MMU_FAULT_AD ); *ra = da;
@@ -171,6 +173,19 @@ static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra) }printk ("\n" ); + errs =0 ; +if (stat &MMU_IRQ_TLBMISS ) + errs |=OMAP_IOMMU_ERR_TLB_MISS ; +if (stat &MMU_IRQ_TRANSLATIONFAULT ) + errs |=OMAP_IOMMU_ERR_TRANS_FAULT ; +if (stat &MMU_IRQ_EMUMISS ) + errs |=OMAP_IOMMU_ERR_EMU_MISS ; +if (stat &MMU_IRQ_TABLEWALKFAULT ) + errs |=OMAP_IOMMU_ERR_TBLWALK_FAULT ; +if (stat &MMU_IRQ_MULTIHITFAULT ) + errs |=OMAP_IOMMU_ERR_MULTIHIT_FAULT ; + *iommu_errs = errs; +iommu_write_reg (obj, stat,MMU_IRQSTATUS );return stat;
arch/arm/plat-omap/include/plat/iommu.h +14 -1
@@ -31,6 +31,7 @@ struct iommu {struct clk *clk;void __iomem *regbase;struct device *dev; +void *fault_cb_priv;unsigned int refcount;struct mutex iommu_lock;/* global for this whole object */
@@ -48,6 +49,7 @@ struct iommu {struct mutex mmap_lock;/* protect mmap */ int (*isr)(struct iommu *obj); +void (*fault_cb)(struct iommu *obj,u32 da,u32 iommu_errs,void *priv);void *ctx;/* iommu context: registres saved area */ u32 da_start;
@@ -83,7 +85,7 @@ struct iommu_functions {int (*enable)(struct iommu *obj);void (*disable)(struct iommu *obj);void (*set_twl)(struct iommu *obj,bool on); -u32 (*fault_isr)(struct iommu *obj,u32 *ra); +u32 (*fault_isr)(struct iommu *obj,u32 *ra,u32 *iommu_errs);void (*tlb_read_cr)(struct iommu *obj,struct cr_regs *cr);void (*tlb_load_cr)(struct iommu *obj,struct cr_regs *cr);
@@ -109,6 +111,13 @@ struct iommu_platform_data {u32 da_end; }; +/* IOMMU errors */ +#define OMAP_IOMMU_ERR_TLB_MISS (1 << 0) +#define OMAP_IOMMU_ERR_TRANS_FAULT (1 << 1) +#define OMAP_IOMMU_ERR_EMU_MISS (1 << 2) +#define OMAP_IOMMU_ERR_TBLWALK_FAULT (1 << 3) +#define OMAP_IOMMU_ERR_MULTIHIT_FAULT (1 << 4) +#if defined(CONFIG_ARCH_OMAP1 )#error "iommu for this processor not implemented yet"#else
@@ -161,6 +170,10 @@ extern size_t iopgtable_clear_entry(struct iommu *obj, u32 iova);extern int iommu_set_da_range (struct iommu *obj,u32 start,u32 end);extern struct iommu *iommu_get (const char *name);extern void iommu_put (struct iommu *obj); +extern int iommu_set_fault_callback (const char *name, +void (*fault_cb)(struct iommu *obj,u32 da, +u32 errs,void *priv), +void *fault_cb_priv);extern void iommu_save_ctx (struct iommu *obj);extern void iommu_restore_ctx (struct iommu *obj);
arch/arm/plat-omap/iommu.c +37 -4
72 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH v2 1/1 OMAP: IOMMU: add support to callback during fault handling
Hi David,
Sorry for a bit late reply....
From: David Cohen <[email protected]>
Subject: [PATCH v2 1/1] OMAP: IOMMU: add support to callback during fault handling
Date: Tue, 15 Feb 2011 16:36:31 +0200
Quoted 73 lines
Add support to register a callback for IOMMU fault situations. Drivers using IOMMU module might want to be informed when such errors happen in order to debug it or react.
Signed-off-by David Cohen <[email protected]>--- arch/arm/mach-omap2/iommu2.c | 21 +++++++++++++-- arch/arm/plat-omap/include/plat/iommu.h | 15 ++++++++++- arch/arm/plat-omap/iommu.c | 41 ++++++++++++++++++++++++++++--- 3 files changed, 69 insertions(+), 8 deletions(-)arch/arm/mach-omap2/iommu2.c +18
-3@@ -143,10 +143,10 @@ static void omap2_iommu_set_twl(struct iommu *obj, bool on)__iommu_set_twl (obj, false); } -static u32 omap2_iommu_fault_isr (struct iommu *obj,u32 *ra) +static u32 omap2_iommu_fault_isr (struct iommu *obj,u32 *ra,u32 *iommu_errs) {int i; -u32 stat, da; +u32 stat, da, errs;const char *err_msg[] = {"tlb miss" ,"translation fault" ,@@ -157,8 +157,10 @@ static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra) stat =iommu_read_reg (obj,MMU_IRQSTATUS ); stat &=MMU_IRQ_MASK ; -if (!stat) +if (!stat) { + *iommu_errs =0 ;return 0 ; + } da =iommu_read_reg (obj,MMU_FAULT_AD ); *ra = da;@@ -171,6 +173,19 @@ static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra) }printk ("\n" ); + errs =0 ; +if (stat &MMU_IRQ_TLBMISS ) + errs |=OMAP_IOMMU_ERR_TLB_MISS ; +if (stat &MMU_IRQ_TRANSLATIONFAULT ) + errs |=OMAP_IOMMU_ERR_TRANS_FAULT ; +if (stat &MMU_IRQ_EMUMISS ) + errs |=OMAP_IOMMU_ERR_EMU_MISS ; +if (stat &MMU_IRQ_TABLEWALKFAULT ) + errs |=OMAP_IOMMU_ERR_TBLWALK_FAULT ; +if (stat &MMU_IRQ_MULTIHITFAULT ) + errs |=OMAP_IOMMU_ERR_MULTIHIT_FAULT ; + *iommu_errs = errs; +iommu_write_reg (obj, stat,MMU_IRQSTATUS );return stat;arch/arm/plat-omap/include/plat/iommu.h +1
-0@@ -31,6 +31,7 @@ struct iommu {struct clk *clk;void __iomem *regbase;struct device *dev; +void *fault_cb_priv;unsigned int refcount;struct mutex iommu_lock;/* global for this whole object */
arch/arm/plat-omap/include/plat/iommu.h struct iommu { · line 52
Quoted 4 lines
arch/arm/plat-omap/include/plat/iommu.h +1
-0@@ -48,6 +49,7 @@ struct iommu {struct mutex mmap_lock;/* protect mmap */ int (*isr)(struct iommu *obj); +void (*fault_cb)(struct iommu *obj,u32 da,u32 iommu_errs,void *priv);
What about making use of (*isr)() for fault call back as well?
Basic concept is that, client can decide how to deal with iommu fault. For example, for advanced case, client wants daynamic loading of TLB(or PTE), or for ISP case, clients just want more appropriate fault reporting. This (*isr)() could be used in such flexibility.
785 * Device IOMMU generic operations
786 */
787 static irqreturn_t iommu_fault_handler(int irq, void *data)
788 {
789 u32 stat, da;
790 u32 *iopgd, *iopte;
791 int err = -EIO;
792 struct iommu *obj = data;
793
794 if (!obj->refcount)
795 return IRQ_NONE;
796
797 /* Dynamic loading TLB or PTE */
798 if (obj->isr)
799 err = obj->isr(obj);
800
801 if (!err)
802 return IRQ_HANDLED;
803
804 clk_enable(obj->clk);
805 stat = iommu_report_fault(obj, &da);
806 clk_disable(obj->clk);
807 if (!stat)
808 return IRQ_HANDLED;
809
810 iommu_disable(obj);I guess that this modifying the above code could make (*isr)() flexible to be used for any purpose for clients? For me, having both following may be a bit residual.
Quoted 2 lines
arch/arm/plat-omap/include/plat/iommu.h +1
-0int (*isr)(struct iommu *obj); +void (*fault_cb)(struct iommu *obj,u32 da,u32 iommu_errs,void *priv);
PATCH v2 1/1 OMAP: IOMMU: add support to callback during fault handling
Quoted 1 line · Hiroshi DOYU
Hi David,
Hi Hiroshi,
Quoted 2 lines
Sorry for a bit late reply....
You're just in time. :)
Quoted 85 lines
From: David Cohen <[email protected]>
Subject: [PATCH v2 1/1] OMAP: IOMMU: add support to callback during fault handling
Date: Tue, 15 Feb 2011 16:36:31 +0200Quoted 75 lines
Add support to register a callback for IOMMU fault situations. Drivers using IOMMU module might want to be informed when such errors happen in order to debug it or react.
Signed-off-by David Cohen <[email protected]>---
?arch/arm/mach-omap2/iommu2.c ? ? ? ? ? ?| ? 21 +++++++++++++-- ?arch/arm/plat-omap/include/plat/iommu.h | ? 15 ++++++++++- ?arch/arm/plat-omap/iommu.c ? ? ? ? ? ? ?| ? 41 ++++++++++++++++++++++++++++---?3 files changed, 69 insertions(+), 8 deletions(-)
arch/arm/mach-omap2/iommu2.c +18
-3@@ -143,10 +143,10 @@ static void omap2_iommu_set_twl(struct iommu *obj, bool on) ? ? ? __iommu_set_twl(obj, false); ?} -static u32 omap2_iommu_fault_isr (struct iommu *obj,u32 *ra) +static u32 omap2_iommu_fault_isr (struct iommu *obj,u32 *ra,u32 *iommu_errs) ?{ ? ? ? int i; - ? ? u32 stat, da; + ? ? u32 stat, da, errs; ? ? ? const char *err_msg[] = { ? ? ? ? ? ? ? "tlb miss", ? ? ? ? ? ? ? "translation fault",@@ -157,8 +157,10 @@ static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra) ? ? ? stat = iommu_read_reg(obj, MMU_IRQSTATUS); ? ? ? stat &= MMU_IRQ_MASK; - ? ? if (!stat) + ? ? if (!stat) { + ? ? ? ? ? ? *iommu_errs = 0; ? ? ? ? ? ? ? return 0; + ? ? } ? ? ? da = iommu_read_reg(obj, MMU_FAULT_AD); ? ? ? *ra = da;@@ -171,6 +173,19 @@ static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra) ? ? ? } ? ? ? printk("\n"); + ? ? errs = 0; + ? ? if (stat & MMU_IRQ_TLBMISS) + ? ? ? ? ? ? errs |= OMAP_IOMMU_ERR_TLB_MISS; + ? ? if (stat & MMU_IRQ_TRANSLATIONFAULT) + ? ? ? ? ? ? errs |= OMAP_IOMMU_ERR_TRANS_FAULT; + ? ? if (stat & MMU_IRQ_EMUMISS) + ? ? ? ? ? ? errs |= OMAP_IOMMU_ERR_EMU_MISS; + ? ? if (stat & MMU_IRQ_TABLEWALKFAULT) + ? ? ? ? ? ? errs |= OMAP_IOMMU_ERR_TBLWALK_FAULT; + ? ? if (stat & MMU_IRQ_MULTIHITFAULT) + ? ? ? ? ? ? errs |= OMAP_IOMMU_ERR_MULTIHIT_FAULT; + ? ? *iommu_errs = errs; + ? ? ? iommu_write_reg(obj, stat, MMU_IRQSTATUS); ? ? ? return stat;arch/arm/plat-omap/include/plat/iommu.h +1
-0@@ -31,6 +31,7 @@ struct iommu { ? ? ? struct clk ? ? ?*clk; ? ? ? void __iomem ? ?*regbase; ? ? ? struct device ? *dev; + ? ? void ? ? ? ? ? ?*fault_cb_priv; ? ? ? unsigned int ? ?refcount;? ? ? struct mutex ? ?iommu_lock; ? ? /* global for this whole object */
arch/arm/plat-omap/include/plat/iommu.h +0
-0@@ -48,6 +49,7 @@ struct iommu {? ? ? struct mutex ? ? ? ? ? ?mmap_lock; /* protect mmap */
Quoted 2 lines
? ? ? int (*isr)(struct iommu *obj);
+ ? ? void (*fault_cb)(struct iommu *obj, u32 da, u32iommu_errs, void *priv);What about making use of (*isr)() for fault call back as well?
Quoted 4 lines
Basic concept is that, client can decide how to deal with iommu fault. For example, for advanced case, client wants daynamic loading of TLB(or PTE), or for ISP case, clients just want more appropriate fault reporting. This (*isr)() could be used in such flexibility.
In this case, it seems we can re-use it.
Quoted 28 lines
? 785 ? * ? ? ?Device IOMMU generic operations
? 786 ? */
? 787 ?staticirqreturn_tiommu_fault_handler(int irq, void *data)? 788 ?{
? 789 ? ? ? ? ?u32 stat, da;
? 790 ? ? ? ? ?u32 *iopgd, *iopte;
? 791 ? ? ? ? ?int err =-EIO;
? 792 ? ? ? ? ?struct iommu *obj = data;
? 793
? 794 ? ? ? ? ?if (!obj->refcount)
? 795 ? ? ? ? ? ? ? ? ?returnIRQ_NONE;
? 796
? 797 ? ? ? ? ?/* Dynamic loading TLB or PTE */
? 798 ? ? ? ? ?if (obj->isr)
? 799 ? ? ? ? ? ? ? ? ?err =obj->isr(obj);
? 800
? 801 ? ? ? ? ?if (!err)
? 802 ? ? ? ? ? ? ? ? ?returnIRQ_HANDLED;
? 803
? 804 ? ? ? ? ?clk_enable(obj->clk);
? 805 ? ? ? ? ?stat =iommu_report_fault(obj, &da);
? 806 ? ? ? ? ?clk_disable(obj->clk);
? 807 ? ? ? ? ?if (!stat)
? 808 ? ? ? ? ? ? ? ? ?returnIRQ_HANDLED;
? 809
? 810 ? ? ? ? ?iommu_disable(obj);
Quoted 3 lines
I guess that this modifying the above code could make (*isr)() flexible to be used for any purpose for clients? For me, having both following may be a bit residual.
I agree. We need to add 'void *isr_priv' to iommu struct and the function to register isr.
I'll send a v3 soon.
Regards,
David
Quoted 4 lines
Quoted 3 lines
? ? ? int (*isr)(struct iommu *obj);
+ ? ? void (*fault_cb)(struct iommu *obj, u32 da, u32iommu_errs, void *priv);
PATCH v2 1/1 OMAP: IOMMU: add support to callback during fault handling
Quoted 95 lines · David Cohen
Quoted 1 line · Hiroshi DOYU
Hi David,
Hi Hiroshi,
Quoted 2 lines
Sorry for a bit late reply....
You're just in time. :)
Quoted 85 lines
From: David Cohen <[email protected]>
Subject: [PATCH v2 1/1] OMAP: IOMMU: add support to callback during fault handling
Date: Tue, 15 Feb 2011 16:36:31 +0200Quoted 75 lines
Add support to register a callback for IOMMU fault situations. Drivers using IOMMU module might want to be informed when such errors happen in order to debug it or react.
Signed-off-by David Cohen <[email protected]>---
?arch/arm/mach-omap2/iommu2.c ? ? ? ? ? ?| ? 21 +++++++++++++-- ?arch/arm/plat-omap/include/plat/iommu.h | ? 15 ++++++++++- ?arch/arm/plat-omap/iommu.c ? ? ? ? ? ? ?| ? 41 ++++++++++++++++++++++++++++---?3 files changed, 69 insertions(+), 8 deletions(-)
arch/arm/mach-omap2/iommu2.c +18
-3@@ -143,10 +143,10 @@ static void omap2_iommu_set_twl(struct iommu *obj, bool on) ? ? ? __iommu_set_twl(obj, false); ?} -static u32 omap2_iommu_fault_isr (struct iommu *obj,u32 *ra) +static u32 omap2_iommu_fault_isr (struct iommu *obj,u32 *ra,u32 *iommu_errs) ?{ ? ? ? int i; - ? ? u32 stat, da; + ? ? u32 stat, da, errs; ? ? ? const char *err_msg[] = { ? ? ? ? ? ? ? "tlb miss", ? ? ? ? ? ? ? "translation fault",@@ -157,8 +157,10 @@ static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra) ? ? ? stat = iommu_read_reg(obj, MMU_IRQSTATUS); ? ? ? stat &= MMU_IRQ_MASK; - ? ? if (!stat) + ? ? if (!stat) { + ? ? ? ? ? ? *iommu_errs = 0; ? ? ? ? ? ? ? return 0; + ? ? } ? ? ? da = iommu_read_reg(obj, MMU_FAULT_AD); ? ? ? *ra = da;@@ -171,6 +173,19 @@ static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra) ? ? ? } ? ? ? printk("\n"); + ? ? errs = 0; + ? ? if (stat & MMU_IRQ_TLBMISS) + ? ? ? ? ? ? errs |= OMAP_IOMMU_ERR_TLB_MISS; + ? ? if (stat & MMU_IRQ_TRANSLATIONFAULT) + ? ? ? ? ? ? errs |= OMAP_IOMMU_ERR_TRANS_FAULT; + ? ? if (stat & MMU_IRQ_EMUMISS) + ? ? ? ? ? ? errs |= OMAP_IOMMU_ERR_EMU_MISS; + ? ? if (stat & MMU_IRQ_TABLEWALKFAULT) + ? ? ? ? ? ? errs |= OMAP_IOMMU_ERR_TBLWALK_FAULT; + ? ? if (stat & MMU_IRQ_MULTIHITFAULT) + ? ? ? ? ? ? errs |= OMAP_IOMMU_ERR_MULTIHIT_FAULT; + ? ? *iommu_errs = errs; + ? ? ? iommu_write_reg(obj, stat, MMU_IRQSTATUS); ? ? ? return stat;arch/arm/plat-omap/include/plat/iommu.h +1
-0@@ -31,6 +31,7 @@ struct iommu { ? ? ? struct clk ? ? ?*clk; ? ? ? void __iomem ? ?*regbase; ? ? ? struct device ? *dev; + ? ? void ? ? ? ? ? ?*fault_cb_priv; ? ? ? unsigned int ? ?refcount;? ? ? struct mutex ? ?iommu_lock; ? ? /* global for this whole object */
arch/arm/plat-omap/include/plat/iommu.h +0
-0@@ -48,6 +49,7 @@ struct iommu {? ? ? struct mutex ? ? ? ? ? ?mmap_lock; /* protect mmap */
Quoted 2 lines
? ? ? int (*isr)(struct iommu *obj);
+ ? ? void (*fault_cb)(struct iommu *obj, u32 da, u32iommu_errs, void *priv);What about making use of (*isr)() for fault call back as well?
Quoted 39 lines
Quoted 4 lines
Basic concept is that, client can decide how to deal with iommu fault. For example, for advanced case, client wants daynamic loading of TLB(or PTE), or for ISP case, clients just want more appropriate fault reporting. This (*isr)() could be used in such flexibility.
In this case, it seems we can re-use it.
Quoted 31 lines
? 785 ? * ? ? ?Device IOMMU generic operations
? 786 ? */
? 787 ?staticirqreturn_tiommu_fault_handler(int irq, void *data)? 788 ?{
? 789 ? ? ? ? ?u32 stat, da;
? 790 ? ? ? ? ?u32 *iopgd, *iopte;
? 791 ? ? ? ? ?int err =-EIO;
? 792 ? ? ? ? ?struct iommu *obj = data;
? 793
? 794 ? ? ? ? ?if (!obj->refcount)
? 795 ? ? ? ? ? ? ? ? ?returnIRQ_NONE;
? 796
? 797 ? ? ? ? ?/* Dynamic loading TLB or PTE */
? 798 ? ? ? ? ?if (obj->isr)
? 799 ? ? ? ? ? ? ? ? ?err =obj->isr(obj);
? 800
? 801 ? ? ? ? ?if (!err)
? 802 ? ? ? ? ? ? ? ? ?returnIRQ_HANDLED;
? 803
? 804 ? ? ? ? ?clk_enable(obj->clk);
? 805 ? ? ? ? ?stat =iommu_report_fault(obj, &da);
? 806 ? ? ? ? ?clk_disable(obj->clk);
? 807 ? ? ? ? ?if (!stat)
? 808 ? ? ? ? ? ? ? ? ?returnIRQ_HANDLED;
? 809
? 810 ? ? ? ? ?iommu_disable(obj);I guess that this modifying the above code could make (*isr)() flexible to be used for any purpose for clients? For me, having both following may be a bit residual.
There are few possible issues in this case. (*isr)() is meant to replace the generic fault handler on iommu, but the fault callback isn't. Basically fault callback needs to call specific iommu fault report to know faulty 'da' and iommu errors, so part of the generic fault handler must be called.
One possible solution is always call specific fault report before (*isr)(). IMO it makes sense as (*isr)() might want to know at least the current faults.
But in this case, specific fault report should not print anything else as only the upper layer and user will know when a fault is actually an error or not. So, they're responsible for error messages.
I'm sending a v3 with these changes. Comments will be welcome.
Br,
David
Quoted 13 lines
I agree. We need to add 'void
*isr_priv' to iommu struct and the function to register isr.
I'll send a v3 soon.Regards,
David
Quoted 4 lines
Quoted 3 lines
? ? ? int (*isr)(struct iommu *obj);
+ ? ? void (*fault_cb)(struct iommu *obj, u32 da, u32iommu_errs, void *priv);