e820.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <efi_loader.h>
  7. #include <asm/e820.h>
  8. DECLARE_GLOBAL_DATA_PTR;
  9. /*
  10. * Install a default e820 table with 4 entries as follows:
  11. *
  12. * 0x000000-0x0a0000 Useable RAM
  13. * 0x0a0000-0x100000 Reserved for ISA
  14. * 0x100000-gd->ram_size Useable RAM
  15. * CONFIG_PCIE_ECAM_BASE PCIe ECAM
  16. */
  17. __weak unsigned int install_e820_map(unsigned int max_entries,
  18. struct e820_entry *entries)
  19. {
  20. entries[0].addr = 0;
  21. entries[0].size = ISA_START_ADDRESS;
  22. entries[0].type = E820_RAM;
  23. entries[1].addr = ISA_START_ADDRESS;
  24. entries[1].size = ISA_END_ADDRESS - ISA_START_ADDRESS;
  25. entries[1].type = E820_RESERVED;
  26. entries[2].addr = ISA_END_ADDRESS;
  27. entries[2].size = gd->ram_size - ISA_END_ADDRESS;
  28. entries[2].type = E820_RAM;
  29. entries[3].addr = CONFIG_PCIE_ECAM_BASE;
  30. entries[3].size = CONFIG_PCIE_ECAM_SIZE;
  31. entries[3].type = E820_RESERVED;
  32. return 4;
  33. }
  34. #if CONFIG_IS_ENABLED(EFI_LOADER)
  35. void efi_add_known_memory(void)
  36. {
  37. struct e820_entry e820[E820MAX];
  38. unsigned int i, num;
  39. u64 start, ram_top;
  40. int type;
  41. num = install_e820_map(ARRAY_SIZE(e820), e820);
  42. ram_top = (u64)gd->ram_top & ~EFI_PAGE_MASK;
  43. if (!ram_top)
  44. ram_top = 0x100000000ULL;
  45. for (i = 0; i < num; ++i) {
  46. start = e820[i].addr;
  47. switch (e820[i].type) {
  48. case E820_RAM:
  49. type = EFI_CONVENTIONAL_MEMORY;
  50. break;
  51. case E820_RESERVED:
  52. type = EFI_RESERVED_MEMORY_TYPE;
  53. break;
  54. case E820_ACPI:
  55. type = EFI_ACPI_RECLAIM_MEMORY;
  56. break;
  57. case E820_NVS:
  58. type = EFI_ACPI_MEMORY_NVS;
  59. break;
  60. case E820_UNUSABLE:
  61. default:
  62. type = EFI_UNUSABLE_MEMORY;
  63. break;
  64. }
  65. if (type == EFI_CONVENTIONAL_MEMORY) {
  66. efi_add_conventional_memory_map(start,
  67. start + e820[i].size,
  68. ram_top);
  69. } else {
  70. efi_add_memory_map(start, e820[i].size, type);
  71. }
  72. }
  73. }
  74. #endif /* CONFIG_IS_ENABLED(EFI_LOADER) */