提交 d093fc7e 编写于 作者: M Marek Szyprowski 提交者: Joerg Roedel

iommu/exynos: Refactor fault handling code

This patch provides a new implementation for page fault handing code. The
new implementation is ready for future extensions. No functional changes
have been made.
Signed-off-by: NMarek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: NJoerg Roedel <jroedel@suse.de>
上级 02cdc365
...@@ -148,40 +148,25 @@ static sysmmu_pte_t *page_entry(sysmmu_pte_t *sent, sysmmu_iova_t iova) ...@@ -148,40 +148,25 @@ static sysmmu_pte_t *page_entry(sysmmu_pte_t *sent, sysmmu_iova_t iova)
lv2table_base(sent)) + lv2ent_offset(iova); lv2table_base(sent)) + lv2ent_offset(iova);
} }
enum exynos_sysmmu_inttype { /*
SYSMMU_PAGEFAULT, * IOMMU fault information register
SYSMMU_AR_MULTIHIT, */
SYSMMU_AW_MULTIHIT, struct sysmmu_fault_info {
SYSMMU_BUSERROR, unsigned int bit; /* bit number in STATUS register */
SYSMMU_AR_SECURITY, unsigned short addr_reg; /* register to read VA fault address */
SYSMMU_AR_ACCESS, const char *name; /* human readable fault name */
SYSMMU_AW_SECURITY, unsigned int type; /* fault type for report_iommu_fault */
SYSMMU_AW_PROTECTION, /* 7 */
SYSMMU_FAULT_UNKNOWN,
SYSMMU_FAULTS_NUM
};
static unsigned short fault_reg_offset[SYSMMU_FAULTS_NUM] = {
REG_PAGE_FAULT_ADDR,
REG_AR_FAULT_ADDR,
REG_AW_FAULT_ADDR,
REG_DEFAULT_SLAVE_ADDR,
REG_AR_FAULT_ADDR,
REG_AR_FAULT_ADDR,
REG_AW_FAULT_ADDR,
REG_AW_FAULT_ADDR
}; };
static char *sysmmu_fault_name[SYSMMU_FAULTS_NUM] = { static const struct sysmmu_fault_info sysmmu_faults[] = {
"PAGE FAULT", { 0, REG_PAGE_FAULT_ADDR, "PAGE", IOMMU_FAULT_READ },
"AR MULTI-HIT FAULT", { 1, REG_AR_FAULT_ADDR, "AR MULTI-HIT", IOMMU_FAULT_READ },
"AW MULTI-HIT FAULT", { 2, REG_AW_FAULT_ADDR, "AW MULTI-HIT", IOMMU_FAULT_WRITE },
"BUS ERROR", { 3, REG_DEFAULT_SLAVE_ADDR, "BUS ERROR", IOMMU_FAULT_READ },
"AR SECURITY PROTECTION FAULT", { 4, REG_AR_FAULT_ADDR, "AR SECURITY PROTECTION", IOMMU_FAULT_READ },
"AR ACCESS PROTECTION FAULT", { 5, REG_AR_FAULT_ADDR, "AR ACCESS PROTECTION", IOMMU_FAULT_READ },
"AW SECURITY PROTECTION FAULT", { 6, REG_AW_FAULT_ADDR, "AW SECURITY PROTECTION", IOMMU_FAULT_WRITE },
"AW ACCESS PROTECTION FAULT", { 7, REG_AW_FAULT_ADDR, "AW ACCESS PROTECTION", IOMMU_FAULT_WRITE },
"UNKNOWN FAULT"
}; };
/* /*
...@@ -299,24 +284,19 @@ static void __sysmmu_set_ptbase(struct sysmmu_drvdata *data, phys_addr_t pgd) ...@@ -299,24 +284,19 @@ static void __sysmmu_set_ptbase(struct sysmmu_drvdata *data, phys_addr_t pgd)
__sysmmu_tlb_invalidate(data); __sysmmu_tlb_invalidate(data);
} }
static void show_fault_information(const char *name, static void show_fault_information(struct sysmmu_drvdata *data,
enum exynos_sysmmu_inttype itype, const struct sysmmu_fault_info *finfo,
phys_addr_t pgtable_base, sysmmu_iova_t fault_addr) sysmmu_iova_t fault_addr)
{ {
sysmmu_pte_t *ent; sysmmu_pte_t *ent;
if ((itype >= SYSMMU_FAULTS_NUM) || (itype < SYSMMU_PAGEFAULT)) dev_err(data->sysmmu, "%s FAULT occurred at %#x (page table base: %pa)\n",
itype = SYSMMU_FAULT_UNKNOWN; finfo->name, fault_addr, &data->pgtable);
ent = section_entry(phys_to_virt(data->pgtable), fault_addr);
pr_err("%s occurred at %#x by %s(Page table base: %pa)\n", dev_err(data->sysmmu, "\tLv1 entry: %#x\n", *ent);
sysmmu_fault_name[itype], fault_addr, name, &pgtable_base);
ent = section_entry(phys_to_virt(pgtable_base), fault_addr);
pr_err("\tLv1 entry: %#x\n", *ent);
if (lv1ent_page(ent)) { if (lv1ent_page(ent)) {
ent = page_entry(ent, fault_addr); ent = page_entry(ent, fault_addr);
pr_err("\t Lv2 entry: %#x\n", *ent); dev_err(data->sysmmu, "\t Lv2 entry: %#x\n", *ent);
} }
} }
...@@ -324,8 +304,10 @@ static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id) ...@@ -324,8 +304,10 @@ static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id)
{ {
/* SYSMMU is in blocked state when interrupt occurred. */ /* SYSMMU is in blocked state when interrupt occurred. */
struct sysmmu_drvdata *data = dev_id; struct sysmmu_drvdata *data = dev_id;
enum exynos_sysmmu_inttype itype; const struct sysmmu_fault_info *finfo = sysmmu_faults;
sysmmu_iova_t addr = -1; int i, n = ARRAY_SIZE(sysmmu_faults);
unsigned int itype;
sysmmu_iova_t fault_addr = -1;
int ret = -ENOSYS; int ret = -ENOSYS;
WARN_ON(!is_sysmmu_active(data)); WARN_ON(!is_sysmmu_active(data));
...@@ -334,29 +316,20 @@ static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id) ...@@ -334,29 +316,20 @@ static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id)
clk_enable(data->clk_master); clk_enable(data->clk_master);
itype = (enum exynos_sysmmu_inttype) itype = __ffs(__raw_readl(data->sfrbase + REG_INT_STATUS));
__ffs(__raw_readl(data->sfrbase + REG_INT_STATUS)); for (i = 0; i < n; i++, finfo++)
if (WARN_ON(!((itype >= 0) && (itype < SYSMMU_FAULT_UNKNOWN)))) if (finfo->bit == itype)
itype = SYSMMU_FAULT_UNKNOWN; break;
else /* unknown/unsupported fault */
addr = __raw_readl(data->sfrbase + fault_reg_offset[itype]); BUG_ON(i == n);
if (itype == SYSMMU_FAULT_UNKNOWN) { /* print debug message */
pr_err("%s: Fault is not occurred by System MMU '%s'!\n", fault_addr = __raw_readl(data->sfrbase + finfo->addr_reg);
__func__, dev_name(data->sysmmu)); show_fault_information(data, finfo, fault_addr);
pr_err("%s: Please check if IRQ is correctly configured.\n",
__func__);
BUG();
} else {
unsigned int base =
__raw_readl(data->sfrbase + REG_PT_BASE_ADDR);
show_fault_information(dev_name(data->sysmmu),
itype, base, addr);
if (data->domain)
ret = report_iommu_fault(&data->domain->domain,
data->master, addr, itype);
}
if (data->domain)
ret = report_iommu_fault(&data->domain->domain,
data->master, fault_addr, finfo->type);
/* fault is not recovered by fault handler */ /* fault is not recovered by fault handler */
BUG_ON(ret != 0); BUG_ON(ret != 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册