UefiNotTiano.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /** @file
  2. Library functions that abstract areas of conflict between framework and UEFI 2.0.
  3. Help Port Framework code that has conflicts with UEFI 2.0 by hiding the
  4. old conflicts with library functions and supporting implementations of the old
  5. (EDK/EFI 1.10) and new (EDK II/UEFI 2.0) way. This module is a DXE driver as
  6. it contains DXE enum extensions for EFI event services.
  7. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
  8. SPDX-License-Identifier: BSD-2-Clause-Patent
  9. **/
  10. #include "UefiLibInternal.h"
  11. /**
  12. Create a Legacy Boot Event.
  13. Tiano extended the CreateEvent Type enum to add a legacy boot event type.
  14. This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
  15. added and now it's possible to not voilate the UEFI specification by
  16. declaring a GUID for the legacy boot event class. This library supports
  17. the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to
  18. work both ways.
  19. @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
  20. @retval EFI_SUCCESS Event was created.
  21. @retval Other Event was not created.
  22. **/
  23. EFI_STATUS
  24. EFIAPI
  25. EfiCreateEventLegacyBoot (
  26. OUT EFI_EVENT *LegacyBootEvent
  27. )
  28. {
  29. return EfiCreateEventLegacyBootEx (
  30. TPL_CALLBACK,
  31. EfiEventEmptyFunction,
  32. NULL,
  33. LegacyBootEvent
  34. );
  35. }
  36. /**
  37. Create an EFI event in the Legacy Boot Event Group and allows
  38. the caller to specify a notification function.
  39. This function abstracts the creation of the Legacy Boot Event.
  40. The Framework moved from a proprietary to UEFI 2.0 based mechanism.
  41. This library abstracts the caller from how this event is created to prevent
  42. to code form having to change with the version of the specification supported.
  43. If LegacyBootEvent is NULL, then ASSERT().
  44. @param NotifyTpl The task priority level of the event.
  45. @param NotifyFunction The notification function to call when the event is signaled.
  46. @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
  47. @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
  48. @retval EFI_SUCCESS Event was created.
  49. @retval Other Event was not created.
  50. **/
  51. EFI_STATUS
  52. EFIAPI
  53. EfiCreateEventLegacyBootEx (
  54. IN EFI_TPL NotifyTpl,
  55. IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL
  56. IN VOID *NotifyContext, OPTIONAL
  57. OUT EFI_EVENT *LegacyBootEvent
  58. )
  59. {
  60. EFI_STATUS Status;
  61. ASSERT (LegacyBootEvent != NULL);
  62. if (gST->Hdr.Revision < 0x00020000) {
  63. //
  64. // prior to UEFI 2.0 use Tiano extension to EFI
  65. //
  66. Status = gBS->CreateEvent (
  67. EFI_EVENT_SIGNAL_LEGACY_BOOT | EVT_NOTIFY_SIGNAL,
  68. NotifyTpl,
  69. NotifyFunction,
  70. NotifyContext,
  71. LegacyBootEvent
  72. );
  73. } else {
  74. //
  75. // For UEFI 2.0 and the future use an Event Group
  76. //
  77. Status = gBS->CreateEventEx (
  78. EVT_NOTIFY_SIGNAL,
  79. NotifyTpl,
  80. NotifyFunction,
  81. NotifyContext,
  82. &gEfiEventLegacyBootGuid,
  83. LegacyBootEvent
  84. );
  85. }
  86. return Status;
  87. }
  88. /**
  89. Create a Read to Boot Event.
  90. Tiano extended the CreateEvent Type enum to add a ready to boot event type.
  91. This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
  92. added and now it's possible to not voilate the UEFI specification and use
  93. the ready to boot event class defined in UEFI 2.0. This library supports
  94. the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to
  95. work both ways.
  96. @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
  97. @retval EFI_SUCCESS Event was created.
  98. @retval Other Event was not created.
  99. **/
  100. EFI_STATUS
  101. EFIAPI
  102. EfiCreateEventReadyToBoot (
  103. OUT EFI_EVENT *ReadyToBootEvent
  104. )
  105. {
  106. return EfiCreateEventReadyToBootEx (
  107. TPL_CALLBACK,
  108. EfiEventEmptyFunction,
  109. NULL,
  110. ReadyToBootEvent
  111. );
  112. }
  113. /**
  114. Create an EFI event in the Ready To Boot Event Group and allows
  115. the caller to specify a notification function.
  116. This function abstracts the creation of the Ready to Boot Event.
  117. The Framework moved from a proprietary to UEFI 2.0 based mechanism.
  118. This library abstracts the caller from how this event is created to prevent
  119. to code form having to change with the version of the specification supported.
  120. If ReadyToBootEvent is NULL, then ASSERT().
  121. @param NotifyTpl The task priority level of the event.
  122. @param NotifyFunction The notification function to call when the event is signaled.
  123. @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
  124. @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
  125. @retval EFI_SUCCESS Event was created.
  126. @retval Other Event was not created.
  127. **/
  128. EFI_STATUS
  129. EFIAPI
  130. EfiCreateEventReadyToBootEx (
  131. IN EFI_TPL NotifyTpl,
  132. IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL
  133. IN VOID *NotifyContext, OPTIONAL
  134. OUT EFI_EVENT *ReadyToBootEvent
  135. )
  136. {
  137. EFI_STATUS Status;
  138. ASSERT (ReadyToBootEvent != NULL);
  139. if (gST->Hdr.Revision < 0x00020000) {
  140. //
  141. // prior to UEFI 2.0 use Tiano extension to EFI
  142. //
  143. Status = gBS->CreateEvent (
  144. EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,
  145. NotifyTpl,
  146. NotifyFunction,
  147. NotifyContext,
  148. ReadyToBootEvent
  149. );
  150. } else {
  151. //
  152. // For UEFI 2.0 and the future use an Event Group
  153. //
  154. Status = gBS->CreateEventEx (
  155. EVT_NOTIFY_SIGNAL,
  156. NotifyTpl,
  157. NotifyFunction,
  158. NotifyContext,
  159. &gEfiEventReadyToBootGuid,
  160. ReadyToBootEvent
  161. );
  162. }
  163. return Status;
  164. }
  165. /**
  166. Signal a Ready to Boot Event.
  167. Create a Ready to Boot Event. Signal it and close it. This causes other
  168. events of the same event group to be signaled in other modules.
  169. **/
  170. VOID
  171. EFIAPI
  172. EfiSignalEventReadyToBoot (
  173. VOID
  174. )
  175. {
  176. EFI_STATUS Status;
  177. EFI_EVENT ReadyToBootEvent;
  178. Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);
  179. if (!EFI_ERROR (Status)) {
  180. gBS->SignalEvent (ReadyToBootEvent);
  181. gBS->CloseEvent (ReadyToBootEvent);
  182. }
  183. }
  184. /**
  185. Signal a Legacy Boot Event.
  186. Create a legacy Boot Event. Signal it and close it. This causes other
  187. events of the same event group to be signaled in other modules.
  188. **/
  189. VOID
  190. EFIAPI
  191. EfiSignalEventLegacyBoot (
  192. VOID
  193. )
  194. {
  195. EFI_STATUS Status;
  196. EFI_EVENT LegacyBootEvent;
  197. Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);
  198. if (!EFI_ERROR (Status)) {
  199. gBS->SignalEvent (LegacyBootEvent);
  200. gBS->CloseEvent (LegacyBootEvent);
  201. }
  202. }
  203. /**
  204. Check to see if the Firmware Volume (FV) Media Device Path is valid
  205. Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
  206. so as we move to UEFI 2.0 support we must use a mechanism that conforms with
  207. the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
  208. device path is defined for Tiano extensions of device path. If the code
  209. is compiled to conform with the UEFI 2.0 specification use the new device path
  210. else use the old form for backwards compatability. The return value to this
  211. function points to a location in FvDevicePathNode and it does not allocate
  212. new memory for the GUID pointer that is returned.
  213. @param FvDevicePathNode Pointer to FV device path to check.
  214. @retval NULL FvDevicePathNode is not valid.
  215. @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.
  216. **/
  217. EFI_GUID *
  218. EFIAPI
  219. EfiGetNameGuidFromFwVolDevicePathNode (
  220. IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode
  221. )
  222. {
  223. ASSERT (FvDevicePathNode != NULL);
  224. //
  225. // EFI Specification extension on Media Device Path. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH is adopted by UEFI later and added in UEFI2.10.
  226. // In EdkCompatibility Package, we only support MEDIA_FW_VOL_FILEPATH_DEVICE_PATH that complies with
  227. // EFI 1.10 and UEFI 2.10.
  228. //
  229. if (DevicePathType (&FvDevicePathNode->Header) == MEDIA_DEVICE_PATH &&
  230. DevicePathSubType (&FvDevicePathNode->Header) == MEDIA_PIWG_FW_FILE_DP) {
  231. return (EFI_GUID *) &FvDevicePathNode->FvFileName;
  232. }
  233. return NULL;
  234. }
  235. /**
  236. Initialize a Firmware Volume (FV) Media Device Path node.
  237. Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
  238. so as we move to UEFI 2.0 support we must use a mechanism that conforms with
  239. the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
  240. device path is defined for Tiano extensions of device path. If the code
  241. is compiled to conform with the UEFI 2.0 specification use the new device path
  242. else use the old form for backwards compatability.
  243. @param FvDevicePathNode Pointer to a FV device path node to initialize
  244. @param NameGuid FV file name to use in FvDevicePathNode
  245. **/
  246. VOID
  247. EFIAPI
  248. EfiInitializeFwVolDevicepathNode (
  249. IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,
  250. IN CONST EFI_GUID *NameGuid
  251. )
  252. {
  253. ASSERT (FvDevicePathNode != NULL);
  254. ASSERT (NameGuid != NULL);
  255. //
  256. // EFI Specification extension on Media Device Path. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH is adopted by UEFI later and added in UEFI2.10.
  257. // In EdkCompatibility Package, we only support MEDIA_FW_VOL_FILEPATH_DEVICE_PATH that complies with
  258. // EFI 1.10 and UEFI 2.10.
  259. //
  260. FvDevicePathNode->Header.Type = MEDIA_DEVICE_PATH;
  261. FvDevicePathNode->Header.SubType = MEDIA_PIWG_FW_FILE_DP;
  262. SetDevicePathNodeLength (&FvDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));
  263. CopyGuid (&FvDevicePathNode->FvFileName, NameGuid);
  264. }