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