blob: 078d1d86b0251fd915e4821b3f9002e3b7c5068d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tom Rinibcb3c8d2016-05-06 10:40:22 -04002/*
Bin Mengef4c9e72019-08-29 02:53:06 -07003 * QEMU x86 specific E820 table generation
4 *
Tom Rinibcb3c8d2016-05-06 10:40:22 -04005 * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com>
Bin Mengef4c9e72019-08-29 02:53:06 -07006 * (C) Copyright 2019 Bin Meng <bmeng.cn@gmail.com>
Tom Rinibcb3c8d2016-05-06 10:40:22 -04007 */
8
Simon Glassf32df8d2025-03-15 14:25:55 +00009#include <bloblist.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060010#include <env_internal.h>
Simon Glass9bc15642020-02-03 07:36:16 -070011#include <malloc.h>
Tom Rinibcb3c8d2016-05-06 10:40:22 -040012#include <asm/e820.h>
Bin Mengef4c9e72019-08-29 02:53:06 -070013#include <asm/arch/qemu.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Simon Glassde1669f2023-07-30 21:02:04 -060015#include <linux/sizes.h>
Tom Rinibcb3c8d2016-05-06 10:40:22 -040016
Bin Mengd6da81d2017-01-18 03:32:51 -080017DECLARE_GLOBAL_DATA_PTR;
18
Bin Meng3838d712018-04-11 22:02:10 -070019unsigned int install_e820_map(unsigned int max_entries,
Bin Meng4b8fc742018-04-11 22:02:11 -070020 struct e820_entry *entries)
Tom Rinibcb3c8d2016-05-06 10:40:22 -040021{
Bin Mengef4c9e72019-08-29 02:53:06 -070022 u64 high_mem_size;
Simon Glass1eedab82025-03-15 14:25:54 +000023 struct e820_ctx ctx;
Tom Rinibcb3c8d2016-05-06 10:40:22 -040024
Simon Glass1eedab82025-03-15 14:25:54 +000025 e820_init(&ctx, entries, max_entries);
Bin Mengef4c9e72019-08-29 02:53:06 -070026
Simon Glass1eedab82025-03-15 14:25:54 +000027 e820_next(&ctx, E820_RAM, ISA_START_ADDRESS);
28 e820_next(&ctx, E820_RESERVED, ISA_END_ADDRESS);
Tom Rinibcb3c8d2016-05-06 10:40:22 -040029
30 /*
Simon Glassf32df8d2025-03-15 14:25:55 +000031 * if we use bloblist to allocate high memory for storing ACPI tables,
32 * we need to reserve that region in e820 tables, otherwise the kernel
33 * will reclaim them and data will be corrupted. The ACPI tables may not
34 * have been written yet, so use the whole bloblist size
Tom Rinibcb3c8d2016-05-06 10:40:22 -040035 */
Simon Glassf32df8d2025-03-15 14:25:55 +000036 if (IS_ENABLED(CONFIG_BLOBLIST_TABLES)) {
37 e820_to_addr(&ctx, E820_RAM, (ulong)gd->bloblist);
38 e820_next(&ctx, E820_ACPI, bloblist_get_total_size());
39 } else {
40 /* If using memalign() reserve that whole region instead */
41 e820_to_addr(&ctx, E820_RAM, gd->relocaddr - TOTAL_MALLOC_LEN);
42 e820_next(&ctx, E820_ACPI, TOTAL_MALLOC_LEN);
43 }
Simon Glass1eedab82025-03-15 14:25:54 +000044 e820_to_addr(&ctx, E820_RAM, qemu_get_low_memory_size());
45 e820_add(&ctx, E820_RESERVED, CONFIG_PCIE_ECAM_BASE,
46 CONFIG_PCIE_ECAM_SIZE);
Bin Mengef4c9e72019-08-29 02:53:06 -070047
48 high_mem_size = qemu_get_high_memory_size();
Simon Glass1eedab82025-03-15 14:25:54 +000049 if (high_mem_size)
50 e820_add(&ctx, E820_RAM, SZ_4G, high_mem_size);
Tom Rinibcb3c8d2016-05-06 10:40:22 -040051
Simon Glass1eedab82025-03-15 14:25:54 +000052 return e820_finish(&ctx);
Tom Rinibcb3c8d2016-05-06 10:40:22 -040053}