]>
Commit | Line | Data |
---|---|---|
fb3df220 | 1 | /** @file\r |
50a64e5b | 2 | Provides library functions to construct and parse UEFI Device Paths.\r |
fb3df220 | 3 | \r |
d80b2f71 | 4 | This library provides defines, macros, and functions to help create and parse \r |
5 | EFI_DEVICE_PATH_PROTOCOL structures. The macros that help create and parse device \r | |
6 | path nodes make use of the ReadUnaligned16() and WriteUnaligned16() functions from \r | |
7 | the Base Library, so this library class has an implied dependency on the Base Library.\r | |
8 | \r | |
3e5c3238 | 9 | Copyright (c) 2006 - 2008, Intel Corporation<BR>\r |
50a64e5b | 10 | All rights reserved. This program and the accompanying materials\r |
11 | are licensed and made available under the terms and conditions of the BSD License\r | |
12 | which accompanies this distribution. The full text of the license may be found at\r | |
13 | http://opensource.org/licenses/bsd-license.php\r | |
fb3df220 | 14 | \r |
50a64e5b | 15 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
16 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
fb3df220 | 17 | \r |
fb3df220 | 18 | **/\r |
19 | \r | |
20 | #ifndef __DEVICE_PATH_LIB_H__\r | |
21 | #define __DEVICE_PATH_LIB_H__\r | |
22 | \r | |
e5dab016 | 23 | #define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r |
d80b2f71 | 24 | \r |
25 | /**\r | |
3dc728fb | 26 | Returns the Type field of a device path node.\r |
d80b2f71 | 27 | \r |
28 | Returns the Type field of the device path node specified by Node.\r | |
29 | \r | |
3dc728fb | 30 | If Node is NULL, then ASSERT().\r |
31 | \r | |
d80b2f71 | 32 | @param Node A pointer to a device path node data structure.\r |
33 | \r | |
34 | @return The Type field of the device path node specified by Node.\r | |
35 | \r | |
36 | **/\r | |
3dc728fb | 37 | UINT8\r |
38 | DevicePathType (\r | |
39 | IN CONST VOID *Node\r | |
40 | );\r | |
d80b2f71 | 41 | \r |
42 | /**\r | |
3dc728fb | 43 | Returns the SubType field of a device path node.\r |
d80b2f71 | 44 | \r |
45 | Returns the SubType field of the device path node specified by Node.\r | |
46 | \r | |
3dc728fb | 47 | If Node is NULL, then ASSERT().\r |
48 | \r | |
d80b2f71 | 49 | @param Node A pointer to a device path node data structure.\r |
50 | \r | |
51 | @return The SubType field of the device path node specified by Node.\r | |
52 | \r | |
53 | **/\r | |
3dc728fb | 54 | UINT8\r |
55 | DevicePathSubType (\r | |
56 | IN CONST VOID *Node\r | |
57 | );\r | |
d80b2f71 | 58 | \r |
59 | /**\r | |
3dc728fb | 60 | Returns the 16-bit Length field of a device path node.\r |
d80b2f71 | 61 | \r |
3dc728fb | 62 | Returns the 16-bit Length field of the device path node specified by Node. \r |
63 | Node is not required to be aligned on a 16-bit boundary, so it is recommended\r | |
64 | that a function such as ReadUnaligned16() be used to extract the contents of \r | |
65 | the Length field.\r | |
66 | \r | |
67 | If Node is NULL, then ASSERT().\r | |
d80b2f71 | 68 | \r |
69 | @param Node A pointer to a device path node data structure.\r | |
70 | \r | |
71 | @return The 16-bit Length field of the device path node specified by Node.\r | |
72 | \r | |
73 | **/\r | |
3dc728fb | 74 | UINTN\r |
75 | DevicePathNodeLength (\r | |
76 | IN CONST VOID *Node\r | |
77 | );\r | |
d80b2f71 | 78 | \r |
79 | /**\r | |
3dc728fb | 80 | Returns a pointer to the next node in a device path.\r |
d80b2f71 | 81 | \r |
82 | Returns a pointer to the device path node that follows the device path node specified by Node.\r | |
83 | \r | |
3dc728fb | 84 | If Node is NULL, then ASSERT().\r |
85 | \r | |
d80b2f71 | 86 | @param Node A pointer to a device path node data structure.\r |
87 | \r | |
88 | @return a pointer to the device path node that follows the device path node specified by Node.\r | |
89 | \r | |
90 | **/\r | |
3dc728fb | 91 | EFI_DEVICE_PATH_PROTOCOL *\r |
92 | NextDevicePathNode (\r | |
93 | IN CONST VOID *Node\r | |
94 | );\r | |
d80b2f71 | 95 | \r |
96 | /**\r | |
3dc728fb | 97 | Determines if a device path node is an end node of a device path.\r |
d80b2f71 | 98 | This includes nodes that are the end of a device path instance and nodes that are the end of an entire device path.\r |
99 | \r | |
100 | Determines if the device path node specified by Node is an end node of a device path. \r | |
101 | This includes nodes that are the end of a device path instance and nodes that are the \r | |
102 | end of an entire device path. If Node represents an end node of a device path, \r | |
103 | then TRUE is returned. Otherwise, FALSE is returned.\r | |
104 | \r | |
3dc728fb | 105 | If Node is NULL, then ASSERT().\r |
106 | \r | |
d80b2f71 | 107 | @param Node A pointer to a device path node data structure.\r |
108 | \r | |
109 | @retval TRUE The device path node specified by Node is an end node of a device path.\r | |
110 | @retval FALSE The device path node specified by Node is not an end node of a device path.\r | |
111 | \r | |
112 | **/\r | |
3dc728fb | 113 | BOOLEAN\r |
114 | IsDevicePathEndType (\r | |
115 | IN CONST VOID *Node\r | |
116 | );\r | |
d80b2f71 | 117 | \r |
118 | /**\r | |
3dc728fb | 119 | Determines if a device path node is an end node of an entire device path.\r |
d80b2f71 | 120 | \r |
121 | Determines if a device path node specified by Node is an end node of an entire device path.\r | |
122 | If Node represents the end of an entire device path, then TRUE is returned. Otherwise, FALSE is returned.\r | |
123 | \r | |
3dc728fb | 124 | If Node is NULL, then ASSERT().\r |
125 | \r | |
d80b2f71 | 126 | @param Node A pointer to a device path node data structure.\r |
127 | \r | |
128 | @retval TRUE The device path node specified by Node is the end of an entire device path.\r | |
129 | @retval FALSE The device path node specified by Node is not the end of an entire device path.\r | |
130 | \r | |
131 | **/\r | |
3dc728fb | 132 | BOOLEAN\r |
133 | IsDevicePathEnd (\r | |
134 | IN CONST VOID *Node\r | |
135 | );\r | |
d80b2f71 | 136 | \r |
137 | /**\r | |
3dc728fb | 138 | Determines if a device path node is an end node of a device path instance.\r |
d80b2f71 | 139 | \r |
140 | Determines if a device path node specified by Node is an end node of a device path instance.\r | |
141 | If Node represents the end of a device path instance, then TRUE is returned. Otherwise, FALSE is returned.\r | |
142 | \r | |
3dc728fb | 143 | If Node is NULL, then ASSERT().\r |
144 | \r | |
d80b2f71 | 145 | @param Node A pointer to a device path node data structure.\r |
146 | \r | |
147 | @retval TRUE The device path node specified by Node is the end of a device path instance.\r | |
148 | @retval FALSE The device path node specified by Node is not the end of a device path instance.\r | |
149 | \r | |
150 | **/\r | |
3dc728fb | 151 | BOOLEAN\r |
152 | IsDevicePathEndInstance (\r | |
153 | IN CONST VOID *Node\r | |
154 | );\r | |
e5dab016 | 155 | \r |
d80b2f71 | 156 | /**\r |
3dc728fb | 157 | Sets the length, in bytes, of a device path node.\r |
158 | \r | |
159 | Sets the length of the device path node specified by Node to the value specified \r | |
160 | by NodeLength. NodeLength is returned. Node is not required to be aligned on \r | |
161 | a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()\r | |
162 | be used to set the contents of the Length field.\r | |
d80b2f71 | 163 | \r |
3dc728fb | 164 | If Node is NULL, then ASSERT().\r |
165 | If NodeLength >= 0x10000, then ASSERT().\r | |
d80b2f71 | 166 | \r |
167 | @param Node A pointer to a device path node data structure.\r | |
168 | @param Length The length, in bytes, of the device path node.\r | |
169 | \r | |
170 | @return Length\r | |
171 | \r | |
172 | **/\r | |
3dc728fb | 173 | UINT16\r |
174 | SetDevicePathNodeLength (\r | |
9bb407c6 | 175 | IN OUT VOID *Node,\r |
176 | IN UINTN Length\r | |
3dc728fb | 177 | );\r |
d80b2f71 | 178 | \r |
179 | /**\r | |
3dc728fb | 180 | Fills in all the fields of a device path node that is the end of an entire device path.\r |
d80b2f71 | 181 | \r |
3dc728fb | 182 | Fills in all the fields of a device path node specified by Node so Node represents \r |
183 | the end of an entire device path. The Type field of Node is set to \r | |
184 | END_DEVICE_PATH_TYPE, the SubType field of Node is set to \r | |
185 | END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to \r | |
186 | END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary, \r | |
187 | so it is recommended that a function such as WriteUnaligned16() be used to set \r | |
188 | the contents of the Length field. \r | |
189 | \r | |
190 | If Node is NULL, then ASSERT(). \r | |
d80b2f71 | 191 | \r |
192 | @param Node A pointer to a device path node data structure.\r | |
193 | \r | |
194 | **/\r | |
3dc728fb | 195 | VOID\r |
196 | SetDevicePathEndNode (\r | |
9bb407c6 | 197 | OUT VOID *Node\r |
3dc728fb | 198 | );\r |
e5dab016 | 199 | \r |
fb3df220 | 200 | /**\r |
201 | Returns the size of a device path in bytes.\r | |
202 | \r | |
203 | This function returns the size, in bytes, of the device path data structure specified by\r | |
204 | DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned.\r | |
205 | \r | |
206 | @param DevicePath A pointer to a device path data structure.\r | |
d80b2f71 | 207 | \r |
208 | @retval 0 If DevicePath is NULL.\r | |
209 | @retval Others The size of a device path in bytes.\r | |
fb3df220 | 210 | \r |
211 | **/\r | |
212 | UINTN\r | |
213 | EFIAPI\r | |
214 | GetDevicePathSize (\r | |
215 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
216 | );\r | |
217 | \r | |
218 | /**\r | |
bc7e6003 | 219 | Creates a new copy of an existing device path.\r |
fb3df220 | 220 | \r |
221 | This function allocates space for a new copy of the device path specified by DevicePath. If\r | |
222 | DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the\r | |
223 | contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r | |
224 | is returned. Otherwise, NULL is returned. \r | |
d80b2f71 | 225 | The memory for the new device path is allocated from EFI boot services memory. \r |
226 | It is the responsibility of the caller to free the memory allocated. \r | |
fb3df220 | 227 | \r |
228 | @param DevicePath A pointer to a device path data structure.\r | |
229 | \r | |
d80b2f71 | 230 | @retval NULL If DevicePath is NULL.\r |
231 | @retval Others A pointer to the duplicated device path.\r | |
232 | \r | |
fb3df220 | 233 | **/\r |
234 | EFI_DEVICE_PATH_PROTOCOL *\r | |
235 | EFIAPI\r | |
236 | DuplicateDevicePath (\r | |
237 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
238 | );\r | |
239 | \r | |
240 | /**\r | |
241 | Creates a new device path by appending a second device path to a first device path.\r | |
242 | \r | |
243 | This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r | |
244 | FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from\r | |
245 | SecondDevicePath is retained. The newly created device path is returned. \r | |
246 | If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned. \r | |
247 | If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned. \r | |
98a14db6 | 248 | If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r |
249 | returned. \r | |
fb3df220 | 250 | If there is not enough memory for the newly allocated buffer, then NULL is returned.\r |
251 | The memory for the new device path is allocated from EFI boot services memory. It is the\r | |
252 | responsibility of the caller to free the memory allocated.\r | |
253 | \r | |
254 | @param FirstDevicePath A pointer to a device path data structure.\r | |
255 | @param SecondDevicePath A pointer to a device path data structure.\r | |
d80b2f71 | 256 | \r |
257 | @retval NULL If there is not enough memory for the newly allocated buffer.\r | |
258 | @retval Others A pointer to the new device path if success.\r | |
259 | Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r | |
fb3df220 | 260 | \r |
261 | **/\r | |
262 | EFI_DEVICE_PATH_PROTOCOL *\r | |
263 | EFIAPI\r | |
264 | AppendDevicePath (\r | |
265 | IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r | |
266 | IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r | |
267 | );\r | |
268 | \r | |
269 | /**\r | |
270 | Creates a new path by appending the device node to the device path.\r | |
271 | \r | |
272 | This function creates a new device path by appending a copy of the device node specified by\r | |
273 | DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r | |
274 | The end-of-device-path device node is moved after the end of the appended device node.\r | |
98a14db6 | 275 | If DevicePathNode is NULL then a copy of DevicePath is returned.\r |
6336a895 | 276 | If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device\r |
277 | node is returned.\r | |
98a14db6 | 278 | If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node\r |
279 | is returned.\r | |
fb3df220 | 280 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r |
281 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
282 | free the memory allocated.\r | |
283 | \r | |
284 | @param DevicePath A pointer to a device path data structure.\r | |
285 | @param DevicePathNode A pointer to a single device path node.\r | |
286 | \r | |
d80b2f71 | 287 | @retval NULL If there is not enough memory for the new device path.\r |
288 | @retval Others A pointer to the new device path if success.\r | |
289 | A copy of DevicePathNode followed by an end-of-device-path node \r | |
290 | if both FirstDevicePath and SecondDevicePath are NULL.\r | |
291 | A copy of an end-of-device-path node if both FirstDevicePath and SecondDevicePath are NULL.\r | |
fb3df220 | 292 | \r |
293 | **/\r | |
294 | EFI_DEVICE_PATH_PROTOCOL *\r | |
295 | EFIAPI\r | |
296 | AppendDevicePathNode (\r | |
297 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
298 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r | |
299 | );\r | |
300 | \r | |
301 | /**\r | |
302 | Creates a new device path by appending the specified device path instance to the specified device\r | |
303 | path.\r | |
304 | \r | |
305 | This function creates a new device path by appending a copy of the device path instance specified\r | |
306 | by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r | |
307 | The end-of-device-path device node is moved after the end of the appended device path instance\r | |
308 | and a new end-of-device-path-instance node is inserted between. \r | |
309 | If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r | |
310 | If DevicePathInstance is NULL, then NULL is returned.\r | |
311 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
312 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
313 | free the memory allocated.\r | |
314 | \r | |
315 | @param DevicePath A pointer to a device path data structure.\r | |
316 | @param DevicePathInstance A pointer to a device path instance.\r | |
317 | \r | |
318 | @return A pointer to the new device path.\r | |
319 | \r | |
320 | **/\r | |
321 | EFI_DEVICE_PATH_PROTOCOL *\r | |
322 | EFIAPI\r | |
323 | AppendDevicePathInstance (\r | |
324 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
325 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r | |
326 | );\r | |
327 | \r | |
328 | /**\r | |
329 | Creates a copy of the current device path instance and returns a pointer to the next device path\r | |
330 | instance.\r | |
331 | \r | |
332 | This function creates a copy of the current device path instance. It also updates DevicePath to\r | |
333 | point to the next device path instance in the device path (or NULL if no more) and updates Size\r | |
334 | to hold the size of the device path instance copy.\r | |
335 | If DevicePath is NULL, then NULL is returned.\r | |
336 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
337 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
338 | free the memory allocated.\r | |
339 | If Size is NULL, then ASSERT().\r | |
340 | \r | |
341 | @param DevicePath On input, this holds the pointer to the current device path\r | |
342 | instance. On output, this holds the pointer to the next device\r | |
343 | path instance or NULL if there are no more device path\r | |
344 | instances in the device path pointer to a device path data\r | |
345 | structure.\r | |
346 | @param Size On output, this holds the size of the device path instance, in\r | |
347 | bytes or zero, if DevicePath is NULL.\r | |
348 | \r | |
349 | @return A pointer to the current device path instance.\r | |
350 | \r | |
351 | **/\r | |
352 | EFI_DEVICE_PATH_PROTOCOL *\r | |
353 | EFIAPI\r | |
354 | GetNextDevicePathInstance (\r | |
355 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r | |
356 | OUT UINTN *Size\r | |
357 | );\r | |
358 | \r | |
359 | /**\r | |
d80b2f71 | 360 | Creates a device node.\r |
fb3df220 | 361 | \r |
362 | This function creates a new device node in a newly allocated buffer of size NodeLength and\r | |
363 | initializes the device path node header with NodeType and NodeSubType. The new device path node\r | |
364 | is returned.\r | |
365 | If NodeLength is smaller than a device path header, then NULL is returned. \r | |
366 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
367 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
368 | free the memory allocated.\r | |
369 | \r | |
370 | @param NodeType The device node type for the new device node.\r | |
371 | @param NodeSubType The device node sub-type for the new device node.\r | |
372 | @param NodeLength The length of the new device node.\r | |
373 | \r | |
374 | @return The new device path.\r | |
375 | \r | |
376 | **/\r | |
377 | EFI_DEVICE_PATH_PROTOCOL *\r | |
378 | EFIAPI\r | |
379 | CreateDeviceNode (\r | |
380 | IN UINT8 NodeType,\r | |
381 | IN UINT8 NodeSubType,\r | |
382 | IN UINT16 NodeLength\r | |
383 | );\r | |
384 | \r | |
385 | /**\r | |
386 | Determines if a device path is single or multi-instance.\r | |
387 | \r | |
388 | This function returns TRUE if the device path specified by DevicePath is multi-instance.\r | |
389 | Otherwise, FALSE is returned. If DevicePath is NULL, then FALSE is returned.\r | |
390 | \r | |
391 | @param DevicePath A pointer to a device path data structure.\r | |
392 | \r | |
393 | @retval TRUE DevicePath is multi-instance.\r | |
394 | @retval FALSE DevicePath is not multi-instance or DevicePath is NULL.\r | |
395 | \r | |
396 | **/\r | |
397 | BOOLEAN\r | |
398 | EFIAPI\r | |
399 | IsDevicePathMultiInstance (\r | |
400 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
401 | );\r | |
402 | \r | |
403 | /**\r | |
404 | Retrieves the device path protocol from a handle.\r | |
405 | \r | |
406 | This function returns the device path protocol from the handle specified by Handle. If Handle is\r | |
407 | NULL or Handle does not contain a device path protocol, then NULL is returned.\r | |
408 | \r | |
409 | @param Handle The handle from which to retrieve the device path protocol.\r | |
410 | \r | |
411 | @return The device path protocol from the handle specified by Handle.\r | |
412 | \r | |
413 | **/\r | |
414 | EFI_DEVICE_PATH_PROTOCOL *\r | |
415 | EFIAPI\r | |
416 | DevicePathFromHandle (\r | |
417 | IN EFI_HANDLE Handle\r | |
418 | );\r | |
419 | \r | |
420 | /**\r | |
421 | Allocates a device path for a file and appends it to an existing device path.\r | |
422 | \r | |
423 | If Device is a valid device handle that contains a device path protocol, then a device path for\r | |
424 | the file specified by FileName is allocated and appended to the device path associated with the\r | |
425 | handle Device. The allocated device path is returned. If Device is NULL or Device is a handle\r | |
426 | that does not support the device path protocol, then a device path containing a single device\r | |
427 | path node for the file specified by FileName is allocated and returned.\r | |
d80b2f71 | 428 | The memory for the new device path is allocated from EFI boot services memory. It is the responsibility\r |
429 | of the caller to free the memory allocated.\r | |
430 | \r | |
fb3df220 | 431 | If FileName is NULL, then ASSERT().\r |
d80b2f71 | 432 | If FileName is not aligned on a 16-bit boundary, then ASSERT().\r |
fb3df220 | 433 | \r |
434 | @param Device A pointer to a device handle. This parameter is optional and\r | |
435 | may be NULL.\r | |
436 | @param FileName A pointer to a Null-terminated Unicode string.\r | |
437 | \r | |
438 | @return The allocated device path.\r | |
439 | \r | |
440 | **/\r | |
441 | EFI_DEVICE_PATH_PROTOCOL *\r | |
442 | EFIAPI\r | |
443 | FileDevicePath (\r | |
444 | IN EFI_HANDLE Device, OPTIONAL\r | |
445 | IN CONST CHAR16 *FileName\r | |
446 | );\r | |
447 | \r | |
448 | #endif\r |