source: mainline/kernel/arch/ia32/src/mm/frame.c@ 056ddc30

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

Factor out the amd64/ia32 code which calculates the bounds of
a zone after considering the low/hich memory split to a new
generic function frame_adjust_zone_bounds().

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