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