PeiServicesLib.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. /** @file
  2. Implementation for PEI Services Library.
  3. Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiPei.h>
  7. #include <Library/EmuMagicPageLib.h>
  8. #include <Library/PeiServicesLib.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/BaseMemoryLib.h>
  11. EFI_STATUS
  12. SecFfsFindNextFile (
  13. IN EFI_FV_FILETYPE SearchType,
  14. IN EFI_PEI_FV_HANDLE VolumeHandle,
  15. IN OUT EFI_PEI_FILE_HANDLE *FileHandle
  16. );
  17. EFI_STATUS
  18. SecFfsFindSectionData (
  19. IN EFI_SECTION_TYPE SectionType,
  20. IN EFI_PEI_FILE_HANDLE FileHandle,
  21. OUT VOID **SectionData
  22. );
  23. /**
  24. This service enables a given PEIM to register an interface into the PEI Foundation.
  25. @param PpiList A pointer to the list of interfaces that the caller shall install.
  26. @retval EFI_SUCCESS The interface was successfully installed.
  27. @retval EFI_INVALID_PARAMETER The PpiList pointer is NULL.
  28. @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
  29. EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
  30. @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
  31. **/
  32. EFI_STATUS
  33. EFIAPI
  34. PeiServicesInstallPpi (
  35. IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList
  36. )
  37. {
  38. ASSERT (FALSE);
  39. return EFI_OUT_OF_RESOURCES;
  40. }
  41. /**
  42. This service enables PEIMs to replace an entry in the PPI database with an alternate entry.
  43. @param OldPpi The pointer to the old PEI PPI Descriptors.
  44. @param NewPpi The pointer to the new PEI PPI Descriptors.
  45. @retval EFI_SUCCESS The interface was successfully installed.
  46. @retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL.
  47. @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
  48. EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
  49. @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
  50. @retval EFI_NOT_FOUND The PPI for which the reinstallation was requested has not been
  51. installed.
  52. **/
  53. EFI_STATUS
  54. EFIAPI
  55. PeiServicesReInstallPpi (
  56. IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi,
  57. IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi
  58. )
  59. {
  60. ASSERT (FALSE);
  61. return EFI_OUT_OF_RESOURCES;
  62. }
  63. /**
  64. This service enables PEIMs to discover a given instance of an interface.
  65. So this is, well a hack, so we can reuse the same libraries as the PEI Core
  66. for XIP modules....
  67. @param Guid A pointer to the GUID whose corresponding interface needs to be
  68. found.
  69. @param Instance The N-th instance of the interface that is required.
  70. @param PpiDescriptor A pointer to instance of the EFI_PEI_PPI_DESCRIPTOR.
  71. @param Ppi A pointer to the instance of the interface.
  72. @retval EFI_SUCCESS The interface was successfully returned.
  73. @retval EFI_NOT_FOUND The PPI descriptor is not found in the database.
  74. **/
  75. EFI_STATUS
  76. EFIAPI
  77. PeiServicesLocatePpi (
  78. IN CONST EFI_GUID *Guid,
  79. IN UINTN Instance,
  80. IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
  81. IN OUT VOID **Ppi
  82. )
  83. {
  84. EFI_PEI_PPI_DESCRIPTOR *PpiList;
  85. if (Instance != 0) {
  86. return EFI_NOT_FOUND;
  87. }
  88. for (PpiList = EMU_MAGIC_PAGE ()->PpiList; ; PpiList++) {
  89. if (CompareGuid (PpiList->Guid, Guid)) {
  90. if (PpiDescriptor != NULL) {
  91. *PpiDescriptor = PpiList;
  92. }
  93. if (Ppi != NULL) {
  94. *Ppi = PpiList->Ppi;
  95. }
  96. return EFI_SUCCESS;
  97. }
  98. if ((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) {
  99. break;
  100. }
  101. }
  102. return EFI_NOT_FOUND;
  103. }
  104. /**
  105. This service enables PEIMs to register a given service to be invoked when another service is
  106. installed or reinstalled.
  107. @param NotifyList A pointer to the list of notification interfaces
  108. that the caller shall install.
  109. @retval EFI_SUCCESS The interface was successfully installed.
  110. @retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL.
  111. @retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do
  112. not have the EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES
  113. bit set in the Flags field.
  114. @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
  115. **/
  116. EFI_STATUS
  117. EFIAPI
  118. PeiServicesNotifyPpi (
  119. IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList
  120. )
  121. {
  122. ASSERT (FALSE);
  123. return EFI_OUT_OF_RESOURCES;
  124. }
  125. /**
  126. This service enables PEIMs to ascertain the present value of the boot mode.
  127. @param BootMode A pointer to contain the value of the boot mode.
  128. @retval EFI_SUCCESS The boot mode was returned successfully.
  129. @retval EFI_INVALID_PARAMETER BootMode is NULL.
  130. **/
  131. EFI_STATUS
  132. EFIAPI
  133. PeiServicesGetBootMode (
  134. OUT EFI_BOOT_MODE *BootMode
  135. )
  136. {
  137. ASSERT (FALSE);
  138. return EFI_OUT_OF_RESOURCES;
  139. }
  140. /**
  141. This service enables PEIMs to update the boot mode variable.
  142. @param BootMode The value of the boot mode to set.
  143. @retval EFI_SUCCESS The value was successfully updated
  144. **/
  145. EFI_STATUS
  146. EFIAPI
  147. PeiServicesSetBootMode (
  148. IN EFI_BOOT_MODE BootMode
  149. )
  150. {
  151. ASSERT (FALSE);
  152. return EFI_OUT_OF_RESOURCES;
  153. }
  154. /**
  155. This service enables a PEIM to ascertain the address of the list of HOBs in memory.
  156. @param HobList A pointer to the list of HOBs that the PEI Foundation
  157. will initialize.
  158. @retval EFI_SUCCESS The list was successfully returned.
  159. @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
  160. **/
  161. EFI_STATUS
  162. EFIAPI
  163. PeiServicesGetHobList (
  164. OUT VOID **HobList
  165. )
  166. {
  167. ASSERT (FALSE);
  168. return EFI_OUT_OF_RESOURCES;
  169. }
  170. /**
  171. This service enables PEIMs to create various types of HOBs.
  172. @param Type The type of HOB to be installed.
  173. @param Length The length of the HOB to be added.
  174. @param Hob The address of a pointer that will contain the
  175. HOB header.
  176. @retval EFI_SUCCESS The HOB was successfully created.
  177. @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
  178. **/
  179. EFI_STATUS
  180. EFIAPI
  181. PeiServicesCreateHob (
  182. IN UINT16 Type,
  183. IN UINT16 Length,
  184. OUT VOID **Hob
  185. )
  186. {
  187. ASSERT (FALSE);
  188. return EFI_OUT_OF_RESOURCES;
  189. }
  190. /**
  191. This service enables PEIMs to discover additional firmware volumes.
  192. @param Instance This instance of the firmware volume to find. The
  193. value 0 is the Boot Firmware Volume (BFV).
  194. @param VolumeHandle Handle of the firmware volume header of the volume
  195. to return.
  196. @retval EFI_SUCCESS The volume was found.
  197. @retval EFI_NOT_FOUND The volume was not found.
  198. @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
  199. **/
  200. EFI_STATUS
  201. EFIAPI
  202. PeiServicesFfsFindNextVolume (
  203. IN UINTN Instance,
  204. IN OUT EFI_PEI_FV_HANDLE *VolumeHandle
  205. )
  206. {
  207. ASSERT (FALSE);
  208. return EFI_OUT_OF_RESOURCES;
  209. }
  210. /**
  211. This service enables PEIMs to discover additional firmware files.
  212. @param SearchType A filter to find files only of this type.
  213. @param VolumeHandle The pointer to the firmware volume header of the
  214. volume to search. This parameter must point to a
  215. valid FFS volume.
  216. @param FileHandle Handle of the current file from which to begin searching.
  217. @retval EFI_SUCCESS The file was found.
  218. @retval EFI_NOT_FOUND The file was not found.
  219. @retval EFI_NOT_FOUND The header checksum was not zero.
  220. **/
  221. EFI_STATUS
  222. EFIAPI
  223. PeiServicesFfsFindNextFile (
  224. IN EFI_FV_FILETYPE SearchType,
  225. IN EFI_PEI_FV_HANDLE VolumeHandle,
  226. IN OUT EFI_PEI_FILE_HANDLE *FileHandle
  227. )
  228. {
  229. return SecFfsFindNextFile (SearchType, VolumeHandle, FileHandle);
  230. }
  231. /**
  232. This service enables PEIMs to discover sections of a given type within a valid FFS file.
  233. @param SectionType The value of the section type to find.
  234. @param FileHandle A pointer to the file header that contains the set
  235. of sections to be searched.
  236. @param SectionData A pointer to the discovered section, if successful.
  237. @retval EFI_SUCCESS The section was found.
  238. @retval EFI_NOT_FOUND The section was not found.
  239. **/
  240. EFI_STATUS
  241. EFIAPI
  242. PeiServicesFfsFindSectionData (
  243. IN EFI_SECTION_TYPE SectionType,
  244. IN EFI_PEI_FILE_HANDLE FileHandle,
  245. OUT VOID **SectionData
  246. )
  247. {
  248. return SecFfsFindSectionData (SectionType, FileHandle, SectionData);
  249. }
  250. /**
  251. This service enables PEIMs to register the permanent memory configuration
  252. that has been initialized with the PEI Foundation.
  253. @param MemoryBegin The value of a region of installed memory.
  254. @param MemoryLength The corresponding length of a region of installed memory.
  255. @retval EFI_SUCCESS The region was successfully installed in a HOB.
  256. @retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system.
  257. @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
  258. **/
  259. EFI_STATUS
  260. EFIAPI
  261. PeiServicesInstallPeiMemory (
  262. IN EFI_PHYSICAL_ADDRESS MemoryBegin,
  263. IN UINT64 MemoryLength
  264. )
  265. {
  266. ASSERT (FALSE);
  267. return EFI_OUT_OF_RESOURCES;
  268. }
  269. /**
  270. This service enables PEIMs to allocate memory after the permanent memory has been
  271. installed by a PEIM.
  272. @param MemoryType Type of memory to allocate.
  273. @param Pages The number of pages to allocate.
  274. @param Memory Pointer of memory allocated.
  275. @retval EFI_SUCCESS The memory range was successfully allocated.
  276. @retval EFI_INVALID_PARAMETER Type is not equal to AllocateAnyPages.
  277. @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available.
  278. @retval EFI_OUT_OF_RESOURCES The pages could not be allocated.
  279. **/
  280. EFI_STATUS
  281. EFIAPI
  282. PeiServicesAllocatePages (
  283. IN EFI_MEMORY_TYPE MemoryType,
  284. IN UINTN Pages,
  285. OUT EFI_PHYSICAL_ADDRESS *Memory
  286. )
  287. {
  288. ASSERT (FALSE);
  289. return EFI_OUT_OF_RESOURCES;
  290. }
  291. /**
  292. This service allocates memory from the Hand-Off Block (HOB) heap.
  293. @param Size The number of bytes to allocate from the pool.
  294. @param Buffer If the call succeeds, a pointer to a pointer to
  295. the allocate buffer; otherwise, undefined.
  296. @retval EFI_SUCCESS The allocation was successful
  297. @retval EFI_OUT_OF_RESOURCES There is not enough heap to allocate the requested size.
  298. **/
  299. EFI_STATUS
  300. EFIAPI
  301. PeiServicesAllocatePool (
  302. IN UINTN Size,
  303. OUT VOID **Buffer
  304. )
  305. {
  306. ASSERT (FALSE);
  307. return EFI_OUT_OF_RESOURCES;
  308. }
  309. /**
  310. Resets the entire platform.
  311. @retval EFI_SUCCESS The function completed successfully.
  312. @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.
  313. **/
  314. EFI_STATUS
  315. EFIAPI
  316. PeiServicesResetSystem (
  317. VOID
  318. )
  319. {
  320. ASSERT (FALSE);
  321. return EFI_OUT_OF_RESOURCES;
  322. }
  323. /**
  324. This service is a wrapper for the PEI Service RegisterForShadow(), except the
  325. pointer to the PEI Services Table has been removed. See the Platform
  326. Initialization Pre-EFI Initialization Core Interface Specification for details.
  327. @param FileHandle PEIM's file handle. Must be the currently
  328. executing PEIM.
  329. @retval EFI_SUCCESS The PEIM was successfully registered for
  330. shadowing.
  331. @retval EFI_ALREADY_STARTED The PEIM was previously
  332. registered for shadowing.
  333. @retval EFI_NOT_FOUND The FileHandle does not refer to a
  334. valid file handle.
  335. **/
  336. EFI_STATUS
  337. EFIAPI
  338. PeiServicesRegisterForShadow (
  339. IN EFI_PEI_FILE_HANDLE FileHandle
  340. )
  341. {
  342. ASSERT (FALSE);
  343. return EFI_OUT_OF_RESOURCES;
  344. }
  345. /**
  346. This service is a wrapper for the PEI Service FfsGetFileInfo(), except the pointer to the PEI Services
  347. Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
  348. Specification for details.
  349. @param FileHandle The handle of the file.
  350. @param FileInfo Upon exit, points to the file's
  351. information.
  352. @retval EFI_SUCCESS File information returned.
  353. @retval EFI_INVALID_PARAMETER If FileHandle does not
  354. represent a valid file.
  355. @retval EFI_INVALID_PARAMETER FileInfo is NULL.
  356. **/
  357. EFI_STATUS
  358. EFIAPI
  359. PeiServicesFfsGetFileInfo (
  360. IN CONST EFI_PEI_FILE_HANDLE FileHandle,
  361. OUT EFI_FV_FILE_INFO *FileInfo
  362. )
  363. {
  364. ASSERT (FALSE);
  365. return EFI_OUT_OF_RESOURCES;
  366. }
  367. /**
  368. This service is a wrapper for the PEI Service FfsFindByName(), except the pointer to the PEI Services
  369. Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
  370. Specification for details.
  371. @param FileName A pointer to the name of the file to
  372. find within the firmware volume.
  373. @param VolumeHandle The firmware volume to search FileHandle
  374. Upon exit, points to the found file's
  375. handle or NULL if it could not be found.
  376. @param FileHandle The pointer to found file handle
  377. @retval EFI_SUCCESS File was found.
  378. @retval EFI_NOT_FOUND File was not found.
  379. @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or
  380. FileName was NULL.
  381. **/
  382. EFI_STATUS
  383. EFIAPI
  384. PeiServicesFfsFindFileByName (
  385. IN CONST EFI_GUID *FileName,
  386. IN CONST EFI_PEI_FV_HANDLE VolumeHandle,
  387. OUT EFI_PEI_FILE_HANDLE *FileHandle
  388. )
  389. {
  390. ASSERT (FALSE);
  391. return EFI_OUT_OF_RESOURCES;
  392. }
  393. /**
  394. This service is a wrapper for the PEI Service FfsGetVolumeInfo(), except the pointer to the PEI Services
  395. Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
  396. Specification for details.
  397. @param VolumeHandle Handle of the volume.
  398. @param VolumeInfo Upon exit, points to the volume's
  399. information.
  400. @retval EFI_SUCCESS File information returned.
  401. @retval EFI_INVALID_PARAMETER If FileHandle does not
  402. represent a valid file.
  403. @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
  404. **/
  405. EFI_STATUS
  406. EFIAPI
  407. PeiServicesFfsGetVolumeInfo (
  408. IN EFI_PEI_FV_HANDLE VolumeHandle,
  409. OUT EFI_FV_INFO *VolumeInfo
  410. )
  411. {
  412. ASSERT (FALSE);
  413. return EFI_OUT_OF_RESOURCES;
  414. }
  415. /**
  416. Install a EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance so the PEI Core will be notified about a new firmware volume.
  417. This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO_PPI using
  418. the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance.
  419. If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO_PPI, then ASSERT().
  420. If the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI can not be installed, then ASSERT().
  421. @param FvFormat Unique identifier of the format of the memory-mapped
  422. firmware volume. This parameter is optional and
  423. may be NULL. If NULL is specified, the
  424. EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed.
  425. @param FvInfo Points to a buffer which allows the
  426. EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume.
  427. The format of this buffer is specific to the FvFormat.
  428. For memory-mapped firmware volumes, this typically
  429. points to the first byte of the firmware volume.
  430. @param FvInfoSize The size, in bytes, of FvInfo. For memory-mapped
  431. firmware volumes, this is typically the size of
  432. the firmware volume.
  433. @param ParentFvName If the new firmware volume originated from a file
  434. in a different firmware volume, then this parameter
  435. specifies the GUID name of the originating firmware
  436. volume. Otherwise, this parameter must be NULL.
  437. @param ParentFileName If the new firmware volume originated from a file
  438. in a different firmware volume, then this parameter
  439. specifies the GUID file name of the originating
  440. firmware file. Otherwise, this parameter must be NULL.
  441. **/
  442. VOID
  443. EFIAPI
  444. PeiServicesInstallFvInfoPpi (
  445. IN CONST EFI_GUID *FvFormat OPTIONAL,
  446. IN CONST VOID *FvInfo,
  447. IN UINT32 FvInfoSize,
  448. IN CONST EFI_GUID *ParentFvName OPTIONAL,
  449. IN CONST EFI_GUID *ParentFileName OPTIONAL
  450. )
  451. {
  452. ASSERT (FALSE);
  453. return;
  454. }