blob: 19e54c5202a923eebd1ce7d8bc76b53b1d0333cb [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
9#include <common.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>
Tom Rinibcb3c8d2016-05-06 10:40:22 -040015
Bin Mengd6da81d2017-01-18 03:32:51 -080016DECLARE_GLOBAL_DATA_PTR;
17
Bin Meng3838d712018-04-11 22:02:10 -070018unsigned int install_e820_map(unsigned int max_entries,
Bin Meng4b8fc742018-04-11 22:02:11 -070019 struct e820_entry *entries)
Tom Rinibcb3c8d2016-05-06 10:40:22 -040020{
Bin Mengef4c9e72019-08-29 02:53:06 -070021 u64 high_mem_size;
22 int n = 0;
Tom Rinibcb3c8d2016-05-06 10:40:22 -040023
Bin Mengef4c9e72019-08-29 02:53:06 -070024 entries[n].addr = 0;
25 entries[n].size = ISA_START_ADDRESS;
26 entries[n].type = E820_RAM;
27 n++;
28
29 entries[n].addr = ISA_START_ADDRESS;
30 entries[n].size = ISA_END_ADDRESS - ISA_START_ADDRESS;
31 entries[n].type = E820_RESERVED;
32 n++;
Tom Rinibcb3c8d2016-05-06 10:40:22 -040033
34 /*
35 * since we use memalign(malloc) to allocate high memory for
36 * storing ACPI tables, we need to reserve them in e820 tables,
37 * otherwise kernel will reclaim them and data will be corrupted
38 */
Bin Mengef4c9e72019-08-29 02:53:06 -070039 entries[n].addr = ISA_END_ADDRESS;
40 entries[n].size = gd->relocaddr - TOTAL_MALLOC_LEN - ISA_END_ADDRESS;
41 entries[n].type = E820_RAM;
42 n++;
Tom Rinibcb3c8d2016-05-06 10:40:22 -040043
44 /* for simplicity, reserve entire malloc space */
Bin Mengef4c9e72019-08-29 02:53:06 -070045 entries[n].addr = gd->relocaddr - TOTAL_MALLOC_LEN;
46 entries[n].size = TOTAL_MALLOC_LEN;
47 entries[n].type = E820_RESERVED;
48 n++;
Tom Rinibcb3c8d2016-05-06 10:40:22 -040049
Bin Mengef4c9e72019-08-29 02:53:06 -070050 entries[n].addr = gd->relocaddr;
51 entries[n].size = qemu_get_low_memory_size() - gd->relocaddr;
52 entries[n].type = E820_RESERVED;
53 n++;
Tom Rinibcb3c8d2016-05-06 10:40:22 -040054
Bin Mengef4c9e72019-08-29 02:53:06 -070055 entries[n].addr = CONFIG_PCIE_ECAM_BASE;
56 entries[n].size = CONFIG_PCIE_ECAM_SIZE;
57 entries[n].type = E820_RESERVED;
58 n++;
59
60 high_mem_size = qemu_get_high_memory_size();
61 if (high_mem_size) {
62 entries[n].addr = SZ_4G;
63 entries[n].size = high_mem_size;
64 entries[n].type = E820_RAM;
65 n++;
66 }
Tom Rinibcb3c8d2016-05-06 10:40:22 -040067
Bin Mengef4c9e72019-08-29 02:53:06 -070068 return n;
Tom Rinibcb3c8d2016-05-06 10:40:22 -040069}