2 #include <asm/arch/mmu.h>
3 #include <asm/sysreg.h>
5 void mmu_init_r(unsigned long dest_addr)
7 uintptr_t vmr_table_addr;
9 /* Round monitor address down to the nearest page boundary */
10 dest_addr &= PAGE_ADDR_MASK;
12 /* Initialize TLB entry 0 to cover the monitor, and lock it */
13 sysreg_write(TLBEHI, dest_addr | SYSREG_BIT(TLBEHI_V));
14 sysreg_write(TLBELO, dest_addr | MMU_VMR_CACHE_WRBACK);
15 sysreg_write(MMUCR, SYSREG_BF(DRP, 0) | SYSREG_BF(DLA, 1)
16 | SYSREG_BIT(MMUCR_S) | SYSREG_BIT(M));
20 * Calculate the address of the VM range table in a PC-relative
21 * manner to make sure we hit the SDRAM and not the flash.
23 vmr_table_addr = (uintptr_t)&mmu_vmr_table;
24 sysreg_write(PTBR, vmr_table_addr);
25 printf("VMR table @ 0x%08lx\n", vmr_table_addr);
28 sysreg_write(MMUCR, SYSREG_BF(DRP, 1) | SYSREG_BF(DLA, 1)
29 | SYSREG_BIT(MMUCR_S) | SYSREG_BIT(M) | SYSREG_BIT(E));
32 int mmu_handle_tlb_miss(void)
34 const struct mmu_vm_range *vmr_table;
35 const struct mmu_vm_range *vmr;
36 unsigned int fault_pgno;
39 fault_pgno = sysreg_read(TLBEAR) >> PAGE_SHIFT;
40 vmr_table = (const struct mmu_vm_range *)sysreg_read(PTBR);
42 /* Do a binary search through the VM ranges */
44 last = CONFIG_SYS_NR_VM_REGIONS;
45 while (first < last) {
49 /* Pick the entry in the middle of the remaining range */
50 middle = (first + last) >> 1;
51 vmr = &vmr_table[middle];
52 start = vmr->virt_pgno;
54 /* Do the bisection thing */
55 if (fault_pgno < start) {
57 } else if (fault_pgno >= (start + vmr->nr_pages)) {
60 /* Got it; let's slam it into the TLB */
63 tlbelo = vmr->phys & ~PAGE_ADDR_MASK;
64 tlbelo |= fault_pgno << PAGE_SHIFT;
65 sysreg_write(TLBELO, tlbelo);
68 /* Zero means success */
74 * Didn't find any matching entries. Return a nonzero value to
75 * indicate that this should be treated as a fatal exception.