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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ff166148 was ff166148, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

arm32: Enable unaligned access and restore uspace compiler optimization

  • Property mode set to 100644
File size: 4.2 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/** Initialize "section" page table entry.
41 *
42 * Will be readable/writable by kernel with no access from user mode.
43 * Will belong to domain 0. No cache or buffering is enabled.
44 *
45 * @param pte Section entry to initialize.
46 * @param frame First frame in the section (frame number).
47 *
48 * @note If frame is not 1 MB aligned, first lower 1 MB aligned frame will be
49 * used.
50 *
51 */
52static void init_ptl0_section(pte_level0_section_t* pte,
53 pfn_t frame)
54{
55 pte->descriptor_type = PTE_DESCRIPTOR_SECTION;
56 pte->bufferable = 1;
57 pte->cacheable = 0;
58 pte->xn = 0;
59 pte->domain = 0;
60 pte->should_be_zero_1 = 0;
61 pte->access_permission_0 = PTE_AP_USER_NO_KERNEL_RW;
62 pte->tex = 0;
63 pte->access_permission_1 = 0;
64 pte->non_global = 0;
65 pte->should_be_zero_2 = 0;
66 pte->non_secure = 0;
67 pte->section_base_addr = frame;
68}
69
70/** Initialize page table used while booting the kernel. */
71static void init_boot_pt(void)
72{
73 const pfn_t split_page = PTL0_ENTRIES;
74 /* Create 1:1 virtual-physical mapping (in lower 2 GB). */
75 pfn_t page;
76 for (page = 0; page < split_page; page++)
77 init_ptl0_section(&boot_pt[page], page);
78
79 /*
80 * Create 1:1 virtual-physical mapping in kernel space
81 * (upper 2 GB), physical addresses start from 0.
82 */
83 /* BeagleBoard-xM (MD37x) memory starts at 2GB border,
84 * thus mapping only lower 2GB is not not enough.
85 * Map entire AS 1:1 instead and hope it works. */
86 for (page = split_page; page < PTL0_ENTRIES; page++)
87#ifndef MACHINE_beagleboardxm
88 init_ptl0_section(&boot_pt[page], page - split_page);
89#else
90 init_ptl0_section(&boot_pt[page], page);
91#endif
92
93 asm volatile (
94 "mcr p15, 0, %[pt], c2, c0, 0\n"
95 :: [pt] "r" (boot_pt)
96 );
97}
98
99static void enable_paging()
100{
101 /* c3 - each two bits controls access to the one of domains (16)
102 * 0b01 - behave as a client (user) of a domain
103 */
104 asm volatile (
105 /* Behave as a client of domains */
106 "ldr r0, =0x55555555\n"
107 "mcr p15, 0, r0, c3, c0, 0\n"
108
109#ifdef PROCESSOR_armv7_a
110 /* Read Auxiliary control register */
111 "mrc p15, 0, r0, c1, c0, 1\n"
112 /* Mask to enable L2 cache */
113 "ldr r1, =0x00000002\n"
114 "orr r0, r0, r1\n"
115 /* Store Auxiliary control register */
116 "mrc p15, 0, r0, c1, c0, 1\n"
117#endif
118 /* Current settings */
119 "mrc p15, 0, r0, c1, c0, 0\n"
120
121#ifdef PROCESSOR_armv7_a
122 /* Mask to enable paging, caching */
123 "ldr r1, =0x00000005\n"
124#else
125 /* Mask to enable paging */
126 "ldr r1, =0x00000001\n"
127#endif
128 "orr r0, r0, r1\n"
129
130 /* Store settings */
131 "mcr p15, 0, r0, c1, c0, 0\n"
132 ::: "r0", "r1"
133 );
134}
135
136/** Start the MMU - initialize page table and enable paging. */
137void mmu_start() {
138 init_boot_pt();
139 enable_paging();
140}
141
142/** @}
143 */
Note: See TracBrowser for help on using the repository browser.