UefiBootServicesTableLibUnitTestMisc.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /** @file
  2. Implementation of miscellaneous services in the UEFI Boot Services table for use in unit tests.
  3. Copyright (c) Microsoft Corporation
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "UefiBootServicesTableLibUnitTest.h"
  7. /**
  8. Returns a monotonically increasing count for the platform.
  9. @param[out] Count The pointer to returned value.
  10. @retval EFI_SUCCESS The next monotonic count was returned.
  11. @retval EFI_INVALID_PARAMETER Count is NULL.
  12. @retval EFI_DEVICE_ERROR The device is not functioning properly.
  13. **/
  14. EFI_STATUS
  15. EFIAPI
  16. UnitTestGetNextMonotonicCount (
  17. OUT UINT64 *Count
  18. )
  19. {
  20. STATIC UINT64 StaticCount = 0;
  21. *Count = StaticCount++;
  22. return EFI_SUCCESS;
  23. }
  24. /**
  25. Introduces a fine-grained stall.
  26. @param Microseconds The number of microseconds to stall execution.
  27. @retval EFI_SUCCESS Execution was stalled for at least the requested
  28. amount of microseconds.
  29. @retval EFI_NOT_AVAILABLE_YET gMetronome is not available yet
  30. **/
  31. EFI_STATUS
  32. EFIAPI
  33. UnitTestStall (
  34. IN UINTN Microseconds
  35. )
  36. {
  37. return EFI_NOT_AVAILABLE_YET;
  38. }
  39. /**
  40. Sets the system's watchdog timer.
  41. @param Timeout The number of seconds to set the watchdog timer to.
  42. A value of zero disables the timer.
  43. @param WatchdogCode The numeric code to log on a watchdog timer timeout
  44. event. The firmware reserves codes 0x0000 to 0xFFFF.
  45. Loaders and operating systems may use other timeout
  46. codes.
  47. @param DataSize The size, in bytes, of WatchdogData.
  48. @param WatchdogData A data buffer that includes a Null-terminated Unicode
  49. string, optionally followed by additional binary data.
  50. The string is a description that the call may use to
  51. further indicate the reason to be logged with a
  52. watchdog event.
  53. @return EFI_SUCCESS Timeout has been set
  54. @return EFI_NOT_AVAILABLE_YET WatchdogTimer is not available yet
  55. @return EFI_UNSUPPORTED System does not have a timer (currently not used)
  56. @return EFI_DEVICE_ERROR Could not complete due to hardware error
  57. **/
  58. EFI_STATUS
  59. EFIAPI
  60. UnitTestSetWatchdogTimer (
  61. IN UINTN Timeout,
  62. IN UINT64 WatchdogCode,
  63. IN UINTN DataSize,
  64. IN CHAR16 *WatchdogData OPTIONAL
  65. )
  66. {
  67. return EFI_NOT_AVAILABLE_YET;
  68. }
  69. /**
  70. Connects one or more drivers to a controller.
  71. @param ControllerHandle The handle of the controller to which driver(s) are to be connected.
  72. @param DriverImageHandle A pointer to an ordered list handles that support the
  73. EFI_DRIVER_BINDING_PROTOCOL.
  74. @param RemainingDevicePath A pointer to the device path that specifies a child of the
  75. controller specified by ControllerHandle.
  76. @param Recursive If TRUE, then ConnectController() is called recursively
  77. until the entire tree of controllers below the controller specified
  78. by ControllerHandle have been created. If FALSE, then
  79. the tree of controllers is only expanded one level.
  80. @retval EFI_SUCCESS 1) One or more drivers were connected to ControllerHandle.
  81. 2) No drivers were connected to ControllerHandle, but
  82. RemainingDevicePath is not NULL, and it is an End Device
  83. Path Node.
  84. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  85. @retval EFI_NOT_FOUND 1) There are no EFI_DRIVER_BINDING_PROTOCOL instances
  86. present in the system.
  87. 2) No drivers were connected to ControllerHandle.
  88. @retval EFI_SECURITY_VIOLATION
  89. The user has no permission to start UEFI device drivers on the device path
  90. associated with the ControllerHandle or specified by the RemainingDevicePath.
  91. **/
  92. EFI_STATUS
  93. EFIAPI
  94. UnitTestConnectController (
  95. IN EFI_HANDLE ControllerHandle,
  96. IN EFI_HANDLE *DriverImageHandle OPTIONAL,
  97. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
  98. IN BOOLEAN Recursive
  99. )
  100. {
  101. return EFI_SUCCESS; // Return success for now
  102. }
  103. /**
  104. Disconnects a controller from a driver
  105. @param ControllerHandle ControllerHandle The handle of
  106. the controller from which
  107. driver(s) are to be
  108. disconnected.
  109. @param DriverImageHandle DriverImageHandle The driver to
  110. disconnect from ControllerHandle.
  111. @param ChildHandle ChildHandle The handle of the
  112. child to destroy.
  113. @retval EFI_SUCCESS One or more drivers were
  114. disconnected from the controller.
  115. @retval EFI_SUCCESS On entry, no drivers are managing
  116. ControllerHandle.
  117. @retval EFI_SUCCESS DriverImageHandle is not NULL,
  118. and on entry DriverImageHandle is
  119. not managing ControllerHandle.
  120. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  121. @retval EFI_INVALID_PARAMETER DriverImageHandle is not NULL,
  122. and it is not a valid EFI_HANDLE.
  123. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it
  124. is not a valid EFI_HANDLE.
  125. @retval EFI_OUT_OF_RESOURCES There are not enough resources
  126. available to disconnect any
  127. drivers from ControllerHandle.
  128. @retval EFI_DEVICE_ERROR The controller could not be
  129. disconnected because of a device
  130. error.
  131. **/
  132. EFI_STATUS
  133. EFIAPI
  134. UnitTestDisconnectController (
  135. IN EFI_HANDLE ControllerHandle,
  136. IN EFI_HANDLE DriverImageHandle OPTIONAL,
  137. IN EFI_HANDLE ChildHandle OPTIONAL
  138. )
  139. {
  140. return EFI_SUCCESS; // Return success for now
  141. }
  142. /**
  143. Computes and returns a 32-bit CRC for a data buffer.
  144. @param[in] Data A pointer to the buffer on which the 32-bit CRC is to be computed.
  145. @param[in] DataSize The number of bytes in the buffer Data.
  146. @param[out] Crc32 The 32-bit CRC that was computed for the data buffer specified by Data
  147. and DataSize.
  148. @retval EFI_SUCCESS The 32-bit CRC was computed for the data buffer and returned in
  149. Crc32.
  150. @retval EFI_INVALID_PARAMETER Data is NULL.
  151. @retval EFI_INVALID_PARAMETER Crc32 is NULL.
  152. @retval EFI_INVALID_PARAMETER DataSize is 0.
  153. **/
  154. EFI_STATUS
  155. EFIAPI
  156. UnitTestCalculateCrc32 (
  157. IN VOID *Data,
  158. IN UINTN DataSize,
  159. OUT UINT32 *Crc32
  160. )
  161. {
  162. if ((Data == NULL) || (Crc32 == NULL) || (DataSize == 0)) {
  163. return EFI_INVALID_PARAMETER;
  164. }
  165. *Crc32 = CalculateCrc32 (Data, DataSize);
  166. return EFI_SUCCESS;
  167. }