fsp_dram.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/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. return 0;
  30. }
  31. void dram_init_banksize(void)
  32. {
  33. gd->bd->bi_dram[0].start = 0;
  34. gd->bd->bi_dram[0].size = gd->ram_size;
  35. }
  36. /*
  37. * This function looks for the highest region of memory lower than 4GB which
  38. * has enough space for U-Boot where U-Boot is aligned on a page boundary.
  39. * It overrides the default implementation found elsewhere which simply
  40. * picks the end of ram, wherever that may be. The location of the stack,
  41. * the relocation address, and how far U-Boot is moved by relocation are
  42. * set in the global data structure.
  43. */
  44. ulong board_get_usable_ram_top(ulong total_size)
  45. {
  46. return fsp_get_usable_lowmem_top(gd->arch.hob_list);
  47. }
  48. unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
  49. {
  50. unsigned num_entries = 0;
  51. const struct hob_header *hdr;
  52. struct hob_res_desc *res_desc;
  53. hdr = gd->arch.hob_list;
  54. while (!end_of_hob(hdr)) {
  55. if (hdr->type == HOB_TYPE_RES_DESC) {
  56. res_desc = (struct hob_res_desc *)hdr;
  57. entries[num_entries].addr = res_desc->phys_start;
  58. entries[num_entries].size = res_desc->len;
  59. if (res_desc->type == RES_SYS_MEM)
  60. entries[num_entries].type = E820_RAM;
  61. else if (res_desc->type == RES_MEM_RESERVED)
  62. entries[num_entries].type = E820_RESERVED;
  63. }
  64. hdr = get_next_hob(hdr);
  65. num_entries++;
  66. }
  67. /* Mark PCIe ECAM address range as reserved */
  68. entries[num_entries].addr = CONFIG_PCIE_ECAM_BASE;
  69. entries[num_entries].size = CONFIG_PCIE_ECAM_SIZE;
  70. entries[num_entries].type = E820_RESERVED;
  71. num_entries++;
  72. return num_entries;
  73. }