HobLib.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /** @file
  2. HOB Library implementation for Dxe Phase with DebugLib dependency removed
  3. Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
  4. Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #define ASSERT(Expression) \
  8. do { \
  9. if (!(Expression)) { \
  10. CpuDeadLoop (); \
  11. } \
  12. } while (FALSE)
  13. #include <PiDxe.h>
  14. #include <Guid/HobList.h>
  15. #include <Library/HobLib.h>
  16. #include <Library/UefiLib.h>
  17. #include <Library/BaseMemoryLib.h>
  18. VOID *mHobList = NULL;
  19. /**
  20. The constructor function caches the pointer to HOB list.
  21. The constructor function gets the start address of HOB list from system configuration table.
  22. @param ImageHandle The firmware allocated handle for the EFI image.
  23. @param SystemTable A pointer to the EFI System Table.
  24. @retval EFI_SUCCESS The constructor successfully gets HobList.
  25. @retval Other value The constructor can't get HobList.
  26. **/
  27. EFI_STATUS
  28. EFIAPI
  29. HobLibConstructor (
  30. IN EFI_HANDLE ImageHandle,
  31. IN EFI_SYSTEM_TABLE *SystemTable
  32. )
  33. {
  34. UINTN Index;
  35. for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {
  36. if (CompareGuid (&gEfiHobListGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {
  37. mHobList = SystemTable->ConfigurationTable[Index].VendorTable;
  38. return EFI_SUCCESS;
  39. }
  40. }
  41. return EFI_NOT_FOUND;
  42. }
  43. /**
  44. Returns the pointer to the HOB list.
  45. This function returns the pointer to first HOB in the list.
  46. For PEI phase, the PEI service GetHobList() can be used to retrieve the pointer
  47. to the HOB list. For the DXE phase, the HOB list pointer can be retrieved through
  48. the EFI System Table by looking up theHOB list GUID in the System Configuration Table.
  49. Since the System Configuration Table does not exist that the time the DXE Core is
  50. launched, the DXE Core uses a global variable from the DXE Core Entry Point Library
  51. to manage the pointer to the HOB list.
  52. If the pointer to the HOB list is NULL, then ASSERT().
  53. @return The pointer to the HOB list.
  54. **/
  55. VOID *
  56. EFIAPI
  57. GetHobList (
  58. VOID
  59. )
  60. {
  61. ASSERT (mHobList != NULL);
  62. return mHobList;
  63. }
  64. /**
  65. Returns the next instance of a HOB type from the starting HOB.
  66. This function searches the first instance of a HOB type from the starting HOB pointer.
  67. If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
  68. In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
  69. unconditionally: it returns HobStart back if HobStart itself meets the requirement;
  70. caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
  71. If HobStart is NULL, then ASSERT().
  72. @param Type The HOB type to return.
  73. @param HobStart The starting HOB pointer to search from.
  74. @return The next instance of a HOB type from the starting HOB.
  75. **/
  76. VOID *
  77. EFIAPI
  78. GetNextHob (
  79. IN UINT16 Type,
  80. IN CONST VOID *HobStart
  81. )
  82. {
  83. EFI_PEI_HOB_POINTERS Hob;
  84. ASSERT (HobStart != NULL);
  85. Hob.Raw = (UINT8 *)HobStart;
  86. //
  87. // Parse the HOB list until end of list or matching type is found.
  88. //
  89. while (!END_OF_HOB_LIST (Hob)) {
  90. if (Hob.Header->HobType == Type) {
  91. return Hob.Raw;
  92. }
  93. Hob.Raw = GET_NEXT_HOB (Hob);
  94. }
  95. return NULL;
  96. }
  97. /**
  98. Returns the first instance of a HOB type among the whole HOB list.
  99. This function searches the first instance of a HOB type among the whole HOB list.
  100. If there does not exist such HOB type in the HOB list, it will return NULL.
  101. If the pointer to the HOB list is NULL, then ASSERT().
  102. @param Type The HOB type to return.
  103. @return The next instance of a HOB type from the starting HOB.
  104. **/
  105. VOID *
  106. EFIAPI
  107. GetFirstHob (
  108. IN UINT16 Type
  109. )
  110. {
  111. VOID *HobList;
  112. HobList = GetHobList ();
  113. return GetNextHob (Type, HobList);
  114. }
  115. /**
  116. Returns the next instance of the matched GUID HOB from the starting HOB.
  117. This function searches the first instance of a HOB from the starting HOB pointer.
  118. Such HOB should satisfy two conditions:
  119. its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
  120. If there does not exist such HOB from the starting HOB pointer, it will return NULL.
  121. Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
  122. to extract the data section and its size information, respectively.
  123. In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
  124. unconditionally: it returns HobStart back if HobStart itself meets the requirement;
  125. caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
  126. If Guid is NULL, then ASSERT().
  127. If HobStart is NULL, then ASSERT().
  128. @param Guid The GUID to match with in the HOB list.
  129. @param HobStart A pointer to a Guid.
  130. @return The next instance of the matched GUID HOB from the starting HOB.
  131. **/
  132. VOID *
  133. EFIAPI
  134. GetNextGuidHob (
  135. IN CONST EFI_GUID *Guid,
  136. IN CONST VOID *HobStart
  137. )
  138. {
  139. EFI_PEI_HOB_POINTERS GuidHob;
  140. GuidHob.Raw = (UINT8 *)HobStart;
  141. while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {
  142. if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
  143. break;
  144. }
  145. GuidHob.Raw = GET_NEXT_HOB (GuidHob);
  146. }
  147. return GuidHob.Raw;
  148. }
  149. /**
  150. Returns the first instance of the matched GUID HOB among the whole HOB list.
  151. This function searches the first instance of a HOB among the whole HOB list.
  152. Such HOB should satisfy two conditions:
  153. its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
  154. If there does not exist such HOB from the starting HOB pointer, it will return NULL.
  155. Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
  156. to extract the data section and its size information, respectively.
  157. If the pointer to the HOB list is NULL, then ASSERT().
  158. If Guid is NULL, then ASSERT().
  159. @param Guid The GUID to match with in the HOB list.
  160. @return The first instance of the matched GUID HOB among the whole HOB list.
  161. **/
  162. VOID *
  163. EFIAPI
  164. GetFirstGuidHob (
  165. IN CONST EFI_GUID *Guid
  166. )
  167. {
  168. VOID *HobList;
  169. HobList = GetHobList ();
  170. return GetNextGuidHob (Guid, HobList);
  171. }
  172. /**
  173. Get the system boot mode from the HOB list.
  174. This function returns the system boot mode information from the
  175. PHIT HOB in HOB list.
  176. If the pointer to the HOB list is NULL, then ASSERT().
  177. @param VOID
  178. @return The Boot Mode.
  179. **/
  180. EFI_BOOT_MODE
  181. EFIAPI
  182. GetBootModeHob (
  183. VOID
  184. )
  185. {
  186. EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
  187. HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *)GetHobList ();
  188. return HandOffHob->BootMode;
  189. }
  190. /**
  191. Builds a HOB for a loaded PE32 module.
  192. This function builds a HOB for a loaded PE32 module.
  193. It can only be invoked during PEI phase;
  194. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  195. If ModuleName is NULL, then ASSERT().
  196. If there is no additional space for HOB creation, then ASSERT().
  197. @param ModuleName The GUID File Name of the module.
  198. @param MemoryAllocationModule The 64 bit physical address of the module.
  199. @param ModuleLength The length of the module in bytes.
  200. @param EntryPoint The 64 bit physical address of the module entry point.
  201. **/
  202. VOID
  203. EFIAPI
  204. BuildModuleHob (
  205. IN CONST EFI_GUID *ModuleName,
  206. IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
  207. IN UINT64 ModuleLength,
  208. IN EFI_PHYSICAL_ADDRESS EntryPoint
  209. )
  210. {
  211. //
  212. // PEI HOB is read only for DXE phase
  213. //
  214. ASSERT (FALSE);
  215. }
  216. /**
  217. Builds a HOB that describes a chunk of system memory.
  218. This function builds a HOB that describes a chunk of system memory.
  219. It can only be invoked during PEI phase;
  220. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  221. If there is no additional space for HOB creation, then ASSERT().
  222. @param ResourceType The type of resource described by this HOB.
  223. @param ResourceAttribute The resource attributes of the memory described by this HOB.
  224. @param PhysicalStart The 64 bit physical address of memory described by this HOB.
  225. @param NumberOfBytes The length of the memory described by this HOB in bytes.
  226. **/
  227. VOID
  228. EFIAPI
  229. BuildResourceDescriptorHob (
  230. IN EFI_RESOURCE_TYPE ResourceType,
  231. IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
  232. IN EFI_PHYSICAL_ADDRESS PhysicalStart,
  233. IN UINT64 NumberOfBytes
  234. )
  235. {
  236. //
  237. // PEI HOB is read only for DXE phase
  238. //
  239. ASSERT (FALSE);
  240. }
  241. /**
  242. Builds a customized HOB tagged with a GUID for identification and returns
  243. the start address of GUID HOB data.
  244. This function builds a customized HOB tagged with a GUID for identification
  245. and returns the start address of GUID HOB data so that caller can fill the customized data.
  246. The HOB Header and Name field is already stripped.
  247. It can only be invoked during PEI phase;
  248. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  249. If Guid is NULL, then ASSERT().
  250. If there is no additional space for HOB creation, then ASSERT().
  251. If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
  252. HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
  253. @param Guid The GUID to tag the customized HOB.
  254. @param DataLength The size of the data payload for the GUID HOB.
  255. @retval NULL The GUID HOB could not be allocated.
  256. @retval others The start address of GUID HOB data.
  257. **/
  258. VOID *
  259. EFIAPI
  260. BuildGuidHob (
  261. IN CONST EFI_GUID *Guid,
  262. IN UINTN DataLength
  263. )
  264. {
  265. //
  266. // PEI HOB is read only for DXE phase
  267. //
  268. ASSERT (FALSE);
  269. return NULL;
  270. }
  271. /**
  272. Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
  273. data field, and returns the start address of the GUID HOB data.
  274. This function builds a customized HOB tagged with a GUID for identification and copies the input
  275. data to the HOB data field and returns the start address of the GUID HOB data. It can only be
  276. invoked during PEI phase; for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  277. The HOB Header and Name field is already stripped.
  278. It can only be invoked during PEI phase;
  279. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  280. If Guid is NULL, then ASSERT().
  281. If Data is NULL and DataLength > 0, then ASSERT().
  282. If there is no additional space for HOB creation, then ASSERT().
  283. If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
  284. HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
  285. @param Guid The GUID to tag the customized HOB.
  286. @param Data The data to be copied into the data field of the GUID HOB.
  287. @param DataLength The size of the data payload for the GUID HOB.
  288. @retval NULL The GUID HOB could not be allocated.
  289. @retval others The start address of GUID HOB data.
  290. **/
  291. VOID *
  292. EFIAPI
  293. BuildGuidDataHob (
  294. IN CONST EFI_GUID *Guid,
  295. IN VOID *Data,
  296. IN UINTN DataLength
  297. )
  298. {
  299. //
  300. // PEI HOB is read only for DXE phase
  301. //
  302. ASSERT (FALSE);
  303. return NULL;
  304. }
  305. /**
  306. Builds a Firmware Volume HOB.
  307. This function builds a Firmware Volume HOB.
  308. It can only be invoked during PEI phase;
  309. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  310. If there is no additional space for HOB creation, then ASSERT().
  311. If the FvImage buffer is not at its required alignment, then ASSERT().
  312. @param BaseAddress The base address of the Firmware Volume.
  313. @param Length The size of the Firmware Volume in bytes.
  314. **/
  315. VOID
  316. EFIAPI
  317. BuildFvHob (
  318. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  319. IN UINT64 Length
  320. )
  321. {
  322. //
  323. // PEI HOB is read only for DXE phase
  324. //
  325. ASSERT (FALSE);
  326. }
  327. /**
  328. Builds a EFI_HOB_TYPE_FV2 HOB.
  329. This function builds a EFI_HOB_TYPE_FV2 HOB.
  330. It can only be invoked during PEI phase;
  331. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  332. If there is no additional space for HOB creation, then ASSERT().
  333. If the FvImage buffer is not at its required alignment, then ASSERT().
  334. @param BaseAddress The base address of the Firmware Volume.
  335. @param Length The size of the Firmware Volume in bytes.
  336. @param FvName The name of the Firmware Volume.
  337. @param FileName The name of the file.
  338. **/
  339. VOID
  340. EFIAPI
  341. BuildFv2Hob (
  342. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  343. IN UINT64 Length,
  344. IN CONST EFI_GUID *FvName,
  345. IN CONST EFI_GUID *FileName
  346. )
  347. {
  348. ASSERT (FALSE);
  349. }
  350. /**
  351. Builds a EFI_HOB_TYPE_FV3 HOB.
  352. This function builds a EFI_HOB_TYPE_FV3 HOB.
  353. It can only be invoked during PEI phase;
  354. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  355. If there is no additional space for HOB creation, then ASSERT().
  356. If the FvImage buffer is not at its required alignment, then ASSERT().
  357. @param BaseAddress The base address of the Firmware Volume.
  358. @param Length The size of the Firmware Volume in bytes.
  359. @param AuthenticationStatus The authentication status.
  360. @param ExtractedFv TRUE if the FV was extracted as a file within
  361. another firmware volume. FALSE otherwise.
  362. @param FvName The name of the Firmware Volume.
  363. Valid only if IsExtractedFv is TRUE.
  364. @param FileName The name of the file.
  365. Valid only if IsExtractedFv is TRUE.
  366. **/
  367. VOID
  368. EFIAPI
  369. BuildFv3Hob (
  370. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  371. IN UINT64 Length,
  372. IN UINT32 AuthenticationStatus,
  373. IN BOOLEAN ExtractedFv,
  374. IN CONST EFI_GUID *FvName OPTIONAL,
  375. IN CONST EFI_GUID *FileName OPTIONAL
  376. )
  377. {
  378. ASSERT (FALSE);
  379. }
  380. /**
  381. Builds a Capsule Volume HOB.
  382. This function builds a Capsule Volume HOB.
  383. It can only be invoked during PEI phase;
  384. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  385. If the platform does not support Capsule Volume HOBs, then ASSERT().
  386. If there is no additional space for HOB creation, then ASSERT().
  387. @param BaseAddress The base address of the Capsule Volume.
  388. @param Length The size of the Capsule Volume in bytes.
  389. **/
  390. VOID
  391. EFIAPI
  392. BuildCvHob (
  393. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  394. IN UINT64 Length
  395. )
  396. {
  397. //
  398. // PEI HOB is read only for DXE phase
  399. //
  400. ASSERT (FALSE);
  401. }
  402. /**
  403. Builds a HOB for the CPU.
  404. This function builds a HOB for the CPU.
  405. It can only be invoked during PEI phase;
  406. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  407. If there is no additional space for HOB creation, then ASSERT().
  408. @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
  409. @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
  410. **/
  411. VOID
  412. EFIAPI
  413. BuildCpuHob (
  414. IN UINT8 SizeOfMemorySpace,
  415. IN UINT8 SizeOfIoSpace
  416. )
  417. {
  418. //
  419. // PEI HOB is read only for DXE phase
  420. //
  421. ASSERT (FALSE);
  422. }
  423. /**
  424. Builds a HOB for the Stack.
  425. This function builds a HOB for the stack.
  426. It can only be invoked during PEI phase;
  427. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  428. If there is no additional space for HOB creation, then ASSERT().
  429. @param BaseAddress The 64 bit physical address of the Stack.
  430. @param Length The length of the stack in bytes.
  431. **/
  432. VOID
  433. EFIAPI
  434. BuildStackHob (
  435. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  436. IN UINT64 Length
  437. )
  438. {
  439. //
  440. // PEI HOB is read only for DXE phase
  441. //
  442. ASSERT (FALSE);
  443. }
  444. /**
  445. Builds a HOB for the BSP store.
  446. This function builds a HOB for BSP store.
  447. It can only be invoked during PEI phase;
  448. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  449. If there is no additional space for HOB creation, then ASSERT().
  450. @param BaseAddress The 64 bit physical address of the BSP.
  451. @param Length The length of the BSP store in bytes.
  452. @param MemoryType Type of memory allocated by this HOB.
  453. **/
  454. VOID
  455. EFIAPI
  456. BuildBspStoreHob (
  457. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  458. IN UINT64 Length,
  459. IN EFI_MEMORY_TYPE MemoryType
  460. )
  461. {
  462. //
  463. // PEI HOB is read only for DXE phase
  464. //
  465. ASSERT (FALSE);
  466. }
  467. /**
  468. Builds a HOB for the memory allocation.
  469. This function builds a HOB for the memory allocation.
  470. It can only be invoked during PEI phase;
  471. for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
  472. If there is no additional space for HOB creation, then ASSERT().
  473. @param BaseAddress The 64 bit physical address of the memory.
  474. @param Length The length of the memory allocation in bytes.
  475. @param MemoryType Type of memory allocated by this HOB.
  476. **/
  477. VOID
  478. EFIAPI
  479. BuildMemoryAllocationHob (
  480. IN EFI_PHYSICAL_ADDRESS BaseAddress,
  481. IN UINT64 Length,
  482. IN EFI_MEMORY_TYPE MemoryType
  483. )
  484. {
  485. //
  486. // PEI HOB is read only for DXE phase
  487. //
  488. ASSERT (FALSE);
  489. }