]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / UefiDevicePathLib.h
... / ...
CommitLineData
1/** @file\r
2 Definition for Device Path library.\r
3\r
4Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
5SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#ifndef _UEFI_DEVICE_PATH_LIB_H_\r
10#define _UEFI_DEVICE_PATH_LIB_H_\r
11#include <Uefi.h>\r
12#include <Protocol/DevicePathUtilities.h>\r
13#include <Protocol/DebugPort.h>\r
14#include <Protocol/DevicePathToText.h>\r
15#include <Protocol/DevicePathFromText.h>\r
16#include <Guid/PcAnsi.h>\r
17#include <Library/DebugLib.h>\r
18#include <Library/PrintLib.h>\r
19#include <Library/BaseLib.h>\r
20#include <Library/BaseMemoryLib.h>\r
21#include <Library/MemoryAllocationLib.h>\r
22#include <Library/UefiBootServicesTableLib.h>\r
23#include <Library/DevicePathLib.h>\r
24#include <Library/PcdLib.h>\r
25#include <IndustryStandard/Bluetooth.h>\r
26\r
27#define IS_COMMA(a) ((a) == L',')\r
28#define IS_HYPHEN(a) ((a) == L'-')\r
29#define IS_DOT(a) ((a) == L'.')\r
30#define IS_LEFT_PARENTH(a) ((a) == L'(')\r
31#define IS_RIGHT_PARENTH(a) ((a) == L')')\r
32#define IS_SLASH(a) ((a) == L'/')\r
33#define IS_NULL(a) ((a) == L'\0')\r
34\r
35//\r
36// Private Data structure\r
37//\r
38typedef struct {\r
39 CHAR16 *Str;\r
40 UINTN Count;\r
41 UINTN Capacity;\r
42} POOL_PRINT;\r
43\r
44typedef\r
45EFI_DEVICE_PATH_PROTOCOL *\r
46(*DEVICE_PATH_FROM_TEXT) (\r
47 IN CHAR16 *Str\r
48 );\r
49\r
50typedef\r
51VOID\r
52(*DEVICE_PATH_TO_TEXT) (\r
53 IN OUT POOL_PRINT *Str,\r
54 IN VOID *DevicePath,\r
55 IN BOOLEAN DisplayOnly,\r
56 IN BOOLEAN AllowShortcuts\r
57 );\r
58\r
59typedef struct {\r
60 UINT8 Type;\r
61 UINT8 SubType;\r
62 DEVICE_PATH_TO_TEXT Function;\r
63} DEVICE_PATH_TO_TEXT_TABLE;\r
64\r
65typedef struct {\r
66 UINT8 Type;\r
67 CHAR16 *Text;\r
68} DEVICE_PATH_TO_TEXT_GENERIC_TABLE;\r
69\r
70typedef struct {\r
71 CHAR16 *DevicePathNodeText;\r
72 DEVICE_PATH_FROM_TEXT Function;\r
73} DEVICE_PATH_FROM_TEXT_TABLE;\r
74\r
75typedef struct {\r
76 BOOLEAN ClassExist;\r
77 UINT8 Class;\r
78 BOOLEAN SubClassExist;\r
79 UINT8 SubClass;\r
80} USB_CLASS_TEXT;\r
81\r
82#define USB_CLASS_AUDIO 1\r
83#define USB_CLASS_CDCCONTROL 2\r
84#define USB_CLASS_HID 3\r
85#define USB_CLASS_IMAGE 6\r
86#define USB_CLASS_PRINTER 7\r
87#define USB_CLASS_MASS_STORAGE 8\r
88#define USB_CLASS_HUB 9\r
89#define USB_CLASS_CDCDATA 10\r
90#define USB_CLASS_SMART_CARD 11\r
91#define USB_CLASS_VIDEO 14\r
92#define USB_CLASS_DIAGNOSTIC 220\r
93#define USB_CLASS_WIRELESS 224\r
94\r
95#define USB_CLASS_RESERVE 254\r
96#define USB_SUBCLASS_FW_UPDATE 1\r
97#define USB_SUBCLASS_IRDA_BRIDGE 2\r
98#define USB_SUBCLASS_TEST 3\r
99\r
100#define RFC_1700_UDP_PROTOCOL 17\r
101#define RFC_1700_TCP_PROTOCOL 6\r
102\r
103#pragma pack(1)\r
104\r
105typedef struct {\r
106 EFI_DEVICE_PATH_PROTOCOL Header;\r
107 EFI_GUID Guid;\r
108 UINT8 VendorDefinedData[1];\r
109} VENDOR_DEFINED_HARDWARE_DEVICE_PATH;\r
110\r
111typedef struct {\r
112 EFI_DEVICE_PATH_PROTOCOL Header;\r
113 EFI_GUID Guid;\r
114 UINT8 VendorDefinedData[1];\r
115} VENDOR_DEFINED_MESSAGING_DEVICE_PATH;\r
116\r
117typedef struct {\r
118 EFI_DEVICE_PATH_PROTOCOL Header;\r
119 EFI_GUID Guid;\r
120 UINT8 VendorDefinedData[1];\r
121} VENDOR_DEFINED_MEDIA_DEVICE_PATH;\r
122\r
123typedef struct {\r
124 EFI_DEVICE_PATH_PROTOCOL Header;\r
125 UINT32 Hid;\r
126 UINT32 Uid;\r
127 UINT32 Cid;\r
128 CHAR8 HidUidCidStr[3];\r
129} ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR;\r
130\r
131typedef struct {\r
132 EFI_DEVICE_PATH_PROTOCOL Header;\r
133 UINT16 NetworkProtocol;\r
134 UINT16 LoginOption;\r
135 UINT64 Lun;\r
136 UINT16 TargetPortalGroupTag;\r
137 CHAR8 TargetName[1];\r
138} ISCSI_DEVICE_PATH_WITH_NAME;\r
139\r
140typedef struct {\r
141 EFI_DEVICE_PATH_PROTOCOL Header;\r
142 EFI_GUID Guid;\r
143 UINT8 VendorDefinedData[1];\r
144} VENDOR_DEVICE_PATH_WITH_DATA;\r
145\r
146#pragma pack()\r
147\r
148/**\r
149 Returns the size of a device path in bytes.\r
150\r
151 This function returns the size, in bytes, of the device path data structure\r
152 specified by DevicePath including the end of device path node.\r
153 If DevicePath is NULL or invalid, then 0 is returned.\r
154\r
155 @param DevicePath A pointer to a device path data structure.\r
156\r
157 @retval 0 If DevicePath is NULL or invalid.\r
158 @retval Others The size of a device path in bytes.\r
159\r
160**/\r
161UINTN\r
162EFIAPI\r
163UefiDevicePathLibGetDevicePathSize (\r
164 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
165 );\r
166\r
167/**\r
168 Creates a new copy of an existing device path.\r
169\r
170 This function allocates space for a new copy of the device path specified by DevicePath.\r
171 If DevicePath is NULL, then NULL is returned. If the memory is successfully\r
172 allocated, then the contents of DevicePath are copied to the newly allocated\r
173 buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.\r
174 The memory for the new device path is allocated from EFI boot services memory.\r
175 It is the responsibility of the caller to free the memory allocated.\r
176\r
177 @param DevicePath A pointer to a device path data structure.\r
178\r
179 @retval NULL DevicePath is NULL or invalid.\r
180 @retval Others A pointer to the duplicated device path.\r
181\r
182**/\r
183EFI_DEVICE_PATH_PROTOCOL *\r
184EFIAPI\r
185UefiDevicePathLibDuplicateDevicePath (\r
186 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
187 );\r
188\r
189/**\r
190 Creates a new device path by appending a second device path to a first device path.\r
191\r
192 This function creates a new device path by appending a copy of SecondDevicePath\r
193 to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path\r
194 device node from SecondDevicePath is retained. The newly created device path is\r
195 returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of\r
196 SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,\r
197 and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and\r
198 SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.\r
199\r
200 If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
201 The memory for the new device path is allocated from EFI boot services memory.\r
202 It is the responsibility of the caller to free the memory allocated.\r
203\r
204 @param FirstDevicePath A pointer to a device path data structure.\r
205 @param SecondDevicePath A pointer to a device path data structure.\r
206\r
207 @retval NULL If there is not enough memory for the newly allocated buffer.\r
208 @retval NULL If FirstDevicePath or SecondDevicePath is invalid.\r
209 @retval Others A pointer to the new device path if success.\r
210 Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r
211\r
212**/\r
213EFI_DEVICE_PATH_PROTOCOL *\r
214EFIAPI\r
215UefiDevicePathLibAppendDevicePath (\r
216 IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath OPTIONAL,\r
217 IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r
218 );\r
219\r
220/**\r
221 Creates a new path by appending the device node to the device path.\r
222\r
223 This function creates a new device path by appending a copy of the device node\r
224 specified by DevicePathNode to a copy of the device path specified by DevicePath\r
225 in an allocated buffer. The end-of-device-path device node is moved after the\r
226 end of the appended device node.\r
227 If DevicePathNode is NULL then a copy of DevicePath is returned.\r
228 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r
229 path device node is returned.\r
230 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r
231 device node is returned.\r
232 If there is not enough memory to allocate space for the new device path, then\r
233 NULL is returned.\r
234 The memory is allocated from EFI boot services memory. It is the responsibility\r
235 of the caller to free the memory allocated.\r
236\r
237 @param DevicePath A pointer to a device path data structure.\r
238 @param DevicePathNode A pointer to a single device path node.\r
239\r
240 @retval NULL If there is not enough memory for the new device path.\r
241 @retval Others A pointer to the new device path if success.\r
242 A copy of DevicePathNode followed by an end-of-device-path node\r
243 if both FirstDevicePath and SecondDevicePath are NULL.\r
244 A copy of an end-of-device-path node if both FirstDevicePath\r
245 and SecondDevicePath are NULL.\r
246\r
247**/\r
248EFI_DEVICE_PATH_PROTOCOL *\r
249EFIAPI\r
250UefiDevicePathLibAppendDevicePathNode (\r
251 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r
252 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r
253 );\r
254\r
255/**\r
256 Creates a new device path by appending the specified device path instance to the specified device\r
257 path.\r
258\r
259 This function creates a new device path by appending a copy of the device path\r
260 instance specified by DevicePathInstance to a copy of the device path specified\r
261 by DevicePath in a allocated buffer.\r
262 The end-of-device-path device node is moved after the end of the appended device\r
263 path instance and a new end-of-device-path-instance node is inserted between.\r
264 If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
265 If DevicePathInstance is NULL, then NULL is returned.\r
266 If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r
267 If there is not enough memory to allocate space for the new device path, then\r
268 NULL is returned.\r
269 The memory is allocated from EFI boot services memory. It is the responsibility\r
270 of the caller to free the memory allocated.\r
271\r
272 @param DevicePath A pointer to a device path data structure.\r
273 @param DevicePathInstance A pointer to a device path instance.\r
274\r
275 @return A pointer to the new device path.\r
276\r
277**/\r
278EFI_DEVICE_PATH_PROTOCOL *\r
279EFIAPI\r
280UefiDevicePathLibAppendDevicePathInstance (\r
281 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r
282 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r
283 );\r
284\r
285/**\r
286 Creates a copy of the current device path instance and returns a pointer to the next device path\r
287 instance.\r
288\r
289 This function creates a copy of the current device path instance. It also updates\r
290 DevicePath to point to the next device path instance in the device path (or NULL\r
291 if no more) and updates Size to hold the size of the device path instance copy.\r
292 If DevicePath is NULL, then NULL is returned.\r
293 If DevicePath points to a invalid device path, then NULL is returned.\r
294 If there is not enough memory to allocate space for the new device path, then\r
295 NULL is returned.\r
296 The memory is allocated from EFI boot services memory. It is the responsibility\r
297 of the caller to free the memory allocated.\r
298 If Size is NULL, then ASSERT().\r
299\r
300 @param DevicePath On input, this holds the pointer to the current\r
301 device path instance. On output, this holds\r
302 the pointer to the next device path instance\r
303 or NULL if there are no more device path\r
304 instances in the device path pointer to a\r
305 device path data structure.\r
306 @param Size On output, this holds the size of the device\r
307 path instance, in bytes or zero, if DevicePath\r
308 is NULL.\r
309\r
310 @return A pointer to the current device path instance.\r
311\r
312**/\r
313EFI_DEVICE_PATH_PROTOCOL *\r
314EFIAPI\r
315UefiDevicePathLibGetNextDevicePathInstance (\r
316 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r
317 OUT UINTN *Size\r
318 );\r
319\r
320/**\r
321 Creates a device node.\r
322\r
323 This function creates a new device node in a newly allocated buffer of size\r
324 NodeLength and initializes the device path node header with NodeType and NodeSubType.\r
325 The new device path node is returned.\r
326 If NodeLength is smaller than a device path header, then NULL is returned.\r
327 If there is not enough memory to allocate space for the new device path, then\r
328 NULL is returned.\r
329 The memory is allocated from EFI boot services memory. It is the responsibility\r
330 of the caller to free the memory allocated.\r
331\r
332 @param NodeType The device node type for the new device node.\r
333 @param NodeSubType The device node sub-type for the new device node.\r
334 @param NodeLength The length of the new device node.\r
335\r
336 @return The new device path.\r
337\r
338**/\r
339EFI_DEVICE_PATH_PROTOCOL *\r
340EFIAPI\r
341UefiDevicePathLibCreateDeviceNode (\r
342 IN UINT8 NodeType,\r
343 IN UINT8 NodeSubType,\r
344 IN UINT16 NodeLength\r
345 );\r
346\r
347/**\r
348 Determines if a device path is single or multi-instance.\r
349\r
350 This function returns TRUE if the device path specified by DevicePath is\r
351 multi-instance.\r
352 Otherwise, FALSE is returned.\r
353 If DevicePath is NULL or invalid, then FALSE is returned.\r
354\r
355 @param DevicePath A pointer to a device path data structure.\r
356\r
357 @retval TRUE DevicePath is multi-instance.\r
358 @retval FALSE DevicePath is not multi-instance, or DevicePath\r
359 is NULL or invalid.\r
360\r
361**/\r
362BOOLEAN\r
363EFIAPI\r
364UefiDevicePathLibIsDevicePathMultiInstance (\r
365 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
366 );\r
367\r
368/**\r
369 Converts a device path to its text representation.\r
370\r
371 @param DevicePath A Pointer to the device to be converted.\r
372 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r
373 of the display node is used, where applicable. If DisplayOnly\r
374 is FALSE, then the longer text representation of the display node\r
375 is used.\r
376 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r
377 representation for a device node can be used, where applicable.\r
378\r
379 @return A pointer to the allocated text representation of the device path or\r
380 NULL if DeviceNode is NULL or there was insufficient memory.\r
381\r
382**/\r
383CHAR16 *\r
384EFIAPI\r
385UefiDevicePathLibConvertDevicePathToText (\r
386 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
387 IN BOOLEAN DisplayOnly,\r
388 IN BOOLEAN AllowShortcuts\r
389 );\r
390\r
391/**\r
392 Converts a device node to its string representation.\r
393\r
394 @param DeviceNode A Pointer to the device node to be converted.\r
395 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r
396 of the display node is used, where applicable. If DisplayOnly\r
397 is FALSE, then the longer text representation of the display node\r
398 is used.\r
399 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r
400 representation for a device node can be used, where applicable.\r
401\r
402 @return A pointer to the allocated text representation of the device node or NULL if DeviceNode\r
403 is NULL or there was insufficient memory.\r
404\r
405**/\r
406CHAR16 *\r
407EFIAPI\r
408UefiDevicePathLibConvertDeviceNodeToText (\r
409 IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,\r
410 IN BOOLEAN DisplayOnly,\r
411 IN BOOLEAN AllowShortcuts\r
412 );\r
413\r
414/**\r
415 Convert text to the binary representation of a device node.\r
416\r
417 @param TextDeviceNode TextDeviceNode points to the text representation of a device\r
418 node. Conversion starts with the first character and continues\r
419 until the first non-device node character.\r
420\r
421 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r
422 insufficient memory or text unsupported.\r
423\r
424**/\r
425EFI_DEVICE_PATH_PROTOCOL *\r
426EFIAPI\r
427UefiDevicePathLibConvertTextToDeviceNode (\r
428 IN CONST CHAR16 *TextDeviceNode\r
429 );\r
430\r
431/**\r
432 Convert text to the binary representation of a device path.\r
433\r
434\r
435 @param TextDevicePath TextDevicePath points to the text representation of a device\r
436 path. Conversion starts with the first character and continues\r
437 until the first non-device node character.\r
438\r
439 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r
440 there was insufficient memory.\r
441\r
442**/\r
443EFI_DEVICE_PATH_PROTOCOL *\r
444EFIAPI\r
445UefiDevicePathLibConvertTextToDevicePath (\r
446 IN CONST CHAR16 *TextDevicePath\r
447 );\r
448\r
449#endif\r