diff options
author | Michael Brown <mcb30@ipxe.org> | 2020-10-16 14:12:56 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2020-10-16 15:36:37 +0100 |
commit | 2bf0fd39cafcfaf9a2a66f1f22bbe36640a72b6c (patch) | |
tree | 9ccf01f8b1b9606204fc77e925983b69da20e7c4 /src | |
parent | bcf858c56da382337eec4601f36db619a79a1d8e (diff) | |
download | ipxe-2bf0fd39cafcfaf9a2a66f1f22bbe36640a72b6c.tar.gz |
[efi] Split device path functions out to efi_path.c
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/drivers/usb/usbio.c | 5 | ||||
-rw-r--r-- | src/image/efi_image.c | 4 | ||||
-rw-r--r-- | src/include/ipxe/efi/efi_path.h | 19 | ||||
-rw-r--r-- | src/include/ipxe/efi/efi_utils.h | 4 | ||||
-rw-r--r-- | src/interface/efi/efi_block.c | 8 | ||||
-rw-r--r-- | src/interface/efi/efi_debug.c | 4 | ||||
-rw-r--r-- | src/interface/efi/efi_driver.c | 4 | ||||
-rw-r--r-- | src/interface/efi/efi_init.c | 4 | ||||
-rw-r--r-- | src/interface/efi/efi_local.c | 4 | ||||
-rw-r--r-- | src/interface/efi/efi_path.c | 57 | ||||
-rw-r--r-- | src/interface/efi/efi_snp.c | 3 | ||||
-rw-r--r-- | src/interface/efi/efi_snp_hii.c | 3 | ||||
-rw-r--r-- | src/interface/efi/efi_usb.c | 4 | ||||
-rw-r--r-- | src/interface/efi/efi_utils.c | 30 |
14 files changed, 99 insertions, 54 deletions
diff --git a/src/drivers/usb/usbio.c b/src/drivers/usb/usbio.c index dfb93dab1..278b43cd3 100644 --- a/src/drivers/usb/usbio.c +++ b/src/drivers/usb/usbio.c @@ -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 ) ); diff --git a/src/image/efi_image.c b/src/image/efi_image.c index 942b7aeeb..3c98decbf 100644 --- a/src/image/efi_image.c +++ b/src/image/efi_image.c @@ -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 index 000000000..f8b95fd21 --- /dev/null +++ b/src/include/ipxe/efi/efi_path.h @@ -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 */ diff --git a/src/include/ipxe/efi/efi_utils.h b/src/include/ipxe/efi/efi_utils.h index 67acba17e..270d38dc8 100644 --- a/src/include/ipxe/efi/efi_utils.h +++ b/src/include/ipxe/efi/efi_utils.h @@ -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 ); diff --git a/src/interface/efi/efi_block.c b/src/interface/efi/efi_block.c index 0024fbbea..a63bc9ccf 100644 --- a/src/interface/efi/efi_block.c +++ b/src/interface/efi/efi_block.c @@ -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 ? diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index f7be9476e..7cff14614 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -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; } diff --git a/src/interface/efi/efi_driver.c b/src/interface/efi/efi_driver.c index a6c0f3032..8388dd535 100644 --- a/src/interface/efi/efi_driver.c +++ b/src/interface/efi/efi_driver.c @@ -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 ); diff --git a/src/interface/efi/efi_init.c b/src/interface/efi/efi_init.c index 70212b184..6d46c5669 100644 --- a/src/interface/efi/efi_init.c +++ b/src/interface/efi/efi_init.c @@ -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 ) { diff --git a/src/interface/efi/efi_local.c b/src/interface/efi/efi_local.c index 617895650..4ebca5726 100644 --- a/src/interface/efi/efi_local.c +++ b/src/interface/efi/efi_local.c @@ -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 index 000000000..1b297567c --- /dev/null +++ b/src/interface/efi/efi_path.c @@ -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 ) ); +} diff --git a/src/interface/efi/efi_snp.c b/src/interface/efi/efi_snp.c index d648700f6..f5c736a11 100644 --- a/src/interface/efi/efi_snp.c +++ b/src/interface/efi/efi_snp.c @@ -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 ) { diff --git a/src/interface/efi/efi_snp_hii.c b/src/interface/efi/efi_snp_hii.c index 1e681a429..05c068a8c 100644 --- a/src/interface/efi/efi_snp_hii.c +++ b/src/interface/efi/efi_snp_hii.c @@ -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 ) ); diff --git a/src/interface/efi/efi_usb.c b/src/interface/efi/efi_usb.c index 4ddc14910..7ffeb7ffa 100644 --- a/src/interface/efi/efi_usb.c +++ b/src/interface/efi/efi_usb.c @@ -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 ) ); diff --git a/src/interface/efi/efi_utils.c b/src/interface/efi/efi_utils.c index 4dc75414c..f8ffce915 100644 --- a/src/interface/efi/efi_utils.c +++ b/src/interface/efi/efi_utils.c @@ -33,36 +33,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 * * @v device EFI device handle |