]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / UefiDevicePathLib.h
CommitLineData
13d40edd 1/** @file\r
4d0a30a4 2 Definition for Device Path library.\r
95276127 3\r
9095d37b 4Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
95276127 6\r
13d40edd 7**/\r
95276127 8\r
4d0a30a4
RN
9#ifndef _UEFI_DEVICE_PATH_LIB_H_\r
10#define _UEFI_DEVICE_PATH_LIB_H_\r
60c93673 11#include <Uefi.h>\r
859b72fa
A
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
859b72fa
A
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
7795c8f9 25#include <IndustryStandard/Bluetooth.h>\r
95276127 26\r
2f88bd3a
MK
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
95276127 34\r
95276127 35//\r
36// Private Data structure\r
37//\r
38typedef struct {\r
2f88bd3a
MK
39 CHAR16 *Str;\r
40 UINTN Count;\r
41 UINTN Capacity;\r
95276127 42} POOL_PRINT;\r
43\r
572f5d8a 44typedef\r
45EFI_DEVICE_PATH_PROTOCOL *\r
4d0a30a4 46(*DEVICE_PATH_FROM_TEXT) (\r
2f88bd3a 47 IN CHAR16 *Str\r
572f5d8a 48 );\r
49\r
1ccdbf2a 50typedef\r
51VOID\r
4d0a30a4 52(*DEVICE_PATH_TO_TEXT) (\r
1ccdbf2a 53 IN OUT POOL_PRINT *Str,\r
4d0a30a4 54 IN VOID *DevicePath,\r
1ccdbf2a 55 IN BOOLEAN DisplayOnly,\r
56 IN BOOLEAN AllowShortcuts\r
57 );\r
58\r
95276127 59typedef struct {\r
2f88bd3a
MK
60 UINT8 Type;\r
61 UINT8 SubType;\r
62 DEVICE_PATH_TO_TEXT Function;\r
95276127 63} DEVICE_PATH_TO_TEXT_TABLE;\r
64\r
5d6a5aee 65typedef struct {\r
2f88bd3a
MK
66 UINT8 Type;\r
67 CHAR16 *Text;\r
5d6a5aee
RN
68} DEVICE_PATH_TO_TEXT_GENERIC_TABLE;\r
69\r
95276127 70typedef struct {\r
2f88bd3a
MK
71 CHAR16 *DevicePathNodeText;\r
72 DEVICE_PATH_FROM_TEXT Function;\r
95276127 73} DEVICE_PATH_FROM_TEXT_TABLE;\r
74\r
75typedef struct {\r
2f88bd3a
MK
76 BOOLEAN ClassExist;\r
77 UINT8 Class;\r
78 BOOLEAN SubClassExist;\r
79 UINT8 SubClass;\r
95276127 80} USB_CLASS_TEXT;\r
81\r
2f88bd3a
MK
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
052019e1 102\r
cf40f28a 103#pragma pack(1)\r
104\r
95276127 105typedef struct {\r
2f88bd3a
MK
106 EFI_DEVICE_PATH_PROTOCOL Header;\r
107 EFI_GUID Guid;\r
108 UINT8 VendorDefinedData[1];\r
95276127 109} VENDOR_DEFINED_HARDWARE_DEVICE_PATH;\r
110\r
111typedef struct {\r
2f88bd3a
MK
112 EFI_DEVICE_PATH_PROTOCOL Header;\r
113 EFI_GUID Guid;\r
114 UINT8 VendorDefinedData[1];\r
95276127 115} VENDOR_DEFINED_MESSAGING_DEVICE_PATH;\r
116\r
117typedef struct {\r
2f88bd3a
MK
118 EFI_DEVICE_PATH_PROTOCOL Header;\r
119 EFI_GUID Guid;\r
120 UINT8 VendorDefinedData[1];\r
95276127 121} VENDOR_DEFINED_MEDIA_DEVICE_PATH;\r
122\r
123typedef struct {\r
2f88bd3a
MK
124 EFI_DEVICE_PATH_PROTOCOL Header;\r
125 UINT32 Hid;\r
126 UINT32 Uid;\r
127 UINT32 Cid;\r
128 CHAR8 HidUidCidStr[3];\r
95276127 129} ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR;\r
130\r
131typedef struct {\r
2f88bd3a
MK
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
95276127 138} ISCSI_DEVICE_PATH_WITH_NAME;\r
139\r
140typedef struct {\r
2f88bd3a
MK
141 EFI_DEVICE_PATH_PROTOCOL Header;\r
142 EFI_GUID Guid;\r
143 UINT8 VendorDefinedData[1];\r
95276127 144} VENDOR_DEVICE_PATH_WITH_DATA;\r
145\r
cf40f28a 146#pragma pack()\r
147\r
572f5d8a 148/**\r
4d0a30a4 149 Returns the size of a device path in bytes.\r
572f5d8a 150\r
9095d37b 151 This function returns the size, in bytes, of the device path data structure\r
4d0a30a4
RN
152 specified by DevicePath including the end of device path node.\r
153 If DevicePath is NULL or invalid, then 0 is returned.\r
572f5d8a 154\r
4d0a30a4
RN
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
572f5d8a 159\r
160**/\r
4d0a30a4 161UINTN\r
572f5d8a 162EFIAPI\r
4d0a30a4
RN
163UefiDevicePathLibGetDevicePathSize (\r
164 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
572f5d8a 165 );\r
95276127 166\r
572f5d8a 167/**\r
4d0a30a4
RN
168 Creates a new copy of an existing device path.\r
169\r
9095d37b
LG
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
4d0a30a4
RN
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
9095d37b 181\r
572f5d8a 182**/\r
4d0a30a4 183EFI_DEVICE_PATH_PROTOCOL *\r
572f5d8a 184EFIAPI\r
4d0a30a4
RN
185UefiDevicePathLibDuplicateDevicePath (\r
186 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
572f5d8a 187 );\r
95276127 188\r
572f5d8a 189/**\r
4d0a30a4 190 Creates a new device path by appending a second device path to a first device path.\r
95276127 191\r
9095d37b
LG
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
4d0a30a4 200 If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
9095d37b 201 The memory for the new device path is allocated from EFI boot services memory.\r
4d0a30a4 202 It is the responsibility of the caller to free the memory allocated.\r
95276127 203\r
4d0a30a4
RN
204 @param FirstDevicePath A pointer to a device path data structure.\r
205 @param SecondDevicePath A pointer to a device path data structure.\r
9095d37b 206\r
4d0a30a4
RN
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
95276127 211\r
572f5d8a 212**/\r
95276127 213EFI_DEVICE_PATH_PROTOCOL *\r
572f5d8a 214EFIAPI\r
4d0a30a4 215UefiDevicePathLibAppendDevicePath (\r
d0e2f823 216 IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath OPTIONAL,\r
4d0a30a4 217 IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r
572f5d8a 218 );\r
95276127 219\r
572f5d8a 220/**\r
4d0a30a4 221 Creates a new path by appending the device node to the device path.\r
95276127 222\r
9095d37b
LG
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
4d0a30a4
RN
226 end of the appended device node.\r
227 If DevicePathNode is NULL then a copy of DevicePath is returned.\r
9095d37b 228 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r
4d0a30a4 229 path device node is returned.\r
9095d37b 230 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r
4d0a30a4 231 device node is returned.\r
9095d37b
LG
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
4d0a30a4 235 of the caller to free the memory allocated.\r
95276127 236\r
4d0a30a4
RN
237 @param DevicePath A pointer to a device path data structure.\r
238 @param DevicePathNode A pointer to a single device path node.\r
95276127 239\r
4d0a30a4
RN
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
9095d37b 242 A copy of DevicePathNode followed by an end-of-device-path node\r
4d0a30a4 243 if both FirstDevicePath and SecondDevicePath are NULL.\r
9095d37b 244 A copy of an end-of-device-path node if both FirstDevicePath\r
4d0a30a4 245 and SecondDevicePath are NULL.\r
95276127 246\r
572f5d8a 247**/\r
95276127 248EFI_DEVICE_PATH_PROTOCOL *\r
572f5d8a 249EFIAPI\r
4d0a30a4 250UefiDevicePathLibAppendDevicePathNode (\r
d0e2f823 251 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r
4d0a30a4 252 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r
572f5d8a 253 );\r
95276127 254\r
572f5d8a 255/**\r
4d0a30a4
RN
256 Creates a new device path by appending the specified device path instance to the specified device\r
257 path.\r
9095d37b
LG
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
4d0a30a4 261 by DevicePath in a allocated buffer.\r
9095d37b
LG
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
4d0a30a4
RN
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
9095d37b
LG
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
4d0a30a4 270 of the caller to free the memory allocated.\r
9095d37b 271\r
572f5d8a 272 @param DevicePath A pointer to a device path data structure.\r
4d0a30a4 273 @param DevicePathInstance A pointer to a device path instance.\r
95276127 274\r
4d0a30a4 275 @return A pointer to the new device path.\r
95276127 276\r
572f5d8a 277**/\r
4d0a30a4 278EFI_DEVICE_PATH_PROTOCOL *\r
572f5d8a 279EFIAPI\r
4d0a30a4 280UefiDevicePathLibAppendDevicePathInstance (\r
d0e2f823 281 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r
4d0a30a4 282 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r
572f5d8a 283 );\r
95276127 284\r
572f5d8a 285/**\r
4d0a30a4
RN
286 Creates a copy of the current device path instance and returns a pointer to the next device path\r
287 instance.\r
95276127 288\r
9095d37b
LG
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
4d0a30a4
RN
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
9095d37b
LG
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
4d0a30a4
RN
297 of the caller to free the memory allocated.\r
298 If Size is NULL, then ASSERT().\r
9095d37b
LG
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
4d0a30a4 303 or NULL if there are no more device path\r
9095d37b 304 instances in the device path pointer to a\r
4d0a30a4 305 device path data structure.\r
9095d37b
LG
306 @param Size On output, this holds the size of the device\r
307 path instance, in bytes or zero, if DevicePath\r
4d0a30a4 308 is NULL.\r
95276127 309\r
4d0a30a4 310 @return A pointer to the current device path instance.\r
95276127 311\r
572f5d8a 312**/\r
95276127 313EFI_DEVICE_PATH_PROTOCOL *\r
572f5d8a 314EFIAPI\r
4d0a30a4 315UefiDevicePathLibGetNextDevicePathInstance (\r
2f88bd3a
MK
316 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r
317 OUT UINTN *Size\r
572f5d8a 318 );\r
95276127 319\r
572f5d8a 320/**\r
4d0a30a4 321 Creates a device node.\r
95276127 322\r
9095d37b
LG
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
4d0a30a4 325 The new device path node is returned.\r
9095d37b
LG
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
4d0a30a4 330 of the caller to free the memory allocated.\r
95276127 331\r
4d0a30a4
RN
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
95276127 335\r
4d0a30a4 336 @return The new device path.\r
95276127 337\r
572f5d8a 338**/\r
95276127 339EFI_DEVICE_PATH_PROTOCOL *\r
572f5d8a 340EFIAPI\r
4d0a30a4 341UefiDevicePathLibCreateDeviceNode (\r
2f88bd3a
MK
342 IN UINT8 NodeType,\r
343 IN UINT8 NodeSubType,\r
344 IN UINT16 NodeLength\r
572f5d8a 345 );\r
346\r
347/**\r
4d0a30a4 348 Determines if a device path is single or multi-instance.\r
572f5d8a 349\r
4d0a30a4
RN
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
572f5d8a 354\r
355 @param DevicePath A pointer to a device path data structure.\r
572f5d8a 356\r
4d0a30a4 357 @retval TRUE DevicePath is multi-instance.\r
9095d37b 358 @retval FALSE DevicePath is not multi-instance, or DevicePath\r
4d0a30a4 359 is NULL or invalid.\r
95276127 360\r
572f5d8a 361**/\r
4d0a30a4 362BOOLEAN\r
572f5d8a 363EFIAPI\r
4d0a30a4
RN
364UefiDevicePathLibIsDevicePathMultiInstance (\r
365 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
572f5d8a 366 );\r
95276127 367\r
4d0a30a4
RN
368/**\r
369 Converts a device path to its text representation.\r
95276127 370\r
4d0a30a4
RN
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
95276127 378\r
4d0a30a4
RN
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
95276127 381\r
572f5d8a 382**/\r
4d0a30a4 383CHAR16 *\r
572f5d8a 384EFIAPI\r
4d0a30a4 385UefiDevicePathLibConvertDevicePathToText (\r
2f88bd3a
MK
386 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
387 IN BOOLEAN DisplayOnly,\r
388 IN BOOLEAN AllowShortcuts\r
572f5d8a 389 );\r
390\r
391/**\r
4d0a30a4 392 Converts a device node to its string representation.\r
572f5d8a 393\r
4d0a30a4
RN
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
572f5d8a 401\r
4d0a30a4
RN
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
95276127 404\r
572f5d8a 405**/\r
4d0a30a4 406CHAR16 *\r
572f5d8a 407EFIAPI\r
4d0a30a4
RN
408UefiDevicePathLibConvertDeviceNodeToText (\r
409 IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,\r
410 IN BOOLEAN DisplayOnly,\r
411 IN BOOLEAN AllowShortcuts\r
572f5d8a 412 );\r
95276127 413\r
572f5d8a 414/**\r
4d0a30a4 415 Convert text to the binary representation of a device node.\r
95276127 416\r
4d0a30a4
RN
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
95276127 420\r
4d0a30a4
RN
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
95276127 423\r
572f5d8a 424**/\r
4d0a30a4 425EFI_DEVICE_PATH_PROTOCOL *\r
572f5d8a 426EFIAPI\r
4d0a30a4 427UefiDevicePathLibConvertTextToDeviceNode (\r
2f88bd3a 428 IN CONST CHAR16 *TextDeviceNode\r
572f5d8a 429 );\r
95276127 430\r
572f5d8a 431/**\r
4d0a30a4 432 Convert text to the binary representation of a device path.\r
95276127 433\r
95276127 434\r
4d0a30a4
RN
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
95276127 438\r
4d0a30a4
RN
439 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r
440 there was insufficient memory.\r
95276127 441\r
572f5d8a 442**/\r
95276127 443EFI_DEVICE_PATH_PROTOCOL *\r
572f5d8a 444EFIAPI\r
4d0a30a4 445UefiDevicePathLibConvertTextToDevicePath (\r
2f88bd3a 446 IN CONST CHAR16 *TextDevicePath\r
572f5d8a 447 );\r
95276127 448\r
449#endif\r