fsp_dram.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <asm/fsp/fsp_support.h>
  7. #include <asm/e820.h>
  8. #include <asm/mrccache.h>
  9. #include <asm/post.h>
  10. DECLARE_GLOBAL_DATA_PTR;
  11. int dram_init(void)
  12. {
  13. phys_size_t ram_size = 0;
  14. const struct hob_header *hdr;
  15. struct hob_res_desc *res_desc;
  16. hdr = gd->arch.hob_list;
  17. while (!end_of_hob(hdr)) {
  18. if (hdr->type == HOB_TYPE_RES_DESC) {
  19. res_desc = (struct hob_res_desc *)hdr;
  20. if (res_desc->type == RES_SYS_MEM ||
  21. res_desc->type == RES_MEM_RESERVED) {
  22. ram_size += res_desc->len;
  23. }
  24. }
  25. hdr = get_next_hob(hdr);
  26. }
  27. gd->ram_size = ram_size;
  28. post_code(POST_DRAM);
  29. #ifdef CONFIG_ENABLE_MRC_CACHE
  30. gd->arch.mrc_output = fsp_get_nvs_data(gd->arch.hob_list,
  31. &gd->arch.mrc_output_len);
  32. #endif
  33. return 0;
  34. }
  35. int dram_init_banksize(void)
  36. {
  37. gd->bd->bi_dram[0].start = 0;
  38. gd->bd->bi_dram[0].size = gd->ram_size;
  39. return 0;
  40. }
  41. /*
  42. * This function looks for the highest region of memory lower than 4GB which
  43. * has enough space for U-Boot where U-Boot is aligned on a page boundary.
  44. * It overrides the default implementation found elsewhere which simply
  45. * picks the end of ram, wherever that may be. The location of the stack,
  46. * the relocation address, and how far U-Boot is moved by relocation are
  47. * set in the global data structure.
  48. */
  49. ulong board_get_usable_ram_top(ulong total_size)
  50. {
  51. return fsp_get_usable_lowmem_top(gd->arch.hob_list);
  52. }
  53. unsigned int install_e820_map(unsigned int max_entries,
  54. struct e820_entry *entries)
  55. {
  56. unsigned int num_entries = 0;
  57. const struct hob_header *hdr;
  58. struct hob_res_desc *res_desc;
  59. hdr = gd->arch.hob_list;
  60. while (!end_of_hob(hdr)) {
  61. if (hdr->type == HOB_TYPE_RES_DESC) {
  62. res_desc = (struct hob_res_desc *)hdr;
  63. entries[num_entries].addr = res_desc->phys_start;
  64. entries[num_entries].size = res_desc->len;
  65. if (res_desc->type == RES_SYS_MEM)
  66. entries[num_entries].type = E820_RAM;
  67. else if (res_desc->type == RES_MEM_RESERVED)
  68. entries[num_entries].type = E820_RESERVED;
  69. num_entries++;
  70. }
  71. hdr = get_next_hob(hdr);
  72. }
  73. /* Mark PCIe ECAM address range as reserved */
  74. entries[num_entries].addr = CONFIG_PCIE_ECAM_BASE;
  75. entries[num_entries].size = CONFIG_PCIE_ECAM_SIZE;
  76. entries[num_entries].type = E820_RESERVED;
  77. num_entries++;
  78. #ifdef CONFIG_HAVE_ACPI_RESUME
  79. /*
  80. * Everything between U-Boot's stack and ram top needs to be
  81. * reserved in order for ACPI S3 resume to work.
  82. */
  83. entries[num_entries].addr = gd->start_addr_sp - CONFIG_STACK_SIZE;
  84. entries[num_entries].size = gd->ram_top - gd->start_addr_sp + \
  85. CONFIG_STACK_SIZE;
  86. entries[num_entries].type = E820_RESERVED;
  87. num_entries++;
  88. #endif
  89. return num_entries;
  90. }