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 | |
Simon Glass | f32df8d | 2025-03-15 14:25:55 +0000 | [diff] [blame] | 9 | #include <bloblist.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> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Simon Glass | de1669f | 2023-07-30 21:02:04 -0600 | [diff] [blame] | 15 | #include <linux/sizes.h> |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 16 | |
Bin Meng | d6da81d | 2017-01-18 03:32:51 -0800 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Bin Meng | 3838d71 | 2018-04-11 22:02:10 -0700 | [diff] [blame] | 19 | unsigned int install_e820_map(unsigned int max_entries, |
Bin Meng | 4b8fc74 | 2018-04-11 22:02:11 -0700 | [diff] [blame] | 20 | struct e820_entry *entries) |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 21 | { |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 22 | u64 high_mem_size; |
Simon Glass | 1eedab8 | 2025-03-15 14:25:54 +0000 | [diff] [blame] | 23 | struct e820_ctx ctx; |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 24 | |
Simon Glass | 1eedab8 | 2025-03-15 14:25:54 +0000 | [diff] [blame] | 25 | e820_init(&ctx, entries, max_entries); |
Bin Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 26 | |
Simon Glass | 1eedab8 | 2025-03-15 14:25:54 +0000 | [diff] [blame] | 27 | e820_next(&ctx, E820_RAM, ISA_START_ADDRESS); |
| 28 | e820_next(&ctx, E820_RESERVED, ISA_END_ADDRESS); |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 29 | |
| 30 | /* |
Simon Glass | f32df8d | 2025-03-15 14:25:55 +0000 | [diff] [blame] | 31 | * 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 Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 35 | */ |
Simon Glass | f32df8d | 2025-03-15 14:25:55 +0000 | [diff] [blame] | 36 | 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 Glass | 1eedab8 | 2025-03-15 14:25:54 +0000 | [diff] [blame] | 44 | 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 Meng | ef4c9e7 | 2019-08-29 02:53:06 -0700 | [diff] [blame] | 47 | |
| 48 | high_mem_size = qemu_get_high_memory_size(); |
Simon Glass | 1eedab8 | 2025-03-15 14:25:54 +0000 | [diff] [blame] | 49 | if (high_mem_size) |
| 50 | e820_add(&ctx, E820_RAM, SZ_4G, high_mem_size); |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 51 | |
Simon Glass | 1eedab8 | 2025-03-15 14:25:54 +0000 | [diff] [blame] | 52 | return e820_finish(&ctx); |
Tom Rini | bcb3c8d | 2016-05-06 10:40:22 -0400 | [diff] [blame] | 53 | } |