2 Definition for Device Path library.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
8 #ifndef _UEFI_DEVICE_PATH_LIB_H_
9 #define _UEFI_DEVICE_PATH_LIB_H_
21 #include <Common/UefiBaseTypes.h>
22 #include <Protocol/DevicePath.h>
23 #include <Protocol/DevicePathUtilities.h>
24 #include "CommonLib.h"
25 #include "EfiUtilityMsgs.h"
27 #define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))
28 #define MAX_DEVICE_PATH_NODE_COUNT 1024
29 #define SIZE_64KB 0x00010000
32 // Private Data structure
35 EFI_DEVICE_PATH_PROTOCOL
*
36 (*DEVICE_PATH_FROM_TEXT
) (
48 CHAR16
*DevicePathNodeText
;
49 DEVICE_PATH_FROM_TEXT Function
;
50 } DEVICE_PATH_FROM_TEXT_TABLE
;
55 BOOLEAN SubClassExist
;
59 #define USB_CLASS_AUDIO 1
60 #define USB_CLASS_CDCCONTROL 2
61 #define USB_CLASS_HID 3
62 #define USB_CLASS_IMAGE 6
63 #define USB_CLASS_PRINTER 7
64 #define USB_CLASS_MASS_STORAGE 8
65 #define USB_CLASS_HUB 9
66 #define USB_CLASS_CDCDATA 10
67 #define USB_CLASS_SMART_CARD 11
68 #define USB_CLASS_VIDEO 14
69 #define USB_CLASS_DIAGNOSTIC 220
70 #define USB_CLASS_WIRELESS 224
72 #define USB_CLASS_RESERVE 254
73 #define USB_SUBCLASS_FW_UPDATE 1
74 #define USB_SUBCLASS_IRDA_BRIDGE 2
75 #define USB_SUBCLASS_TEST 3
77 #define RFC_1700_UDP_PROTOCOL 17
78 #define RFC_1700_TCP_PROTOCOL 6
83 EFI_DEVICE_PATH_PROTOCOL Header
;
85 UINT8 VendorDefinedData
[1];
86 } VENDOR_DEFINED_HARDWARE_DEVICE_PATH
;
89 EFI_DEVICE_PATH_PROTOCOL Header
;
91 UINT8 VendorDefinedData
[1];
92 } VENDOR_DEFINED_MESSAGING_DEVICE_PATH
;
95 EFI_DEVICE_PATH_PROTOCOL Header
;
97 UINT8 VendorDefinedData
[1];
98 } VENDOR_DEFINED_MEDIA_DEVICE_PATH
;
101 EFI_DEVICE_PATH_PROTOCOL Header
;
105 CHAR8 HidUidCidStr
[3];
106 } ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR
;
109 EFI_DEVICE_PATH_PROTOCOL Header
;
110 UINT16 NetworkProtocol
;
113 UINT16 TargetPortalGroupTag
;
115 } ISCSI_DEVICE_PATH_WITH_NAME
;
118 EFI_DEVICE_PATH_PROTOCOL Header
;
120 UINT8 VendorDefinedData
[1];
121 } VENDOR_DEVICE_PATH_WITH_DATA
;
126 Returns the size of a device path in bytes.
128 This function returns the size, in bytes, of the device path data structure
129 specified by DevicePath including the end of device path node.
130 If DevicePath is NULL or invalid, then 0 is returned.
132 @param DevicePath A pointer to a device path data structure.
134 @retval 0 If DevicePath is NULL or invalid.
135 @retval Others The size of a device path in bytes.
139 UefiDevicePathLibGetDevicePathSize (
140 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
144 Creates a new copy of an existing device path.
146 This function allocates space for a new copy of the device path specified by DevicePath.
147 If DevicePath is NULL, then NULL is returned. If the memory is successfully
148 allocated, then the contents of DevicePath are copied to the newly allocated
149 buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.
150 The memory for the new device path is allocated from EFI boot services memory.
151 It is the responsibility of the caller to free the memory allocated.
153 @param DevicePath A pointer to a device path data structure.
155 @retval NULL DevicePath is NULL or invalid.
156 @retval Others A pointer to the duplicated device path.
159 EFI_DEVICE_PATH_PROTOCOL
*
160 UefiDevicePathLibDuplicateDevicePath (
161 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
165 Creates a new device path by appending a second device path to a first device path.
167 This function creates a new device path by appending a copy of SecondDevicePath
168 to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path
169 device node from SecondDevicePath is retained. The newly created device path is
170 returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of
171 SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,
172 and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and
173 SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.
175 If there is not enough memory for the newly allocated buffer, then NULL is returned.
176 The memory for the new device path is allocated from EFI boot services memory.
177 It is the responsibility of the caller to free the memory allocated.
179 @param FirstDevicePath A pointer to a device path data structure.
180 @param SecondDevicePath A pointer to a device path data structure.
182 @retval NULL If there is not enough memory for the newly allocated buffer.
183 @retval NULL If FirstDevicePath or SecondDevicePath is invalid.
184 @retval Others A pointer to the new device path if success.
185 Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
188 EFI_DEVICE_PATH_PROTOCOL
*
189 UefiDevicePathLibAppendDevicePath (
190 CONST EFI_DEVICE_PATH_PROTOCOL
*FirstDevicePath
, OPTIONAL
191 CONST EFI_DEVICE_PATH_PROTOCOL
*SecondDevicePath OPTIONAL
195 Creates a new path by appending the device node to the device path.
197 This function creates a new device path by appending a copy of the device node
198 specified by DevicePathNode to a copy of the device path specified by DevicePath
199 in an allocated buffer. The end-of-device-path device node is moved after the
200 end of the appended device node.
201 If DevicePathNode is NULL then a copy of DevicePath is returned.
202 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device
203 path device node is returned.
204 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path
205 device node is returned.
206 If there is not enough memory to allocate space for the new device path, then
208 The memory is allocated from EFI boot services memory. It is the responsibility
209 of the caller to free the memory allocated.
211 @param DevicePath A pointer to a device path data structure.
212 @param DevicePathNode A pointer to a single device path node.
214 @retval NULL If there is not enough memory for the new device path.
215 @retval Others A pointer to the new device path if success.
216 A copy of DevicePathNode followed by an end-of-device-path node
217 if both FirstDevicePath and SecondDevicePath are NULL.
218 A copy of an end-of-device-path node if both FirstDevicePath
219 and SecondDevicePath are NULL.
222 EFI_DEVICE_PATH_PROTOCOL
*
223 UefiDevicePathLibAppendDevicePathNode (
224 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
, OPTIONAL
225 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode OPTIONAL
229 Creates a new device path by appending the specified device path instance to the specified device
232 This function creates a new device path by appending a copy of the device path
233 instance specified by DevicePathInstance to a copy of the device path specified
234 by DevicePath in a allocated buffer.
235 The end-of-device-path device node is moved after the end of the appended device
236 path instance and a new end-of-device-path-instance node is inserted between.
237 If DevicePath is NULL, then a copy if DevicePathInstance is returned.
238 If DevicePathInstance is NULL, then NULL is returned.
239 If DevicePath or DevicePathInstance is invalid, then NULL is returned.
240 If there is not enough memory to allocate space for the new device path, then
242 The memory is allocated from EFI boot services memory. It is the responsibility
243 of the caller to free the memory allocated.
245 @param DevicePath A pointer to a device path data structure.
246 @param DevicePathInstance A pointer to a device path instance.
248 @return A pointer to the new device path.
251 EFI_DEVICE_PATH_PROTOCOL
*
252 UefiDevicePathLibAppendDevicePathInstance (
253 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
, OPTIONAL
254 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathInstance OPTIONAL
258 Creates a copy of the current device path instance and returns a pointer to the next device path
261 This function creates a copy of the current device path instance. It also updates
262 DevicePath to point to the next device path instance in the device path (or NULL
263 if no more) and updates Size to hold the size of the device path instance copy.
264 If DevicePath is NULL, then NULL is returned.
265 If DevicePath points to a invalid device path, then NULL is returned.
266 If there is not enough memory to allocate space for the new device path, then
268 The memory is allocated from EFI boot services memory. It is the responsibility
269 of the caller to free the memory allocated.
270 If Size is NULL, then ASSERT().
272 @param DevicePath On input, this holds the pointer to the current
273 device path instance. On output, this holds
274 the pointer to the next device path instance
275 or NULL if there are no more device path
276 instances in the device path pointer to a
277 device path data structure.
278 @param Size On output, this holds the size of the device
279 path instance, in bytes or zero, if DevicePath
282 @return A pointer to the current device path instance.
285 EFI_DEVICE_PATH_PROTOCOL
*
286 UefiDevicePathLibGetNextDevicePathInstance (
287 EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
292 Creates a device node.
294 This function creates a new device node in a newly allocated buffer of size
295 NodeLength and initializes the device path node header with NodeType and NodeSubType.
296 The new device path node is returned.
297 If NodeLength is smaller than a device path header, then NULL is returned.
298 If there is not enough memory to allocate space for the new device path, then
300 The memory is allocated from EFI boot services memory. It is the responsibility
301 of the caller to free the memory allocated.
303 @param NodeType The device node type for the new device node.
304 @param NodeSubType The device node sub-type for the new device node.
305 @param NodeLength The length of the new device node.
307 @return The new device path.
310 EFI_DEVICE_PATH_PROTOCOL
*
311 UefiDevicePathLibCreateDeviceNode (
318 Determines if a device path is single or multi-instance.
320 This function returns TRUE if the device path specified by DevicePath is
322 Otherwise, FALSE is returned.
323 If DevicePath is NULL or invalid, then FALSE is returned.
325 @param DevicePath A pointer to a device path data structure.
327 @retval TRUE DevicePath is multi-instance.
328 @retval FALSE DevicePath is not multi-instance, or DevicePath
333 UefiDevicePathLibIsDevicePathMultiInstance (
334 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
338 Convert text to the binary representation of a device node.
340 @param TextDeviceNode TextDeviceNode points to the text representation of a device
341 node. Conversion starts with the first character and continues
342 until the first non-device node character.
344 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
345 insufficient memory or text unsupported.
348 EFI_DEVICE_PATH_PROTOCOL
*
349 UefiDevicePathLibConvertTextToDeviceNode (
350 CONST CHAR16
*TextDeviceNode
354 Convert text to the binary representation of a device path.
357 @param TextDevicePath TextDevicePath points to the text representation of a device
358 path. Conversion starts with the first character and continues
359 until the first non-device node character.
361 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
362 there was insufficient memory.
365 EFI_DEVICE_PATH_PROTOCOL
*
366 UefiDevicePathLibConvertTextToDevicePath (
367 CONST CHAR16
*TextDevicePath
370 EFI_DEVICE_PATH_PROTOCOL
*
378 IsDevicePathMultiInstance (
379 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
382 EFI_DEVICE_PATH_PROTOCOL
*
383 GetNextDevicePathInstance (
384 EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
388 EFI_DEVICE_PATH_PROTOCOL
*
389 AppendDevicePathInstance (
390 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
, OPTIONAL
391 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathInstance OPTIONAL
394 EFI_DEVICE_PATH_PROTOCOL
*
395 AppendDevicePathNode (
396 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
, OPTIONAL
397 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode OPTIONAL
399 EFI_DEVICE_PATH_PROTOCOL
*
401 CONST EFI_DEVICE_PATH_PROTOCOL
*FirstDevicePath
, OPTIONAL
402 CONST EFI_DEVICE_PATH_PROTOCOL
*SecondDevicePath OPTIONAL
405 EFI_DEVICE_PATH_PROTOCOL
*
406 DuplicateDevicePath (
407 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
412 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
416 ConvertDeviceNodeToText (
417 CONST EFI_DEVICE_PATH_PROTOCOL
*DeviceNode
,
419 BOOLEAN AllowShortcuts
423 ConvertDevicePathToText (
424 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
426 BOOLEAN AllowShortcuts
429 EFI_DEVICE_PATH_PROTOCOL
*
430 ConvertTextToDeviceNode (
431 CONST CHAR16
*TextDeviceNode
434 EFI_DEVICE_PATH_PROTOCOL
*
435 ConvertTextToDevicePath (
436 CONST CHAR16
*TextDevicePath