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