]>
Commit | Line | Data |
---|---|---|
e386b444 | 1 | /** @file\r |
f008fc32 | 2 | Library instance that implement UEFI Device Path Library class based on protocol\r |
3 | gEfiDevicePathUtilitiesProtocolGuid.\r | |
e386b444 | 4 | \r |
373ade0e | 5 | Copyright (c) 2006 - 2008, Intel Corporation<BR>\r |
e386b444 | 6 | All rights reserved. This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
e386b444 | 14 | **/\r |
15 | \r | |
c892d846 | 16 | \r |
c7d265a9 | 17 | #include <Uefi.h>\r |
c892d846 | 18 | \r |
c7d265a9 | 19 | #include <Protocol/DevicePathUtilities.h>\r |
20 | #include <Protocol/DevicePath.h>\r | |
c892d846 | 21 | \r |
c7d265a9 | 22 | #include <Library/DevicePathLib.h>\r |
23 | #include <Library/DebugLib.h>\r | |
24 | #include <Library/BaseLib.h>\r | |
25 | #include <Library/MemoryAllocationLib.h>\r | |
26 | #include <Library/BaseMemoryLib.h>\r | |
27 | #include <Library/UefiBootServicesTableLib.h>\r | |
e386b444 | 28 | \r |
fe467413 | 29 | EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathUtilities = NULL;\r |
e386b444 | 30 | \r |
3dc728fb | 31 | //\r |
32 | // Template for an end-of-device path node.\r | |
33 | //\r | |
34 | GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_PROTOCOL mUefiDevicePathLibEndDevicePath = {\r | |
35 | END_DEVICE_PATH_TYPE,\r | |
36 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
37 | {\r | |
38 | END_DEVICE_PATH_LENGTH,\r | |
39 | 0\r | |
40 | }\r | |
41 | };\r | |
42 | \r | |
e386b444 | 43 | /**\r |
44 | The constructor function caches the pointer to DevicePathUtilites protocol.\r | |
45 | \r | |
46 | The constructor function locates DevicePathUtilities protocol from protocol database.\r | |
47 | It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r | |
48 | \r | |
49 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
50 | @param SystemTable A pointer to the EFI System Table.\r | |
51 | \r | |
52 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
53 | \r | |
54 | **/\r | |
55 | EFI_STATUS\r | |
56 | EFIAPI\r | |
57 | DevicePathLibConstructor (\r | |
58 | IN EFI_HANDLE ImageHandle,\r | |
59 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
60 | )\r | |
61 | {\r | |
62 | EFI_STATUS Status;\r | |
63 | \r | |
64 | Status = gBS->LocateProtocol (\r | |
65 | &gEfiDevicePathUtilitiesProtocolGuid,\r | |
66 | NULL,\r | |
67 | (VOID**) &mDevicePathUtilities\r | |
68 | );\r | |
69 | ASSERT_EFI_ERROR (Status);\r | |
70 | ASSERT (mDevicePathUtilities != NULL);\r | |
71 | \r | |
72 | return Status;\r | |
73 | }\r | |
74 | \r | |
3dc728fb | 75 | /**\r |
76 | Returns the Type field of a device path node.\r | |
77 | \r | |
78 | Returns the Type field of the device path node specified by Node.\r | |
79 | \r | |
80 | If Node is NULL, then ASSERT().\r | |
81 | \r | |
82 | @param Node A pointer to a device path node data structure.\r | |
83 | \r | |
84 | @return The Type field of the device path node specified by Node.\r | |
85 | \r | |
86 | **/\r | |
87 | UINT8\r | |
88 | DevicePathType (\r | |
89 | IN CONST VOID *Node\r | |
90 | )\r | |
91 | {\r | |
92 | ASSERT (Node != NULL);\r | |
93 | return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type;\r | |
94 | }\r | |
95 | \r | |
96 | /**\r | |
97 | Returns the SubType field of a device path node.\r | |
98 | \r | |
99 | Returns the SubType field of the device path node specified by Node.\r | |
100 | \r | |
101 | If Node is NULL, then ASSERT().\r | |
102 | \r | |
103 | @param Node A pointer to a device path node data structure.\r | |
104 | \r | |
105 | @return The SubType field of the device path node specified by Node.\r | |
106 | \r | |
107 | **/\r | |
108 | UINT8\r | |
109 | DevicePathSubType (\r | |
110 | IN CONST VOID *Node\r | |
111 | )\r | |
112 | {\r | |
113 | ASSERT (Node != NULL);\r | |
114 | return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType;\r | |
115 | }\r | |
116 | \r | |
117 | /**\r | |
118 | Returns the 16-bit Length field of a device path node.\r | |
119 | \r | |
120 | Returns the 16-bit Length field of the device path node specified by Node. \r | |
121 | Node is not required to be aligned on a 16-bit boundary, so it is recommended\r | |
122 | that a function such as ReadUnaligned16() be used to extract the contents of \r | |
123 | the Length field.\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 | @return The 16-bit Length field of the device path node specified by Node.\r | |
130 | \r | |
131 | **/\r | |
132 | UINTN\r | |
133 | DevicePathNodeLength (\r | |
134 | IN CONST VOID *Node\r | |
135 | )\r | |
136 | {\r | |
137 | ASSERT (Node != NULL);\r | |
138 | return ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);\r | |
139 | }\r | |
140 | \r | |
141 | /**\r | |
142 | Returns a pointer to the next node in a device path.\r | |
143 | \r | |
144 | Returns a pointer to the device path node that follows the device path node specified by Node.\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 | @return a pointer to the device path node that follows the device path node specified by Node.\r | |
151 | \r | |
152 | **/\r | |
153 | EFI_DEVICE_PATH_PROTOCOL *\r | |
154 | NextDevicePathNode (\r | |
155 | IN CONST VOID *Node\r | |
156 | )\r | |
157 | {\r | |
158 | ASSERT (Node != NULL);\r | |
159 | return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));\r | |
160 | }\r | |
161 | \r | |
162 | /**\r | |
163 | Determines if a device path node is an end node of a device path.\r | |
164 | This includes nodes that are the end of a device path instance and nodes that are the end of an entire device path.\r | |
165 | \r | |
166 | Determines if the device path node specified by Node is an end node of a device path. \r | |
167 | This includes nodes that are the end of a device path instance and nodes that are the \r | |
168 | end of an entire device path. If Node represents an end node of a device path, \r | |
169 | then TRUE is returned. Otherwise, FALSE is returned.\r | |
170 | \r | |
171 | If Node is NULL, then ASSERT().\r | |
172 | \r | |
173 | @param Node A pointer to a device path node data structure.\r | |
174 | \r | |
175 | @retval TRUE The device path node specified by Node is an end node of a device path.\r | |
176 | @retval FALSE The device path node specified by Node is not an end node of a device path.\r | |
177 | \r | |
178 | **/\r | |
179 | BOOLEAN\r | |
180 | IsDevicePathEndType (\r | |
181 | IN CONST VOID *Node\r | |
182 | )\r | |
183 | {\r | |
184 | ASSERT (Node != NULL);\r | |
1bfc7438 | 185 | return (BOOLEAN) ((DevicePathType (Node) & 0x7f) == END_DEVICE_PATH_TYPE);\r |
3dc728fb | 186 | }\r |
187 | \r | |
188 | /**\r | |
189 | Determines if a device path node is an end node of an entire device path.\r | |
190 | \r | |
191 | Determines if a device path node specified by Node is an end node of an entire device path.\r | |
192 | If Node represents the end of an entire device path, then TRUE is returned. Otherwise, FALSE is returned.\r | |
193 | \r | |
194 | If Node is NULL, then ASSERT().\r | |
195 | \r | |
196 | @param Node A pointer to a device path node data structure.\r | |
197 | \r | |
198 | @retval TRUE The device path node specified by Node is the end of an entire device path.\r | |
199 | @retval FALSE The device path node specified by Node is not the end of an entire device path.\r | |
200 | \r | |
201 | **/\r | |
202 | BOOLEAN\r | |
203 | IsDevicePathEnd (\r | |
204 | IN CONST VOID *Node\r | |
205 | )\r | |
206 | {\r | |
207 | ASSERT (Node != NULL);\r | |
1bfc7438 | 208 | return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);\r |
3dc728fb | 209 | }\r |
210 | \r | |
211 | /**\r | |
212 | Determines if a device path node is an end node of a device path instance.\r | |
213 | \r | |
214 | Determines if a device path node specified by Node is an end node of a device path instance.\r | |
215 | If Node represents the end of a device path instance, then TRUE is returned. Otherwise, FALSE is returned.\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 | @retval TRUE The device path node specified by Node is the end of a device path instance.\r | |
222 | @retval FALSE The device path node specified by Node is not the end of a device path instance.\r | |
223 | \r | |
224 | **/\r | |
225 | BOOLEAN\r | |
226 | IsDevicePathEndInstance (\r | |
227 | IN CONST VOID *Node\r | |
228 | )\r | |
229 | {\r | |
230 | ASSERT (Node != NULL);\r | |
1bfc7438 | 231 | return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);\r |
3dc728fb | 232 | }\r |
233 | \r | |
234 | /**\r | |
235 | Sets the length, in bytes, of a device path node.\r | |
236 | \r | |
237 | Sets the length of the device path node specified by Node to the value specified \r | |
238 | by NodeLength. NodeLength is returned. Node is not required to be aligned on \r | |
239 | a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()\r | |
240 | be used to set the contents of the Length field.\r | |
241 | \r | |
242 | If Node is NULL, then ASSERT().\r | |
243 | If NodeLength >= 0x10000, then ASSERT().\r | |
244 | \r | |
245 | @param Node A pointer to a device path node data structure.\r | |
246 | @param Length The length, in bytes, of the device path node.\r | |
247 | \r | |
248 | @return Length\r | |
249 | \r | |
250 | **/\r | |
251 | UINT16\r | |
252 | SetDevicePathNodeLength (\r | |
9bb407c6 | 253 | IN OUT VOID *Node,\r |
8f0dd97e | 254 | IN UINTN Length\r |
3dc728fb | 255 | )\r |
256 | {\r | |
257 | ASSERT (Node != NULL);\r | |
8f0dd97e | 258 | ASSERT (Length < 0x10000);\r |
259 | return WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(Length));\r | |
3dc728fb | 260 | }\r |
261 | \r | |
262 | /**\r | |
263 | Fills in all the fields of a device path node that is the end of an entire device path.\r | |
264 | \r | |
265 | Fills in all the fields of a device path node specified by Node so Node represents \r | |
266 | the end of an entire device path. The Type field of Node is set to \r | |
267 | END_DEVICE_PATH_TYPE, the SubType field of Node is set to \r | |
268 | END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to \r | |
269 | END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary, \r | |
270 | so it is recommended that a function such as WriteUnaligned16() be used to set \r | |
271 | the contents of the Length field. \r | |
272 | \r | |
273 | If Node is NULL, then ASSERT(). \r | |
274 | \r | |
275 | @param Node A pointer to a device path node data structure.\r | |
276 | \r | |
277 | **/\r | |
278 | VOID\r | |
279 | SetDevicePathEndNode (\r | |
9bb407c6 | 280 | OUT VOID *Node\r |
3dc728fb | 281 | )\r |
282 | {\r | |
283 | ASSERT (Node != NULL);\r | |
284 | CopyMem (Node, &mUefiDevicePathLibEndDevicePath, sizeof (mUefiDevicePathLibEndDevicePath));\r | |
285 | }\r | |
286 | \r | |
e386b444 | 287 | /**\r |
288 | Returns the size of a device path in bytes.\r | |
289 | \r | |
290 | This function returns the size, in bytes, of the device path data structure specified by\r | |
291 | DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned.\r | |
292 | \r | |
293 | @param DevicePath A pointer to a device path data structure.\r | |
3e5c3238 | 294 | \r |
295 | @retval 0 If DevicePath is NULL.\r | |
296 | @retval Others The size of a device path in bytes.\r | |
e386b444 | 297 | \r |
298 | **/\r | |
299 | UINTN\r | |
300 | EFIAPI\r | |
301 | GetDevicePathSize (\r | |
302 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
303 | )\r | |
304 | {\r | |
305 | return mDevicePathUtilities->GetDevicePathSize (DevicePath);\r | |
306 | }\r | |
307 | \r | |
308 | /**\r | |
6a3f4ef9 | 309 | Creates a new copy of an existing device path.\r |
e386b444 | 310 | \r |
311 | This function allocates space for a new copy of the device path specified by DevicePath. If\r | |
312 | DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the\r | |
313 | contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r | |
314 | is returned. Otherwise, NULL is returned. \r | |
3e5c3238 | 315 | The memory for the new device path is allocated from EFI boot services memory. \r |
316 | It is the responsibility of the caller to free the memory allocated. \r | |
e386b444 | 317 | \r |
318 | @param DevicePath A pointer to a device path data structure.\r | |
319 | \r | |
3e5c3238 | 320 | @retval NULL If DevicePath is NULL.\r |
321 | @retval Others A pointer to the duplicated device path.\r | |
322 | \r | |
e386b444 | 323 | **/\r |
324 | EFI_DEVICE_PATH_PROTOCOL *\r | |
325 | EFIAPI\r | |
326 | DuplicateDevicePath (\r | |
327 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
328 | )\r | |
329 | {\r | |
330 | return mDevicePathUtilities->DuplicateDevicePath (DevicePath);\r | |
331 | }\r | |
332 | \r | |
333 | /**\r | |
334 | Creates a new device path by appending a second device path to a first device path.\r | |
335 | \r | |
336 | This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r | |
337 | FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from\r | |
338 | SecondDevicePath is retained. The newly created device path is returned. \r | |
339 | If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned. \r | |
340 | If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned. \r | |
98a14db6 | 341 | If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r |
342 | returned. \r | |
e386b444 | 343 | If there is not enough memory for the newly allocated buffer, then NULL is returned.\r |
344 | The memory for the new device path is allocated from EFI boot services memory. It is the\r | |
345 | responsibility of the caller to free the memory allocated.\r | |
346 | \r | |
347 | @param FirstDevicePath A pointer to a device path data structure.\r | |
348 | @param SecondDevicePath A pointer to a device path data structure.\r | |
3e5c3238 | 349 | \r |
350 | @retval NULL If there is not enough memory for the newly allocated buffer.\r | |
351 | @retval Others A pointer to the new device path if success.\r | |
352 | Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r | |
e386b444 | 353 | \r |
354 | **/\r | |
355 | EFI_DEVICE_PATH_PROTOCOL *\r | |
356 | EFIAPI\r | |
357 | AppendDevicePath (\r | |
358 | IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r | |
359 | IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r | |
360 | )\r | |
361 | {\r | |
362 | return mDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);\r | |
363 | }\r | |
364 | \r | |
365 | /**\r | |
366 | Creates a new path by appending the device node to the device path.\r | |
367 | \r | |
368 | This function creates a new device path by appending a copy of the device node specified by\r | |
369 | DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r | |
370 | The end-of-device-path device node is moved after the end of the appended device node.\r | |
98a14db6 | 371 | If DevicePathNode is NULL then a copy of DevicePath is returned.\r |
6336a895 | 372 | If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device\r |
373 | node is returned.\r | |
98a14db6 | 374 | If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node\r |
375 | is returned.\r | |
e386b444 | 376 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r |
377 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
378 | free the memory allocated.\r | |
379 | \r | |
380 | @param DevicePath A pointer to a device path data structure.\r | |
381 | @param DevicePathNode A pointer to a single device path node.\r | |
382 | \r | |
3e5c3238 | 383 | @retval NULL If there is not enough memory for the new device path.\r |
384 | @retval Others A pointer to the new device path if success.\r | |
385 | A copy of DevicePathNode followed by an end-of-device-path node \r | |
386 | if both FirstDevicePath and SecondDevicePath are NULL.\r | |
387 | A copy of an end-of-device-path node if both FirstDevicePath and SecondDevicePath are NULL.\r | |
e386b444 | 388 | \r |
389 | **/\r | |
390 | EFI_DEVICE_PATH_PROTOCOL *\r | |
391 | EFIAPI\r | |
392 | AppendDevicePathNode (\r | |
393 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
394 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r | |
395 | )\r | |
396 | {\r | |
397 | return mDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode);\r | |
398 | }\r | |
399 | \r | |
400 | /**\r | |
401 | Creates a new device path by appending the specified device path instance to the specified device\r | |
402 | path.\r | |
403 | \r | |
404 | This function creates a new device path by appending a copy of the device path instance specified\r | |
405 | by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r | |
406 | The end-of-device-path device node is moved after the end of the appended device path instance\r | |
407 | and a new end-of-device-path-instance node is inserted between. \r | |
408 | If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r | |
409 | If DevicePathInstance is NULL, then NULL is returned.\r | |
410 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
411 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
412 | free the memory allocated.\r | |
413 | \r | |
414 | @param DevicePath A pointer to a device path data structure.\r | |
415 | @param DevicePathInstance A pointer to a device path instance.\r | |
416 | \r | |
417 | @return A pointer to the new device path.\r | |
418 | \r | |
419 | **/\r | |
420 | EFI_DEVICE_PATH_PROTOCOL *\r | |
421 | EFIAPI\r | |
422 | AppendDevicePathInstance (\r | |
423 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
424 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r | |
425 | )\r | |
426 | {\r | |
427 | return mDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);\r | |
428 | }\r | |
429 | \r | |
430 | /**\r | |
431 | Creates a copy of the current device path instance and returns a pointer to the next device path\r | |
432 | instance.\r | |
433 | \r | |
434 | This function creates a copy of the current device path instance. It also updates DevicePath to\r | |
435 | point to the next device path instance in the device path (or NULL if no more) and updates Size\r | |
436 | to hold the size of the device path instance copy.\r | |
437 | If DevicePath is NULL, then NULL is returned.\r | |
438 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
439 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
440 | free the memory allocated.\r | |
441 | If Size is NULL, then ASSERT().\r | |
442 | \r | |
443 | @param DevicePath On input, this holds the pointer to the current device path\r | |
444 | instance. On output, this holds the pointer to the next device\r | |
445 | path instance or NULL if there are no more device path\r | |
446 | instances in the device path pointer to a device path data\r | |
447 | structure.\r | |
448 | @param Size On output, this holds the size of the device path instance, in\r | |
449 | bytes or zero, if DevicePath is NULL.\r | |
450 | \r | |
451 | @return A pointer to the current device path instance.\r | |
452 | \r | |
453 | **/\r | |
454 | EFI_DEVICE_PATH_PROTOCOL *\r | |
455 | EFIAPI\r | |
456 | GetNextDevicePathInstance (\r | |
457 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r | |
458 | OUT UINTN *Size\r | |
459 | )\r | |
460 | {\r | |
461 | ASSERT (Size != NULL);\r | |
462 | return mDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);\r | |
463 | }\r | |
464 | \r | |
465 | /**\r | |
3e5c3238 | 466 | Creates a device node.\r |
e386b444 | 467 | \r |
468 | This function creates a new device node in a newly allocated buffer of size NodeLength and\r | |
469 | initializes the device path node header with NodeType and NodeSubType. The new device path node\r | |
470 | is returned.\r | |
471 | If NodeLength is smaller than a device path header, then NULL is returned. \r | |
472 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
473 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
474 | free the memory allocated.\r | |
475 | \r | |
476 | @param NodeType The device node type for the new device node.\r | |
477 | @param NodeSubType The device node sub-type for the new device node.\r | |
478 | @param NodeLength The length of the new device node.\r | |
479 | \r | |
3e5c3238 | 480 | @return The new device path.\r |
e386b444 | 481 | \r |
482 | **/\r | |
483 | EFI_DEVICE_PATH_PROTOCOL *\r | |
484 | EFIAPI\r | |
485 | CreateDeviceNode (\r | |
486 | IN UINT8 NodeType,\r | |
487 | IN UINT8 NodeSubType,\r | |
488 | IN UINT16 NodeLength\r | |
489 | )\r | |
490 | {\r | |
491 | return mDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);\r | |
492 | }\r | |
493 | \r | |
494 | /**\r | |
495 | Determines if a device path is single or multi-instance.\r | |
496 | \r | |
497 | This function returns TRUE if the device path specified by DevicePath is multi-instance.\r | |
498 | Otherwise, FALSE is returned. If DevicePath is NULL, then FALSE is returned.\r | |
499 | \r | |
500 | @param DevicePath A pointer to a device path data structure.\r | |
501 | \r | |
502 | @retval TRUE DevicePath is multi-instance.\r | |
503 | @retval FALSE DevicePath is not multi-instance or DevicePath is NULL.\r | |
504 | \r | |
505 | **/\r | |
506 | BOOLEAN\r | |
507 | EFIAPI\r | |
508 | IsDevicePathMultiInstance (\r | |
509 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
510 | )\r | |
511 | {\r | |
512 | return mDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);\r | |
513 | }\r | |
514 | \r | |
515 | /**\r | |
516 | Retrieves the device path protocol from a handle.\r | |
517 | \r | |
518 | This function returns the device path protocol from the handle specified by Handle. If Handle is\r | |
519 | NULL or Handle does not contain a device path protocol, then NULL is returned.\r | |
520 | \r | |
521 | @param Handle The handle from which to retrieve the device path protocol.\r | |
522 | \r | |
523 | @return The device path protocol from the handle specified by Handle.\r | |
524 | \r | |
525 | **/\r | |
526 | EFI_DEVICE_PATH_PROTOCOL *\r | |
527 | EFIAPI\r | |
528 | DevicePathFromHandle (\r | |
529 | IN EFI_HANDLE Handle\r | |
530 | )\r | |
531 | {\r | |
532 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
533 | EFI_STATUS Status;\r | |
534 | \r | |
535 | Status = gBS->HandleProtocol (\r | |
536 | Handle,\r | |
537 | &gEfiDevicePathProtocolGuid,\r | |
538 | (VOID *) &DevicePath\r | |
539 | );\r | |
540 | if (EFI_ERROR (Status)) {\r | |
541 | DevicePath = NULL;\r | |
542 | }\r | |
543 | return DevicePath;\r | |
544 | }\r | |
545 | \r | |
546 | /**\r | |
547 | Allocates a device path for a file and appends it to an existing device path.\r | |
548 | \r | |
549 | If Device is a valid device handle that contains a device path protocol, then a device path for\r | |
550 | the file specified by FileName is allocated and appended to the device path associated with the\r | |
551 | handle Device. The allocated device path is returned. If Device is NULL or Device is a handle\r | |
552 | that does not support the device path protocol, then a device path containing a single device\r | |
553 | path node for the file specified by FileName is allocated and returned.\r | |
3e5c3238 | 554 | The memory for the new device path is allocated from EFI boot services memory. It is the responsibility\r |
555 | of the caller to free the memory allocated.\r | |
556 | \r | |
e386b444 | 557 | If FileName is NULL, then ASSERT().\r |
3e5c3238 | 558 | If FileName is not aligned on a 16-bit boundary, then ASSERT().\r |
e386b444 | 559 | \r |
560 | @param Device A pointer to a device handle. This parameter is optional and\r | |
561 | may be NULL.\r | |
562 | @param FileName A pointer to a Null-terminated Unicode string.\r | |
563 | \r | |
3e5c3238 | 564 | @return The allocated device path.\r |
e386b444 | 565 | \r |
566 | **/\r | |
567 | EFI_DEVICE_PATH_PROTOCOL *\r | |
568 | EFIAPI\r | |
569 | FileDevicePath (\r | |
570 | IN EFI_HANDLE Device, OPTIONAL\r | |
571 | IN CONST CHAR16 *FileName\r | |
572 | )\r | |
573 | {\r | |
574 | UINTN Size;\r | |
575 | FILEPATH_DEVICE_PATH *FilePath;\r | |
576 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
577 | EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;\r | |
578 | \r | |
579 | DevicePath = NULL;\r | |
580 | \r | |
581 | Size = StrSize (FileName);\r | |
e5dab016 | 582 | FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);\r |
e386b444 | 583 | if (FileDevicePath != NULL) {\r |
584 | FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;\r | |
585 | FilePath->Header.Type = MEDIA_DEVICE_PATH;\r | |
586 | FilePath->Header.SubType = MEDIA_FILEPATH_DP;\r | |
587 | CopyMem (&FilePath->PathName, FileName, Size);\r | |
588 | SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);\r | |
589 | SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));\r | |
590 | \r | |
591 | if (Device != NULL) {\r | |
592 | DevicePath = DevicePathFromHandle (Device);\r | |
593 | }\r | |
594 | \r | |
595 | DevicePath = AppendDevicePath (DevicePath, FileDevicePath);\r | |
596 | FreePool (FileDevicePath);\r | |
597 | }\r | |
598 | \r | |
599 | return DevicePath;\r | |
600 | }\r |