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

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

Disambiguate architecture specific doxygroups

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