blob: a4136eb98cfd14372b67c45b262f8476a41d9774 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tom Rinidd6f3ab2016-05-06 10:40:22 -04002/*
Bin Meng2495c3a2019-08-29 02:53:06 -07003 * QEMU x86 specific E820 table generation
4 *
Tom Rinidd6f3ab2016-05-06 10:40:22 -04005 * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com>
Bin Meng2495c3a2019-08-29 02:53:06 -07006 * (C) Copyright 2019 Bin Meng <bmeng.cn@gmail.com>
Tom Rinidd6f3ab2016-05-06 10:40:22 -04007 */
8
9#include <common.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060010#include <env_internal.h>
Tom Rinidd6f3ab2016-05-06 10:40:22 -040011#include <asm/e820.h>
Bin Meng2495c3a2019-08-29 02:53:06 -070012#include <asm/arch/qemu.h>
Tom Rinidd6f3ab2016-05-06 10:40:22 -040013
Bin Meng45ffa122017-01-18 03:32:51 -080014DECLARE_GLOBAL_DATA_PTR;
15
Bin Meng87af71c2018-04-11 22:02:10 -070016unsigned int install_e820_map(unsigned int max_entries,
Bin Meng45519922018-04-11 22:02:11 -070017 struct e820_entry *entries)
Tom Rinidd6f3ab2016-05-06 10:40:22 -040018{
Bin Meng2495c3a2019-08-29 02:53:06 -070019 u64 high_mem_size;
20 int n = 0;
Tom Rinidd6f3ab2016-05-06 10:40:22 -040021
Bin Meng2495c3a2019-08-29 02:53:06 -070022 entries[n].addr = 0;
23 entries[n].size = ISA_START_ADDRESS;
24 entries[n].type = E820_RAM;
25 n++;
26
27 entries[n].addr = ISA_START_ADDRESS;
28 entries[n].size = ISA_END_ADDRESS - ISA_START_ADDRESS;
29 entries[n].type = E820_RESERVED;
30 n++;
Tom Rinidd6f3ab2016-05-06 10:40:22 -040031
32 /*
33 * since we use memalign(malloc) to allocate high memory for
34 * storing ACPI tables, we need to reserve them in e820 tables,
35 * otherwise kernel will reclaim them and data will be corrupted
36 */
Bin Meng2495c3a2019-08-29 02:53:06 -070037 entries[n].addr = ISA_END_ADDRESS;
38 entries[n].size = gd->relocaddr - TOTAL_MALLOC_LEN - ISA_END_ADDRESS;
39 entries[n].type = E820_RAM;
40 n++;
Tom Rinidd6f3ab2016-05-06 10:40:22 -040041
42 /* for simplicity, reserve entire malloc space */
Bin Meng2495c3a2019-08-29 02:53:06 -070043 entries[n].addr = gd->relocaddr - TOTAL_MALLOC_LEN;
44 entries[n].size = TOTAL_MALLOC_LEN;
45 entries[n].type = E820_RESERVED;
46 n++;
Tom Rinidd6f3ab2016-05-06 10:40:22 -040047
Bin Meng2495c3a2019-08-29 02:53:06 -070048 entries[n].addr = gd->relocaddr;
49 entries[n].size = qemu_get_low_memory_size() - gd->relocaddr;
50 entries[n].type = E820_RESERVED;
51 n++;
Tom Rinidd6f3ab2016-05-06 10:40:22 -040052
Bin Meng2495c3a2019-08-29 02:53:06 -070053 entries[n].addr = CONFIG_PCIE_ECAM_BASE;
54 entries[n].size = CONFIG_PCIE_ECAM_SIZE;
55 entries[n].type = E820_RESERVED;
56 n++;
Tom Rinidd6f3ab2016-05-06 10:40:22 -040057
Bin Meng2495c3a2019-08-29 02:53:06 -070058 high_mem_size = qemu_get_high_memory_size();
59 if (high_mem_size) {
60 entries[n].addr = SZ_4G;
61 entries[n].size = high_mem_size;
62 entries[n].type = E820_RAM;
63 n++;
64 }
65
66 return n;
Tom Rinidd6f3ab2016-05-06 10:40:22 -040067}