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
RevLine 
[f761f1eb]1/*
[4bb31f7]2 * Copyright (c) 2008 Jakub Jermar
[f761f1eb]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
[a000878c]29/** @addtogroup ia32mm
[b45c443]30 * @{
31 */
32/** @file
33 * @ingroup ia32mm, amd64mm
34 */
35
[f761f1eb]36#include <mm/frame.h>
37#include <arch/mm/frame.h>
[20d50a1]38#include <mm/as.h>
[f761f1eb]39#include <config.h>
[f6297e0]40#include <arch/boot/boot.h>
[5d721f0]41#include <arch/boot/memmap.h>
[84dd253]42#include <panic.h>
[328f2934]43#include <debug.h>
[95498e5]44#include <align.h>
[085d973]45#include <macros.h>
46#include <print.h>
47
[f6297e0]48size_t hardcoded_unmapped_ktext_size = 0;
49size_t hardcoded_unmapped_kdata_size = 0;
[f761f1eb]50
[80d301ab]51// XXX: remove me
[7f1c620]52uintptr_t last_frame = 0;
[95498e5]53
[80d301ab]54static void init_e820_memory(pfn_t minconf, bool low)
[085d973]55{
[b07c332]56 unsigned int i;
[cae5404]57
[085d973]58 for (i = 0; i < e820counter; i++) {
[e49e234]59 uint64_t base = e820table[i].base_address;
60 uint64_t size = e820table[i].size;
[80d301ab]61 uintptr_t limit = config.identity_size;
[e49e234]62
[80d301ab]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 }
[cae5404]76
[085d973]77 if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) {
[720db0c]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);
[80d301ab]84 pfn_t pfn = ADDR2PFN(new_base);
[e49e234]85 pfn_t conf;
[b07c332]86
[80d301ab]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 }
[b07c332]100
[80d301ab]101 // XXX: remove me
102 if (last_frame < new_base + new_size)
103 last_frame = new_base + new_size;
[142084b2]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 */
[720db0c]107 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
108 uint64_t new_size = ALIGN_UP(size + (base - new_base),
109 FRAME_SIZE);
[e49e234]110
[720db0c]111 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
[142084b2]112 ZONE_FIRMWARE);
113 } else {
114 /* To be safe, make the reserved zone possibly larger */
[720db0c]115 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
116 uint64_t new_size = ALIGN_UP(size + (base - new_base),
117 FRAME_SIZE);
[e49e234]118
[720db0c]119 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
[142084b2]120 ZONE_RESERVED);
[ae318d3]121 }
[085d973]122 }
123}
124
[a000878c]125static const char *e820names[] = {
[a7df23c]126 "invalid",
127 "available",
128 "reserved",
129 "acpi",
130 "nvs",
131 "unusable"
132};
[085d973]133
[b07c332]134void physmem_print(void)
[085d973]135{
[43b1e86]136 unsigned int i;
[33dac7d]137 printf("[base ] [size ] [name ]\n");
[43b1e86]138
[085d973]139 for (i = 0; i < e820counter; i++) {
[33dac7d]140 const char *name;
141
[085d973]142 if (e820table[i].type <= MEMMAP_MEMORY_UNUSABLE)
143 name = e820names[e820table[i].type];
144 else
145 name = "invalid";
[43b1e86]146
[33dac7d]147 printf("%#018" PRIx64 " %#018" PRIx64" %s\n", e820table[i].base_address,
[ba4a63b8]148 e820table[i].size, name);
[0b5f9fa]149 }
[085d973]150}
151
152
[ddcc8a0]153void frame_low_arch_init(void)
[f761f1eb]154{
[b07c332]155 pfn_t minconf;
[4cc2ddd]156
[f761f1eb]157 if (config.cpu_active == 1) {
[085d973]158 minconf = 1;
[ae318d3]159
[085d973]160#ifdef CONFIG_SMP
161 minconf = max(minconf,
[ba4a63b8]162 ADDR2PFN(AP_BOOT_OFFSET + hardcoded_unmapped_ktext_size +
163 hardcoded_unmapped_kdata_size));
[085d973]164#endif
[33dac7d]165
[80d301ab]166 init_e820_memory(minconf, true);
[ae318d3]167
[328f2934]168 /* Reserve frame 0 (BIOS data) */
[085d973]169 frame_mark_unavailable(0, 1);
[328f2934]170
[66def8d]171#ifdef CONFIG_SMP
172 /* Reserve AP real mode bootstrap memory */
[142084b2]173 frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH,
[ba4a63b8]174 (hardcoded_unmapped_ktext_size +
175 hardcoded_unmapped_kdata_size) >> FRAME_WIDTH);
[66def8d]176#endif
[f761f1eb]177 }
178}
[b45c443]179
[ddcc8a0]180void frame_high_arch_init(void)
181{
[80d301ab]182 if (config.cpu_active == 1)
183 init_e820_memory(0, false);
[ddcc8a0]184}
185
[06e1e95]186/** @}
[b45c443]187 */
Note: See TracBrowser for help on using the repository browser.