1 /* linux/arch/arm/plat-s5p/sysmmu.c
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include <linux/interrupt.h>
13 #include <linux/platform_device.h>
15 #include <asm/pgtable.h>
18 #include <mach/regs-sysmmu.h>
19 #include <plat/sysmmu.h>
21 #define CTRL_ENABLE 0x5
22 #define CTRL_BLOCK 0x7
23 #define CTRL_DISABLE 0x0
25 static struct device
*dev
;
27 static unsigned short fault_reg_offset
[SYSMMU_FAULTS_NUM
] = {
31 S5P_DEFAULT_SLAVE_ADDR
,
38 static char *sysmmu_fault_name
[SYSMMU_FAULTS_NUM
] = {
43 "AR SECURITY PROTECTION FAULT",
44 "AR ACCESS PROTECTION FAULT",
45 "AW SECURITY PROTECTION FAULT",
46 "AW ACCESS PROTECTION FAULT"
49 static int (*fault_handlers
[S5P_SYSMMU_TOTAL_IPNUM
])(
50 enum S5P_SYSMMU_INTERRUPT_TYPE itype
,
51 unsigned long pgtable_base
,
52 unsigned long fault_addr
);
55 * If adjacent 2 bits are true, the system MMU is enabled.
56 * The system MMU is disabled, otherwise.
58 static unsigned long sysmmu_states
;
60 static inline void set_sysmmu_active(sysmmu_ips ips
)
62 sysmmu_states
|= 3 << (ips
* 2);
65 static inline void set_sysmmu_inactive(sysmmu_ips ips
)
67 sysmmu_states
&= ~(3 << (ips
* 2));
70 static inline int is_sysmmu_active(sysmmu_ips ips
)
72 return sysmmu_states
& (3 << (ips
* 2));
75 static void __iomem
*sysmmusfrs
[S5P_SYSMMU_TOTAL_IPNUM
];
77 static inline void sysmmu_block(sysmmu_ips ips
)
79 __raw_writel(CTRL_BLOCK
, sysmmusfrs
[ips
] + S5P_MMU_CTRL
);
80 dev_dbg(dev
, "%s is blocked.\n", sysmmu_ips_name
[ips
]);
83 static inline void sysmmu_unblock(sysmmu_ips ips
)
85 __raw_writel(CTRL_ENABLE
, sysmmusfrs
[ips
] + S5P_MMU_CTRL
);
86 dev_dbg(dev
, "%s is unblocked.\n", sysmmu_ips_name
[ips
]);
89 static inline void __sysmmu_tlb_invalidate(sysmmu_ips ips
)
91 __raw_writel(0x1, sysmmusfrs
[ips
] + S5P_MMU_FLUSH
);
92 dev_dbg(dev
, "TLB of %s is invalidated.\n", sysmmu_ips_name
[ips
]);
95 static inline void __sysmmu_set_ptbase(sysmmu_ips ips
, unsigned long pgd
)
97 if (unlikely(pgd
== 0)) {
98 pgd
= (unsigned long)ZERO_PAGE(0);
99 __raw_writel(0x20, sysmmusfrs
[ips
] + S5P_MMU_CFG
); /* 4KB LV1 */
101 __raw_writel(0x0, sysmmusfrs
[ips
] + S5P_MMU_CFG
); /* 16KB LV1 */
104 __raw_writel(pgd
, sysmmusfrs
[ips
] + S5P_PT_BASE_ADDR
);
106 dev_dbg(dev
, "Page table base of %s is initialized with 0x%08lX.\n",
107 sysmmu_ips_name
[ips
], pgd
);
108 __sysmmu_tlb_invalidate(ips
);
111 void sysmmu_set_fault_handler(sysmmu_ips ips
,
112 int (*handler
)(enum S5P_SYSMMU_INTERRUPT_TYPE itype
,
113 unsigned long pgtable_base
,
114 unsigned long fault_addr
))
116 BUG_ON(!((ips
>= SYSMMU_MDMA
) && (ips
< S5P_SYSMMU_TOTAL_IPNUM
)));
117 fault_handlers
[ips
] = handler
;
120 static irqreturn_t
s5p_sysmmu_irq(int irq
, void *dev_id
)
122 /* SYSMMU is in blocked when interrupt occurred. */
123 unsigned long base
= 0;
124 sysmmu_ips ips
= (sysmmu_ips
)dev_id
;
125 enum S5P_SYSMMU_INTERRUPT_TYPE itype
;
127 itype
= (enum S5P_SYSMMU_INTERRUPT_TYPE
)
128 __ffs(__raw_readl(sysmmusfrs
[ips
] + S5P_INT_STATUS
));
130 BUG_ON(!((itype
>= 0) && (itype
< 8)));
132 dev_alert(dev
, "%s occurred by %s.\n", sysmmu_fault_name
[itype
],
133 sysmmu_ips_name
[ips
]);
135 if (fault_handlers
[ips
]) {
138 base
= __raw_readl(sysmmusfrs
[ips
] + S5P_PT_BASE_ADDR
);
139 addr
= __raw_readl(sysmmusfrs
[ips
] + fault_reg_offset
[itype
]);
141 if (fault_handlers
[ips
](itype
, base
, addr
)) {
142 __raw_writel(1 << itype
,
143 sysmmusfrs
[ips
] + S5P_INT_CLEAR
);
144 dev_notice(dev
, "%s from %s is resolved."
145 " Retrying translation.\n",
146 sysmmu_fault_name
[itype
], sysmmu_ips_name
[ips
]);
155 dev_notice(dev
, "%s from %s is not handled.\n",
156 sysmmu_fault_name
[itype
], sysmmu_ips_name
[ips
]);
161 void s5p_sysmmu_set_tablebase_pgd(sysmmu_ips ips
, unsigned long pgd
)
163 if (is_sysmmu_active(ips
)) {
165 __sysmmu_set_ptbase(ips
, pgd
);
168 dev_dbg(dev
, "%s is disabled. "
169 "Skipping initializing page table base.\n",
170 sysmmu_ips_name
[ips
]);
174 void s5p_sysmmu_enable(sysmmu_ips ips
, unsigned long pgd
)
176 if (!is_sysmmu_active(ips
)) {
177 sysmmu_clk_enable(ips
);
179 __sysmmu_set_ptbase(ips
, pgd
);
181 __raw_writel(CTRL_ENABLE
, sysmmusfrs
[ips
] + S5P_MMU_CTRL
);
183 set_sysmmu_active(ips
);
184 dev_dbg(dev
, "%s is enabled.\n", sysmmu_ips_name
[ips
]);
186 dev_dbg(dev
, "%s is already enabled.\n", sysmmu_ips_name
[ips
]);
190 void s5p_sysmmu_disable(sysmmu_ips ips
)
192 if (is_sysmmu_active(ips
)) {
193 __raw_writel(CTRL_DISABLE
, sysmmusfrs
[ips
] + S5P_MMU_CTRL
);
194 set_sysmmu_inactive(ips
);
195 sysmmu_clk_disable(ips
);
196 dev_dbg(dev
, "%s is disabled.\n", sysmmu_ips_name
[ips
]);
198 dev_dbg(dev
, "%s is already disabled.\n", sysmmu_ips_name
[ips
]);
202 void s5p_sysmmu_tlb_invalidate(sysmmu_ips ips
)
204 if (is_sysmmu_active(ips
)) {
206 __sysmmu_tlb_invalidate(ips
);
209 dev_dbg(dev
, "%s is disabled. "
210 "Skipping invalidating TLB.\n", sysmmu_ips_name
[ips
]);
214 static int s5p_sysmmu_probe(struct platform_device
*pdev
)
217 struct resource
*res
, *mem
;
221 for (i
= 0; i
< S5P_SYSMMU_TOTAL_IPNUM
; i
++) {
224 sysmmu_clk_init(dev
, i
);
225 sysmmu_clk_disable(i
);
227 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, i
);
229 dev_err(dev
, "Failed to get the resource of %s.\n",
235 mem
= request_mem_region(res
->start
, resource_size(res
),
238 dev_err(dev
, "Failed to request the memory region of %s.\n",
244 sysmmusfrs
[i
] = ioremap(res
->start
, resource_size(res
));
245 if (!sysmmusfrs
[i
]) {
246 dev_err(dev
, "Failed to ioremap() for %s.\n",
252 irq
= platform_get_irq(pdev
, i
);
254 dev_err(dev
, "Failed to get the IRQ resource of %s.\n",
260 if (request_irq(irq
, s5p_sysmmu_irq
, IRQF_DISABLED
,
261 pdev
->name
, (void *)i
)) {
262 dev_err(dev
, "Failed to request IRQ for %s.\n",
272 iounmap(sysmmusfrs
[i
]);
274 release_mem_region(mem
->start
, resource_size(mem
));
279 static int s5p_sysmmu_remove(struct platform_device
*pdev
)
283 int s5p_sysmmu_runtime_suspend(struct device
*dev
)
288 int s5p_sysmmu_runtime_resume(struct device
*dev
)
293 const struct dev_pm_ops s5p_sysmmu_pm_ops
= {
294 .runtime_suspend
= s5p_sysmmu_runtime_suspend
,
295 .runtime_resume
= s5p_sysmmu_runtime_resume
,
298 static struct platform_driver s5p_sysmmu_driver
= {
299 .probe
= s5p_sysmmu_probe
,
300 .remove
= s5p_sysmmu_remove
,
302 .owner
= THIS_MODULE
,
303 .name
= "s5p-sysmmu",
304 .pm
= &s5p_sysmmu_pm_ops
,
308 static int __init
s5p_sysmmu_init(void)
310 return platform_driver_register(&s5p_sysmmu_driver
);
312 arch_initcall(s5p_sysmmu_init
);