]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Include/Library/DevicePathLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Include / Library / DevicePathLib.h
... / ...
CommitLineData
1/** @file\r
2 Provides library functions to construct and parse UEFI Device Paths.\r
3\r
4 This library provides defines, macros, and functions to help create and parse\r
5 EFI_DEVICE_PATH_PROTOCOL structures.\r
6\r
7Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
8SPDX-License-Identifier: BSD-2-Clause-Patent\r
9\r
10**/\r
11\r
12#ifndef __DEVICE_PATH_LIB_H__\r
13#define __DEVICE_PATH_LIB_H__\r
14\r
15#define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r
16\r
17/**\r
18 Determine whether a given device path is valid.\r
19\r
20 @param DevicePath A pointer to a device path data structure.\r
21 @param MaxSize The maximum size of the device path data structure.\r
22\r
23 @retval TRUE DevicePath is valid.\r
24 @retval FALSE DevicePath is NULL.\r
25 @retval FALSE Maxsize is less than sizeof(EFI_DEVICE_PATH_PROTOCOL).\r
26 @retval FALSE The length of any node node in the DevicePath is less\r
27 than sizeof (EFI_DEVICE_PATH_PROTOCOL).\r
28 @retval FALSE If MaxSize is not zero, the size of the DevicePath\r
29 exceeds MaxSize.\r
30 @retval FALSE If PcdMaximumDevicePathNodeCount is not zero, the node\r
31 count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.\r
32**/\r
33BOOLEAN\r
34EFIAPI\r
35IsDevicePathValid (\r
36 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
37 IN UINTN MaxSize\r
38 );\r
39\r
40/**\r
41 Returns the Type field of a device path node.\r
42\r
43 Returns the Type field of the device path node specified by Node.\r
44\r
45 If Node is NULL, then ASSERT().\r
46\r
47 @param Node A pointer to a device path node data structure.\r
48\r
49 @return The Type field of the device path node specified by Node.\r
50\r
51**/\r
52UINT8\r
53EFIAPI\r
54DevicePathType (\r
55 IN CONST VOID *Node\r
56 );\r
57\r
58/**\r
59 Returns the SubType field of a device path node.\r
60\r
61 Returns the SubType field of the device path node specified by Node.\r
62\r
63 If Node is NULL, then ASSERT().\r
64\r
65 @param Node A pointer to a device path node data structure.\r
66\r
67 @return The SubType field of the device path node specified by Node.\r
68\r
69**/\r
70UINT8\r
71EFIAPI\r
72DevicePathSubType (\r
73 IN CONST VOID *Node\r
74 );\r
75\r
76/**\r
77 Returns the 16-bit Length field of a device path node.\r
78\r
79 Returns the 16-bit Length field of the device path node specified by Node.\r
80 Node is not required to be aligned on a 16-bit boundary, so it is recommended\r
81 that a function such as ReadUnaligned16() be used to extract the contents of\r
82 the Length field.\r
83\r
84 If Node is NULL, then ASSERT().\r
85\r
86 @param Node A pointer to a device path node data structure.\r
87\r
88 @return The 16-bit Length field of the device path node specified by Node.\r
89\r
90**/\r
91UINTN\r
92EFIAPI\r
93DevicePathNodeLength (\r
94 IN CONST VOID *Node\r
95 );\r
96\r
97/**\r
98 Returns a pointer to the next node in a device path.\r
99\r
100 Returns a pointer to the device path node that follows the device path node specified by Node.\r
101\r
102 If Node is NULL, then ASSERT().\r
103\r
104 @param Node A pointer to a device path node data structure.\r
105\r
106 @return a pointer to the device path node that follows the device path node specified by Node.\r
107\r
108**/\r
109EFI_DEVICE_PATH_PROTOCOL *\r
110EFIAPI\r
111NextDevicePathNode (\r
112 IN CONST VOID *Node\r
113 );\r
114\r
115/**\r
116 Determines if a device path node is an end node of a device path.\r
117 This includes nodes that are the end of a device path instance and nodes that\r
118 are the end of an entire device path.\r
119\r
120 Determines if the device path node specified by Node is an end node of a device path.\r
121 This includes nodes that are the end of a device path instance and nodes that are the\r
122 end of an entire device path. If Node represents an end node of a device path,\r
123 then TRUE is returned. Otherwise, FALSE is returned.\r
124\r
125 If Node is NULL, then ASSERT().\r
126\r
127 @param Node A pointer to a device path node data structure.\r
128\r
129 @retval TRUE The device path node specified by Node is an end node of a device path.\r
130 @retval FALSE The device path node specified by Node is not an end node of a device path.\r
131\r
132**/\r
133BOOLEAN\r
134EFIAPI\r
135IsDevicePathEndType (\r
136 IN CONST VOID *Node\r
137 );\r
138\r
139/**\r
140 Determines if a device path node is an end node of an entire device path.\r
141\r
142 Determines if a device path node specified by Node is an end node of an entire device path.\r
143 If Node represents the end of an entire device path, then TRUE is returned.\r
144 Otherwise, FALSE is returned.\r
145\r
146 If Node is NULL, then ASSERT().\r
147\r
148 @param Node A pointer to a device path node data structure.\r
149\r
150 @retval TRUE The device path node specified by Node is the end of an entire device path.\r
151 @retval FALSE The device path node specified by Node is not the end of an entire device path.\r
152\r
153**/\r
154BOOLEAN\r
155EFIAPI\r
156IsDevicePathEnd (\r
157 IN CONST VOID *Node\r
158 );\r
159\r
160/**\r
161 Determines if a device path node is an end node of a device path instance.\r
162\r
163 Determines if a device path node specified by Node is an end node of a device path instance.\r
164 If Node represents the end of a device path instance, then TRUE is returned.\r
165 Otherwise, FALSE is returned.\r
166\r
167 If Node is NULL, then ASSERT().\r
168\r
169 @param Node A pointer to a device path node data structure.\r
170\r
171 @retval TRUE The device path node specified by Node is the end of a device path instance.\r
172 @retval FALSE The device path node specified by Node is not the end of a device path instance.\r
173\r
174**/\r
175BOOLEAN\r
176EFIAPI\r
177IsDevicePathEndInstance (\r
178 IN CONST VOID *Node\r
179 );\r
180\r
181/**\r
182 Sets the length, in bytes, of a device path node.\r
183\r
184 Sets the length of the device path node specified by Node to the value specified\r
185 by NodeLength. NodeLength is returned. Node is not required to be aligned on\r
186 a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()\r
187 be used to set the contents of the Length field.\r
188\r
189 If Node is NULL, then ASSERT().\r
190 If NodeLength >= 0x10000, then ASSERT().\r
191 If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().\r
192\r
193 @param Node A pointer to a device path node data structure.\r
194 @param Length The length, in bytes, of the device path node.\r
195\r
196 @return Length\r
197\r
198**/\r
199UINT16\r
200EFIAPI\r
201SetDevicePathNodeLength (\r
202 IN OUT VOID *Node,\r
203 IN UINTN Length\r
204 );\r
205\r
206/**\r
207 Fills in all the fields of a device path node that is the end of an entire device path.\r
208\r
209 Fills in all the fields of a device path node specified by Node so Node represents\r
210 the end of an entire device path. The Type field of Node is set to\r
211 END_DEVICE_PATH_TYPE, the SubType field of Node is set to\r
212 END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to\r
213 END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary,\r
214 so it is recommended that a function such as WriteUnaligned16() be used to set\r
215 the contents of the Length field.\r
216\r
217 If Node is NULL, then ASSERT().\r
218\r
219 @param Node A pointer to a device path node data structure.\r
220\r
221**/\r
222VOID\r
223EFIAPI\r
224SetDevicePathEndNode (\r
225 OUT VOID *Node\r
226 );\r
227\r
228/**\r
229 Returns the size of a device path in bytes.\r
230\r
231 This function returns the size, in bytes, of the device path data structure\r
232 specified by DevicePath including the end of device path node.\r
233 If DevicePath is NULL or invalid, then 0 is returned.\r
234\r
235 @param DevicePath A pointer to a device path data structure.\r
236\r
237 @retval 0 If DevicePath is NULL or invalid.\r
238 @retval Others The size of a device path in bytes.\r
239\r
240**/\r
241UINTN\r
242EFIAPI\r
243GetDevicePathSize (\r
244 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
245 );\r
246\r
247/**\r
248 Creates a new copy of an existing device path.\r
249\r
250 This function allocates space for a new copy of the device path specified by DevicePath. If\r
251 DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the\r
252 contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r
253 is returned. Otherwise, NULL is returned.\r
254 The memory for the new device path is allocated from EFI boot services memory.\r
255 It is the responsibility of the caller to free the memory allocated.\r
256\r
257 @param DevicePath A pointer to a device path data structure.\r
258\r
259 @retval NULL DevicePath is NULL or invalid.\r
260 @retval Others A pointer to the duplicated device path.\r
261\r
262**/\r
263EFI_DEVICE_PATH_PROTOCOL *\r
264EFIAPI\r
265DuplicateDevicePath (\r
266 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
267 );\r
268\r
269/**\r
270 Creates a new device path by appending a second device path to a first device path.\r
271\r
272 This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r
273 FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from\r
274 SecondDevicePath is retained. The newly created device path is returned.\r
275 If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.\r
276 If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.\r
277 If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r
278 returned.\r
279 If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
280 The memory for the new device path is allocated from EFI boot services memory. It is the\r
281 responsibility of the caller to free the memory allocated.\r
282\r
283 @param FirstDevicePath A pointer to a device path data structure.\r
284 @param SecondDevicePath A pointer to a device path data structure.\r
285\r
286 @retval NULL If there is not enough memory for the newly allocated buffer.\r
287 @retval NULL If FirstDevicePath or SecondDevicePath is invalid.\r
288 @retval Others A pointer to the new device path if success.\r
289 Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r
290\r
291**/\r
292EFI_DEVICE_PATH_PROTOCOL *\r
293EFIAPI\r
294AppendDevicePath (\r
295 IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath OPTIONAL,\r
296 IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r
297 );\r
298\r
299/**\r
300 Creates a new path by appending the device node to the device path.\r
301\r
302 This function creates a new device path by appending a copy of the device node specified by\r
303 DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r
304 The end-of-device-path device node is moved after the end of the appended device node.\r
305 If DevicePathNode is NULL then a copy of DevicePath is returned.\r
306 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device\r
307 node is returned.\r
308 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node\r
309 is returned.\r
310 If there is not enough memory to allocate space for the new device path, then NULL is returned.\r
311 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
312 free the memory allocated.\r
313\r
314 @param DevicePath A pointer to a device path data structure.\r
315 @param DevicePathNode A pointer to a single device path node.\r
316\r
317 @retval NULL There is not enough memory for the new device path.\r
318 @retval Others A pointer to the new device path if success.\r
319 A copy of DevicePathNode followed by an end-of-device-path node\r
320 if both FirstDevicePath and SecondDevicePath are NULL.\r
321 A copy of an end-of-device-path node if both FirstDevicePath and SecondDevicePath are NULL.\r
322\r
323**/\r
324EFI_DEVICE_PATH_PROTOCOL *\r
325EFIAPI\r
326AppendDevicePathNode (\r
327 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r
328 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r
329 );\r
330\r
331/**\r
332 Creates a new device path by appending the specified device path instance to the specified device\r
333 path.\r
334\r
335 This function creates a new device path by appending a copy of the device path instance specified\r
336 by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r
337 The end-of-device-path device node is moved after the end of the appended device path instance\r
338 and a new end-of-device-path-instance node is inserted between.\r
339 If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
340 If DevicePathInstance is NULL, then NULL is returned.\r
341 If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r
342 If there is not enough memory to allocate space for the new device path, then NULL is returned.\r
343 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
344 free the memory allocated.\r
345\r
346 @param DevicePath A pointer to a device path data structure.\r
347 @param DevicePathInstance A pointer to a device path instance.\r
348\r
349 @return A pointer to the new device path.\r
350\r
351**/\r
352EFI_DEVICE_PATH_PROTOCOL *\r
353EFIAPI\r
354AppendDevicePathInstance (\r
355 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r
356 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r
357 );\r
358\r
359/**\r
360 Creates a copy of the current device path instance and returns a pointer to the next device path\r
361 instance.\r
362\r
363 This function creates a copy of the current device path instance. It also updates DevicePath to\r
364 point to the next device path instance in the device path (or NULL if no more) and updates Size\r
365 to hold the size of the device path instance copy.\r
366 If DevicePath is NULL, then NULL is returned.\r
367 If DevicePath points to a invalid device path, then NULL is returned.\r
368 If there is not enough memory to allocate space for the new device path, then NULL is returned.\r
369 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
370 free the memory allocated.\r
371 If Size is NULL, then ASSERT().\r
372\r
373 @param DevicePath On input, this holds the pointer to the current device path\r
374 instance. On output, this holds the pointer to the next device\r
375 path instance or NULL if there are no more device path\r
376 instances in the device path pointer to a device path data\r
377 structure.\r
378 @param Size On output, this holds the size of the device path instance, in\r
379 bytes or zero, if DevicePath is NULL.\r
380\r
381 @return A pointer to the current device path instance.\r
382\r
383**/\r
384EFI_DEVICE_PATH_PROTOCOL *\r
385EFIAPI\r
386GetNextDevicePathInstance (\r
387 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r
388 OUT UINTN *Size\r
389 );\r
390\r
391/**\r
392 Creates a device node.\r
393\r
394 This function creates a new device node in a newly allocated buffer of size NodeLength and\r
395 initializes the device path node header with NodeType and NodeSubType. The new device path node\r
396 is returned.\r
397 If NodeLength is smaller than a device path header, then NULL is returned.\r
398 If there is not enough memory to allocate space for the new device path, then NULL is returned.\r
399 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
400 free the memory allocated.\r
401\r
402 @param NodeType The device node type for the new device node.\r
403 @param NodeSubType The device node sub-type for the new device node.\r
404 @param NodeLength The length of the new device node.\r
405\r
406 @return The new device path.\r
407\r
408**/\r
409EFI_DEVICE_PATH_PROTOCOL *\r
410EFIAPI\r
411CreateDeviceNode (\r
412 IN UINT8 NodeType,\r
413 IN UINT8 NodeSubType,\r
414 IN UINT16 NodeLength\r
415 );\r
416\r
417/**\r
418 Determines if a device path is single or multi-instance.\r
419\r
420 This function returns TRUE if the device path specified by DevicePath is multi-instance.\r
421 Otherwise, FALSE is returned.\r
422 If DevicePath is NULL or invalid, then FALSE is returned.\r
423\r
424 @param DevicePath A pointer to a device path data structure.\r
425\r
426 @retval TRUE DevicePath is multi-instance.\r
427 @retval FALSE DevicePath is not multi-instance, or DevicePath is NULL or invalid.\r
428\r
429**/\r
430BOOLEAN\r
431EFIAPI\r
432IsDevicePathMultiInstance (\r
433 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
434 );\r
435\r
436/**\r
437 Retrieves the device path protocol from a handle.\r
438\r
439 This function returns the device path protocol from the handle specified by Handle. If Handle is\r
440 NULL or Handle does not contain a device path protocol, then NULL is returned.\r
441\r
442 @param Handle The handle from which to retrieve the device path protocol.\r
443\r
444 @return The device path protocol from the handle specified by Handle.\r
445\r
446**/\r
447EFI_DEVICE_PATH_PROTOCOL *\r
448EFIAPI\r
449DevicePathFromHandle (\r
450 IN EFI_HANDLE Handle\r
451 );\r
452\r
453/**\r
454 Allocates a device path for a file and appends it to an existing device path.\r
455\r
456 If Device is a valid device handle that contains a device path protocol, then a device path for\r
457 the file specified by FileName is allocated and appended to the device path associated with the\r
458 handle Device. The allocated device path is returned. If Device is NULL or Device is a handle\r
459 that does not support the device path protocol, then a device path containing a single device\r
460 path node for the file specified by FileName is allocated and returned.\r
461 The memory for the new device path is allocated from EFI boot services memory. It is the responsibility\r
462 of the caller to free the memory allocated.\r
463\r
464 If FileName is NULL, then ASSERT().\r
465 If FileName is not aligned on a 16-bit boundary, then ASSERT().\r
466\r
467 @param Device A pointer to a device handle. This parameter is optional and\r
468 may be NULL.\r
469 @param FileName A pointer to a Null-terminated Unicode string.\r
470\r
471 @return The allocated device path.\r
472\r
473**/\r
474EFI_DEVICE_PATH_PROTOCOL *\r
475EFIAPI\r
476FileDevicePath (\r
477 IN EFI_HANDLE Device OPTIONAL,\r
478 IN CONST CHAR16 *FileName\r
479 );\r
480\r
481/**\r
482 Converts a device path to its text representation.\r
483\r
484 @param DevicePath A Pointer to the device to be converted.\r
485 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r
486 of the display node is used, where applicable. If DisplayOnly\r
487 is FALSE, then the longer text representation of the display node\r
488 is used.\r
489 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r
490 representation for a device node can be used, where applicable.\r
491\r
492 @return A pointer to the allocated text representation of the device path or\r
493 NULL if DeviceNode is NULL or there was insufficient memory.\r
494\r
495**/\r
496CHAR16 *\r
497EFIAPI\r
498ConvertDevicePathToText (\r
499 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
500 IN BOOLEAN DisplayOnly,\r
501 IN BOOLEAN AllowShortcuts\r
502 );\r
503\r
504/**\r
505 Converts a device node to its string representation.\r
506\r
507 @param DeviceNode A Pointer to the device node to be converted.\r
508 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r
509 of the display node is used, where applicable. If DisplayOnly\r
510 is FALSE, then the longer text representation of the display node\r
511 is used.\r
512 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r
513 representation for a device node can be used, where applicable.\r
514\r
515 @return A pointer to the allocated text representation of the device node or NULL if DeviceNode\r
516 is NULL or there was insufficient memory.\r
517\r
518**/\r
519CHAR16 *\r
520EFIAPI\r
521ConvertDeviceNodeToText (\r
522 IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,\r
523 IN BOOLEAN DisplayOnly,\r
524 IN BOOLEAN AllowShortcuts\r
525 );\r
526\r
527/**\r
528 Convert text to the binary representation of a device node.\r
529\r
530 @param TextDeviceNode TextDeviceNode points to the text representation of a device\r
531 node. Conversion starts with the first character and continues\r
532 until the first non-device node character.\r
533\r
534 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r
535 insufficient memory or text unsupported.\r
536\r
537**/\r
538EFI_DEVICE_PATH_PROTOCOL *\r
539EFIAPI\r
540ConvertTextToDeviceNode (\r
541 IN CONST CHAR16 *TextDeviceNode\r
542 );\r
543\r
544/**\r
545 Convert text to the binary representation of a device path.\r
546\r
547 @param TextDevicePath TextDevicePath points to the text representation of a device\r
548 path. Conversion starts with the first character and continues\r
549 until the first non-device node character.\r
550\r
551 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r
552 there was insufficient memory.\r
553\r
554**/\r
555EFI_DEVICE_PATH_PROTOCOL *\r
556EFIAPI\r
557ConvertTextToDevicePath (\r
558 IN CONST CHAR16 *TextDevicePath\r
559 );\r
560\r
561#endif\r