]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Move abstract device path and handle functions to efi_utils.c
authorMichael Brown <mcb30@ipxe.org>
Wed, 6 Aug 2014 12:52:41 +0000 (13:52 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 6 Aug 2014 13:27:45 +0000 (14:27 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/image/efi_image.c
src/include/ipxe/efi/efi_driver.h
src/include/ipxe/efi/efi_utils.h [new file with mode: 0644]
src/include/ipxe/errfile.h
src/interface/efi/efi_debug.c
src/interface/efi/efi_driver.c
src/interface/efi/efi_snp.c
src/interface/efi/efi_utils.c [new file with mode: 0644]

index 613c9d923e826272f3ba26b8d22fec065e80d627..ce1d4b837a6da873d841c9955c48dd825e9a4b42 100644 (file)
@@ -26,7 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <ipxe/efi/efi_snp.h>
 #include <ipxe/efi/efi_download.h>
 #include <ipxe/efi/efi_file.h>
-#include <ipxe/efi/efi_driver.h>
+#include <ipxe/efi/efi_utils.h>
 #include <ipxe/efi/efi_strings.h>
 #include <ipxe/efi/efi_wrap.h>
 #include <ipxe/image.h>
index 1b890b0613a6083cbd36d519fec35d53c84765e9..e16a24daa53fc146394c09d90e91e8b0d096f42c 100644 (file)
@@ -82,11 +82,7 @@ static inline void * efidev_get_drvdata ( struct efi_device *efidev ) {
        return efidev->priv;
 }
 
-extern EFI_DEVICE_PATH_PROTOCOL *
-efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
 extern struct efi_device * efidev_parent ( struct device *dev );
-extern int efidev_child_add ( struct efi_device *efidev, EFI_HANDLE device );
-extern void efidev_child_del ( struct efi_device *efidev, EFI_HANDLE device );
 extern int efi_driver_install ( void );
 extern void efi_driver_uninstall ( void );
 extern int efi_driver_connect_all ( void );
diff --git a/src/include/ipxe/efi/efi_utils.h b/src/include/ipxe/efi/efi_utils.h
new file mode 100644 (file)
index 0000000..23972c7
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _IPXE_EFI_UTILS_H
+#define _IPXE_EFI_UTILS_H
+
+/** @file
+ *
+ * EFI utilities
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <ipxe/efi/efi.h>
+#include <ipxe/efi/Protocol/DevicePath.h>
+
+extern EFI_DEVICE_PATH_PROTOCOL *
+efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
+extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child );
+extern void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child );
+
+#endif /* _IPXE_EFI_UTILS_H */
index f3e21d4408342f1c40a23647bd743e8ff0a953a7..1029670ac84410f5ad0b28a8be98e9e2a2a31191 100644 (file)
@@ -305,6 +305,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #define ERRFILE_xenstore             ( ERRFILE_OTHER | 0x00420000 )
 #define ERRFILE_xenbus               ( ERRFILE_OTHER | 0x00430000 )
 #define ERRFILE_xengrant             ( ERRFILE_OTHER | 0x00440000 )
+#define ERRFILE_efi_utils            ( ERRFILE_OTHER | 0x00450000 )
 
 /** @} */
 
index 4cbd831c461020e7b8e20e6317f0a4915c1b52d1..4b8448cb0fb313be39b9cf24374004a1233e4115 100644 (file)
@@ -32,7 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <ipxe/uuid.h>
 #include <ipxe/base16.h>
 #include <ipxe/efi/efi.h>
-#include <ipxe/efi/efi_driver.h>
+#include <ipxe/efi/efi_utils.h>
 #include <ipxe/efi/Protocol/ComponentName.h>
 #include <ipxe/efi/Protocol/ComponentName2.h>
 #include <ipxe/efi/Protocol/DevicePathToText.h>
index 3a1945a5f2f62a1215c68a76cc1a3841edf309ab..ba7784cd7752141c78a3a615093c46b51e1104b3 100644 (file)
@@ -43,24 +43,6 @@ static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding;
 /** List of controlled EFI devices */
 static LIST_HEAD ( efi_devices );
 
-/**
- * Find end of device path
- *
- * @v path             Path to device
- * @ret path_end       End of device path
- */
-EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
-
-       while ( path->Type != END_DEVICE_PATH_TYPE ) {
-               path = ( ( ( void * ) path ) +
-                        /* There's this amazing new-fangled thing known as
-                         * a UINT16, but who wants to use one of those? */
-                        ( ( path->Length[1] << 8 ) | path->Length[0] ) );
-       }
-
-       return path;
-}
-
 /**
  * Find EFI device
  *
@@ -100,61 +82,6 @@ struct efi_device * efidev_parent ( struct device *dev ) {
        return efidev;
 }
 
-/**
- * Add EFI device as child of EFI device
- *
- * @v efidev           EFI device
- * @v device           EFI child device handle
- * @ret efirc          EFI status code
- */
-int efidev_child_add ( struct efi_device *efidev, EFI_HANDLE device ) {
-       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
-       void *devpath;
-       EFI_STATUS efirc;
-       int rc;
-
-       /* Re-open the device path protocol */
-       if ( ( efirc = bs->OpenProtocol ( efidev->device,
-                                         &efi_device_path_protocol_guid,
-                                         &devpath,
-                                         efi_image_handle, device,
-                                         EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
-                                         ) ) != 0 ) {
-               rc = -EEFI ( efirc );
-               DBGC ( efidev->device, "EFIDRV %p %s could not add child",
-                      efidev->device, efi_handle_name ( efidev->device ) );
-               DBGC ( efidev->device, " %p %s: %s\n", device,
-                      efi_handle_name ( device ), strerror ( rc ) );
-               DBGC_EFI_OPENERS ( efidev->device, efidev->device,
-                                  &efi_device_path_protocol_guid );
-               return rc;
-       }
-
-       DBGC2 ( efidev->device, "EFIDRV %p %s added child",
-               efidev->device, efi_handle_name ( efidev->device ) );
-       DBGC2 ( efidev->device, " %p %s\n", device, efi_handle_name ( device ));
-       return 0;
-}
-
-/**
- * Remove EFI device as child of EFI device
- *
- * @v efidev           EFI device
- * @v device           EFI child device handle
- * @ret efirc          EFI status code
- */
-void efidev_child_del ( struct efi_device *efidev, EFI_HANDLE device ) {
-       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
-
-       bs->CloseProtocol ( efidev->device,
-                           &efi_device_path_protocol_guid,
-                           efi_image_handle, device );
-       DBGC2 ( efidev->device, "EFIDRV %p %s removed child",
-               efidev->device, efi_handle_name ( efidev->device ) );
-       DBGC2 ( efidev->device, " %p %s\n",
-               device, efi_handle_name ( device ) );
-}
-
 /**
  * Check to see if driver supports a device
  *
@@ -242,7 +169,7 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
        /* Try to start this device */
        for_each_table_entry ( efidrv, EFI_DRIVERS ) {
                if ( ( rc = efidrv->supported ( device ) ) != 0 ) {
-                       DBGC ( device, "EFIDEV %p %s is not supported by "
+                       DBGC ( device, "EFIDRV %p %s is not supported by "
                               "driver \"%s\": %s\n", device,
                               efi_handle_name ( device ), efidrv->name,
                               strerror ( rc ) );
index 2eec29cab9a292a89fdb6f760a551dc5e42c27a7..bd45d744dd408a7ae172ffea62e8fafac69765d2 100644 (file)
@@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <ipxe/efi/efi.h>
 #include <ipxe/efi/efi_driver.h>
 #include <ipxe/efi/efi_strings.h>
+#include <ipxe/efi/efi_utils.h>
 #include <ipxe/efi/efi_snp.h>
 #include <usr/autoboot.h>
 
@@ -1047,11 +1048,11 @@ static int efi_snp_probe ( struct net_device *netdev ) {
        }
 
        /* Add as child of EFI parent device */
-       if ( ( rc = efidev_child_add ( efidev, snpdev->handle ) ) != 0 ) {
+       if ( ( rc = efi_child_add ( efidev->device, snpdev->handle ) ) != 0 ) {
                DBGC ( snpdev, "SNPDEV %p could not become child of %p %s: "
                       "%s\n", snpdev, efidev->device,
                       efi_handle_name ( efidev->device ), strerror ( rc ) );
-               goto err_efidev_child_add;
+               goto err_efi_child_add;
        }
 
        /* Install HII */
@@ -1078,8 +1079,8 @@ static int efi_snp_probe ( struct net_device *netdev ) {
 
        if ( snpdev->package_list )
                efi_snp_hii_uninstall ( snpdev );
-       efidev_child_del ( efidev, snpdev->handle );
- err_efidev_child_add:
+       efi_child_del ( efidev->device, snpdev->handle );
+ err_efi_child_add:
        bs->UninstallMultipleProtocolInterfaces (
                        snpdev->handle,
                        &efi_simple_network_protocol_guid, &snpdev->snp,
@@ -1149,7 +1150,7 @@ static void efi_snp_remove ( struct net_device *netdev ) {
        /* Uninstall the SNP */
        if ( snpdev->package_list )
                efi_snp_hii_uninstall ( snpdev );
-       efidev_child_del ( snpdev->efidev, snpdev->handle );
+       efi_child_del ( snpdev->efidev->device, snpdev->handle );
        list_del ( &snpdev->list );
        bs->UninstallMultipleProtocolInterfaces (
                        snpdev->handle,
diff --git a/src/interface/efi/efi_utils.c b/src/interface/efi/efi_utils.c
new file mode 100644 (file)
index 0000000..9a3ec15
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <string.h>
+#include <errno.h>
+#include <ipxe/efi/efi.h>
+#include <ipxe/efi/efi_utils.h>
+
+/** @file
+ *
+ * EFI utilities
+ *
+ */
+
+/**
+ * Find end of device path
+ *
+ * @v path             Path to device
+ * @ret path_end       End of device path
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
+
+       while ( path->Type != END_DEVICE_PATH_TYPE ) {
+               path = ( ( ( void * ) path ) +
+                        /* There's this amazing new-fangled thing known as
+                         * a UINT16, but who wants to use one of those? */
+                        ( ( path->Length[1] << 8 ) | path->Length[0] ) );
+       }
+
+       return path;
+}
+
+/**
+ * Add EFI device as child of another EFI device
+ *
+ * @v parent           EFI parent device handle
+ * @v child            EFI child device handle
+ * @ret rc             Return status code
+ */
+int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *devpath;
+       EFI_STATUS efirc;
+       int rc;
+
+       /* Re-open the device path protocol */
+       if ( ( efirc = bs->OpenProtocol ( parent,
+                                         &efi_device_path_protocol_guid,
+                                         &devpath,
+                                         efi_image_handle, child,
+                                         EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
+                                         ) ) != 0 ) {
+               rc = -EEFI ( efirc );
+               DBGC ( parent, "EFIDEV %p %s could not add child",
+                      parent, efi_handle_name ( parent ) );
+               DBGC ( parent, " %p %s: %s\n", child,
+                      efi_handle_name ( child ), strerror ( rc ) );
+               DBGC_EFI_OPENERS ( parent, parent,
+                                  &efi_device_path_protocol_guid );
+               return rc;
+       }
+
+       DBGC2 ( parent, "EFIDEV %p %s added child",
+               parent, efi_handle_name ( parent ) );
+       DBGC2 ( parent, " %p %s\n", child, efi_handle_name ( child ) );
+       return 0;
+}
+
+/**
+ * Remove EFI device as child of another EFI device
+ *
+ * @v parent           EFI parent device handle
+ * @v child            EFI child device handle
+ */
+void efi_child_del ( EFI_HANDLE parent, EFI_HANDLE child ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+
+       bs->CloseProtocol ( parent, &efi_device_path_protocol_guid,
+                           efi_image_handle, child );
+       DBGC2 ( parent, "EFIDEV %p %s removed child",
+               parent, efi_handle_name ( parent ) );
+       DBGC2 ( parent, " %p %s\n",
+               child, efi_handle_name ( child ) );
+}