source: mainline/kernel/arch/ia32/src/mm/frame.c@ 33dac7d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 33dac7d was 33dac7d, checked in by Martin Decky <martin@…>, 15 years ago

improve printouts

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 * Copyright (c) 2008 Jakub Jermar
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 ia32mm
30 * @{
31 */
32/** @file
33 * @ingroup ia32mm, amd64mm
34 */
35
36#include <mm/frame.h>
37#include <arch/mm/frame.h>
38#include <mm/as.h>
39#include <config.h>
40#include <arch/boot/boot.h>
41#include <arch/boot/memmap.h>
42#include <panic.h>
43#include <debug.h>
44#include <align.h>
45#include <macros.h>
46
47#include <print.h>
48
49#define PHYSMEM_LIMIT32 0x7c000000ull
50#define PHYSMEM_LIMIT64 0xe0000000ull
51
52size_t hardcoded_unmapped_ktext_size = 0;
53size_t hardcoded_unmapped_kdata_size = 0;
54
55uintptr_t last_frame = 0;
56
57static void init_e820_memory(pfn_t minconf)
58{
59 unsigned int i;
60
61 for (i = 0; i < e820counter; i++) {
62 uint64_t base = e820table[i].base_address;
63 uint64_t size = e820table[i].size;
64
65#ifdef __32_BITS__
66 /*
67 * XXX FIXME:
68 *
69 * Ignore zones which start above PHYSMEM_LIMIT32
70 * or clip zones which go beyond PHYSMEM_LIMIT32.
71 *
72 * The PHYSMEM_LIMIT32 (2 GB - 64 MB) is a rather
73 * arbitrary constant which allows to have at
74 * least 64 MB in the kernel address space to
75 * map hardware resources.
76 *
77 * The kernel uses fixed 1:1 identity mapping
78 * of the physical memory with 2:2 GB split.
79 * This is a severe limitation of the current
80 * kernel memory management.
81 *
82 */
83
84 if (base > PHYSMEM_LIMIT32)
85 continue;
86
87 if (base + size > PHYSMEM_LIMIT32)
88 size = PHYSMEM_LIMIT32 - base;
89#endif
90
91#ifdef __64_BITS__
92 /*
93 * XXX FIXME:
94 *
95 * Ignore zones which start above PHYSMEM_LIMIT64
96 * or clip zones which go beyond PHYSMEM_LIMIT64.
97 *
98 * The limit PHYSMEM_LIMIT64 (3.5 GB) is caused
99 * by various limitations of the current kernel
100 * memory management.
101 *
102 */
103
104 if (base > PHYSMEM_LIMIT64)
105 continue;
106
107 if (base + size > PHYSMEM_LIMIT64)
108 size = PHYSMEM_LIMIT64 - base;
109#endif
110
111 if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) {
112 /* To be safe, make the available zone possibly smaller */
113 uint64_t new_base = ALIGN_UP(base, FRAME_SIZE);
114 uint64_t new_size = ALIGN_DOWN(size - (new_base - base),
115 FRAME_SIZE);
116
117 pfn_t pfn = ADDR2PFN(new_base);
118 size_t count = SIZE2FRAMES(new_size);
119
120 pfn_t conf;
121 if ((minconf < pfn) || (minconf >= pfn + count))
122 conf = pfn;
123 else
124 conf = minconf;
125
126 zone_create(pfn, count, conf, ZONE_AVAILABLE);
127
128 // XXX this has to be removed
129 if (last_frame < ALIGN_UP(new_base + new_size, FRAME_SIZE))
130 last_frame = ALIGN_UP(new_base + new_size, FRAME_SIZE);
131 }
132
133 if (e820table[i].type == MEMMAP_MEMORY_RESERVED) {
134 /* To be safe, make the reserved zone possibly larger */
135 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
136 uint64_t new_size = ALIGN_UP(size + (base - new_base),
137 FRAME_SIZE);
138
139 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
140 ZONE_RESERVED);
141 }
142
143 if (e820table[i].type == MEMMAP_MEMORY_ACPI) {
144 /* To be safe, make the firmware zone possibly larger */
145 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
146 uint64_t new_size = ALIGN_UP(size + (base - new_base),
147 FRAME_SIZE);
148
149 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
150 ZONE_FIRMWARE);
151 }
152 }
153}
154
155static const char *e820names[] = {
156 "invalid",
157 "available",
158 "reserved",
159 "acpi",
160 "nvs",
161 "unusable"
162};
163
164void physmem_print(void)
165{
166 unsigned int i;
167 printf("[base ] [size ] [name ]\n");
168
169 for (i = 0; i < e820counter; i++) {
170 const char *name;
171
172 if (e820table[i].type <= MEMMAP_MEMORY_UNUSABLE)
173 name = e820names[e820table[i].type];
174 else
175 name = "invalid";
176
177 printf("%#018" PRIx64 " %#018" PRIx64" %s\n", e820table[i].base_address,
178 e820table[i].size, name);
179 }
180}
181
182
183void frame_arch_init(void)
184{
185 pfn_t minconf;
186
187 if (config.cpu_active == 1) {
188 minconf = 1;
189
190#ifdef CONFIG_SMP
191 minconf = max(minconf,
192 ADDR2PFN(AP_BOOT_OFFSET + hardcoded_unmapped_ktext_size +
193 hardcoded_unmapped_kdata_size));
194#endif
195
196 init_e820_memory(minconf);
197
198 /* Reserve frame 0 (BIOS data) */
199 frame_mark_unavailable(0, 1);
200
201#ifdef CONFIG_SMP
202 /* Reserve AP real mode bootstrap memory */
203 frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH,
204 (hardcoded_unmapped_ktext_size +
205 hardcoded_unmapped_kdata_size) >> FRAME_WIDTH);
206#endif
207 }
208}
209
210/** @}
211 */
Note: See TracBrowser for help on using the repository browser.