]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Split device path functions out to efi_path.c
authorMichael Brown <mcb30@ipxe.org>
Fri, 16 Oct 2020 13:12:56 +0000 (14:12 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 16 Oct 2020 14:36:37 +0000 (15:36 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
14 files changed:
src/drivers/usb/usbio.c
src/image/efi_image.c
src/include/ipxe/efi/efi_path.h [new file with mode: 0644]
src/include/ipxe/efi/efi_utils.h
src/interface/efi/efi_block.c
src/interface/efi/efi_debug.c
src/interface/efi/efi_driver.c
src/interface/efi/efi_init.c
src/interface/efi/efi_local.c
src/interface/efi/efi_path.c [new file with mode: 0644]
src/interface/efi/efi_snp.c
src/interface/efi/efi_snp_hii.c
src/interface/efi/efi_usb.c
src/interface/efi/efi_utils.c

index dfb93dab18f358ddb48caee66b859a5cb763fff8..278b43cd38903d3e8abb4c5f7dc7dffb6d5a3f42 100644 (file)
@@ -29,6 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <assert.h>
 #include <ipxe/efi/efi.h>
 #include <ipxe/efi/efi_driver.h>
+#include <ipxe/efi/efi_path.h>
 #include <ipxe/efi/efi_utils.h>
 #include <ipxe/efi/Protocol/UsbIo.h>
 #include <ipxe/usb.h>
@@ -206,7 +207,7 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) {
        path = usbio->path;
        usbpath = usbio->usbpath;
        usbpath->InterfaceNumber = interface;
-       end = efi_devpath_end ( path );
+       end = efi_path_end ( path );
 
        /* Locate handle for this endpoint's interface */
        if ( ( efirc = bs->LocateDevicePath ( &efi_usb_io_protocol_guid, &path,
@@ -1503,7 +1504,7 @@ static int usbio_path ( struct usbio_device *usbio ) {
        path = u.interface;
 
        /* Locate end of device path and sanity check */
-       len = efi_devpath_len ( path );
+       len = efi_path_len ( path );
        if ( len < sizeof ( *usbpath ) ) {
                DBGC ( usbio, "USBIO %s underlength device path\n",
                       efi_handle_name ( handle ) );
index 942b7aeeb86a23a6d99929db617187e11bb6a294..3c98decbf61a400e607100159aba295e73cd2576 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_utils.h>
+#include <ipxe/efi/efi_path.h>
 #include <ipxe/efi/efi_strings.h>
 #include <ipxe/efi/efi_wrap.h>
 #include <ipxe/efi/efi_pxe.h>
@@ -75,7 +75,7 @@ efi_image_path ( struct image *image, EFI_DEVICE_PATH_PROTOCOL *parent ) {
        size_t len;
 
        /* Calculate device path lengths */
-       prefix_len = efi_devpath_len ( parent );
+       prefix_len = efi_path_len ( parent );
        name_len = strlen ( image->name );
        filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
                         ( name_len + 1 /* NUL */ ) * sizeof ( wchar_t ) );
diff --git a/src/include/ipxe/efi/efi_path.h b/src/include/ipxe/efi/efi_path.h
new file mode 100644 (file)
index 0000000..f8b95fd
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _IPXE_EFI_PATH_H
+#define _IPXE_EFI_PATH_H
+
+/** @file
+ *
+ * EFI device paths
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <ipxe/efi/efi.h>
+#include <ipxe/efi/Protocol/DevicePath.h>
+
+extern EFI_DEVICE_PATH_PROTOCOL *
+efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path );
+extern size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path );
+
+#endif /* _IPXE_EFI_PATH_H */
index 67acba17eef232d5c7cd3da5ebb42e49d1b4b579..270d38dc8e894eeb5f586f0b094c25abd653a308 100644 (file)
@@ -9,13 +9,9 @@
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #include <ipxe/efi/efi.h>
-#include <ipxe/efi/Protocol/DevicePath.h>
 
 struct device;
 
-extern EFI_DEVICE_PATH_PROTOCOL *
-efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path );
-extern size_t efi_devpath_len ( EFI_DEVICE_PATH_PROTOCOL *path );
 extern int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
                               EFI_HANDLE *parent );
 extern int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child );
index 0024fbbea937933c3e0a6ff0d6b9992d6ca0f45b..a63bc9ccfc4dd20fc373d5f67136ad7941d87b80 100644 (file)
@@ -54,7 +54,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/efi/efi_driver.h>
 #include <ipxe/efi/efi_strings.h>
 #include <ipxe/efi/efi_snp.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
 #include <ipxe/efi/efi_block.h>
 
 /** ACPI table protocol protocol */
@@ -288,7 +288,7 @@ static int efi_block_hook ( unsigned int drive, struct uri **uris,
        }
 
        /* Calculate length of private data */
-       prefix_len = efi_devpath_len ( snpdev->path );
+       prefix_len = efi_path_len ( snpdev->path );
        uri_len = format_uri ( uris[0], NULL, 0 );
        vendor_len = ( sizeof ( *vendor ) +
                       ( ( uri_len + 1 /* NUL */ ) * sizeof ( wchar_t ) ) );
@@ -551,7 +551,7 @@ static int efi_block_boot_image ( struct san_device *sandev, EFI_HANDLE handle,
        }
 
        /* Check if this device is a child of our block device */
-       prefix_len = efi_devpath_len ( block->path );
+       prefix_len = efi_path_len ( block->path );
        if ( memcmp ( path.path, block->path, prefix_len ) != 0 ) {
                /* Not a child device */
                rc = -ENOTTY;
@@ -561,7 +561,7 @@ static int efi_block_boot_image ( struct san_device *sandev, EFI_HANDLE handle,
               sandev->drive, efi_devpath_text ( path.path ) );
 
        /* Construct device path for boot image */
-       end = efi_devpath_end ( path.path );
+       end = efi_path_end ( path.path );
        prefix_len = ( ( ( void * ) end ) - ( ( void * ) path.path ) );
        filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
                         ( filename ?
index f7be9476e7bdfdeced88408a0b94053ff574fe2f..7cff14614a1521ae389589cedd64ea0d27b41b79 100644 (file)
@@ -37,7 +37,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/base16.h>
 #include <ipxe/vsprintf.h>
 #include <ipxe/efi/efi.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
 #include <ipxe/efi/Protocol/ComponentName.h>
 #include <ipxe/efi/Protocol/ComponentName2.h>
 #include <ipxe/efi/Protocol/DevicePathToText.h>
@@ -378,7 +378,7 @@ efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) {
        /* If we have no DevicePathToText protocol then use a raw hex string */
        if ( ! efidpt ) {
                DBG ( "[No DevicePathToText]" );
-               len = efi_devpath_len ( path );
+               len = efi_path_len ( path );
                base16_encode ( path, len, text, sizeof ( text ) );
                return text;
        }
index a6c0f3032e5d0ce0795fd52df97aa1195ba8af65..8388dd535f6961a586d47c834af664bab4165464 100644 (file)
@@ -30,7 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <ipxe/efi/Protocol/ComponentName2.h>
 #include <ipxe/efi/Protocol/DevicePath.h>
 #include <ipxe/efi/efi_strings.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
 #include <ipxe/efi/efi_driver.h>
 
 /** @file
@@ -202,7 +202,7 @@ efi_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver __unused,
                       efi_handle_name ( device ), strerror ( rc ) );
                goto err_open_path;
        }
-       path_len = ( efi_devpath_len ( path.path ) + sizeof ( *path_end ) );
+       path_len = ( efi_path_len ( path.path ) + sizeof ( *path_end ) );
 
        /* Allocate and initialise structure */
        efidev = zalloc ( sizeof ( *efidev ) + path_len );
index 70212b184c9a183d81509a1a4dbbc47247f454d6..6d46c566978630d7f9f49400b6c7ba6b5a57f4cc 100644 (file)
@@ -26,7 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #include <ipxe/rotate.h>
 #include <ipxe/efi/efi.h>
 #include <ipxe/efi/efi_driver.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
 #include <ipxe/efi/Protocol/LoadedImage.h>
 
 /** Image handle passed to entry point */
@@ -252,7 +252,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
         * path, since the device handle itself may become invalidated
         * when we load our own drivers.
         */
-       device_path_len = ( efi_devpath_len ( device_path ) +
+       device_path_len = ( efi_path_len ( device_path ) +
                            sizeof ( EFI_DEVICE_PATH_PROTOCOL ) );
        if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, device_path_len,
                                          &device_path_copy ) ) != 0 ) {
index 617895650c0da63204b1deccde5e341e72ac47d9..4ebca572645abef9fa0edff098a15310fd0a1c97 100644 (file)
@@ -37,7 +37,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/process.h>
 #include <ipxe/efi/efi.h>
 #include <ipxe/efi/efi_strings.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
 #include <ipxe/efi/Protocol/SimpleFileSystem.h>
 #include <ipxe/efi/Guid/FileInfo.h>
 #include <ipxe/efi/Guid/FileSystemInfo.h>
@@ -425,7 +425,7 @@ static int efi_local_open_resolved ( struct efi_local *local,
 static int efi_local_open_path ( struct efi_local *local, const char *path ) {
        FILEPATH_DEVICE_PATH *fp = container_of ( efi_loaded_image->FilePath,
                                                  FILEPATH_DEVICE_PATH, Header);
-       size_t fp_len = ( fp ? efi_devpath_len ( &fp->Header ) : 0 );
+       size_t fp_len = ( fp ? efi_path_len ( &fp->Header ) : 0 );
        char base[ fp_len / 2 /* Cannot exceed this length */ ];
        size_t remaining = sizeof ( base );
        size_t len;
diff --git a/src/interface/efi/efi_path.c b/src/interface/efi/efi_path.c
new file mode 100644 (file)
index 0000000..1b29756
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#include <ipxe/efi/efi.h>
+#include <ipxe/efi/efi_path.h>
+
+/** @file
+ *
+ * EFI device paths
+ *
+ */
+
+/**
+ * Find end of device path
+ *
+ * @v path             Path to device
+ * @ret path_end       End of device path
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_path_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 length of device path (excluding terminator)
+ *
+ * @v path             Path to device
+ * @ret path_len       Length of device path
+ */
+size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path ) {
+       EFI_DEVICE_PATH_PROTOCOL *end = efi_path_end ( path );
+
+       return ( ( ( void * ) end ) - ( ( void * ) path ) );
+}
index d648700f68e935a8e7ecf12b70fe0a1ec90eb8fb..f5c736a11c5dd0d75f69485a28d33798fe501ebe 100644 (file)
@@ -33,6 +33,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_path.h>
 #include <ipxe/efi/efi_utils.h>
 #include <ipxe/efi/efi_watchdog.h>
 #include <ipxe/efi/efi_snp.h>
@@ -1714,7 +1715,7 @@ static int efi_snp_probe ( struct net_device *netdev ) {
                       "%s", netdev->name );
 
        /* Allocate the new device path */
-       path_prefix_len = efi_devpath_len ( efidev->path );
+       path_prefix_len = efi_path_len ( efidev->path );
        snpdev->path = zalloc ( path_prefix_len + sizeof ( *macpath ) +
                                sizeof ( *vlanpath ) + sizeof ( *path_end ) );
        if ( ! snpdev->path ) {
index 1e681a429c63c95904aa48077882af3b15ee37a5..05c068a8c5157ffb05a898b44d18400c49590efa 100644 (file)
@@ -63,6 +63,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/efi/efi_hii.h>
 #include <ipxe/efi/efi_snp.h>
 #include <ipxe/efi/efi_strings.h>
+#include <ipxe/efi/efi_path.h>
 #include <ipxe/efi/efi_utils.h>
 #include <config/branding.h>
 
@@ -680,7 +681,7 @@ int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
        }
 
        /* Allocate the new device path */
-       path_prefix_len = efi_devpath_len ( snpdev->path );
+       path_prefix_len = efi_path_len ( snpdev->path );
        snpdev->hii_child_path = zalloc ( path_prefix_len +
                                          sizeof ( *vendor_path ) +
                                          sizeof ( *path_end ) );
index 4ddc14910cfbdf078c8697b5d12f554ec1ab3b4b..7ffeb7ffa5fa6fbb6c371b66f4c3fce2a8cf039e 100644 (file)
@@ -30,7 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <errno.h>
 #include <assert.h>
 #include <ipxe/efi/efi.h>
-#include <ipxe/efi/efi_utils.h>
+#include <ipxe/efi/efi_path.h>
 #include <ipxe/efi/efi_driver.h>
 #include <ipxe/efi/efi_usb.h>
 #include <ipxe/usb.h>
@@ -1120,7 +1120,7 @@ static int efi_usb_install ( struct efi_usb_device *usbdev,
 
        /* Calculate device path length */
        path_count = ( usb_depth ( usbdev->usb ) + 1 );
-       path_prefix_len = efi_devpath_len ( efidev->path );
+       path_prefix_len = efi_path_len ( efidev->path );
        path_len = ( path_prefix_len + ( path_count * sizeof ( *usbpath ) ) +
                     sizeof ( *path_end ) );
 
index 4dc75414c0ff4d0420abc89df26e5322f3b814ec..f8ffce915031a4a8057cee3617956f10592a7890 100644 (file)
@@ -32,36 +32,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
  *
  */
 
-/**
- * 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 length of device path (excluding terminator)
- *
- * @v path             Path to device
- * @ret path_len       Length of device path
- */
-size_t efi_devpath_len ( EFI_DEVICE_PATH_PROTOCOL *path ) {
-       EFI_DEVICE_PATH_PROTOCOL *end = efi_devpath_end ( path );
-
-       return ( ( ( void * ) end ) - ( ( void * ) path ) );
-}
-
 /**
  * Locate parent device supporting a given protocol
  *