summaryrefslogtreecommitdiffstats
path: root/src/interface
diff options
context:
space:
mode:
authorMichael Brown2014-09-30 19:06:13 +0200
committerMichael Brown2014-10-16 15:12:42 +0200
commitb9a5ff2b03b7354c9fafdca7e0e6c9b3da151f1c (patch)
treed8334055a33b009743b4b28334feb996bc97ade1 /src/interface
parent[efi] Free transmit ring entry before calling netdev_tx_complete() (diff)
downloadipxe-b9a5ff2b03b7354c9fafdca7e0e6c9b3da151f1c.tar.gz
ipxe-b9a5ff2b03b7354c9fafdca7e0e6c9b3da151f1c.tar.xz
ipxe-b9a5ff2b03b7354c9fafdca7e0e6c9b3da151f1c.zip
[efi] Generalise snpnet_dev_info() to efi_device_info()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/interface')
-rw-r--r--src/interface/efi/efi_utils.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/interface/efi/efi_utils.c b/src/interface/efi/efi_utils.c
index b4f07330..936ad48e 100644
--- a/src/interface/efi/efi_utils.c
+++ b/src/interface/efi/efi_utils.c
@@ -19,9 +19,11 @@
FILE_LICENCE ( GPL2_OR_LATER );
+#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/efi/efi.h>
+#include <ipxe/efi/efi_pci.h>
#include <ipxe/efi/efi_utils.h>
/** @file
@@ -152,3 +154,65 @@ void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child ) {
DBGC2 ( parent, " %p %s\n",
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 );
+}