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

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

boot,arm32: Make arm32 bootstrap code BeagleBoard-xM aware.

  • Property mode set to 100644
File size: 3.8 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 = 0;
57 pte->cacheable = 0;
58 pte->impl_specific = 0;
59 pte->domain = 0;
60 pte->should_be_zero_1 = 0;
61 pte->access_permission = PTE_AP_USER_NO_KERNEL_RW;
62 pte->should_be_zero_2 = 0;
63 pte->section_base_addr = frame;
64}
65
66/** Initialize page table used while booting the kernel. */
67static void init_boot_pt(void)
68{
69/* BeagleBoard-xM (MD37x) memory starts at 2GB border,
70 * thus mapping only lower 2GB is not not enough.
71 * Map entire AS 1:1 instead and hope it works. */
72#ifdef MACHINE_beagleboardxm
73 const pfn_t split_page = PTL0_ENTRIES;
74#else
75 const pfn_t split_page = 0x800;
76#endif
77 /* Create 1:1 virtual-physical mapping (in lower 2 GB). */
78 pfn_t page;
79 for (page = 0; page < split_page; page++)
80 init_ptl0_section(&boot_pt[page], page);
81
82 /*
83 * Create 1:1 virtual-physical mapping in kernel space
84 * (upper 2 GB), physical addresses start from 0.
85 */
86 for (page = split_page; page < PTL0_ENTRIES; page++)
87 init_ptl0_section(&boot_pt[page], page - split_page);
88
89 asm volatile (
90 "mcr p15, 0, %[pt], c2, c0, 0\n"
91 :: [pt] "r" (boot_pt)
92 );
93}
94
95static void enable_paging()
96{
97 /* c3 - each two bits controls access to the one of domains (16)
98 * 0b01 - behave as a client (user) of a domain
99 */
100 asm volatile (
101 /* Behave as a client of domains */
102 "ldr r0, =0x55555555\n"
103 "mcr p15, 0, r0, c3, c0, 0\n"
104
105 /* Current settings */
106 "mrc p15, 0, r0, c1, c0, 0\n"
107
108 /* Mask to enable paging */
109 "ldr r1, =0x00000001\n"
110 "orr r0, r0, r1\n"
111
112 /* Store settings */
113 "mcr p15, 0, r0, c1, c0, 0\n"
114 ::: "r0", "r1"
115 );
116}
117
118/** Start the MMU - initialize page table and enable paging. */
119void mmu_start() {
120 init_boot_pt();
121 enable_paging();
122}
123
124/** @}
125 */
Note: See TracBrowser for help on using the repository browser.