]> git.proxmox.com Git - mirror_edk2.git/blob - UnitTestFrameworkPkg/Library/UnitTestUefiBootServicesTableLib/UnitTestUefiBootServicesTableLibMisc.c
UnitTestFrameworkPkg: Add UnitTestUefiBootServicesTableLib
[mirror_edk2.git] / UnitTestFrameworkPkg / Library / UnitTestUefiBootServicesTableLib / UnitTestUefiBootServicesTableLibMisc.c
1 /** @file
2 Implementation of miscellaneous services in the UEFI Boot Services table for use in unit tests.
3
4 Copyright (c) Microsoft Corporation
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "UnitTestUefiBootServicesTableLib.h"
10
11 /**
12 Returns a monotonically increasing count for the platform.
13
14 @param[out] Count The pointer to returned value.
15
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.
19
20 **/
21 EFI_STATUS
22 EFIAPI
23 UnitTestGetNextMonotonicCount (
24 OUT UINT64 *Count
25 )
26 {
27 STATIC UINT64 StaticCount = 0;
28
29 *Count = StaticCount++;
30
31 return EFI_SUCCESS;
32 }
33
34 /**
35 Introduces a fine-grained stall.
36
37 @param Microseconds The number of microseconds to stall execution.
38
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
42
43 **/
44 EFI_STATUS
45 EFIAPI
46 UnitTestStall (
47 IN UINTN Microseconds
48 )
49 {
50 return EFI_NOT_AVAILABLE_YET;
51 }
52
53 /**
54 Sets the system's watchdog timer.
55
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
61 codes.
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
67 watchdog event.
68
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
73
74 **/
75 EFI_STATUS
76 EFIAPI
77 UnitTestSetWatchdogTimer (
78 IN UINTN Timeout,
79 IN UINT64 WatchdogCode,
80 IN UINTN DataSize,
81 IN CHAR16 *WatchdogData OPTIONAL
82 )
83 {
84 return EFI_NOT_AVAILABLE_YET;
85 }
86
87 /**
88 Connects one or more drivers to a controller.
89
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.
99
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
103 Path Node.
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.
111
112 **/
113 EFI_STATUS
114 EFIAPI
115 UnitTestConnectController (
116 IN EFI_HANDLE ControllerHandle,
117 IN EFI_HANDLE *DriverImageHandle OPTIONAL,
118 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
119 IN BOOLEAN Recursive
120 )
121 {
122 return EFI_SUCCESS; // Return success for now
123 }
124
125 /**
126 Disconnects a controller from a driver
127
128 @param ControllerHandle ControllerHandle The handle of
129 the controller from which
130 driver(s) are to be
131 disconnected.
132 @param DriverImageHandle DriverImageHandle The driver to
133 disconnect from ControllerHandle.
134 @param ChildHandle ChildHandle The handle of the
135 child to destroy.
136
137 @retval EFI_SUCCESS One or more drivers were
138 disconnected from the controller.
139 @retval EFI_SUCCESS On entry, no drivers are managing
140 ControllerHandle.
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
154 error.
155
156 **/
157 EFI_STATUS
158 EFIAPI
159 UnitTestDisconnectController (
160 IN EFI_HANDLE ControllerHandle,
161 IN EFI_HANDLE DriverImageHandle OPTIONAL,
162 IN EFI_HANDLE ChildHandle OPTIONAL
163 )
164 {
165 return EFI_SUCCESS; // Return success for now
166 }
167
168 /**
169 Computes and returns a 32-bit CRC for a data buffer.
170
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
174 and DataSize.
175
176 @retval EFI_SUCCESS The 32-bit CRC was computed for the data buffer and returned in
177 Crc32.
178 @retval EFI_INVALID_PARAMETER Data is NULL.
179 @retval EFI_INVALID_PARAMETER Crc32 is NULL.
180 @retval EFI_INVALID_PARAMETER DataSize is 0.
181
182 **/
183 EFI_STATUS
184 EFIAPI
185 UnitTestCalculateCrc32 (
186 IN VOID *Data,
187 IN UINTN DataSize,
188 OUT UINT32 *Crc32
189 )
190 {
191 if ((Data == NULL) || (Crc32 == NULL) || (DataSize == 0)) {
192 return EFI_INVALID_PARAMETER;
193 }
194
195 *Crc32 = CalculateCrc32 (Data, DataSize);
196
197 return EFI_SUCCESS;
198 }