source: mainline/kernel/arch/ia32/src/mm/frame.c@ 80d301ab

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

Add amd64 and ia32 support for frame_low/high_arch_init().

  • Property mode set to 100644
File size: 5.0 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#include <print.h>
47
48size_t hardcoded_unmapped_ktext_size = 0;
49size_t hardcoded_unmapped_kdata_size = 0;
50
51// XXX: remove me
52uintptr_t last_frame = 0;
53
54static void init_e820_memory(pfn_t minconf, bool low)
55{
56 unsigned int i;
57
58 for (i = 0; i < e820counter; i++) {
59 uint64_t base = e820table[i].base_address;
60 uint64_t size = e820table[i].size;
61 uintptr_t limit = config.identity_size;
62
63 if (low) {
64 if (base > limit)
65 continue;
66 if (base + size > limit)
67 size = limit - base;
68 } else {
69 if (base + size <= limit)
70 continue;
71 if (base <= limit) {
72 size -= limit - base;
73 base = limit;
74 }
75 }
76
77 if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) {
78 /* To be safe, make the available zone possibly smaller */
79 uint64_t new_base = ALIGN_UP(base, FRAME_SIZE);
80 uint64_t new_size = ALIGN_DOWN(size - (new_base - base),
81 FRAME_SIZE);
82
83 size_t count = SIZE2FRAMES(new_size);
84 pfn_t pfn = ADDR2PFN(new_base);
85 pfn_t conf;
86
87 if (low) {
88 if ((minconf < pfn) || (minconf >= pfn + count))
89 conf = pfn;
90 else
91 conf = minconf;
92 zone_create(pfn, count, conf,
93 ZONE_AVAILABLE | ZONE_LOWMEM);
94 } else {
95 printf("count=%lld\n", (long long int) count);
96 conf = zone_external_conf_alloc(count);
97 zone_create(pfn, count, conf,
98 ZONE_AVAILABLE | ZONE_HIGHMEM);
99 }
100
101 // XXX: remove me
102 if (last_frame < new_base + new_size)
103 last_frame = new_base + new_size;
104 } else if ((e820table[i].type == MEMMAP_MEMORY_ACPI) ||
105 (e820table[i].type == MEMMAP_MEMORY_NVS)) {
106 /* To be safe, make the firmware zone possibly larger */
107 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
108 uint64_t new_size = ALIGN_UP(size + (base - new_base),
109 FRAME_SIZE);
110
111 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
112 ZONE_FIRMWARE);
113 } else {
114 /* To be safe, make the reserved zone possibly larger */
115 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
116 uint64_t new_size = ALIGN_UP(size + (base - new_base),
117 FRAME_SIZE);
118
119 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
120 ZONE_RESERVED);
121 }
122 }
123}
124
125static const char *e820names[] = {
126 "invalid",
127 "available",
128 "reserved",
129 "acpi",
130 "nvs",
131 "unusable"
132};
133
134void physmem_print(void)
135{
136 unsigned int i;
137 printf("[base ] [size ] [name ]\n");
138
139 for (i = 0; i < e820counter; i++) {
140 const char *name;
141
142 if (e820table[i].type <= MEMMAP_MEMORY_UNUSABLE)
143 name = e820names[e820table[i].type];
144 else
145 name = "invalid";
146
147 printf("%#018" PRIx64 " %#018" PRIx64" %s\n", e820table[i].base_address,
148 e820table[i].size, name);
149 }
150}
151
152
153void frame_low_arch_init(void)
154{
155 pfn_t minconf;
156
157 if (config.cpu_active == 1) {
158 minconf = 1;
159
160#ifdef CONFIG_SMP
161 minconf = max(minconf,
162 ADDR2PFN(AP_BOOT_OFFSET + hardcoded_unmapped_ktext_size +
163 hardcoded_unmapped_kdata_size));
164#endif
165
166 init_e820_memory(minconf, true);
167
168 /* Reserve frame 0 (BIOS data) */
169 frame_mark_unavailable(0, 1);
170
171#ifdef CONFIG_SMP
172 /* Reserve AP real mode bootstrap memory */
173 frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH,
174 (hardcoded_unmapped_ktext_size +
175 hardcoded_unmapped_kdata_size) >> FRAME_WIDTH);
176#endif
177 }
178}
179
180void frame_high_arch_init(void)
181{
182 if (config.cpu_active == 1)
183 init_e820_memory(0, false);
184}
185
186/** @}
187 */
Note: See TracBrowser for help on using the repository browser.