2 Definition for Device Path library.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #ifndef _UEFI_DEVICE_PATH_LIB_H_
15 #define _UEFI_DEVICE_PATH_LIB_H_
27 #include <Common/UefiBaseTypes.h>
28 #include <Protocol/DevicePath.h>
29 #include <Protocol/DevicePathUtilities.h>
30 #include "CommonLib.h"
31 #include "EfiUtilityMsgs.h"
33 #define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))
34 #define MAX_DEVICE_PATH_NODE_COUNT 1024
35 #define SIZE_64KB 0x00010000
38 // Private Data structure
41 EFI_DEVICE_PATH_PROTOCOL
*
42 (*DEVICE_PATH_FROM_TEXT
) (
54 CHAR16
*DevicePathNodeText
;
55 DEVICE_PATH_FROM_TEXT Function
;
56 } DEVICE_PATH_FROM_TEXT_TABLE
;
61 BOOLEAN SubClassExist
;
65 #define USB_CLASS_AUDIO 1
66 #define USB_CLASS_CDCCONTROL 2
67 #define USB_CLASS_HID 3
68 #define USB_CLASS_IMAGE 6
69 #define USB_CLASS_PRINTER 7
70 #define USB_CLASS_MASS_STORAGE 8
71 #define USB_CLASS_HUB 9
72 #define USB_CLASS_CDCDATA 10
73 #define USB_CLASS_SMART_CARD 11
74 #define USB_CLASS_VIDEO 14
75 #define USB_CLASS_DIAGNOSTIC 220
76 #define USB_CLASS_WIRELESS 224
78 #define USB_CLASS_RESERVE 254
79 #define USB_SUBCLASS_FW_UPDATE 1
80 #define USB_SUBCLASS_IRDA_BRIDGE 2
81 #define USB_SUBCLASS_TEST 3
83 #define RFC_1700_UDP_PROTOCOL 17
84 #define RFC_1700_TCP_PROTOCOL 6
89 EFI_DEVICE_PATH_PROTOCOL Header
;
91 UINT8 VendorDefinedData
[1];
92 } VENDOR_DEFINED_HARDWARE_DEVICE_PATH
;
95 EFI_DEVICE_PATH_PROTOCOL Header
;
97 UINT8 VendorDefinedData
[1];
98 } VENDOR_DEFINED_MESSAGING_DEVICE_PATH
;
101 EFI_DEVICE_PATH_PROTOCOL Header
;
103 UINT8 VendorDefinedData
[1];
104 } VENDOR_DEFINED_MEDIA_DEVICE_PATH
;
107 EFI_DEVICE_PATH_PROTOCOL Header
;
111 CHAR8 HidUidCidStr
[3];
112 } ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR
;
115 EFI_DEVICE_PATH_PROTOCOL Header
;
116 UINT16 NetworkProtocol
;
119 UINT16 TargetPortalGroupTag
;
121 } ISCSI_DEVICE_PATH_WITH_NAME
;
124 EFI_DEVICE_PATH_PROTOCOL Header
;
126 UINT8 VendorDefinedData
[1];
127 } VENDOR_DEVICE_PATH_WITH_DATA
;
132 Returns the size of a device path in bytes.
134 This function returns the size, in bytes, of the device path data structure
135 specified by DevicePath including the end of device path node.
136 If DevicePath is NULL or invalid, then 0 is returned.
138 @param DevicePath A pointer to a device path data structure.
140 @retval 0 If DevicePath is NULL or invalid.
141 @retval Others The size of a device path in bytes.
145 UefiDevicePathLibGetDevicePathSize (
146 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
150 Creates a new copy of an existing device path.
152 This function allocates space for a new copy of the device path specified by DevicePath.
153 If DevicePath is NULL, then NULL is returned. If the memory is successfully
154 allocated, then the contents of DevicePath are copied to the newly allocated
155 buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.
156 The memory for the new device path is allocated from EFI boot services memory.
157 It is the responsibility of the caller to free the memory allocated.
159 @param DevicePath A pointer to a device path data structure.
161 @retval NULL DevicePath is NULL or invalid.
162 @retval Others A pointer to the duplicated device path.
165 EFI_DEVICE_PATH_PROTOCOL
*
166 UefiDevicePathLibDuplicateDevicePath (
167 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
171 Creates a new device path by appending a second device path to a first device path.
173 This function creates a new device path by appending a copy of SecondDevicePath
174 to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path
175 device node from SecondDevicePath is retained. The newly created device path is
176 returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of
177 SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,
178 and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and
179 SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.
181 If there is not enough memory for the newly allocated buffer, then NULL is returned.
182 The memory for the new device path is allocated from EFI boot services memory.
183 It is the responsibility of the caller to free the memory allocated.
185 @param FirstDevicePath A pointer to a device path data structure.
186 @param SecondDevicePath A pointer to a device path data structure.
188 @retval NULL If there is not enough memory for the newly allocated buffer.
189 @retval NULL If FirstDevicePath or SecondDevicePath is invalid.
190 @retval Others A pointer to the new device path if success.
191 Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
194 EFI_DEVICE_PATH_PROTOCOL
*
195 UefiDevicePathLibAppendDevicePath (
196 CONST EFI_DEVICE_PATH_PROTOCOL
*FirstDevicePath
, OPTIONAL
197 CONST EFI_DEVICE_PATH_PROTOCOL
*SecondDevicePath OPTIONAL
201 Creates a new path by appending the device node to the device path.
203 This function creates a new device path by appending a copy of the device node
204 specified by DevicePathNode to a copy of the device path specified by DevicePath
205 in an allocated buffer. The end-of-device-path device node is moved after the
206 end of the appended device node.
207 If DevicePathNode is NULL then a copy of DevicePath is returned.
208 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device
209 path device node is returned.
210 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path
211 device node is returned.
212 If there is not enough memory to allocate space for the new device path, then
214 The memory is allocated from EFI boot services memory. It is the responsibility
215 of the caller to free the memory allocated.
217 @param DevicePath A pointer to a device path data structure.
218 @param DevicePathNode A pointer to a single device path node.
220 @retval NULL If there is not enough memory for the new device path.
221 @retval Others A pointer to the new device path if success.
222 A copy of DevicePathNode followed by an end-of-device-path node
223 if both FirstDevicePath and SecondDevicePath are NULL.
224 A copy of an end-of-device-path node if both FirstDevicePath
225 and SecondDevicePath are NULL.
228 EFI_DEVICE_PATH_PROTOCOL
*
229 UefiDevicePathLibAppendDevicePathNode (
230 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
, OPTIONAL
231 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode OPTIONAL
235 Creates a new device path by appending the specified device path instance to the specified device
238 This function creates a new device path by appending a copy of the device path
239 instance specified by DevicePathInstance to a copy of the device path specified
240 by DevicePath in a allocated buffer.
241 The end-of-device-path device node is moved after the end of the appended device
242 path instance and a new end-of-device-path-instance node is inserted between.
243 If DevicePath is NULL, then a copy if DevicePathInstance is returned.
244 If DevicePathInstance is NULL, then NULL is returned.
245 If DevicePath or DevicePathInstance is invalid, then NULL is returned.
246 If there is not enough memory to allocate space for the new device path, then
248 The memory is allocated from EFI boot services memory. It is the responsibility
249 of the caller to free the memory allocated.
251 @param DevicePath A pointer to a device path data structure.
252 @param DevicePathInstance A pointer to a device path instance.
254 @return A pointer to the new device path.
257 EFI_DEVICE_PATH_PROTOCOL
*
258 UefiDevicePathLibAppendDevicePathInstance (
259 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
, OPTIONAL
260 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathInstance OPTIONAL
264 Creates a copy of the current device path instance and returns a pointer to the next device path
267 This function creates a copy of the current device path instance. It also updates
268 DevicePath to point to the next device path instance in the device path (or NULL
269 if no more) and updates Size to hold the size of the device path instance copy.
270 If DevicePath is NULL, then NULL is returned.
271 If DevicePath points to a invalid device path, then NULL is returned.
272 If there is not enough memory to allocate space for the new device path, then
274 The memory is allocated from EFI boot services memory. It is the responsibility
275 of the caller to free the memory allocated.
276 If Size is NULL, then ASSERT().
278 @param DevicePath On input, this holds the pointer to the current
279 device path instance. On output, this holds
280 the pointer to the next device path instance
281 or NULL if there are no more device path
282 instances in the device path pointer to a
283 device path data structure.
284 @param Size On output, this holds the size of the device
285 path instance, in bytes or zero, if DevicePath
288 @return A pointer to the current device path instance.
291 EFI_DEVICE_PATH_PROTOCOL
*
292 UefiDevicePathLibGetNextDevicePathInstance (
293 EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
298 Creates a device node.
300 This function creates a new device node in a newly allocated buffer of size
301 NodeLength and initializes the device path node header with NodeType and NodeSubType.
302 The new device path node is returned.
303 If NodeLength is smaller than a device path header, then NULL is returned.
304 If there is not enough memory to allocate space for the new device path, then
306 The memory is allocated from EFI boot services memory. It is the responsibility
307 of the caller to free the memory allocated.
309 @param NodeType The device node type for the new device node.
310 @param NodeSubType The device node sub-type for the new device node.
311 @param NodeLength The length of the new device node.
313 @return The new device path.
316 EFI_DEVICE_PATH_PROTOCOL
*
317 UefiDevicePathLibCreateDeviceNode (
324 Determines if a device path is single or multi-instance.
326 This function returns TRUE if the device path specified by DevicePath is
328 Otherwise, FALSE is returned.
329 If DevicePath is NULL or invalid, then FALSE is returned.
331 @param DevicePath A pointer to a device path data structure.
333 @retval TRUE DevicePath is multi-instance.
334 @retval FALSE DevicePath is not multi-instance, or DevicePath
339 UefiDevicePathLibIsDevicePathMultiInstance (
340 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
344 Convert text to the binary representation of a device node.
346 @param TextDeviceNode TextDeviceNode points to the text representation of a device
347 node. Conversion starts with the first character and continues
348 until the first non-device node character.
350 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
351 insufficient memory or text unsupported.
354 EFI_DEVICE_PATH_PROTOCOL
*
355 UefiDevicePathLibConvertTextToDeviceNode (
356 CONST CHAR16
*TextDeviceNode
360 Convert text to the binary representation of a device path.
363 @param TextDevicePath TextDevicePath points to the text representation of a device
364 path. Conversion starts with the first character and continues
365 until the first non-device node character.
367 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
368 there was insufficient memory.
371 EFI_DEVICE_PATH_PROTOCOL
*
372 UefiDevicePathLibConvertTextToDevicePath (
373 CONST CHAR16
*TextDevicePath
376 EFI_DEVICE_PATH_PROTOCOL
*
383 EFI_DEVICE_PATH_PROTOCOL
*
391 IsDevicePathMultiInstance (
392 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
395 EFI_DEVICE_PATH_PROTOCOL
*
396 GetNextDevicePathInstance (
397 EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
401 EFI_DEVICE_PATH_PROTOCOL
*
402 AppendDevicePathInstance (
403 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
, OPTIONAL
404 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathInstance OPTIONAL
407 EFI_DEVICE_PATH_PROTOCOL
*
408 AppendDevicePathNode (
409 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
, OPTIONAL
410 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode OPTIONAL
412 EFI_DEVICE_PATH_PROTOCOL
*
414 CONST EFI_DEVICE_PATH_PROTOCOL
*FirstDevicePath
, OPTIONAL
415 CONST EFI_DEVICE_PATH_PROTOCOL
*SecondDevicePath OPTIONAL
418 EFI_DEVICE_PATH_PROTOCOL
*
419 DuplicateDevicePath (
420 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
425 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
429 ConvertDeviceNodeToText (
430 CONST EFI_DEVICE_PATH_PROTOCOL
*DeviceNode
,
432 BOOLEAN AllowShortcuts
436 ConvertDevicePathToText (
437 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
439 BOOLEAN AllowShortcuts
442 EFI_DEVICE_PATH_PROTOCOL
*
443 ConvertTextToDeviceNode (
444 CONST CHAR16
*TextDeviceNode
447 EFI_DEVICE_PATH_PROTOCOL
*
448 ConvertTextToDevicePath (
449 CONST CHAR16
*TextDevicePath