fsp_dram.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 <handoff.h>
  7. #include <init.h>
  8. #include <asm/fsp/fsp_support.h>
  9. #include <asm/e820.h>
  10. #include <asm/mrccache.h>
  11. #include <asm/post.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. int fsp_scan_for_ram_size(void)
  14. {
  15. phys_size_t ram_size = 0;
  16. const struct hob_header *hdr;
  17. struct hob_res_desc *res_desc;
  18. hdr = gd->arch.hob_list;
  19. while (!end_of_hob(hdr)) {
  20. if (hdr->type == HOB_TYPE_RES_DESC) {
  21. res_desc = (struct hob_res_desc *)hdr;
  22. if (res_desc->type == RES_SYS_MEM ||
  23. res_desc->type == RES_MEM_RESERVED)
  24. ram_size += res_desc->len;
  25. }
  26. hdr = get_next_hob(hdr);
  27. }
  28. gd->ram_size = ram_size;
  29. post_code(POST_DRAM);
  30. return 0;
  31. };
  32. int dram_init_banksize(void)
  33. {
  34. gd->bd->bi_dram[0].start = 0;
  35. gd->bd->bi_dram[0].size = gd->ram_size;
  36. return 0;
  37. }
  38. unsigned int install_e820_map(unsigned int max_entries,
  39. struct e820_entry *entries)
  40. {
  41. unsigned int num_entries = 0;
  42. const struct hob_header *hdr;
  43. struct hob_res_desc *res_desc;
  44. hdr = gd->arch.hob_list;
  45. while (!end_of_hob(hdr)) {
  46. if (hdr->type == HOB_TYPE_RES_DESC) {
  47. res_desc = (struct hob_res_desc *)hdr;
  48. entries[num_entries].addr = res_desc->phys_start;
  49. entries[num_entries].size = res_desc->len;
  50. if (res_desc->type == RES_SYS_MEM)
  51. entries[num_entries].type = E820_RAM;
  52. else if (res_desc->type == RES_MEM_RESERVED)
  53. entries[num_entries].type = E820_RESERVED;
  54. num_entries++;
  55. }
  56. hdr = get_next_hob(hdr);
  57. }
  58. /* Mark PCIe ECAM address range as reserved */
  59. entries[num_entries].addr = CONFIG_PCIE_ECAM_BASE;
  60. entries[num_entries].size = CONFIG_PCIE_ECAM_SIZE;
  61. entries[num_entries].type = E820_RESERVED;
  62. num_entries++;
  63. #ifdef CONFIG_HAVE_ACPI_RESUME
  64. /*
  65. * Everything between U-Boot's stack and ram top needs to be
  66. * reserved in order for ACPI S3 resume to work.
  67. */
  68. entries[num_entries].addr = gd->start_addr_sp - CONFIG_STACK_SIZE;
  69. entries[num_entries].size = gd->ram_top - gd->start_addr_sp +
  70. CONFIG_STACK_SIZE;
  71. entries[num_entries].type = E820_RESERVED;
  72. num_entries++;
  73. #endif
  74. return num_entries;
  75. }
  76. #if CONFIG_IS_ENABLED(HANDOFF) && IS_ENABLED(CONFIG_USE_HOB)
  77. int handoff_arch_save(struct spl_handoff *ho)
  78. {
  79. ho->arch.usable_ram_top = fsp_get_usable_lowmem_top(gd->arch.hob_list);
  80. ho->arch.hob_list = gd->arch.hob_list;
  81. return 0;
  82. }
  83. #endif