e820.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * QEMU x86 specific E820 table generation
  4. *
  5. * (C) Copyright 2015 Miao Yan <yanmiaobest@gmail.com>
  6. * (C) Copyright 2019 Bin Meng <bmeng.cn@gmail.com>
  7. */
  8. #include <common.h>
  9. #include <env_internal.h>
  10. #include <malloc.h>
  11. #include <asm/e820.h>
  12. #include <asm/arch/qemu.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. unsigned int install_e820_map(unsigned int max_entries,
  15. struct e820_entry *entries)
  16. {
  17. u64 high_mem_size;
  18. int n = 0;
  19. entries[n].addr = 0;
  20. entries[n].size = ISA_START_ADDRESS;
  21. entries[n].type = E820_RAM;
  22. n++;
  23. entries[n].addr = ISA_START_ADDRESS;
  24. entries[n].size = ISA_END_ADDRESS - ISA_START_ADDRESS;
  25. entries[n].type = E820_RESERVED;
  26. n++;
  27. /*
  28. * since we use memalign(malloc) to allocate high memory for
  29. * storing ACPI tables, we need to reserve them in e820 tables,
  30. * otherwise kernel will reclaim them and data will be corrupted
  31. */
  32. entries[n].addr = ISA_END_ADDRESS;
  33. entries[n].size = gd->relocaddr - TOTAL_MALLOC_LEN - ISA_END_ADDRESS;
  34. entries[n].type = E820_RAM;
  35. n++;
  36. /* for simplicity, reserve entire malloc space */
  37. entries[n].addr = gd->relocaddr - TOTAL_MALLOC_LEN;
  38. entries[n].size = TOTAL_MALLOC_LEN;
  39. entries[n].type = E820_RESERVED;
  40. n++;
  41. entries[n].addr = gd->relocaddr;
  42. entries[n].size = qemu_get_low_memory_size() - gd->relocaddr;
  43. entries[n].type = E820_RESERVED;
  44. n++;
  45. entries[n].addr = CONFIG_PCIE_ECAM_BASE;
  46. entries[n].size = CONFIG_PCIE_ECAM_SIZE;
  47. entries[n].type = E820_RESERVED;
  48. n++;
  49. high_mem_size = qemu_get_high_memory_size();
  50. if (high_mem_size) {
  51. entries[n].addr = SZ_4G;
  52. entries[n].size = high_mem_size;
  53. entries[n].type = E820_RAM;
  54. n++;
  55. }
  56. return n;
  57. }