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
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++) {
[ad12b5ea]59 uintptr_t base = (uintptr_t) e820table[i].base_address;
60 size_t size = (size_t) e820table[i].size;
[e49e234]61
[ad12b5ea]62 if (!frame_adjust_zone_bounds(low, &base, &size))
63 continue;
[cae5404]64
[085d973]65 if (e820table[i].type == MEMMAP_MEMORY_AVAILABLE) {
[720db0c]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);
[80d301ab]72 pfn_t pfn = ADDR2PFN(new_base);
[e49e234]73 pfn_t conf;
[b07c332]74
[80d301ab]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 }
[b07c332]87
[80d301ab]88 // XXX: remove me
89 if (last_frame < new_base + new_size)
90 last_frame = new_base + new_size;
[142084b2]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 */
[720db0c]94 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
95 uint64_t new_size = ALIGN_UP(size + (base - new_base),
96 FRAME_SIZE);
[e49e234]97
[720db0c]98 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
[142084b2]99 ZONE_FIRMWARE);
100 } else {
101 /* To be safe, make the reserved zone possibly larger */
[720db0c]102 uint64_t new_base = ALIGN_DOWN(base, FRAME_SIZE);
103 uint64_t new_size = ALIGN_UP(size + (base - new_base),
104 FRAME_SIZE);
[e49e234]105
[720db0c]106 zone_create(ADDR2PFN(new_base), SIZE2FRAMES(new_size), 0,
[142084b2]107 ZONE_RESERVED);
[ae318d3]108 }
[085d973]109 }
110}
111
[a000878c]112static const char *e820names[] = {
[a7df23c]113 "invalid",
114 "available",
115 "reserved",
116 "acpi",
117 "nvs",
118 "unusable"
119};
[085d973]120
[b07c332]121void physmem_print(void)
[085d973]122{
[43b1e86]123 unsigned int i;
[33dac7d]124 printf("[base ] [size ] [name ]\n");
[43b1e86]125
[085d973]126 for (i = 0; i < e820counter; i++) {
[33dac7d]127 const char *name;
128
[085d973]129 if (e820table[i].type <= MEMMAP_MEMORY_UNUSABLE)
130 name = e820names[e820table[i].type];
131 else
132 name = "invalid";
[43b1e86]133
[33dac7d]134 printf("%#018" PRIx64 " %#018" PRIx64" %s\n", e820table[i].base_address,
[ba4a63b8]135 e820table[i].size, name);
[0b5f9fa]136 }
[085d973]137}
138
139
[ddcc8a0]140void frame_low_arch_init(void)
[f761f1eb]141{
[b07c332]142 pfn_t minconf;
[4cc2ddd]143
[f761f1eb]144 if (config.cpu_active == 1) {
[085d973]145 minconf = 1;
[ae318d3]146
[085d973]147#ifdef CONFIG_SMP
148 minconf = max(minconf,
[ba4a63b8]149 ADDR2PFN(AP_BOOT_OFFSET + hardcoded_unmapped_ktext_size +
150 hardcoded_unmapped_kdata_size));
[085d973]151#endif
[33dac7d]152
[80d301ab]153 init_e820_memory(minconf, true);
[ae318d3]154
[328f2934]155 /* Reserve frame 0 (BIOS data) */
[085d973]156 frame_mark_unavailable(0, 1);
[328f2934]157
[66def8d]158#ifdef CONFIG_SMP
159 /* Reserve AP real mode bootstrap memory */
[142084b2]160 frame_mark_unavailable(AP_BOOT_OFFSET >> FRAME_WIDTH,
[ba4a63b8]161 (hardcoded_unmapped_ktext_size +
162 hardcoded_unmapped_kdata_size) >> FRAME_WIDTH);
[66def8d]163#endif
[f761f1eb]164 }
165}
[b45c443]166
[ddcc8a0]167void frame_high_arch_init(void)
168{
[80d301ab]169 if (config.cpu_active == 1)
170 init_e820_memory(0, false);
[ddcc8a0]171}
172
[06e1e95]173/** @}
[b45c443]174 */
Note: See TracBrowser for help on using the repository browser.