]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / UefiDevicePathLib.c
CommitLineData
e386b444 1/** @file\r
2 Device Path services. The thing to remember is device paths are built out of\r
3 nodes. The device path is terminated by an end node that is length\r
4 sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)\r
5 all over this file.\r
6\r
7 The only place where multi-instance device paths are supported is in\r
8 environment varibles. Multi-instance device paths should never be placed\r
9 on a Handle.\r
10\r
9095d37b 11 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 12 SPDX-License-Identifier: BSD-2-Clause-Patent\r
e386b444 13\r
e386b444 14**/\r
15\r
4d0a30a4 16#include "UefiDevicePathLib.h"\r
3dc728fb 17\r
e386b444 18/**\r
19 Returns the size of a device path in bytes.\r
20\r
9095d37b 21 This function returns the size, in bytes, of the device path data structure\r
771729c7
RN
22 specified by DevicePath including the end of device path node.\r
23 If DevicePath is NULL or invalid, then 0 is returned.\r
e386b444 24\r
58380e9c 25 @param DevicePath A pointer to a device path data structure.\r
771729c7
RN
26\r
27 @retval 0 If DevicePath is NULL or invalid.\r
58380e9c 28 @retval Others The size of a device path in bytes.\r
e386b444 29\r
30**/\r
31UINTN\r
32EFIAPI\r
33GetDevicePathSize (\r
34 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
35 )\r
36{\r
4d0a30a4 37 return UefiDevicePathLibGetDevicePathSize (DevicePath);\r
e386b444 38}\r
39\r
40/**\r
6a3f4ef9 41 Creates a new copy of an existing device path.\r
e386b444 42\r
9095d37b
LG
43 This function allocates space for a new copy of the device path specified by DevicePath.\r
44 If DevicePath is NULL, then NULL is returned. If the memory is successfully\r
45 allocated, then the contents of DevicePath are copied to the newly allocated\r
46 buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.\r
47 The memory for the new device path is allocated from EFI boot services memory.\r
48 It is the responsibility of the caller to free the memory allocated.\r
49\r
58380e9c 50 @param DevicePath A pointer to a device path data structure.\r
e386b444 51\r
771729c7 52 @retval NULL DevicePath is NULL or invalid.\r
58380e9c 53 @retval Others A pointer to the duplicated device path.\r
9095d37b 54\r
e386b444 55**/\r
56EFI_DEVICE_PATH_PROTOCOL *\r
57EFIAPI\r
58DuplicateDevicePath (\r
59 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
60 )\r
61{\r
4d0a30a4 62 return UefiDevicePathLibDuplicateDevicePath (DevicePath);\r
e386b444 63}\r
64\r
65/**\r
66 Creates a new device path by appending a second device path to a first device path.\r
67\r
9095d37b
LG
68 This function creates a new device path by appending a copy of SecondDevicePath\r
69 to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path\r
70 device node from SecondDevicePath is retained. The newly created device path is\r
71 returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of\r
72 SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,\r
73 and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and\r
74 SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.\r
75\r
e386b444 76 If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
9095d37b 77 The memory for the new device path is allocated from EFI boot services memory.\r
58380e9c 78 It is the responsibility of the caller to free the memory allocated.\r
e386b444 79\r
80 @param FirstDevicePath A pointer to a device path data structure.\r
81 @param SecondDevicePath A pointer to a device path data structure.\r
9095d37b 82\r
3e5c3238 83 @retval NULL If there is not enough memory for the newly allocated buffer.\r
771729c7 84 @retval NULL If FirstDevicePath or SecondDevicePath is invalid.\r
3e5c3238 85 @retval Others A pointer to the new device path if success.\r
86 Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r
e386b444 87\r
88**/\r
89EFI_DEVICE_PATH_PROTOCOL *\r
90EFIAPI\r
91AppendDevicePath (\r
d0e2f823 92 IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath OPTIONAL,\r
e386b444 93 IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r
94 )\r
95{\r
4d0a30a4 96 return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);\r
e386b444 97}\r
98\r
99/**\r
100 Creates a new path by appending the device node to the device path.\r
101\r
9095d37b
LG
102 This function creates a new device path by appending a copy of the device node\r
103 specified by DevicePathNode to a copy of the device path specified by DevicePath\r
104 in an allocated buffer. The end-of-device-path device node is moved after the\r
58380e9c 105 end of the appended device node.\r
98a14db6 106 If DevicePathNode is NULL then a copy of DevicePath is returned.\r
9095d37b 107 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r
58380e9c 108 path device node is returned.\r
9095d37b 109 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r
58380e9c 110 device node is returned.\r
9095d37b
LG
111 If there is not enough memory to allocate space for the new device path, then\r
112 NULL is returned.\r
113 The memory is allocated from EFI boot services memory. It is the responsibility\r
58380e9c 114 of the caller to free the memory allocated.\r
e386b444 115\r
116 @param DevicePath A pointer to a device path data structure.\r
117 @param DevicePathNode A pointer to a single device path node.\r
118\r
3e5c3238 119 @retval NULL If there is not enough memory for the new device path.\r
120 @retval Others A pointer to the new device path if success.\r
9095d37b 121 A copy of DevicePathNode followed by an end-of-device-path node\r
3e5c3238 122 if both FirstDevicePath and SecondDevicePath are NULL.\r
9095d37b 123 A copy of an end-of-device-path node if both FirstDevicePath\r
58380e9c 124 and SecondDevicePath are NULL.\r
e386b444 125\r
126**/\r
127EFI_DEVICE_PATH_PROTOCOL *\r
128EFIAPI\r
129AppendDevicePathNode (\r
d0e2f823 130 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r
e386b444 131 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r
132 )\r
133{\r
4d0a30a4 134 return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);\r
e386b444 135}\r
136\r
137/**\r
138 Creates a new device path by appending the specified device path instance to the specified device\r
139 path.\r
9095d37b
LG
140\r
141 This function creates a new device path by appending a copy of the device path\r
142 instance specified by DevicePathInstance to a copy of the device path specified\r
58380e9c 143 by DevicePath in a allocated buffer.\r
9095d37b
LG
144 The end-of-device-path device node is moved after the end of the appended device\r
145 path instance and a new end-of-device-path-instance node is inserted between.\r
e386b444 146 If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
147 If DevicePathInstance is NULL, then NULL is returned.\r
771729c7 148 If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r
9095d37b
LG
149 If there is not enough memory to allocate space for the new device path, then\r
150 NULL is returned.\r
151 The memory is allocated from EFI boot services memory. It is the responsibility\r
58380e9c 152 of the caller to free the memory allocated.\r
9095d37b 153\r
e386b444 154 @param DevicePath A pointer to a device path data structure.\r
155 @param DevicePathInstance A pointer to a device path instance.\r
156\r
157 @return A pointer to the new device path.\r
158\r
159**/\r
160EFI_DEVICE_PATH_PROTOCOL *\r
161EFIAPI\r
162AppendDevicePathInstance (\r
d0e2f823 163 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r
e386b444 164 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r
165 )\r
166{\r
4d0a30a4 167 return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);\r
e386b444 168}\r
169\r
170/**\r
171 Creates a copy of the current device path instance and returns a pointer to the next device path\r
172 instance.\r
173\r
9095d37b
LG
174 This function creates a copy of the current device path instance. It also updates\r
175 DevicePath to point to the next device path instance in the device path (or NULL\r
58380e9c 176 if no more) and updates Size to hold the size of the device path instance copy.\r
e386b444 177 If DevicePath is NULL, then NULL is returned.\r
771729c7 178 If DevicePath points to a invalid device path, then NULL is returned.\r
9095d37b
LG
179 If there is not enough memory to allocate space for the new device path, then\r
180 NULL is returned.\r
181 The memory is allocated from EFI boot services memory. It is the responsibility\r
58380e9c 182 of the caller to free the memory allocated.\r
e386b444 183 If Size is NULL, then ASSERT().\r
9095d37b
LG
184\r
185 @param DevicePath On input, this holds the pointer to the current\r
186 device path instance. On output, this holds\r
187 the pointer to the next device path instance\r
58380e9c 188 or NULL if there are no more device path\r
9095d37b 189 instances in the device path pointer to a\r
58380e9c 190 device path data structure.\r
9095d37b
LG
191 @param Size On output, this holds the size of the device\r
192 path instance, in bytes or zero, if DevicePath\r
58380e9c 193 is NULL.\r
e386b444 194\r
195 @return A pointer to the current device path instance.\r
196\r
197**/\r
198EFI_DEVICE_PATH_PROTOCOL *\r
199EFIAPI\r
200GetNextDevicePathInstance (\r
2f88bd3a
MK
201 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r
202 OUT UINTN *Size\r
e386b444 203 )\r
204{\r
4d0a30a4 205 return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);\r
e386b444 206}\r
207\r
208/**\r
3e5c3238 209 Creates a device node.\r
e386b444 210\r
9095d37b
LG
211 This function creates a new device node in a newly allocated buffer of size\r
212 NodeLength and initializes the device path node header with NodeType and NodeSubType.\r
58380e9c 213 The new device path node is returned.\r
9095d37b
LG
214 If NodeLength is smaller than a device path header, then NULL is returned.\r
215 If there is not enough memory to allocate space for the new device path, then\r
216 NULL is returned.\r
217 The memory is allocated from EFI boot services memory. It is the responsibility\r
58380e9c 218 of the caller to free the memory allocated.\r
e386b444 219\r
220 @param NodeType The device node type for the new device node.\r
221 @param NodeSubType The device node sub-type for the new device node.\r
222 @param NodeLength The length of the new device node.\r
223\r
3e5c3238 224 @return The new device path.\r
e386b444 225\r
226**/\r
227EFI_DEVICE_PATH_PROTOCOL *\r
228EFIAPI\r
229CreateDeviceNode (\r
2f88bd3a
MK
230 IN UINT8 NodeType,\r
231 IN UINT8 NodeSubType,\r
232 IN UINT16 NodeLength\r
e386b444 233 )\r
234{\r
4d0a30a4 235 return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);\r
e386b444 236}\r
237\r
238/**\r
239 Determines if a device path is single or multi-instance.\r
240\r
58380e9c 241 This function returns TRUE if the device path specified by DevicePath is\r
242 multi-instance.\r
771729c7
RN
243 Otherwise, FALSE is returned.\r
244 If DevicePath is NULL or invalid, then FALSE is returned.\r
e386b444 245\r
246 @param DevicePath A pointer to a device path data structure.\r
247\r
248 @retval TRUE DevicePath is multi-instance.\r
9095d37b 249 @retval FALSE DevicePath is not multi-instance, or DevicePath\r
771729c7 250 is NULL or invalid.\r
e386b444 251\r
252**/\r
253BOOLEAN\r
254EFIAPI\r
255IsDevicePathMultiInstance (\r
256 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
257 )\r
258{\r
4d0a30a4
RN
259 return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);\r
260}\r
e386b444 261\r
4d0a30a4
RN
262/**\r
263 Converts a device node to its string representation.\r
771729c7 264\r
4d0a30a4
RN
265 @param DeviceNode A Pointer to the device node to be converted.\r
266 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r
267 of the display node is used, where applicable. If DisplayOnly\r
268 is FALSE, then the longer text representation of the display node\r
269 is used.\r
270 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r
271 representation for a device node can be used, where applicable.\r
e386b444 272\r
4d0a30a4
RN
273 @return A pointer to the allocated text representation of the device node or NULL if DeviceNode\r
274 is NULL or there was insufficient memory.\r
e386b444 275\r
4d0a30a4
RN
276**/\r
277CHAR16 *\r
278EFIAPI\r
279ConvertDeviceNodeToText (\r
280 IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,\r
281 IN BOOLEAN DisplayOnly,\r
282 IN BOOLEAN AllowShortcuts\r
283 )\r
284{\r
285 return UefiDevicePathLibConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);\r
e386b444 286}\r
287\r
4d0a30a4
RN
288/**\r
289 Converts a device path to its text representation.\r
290\r
291 @param DevicePath A Pointer to the device to be converted.\r
292 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r
293 of the display node is used, where applicable. If DisplayOnly\r
294 is FALSE, then the longer text representation of the display node\r
295 is used.\r
296 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r
297 representation for a device node can be used, where applicable.\r
298\r
299 @return A pointer to the allocated text representation of the device path or\r
300 NULL if DeviceNode is NULL or there was insufficient memory.\r
301\r
302**/\r
303CHAR16 *\r
304EFIAPI\r
305ConvertDevicePathToText (\r
2f88bd3a
MK
306 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
307 IN BOOLEAN DisplayOnly,\r
308 IN BOOLEAN AllowShortcuts\r
4d0a30a4
RN
309 )\r
310{\r
311 return UefiDevicePathLibConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);\r
312}\r
e386b444 313\r
314/**\r
4d0a30a4 315 Convert text to the binary representation of a device node.\r
e386b444 316\r
4d0a30a4
RN
317 @param TextDeviceNode TextDeviceNode points to the text representation of a device\r
318 node. Conversion starts with the first character and continues\r
319 until the first non-device node character.\r
e386b444 320\r
4d0a30a4
RN
321 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r
322 insufficient memory or text unsupported.\r
e386b444 323\r
324**/\r
325EFI_DEVICE_PATH_PROTOCOL *\r
326EFIAPI\r
4d0a30a4 327ConvertTextToDeviceNode (\r
2f88bd3a 328 IN CONST CHAR16 *TextDeviceNode\r
e386b444 329 )\r
330{\r
4d0a30a4 331 return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);\r
e386b444 332}\r
333\r
334/**\r
4d0a30a4 335 Convert text to the binary representation of a device path.\r
e386b444 336\r
e386b444 337\r
4d0a30a4
RN
338 @param TextDevicePath TextDevicePath points to the text representation of a device\r
339 path. Conversion starts with the first character and continues\r
340 until the first non-device node character.\r
341\r
342 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r
343 there was insufficient memory.\r
e386b444 344\r
345**/\r
346EFI_DEVICE_PATH_PROTOCOL *\r
347EFIAPI\r
4d0a30a4 348ConvertTextToDevicePath (\r
2f88bd3a 349 IN CONST CHAR16 *TextDevicePath\r
e386b444 350 )\r
351{\r
4d0a30a4 352 return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);\r
e386b444 353}\r