]>
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 | |
50a64e5b | 9 | Copyright (c) 2006 - 2008, Intel Corporation\r |
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 | #include <Library/BaseLib.h>\r |
24 | \r | |
25 | #define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r | |
d80b2f71 | 26 | \r |
27 | /**\r | |
28 | Macro that returns the Type field of a device path node.\r | |
29 | \r | |
30 | Returns the Type field of the device path node specified by Node.\r | |
31 | \r | |
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 | |
8dd2a792 | 37 | #define DevicePathType(Node) (((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type)\r |
d80b2f71 | 38 | \r |
39 | /**\r | |
40 | Macro that returns the SubType field of a device path node.\r | |
41 | \r | |
42 | Returns the SubType field of the device path node specified by Node.\r | |
43 | \r | |
44 | @param Node A pointer to a device path node data structure.\r | |
45 | \r | |
46 | @return The SubType field of the device path node specified by Node.\r | |
47 | \r | |
48 | **/\r | |
e5dab016 | 49 | #define DevicePathSubType(Node) (((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType)\r |
d80b2f71 | 50 | \r |
51 | /**\r | |
52 | Macro that returns the 16-bit Length field of a device path node.\r | |
53 | \r | |
54 | Returns the 16-bit Length field of the device path node specified by Node.\r | |
55 | \r | |
56 | @param Node A pointer to a device path node data structure.\r | |
57 | \r | |
58 | @return The 16-bit Length field of the device path node specified by Node.\r | |
59 | \r | |
60 | **/\r | |
61 | #define DevicePathNodeLength(Node) ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0])\r | |
62 | \r | |
63 | /**\r | |
64 | Macro that returns a pointer to the next node in a device path.\r | |
65 | \r | |
66 | Returns a pointer to the device path node that follows the device path node specified by Node.\r | |
67 | \r | |
68 | @param Node A pointer to a device path node data structure.\r | |
69 | \r | |
70 | @return a pointer to the device path node that follows the device path node specified by Node.\r | |
71 | \r | |
72 | **/\r | |
73 | #define NextDevicePathNode(Node) ((EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node)))\r | |
74 | \r | |
75 | /**\r | |
76 | Macro that determines if a device path node is an end node of a device path.\r | |
77 | This includes nodes that are the end of a device path instance and nodes that are the end of an entire device path.\r | |
78 | \r | |
79 | Determines if the device path node specified by Node is an end node of a device path. \r | |
80 | This includes nodes that are the end of a device path instance and nodes that are the \r | |
81 | end of an entire device path. If Node represents an end node of a device path, \r | |
82 | then TRUE is returned. Otherwise, FALSE is returned.\r | |
83 | \r | |
84 | @param Node A pointer to a device path node data structure.\r | |
85 | \r | |
86 | @retval TRUE The device path node specified by Node is an end node of a device path.\r | |
87 | @retval FALSE The device path node specified by Node is not an end node of a device path.\r | |
88 | \r | |
89 | **/\r | |
8dd2a792 | 90 | #define IsDevicePathEndType(Node) ((DevicePathType (Node) & 0x7f) == END_DEVICE_PATH_TYPE)\r |
d80b2f71 | 91 | \r |
92 | /**\r | |
93 | Macro that determines if a device path node is an end node of an entire device path.\r | |
94 | \r | |
95 | Determines if a device path node specified by Node is an end node of an entire device path.\r | |
96 | If Node represents the end of an entire device path, then TRUE is returned. Otherwise, FALSE is returned.\r | |
97 | \r | |
98 | @param Node A pointer to a device path node data structure.\r | |
99 | \r | |
100 | @retval TRUE The device path node specified by Node is the end of an entire device path.\r | |
101 | @retval FALSE The device path node specified by Node is not the end of an entire device path.\r | |
102 | \r | |
103 | **/\r | |
e5dab016 | 104 | #define IsDevicePathEnd(Node) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE)\r |
d80b2f71 | 105 | \r |
106 | /**\r | |
107 | Macro that determines if a device path node is an end node of a device path instance.\r | |
108 | \r | |
109 | Determines if a device path node specified by Node is an end node of a device path instance.\r | |
110 | If Node represents the end of a device path instance, then TRUE is returned. Otherwise, FALSE is returned.\r | |
111 | \r | |
112 | @param Node A pointer to a device path node data structure.\r | |
113 | \r | |
114 | @retval TRUE The device path node specified by Node is the end of a device path instance.\r | |
115 | @retval FALSE The device path node specified by Node is not the end of a device path instance.\r | |
116 | \r | |
117 | **/\r | |
e5dab016 | 118 | #define IsDevicePathEndInstance(Node) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE)\r |
119 | \r | |
d80b2f71 | 120 | /**\r |
121 | Macro that sets the length, in bytes, of a device path node.\r | |
122 | \r | |
123 | Sets the length of the device path node specified by Node to the value specified by Length. Length is returned.\r | |
124 | \r | |
125 | @param Node A pointer to a device path node data structure.\r | |
126 | @param Length The length, in bytes, of the device path node.\r | |
127 | \r | |
128 | @return Length\r | |
129 | \r | |
130 | **/\r | |
e5dab016 | 131 | #define SetDevicePathNodeLength(Node,NodeLength) WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(NodeLength))\r |
d80b2f71 | 132 | \r |
133 | /**\r | |
134 | Macro that fills in all the fields of a device path node that is the end of an entire device path.\r | |
135 | \r | |
136 | Fills in all the fields of a device path node specified by Node so Node represents the end of an entire device path.\r | |
137 | \r | |
138 | @param Node A pointer to a device path node data structure.\r | |
139 | \r | |
140 | **/\r | |
e5dab016 | 141 | #define SetDevicePathEndNode(Node) { \\r |
142 | DevicePathType (Node) = END_DEVICE_PATH_TYPE; \\r | |
143 | DevicePathSubType (Node) = END_ENTIRE_DEVICE_PATH_SUBTYPE; \\r | |
8dd2a792 | 144 | SetDevicePathNodeLength ((Node), END_DEVICE_PATH_LENGTH); \\r |
e5dab016 | 145 | }\r |
146 | \r | |
fb3df220 | 147 | /**\r |
148 | Returns the size of a device path in bytes.\r | |
149 | \r | |
150 | This function returns the size, in bytes, of the device path data structure specified by\r | |
151 | DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned.\r | |
152 | \r | |
153 | @param DevicePath A pointer to a device path data structure.\r | |
d80b2f71 | 154 | \r |
155 | @retval 0 If DevicePath is NULL.\r | |
156 | @retval Others The size of a device path in bytes.\r | |
fb3df220 | 157 | \r |
158 | **/\r | |
159 | UINTN\r | |
160 | EFIAPI\r | |
161 | GetDevicePathSize (\r | |
162 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
163 | );\r | |
164 | \r | |
165 | /**\r | |
166 | Creates a new device path by appending a second device path to a first device path.\r | |
167 | \r | |
168 | This function allocates space for a new copy of the device path specified by DevicePath. If\r | |
169 | DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the\r | |
170 | contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r | |
171 | is returned. Otherwise, NULL is returned. \r | |
d80b2f71 | 172 | The memory for the new device path is allocated from EFI boot services memory. \r |
173 | It is the responsibility of the caller to free the memory allocated. \r | |
fb3df220 | 174 | \r |
175 | @param DevicePath A pointer to a device path data structure.\r | |
176 | \r | |
d80b2f71 | 177 | @retval NULL If DevicePath is NULL.\r |
178 | @retval Others A pointer to the duplicated device path.\r | |
179 | \r | |
fb3df220 | 180 | **/\r |
181 | EFI_DEVICE_PATH_PROTOCOL *\r | |
182 | EFIAPI\r | |
183 | DuplicateDevicePath (\r | |
184 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
185 | );\r | |
186 | \r | |
187 | /**\r | |
188 | Creates a new device path by appending a second device path to a first device path.\r | |
189 | \r | |
190 | This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r | |
191 | FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from\r | |
192 | SecondDevicePath is retained. The newly created device path is returned. \r | |
193 | If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned. \r | |
194 | If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned. \r | |
98a14db6 | 195 | If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r |
196 | returned. \r | |
fb3df220 | 197 | If there is not enough memory for the newly allocated buffer, then NULL is returned.\r |
198 | The memory for the new device path is allocated from EFI boot services memory. It is the\r | |
199 | responsibility of the caller to free the memory allocated.\r | |
200 | \r | |
201 | @param FirstDevicePath A pointer to a device path data structure.\r | |
202 | @param SecondDevicePath A pointer to a device path data structure.\r | |
d80b2f71 | 203 | \r |
204 | @retval NULL If there is not enough memory for the newly allocated buffer.\r | |
205 | @retval Others A pointer to the new device path if success.\r | |
206 | Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r | |
fb3df220 | 207 | \r |
208 | **/\r | |
209 | EFI_DEVICE_PATH_PROTOCOL *\r | |
210 | EFIAPI\r | |
211 | AppendDevicePath (\r | |
212 | IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r | |
213 | IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r | |
214 | );\r | |
215 | \r | |
216 | /**\r | |
217 | Creates a new path by appending the device node to the device path.\r | |
218 | \r | |
219 | This function creates a new device path by appending a copy of the device node specified by\r | |
220 | DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r | |
221 | The end-of-device-path device node is moved after the end of the appended device node.\r | |
98a14db6 | 222 | If DevicePathNode is NULL then a copy of DevicePath is returned.\r |
6336a895 | 223 | If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device\r |
224 | node is returned.\r | |
98a14db6 | 225 | If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node\r |
226 | is returned.\r | |
fb3df220 | 227 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r |
228 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
229 | free the memory allocated.\r | |
230 | \r | |
231 | @param DevicePath A pointer to a device path data structure.\r | |
232 | @param DevicePathNode A pointer to a single device path node.\r | |
233 | \r | |
d80b2f71 | 234 | @retval NULL If there is not enough memory for the new device path.\r |
235 | @retval Others A pointer to the new device path if success.\r | |
236 | A copy of DevicePathNode followed by an end-of-device-path node \r | |
237 | if both FirstDevicePath and SecondDevicePath are NULL.\r | |
238 | A copy of an end-of-device-path node if both FirstDevicePath and SecondDevicePath are NULL.\r | |
fb3df220 | 239 | \r |
240 | **/\r | |
241 | EFI_DEVICE_PATH_PROTOCOL *\r | |
242 | EFIAPI\r | |
243 | AppendDevicePathNode (\r | |
244 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
245 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r | |
246 | );\r | |
247 | \r | |
248 | /**\r | |
249 | Creates a new device path by appending the specified device path instance to the specified device\r | |
250 | path.\r | |
251 | \r | |
252 | This function creates a new device path by appending a copy of the device path instance specified\r | |
253 | by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r | |
254 | The end-of-device-path device node is moved after the end of the appended device path instance\r | |
255 | and a new end-of-device-path-instance node is inserted between. \r | |
256 | If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r | |
257 | If DevicePathInstance is NULL, then NULL is returned.\r | |
258 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
259 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
260 | free the memory allocated.\r | |
261 | \r | |
262 | @param DevicePath A pointer to a device path data structure.\r | |
263 | @param DevicePathInstance A pointer to a device path instance.\r | |
264 | \r | |
265 | @return A pointer to the new device path.\r | |
266 | \r | |
267 | **/\r | |
268 | EFI_DEVICE_PATH_PROTOCOL *\r | |
269 | EFIAPI\r | |
270 | AppendDevicePathInstance (\r | |
271 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
272 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r | |
273 | );\r | |
274 | \r | |
275 | /**\r | |
276 | Creates a copy of the current device path instance and returns a pointer to the next device path\r | |
277 | instance.\r | |
278 | \r | |
279 | This function creates a copy of the current device path instance. It also updates DevicePath to\r | |
280 | point to the next device path instance in the device path (or NULL if no more) and updates Size\r | |
281 | to hold the size of the device path instance copy.\r | |
282 | If DevicePath is NULL, then NULL is returned.\r | |
283 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
284 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
285 | free the memory allocated.\r | |
286 | If Size is NULL, then ASSERT().\r | |
287 | \r | |
288 | @param DevicePath On input, this holds the pointer to the current device path\r | |
289 | instance. On output, this holds the pointer to the next device\r | |
290 | path instance or NULL if there are no more device path\r | |
291 | instances in the device path pointer to a device path data\r | |
292 | structure.\r | |
293 | @param Size On output, this holds the size of the device path instance, in\r | |
294 | bytes or zero, if DevicePath is NULL.\r | |
295 | \r | |
296 | @return A pointer to the current device path instance.\r | |
297 | \r | |
298 | **/\r | |
299 | EFI_DEVICE_PATH_PROTOCOL *\r | |
300 | EFIAPI\r | |
301 | GetNextDevicePathInstance (\r | |
302 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r | |
303 | OUT UINTN *Size\r | |
304 | );\r | |
305 | \r | |
306 | /**\r | |
d80b2f71 | 307 | Creates a device node.\r |
fb3df220 | 308 | \r |
309 | This function creates a new device node in a newly allocated buffer of size NodeLength and\r | |
310 | initializes the device path node header with NodeType and NodeSubType. The new device path node\r | |
311 | is returned.\r | |
312 | If NodeLength is smaller than a device path header, then NULL is returned. \r | |
313 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
314 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
315 | free the memory allocated.\r | |
316 | \r | |
317 | @param NodeType The device node type for the new device node.\r | |
318 | @param NodeSubType The device node sub-type for the new device node.\r | |
319 | @param NodeLength The length of the new device node.\r | |
320 | \r | |
321 | @return The new device path.\r | |
322 | \r | |
323 | **/\r | |
324 | EFI_DEVICE_PATH_PROTOCOL *\r | |
325 | EFIAPI\r | |
326 | CreateDeviceNode (\r | |
327 | IN UINT8 NodeType,\r | |
328 | IN UINT8 NodeSubType,\r | |
329 | IN UINT16 NodeLength\r | |
330 | );\r | |
331 | \r | |
332 | /**\r | |
333 | Determines if a device path is single or multi-instance.\r | |
334 | \r | |
335 | This function returns TRUE if the device path specified by DevicePath is multi-instance.\r | |
336 | Otherwise, FALSE is returned. If DevicePath is NULL, then FALSE is returned.\r | |
337 | \r | |
338 | @param DevicePath A pointer to a device path data structure.\r | |
339 | \r | |
340 | @retval TRUE DevicePath is multi-instance.\r | |
341 | @retval FALSE DevicePath is not multi-instance or DevicePath is NULL.\r | |
342 | \r | |
343 | **/\r | |
344 | BOOLEAN\r | |
345 | EFIAPI\r | |
346 | IsDevicePathMultiInstance (\r | |
347 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
348 | );\r | |
349 | \r | |
350 | /**\r | |
351 | Retrieves the device path protocol from a handle.\r | |
352 | \r | |
353 | This function returns the device path protocol from the handle specified by Handle. If Handle is\r | |
354 | NULL or Handle does not contain a device path protocol, then NULL is returned.\r | |
355 | \r | |
356 | @param Handle The handle from which to retrieve the device path protocol.\r | |
357 | \r | |
358 | @return The device path protocol from the handle specified by Handle.\r | |
359 | \r | |
360 | **/\r | |
361 | EFI_DEVICE_PATH_PROTOCOL *\r | |
362 | EFIAPI\r | |
363 | DevicePathFromHandle (\r | |
364 | IN EFI_HANDLE Handle\r | |
365 | );\r | |
366 | \r | |
367 | /**\r | |
368 | Allocates a device path for a file and appends it to an existing device path.\r | |
369 | \r | |
370 | If Device is a valid device handle that contains a device path protocol, then a device path for\r | |
371 | the file specified by FileName is allocated and appended to the device path associated with the\r | |
372 | handle Device. The allocated device path is returned. If Device is NULL or Device is a handle\r | |
373 | that does not support the device path protocol, then a device path containing a single device\r | |
374 | path node for the file specified by FileName is allocated and returned.\r | |
d80b2f71 | 375 | The memory for the new device path is allocated from EFI boot services memory. It is the responsibility\r |
376 | of the caller to free the memory allocated.\r | |
377 | \r | |
fb3df220 | 378 | If FileName is NULL, then ASSERT().\r |
d80b2f71 | 379 | If FileName is not aligned on a 16-bit boundary, then ASSERT().\r |
fb3df220 | 380 | \r |
381 | @param Device A pointer to a device handle. This parameter is optional and\r | |
382 | may be NULL.\r | |
383 | @param FileName A pointer to a Null-terminated Unicode string.\r | |
384 | \r | |
385 | @return The allocated device path.\r | |
386 | \r | |
387 | **/\r | |
388 | EFI_DEVICE_PATH_PROTOCOL *\r | |
389 | EFIAPI\r | |
390 | FileDevicePath (\r | |
391 | IN EFI_HANDLE Device, OPTIONAL\r | |
392 | IN CONST CHAR16 *FileName\r | |
393 | );\r | |
394 | \r | |
395 | #endif\r |