fsp_support.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // SPDX-License-Identifier: Intel
  2. /*
  3. * Copyright (C) 2013, Intel Corporation
  4. * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
  5. */
  6. #include <common.h>
  7. #include <log.h>
  8. #include <asm/fsp/fsp_support.h>
  9. #include <asm/post.h>
  10. u32 fsp_get_usable_lowmem_top(const void *hob_list)
  11. {
  12. const struct hob_header *hdr;
  13. struct hob_res_desc *res_desc;
  14. phys_addr_t phys_start;
  15. u32 top;
  16. #ifdef CONFIG_FSP_BROKEN_HOB
  17. struct hob_mem_alloc *res_mem;
  18. phys_addr_t mem_base = 0;
  19. #endif
  20. /* Get the HOB list for processing */
  21. hdr = hob_list;
  22. /* * Collect memory ranges */
  23. top = FSP_LOWMEM_BASE;
  24. while (!end_of_hob(hdr)) {
  25. if (hdr->type == HOB_TYPE_RES_DESC) {
  26. res_desc = (struct hob_res_desc *)hdr;
  27. if (res_desc->type == RES_SYS_MEM) {
  28. phys_start = res_desc->phys_start;
  29. /* Need memory above 1MB to be collected here */
  30. if (phys_start >= FSP_LOWMEM_BASE &&
  31. phys_start < (phys_addr_t)FSP_HIGHMEM_BASE)
  32. top += (u32)(res_desc->len);
  33. }
  34. }
  35. #ifdef CONFIG_FSP_BROKEN_HOB
  36. /*
  37. * Find out the lowest memory base address allocated by FSP
  38. * for the boot service data
  39. */
  40. if (hdr->type == HOB_TYPE_MEM_ALLOC) {
  41. res_mem = (struct hob_mem_alloc *)hdr;
  42. if (!mem_base)
  43. mem_base = res_mem->mem_base;
  44. if (res_mem->mem_base < mem_base)
  45. mem_base = res_mem->mem_base;
  46. }
  47. #endif
  48. hdr = get_next_hob(hdr);
  49. }
  50. #ifdef CONFIG_FSP_BROKEN_HOB
  51. /*
  52. * Check whether the memory top address is below the FSP HOB list.
  53. * If not, use the lowest memory base address allocated by FSP as
  54. * the memory top address. This is to prevent U-Boot relocation
  55. * overwrites the important boot service data which is used by FSP,
  56. * otherwise the subsequent call to fsp_notify() will fail.
  57. */
  58. if (top > (u32)hob_list) {
  59. debug("Adjust memory top address due to a buggy FSP\n");
  60. top = (u32)mem_base;
  61. }
  62. #endif
  63. return top;
  64. }
  65. u64 fsp_get_usable_highmem_top(const void *hob_list)
  66. {
  67. const struct hob_header *hdr;
  68. struct hob_res_desc *res_desc;
  69. phys_addr_t phys_start;
  70. u64 top;
  71. /* Get the HOB list for processing */
  72. hdr = hob_list;
  73. /* Collect memory ranges */
  74. top = FSP_HIGHMEM_BASE;
  75. while (!end_of_hob(hdr)) {
  76. if (hdr->type == HOB_TYPE_RES_DESC) {
  77. res_desc = (struct hob_res_desc *)hdr;
  78. if (res_desc->type == RES_SYS_MEM) {
  79. phys_start = res_desc->phys_start;
  80. /* Need memory above 4GB to be collected here */
  81. if (phys_start >= (phys_addr_t)FSP_HIGHMEM_BASE)
  82. top += (u32)(res_desc->len);
  83. }
  84. }
  85. hdr = get_next_hob(hdr);
  86. }
  87. return top;
  88. }
  89. u64 fsp_get_reserved_mem_from_guid(const void *hob_list, u64 *len,
  90. const efi_guid_t *guid)
  91. {
  92. const struct hob_header *hdr;
  93. struct hob_res_desc *res_desc;
  94. /* Get the HOB list for processing */
  95. hdr = hob_list;
  96. /* Collect memory ranges */
  97. while (!end_of_hob(hdr)) {
  98. if (hdr->type == HOB_TYPE_RES_DESC) {
  99. res_desc = (struct hob_res_desc *)hdr;
  100. if (res_desc->type == RES_MEM_RESERVED) {
  101. if (!guidcmp(&res_desc->owner, guid)) {
  102. if (len)
  103. *len = (u32)(res_desc->len);
  104. return (u64)(res_desc->phys_start);
  105. }
  106. }
  107. }
  108. hdr = get_next_hob(hdr);
  109. }
  110. return 0;
  111. }
  112. u32 fsp_get_fsp_reserved_mem(const void *hob_list, u32 *len)
  113. {
  114. const efi_guid_t guid = FSP_HOB_RESOURCE_OWNER_FSP_GUID;
  115. u64 length;
  116. u32 base;
  117. base = (u32)fsp_get_reserved_mem_from_guid(hob_list,
  118. &length, &guid);
  119. if (len && base)
  120. *len = (u32)length;
  121. return base;
  122. }
  123. u32 fsp_get_tseg_reserved_mem(const void *hob_list, u32 *len)
  124. {
  125. const efi_guid_t guid = FSP_HOB_RESOURCE_OWNER_TSEG_GUID;
  126. u64 length;
  127. u32 base;
  128. base = (u32)fsp_get_reserved_mem_from_guid(hob_list,
  129. &length, &guid);
  130. if (len && base)
  131. *len = (u32)length;
  132. return base;
  133. }
  134. void *fsp_get_nvs_data(const void *hob_list, u32 *len)
  135. {
  136. const efi_guid_t guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
  137. return hob_get_guid_hob_data(hob_list, len, &guid);
  138. }
  139. void *fsp_get_var_nvs_data(const void *hob_list, u32 *len)
  140. {
  141. const efi_guid_t guid = FSP_VARIABLE_NV_DATA_HOB_GUID;
  142. return hob_get_guid_hob_data(hob_list, len, &guid);
  143. }
  144. void *fsp_get_bootloader_tmp_mem(const void *hob_list, u32 *len)
  145. {
  146. const efi_guid_t guid = FSP_BOOTLOADER_TEMP_MEM_HOB_GUID;
  147. return hob_get_guid_hob_data(hob_list, len, &guid);
  148. }
  149. void *fsp_get_graphics_info(const void *hob_list, u32 *len)
  150. {
  151. const efi_guid_t guid = FSP_GRAPHICS_INFO_HOB_GUID;
  152. return hob_get_guid_hob_data(hob_list, len, &guid);
  153. }