fsp_dram.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. void dram_init_banksize(void)
  37. {
  38. gd->bd->bi_dram[0].start = 0;
  39. gd->bd->bi_dram[0].size = gd->ram_size;
  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 install_e820_map(unsigned max_entries, struct e820entry *entries)
  54. {
  55. unsigned num_entries = 0;
  56. const struct hob_header *hdr;
  57. struct hob_res_desc *res_desc;
  58. hdr = gd->arch.hob_list;
  59. while (!end_of_hob(hdr)) {
  60. if (hdr->type == HOB_TYPE_RES_DESC) {
  61. res_desc = (struct hob_res_desc *)hdr;
  62. entries[num_entries].addr = res_desc->phys_start;
  63. entries[num_entries].size = res_desc->len;
  64. if (res_desc->type == RES_SYS_MEM)
  65. entries[num_entries].type = E820_RAM;
  66. else if (res_desc->type == RES_MEM_RESERVED)
  67. entries[num_entries].type = E820_RESERVED;
  68. num_entries++;
  69. }
  70. hdr = get_next_hob(hdr);
  71. }
  72. /* Mark PCIe ECAM address range as reserved */
  73. entries[num_entries].addr = CONFIG_PCIE_ECAM_BASE;
  74. entries[num_entries].size = CONFIG_PCIE_ECAM_SIZE;
  75. entries[num_entries].type = E820_RESERVED;
  76. num_entries++;
  77. return num_entries;
  78. }