2 Implementation of miscellaneous services in the UEFI Boot Services table for use in unit tests.
4 Copyright (c) Microsoft Corporation
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "UnitTestUefiBootServicesTableLib.h"
12 Returns a monotonically increasing count for the platform.
14 @param[out] Count The pointer to returned value.
16 @retval EFI_SUCCESS The next monotonic count was returned.
17 @retval EFI_INVALID_PARAMETER Count is NULL.
18 @retval EFI_DEVICE_ERROR The device is not functioning properly.
23 UnitTestGetNextMonotonicCount (
27 STATIC UINT64 StaticCount
= 0;
29 *Count
= StaticCount
++;
35 Introduces a fine-grained stall.
37 @param Microseconds The number of microseconds to stall execution.
39 @retval EFI_SUCCESS Execution was stalled for at least the requested
40 amount of microseconds.
41 @retval EFI_NOT_AVAILABLE_YET gMetronome is not available yet
50 return EFI_NOT_AVAILABLE_YET
;
54 Sets the system's watchdog timer.
56 @param Timeout The number of seconds to set the watchdog timer to.
57 A value of zero disables the timer.
58 @param WatchdogCode The numeric code to log on a watchdog timer timeout
59 event. The firmware reserves codes 0x0000 to 0xFFFF.
60 Loaders and operating systems may use other timeout
62 @param DataSize The size, in bytes, of WatchdogData.
63 @param WatchdogData A data buffer that includes a Null-terminated Unicode
64 string, optionally followed by additional binary data.
65 The string is a description that the call may use to
66 further indicate the reason to be logged with a
69 @return EFI_SUCCESS Timeout has been set
70 @return EFI_NOT_AVAILABLE_YET WatchdogTimer is not available yet
71 @return EFI_UNSUPPORTED System does not have a timer (currently not used)
72 @return EFI_DEVICE_ERROR Could not complete due to hardware error
77 UnitTestSetWatchdogTimer (
79 IN UINT64 WatchdogCode
,
81 IN CHAR16
*WatchdogData OPTIONAL
84 return EFI_NOT_AVAILABLE_YET
;
88 Connects one or more drivers to a controller.
90 @param ControllerHandle The handle of the controller to which driver(s) are to be connected.
91 @param DriverImageHandle A pointer to an ordered list handles that support the
92 EFI_DRIVER_BINDING_PROTOCOL.
93 @param RemainingDevicePath A pointer to the device path that specifies a child of the
94 controller specified by ControllerHandle.
95 @param Recursive If TRUE, then ConnectController() is called recursively
96 until the entire tree of controllers below the controller specified
97 by ControllerHandle have been created. If FALSE, then
98 the tree of controllers is only expanded one level.
100 @retval EFI_SUCCESS 1) One or more drivers were connected to ControllerHandle.
101 2) No drivers were connected to ControllerHandle, but
102 RemainingDevicePath is not NULL, and it is an End Device
104 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
105 @retval EFI_NOT_FOUND 1) There are no EFI_DRIVER_BINDING_PROTOCOL instances
106 present in the system.
107 2) No drivers were connected to ControllerHandle.
108 @retval EFI_SECURITY_VIOLATION
109 The user has no permission to start UEFI device drivers on the device path
110 associated with the ControllerHandle or specified by the RemainingDevicePath.
115 UnitTestConnectController (
116 IN EFI_HANDLE ControllerHandle
,
117 IN EFI_HANDLE
*DriverImageHandle OPTIONAL
,
118 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
,
122 return EFI_SUCCESS
; // Return success for now
126 Disconnects a controller from a driver
128 @param ControllerHandle ControllerHandle The handle of
129 the controller from which
132 @param DriverImageHandle DriverImageHandle The driver to
133 disconnect from ControllerHandle.
134 @param ChildHandle ChildHandle The handle of the
137 @retval EFI_SUCCESS One or more drivers were
138 disconnected from the controller.
139 @retval EFI_SUCCESS On entry, no drivers are managing
141 @retval EFI_SUCCESS DriverImageHandle is not NULL,
142 and on entry DriverImageHandle is
143 not managing ControllerHandle.
144 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
145 @retval EFI_INVALID_PARAMETER DriverImageHandle is not NULL,
146 and it is not a valid EFI_HANDLE.
147 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it
148 is not a valid EFI_HANDLE.
149 @retval EFI_OUT_OF_RESOURCES There are not enough resources
150 available to disconnect any
151 drivers from ControllerHandle.
152 @retval EFI_DEVICE_ERROR The controller could not be
153 disconnected because of a device
159 UnitTestDisconnectController (
160 IN EFI_HANDLE ControllerHandle
,
161 IN EFI_HANDLE DriverImageHandle OPTIONAL
,
162 IN EFI_HANDLE ChildHandle OPTIONAL
165 return EFI_SUCCESS
; // Return success for now
169 Computes and returns a 32-bit CRC for a data buffer.
171 @param[in] Data A pointer to the buffer on which the 32-bit CRC is to be computed.
172 @param[in] DataSize The number of bytes in the buffer Data.
173 @param[out] Crc32 The 32-bit CRC that was computed for the data buffer specified by Data
176 @retval EFI_SUCCESS The 32-bit CRC was computed for the data buffer and returned in
178 @retval EFI_INVALID_PARAMETER Data is NULL.
179 @retval EFI_INVALID_PARAMETER Crc32 is NULL.
180 @retval EFI_INVALID_PARAMETER DataSize is 0.
185 UnitTestCalculateCrc32 (
191 if ((Data
== NULL
) || (Crc32
== NULL
) || (DataSize
== 0)) {
192 return EFI_INVALID_PARAMETER
;
195 *Crc32
= CalculateCrc32 (Data
, DataSize
);