mirror of
https://github.com/ipxe/ipxe
synced 2025-12-28 02:28:57 +03:00
[efi] Extend efi_locate_device() to allow searching up the device path
Extend the functionality of efi_locate_device() to allow callers to find instances of the protocol that may exist further up the device path. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -222,7 +222,7 @@ static int nii_pci_open ( struct nii_nic *nii ) {
|
|||||||
|
|
||||||
/* Locate PCI I/O protocol */
|
/* Locate PCI I/O protocol */
|
||||||
if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid,
|
if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid,
|
||||||
&pci_device ) ) != 0 ) {
|
&pci_device, 0 ) ) != 0 ) {
|
||||||
DBGC ( nii, "NII %s could not locate PCI I/O protocol: %s\n",
|
DBGC ( nii, "NII %s could not locate PCI I/O protocol: %s\n",
|
||||||
nii->dev.name, strerror ( rc ) );
|
nii->dev.name, strerror ( rc ) );
|
||||||
goto err_locate;
|
goto err_locate;
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ static int chained_locate ( struct chained_protocol *chained ) {
|
|||||||
|
|
||||||
/* Locate handle supporting this protocol */
|
/* Locate handle supporting this protocol */
|
||||||
if ( ( rc = efi_locate_device ( device, chained->protocol,
|
if ( ( rc = efi_locate_device ( device, chained->protocol,
|
||||||
&parent ) ) != 0 ) {
|
&parent, 0 ) ) != 0 ) {
|
||||||
DBGC ( device, "CHAINED %s does not support %s: %s\n",
|
DBGC ( device, "CHAINED %s does not support %s: %s\n",
|
||||||
efi_handle_name ( device ),
|
efi_handle_name ( device ),
|
||||||
efi_guid_ntoa ( chained->protocol ), strerror ( rc ) );
|
efi_guid_ntoa ( chained->protocol ), strerror ( rc ) );
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||||||
struct device;
|
struct device;
|
||||||
|
|
||||||
extern int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
|
extern int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
|
||||||
EFI_HANDLE *parent );
|
EFI_HANDLE *parent, unsigned int skip );
|
||||||
extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child );
|
extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child );
|
||||||
extern void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child );
|
extern void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child );
|
||||||
extern void efi_device_info ( EFI_HANDLE device, const char *prefix,
|
extern void efi_device_info ( EFI_HANDLE device, const char *prefix,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ipxe/efi/efi.h>
|
#include <ipxe/efi/efi.h>
|
||||||
|
#include <ipxe/efi/efi_path.h>
|
||||||
#include <ipxe/efi/efi_pci.h>
|
#include <ipxe/efi/efi_pci.h>
|
||||||
#include <ipxe/efi/efi_utils.h>
|
#include <ipxe/efi/efi_utils.h>
|
||||||
|
|
||||||
@@ -38,23 +39,26 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
|||||||
* @v device EFI device handle
|
* @v device EFI device handle
|
||||||
* @v protocol Protocol GUID
|
* @v protocol Protocol GUID
|
||||||
* @v parent Parent EFI device handle to fill in
|
* @v parent Parent EFI device handle to fill in
|
||||||
|
* @v skip Number of protocol-supporting parent devices to skip
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
|
int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
|
||||||
EFI_HANDLE *parent ) {
|
EFI_HANDLE *parent, unsigned int skip ) {
|
||||||
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
||||||
union {
|
union {
|
||||||
EFI_DEVICE_PATH_PROTOCOL *path;
|
EFI_DEVICE_PATH_PROTOCOL *path;
|
||||||
void *interface;
|
void *interface;
|
||||||
} path;
|
} u;
|
||||||
EFI_DEVICE_PATH_PROTOCOL *devpath;
|
EFI_DEVICE_PATH_PROTOCOL *path;
|
||||||
|
EFI_DEVICE_PATH_PROTOCOL *end;
|
||||||
|
size_t len;
|
||||||
EFI_STATUS efirc;
|
EFI_STATUS efirc;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Get device path */
|
/* Get device path */
|
||||||
if ( ( efirc = bs->OpenProtocol ( device,
|
if ( ( efirc = bs->OpenProtocol ( device,
|
||||||
&efi_device_path_protocol_guid,
|
&efi_device_path_protocol_guid,
|
||||||
&path.interface,
|
&u.interface,
|
||||||
efi_image_handle, device,
|
efi_image_handle, device,
|
||||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
|
||||||
rc = -EEFI ( efirc );
|
rc = -EEFI ( efirc );
|
||||||
@@ -62,22 +66,46 @@ int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
|
|||||||
efi_handle_name ( device ), strerror ( rc ) );
|
efi_handle_name ( device ), strerror ( rc ) );
|
||||||
goto err_open_device_path;
|
goto err_open_device_path;
|
||||||
}
|
}
|
||||||
devpath = path.path;
|
|
||||||
|
/* Create modifiable copy of device path */
|
||||||
|
len = ( efi_path_len ( u.path ) + sizeof ( EFI_DEVICE_PATH_PROTOCOL ));
|
||||||
|
path = malloc ( len );
|
||||||
|
if ( ! path ) {
|
||||||
|
rc = -ENOMEM;
|
||||||
|
goto err_alloc_path;
|
||||||
|
}
|
||||||
|
memcpy ( path, u.path, len );
|
||||||
|
|
||||||
|
/* Locate parent device(s) */
|
||||||
|
while ( 1 ) {
|
||||||
|
|
||||||
/* Check for presence of specified protocol */
|
/* Check for presence of specified protocol */
|
||||||
if ( ( efirc = bs->LocateDevicePath ( protocol, &devpath,
|
end = path;
|
||||||
|
if ( ( efirc = bs->LocateDevicePath ( protocol, &end,
|
||||||
parent ) ) != 0 ) {
|
parent ) ) != 0 ) {
|
||||||
rc = -EEFI ( efirc );
|
rc = -EEFI ( efirc );
|
||||||
DBGC ( device, "EFIDEV %s has no parent supporting %s: %s\n",
|
DBGC ( device, "EFIDEV %s has no parent supporting "
|
||||||
efi_handle_name ( device ),
|
"%s: %s\n", efi_devpath_text ( path ),
|
||||||
efi_guid_ntoa ( protocol ), strerror ( rc ) );
|
efi_guid_ntoa ( protocol ), strerror ( rc ) );
|
||||||
goto err_locate_protocol;
|
goto err_locate_protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Stop if we have skipped the requested number of devices */
|
||||||
|
if ( ! skip-- )
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Trim device path */
|
||||||
|
efi_path_terminate ( end );
|
||||||
|
end = efi_path_prev ( path, end );
|
||||||
|
efi_path_terminate ( end );
|
||||||
|
}
|
||||||
|
|
||||||
/* Success */
|
/* Success */
|
||||||
rc = 0;
|
rc = 0;
|
||||||
|
|
||||||
err_locate_protocol:
|
err_locate_protocol:
|
||||||
|
free ( path );
|
||||||
|
err_alloc_path:
|
||||||
bs->CloseProtocol ( device, &efi_device_path_protocol_guid,
|
bs->CloseProtocol ( device, &efi_device_path_protocol_guid,
|
||||||
efi_image_handle, device );
|
efi_image_handle, device );
|
||||||
err_open_device_path:
|
err_open_device_path:
|
||||||
@@ -150,7 +178,7 @@ static int efi_pci_info ( EFI_HANDLE device, const char *prefix,
|
|||||||
|
|
||||||
/* Find parent PCI device */
|
/* Find parent PCI device */
|
||||||
if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid,
|
if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid,
|
||||||
&pci_device ) ) != 0 ) {
|
&pci_device, 0 ) ) != 0 ) {
|
||||||
DBGC ( device, "EFIDEV %s is not a PCI device: %s\n",
|
DBGC ( device, "EFIDEV %s is not a PCI device: %s\n",
|
||||||
efi_handle_name ( device ), strerror ( rc ) );
|
efi_handle_name ( device ), strerror ( rc ) );
|
||||||
return rc;
|
return rc;
|
||||||
|
|||||||
Reference in New Issue
Block a user