blob: 2027b414f503bfccc37901d4a891546a42732d33 [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>
Channagoud Kadabic9f8da62013-08-05 15:27:13 -070028#include <arch/defines.h>
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070029#include <arch/arm/mmu.h>
30
31#if ARM_WITH_MMU
32
33#define MB (1024*1024)
34
35/* the location of the table may be brought in from outside */
36#if WITH_EXTERNAL_TRANSLATION_TABLE
37#if !defined(MMU_TRANSLATION_TABLE_ADDR)
38#error must set MMU_TRANSLATION_TABLE_ADDR in the make configuration
39#endif
40static uint32_t *tt = (void *)MMU_TRANSLATION_TABLE_ADDR;
41#else
42/* the main translation table */
43static uint32_t tt[4096] __ALIGNED(16384);
44#endif
45
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070046void arm_mmu_map_section(addr_t paddr, addr_t vaddr, uint flags)
47{
48 int index;
Brian Swetlandeceda412008-09-07 02:48:41 -070049
Amol Jadi9ef9b732011-05-23 16:00:17 -070050 /* Get the index into the translation table */
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070051 index = vaddr / MB;
Amol Jadi9ef9b732011-05-23 16:00:17 -070052
53 /* Set the entry value:
54 * (2<<0): Section entry
55 * (0<<5): Domain = 0
56 * flags: TEX, CB and AP bit settings provided by the caller.
57 */
58 tt[index] = (paddr & ~(MB-1)) | (0<<5) | (2<<0) | flags;
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070059
60 arm_invalidate_tlb();
61}
62
63void arm_mmu_init(void)
64{
65 int i;
66
Amol Jadi9ef9b732011-05-23 16:00:17 -070067 /* set some mmu specific control bits:
68 * access flag disabled, TEX remap disabled, mmu disabled
69 */
70 arm_write_cr1(arm_read_cr1() & ~((1<<29)|(1<<28)|(1<<0)));
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070071
Deepa Dinamani20cb9e52012-10-18 12:20:47 -070072 if (platform_use_identity_mmu_mappings())
73 {
74 /* set up an identity-mapped translation table with
75 * strongly ordered memory type and read/write access.
76 */
77 for (i=0; i < 4096; i++) {
78 arm_mmu_map_section(i * MB,
79 i * MB,
80 MMU_MEMORY_TYPE_STRONGLY_ORDERED | MMU_MEMORY_AP_READ_WRITE);
81 }
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070082 }
83
Neeti Desai13e688d2012-08-22 16:30:55 -070084 platform_init_mmu_mappings();
85
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070086 /* set up the translation table base */
87 arm_write_ttbr((uint32_t)tt);
88
89 /* set up the domain access register */
90 arm_write_dacr(0x00000001);
91
92 /* turn on the mmu */
93 arm_write_cr1(arm_read_cr1() | 0x1);
94}
95
96void arch_disable_mmu(void)
97{
Channagoud Kadabic9f8da62013-08-05 15:27:13 -070098 /* Ensure all memory access are complete
99 * before disabling MMU
100 */
101 dsb();
Amol Jadi9ef9b732011-05-23 16:00:17 -0700102 arm_write_cr1(arm_read_cr1() & ~(1<<0));
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700103 arm_invalidate_tlb();
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700104}
105
106#endif // ARM_WITH_MMU