source: mainline/kernel/arch/ia32/src/mm/frame.c@ 0a549cc

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

zone_external_conf_alloc() must be allowed to fail gracefully (by passing FRAME_ATOMIC to frame_alloc()), otherwise the frame_alloc_generic() might panic on the "Cannot wait for memory to become available" assertion in specific memory configurations

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