[efi] Generalise snpnet_dev_info() to efi_device_info()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
b71e93bb71
commit
b9a5ff2b03
|
@ -30,7 +30,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#include <ipxe/efi/efi.h>
|
#include <ipxe/efi/efi.h>
|
||||||
#include <ipxe/efi/Protocol/SimpleNetwork.h>
|
#include <ipxe/efi/Protocol/SimpleNetwork.h>
|
||||||
#include <ipxe/efi/efi_driver.h>
|
#include <ipxe/efi/efi_driver.h>
|
||||||
#include <ipxe/efi/efi_pci.h>
|
|
||||||
#include <ipxe/efi/efi_utils.h>
|
#include <ipxe/efi/efi_utils.h>
|
||||||
#include "snpnet.h"
|
#include "snpnet.h"
|
||||||
|
|
||||||
|
@ -409,64 +408,6 @@ static struct net_device_operations snpnet_operations = {
|
||||||
.poll = snpnet_poll,
|
.poll = snpnet_poll,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Get underlying PCI device information
|
|
||||||
*
|
|
||||||
* @v efidev EFI device
|
|
||||||
* @v dev Generic device to fill in
|
|
||||||
* @ret rc Return status code
|
|
||||||
*/
|
|
||||||
static int snpnet_pci_info ( struct efi_device *efidev, struct device *dev ) {
|
|
||||||
EFI_HANDLE device = efidev->device;
|
|
||||||
EFI_HANDLE pci_device;
|
|
||||||
struct pci_device pci;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
/* Find parent PCI device */
|
|
||||||
if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid,
|
|
||||||
&pci_device ) ) != 0 ) {
|
|
||||||
DBGC ( device, "SNP %p %s is not a PCI device: %s\n",
|
|
||||||
device, efi_handle_name ( device ), strerror ( rc ) );
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get PCI device information */
|
|
||||||
if ( ( rc = efipci_info ( pci_device, &pci ) ) != 0 ) {
|
|
||||||
DBGC ( device, "SNP %p %s could not get PCI information: %s\n",
|
|
||||||
device, efi_handle_name ( device ), strerror ( rc ) );
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Populate SNP device information */
|
|
||||||
memcpy ( &dev->desc, &pci.dev.desc, sizeof ( dev->desc ) );
|
|
||||||
snprintf ( dev->name, sizeof ( dev->name ), "SNP-%s", pci.dev.name );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get underlying device information
|
|
||||||
*
|
|
||||||
* @v efidev EFI device
|
|
||||||
* @v dev Generic device to fill in
|
|
||||||
*/
|
|
||||||
static void snpnet_dev_info ( struct efi_device *efidev, struct device *dev ) {
|
|
||||||
EFI_HANDLE device = efidev->device;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
/* Try getting underlying PCI device information */
|
|
||||||
if ( ( rc = snpnet_pci_info ( efidev, dev ) ) == 0 )
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* If we cannot get any underlying device information, fall
|
|
||||||
* back to providing information about the EFI handle.
|
|
||||||
*/
|
|
||||||
DBGC ( device, "SNP %p %s could not get underlying device "
|
|
||||||
"information\n", device, efi_handle_name ( device ) );
|
|
||||||
dev->desc.bus_type = BUS_TYPE_EFI;
|
|
||||||
snprintf ( dev->name, sizeof ( dev->name ), "SNP-%p", device );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach driver to device
|
* Attach driver to device
|
||||||
*
|
*
|
||||||
|
@ -511,7 +452,7 @@ int snpnet_start ( struct efi_device *efidev ) {
|
||||||
efidev_set_drvdata ( efidev, netdev );
|
efidev_set_drvdata ( efidev, netdev );
|
||||||
|
|
||||||
/* Populate underlying device information */
|
/* Populate underlying device information */
|
||||||
snpnet_dev_info ( efidev, &snp->dev );
|
efi_device_info ( device, "SNP", &snp->dev );
|
||||||
snp->dev.driver_name = "SNP";
|
snp->dev.driver_name = "SNP";
|
||||||
snp->dev.parent = &efidev->dev;
|
snp->dev.parent = &efidev->dev;
|
||||||
list_add ( &snp->dev.siblings, &efidev->dev.children );
|
list_add ( &snp->dev.siblings, &efidev->dev.children );
|
||||||
|
|
|
@ -11,11 +11,15 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#include <ipxe/efi/efi.h>
|
#include <ipxe/efi/efi.h>
|
||||||
#include <ipxe/efi/Protocol/DevicePath.h>
|
#include <ipxe/efi/Protocol/DevicePath.h>
|
||||||
|
|
||||||
|
struct device;
|
||||||
|
|
||||||
extern EFI_DEVICE_PATH_PROTOCOL *
|
extern EFI_DEVICE_PATH_PROTOCOL *
|
||||||
efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
|
efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
|
||||||
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 );
|
||||||
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,
|
||||||
|
struct device *dev );
|
||||||
|
|
||||||
#endif /* _IPXE_EFI_UTILS_H */
|
#endif /* _IPXE_EFI_UTILS_H */
|
||||||
|
|
|
@ -19,9 +19,11 @@
|
||||||
|
|
||||||
FILE_LICENCE ( GPL2_OR_LATER );
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#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_pci.h>
|
||||||
#include <ipxe/efi/efi_utils.h>
|
#include <ipxe/efi/efi_utils.h>
|
||||||
|
|
||||||
/** @file
|
/** @file
|
||||||
|
@ -152,3 +154,65 @@ void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child ) {
|
||||||
DBGC2 ( parent, " %p %s\n",
|
DBGC2 ( parent, " %p %s\n",
|
||||||
child, efi_handle_name ( child ) );
|
child, efi_handle_name ( child ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get underlying PCI device information
|
||||||
|
*
|
||||||
|
* @v device EFI device handle
|
||||||
|
* @v prefix Device name prefix
|
||||||
|
* @v dev Generic device to fill in
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
static int efi_pci_info ( EFI_HANDLE device, const char *prefix,
|
||||||
|
struct device *dev ) {
|
||||||
|
EFI_HANDLE pci_device;
|
||||||
|
struct pci_device pci;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Find parent PCI device */
|
||||||
|
if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid,
|
||||||
|
&pci_device ) ) != 0 ) {
|
||||||
|
DBGC ( device, "EFIDEV %p %s is not a PCI device: %s\n",
|
||||||
|
device, efi_handle_name ( device ), strerror ( rc ) );
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get PCI device information */
|
||||||
|
if ( ( rc = efipci_info ( pci_device, &pci ) ) != 0 ) {
|
||||||
|
DBGC ( device, "EFIDEV %p %s could not get PCI information: "
|
||||||
|
"%s\n", device, efi_handle_name ( device ),
|
||||||
|
strerror ( rc ) );
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Populate device information */
|
||||||
|
memcpy ( &dev->desc, &pci.dev.desc, sizeof ( dev->desc ) );
|
||||||
|
snprintf ( dev->name, sizeof ( dev->name ), "%s-%s",
|
||||||
|
prefix, pci.dev.name );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get underlying device information
|
||||||
|
*
|
||||||
|
* @v device EFI device handle
|
||||||
|
* @v prefix Device name prefix
|
||||||
|
* @v dev Generic device to fill in
|
||||||
|
*/
|
||||||
|
void efi_device_info ( EFI_HANDLE device, const char *prefix,
|
||||||
|
struct device *dev ) {
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Try getting underlying PCI device information */
|
||||||
|
if ( ( rc = efi_pci_info ( device, prefix, dev ) ) == 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* If we cannot get any underlying device information, fall
|
||||||
|
* back to providing information about the EFI handle.
|
||||||
|
*/
|
||||||
|
DBGC ( device, "EFIDEV %p %s could not get underlying device "
|
||||||
|
"information\n", device, efi_handle_name ( device ) );
|
||||||
|
dev->desc.bus_type = BUS_TYPE_EFI;
|
||||||
|
snprintf ( dev->name, sizeof ( dev->name ), "%s-%p", prefix, device );
|
||||||
|
}
|
||||||
|
|
Reference in New Issue