]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Library instance that implement UEFI Device Path Library class based on protocol\r | |
3 | gEfiDevicePathUtilitiesProtocolGuid.\r | |
4 | \r | |
5 | Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r | |
6 | 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 | |
14 | **/\r | |
15 | \r | |
16 | \r | |
17 | #include <Uefi.h>\r | |
18 | \r | |
19 | #include <Protocol/DevicePathUtilities.h>\r | |
20 | #include <Protocol/DevicePathToText.h>\r | |
21 | #include <Protocol/DevicePathFromText.h>\r | |
22 | \r | |
23 | #include <Library/DevicePathLib.h>\r | |
24 | #include <Library/DebugLib.h>\r | |
25 | #include <Library/BaseLib.h>\r | |
26 | #include <Library/MemoryAllocationLib.h>\r | |
27 | #include <Library/BaseMemoryLib.h>\r | |
28 | #include <Library/UefiBootServicesTableLib.h>\r | |
29 | #include <Library/PcdLib.h>\r | |
30 | \r | |
31 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathLibDevicePathUtilities = NULL;\r | |
32 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *mDevicePathLibDevicePathToText = NULL;\r | |
33 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *mDevicePathLibDevicePathFromText = NULL;\r | |
34 | \r | |
35 | //\r | |
36 | // Template for an end-of-device path node.\r | |
37 | //\r | |
38 | GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_PROTOCOL mUefiDevicePathLibEndDevicePath = {\r | |
39 | END_DEVICE_PATH_TYPE,\r | |
40 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
41 | {\r | |
42 | END_DEVICE_PATH_LENGTH,\r | |
43 | 0\r | |
44 | }\r | |
45 | };\r | |
46 | \r | |
47 | /**\r | |
48 | The constructor function caches the pointer to DevicePathUtilites protocol.\r | |
49 | \r | |
50 | The constructor function locates DevicePathUtilities protocol from protocol database.\r | |
51 | It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r | |
52 | \r | |
53 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
54 | @param SystemTable A pointer to the EFI System Table.\r | |
55 | \r | |
56 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
57 | \r | |
58 | **/\r | |
59 | EFI_STATUS\r | |
60 | EFIAPI\r | |
61 | DevicePathLibConstructor (\r | |
62 | IN EFI_HANDLE ImageHandle,\r | |
63 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
64 | )\r | |
65 | {\r | |
66 | EFI_STATUS Status;\r | |
67 | \r | |
68 | Status = gBS->LocateProtocol (\r | |
69 | &gEfiDevicePathUtilitiesProtocolGuid,\r | |
70 | NULL,\r | |
71 | (VOID**) &mDevicePathLibDevicePathUtilities\r | |
72 | );\r | |
73 | ASSERT_EFI_ERROR (Status);\r | |
74 | ASSERT (mDevicePathLibDevicePathUtilities != NULL);\r | |
75 | return Status;\r | |
76 | }\r | |
77 | \r | |
78 | /**\r | |
79 | Determine whether a given device path is valid.\r | |
80 | If DevicePath is NULL, then ASSERT().\r | |
81 | \r | |
82 | @param DevicePath A pointer to a device path data structure.\r | |
83 | @param MaxSize The maximum size of the device path data structure.\r | |
84 | \r | |
85 | @retval TRUE DevicePath is valid.\r | |
86 | @retval FALSE The length of any node node in the DevicePath is less\r | |
87 | than sizeof (EFI_DEVICE_PATH_PROTOCOL).\r | |
88 | @retval FALSE If MaxSize is not zero, the size of the DevicePath\r | |
89 | exceeds MaxSize.\r | |
90 | @retval FALSE If PcdMaximumDevicePathNodeCount is not zero, the node\r | |
91 | count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.\r | |
92 | **/\r | |
93 | BOOLEAN\r | |
94 | EFIAPI\r | |
95 | IsDevicePathValid (\r | |
96 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
97 | IN UINTN MaxSize\r | |
98 | )\r | |
99 | {\r | |
100 | UINTN Count;\r | |
101 | UINTN Size;\r | |
102 | UINTN NodeLength;\r | |
103 | \r | |
104 | ASSERT (DevicePath != NULL);\r | |
105 | \r | |
106 | for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {\r | |
107 | NodeLength = DevicePathNodeLength (DevicePath);\r | |
108 | if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r | |
109 | return FALSE;\r | |
110 | }\r | |
111 | \r | |
112 | if (MaxSize > 0) {\r | |
113 | Size += NodeLength;\r | |
114 | if (Size + END_DEVICE_PATH_LENGTH > MaxSize) {\r | |
115 | return FALSE;\r | |
116 | }\r | |
117 | }\r | |
118 | \r | |
119 | if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {\r | |
120 | Count++;\r | |
121 | if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) {\r | |
122 | return FALSE;\r | |
123 | }\r | |
124 | }\r | |
125 | }\r | |
126 | \r | |
127 | //\r | |
128 | // Only return TRUE when the End Device Path node is valid.\r | |
129 | //\r | |
130 | return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);\r | |
131 | }\r | |
132 | \r | |
133 | /**\r | |
134 | Returns the Type field of a device path node.\r | |
135 | \r | |
136 | Returns the Type field of the device path node specified by Node.\r | |
137 | \r | |
138 | If Node is NULL, then ASSERT().\r | |
139 | \r | |
140 | @param Node A pointer to a device path node data structure.\r | |
141 | \r | |
142 | @return The Type field of the device path node specified by Node.\r | |
143 | \r | |
144 | **/\r | |
145 | UINT8\r | |
146 | EFIAPI\r | |
147 | DevicePathType (\r | |
148 | IN CONST VOID *Node\r | |
149 | )\r | |
150 | {\r | |
151 | ASSERT (Node != NULL);\r | |
152 | return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type;\r | |
153 | }\r | |
154 | \r | |
155 | /**\r | |
156 | Returns the SubType field of a device path node.\r | |
157 | \r | |
158 | Returns the SubType field of the device path node specified by Node.\r | |
159 | \r | |
160 | If Node is NULL, then ASSERT().\r | |
161 | \r | |
162 | @param Node A pointer to a device path node data structure.\r | |
163 | \r | |
164 | @return The SubType field of the device path node specified by Node.\r | |
165 | \r | |
166 | **/\r | |
167 | UINT8\r | |
168 | EFIAPI\r | |
169 | DevicePathSubType (\r | |
170 | IN CONST VOID *Node\r | |
171 | )\r | |
172 | {\r | |
173 | ASSERT (Node != NULL);\r | |
174 | return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType;\r | |
175 | }\r | |
176 | \r | |
177 | /**\r | |
178 | Returns the 16-bit Length field of a device path node.\r | |
179 | \r | |
180 | Returns the 16-bit Length field of the device path node specified by Node. \r | |
181 | Node is not required to be aligned on a 16-bit boundary, so it is recommended\r | |
182 | that a function such as ReadUnaligned16() be used to extract the contents of \r | |
183 | the Length field.\r | |
184 | \r | |
185 | If Node is NULL, then ASSERT().\r | |
186 | \r | |
187 | @param Node A pointer to a device path node data structure.\r | |
188 | \r | |
189 | @return The 16-bit Length field of the device path node specified by Node.\r | |
190 | \r | |
191 | **/\r | |
192 | UINTN\r | |
193 | EFIAPI\r | |
194 | DevicePathNodeLength (\r | |
195 | IN CONST VOID *Node\r | |
196 | )\r | |
197 | {\r | |
198 | UINTN Length;\r | |
199 | \r | |
200 | ASSERT (Node != NULL);\r | |
201 | Length = ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);\r | |
202 | ASSERT (Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL));\r | |
203 | return Length;\r | |
204 | }\r | |
205 | \r | |
206 | /**\r | |
207 | Returns a pointer to the next node in a device path.\r | |
208 | \r | |
209 | Returns a pointer to the device path node that follows the device path node \r | |
210 | specified by Node.\r | |
211 | \r | |
212 | If Node is NULL, then ASSERT().\r | |
213 | \r | |
214 | @param Node A pointer to a device path node data structure.\r | |
215 | \r | |
216 | @return a pointer to the device path node that follows the device path node \r | |
217 | specified by Node.\r | |
218 | \r | |
219 | **/\r | |
220 | EFI_DEVICE_PATH_PROTOCOL *\r | |
221 | EFIAPI\r | |
222 | NextDevicePathNode (\r | |
223 | IN CONST VOID *Node\r | |
224 | )\r | |
225 | {\r | |
226 | ASSERT (Node != NULL);\r | |
227 | return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));\r | |
228 | }\r | |
229 | \r | |
230 | /**\r | |
231 | Determines if a device path node is an end node of a device path.\r | |
232 | This includes nodes that are the end of a device path instance and nodes that \r | |
233 | are the end of an entire device path.\r | |
234 | \r | |
235 | Determines if the device path node specified by Node is an end node of a device path. \r | |
236 | This includes nodes that are the end of a device path instance and nodes that are the \r | |
237 | end of an entire device path. If Node represents an end node of a device path, \r | |
238 | then TRUE is returned. Otherwise, FALSE is returned.\r | |
239 | \r | |
240 | If Node is NULL, then ASSERT().\r | |
241 | \r | |
242 | @param Node A pointer to a device path node data structure.\r | |
243 | \r | |
244 | @retval TRUE The device path node specified by Node is an end node of a device path.\r | |
245 | @retval FALSE The device path node specified by Node is not an end node of \r | |
246 | a device path.\r | |
247 | \r | |
248 | **/\r | |
249 | BOOLEAN\r | |
250 | EFIAPI\r | |
251 | IsDevicePathEndType (\r | |
252 | IN CONST VOID *Node\r | |
253 | )\r | |
254 | {\r | |
255 | ASSERT (Node != NULL);\r | |
256 | return (BOOLEAN) (DevicePathType (Node) == END_DEVICE_PATH_TYPE);\r | |
257 | }\r | |
258 | \r | |
259 | /**\r | |
260 | Determines if a device path node is an end node of an entire device path.\r | |
261 | \r | |
262 | Determines if a device path node specified by Node is an end node of an entire \r | |
263 | device path.\r | |
264 | If Node represents the end of an entire device path, then TRUE is returned. \r | |
265 | Otherwise, FALSE is returned.\r | |
266 | \r | |
267 | If Node is NULL, then ASSERT().\r | |
268 | \r | |
269 | @param Node A pointer to a device path node data structure.\r | |
270 | \r | |
271 | @retval TRUE The device path node specified by Node is the end of an entire device path.\r | |
272 | @retval FALSE The device path node specified by Node is not the end of an entire device path.\r | |
273 | \r | |
274 | **/\r | |
275 | BOOLEAN\r | |
276 | EFIAPI\r | |
277 | IsDevicePathEnd (\r | |
278 | IN CONST VOID *Node\r | |
279 | )\r | |
280 | {\r | |
281 | ASSERT (Node != NULL);\r | |
282 | return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);\r | |
283 | }\r | |
284 | \r | |
285 | /**\r | |
286 | Determines if a device path node is an end node of a device path instance.\r | |
287 | \r | |
288 | Determines if a device path node specified by Node is an end node of a device \r | |
289 | path instance.\r | |
290 | If Node represents the end of a device path instance, then TRUE is returned. \r | |
291 | Otherwise, FALSE is returned.\r | |
292 | \r | |
293 | If Node is NULL, then ASSERT().\r | |
294 | \r | |
295 | @param Node A pointer to a device path node data structure.\r | |
296 | \r | |
297 | @retval TRUE The device path node specified by Node is the end of a device \r | |
298 | path instance.\r | |
299 | @retval FALSE The device path node specified by Node is not the end of a \r | |
300 | device path instance.\r | |
301 | \r | |
302 | **/\r | |
303 | BOOLEAN\r | |
304 | EFIAPI\r | |
305 | IsDevicePathEndInstance (\r | |
306 | IN CONST VOID *Node\r | |
307 | )\r | |
308 | {\r | |
309 | ASSERT (Node != NULL);\r | |
310 | return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);\r | |
311 | }\r | |
312 | \r | |
313 | /**\r | |
314 | Sets the length, in bytes, of a device path node.\r | |
315 | \r | |
316 | Sets the length of the device path node specified by Node to the value specified \r | |
317 | by NodeLength. NodeLength is returned. Node is not required to be aligned on \r | |
318 | a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()\r | |
319 | be used to set the contents of the Length field.\r | |
320 | \r | |
321 | If Node is NULL, then ASSERT().\r | |
322 | If NodeLength >= SIZE_64KB, then ASSERT().\r | |
323 | If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().\r | |
324 | \r | |
325 | @param Node A pointer to a device path node data structure.\r | |
326 | @param Length The length, in bytes, of the device path node.\r | |
327 | \r | |
328 | @return Length\r | |
329 | \r | |
330 | **/\r | |
331 | UINT16\r | |
332 | EFIAPI\r | |
333 | SetDevicePathNodeLength (\r | |
334 | IN OUT VOID *Node,\r | |
335 | IN UINTN Length\r | |
336 | )\r | |
337 | {\r | |
338 | ASSERT (Node != NULL);\r | |
339 | ASSERT ((Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL)) && (Length < SIZE_64KB));\r | |
340 | return WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(Length));\r | |
341 | }\r | |
342 | \r | |
343 | /**\r | |
344 | Fills in all the fields of a device path node that is the end of an entire device path.\r | |
345 | \r | |
346 | Fills in all the fields of a device path node specified by Node so Node represents \r | |
347 | the end of an entire device path. The Type field of Node is set to \r | |
348 | END_DEVICE_PATH_TYPE, the SubType field of Node is set to \r | |
349 | END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to \r | |
350 | END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary, \r | |
351 | so it is recommended that a function such as WriteUnaligned16() be used to set \r | |
352 | the contents of the Length field. \r | |
353 | \r | |
354 | If Node is NULL, then ASSERT(). \r | |
355 | \r | |
356 | @param Node A pointer to a device path node data structure.\r | |
357 | \r | |
358 | **/\r | |
359 | VOID\r | |
360 | EFIAPI\r | |
361 | SetDevicePathEndNode (\r | |
362 | OUT VOID *Node\r | |
363 | )\r | |
364 | {\r | |
365 | ASSERT (Node != NULL);\r | |
366 | CopyMem (Node, &mUefiDevicePathLibEndDevicePath, sizeof (mUefiDevicePathLibEndDevicePath));\r | |
367 | }\r | |
368 | \r | |
369 | /**\r | |
370 | Returns the size of a device path in bytes.\r | |
371 | \r | |
372 | This function returns the size, in bytes, of the device path data structure \r | |
373 | specified by DevicePath including the end of device path node.\r | |
374 | If DevicePath is NULL or invalid, then 0 is returned.\r | |
375 | \r | |
376 | @param DevicePath A pointer to a device path data structure.\r | |
377 | \r | |
378 | @retval 0 If DevicePath is NULL or invalid.\r | |
379 | @retval Others The size of a device path in bytes.\r | |
380 | \r | |
381 | **/\r | |
382 | UINTN\r | |
383 | EFIAPI\r | |
384 | GetDevicePathSize (\r | |
385 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
386 | )\r | |
387 | {\r | |
388 | return mDevicePathLibDevicePathUtilities->GetDevicePathSize (DevicePath);\r | |
389 | }\r | |
390 | \r | |
391 | /**\r | |
392 | Creates a new copy of an existing device path.\r | |
393 | \r | |
394 | This function allocates space for a new copy of the device path specified by \r | |
395 | DevicePath. If DevicePath is NULL, then NULL is returned. \r | |
396 | If the memory is successfully allocated, then the\r | |
397 | contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r | |
398 | is returned. Otherwise, NULL is returned. \r | |
399 | The memory for the new device path is allocated from EFI boot services memory. \r | |
400 | It is the responsibility of the caller to free the memory allocated. \r | |
401 | \r | |
402 | @param DevicePath A pointer to a device path data structure.\r | |
403 | \r | |
404 | @retval NULL If DevicePath is NULL or invalid.\r | |
405 | @retval Others A pointer to the duplicated device path.\r | |
406 | \r | |
407 | **/\r | |
408 | EFI_DEVICE_PATH_PROTOCOL *\r | |
409 | EFIAPI\r | |
410 | DuplicateDevicePath (\r | |
411 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
412 | )\r | |
413 | {\r | |
414 | return mDevicePathLibDevicePathUtilities->DuplicateDevicePath (DevicePath);\r | |
415 | }\r | |
416 | \r | |
417 | /**\r | |
418 | Creates a new device path by appending a second device path to a first device path.\r | |
419 | \r | |
420 | This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r | |
421 | FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from\r | |
422 | SecondDevicePath is retained. The newly created device path is returned. \r | |
423 | If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned. \r | |
424 | If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned. \r | |
425 | If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r | |
426 | returned. \r | |
427 | If there is not enough memory for the newly allocated buffer, then NULL is returned.\r | |
428 | The memory for the new device path is allocated from EFI boot services memory. It is the\r | |
429 | responsibility of the caller to free the memory allocated.\r | |
430 | \r | |
431 | @param FirstDevicePath A pointer to a device path data structure.\r | |
432 | @param SecondDevicePath A pointer to a device path data structure.\r | |
433 | \r | |
434 | @retval NULL If there is not enough memory for the newly allocated buffer.\r | |
435 | @retval NULL If FirstDevicePath or SecondDevicePath is invalid.\r | |
436 | @retval Others A pointer to the new device path if success.\r | |
437 | Or a copy an end-of-device-path if both FirstDevicePath and \r | |
438 | SecondDevicePath are NULL.\r | |
439 | \r | |
440 | **/\r | |
441 | EFI_DEVICE_PATH_PROTOCOL *\r | |
442 | EFIAPI\r | |
443 | AppendDevicePath (\r | |
444 | IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r | |
445 | IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r | |
446 | )\r | |
447 | {\r | |
448 | return mDevicePathLibDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);\r | |
449 | }\r | |
450 | \r | |
451 | /**\r | |
452 | Creates a new path by appending the device node to the device path.\r | |
453 | \r | |
454 | This function creates a new device path by appending a copy of the device node \r | |
455 | specified by DevicePathNode to a copy of the device path specified by DevicePath \r | |
456 | in an allocated buffer.\r | |
457 | The end-of-device-path device node is moved after the end of the appended device node.\r | |
458 | If DevicePathNode is NULL then a copy of DevicePath is returned.\r | |
459 | If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device \r | |
460 | path device node is returned.\r | |
461 | If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path \r | |
462 | device node is returned.\r | |
463 | If there is not enough memory to allocate space for the new device path, then \r | |
464 | NULL is returned. \r | |
465 | The memory is allocated from EFI boot services memory. It is the responsibility \r | |
466 | of the caller to free the memory allocated.\r | |
467 | \r | |
468 | @param DevicePath A pointer to a device path data structure.\r | |
469 | @param DevicePathNode A pointer to a single device path node.\r | |
470 | \r | |
471 | @retval NULL If there is not enough memory for the new device path.\r | |
472 | @retval Others A pointer to the new device path if success.\r | |
473 | A copy of DevicePathNode followed by an end-of-device-path node \r | |
474 | if both FirstDevicePath and SecondDevicePath are NULL.\r | |
475 | A copy of an end-of-device-path node if both FirstDevicePath \r | |
476 | and SecondDevicePath are NULL.\r | |
477 | \r | |
478 | **/\r | |
479 | EFI_DEVICE_PATH_PROTOCOL *\r | |
480 | EFIAPI\r | |
481 | AppendDevicePathNode (\r | |
482 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
483 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r | |
484 | )\r | |
485 | {\r | |
486 | return mDevicePathLibDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode);\r | |
487 | }\r | |
488 | \r | |
489 | /**\r | |
490 | Creates a new device path by appending the specified device path instance to \r | |
491 | the specified device path.\r | |
492 | \r | |
493 | This function creates a new device path by appending a copy of the device path \r | |
494 | instance specified by DevicePathInstance to a copy of the device path specified \r | |
495 | by DevicePath in a allocated buffer.\r | |
496 | The end-of-device-path device node is moved after the end of the appended device \r | |
497 | path instance and a new end-of-device-path-instance node is inserted between. \r | |
498 | If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r | |
499 | If DevicePathInstance is NULL, then NULL is returned.\r | |
500 | If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r | |
501 | If there is not enough memory to allocate space for the new device path, then \r | |
502 | NULL is returned. \r | |
503 | The memory is allocated from EFI boot services memory. It is the responsibility \r | |
504 | of the caller to free the memory allocated.\r | |
505 | \r | |
506 | @param DevicePath A pointer to a device path data structure.\r | |
507 | @param DevicePathInstance A pointer to a device path instance.\r | |
508 | \r | |
509 | @return A pointer to the new device path.\r | |
510 | \r | |
511 | **/\r | |
512 | EFI_DEVICE_PATH_PROTOCOL *\r | |
513 | EFIAPI\r | |
514 | AppendDevicePathInstance (\r | |
515 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r | |
516 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r | |
517 | )\r | |
518 | {\r | |
519 | return mDevicePathLibDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);\r | |
520 | }\r | |
521 | \r | |
522 | /**\r | |
523 | Creates a copy of the current device path instance and returns a pointer to the \r | |
524 | next device path instance.\r | |
525 | \r | |
526 | This function creates a copy of the current device path instance. It also updates \r | |
527 | DevicePath to point to the next device path instance in the device path (or NULL \r | |
528 | if no more) and updates Size to hold the size of the device path instance copy.\r | |
529 | If DevicePath is NULL, then NULL is returned.\r | |
530 | If there is not enough memory to allocate space for the new device path, then \r | |
531 | NULL is returned. \r | |
532 | The memory is allocated from EFI boot services memory. It is the responsibility \r | |
533 | of the caller to free the memory allocated.\r | |
534 | If Size is NULL, then ASSERT().\r | |
535 | \r | |
536 | @param DevicePath On input, this holds the pointer to the current \r | |
537 | device path instance. On output, this holds \r | |
538 | the pointer to the next device path instance \r | |
539 | or NULL if there are no more device path\r | |
540 | instances in the device path pointer to a \r | |
541 | device path data structure.\r | |
542 | @param Size On output, this holds the size of the device \r | |
543 | path instance, in bytes or zero, if DevicePath \r | |
544 | is NULL.\r | |
545 | \r | |
546 | @return A pointer to the current device path instance.\r | |
547 | \r | |
548 | **/\r | |
549 | EFI_DEVICE_PATH_PROTOCOL *\r | |
550 | EFIAPI\r | |
551 | GetNextDevicePathInstance (\r | |
552 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r | |
553 | OUT UINTN *Size\r | |
554 | )\r | |
555 | {\r | |
556 | ASSERT (Size != NULL);\r | |
557 | return mDevicePathLibDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);\r | |
558 | }\r | |
559 | \r | |
560 | /**\r | |
561 | Creates a device node.\r | |
562 | \r | |
563 | This function creates a new device node in a newly allocated buffer of size \r | |
564 | NodeLength and initializes the device path node header with NodeType and NodeSubType. \r | |
565 | The new device path node is returned.\r | |
566 | If NodeLength is smaller than a device path header, then NULL is returned. \r | |
567 | If there is not enough memory to allocate space for the new device path, then \r | |
568 | NULL is returned. \r | |
569 | The memory is allocated from EFI boot services memory. It is the responsibility \r | |
570 | of the caller to\r | |
571 | free the memory allocated.\r | |
572 | \r | |
573 | @param NodeType The device node type for the new device node.\r | |
574 | @param NodeSubType The device node sub-type for the new device node.\r | |
575 | @param NodeLength The length of the new device node.\r | |
576 | \r | |
577 | @return The new device path.\r | |
578 | \r | |
579 | **/\r | |
580 | EFI_DEVICE_PATH_PROTOCOL *\r | |
581 | EFIAPI\r | |
582 | CreateDeviceNode (\r | |
583 | IN UINT8 NodeType,\r | |
584 | IN UINT8 NodeSubType,\r | |
585 | IN UINT16 NodeLength\r | |
586 | )\r | |
587 | {\r | |
588 | return mDevicePathLibDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);\r | |
589 | }\r | |
590 | \r | |
591 | /**\r | |
592 | Determines if a device path is single or multi-instance.\r | |
593 | \r | |
594 | This function returns TRUE if the device path specified by DevicePath is\r | |
595 | multi-instance.\r | |
596 | Otherwise, FALSE is returned.\r | |
597 | If DevicePath is NULL or invalid, then FALSE is returned.\r | |
598 | \r | |
599 | @param DevicePath A pointer to a device path data structure.\r | |
600 | \r | |
601 | @retval TRUE DevicePath is multi-instance.\r | |
602 | @retval FALSE DevicePath is not multi-instance, or DevicePath \r | |
603 | is NULL or invalid.\r | |
604 | \r | |
605 | **/\r | |
606 | BOOLEAN\r | |
607 | EFIAPI\r | |
608 | IsDevicePathMultiInstance (\r | |
609 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
610 | )\r | |
611 | {\r | |
612 | return mDevicePathLibDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);\r | |
613 | }\r | |
614 | \r | |
615 | /**\r | |
616 | Retrieves the device path protocol from a handle.\r | |
617 | \r | |
618 | This function returns the device path protocol from the handle specified by Handle. \r | |
619 | If Handle is NULL or Handle does not contain a device path protocol, then NULL \r | |
620 | is returned.\r | |
621 | \r | |
622 | @param Handle The handle from which to retrieve the device \r | |
623 | path protocol.\r | |
624 | \r | |
625 | @return The device path protocol from the handle specified by Handle.\r | |
626 | \r | |
627 | **/\r | |
628 | EFI_DEVICE_PATH_PROTOCOL *\r | |
629 | EFIAPI\r | |
630 | DevicePathFromHandle (\r | |
631 | IN EFI_HANDLE Handle\r | |
632 | )\r | |
633 | {\r | |
634 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
635 | EFI_STATUS Status;\r | |
636 | \r | |
637 | Status = gBS->HandleProtocol (\r | |
638 | Handle,\r | |
639 | &gEfiDevicePathProtocolGuid,\r | |
640 | (VOID *) &DevicePath\r | |
641 | );\r | |
642 | if (EFI_ERROR (Status)) {\r | |
643 | DevicePath = NULL;\r | |
644 | }\r | |
645 | return DevicePath;\r | |
646 | }\r | |
647 | \r | |
648 | /**\r | |
649 | Allocates a device path for a file and appends it to an existing device path.\r | |
650 | \r | |
651 | If Device is a valid device handle that contains a device path protocol, then \r | |
652 | a device path for the file specified by FileName is allocated and appended to \r | |
653 | the device path associated with the handle Device. The allocated device path \r | |
654 | is returned. If Device is NULL or Device is a handle that does not support the \r | |
655 | device path protocol, then a device path containing a single device path node \r | |
656 | for the file specified by FileName is allocated and returned.\r | |
657 | The memory for the new device path is allocated from EFI boot services memory. \r | |
658 | It is the responsibility of the caller to free the memory allocated.\r | |
659 | \r | |
660 | If FileName is NULL, then ASSERT().\r | |
661 | If FileName is not aligned on a 16-bit boundary, then ASSERT().\r | |
662 | \r | |
663 | @param Device A pointer to a device handle. This parameter \r | |
664 | is optional and may be NULL.\r | |
665 | @param FileName A pointer to a Null-terminated Unicode string.\r | |
666 | \r | |
667 | @return The allocated device path.\r | |
668 | \r | |
669 | **/\r | |
670 | EFI_DEVICE_PATH_PROTOCOL *\r | |
671 | EFIAPI\r | |
672 | FileDevicePath (\r | |
673 | IN EFI_HANDLE Device, OPTIONAL\r | |
674 | IN CONST CHAR16 *FileName\r | |
675 | )\r | |
676 | {\r | |
677 | UINTN Size;\r | |
678 | FILEPATH_DEVICE_PATH *FilePath;\r | |
679 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
680 | EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;\r | |
681 | \r | |
682 | DevicePath = NULL;\r | |
683 | \r | |
684 | Size = StrSize (FileName);\r | |
685 | FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);\r | |
686 | if (FileDevicePath != NULL) {\r | |
687 | FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;\r | |
688 | FilePath->Header.Type = MEDIA_DEVICE_PATH;\r | |
689 | FilePath->Header.SubType = MEDIA_FILEPATH_DP;\r | |
690 | CopyMem (&FilePath->PathName, FileName, Size);\r | |
691 | SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);\r | |
692 | SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));\r | |
693 | \r | |
694 | if (Device != NULL) {\r | |
695 | DevicePath = DevicePathFromHandle (Device);\r | |
696 | }\r | |
697 | \r | |
698 | DevicePath = AppendDevicePath (DevicePath, FileDevicePath);\r | |
699 | FreePool (FileDevicePath);\r | |
700 | }\r | |
701 | \r | |
702 | return DevicePath;\r | |
703 | }\r | |
704 | \r | |
705 | /**\r | |
706 | Locate and return the protocol instance identified by the ProtocolGuid.\r | |
707 | \r | |
708 | @param ProtocolGuid The GUID of the protocol.\r | |
709 | \r | |
710 | @return A pointer to the protocol instance or NULL when absent.\r | |
711 | **/\r | |
712 | VOID *\r | |
713 | UefiDevicePathLibLocateProtocol (\r | |
714 | EFI_GUID *ProtocolGuid\r | |
715 | )\r | |
716 | {\r | |
717 | EFI_STATUS Status;\r | |
718 | VOID *Protocol;\r | |
719 | Status = gBS->LocateProtocol (\r | |
720 | ProtocolGuid,\r | |
721 | NULL,\r | |
722 | (VOID**) &Protocol\r | |
723 | );\r | |
724 | if (EFI_ERROR (Status)) {\r | |
725 | return NULL;\r | |
726 | } else {\r | |
727 | return Protocol;\r | |
728 | }\r | |
729 | }\r | |
730 | \r | |
731 | /**\r | |
732 | Converts a device node to its string representation.\r | |
733 | \r | |
734 | @param DeviceNode A Pointer to the device node to be converted.\r | |
735 | @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r | |
736 | of the display node is used, where applicable. If DisplayOnly\r | |
737 | is FALSE, then the longer text representation of the display node\r | |
738 | is used.\r | |
739 | @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r | |
740 | representation for a device node can be used, where applicable.\r | |
741 | \r | |
742 | @return A pointer to the allocated text representation of the device node or NULL if DeviceNode\r | |
743 | is NULL or there was insufficient memory.\r | |
744 | \r | |
745 | **/\r | |
746 | CHAR16 *\r | |
747 | EFIAPI\r | |
748 | ConvertDeviceNodeToText (\r | |
749 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,\r | |
750 | IN BOOLEAN DisplayOnly,\r | |
751 | IN BOOLEAN AllowShortcuts\r | |
752 | )\r | |
753 | {\r | |
754 | if (mDevicePathLibDevicePathToText == NULL) {\r | |
755 | mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);\r | |
756 | }\r | |
757 | if (mDevicePathLibDevicePathToText != NULL) {\r | |
758 | return mDevicePathLibDevicePathToText->ConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);\r | |
759 | } else {\r | |
760 | return NULL;\r | |
761 | }\r | |
762 | }\r | |
763 | \r | |
764 | /**\r | |
765 | Converts a device path to its text representation.\r | |
766 | \r | |
767 | @param DevicePath A Pointer to the device to be converted.\r | |
768 | @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r | |
769 | of the display node is used, where applicable. If DisplayOnly\r | |
770 | is FALSE, then the longer text representation of the display node\r | |
771 | is used.\r | |
772 | @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r | |
773 | representation for a device node can be used, where applicable.\r | |
774 | \r | |
775 | @return A pointer to the allocated text representation of the device path or\r | |
776 | NULL if DeviceNode is NULL or there was insufficient memory.\r | |
777 | \r | |
778 | **/\r | |
779 | CHAR16 *\r | |
780 | EFIAPI\r | |
781 | ConvertDevicePathToText (\r | |
782 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
783 | IN BOOLEAN DisplayOnly,\r | |
784 | IN BOOLEAN AllowShortcuts\r | |
785 | )\r | |
786 | {\r | |
787 | if (mDevicePathLibDevicePathToText == NULL) {\r | |
788 | mDevicePathLibDevicePathToText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathToTextProtocolGuid);\r | |
789 | }\r | |
790 | if (mDevicePathLibDevicePathToText != NULL) {\r | |
791 | return mDevicePathLibDevicePathToText->ConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);\r | |
792 | } else {\r | |
793 | return NULL;\r | |
794 | }\r | |
795 | }\r | |
796 | \r | |
797 | /**\r | |
798 | Convert text to the binary representation of a device node.\r | |
799 | \r | |
800 | @param TextDeviceNode TextDeviceNode points to the text representation of a device\r | |
801 | node. Conversion starts with the first character and continues\r | |
802 | until the first non-device node character.\r | |
803 | \r | |
804 | @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r | |
805 | insufficient memory or text unsupported.\r | |
806 | \r | |
807 | **/\r | |
808 | EFI_DEVICE_PATH_PROTOCOL *\r | |
809 | EFIAPI\r | |
810 | ConvertTextToDeviceNode (\r | |
811 | IN CONST CHAR16 *TextDeviceNode\r | |
812 | )\r | |
813 | {\r | |
814 | if (mDevicePathLibDevicePathFromText == NULL) {\r | |
815 | mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);\r | |
816 | }\r | |
817 | if (mDevicePathLibDevicePathFromText != NULL) {\r | |
818 | return mDevicePathLibDevicePathFromText->ConvertTextToDeviceNode (TextDeviceNode);\r | |
819 | } else {\r | |
820 | return NULL;\r | |
821 | }\r | |
822 | }\r | |
823 | \r | |
824 | /**\r | |
825 | Convert text to the binary representation of a device path.\r | |
826 | \r | |
827 | \r | |
828 | @param TextDevicePath TextDevicePath points to the text representation of a device\r | |
829 | path. Conversion starts with the first character and continues\r | |
830 | until the first non-device node character.\r | |
831 | \r | |
832 | @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r | |
833 | there was insufficient memory.\r | |
834 | \r | |
835 | **/\r | |
836 | EFI_DEVICE_PATH_PROTOCOL *\r | |
837 | EFIAPI\r | |
838 | ConvertTextToDevicePath (\r | |
839 | IN CONST CHAR16 *TextDevicePath\r | |
840 | )\r | |
841 | {\r | |
842 | if (mDevicePathLibDevicePathFromText == NULL) {\r | |
843 | mDevicePathLibDevicePathFromText = UefiDevicePathLibLocateProtocol (&gEfiDevicePathFromTextProtocolGuid);\r | |
844 | }\r | |
845 | if (mDevicePathLibDevicePathFromText != NULL) {\r | |
846 | return mDevicePathLibDevicePathFromText->ConvertTextToDevicePath (TextDevicePath);\r | |
847 | } else {\r | |
848 | return NULL;\r | |
849 | }\r | |
850 | }\r | |
851 | \r |