Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 2 | /* |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 3 | * QEMU x86 specific E820 table generation |
| 4 | * |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 5 | * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com> |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 6 | * (C) Copyright 2019 Bin Meng <bmeng.cn@gmail.com> |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 10 | #include <env_internal.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 12 | #include <asm/e820.h> |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 13 | #include <asm/arch/qemu.h> |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 14 | |
Bin Meng | d6da81d | 2017-01-18 03:32:51 -0800 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Bin Meng | 3838d71 | 2018-04-11 22:02:10 -0700 | [diff] [blame] | 17 | unsigned int install_e820_map(unsigned int max_entries, |
Bin Meng | 4b8fc74 | 2018-04-11 22:02:11 -0700 | [diff] [blame] | 18 | struct e820_entry *entries) |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 19 | { |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 20 | u64 high_mem_size; |
| 21 | int n = 0; |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 22 | |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 23 | entries[n].addr = 0; |
| 24 | entries[n].size = ISA_START_ADDRESS; |
| 25 | entries[n].type = E820_RAM; |
| 26 | n++; |
| 27 | |
| 28 | entries[n].addr = ISA_START_ADDRESS; |
| 29 | entries[n].size = ISA_END_ADDRESS - ISA_START_ADDRESS; |
| 30 | entries[n].type = E820_RESERVED; |
| 31 | n++; |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * since we use memalign(malloc) to allocate high memory for |
| 35 | * storing ACPI tables, we need to reserve them in e820 tables, |
| 36 | * otherwise kernel will reclaim them and data will be corrupted |
| 37 | */ |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 38 | entries[n].addr = ISA_END_ADDRESS; |
| 39 | entries[n].size = gd->relocaddr - TOTAL_MALLOC_LEN - ISA_END_ADDRESS; |
| 40 | entries[n].type = E820_RAM; |
| 41 | n++; |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 42 | |
| 43 | /* for simplicity, reserve entire malloc space */ |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 44 | entries[n].addr = gd->relocaddr - TOTAL_MALLOC_LEN; |
| 45 | entries[n].size = TOTAL_MALLOC_LEN; |
| 46 | entries[n].type = E820_RESERVED; |
| 47 | n++; |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 48 | |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 49 | entries[n].addr = gd->relocaddr; |
| 50 | entries[n].size = qemu_get_low_memory_size() - gd->relocaddr; |
| 51 | entries[n].type = E820_RESERVED; |
| 52 | n++; |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 53 | |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 54 | entries[n].addr = CONFIG_PCIE_ECAM_BASE; |
| 55 | entries[n].size = CONFIG_PCIE_ECAM_SIZE; |
| 56 | entries[n].type = E820_RESERVED; |
| 57 | n++; |
| 58 | |
| 59 | high_mem_size = qemu_get_high_memory_size(); |
| 60 | if (high_mem_size) { |
| 61 | entries[n].addr = SZ_4G; |
| 62 | entries[n].size = high_mem_size; |
| 63 | entries[n].type = E820_RAM; |
| 64 | n++; |
| 65 | } |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 66 | |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 67 | return n; |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 68 | } |