blob: 74e9ecd9837c8725225517b11e11ca29d6ded104 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <debug.h>
24#include <sys/types.h>
25#include <compiler.h>
26#include <arch.h>
27#include <arch/arm.h>
28#include <arch/arm/mmu.h>
29
30#if ARM_WITH_MMU
31
32#define MB (1024*1024)
33
34/* the location of the table may be brought in from outside */
35#if WITH_EXTERNAL_TRANSLATION_TABLE
36#if !defined(MMU_TRANSLATION_TABLE_ADDR)
37#error must set MMU_TRANSLATION_TABLE_ADDR in the make configuration
38#endif
39static uint32_t *tt = (void *)MMU_TRANSLATION_TABLE_ADDR;
40#else
41/* the main translation table */
42static uint32_t tt[4096] __ALIGNED(16384);
43#endif
44
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070045void arm_mmu_map_section(addr_t paddr, addr_t vaddr, uint flags)
46{
47 int index;
48 uint AP;
49 uint CB;
Brian Swetlandeceda412008-09-07 02:48:41 -070050 uint TEX = 0;
51
52#if defined(PLATFORM_MSM7K)
53 if ((paddr >= 0x88000000) && (paddr < 0xD0000000)) {
54 /* peripherals in the 0x88000000 - 0xD0000000 range must
55 * be mapped as DEVICE NON-SHARED: TEX=2, C=0, B=0
56 */
57 TEX = 2;
58 flags &= (~(MMU_FLAG_CACHED | MMU_FLAG_BUFFERED));
59 }
60#endif
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070061
62 AP = (flags & MMU_FLAG_READWRITE) ? 0x3 : 0x2;
63 CB = ((flags & MMU_FLAG_CACHED) ? 0x2 : 0) | ((flags & MMU_FLAG_BUFFERED) ? 0x1 : 0);
64
65 index = vaddr / MB;
Brian Swetlandeceda412008-09-07 02:48:41 -070066 // section mapping
67 tt[index] = (paddr & ~(MB-1)) | (TEX << 12) | (AP << 10) | (0<<5) | (CB << 2) | (2<<0);
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070068
69 arm_invalidate_tlb();
70}
71
72void arm_mmu_init(void)
73{
74 int i;
75
76 /* set some mmu specific control bits */
77 arm_write_cr1(arm_read_cr1() & ~((1<<29)|(1<<28)|(1<<0))); // access flag disabled, TEX remap disabled, mmu disabled
78
79 /* set up an identity-mapped translation table with cache disabled */
80 for (i=0; i < 4096; i++) {
81 arm_mmu_map_section(i * MB, i * MB, MMU_FLAG_READWRITE); // map everything uncached
82 }
83
84 /* set up the translation table base */
85 arm_write_ttbr((uint32_t)tt);
86
87 /* set up the domain access register */
88 arm_write_dacr(0x00000001);
89
90 /* turn on the mmu */
91 arm_write_cr1(arm_read_cr1() | 0x1);
92}
93
94void arch_disable_mmu(void)
95{
96 arm_write_cr1(arm_read_cr1() & ~(1<<0)); // access flag disabled, TEX remap disabled, mmu disabled
97}
98
99#endif // ARM_WITH_MMU
100