source: mainline/boot/arch/arm32/src/mm.c@ 077b9172

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 077b9172 was b1011dae, checked in by Maurizio Lombardi <m.lombardi85@…>, 13 years ago

Merge changes from jan.vesely/helenos/arm

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * Copyright (c) 2007 Pavel Jancik, Michal Kebrt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup arm32boot
30 * @{
31 */
32/** @file
33 * @brief Memory management used while booting the kernel.
34 */
35
36#include <typedefs.h>
37#include <arch/asm.h>
38#include <arch/mm.h>
39
40/** Disable the MMU */
41static void disable_paging(void)
42{
43 asm volatile (
44 "mrc p15, 0, r0, c1, c0, 0\n"
45 "bic r0, r0, #1\n"
46 "mcr p15, 0, r0, c1, c0, 0\n"
47 );
48}
49
50/** Check if caching can be enabled for a given memory section.
51 *
52 * Memory areas used for I/O are excluded from caching.
53 * At the moment caching is enabled only on GTA02.
54 *
55 * @param section The section number.
56 *
57 * @return 1 if the given section can be mapped as cacheable, 0 otherwise.
58*/
59static inline int section_cacheable(pfn_t section)
60{
61#ifdef MACHINE_gta02
62 unsigned long address = section << PTE_SECTION_SHIFT;
63
64 if (address >= GTA02_IOMEM_START && address < GTA02_IOMEM_END)
65 return 0;
66 else
67 return 1;
68#elif defined MACHINE_beagleboardxm
69 const unsigned long address = section << PTE_SECTION_SHIFT;
70 if (address >= BBXM_RAM_START && address < BBXM_RAM_END)
71 return 1;
72#endif
73 return 0;
74}
75
76/** Initialize "section" page table entry.
77 *
78 * Will be readable/writable by kernel with no access from user mode.
79 * Will belong to domain 0. No cache or buffering is enabled.
80 *
81 * @param pte Section entry to initialize.
82 * @param frame First frame in the section (frame number).
83 *
84 * @note If frame is not 1 MB aligned, first lower 1 MB aligned frame will be
85 * used.
86 *
87 */
88static void init_ptl0_section(pte_level0_section_t* pte,
89 pfn_t frame)
90{
91 pte->descriptor_type = PTE_DESCRIPTOR_SECTION;
92 pte->bufferable = 1;
93 pte->cacheable = section_cacheable(frame);
94 pte->xn = 0;
95 pte->domain = 0;
96 pte->should_be_zero_1 = 0;
97 pte->access_permission_0 = PTE_AP_USER_NO_KERNEL_RW;
98 pte->tex = 0;
99 pte->access_permission_1 = 0;
100 pte->non_global = 0;
101 pte->should_be_zero_2 = 0;
102 pte->non_secure = 0;
103 pte->section_base_addr = frame;
104}
105
106/** Initialize page table used while booting the kernel. */
107static void init_boot_pt(void)
108{
109 const pfn_t split_page = PTL0_ENTRIES;
110 /* Create 1:1 virtual-physical mapping (in lower 2 GB). */
111 pfn_t page;
112 for (page = 0; page < split_page; page++)
113 init_ptl0_section(&boot_pt[page], page);
114
115 asm volatile (
116 "mcr p15, 0, %[pt], c2, c0, 0\n"
117 :: [pt] "r" (boot_pt)
118 );
119}
120
121static void enable_paging()
122{
123 /* c3 - each two bits controls access to the one of domains (16)
124 * 0b01 - behave as a client (user) of a domain
125 */
126 asm volatile (
127 /* Behave as a client of domains */
128 "ldr r0, =0x55555555\n"
129 "mcr p15, 0, r0, c3, c0, 0\n"
130
131 /* Current settings */
132 "mrc p15, 0, r0, c1, c0, 0\n"
133
134 /* Enable ICache, DCache, BPredictors and MMU,
135 * we disable caches before jumping to kernel
136 * so this is safe for all archs.
137 */
138 "ldr r1, =0x00001805\n"
139
140 "orr r0, r0, r1\n"
141
142 /* Flush the TLB */
143 "mcr p15, 0, r0, c8, c7, 0\n"
144
145 /* Store settings, enable the MMU */
146 "mcr p15, 0, r0, c1, c0, 0\n"
147 ::: "r0", "r1"
148 );
149}
150
151/** Start the MMU - initialize page table and enable paging. */
152void mmu_start() {
153 disable_paging();
154 init_boot_pt();
155 enable_paging();
156}
157
158/** @}
159 */
Note: See TracBrowser for help on using the repository browser.