3 Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Device Path services. The thing to remember is device paths are built out of
19 nodes. The device path is terminated by an end node that is length
20 sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
23 The only place where multi-instance device paths are supported is in
24 environment varibles. Multi-instance device paths should never be placed
30 #include "EfiDriverLib.h"
31 #include EFI_PROTOCOL_DEFINITION (DevicePath)
33 EFI_DEVICE_PATH_PROTOCOL
*
34 EfiDevicePathInstance (
35 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
41 Function retrieves the next device path instance from a device path data structure.
44 DevicePath - A pointer to a device path data structure.
46 Size - A pointer to the size of a device path instance in bytes.
50 This function returns a pointer to the current device path instance.
51 In addition, it returns the size in bytes of the current device path instance in Size,
52 and a pointer to the next device path instance in DevicePath.
53 If there are no more device path instances in DevicePath, then DevicePath will be set to NULL.
57 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
58 EFI_DEVICE_PATH_PROTOCOL
*ReturnValue
;
61 if (*DevicePath
== NULL
) {
70 // Find the end of the device path instance
72 DevPath
= *DevicePath
;
73 while (!IsDevicePathEndType (DevPath
)) {
74 DevPath
= NextDevicePathNode (DevPath
);
78 // Compute the size of the device path instance
81 *Size
= ((UINTN
) DevPath
- (UINTN
) (*DevicePath
)) + sizeof (EFI_DEVICE_PATH_PROTOCOL
);
85 // Make a copy and return the device path instance
87 Temp
= DevPath
->SubType
;
88 DevPath
->SubType
= END_ENTIRE_DEVICE_PATH_SUBTYPE
;
89 ReturnValue
= EfiDuplicateDevicePath (*DevicePath
);
90 DevPath
->SubType
= Temp
;
93 // If DevPath is the end of an entire device path, then another instance
94 // does not follow, so *DevicePath is set to NULL.
96 if (DevicePathSubType (DevPath
) == END_ENTIRE_DEVICE_PATH_SUBTYPE
) {
99 *DevicePath
= NextDevicePathNode (DevPath
);
106 EfiIsDevicePathMultiInstance (
107 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
112 Return TRUE is this is a multi instance device path.
115 DevicePath - A pointer to a device path data structure.
119 TRUE - If DevicePath is multi instance. FALSE - If DevicePath is not multi
124 EFI_DEVICE_PATH_PROTOCOL
*Node
;
126 if (DevicePath
== NULL
) {
131 while (!EfiIsDevicePathEnd (Node
)) {
132 if (EfiIsDevicePathEndInstance (Node
)) {
136 Node
= EfiNextDevicePathNode (Node
);
144 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
150 Calculate the space size of a device path.
154 DevicePath - A specified device path
162 EFI_DEVICE_PATH_PROTOCOL
*Start
;
164 if (DevicePath
== NULL
) {
169 // Search for the end of the device path structure
172 while (!EfiIsDevicePathEnd (DevicePath
)) {
173 DevicePath
= EfiNextDevicePathNode (DevicePath
);
177 // Compute the size and add back in the size of the end device path structure
179 return ((UINTN
) DevicePath
- (UINTN
) Start
) + sizeof (EFI_DEVICE_PATH_PROTOCOL
);
182 EFI_DEVICE_PATH_PROTOCOL
*
183 EfiDevicePathFromHandle (
190 Get the device path protocol interface installed on a specified handle.
194 Handle - a specified handle
198 The device path protocol interface installed on that handle.
202 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
205 gBS
->HandleProtocol (
207 &gEfiDevicePathProtocolGuid
,
213 EFI_DEVICE_PATH_PROTOCOL
*
214 EfiDuplicateDevicePath (
215 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
221 Duplicate a device path structure.
225 DevicePath - The device path to duplicated.
229 The duplicated device path.
233 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
236 if (DevicePath
== NULL
) {
243 Size
= EfiDevicePathSize (DevicePath
);
249 // Allocate space for duplicate device path
251 NewDevicePath
= EfiLibAllocateCopyPool (Size
, DevicePath
);
253 return NewDevicePath
;
256 EFI_DEVICE_PATH_PROTOCOL
*
257 EfiAppendDevicePath (
258 IN EFI_DEVICE_PATH_PROTOCOL
*Src1
,
259 IN EFI_DEVICE_PATH_PROTOCOL
*Src2
264 Function is used to append a Src1 and Src2 together.
267 Src1 - A pointer to a device path data structure.
269 Src2 - A pointer to a device path data structure.
273 A pointer to the new device path is returned.
274 NULL is returned if space for the new device path could not be allocated from pool.
275 It is up to the caller to free the memory used by Src1 and Src2 if they are no longer needed.
282 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
283 EFI_DEVICE_PATH_PROTOCOL
*SecondDevicePath
;
286 // If there's only 1 path, just duplicate it
289 ASSERT (!IsDevicePathUnpacked (Src2
));
290 return EfiDuplicateDevicePath (Src2
);
294 ASSERT (!IsDevicePathUnpacked (Src1
));
295 return EfiDuplicateDevicePath (Src1
);
299 // Allocate space for the combined device path. It only has one end node of
300 // length EFI_DEVICE_PATH_PROTOCOL
302 Size1
= EfiDevicePathSize (Src1
);
303 Size2
= EfiDevicePathSize (Src2
);
304 Size
= Size1
+ Size2
- sizeof (EFI_DEVICE_PATH_PROTOCOL
);
306 NewDevicePath
= EfiLibAllocateCopyPool (Size
, Src1
);
308 if (NewDevicePath
!= NULL
) {
311 // Over write Src1 EndNode and do the copy
313 SecondDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) ((CHAR8
*) NewDevicePath
+ (Size1
- sizeof (EFI_DEVICE_PATH_PROTOCOL
)));
314 EfiCopyMem (SecondDevicePath
, Src2
, Size2
);
317 return NewDevicePath
;
320 EFI_DEVICE_PATH_PROTOCOL
*
321 EfiAppendDevicePathNode (
322 IN EFI_DEVICE_PATH_PROTOCOL
*Src1
,
323 IN EFI_DEVICE_PATH_PROTOCOL
*Node
328 Function is used to append a device path node to the end of another device path.
331 Src1 - A pointer to a device path data structure.
333 Node - A pointer to a device path data structure.
336 This function returns a pointer to the new device path.
337 If there is not enough temporary pool memory available to complete this function,
338 then NULL is returned.
343 EFI_DEVICE_PATH_PROTOCOL
*Temp
;
344 EFI_DEVICE_PATH_PROTOCOL
*NextNode
;
345 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
349 // Build a Node that has a terminator on it
351 NodeLength
= DevicePathNodeLength (Node
);
353 Temp
= EfiLibAllocateCopyPool (NodeLength
+ sizeof (EFI_DEVICE_PATH_PROTOCOL
), Node
);
359 // Add and end device path node to convert Node to device path
361 NextNode
= NextDevicePathNode (Temp
);
362 SetDevicePathEndNode (NextNode
);
365 // Append device paths
367 NewDevicePath
= EfiAppendDevicePath (Src1
, Temp
);
368 gBS
->FreePool (Temp
);
369 return NewDevicePath
;
372 EFI_DEVICE_PATH_PROTOCOL
*
374 IN EFI_HANDLE Device OPTIONAL
,
381 This function allocates a device path for a file and appends it to an existiong
385 Device - A pointer to a device handle.
387 FileName - A pointer to a Null-terminated Unicodestring.
390 A device path contain the file name.
395 FILEPATH_DEVICE_PATH
*FilePath
;
396 EFI_DEVICE_PATH_PROTOCOL
*Eop
;
397 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
399 for (Size
= 0; FileName
[Size
] != 0; Size
++)
401 Size
= (Size
+ 1) * 2;
403 FilePath
= EfiLibAllocateZeroPool (Size
+ SIZE_OF_FILEPATH_DEVICE_PATH
+ sizeof (EFI_DEVICE_PATH_PROTOCOL
));
407 if (FilePath
!= NULL
) {
412 FilePath
->Header
.Type
= MEDIA_DEVICE_PATH
;
413 FilePath
->Header
.SubType
= MEDIA_FILEPATH_DP
;
414 SetDevicePathNodeLength (&FilePath
->Header
, Size
+ SIZE_OF_FILEPATH_DEVICE_PATH
);
415 EfiCopyMem (FilePath
->PathName
, FileName
, Size
);
416 Eop
= NextDevicePathNode (&FilePath
->Header
);
417 SetDevicePathEndNode (Eop
);
420 // Append file path to device's device path
423 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) FilePath
;
424 if (Device
!= NULL
) {
425 DevicePath
= EfiAppendDevicePath (
426 EfiDevicePathFromHandle (Device
),
430 gBS
->FreePool (FilePath
);
437 EFI_DEVICE_PATH_PROTOCOL
*
438 EfiAppendDevicePathInstance (
439 IN EFI_DEVICE_PATH_PROTOCOL
*Src
,
440 IN EFI_DEVICE_PATH_PROTOCOL
*Instance
446 Append a device path instance to another.
450 Src - The device path instance to be appended with.
451 Instance - The device path instance appending the other.
455 The contaction of these two.
460 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
465 return EfiDuplicateDevicePath (Instance
);
468 SrcSize
= EfiDevicePathSize (Src
);
469 InstanceSize
= EfiDevicePathSize (Instance
);
471 Ptr
= EfiLibAllocateCopyPool (SrcSize
+ InstanceSize
, Src
);
474 DevPath
= (EFI_DEVICE_PATH_PROTOCOL
*) Ptr
;
476 while (!IsDevicePathEnd (DevPath
)) {
477 DevPath
= NextDevicePathNode (DevPath
);
480 // Convert the End to an End Instance, since we are
481 // appending another instacne after this one its a good
484 DevPath
->SubType
= END_INSTANCE_DEVICE_PATH_SUBTYPE
;
486 DevPath
= NextDevicePathNode (DevPath
);
487 EfiCopyMem (DevPath
, Instance
, InstanceSize
);
490 return (EFI_DEVICE_PATH_PROTOCOL
*) Ptr
;
495 EfiInitializeFwVolDevicepathNode (
496 IN MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvDevicePathNode
,
497 IN EFI_GUID
*NameGuid
503 Initialize a Firmware Volume (FV) Media Device Path node.
505 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
506 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
507 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
508 device path is defined for PIWG extensions of device path. If the code
509 is compiled to conform with the UEFI 2.0 specification use the new device path
510 else use the old form for backwards compatability.
514 FvDevicePathNode - Pointer to a FV device path node to initialize
515 NameGuid - FV file name to use in FvDevicePathNode
524 // EFI Specification extension on Media Device Path. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH is adopted by UEFI later and added in UEFI2.10.
525 // In EdkCompatibility Package, we only support MEDIA_FW_VOL_FILEPATH_DEVICE_PATH that complies with
526 // EFI 1.10 and UEFI 2.10.
529 FvDevicePathNode
->Header
.Type
= MEDIA_DEVICE_PATH
;
530 FvDevicePathNode
->Header
.SubType
= MEDIA_FV_FILEPATH_DP
;
531 SetDevicePathNodeLength (&FvDevicePathNode
->Header
, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
));
533 EfiCopyMem (&FvDevicePathNode
->NameGuid
, NameGuid
, sizeof(EFI_GUID
));
538 EfiGetNameGuidFromFwVolDevicePathNode (
539 IN MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvDevicePathNode
545 Check to see if the Firmware Volume (FV) Media Device Path is valid.
547 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
548 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
549 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
550 device path is defined for PIWG extensions of device path. If the code
551 is compiled to conform with the UEFI 2.0 specification use the new device path
552 else use the old form for backwards compatability. The return value to this
553 function points to a location in FvDevicePathNode and it does not allocate
554 new memory for the GUID pointer that is returned.
558 FvDevicePathNode - Pointer to FV device path to check
562 NULL - FvDevicePathNode is not valid.
563 Other - FvDevicePathNode is valid and pointer to NameGuid was returned.
568 // EFI Specification extension on Media Device Path. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH is adopted by UEFI later and added in UEFI2.10.
569 // In EdkCompatibility Package, we only support MEDIA_FW_VOL_FILEPATH_DEVICE_PATH that complies with
570 // EFI 1.10 and UEFI 2.10.
572 if (DevicePathType (&FvDevicePathNode
->Header
) == MEDIA_DEVICE_PATH
&&
573 DevicePathSubType (&FvDevicePathNode
->Header
) == MEDIA_FV_FILEPATH_DP
) {
574 return &FvDevicePathNode
->NameGuid
;