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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 17cc8f4f was b5a3b50, checked in by Jakub Jermar <jakub@…>, 13 years ago

Enable ARM caches in the boot stage of HelenOS to speed up the
decompression. We get a decompression time of 8 seconds on a mini2440
board and only slightly more on a GTA02.

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