fsp_dram.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/fsp/fsp_support.h>
  8. #include <asm/e820.h>
  9. #include <asm/mrccache.h>
  10. #include <asm/post.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. int dram_init(void)
  13. {
  14. phys_size_t ram_size = 0;
  15. const struct hob_header *hdr;
  16. struct hob_res_desc *res_desc;
  17. hdr = gd->arch.hob_list;
  18. while (!end_of_hob(hdr)) {
  19. if (hdr->type == HOB_TYPE_RES_DESC) {
  20. res_desc = (struct hob_res_desc *)hdr;
  21. if (res_desc->type == RES_SYS_MEM ||
  22. res_desc->type == RES_MEM_RESERVED) {
  23. ram_size += res_desc->len;
  24. }
  25. }
  26. hdr = get_next_hob(hdr);
  27. }
  28. gd->ram_size = ram_size;
  29. post_code(POST_DRAM);
  30. #ifdef CONFIG_ENABLE_MRC_CACHE
  31. gd->arch.mrc_output = fsp_get_nvs_data(gd->arch.hob_list,
  32. &gd->arch.mrc_output_len);
  33. #endif
  34. return 0;
  35. }
  36. int dram_init_banksize(void)
  37. {
  38. gd->bd->bi_dram[0].start = 0;
  39. gd->bd->bi_dram[0].size = gd->ram_size;
  40. return 0;
  41. }
  42. /*
  43. * This function looks for the highest region of memory lower than 4GB which
  44. * has enough space for U-Boot where U-Boot is aligned on a page boundary.
  45. * It overrides the default implementation found elsewhere which simply
  46. * picks the end of ram, wherever that may be. The location of the stack,
  47. * the relocation address, and how far U-Boot is moved by relocation are
  48. * set in the global data structure.
  49. */
  50. ulong board_get_usable_ram_top(ulong total_size)
  51. {
  52. return fsp_get_usable_lowmem_top(gd->arch.hob_list);
  53. }
  54. unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
  55. {
  56. unsigned 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. return num_entries;
  79. }