15 #include <linux/device.h>
17 #include <linux/module.h>
18 #include <linux/slab.h>
26 #define IOMMU_ARCH_VERSION 0x00000011
29 #define MMU_SYS_IDLE_SHIFT 3
30 #define MMU_SYS_IDLE_FORCE (0 << MMU_SYS_IDLE_SHIFT)
31 #define MMU_SYS_IDLE_NONE (1 << MMU_SYS_IDLE_SHIFT)
32 #define MMU_SYS_IDLE_SMART (2 << MMU_SYS_IDLE_SHIFT)
33 #define MMU_SYS_IDLE_MASK (3 << MMU_SYS_IDLE_SHIFT)
35 #define MMU_SYS_SOFTRESET (1 << 1)
36 #define MMU_SYS_AUTOIDLE 1
39 #define MMU_SYS_RESETDONE 1
42 #define MMU_IRQ_MULTIHITFAULT (1 << 4)
43 #define MMU_IRQ_TABLEWALKFAULT (1 << 3)
44 #define MMU_IRQ_EMUMISS (1 << 2)
45 #define MMU_IRQ_TRANSLATIONFAULT (1 << 1)
46 #define MMU_IRQ_TLBMISS (1 << 0)
48 #define __MMU_IRQ_FAULT \
49 (MMU_IRQ_MULTIHITFAULT | MMU_IRQ_EMUMISS | MMU_IRQ_TRANSLATIONFAULT)
50 #define MMU_IRQ_MASK \
51 (__MMU_IRQ_FAULT | MMU_IRQ_TABLEWALKFAULT | MMU_IRQ_TLBMISS)
52 #define MMU_IRQ_TWL_MASK (__MMU_IRQ_FAULT | MMU_IRQ_TABLEWALKFAULT)
53 #define MMU_IRQ_TLB_MISS_MASK (__MMU_IRQ_FAULT | MMU_IRQ_TLBMISS)
56 #define MMU_CNTL_SHIFT 1
57 #define MMU_CNTL_MASK (7 << MMU_CNTL_SHIFT)
58 #define MMU_CNTL_EML_TLB (1 << 3)
59 #define MMU_CNTL_TWL_EN (1 << 2)
60 #define MMU_CNTL_MMU_EN (1 << 1)
62 #define get_cam_va_mask(pgsz) \
63 (((pgsz) == MMU_CAM_PGSZ_16M) ? 0xff000000 : \
64 ((pgsz) == MMU_CAM_PGSZ_1M) ? 0xfff00000 : \
65 ((pgsz) == MMU_CAM_PGSZ_64K) ? 0xffff0000 : \
66 ((pgsz) == MMU_CAM_PGSZ_4K) ? 0xfffff000 : 0)
69 static void __iommu_set_twl(
struct omap_iommu *obj,
bool on)
88 static int omap2_iommu_enable(
struct omap_iommu *obj)
110 dev_err(obj->
dev,
"can't take mmu out of reset\n");
116 (l >> 4) & 0xf, l & 0xf);
123 iommu_write_reg(obj, pa,
MMU_TTB);
125 __iommu_set_twl(obj,
true);
130 static void omap2_iommu_disable(
struct omap_iommu *obj)
141 static void omap2_iommu_set_twl(
struct omap_iommu *obj,
bool on)
143 __iommu_set_twl(obj,
false);
202 dev_err(obj->
dev,
"%s:\twrong alignment: %08x\n", __func__,
217 static inline int omap2_cr_valid(
struct cr_regs *cr)
226 attr = e->
mixed << 5;
228 attr |= e->
elsz >> 3;
246 #define pr_reg(name) \
249 const char *str = "%20s: %08x\n"; \
250 const int maxcol = 32; \
251 bytes = snprintf(p, maxcol, str, __stringify(name), \
252 iommu_read_reg(obj, MMU_##name)); \
286 static void omap2_iommu_save_ctx(
struct omap_iommu *obj)
292 p[
i] = iommu_read_reg(obj, i *
sizeof(
u32));
293 dev_dbg(obj->
dev,
"%s\t[%02d] %08x\n", __func__, i, p[i]);
299 static void omap2_iommu_restore_ctx(
struct omap_iommu *obj)
305 iommu_write_reg(obj, p[i], i *
sizeof(
u32));
306 dev_dbg(obj->
dev,
"%s\t[%02d] %08x\n", __func__, i, p[i]);
326 .enable = omap2_iommu_enable,
327 .disable = omap2_iommu_disable,
328 .set_twl = omap2_iommu_set_twl,
329 .fault_isr = omap2_iommu_fault_isr,
331 .tlb_read_cr = omap2_tlb_read_cr,
332 .tlb_load_cr = omap2_tlb_load_cr,
334 .cr_to_e = omap2_cr_to_e,
335 .cr_to_virt = omap2_cr_to_virt,
336 .alloc_cr = omap2_alloc_cr,
337 .cr_valid = omap2_cr_valid,
338 .dump_cr = omap2_dump_cr,
340 .get_pte_attr = omap2_get_pte_attr,
342 .save_ctx = omap2_iommu_save_ctx,
343 .restore_ctx = omap2_iommu_restore_ctx,
344 .dump_ctx = omap2_iommu_dump_ctx,
347 static int __init omap2_iommu_init(
void)
353 static void __exit omap2_iommu_exit(
void)
359 MODULE_AUTHOR(
"Hiroshi DOYU, Paul Mundt and Toshihiro Kobayashi");