diff --git a/src/drivers/net/efi/mnpnet.c b/src/drivers/net/efi/mnpnet.c index ead8691ff..902eb91f3 100644 --- a/src/drivers/net/efi/mnpnet.c +++ b/src/drivers/net/efi/mnpnet.c @@ -370,10 +370,6 @@ int mnpnet_start ( struct efi_device *efidev ) { EFI_HANDLE device = efidev->device; EFI_GUID *binding = &efi_managed_network_service_binding_protocol_guid; EFI_SIMPLE_NETWORK_MODE mode; - union { - EFI_MANAGED_NETWORK_PROTOCOL *mnp; - void *interface; - } u; struct net_device *netdev; struct mnp_nic *mnp; EFI_STATUS efirc; @@ -409,12 +405,11 @@ int mnpnet_start ( struct efi_device *efidev ) { /* Open MNP protocol */ if ( ( rc = efi_open_by_driver ( efidev->child, &efi_managed_network_protocol_guid, - &u.interface ) ) != 0 ) { + &mnp->mnp ) ) != 0 ) { DBGC ( mnp, "MNP %s could not open MNP protocol: %s\n", efi_handle_name ( device ), strerror ( rc ) ); goto err_open; } - mnp->mnp = u.mnp; /* Get configuration */ efirc = mnp->mnp->GetModeData ( mnp->mnp, NULL, &mode ); diff --git a/src/drivers/net/efi/nii.c b/src/drivers/net/efi/nii.c index 126584eff..81f1838a4 100644 --- a/src/drivers/net/efi/nii.c +++ b/src/drivers/net/efi/nii.c @@ -209,10 +209,6 @@ static int nii_pci_open ( struct nii_nic *nii ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE device = nii->efidev->device; EFI_HANDLE pci_device; - union { - EFI_PCI_IO_PROTOCOL *pci_io; - void *interface; - } pci_io; union { EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *acpi; void *resource; @@ -237,12 +233,11 @@ static int nii_pci_open ( struct nii_nic *nii ) { * therefore use an unsafe open. */ if ( ( rc = efi_open_unsafe ( pci_device, &efi_pci_io_protocol_guid, - &pci_io.interface ) ) != 0 ) { + &nii->pci_io ) ) != 0 ) { DBGC ( nii, "NII %s could not open PCI I/O protocol: %s\n", nii->dev.name, strerror ( rc ) ); goto err_open; } - nii->pci_io = pci_io.pci_io; /* Identify memory and I/O BARs */ nii->mem_bar = PCI_MAX_BAR; @@ -1272,7 +1267,6 @@ int nii_start ( struct efi_device *efidev ) { EFI_HANDLE device = efidev->device; struct net_device *netdev; struct nii_nic *nii; - void *interface; int rc; /* Allocate and initialise structure */ @@ -1298,13 +1292,12 @@ int nii_start ( struct efi_device *efidev ) { /* Open NII protocol */ if ( ( rc = efi_open_by_driver ( device, &efi_nii31_protocol_guid, - &interface ) ) != 0 ) { + &nii->nii ) ) != 0 ) { DBGC ( nii, "NII %s cannot open NII protocol: %s\n", nii->dev.name, strerror ( rc ) ); DBGC_EFI_OPENERS ( device, device, &efi_nii31_protocol_guid ); goto err_open_protocol; } - nii->nii = interface; /* Locate UNDI and entry point */ nii->undi = ( ( void * ) ( intptr_t ) nii->nii->Id ); diff --git a/src/drivers/net/efi/snpnet.c b/src/drivers/net/efi/snpnet.c index 93ed8cd95..c8e2f2f68 100644 --- a/src/drivers/net/efi/snpnet.c +++ b/src/drivers/net/efi/snpnet.c @@ -504,7 +504,7 @@ int snpnet_supported ( EFI_HANDLE device, EFI_GUID *protocol ) { } /* Test for presence of protocol */ - if ( ( rc = efi_open ( device, protocol, NULL ) ) != 0 ) { + if ( ( rc = efi_test ( device, protocol ) ) != 0 ) { DBGCP ( device, "HANDLE %s is not a %s device\n", efi_handle_name ( device ), efi_guid_ntoa ( protocol ) ); @@ -536,10 +536,10 @@ int snpnet_supported ( EFI_HANDLE device, EFI_GUID *protocol ) { */ int snpnet_start ( struct efi_device *efidev ) { EFI_HANDLE device = efidev->device; + EFI_SIMPLE_NETWORK_PROTOCOL *interface; EFI_SIMPLE_NETWORK_MODE *mode; struct net_device *netdev; struct snp_nic *snp; - void *interface; EFI_STATUS efirc; int rc; diff --git a/src/drivers/usb/usbio.c b/src/drivers/usb/usbio.c index db3beff21..73151c536 100644 --- a/src/drivers/usb/usbio.c +++ b/src/drivers/usb/usbio.c @@ -187,10 +187,6 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) { EFI_DEVICE_PATH_PROTOCOL *path; EFI_DEVICE_PATH_PROTOCOL *end; USB_DEVICE_PATH *usbpath; - union { - void *interface; - EFI_USB_IO_PROTOCOL *io; - } u; EFI_STATUS efirc; int rc; @@ -231,7 +227,7 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) { /* Open USB I/O protocol on this handle */ if ( ( rc = efi_open_by_driver ( intf->handle, &efi_usb_io_protocol_guid, - &u.interface ) ) != 0 ) { + &intf->io ) ) != 0 ) { DBGC ( usbio, "USBIO %s cannot open ", efi_handle_name ( handle ) ); DBGC ( usbio, "%s: %s\n", @@ -240,7 +236,6 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) { &efi_usb_io_protocol_guid ); return rc; } - intf->io = u.io; /* Increment usage count */ intf->count++; @@ -1296,24 +1291,20 @@ static int usbio_supported ( EFI_HANDLE handle ) { struct usb_function_descriptor desc; struct usb_driver *driver; struct usb_device_id *id; - union { - void *interface; - EFI_USB_IO_PROTOCOL *io; - } usb; + EFI_USB_IO_PROTOCOL *io; EFI_STATUS efirc; int rc; /* Get protocol */ if ( ( rc = efi_open ( handle, &efi_usb_io_protocol_guid, - &usb.interface ) ) != 0 ) { + &io ) ) != 0 ) { DBGCP ( handle, "USB %s is not a USB device\n", efi_handle_name ( handle ) ); return rc; } /* Get device descriptor */ - if ( ( efirc = usb.io->UsbGetDeviceDescriptor ( usb.io, - &device ) ) != 0 ) { + if ( ( efirc = io->UsbGetDeviceDescriptor ( io, &device ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( handle, "USB %s could not get device descriptor: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); @@ -1324,8 +1315,7 @@ static int usbio_supported ( EFI_HANDLE handle ) { desc.product = device.IdProduct; /* Get interface descriptor */ - if ( ( efirc = usb.io->UsbGetInterfaceDescriptor ( usb.io, - &interface ) ) !=0){ + if ( ( efirc = io->UsbGetInterfaceDescriptor ( io, &interface ) ) != 0){ rc = -EEFI ( efirc ); DBGC ( handle, "USB %s could not get interface descriptor: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); @@ -1460,21 +1450,16 @@ static int usbio_path ( struct usbio_device *usbio ) { EFI_DEVICE_PATH_PROTOCOL *path; EFI_DEVICE_PATH_PROTOCOL *end; USB_DEVICE_PATH *usbpath; - union { - void *interface; - EFI_DEVICE_PATH_PROTOCOL *path; - } u; size_t len; int rc; /* Open device path protocol */ if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, - &u.interface ) ) != 0 ) { + &path ) ) != 0 ) { DBGC ( usbio, "USBIO %s cannot open device path protocol: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); return rc; } - path = u.interface; /* Locate end of device path and sanity check */ len = efi_path_len ( path ); @@ -1567,10 +1552,6 @@ static int usbio_start ( struct efi_device *efidev ) { EFI_HANDLE handle = efidev->device; struct usbio_device *usbio; struct usb_port *port; - union { - void *interface; - EFI_USB_IO_PROTOCOL *io; - } u; int rc; /* Allocate and initialise structure */ @@ -1585,13 +1566,12 @@ static int usbio_start ( struct efi_device *efidev ) { /* Open USB I/O protocol */ if ( ( rc = efi_open_by_driver ( handle, &efi_usb_io_protocol_guid, - &u.interface ) ) != 0 ) { + &usbio->io ) ) != 0 ) { DBGC ( usbio, "USBIO %s cannot open USB I/O protocol: %s\n", efi_handle_name ( handle ), strerror ( rc ) ); DBGC_EFI_OPENERS ( usbio, handle, &efi_usb_io_protocol_guid ); goto err_open_usbio; } - usbio->io = u.io; /* Describe generic device */ efi_device_info ( handle, "USB", &usbio->dev ); diff --git a/src/image/efi_image.c b/src/image/efi_image.c index ae9255ce5..82101d484 100644 --- a/src/image/efi_image.c +++ b/src/image/efi_image.c @@ -132,10 +132,7 @@ static int efi_image_exec ( struct image *image ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; struct efi_snp_device *snpdev; EFI_DEVICE_PATH_PROTOCOL *path; - union { - EFI_LOADED_IMAGE_PROTOCOL *image; - void *interface; - } loaded; + EFI_LOADED_IMAGE_PROTOCOL *loaded; struct image *shim; struct image *exec; EFI_HANDLE handle; @@ -235,30 +232,30 @@ static int efi_image_exec ( struct image *image ) { /* Get the loaded image protocol for the newly loaded image */ if ( ( rc = efi_open ( handle, &efi_loaded_image_protocol_guid, - &loaded.interface ) ) != 0 ) { + &loaded ) ) != 0 ) { /* Should never happen */ goto err_open_protocol; } /* Some EFI 1.10 implementations seem not to fill in DeviceHandle */ - if ( loaded.image->DeviceHandle == NULL ) { + if ( loaded->DeviceHandle == NULL ) { DBGC ( image, "EFIIMAGE %s filling in missing DeviceHandle\n", image->name ); - loaded.image->DeviceHandle = snpdev->handle; + loaded->DeviceHandle = snpdev->handle; } /* Sanity checks */ - assert ( loaded.image->ParentHandle == efi_image_handle ); - assert ( loaded.image->DeviceHandle == snpdev->handle ); - assert ( loaded.image->LoadOptionsSize == 0 ); - assert ( loaded.image->LoadOptions == NULL ); + assert ( loaded->ParentHandle == efi_image_handle ); + assert ( loaded->DeviceHandle == snpdev->handle ); + assert ( loaded->LoadOptionsSize == 0 ); + assert ( loaded->LoadOptions == NULL ); /* Record image code type */ - type = loaded.image->ImageCodeType; + type = loaded->ImageCodeType; /* Set command line */ - loaded.image->LoadOptions = cmdline; - loaded.image->LoadOptionsSize = + loaded->LoadOptions = cmdline; + loaded->LoadOptionsSize = ( ( wcslen ( cmdline ) + 1 /* NUL */ ) * sizeof ( wchar_t ) ); /* Release network devices for use via SNP */ diff --git a/src/include/ipxe/efi/efi.h b/src/include/ipxe/efi/efi.h index 6126d3b87..5fae87731 100644 --- a/src/include/ipxe/efi/efi.h +++ b/src/include/ipxe/efi/efi.h @@ -389,17 +389,88 @@ extern EFI_STATUS efi_init ( EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab ); extern void efi_raise_tpl ( struct efi_saved_tpl *tpl ); extern void efi_restore_tpl ( struct efi_saved_tpl *tpl ); -extern int efi_open ( EFI_HANDLE handle, EFI_GUID *protocol, - void **interface ); -extern int efi_open_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol, - void **interface ); +extern int efi_open_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ); +extern int efi_open_unsafe_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ); extern void efi_close_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol ); -extern int efi_open_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol, - void **interface ); +extern int efi_open_by_driver_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ); extern void efi_close_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol ); -extern int efi_open_by_child ( EFI_HANDLE handle, EFI_GUID *protocol, - EFI_HANDLE child, void **interface ); +extern int efi_open_by_child_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + EFI_HANDLE child, void **interface ); extern void efi_close_by_child ( EFI_HANDLE handle, EFI_GUID *protocol, EFI_HANDLE child ); +/** + * Test protocol existence + * + * @v handle EFI handle + * @v protocol Protocol GUID + * @ret rc Return status code + */ +#define efi_test( handle, protocol ) \ + efi_open_untyped ( (handle), (protocol), NULL ) + +/** + * Open protocol for ephemeral use + * + * @v handle EFI handle + * @v protocol Protocol GUID + * @v interface Protocol interface pointer to fill in + * @ret rc Return status code + */ +#define efi_open( handle, protocol, interface ) ( { \ + typeof ( *(interface) ) check_ptr_ptr = NULL; \ + efi_open_untyped ( (handle), (protocol), \ + ( ( void ) check_ptr_ptr, \ + ( void ** ) (interface) ) ); \ + } ) + +/** + * Open protocol for unsafe persistent use + * + * @v handle EFI handle + * @v protocol Protocol GUID + * @v interface Protocol interface pointer to fill in + * @ret rc Return status code + */ +#define efi_open_unsafe( handle, protocol, interface ) ( { \ + typeof ( *(interface) ) check_ptr_ptr = NULL; \ + efi_open_unsafe_untyped ( (handle), (protocol), \ + ( ( void ) check_ptr_ptr, \ + ( void ** ) (interface) ) ); \ + } ) + +/** + * Open protocol for persistent use by a driver + * + * @v handle EFI handle + * @v protocol Protocol GUID + * @v interface Protocol interface pointer to fill in + * @ret rc Return status code + */ +#define efi_open_by_driver( handle, protocol, interface ) ( { \ + typeof ( *(interface) ) check_ptr_ptr = NULL; \ + efi_open_by_driver_untyped ( (handle), (protocol), \ + ( ( void ) check_ptr_ptr, \ + ( void ** ) (interface) ) ); \ + } ) + +/** + * Open protocol for persistent use by a child controller + * + * @v handle EFI handle + * @v protocol Protocol GUID + * @v child Child controller handle + * @v interface Protocol interface pointer to fill in + * @ret rc Return status code + */ +#define efi_open_by_child( handle, protocol, child, interface ) ( { \ + typeof ( *(interface) ) check_ptr_ptr = NULL; \ + efi_open_by_child_untyped ( (handle), (protocol), (child), \ + ( ( void ) check_ptr_ptr, \ + ( void ** ) (interface) ) ); \ + } ) + #endif /* _IPXE_EFI_H */ diff --git a/src/interface/efi/efi_autoboot.c b/src/interface/efi/efi_autoboot.c index 528b84f1e..e52c857d8 100644 --- a/src/interface/efi/efi_autoboot.c +++ b/src/interface/efi/efi_autoboot.c @@ -48,24 +48,21 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ int efi_set_autoboot_ll_addr ( EFI_HANDLE device, EFI_DEVICE_PATH_PROTOCOL *path ) { - union { - EFI_SIMPLE_NETWORK_PROTOCOL *snp; - void *interface; - } snp; + EFI_SIMPLE_NETWORK_PROTOCOL *snp; EFI_SIMPLE_NETWORK_MODE *mode; unsigned int vlan; int rc; /* Look for an SNP instance on the image's device handle */ if ( ( rc = efi_open ( device, &efi_simple_network_protocol_guid, - &snp.interface ) ) != 0 ) { + &snp ) ) != 0 ) { DBGC ( device, "EFI %s has no SNP instance: %s\n", efi_handle_name ( device ), strerror ( rc ) ); return rc; } /* Record autoboot device */ - mode = snp.snp->Mode; + mode = snp->Mode; vlan = efi_path_vlan ( path ); set_autoboot_ll_addr ( &mode->CurrentAddress, mode->HwAddressSize, vlan ); diff --git a/src/interface/efi/efi_block.c b/src/interface/efi/efi_block.c index 34b73c265..5165bd804 100644 --- a/src/interface/efi/efi_block.c +++ b/src/interface/efi/efi_block.c @@ -518,23 +518,20 @@ static int efi_block_describe ( void ) { */ static int efi_block_root ( unsigned int drive, EFI_HANDLE handle, EFI_FILE_PROTOCOL **root ) { - union { - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; - void *interface; - } u; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; EFI_STATUS efirc; int rc; /* Open filesystem protocol */ if ( ( rc = efi_open ( handle, &efi_simple_file_system_protocol_guid, - &u.interface ) ) != 0 ) { + &fs ) ) != 0 ) { DBGC ( drive, "EFIBLK %#02x could not open %s filesystem: %s\n", drive, efi_handle_name ( handle ), strerror ( rc ) ); return rc; } /* Open root volume */ - if ( ( efirc = u.fs->OpenVolume ( u.fs, root ) ) != 0 ) { + if ( ( efirc = fs->OpenVolume ( fs, root ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( drive, "EFIBLK %#02x could not open %s root: %s\n", drive, efi_handle_name ( handle ), strerror ( rc ) ); @@ -664,26 +661,21 @@ static int efi_block_match ( unsigned int drive, EFI_HANDLE handle, EFI_DEVICE_PATH_PROTOCOL *path, struct san_boot_config *config, EFI_DEVICE_PATH_PROTOCOL **fspath ) { - union { - EFI_DEVICE_PATH_PROTOCOL *path; - void *interface; - } u; EFI_FILE *root; union uuid guid; int rc; /* Identify device path */ if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, - &u.interface ) ) != 0 ) { + fspath ) ) != 0 ) { DBGC ( drive, "EFIBLK %#02x could not open %s device path: " "%s\n", drive, efi_handle_name ( handle ), strerror ( rc ) ); goto err_open; } - *fspath = u.path; /* Check if filesystem is a child of this block device */ - if ( memcmp ( u.path, path, efi_path_len ( path ) ) != 0 ) { + if ( memcmp ( *fspath, path, efi_path_len ( path ) ) != 0 ) { /* Not a child device */ rc = -ENOTTY; DBGC2 ( drive, "EFIBLK %#02x is not parent of %s\n", @@ -691,11 +683,11 @@ static int efi_block_match ( unsigned int drive, EFI_HANDLE handle, goto err_not_child; } DBGC ( drive, "EFIBLK %#02x contains filesystem %s\n", - drive, efi_devpath_text ( u.path ) ); + drive, efi_devpath_text ( *fspath ) ); /* Check if filesystem matches GUID, if applicable */ if ( config->uuid ) { - if ( ( rc = efi_path_guid ( u.path, &guid ) ) != 0 ) { + if ( ( rc = efi_path_guid ( *fspath, &guid ) ) != 0 ) { DBGC ( drive, "EFIBLK %#02x could not determine GUID: " "%s\n", drive, strerror ( rc ) ); goto err_no_guid; @@ -760,10 +752,7 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle, struct san_boot_config *config, EFI_DEVICE_PATH_PROTOCOL **fspath ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - union { - EFI_DEVICE_PATH_PROTOCOL *path; - void *interface; - } u; + EFI_DEVICE_PATH_PROTOCOL *path; EFI_HANDLE *handles; UINTN count; unsigned int i; @@ -775,7 +764,7 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle, /* Identify device path */ if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, - &u.interface ) ) != 0 ) { + &path ) ) != 0 ) { DBGC ( drive, "EFIBLK %#02x could not open device path: %s\n", drive, strerror ( rc ) ); goto err_open; @@ -796,7 +785,7 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle, for ( i = 0 ; i < count ; i++ ) { /* Check for a matching filesystem */ - if ( ( rc = efi_block_match ( drive, handles[i], u.path, + if ( ( rc = efi_block_match ( drive, handles[i], path, config, fspath ) ) != 0 ) continue; @@ -903,10 +892,7 @@ static int efi_block_exec ( unsigned int drive, static int efi_block_local ( EFI_HANDLE handle ) { struct san_device *sandev; struct efi_block_data *block; - union { - EFI_BLOCK_IO_PROTOCOL *blockio; - void *interface; - } u; + EFI_BLOCK_IO_PROTOCOL *blockio; int rc; /* Check if handle belongs to a SAN device */ @@ -918,14 +904,14 @@ static int efi_block_local ( EFI_HANDLE handle ) { /* Open block I/O protocol */ if ( ( rc = efi_open ( handle, &efi_block_io_protocol_guid, - &u.interface ) ) != 0 ) { + &blockio ) ) != 0 ) { DBGC ( handle, "EFIBLK %s could not open block I/O: %s\n", efi_handle_name ( handle ), strerror ( rc ) ); return rc; } /* Do not assign drive numbers for partitions */ - if ( u.blockio->Media->LogicalPartition ) { + if ( blockio->Media->LogicalPartition ) { DBGC2 ( handle, "EFLBLK %s is a partition\n", efi_handle_name ( handle ) ); return -ENOTTY; diff --git a/src/interface/efi/efi_bofm.c b/src/interface/efi/efi_bofm.c index 6d97ff445..b64770d8a 100644 --- a/src/interface/efi/efi_bofm.c +++ b/src/interface/efi/efi_bofm.c @@ -228,7 +228,6 @@ static int efi_bofm_start ( struct efi_device *efidev ) { struct efi_pci_device efipci; IBM_BOFM_TABLE *bofmtab; IBM_BOFM_TABLE *bofmtab2; - void *pci_io; int bofmrc; EFI_STATUS efirc; int rc; @@ -242,7 +241,7 @@ static int efi_bofm_start ( struct efi_device *efidev ) { /* Open PCI I/O protocol */ if ( ( rc = efi_open_unsafe ( device, &efi_pci_io_protocol_guid, - &pci_io ) ) != 0 ) { + &efipci.io ) ) != 0 ) { DBGC ( device, "EFIBOFM %s cannot open PCI device: %s\n", efi_handle_name ( device ), strerror ( rc ) ); goto err_open; diff --git a/src/interface/efi/efi_cachedhcp.c b/src/interface/efi/efi_cachedhcp.c index 68671d7c6..eb41a8e43 100644 --- a/src/interface/efi/efi_cachedhcp.c +++ b/src/interface/efi/efi_cachedhcp.c @@ -47,10 +47,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); int efi_cachedhcp_record ( EFI_HANDLE device, EFI_DEVICE_PATH_PROTOCOL *path ) { unsigned int vlan; - union { - EFI_PXE_BASE_CODE_PROTOCOL *pxe; - void *interface; - } pxe; + EFI_PXE_BASE_CODE_PROTOCOL *pxe; EFI_PXE_BASE_CODE_MODE *mode; int rc; @@ -59,14 +56,14 @@ int efi_cachedhcp_record ( EFI_HANDLE device, /* Look for a PXE base code instance on the image's device handle */ if ( ( rc = efi_open ( device, &efi_pxe_base_code_protocol_guid, - &pxe.interface ) ) != 0 ) { + &pxe ) ) != 0 ) { DBGC ( device, "EFI %s has no PXE base code instance: %s\n", efi_handle_name ( device ), strerror ( rc ) ); return rc; } /* Do not attempt to cache IPv6 packets */ - mode = pxe.pxe->Mode; + mode = pxe->Mode; if ( mode->UsingIpv6 ) { DBGC ( device, "EFI %s has IPv6 PXE base code\n", efi_handle_name ( device ) ); diff --git a/src/interface/efi/efi_console.c b/src/interface/efi/efi_console.c index 41c4dcf2c..9fc3c65c0 100644 --- a/src/interface/efi/efi_console.c +++ b/src/interface/efi/efi_console.c @@ -416,10 +416,6 @@ struct console_driver efi_console __console_driver = { */ static void efi_console_init ( void ) { EFI_CONSOLE_CONTROL_SCREEN_MODE mode; - union { - void *interface; - EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *wtf; - } u; int rc; /* On some older EFI 1.10 implementations, we must use the @@ -441,8 +437,7 @@ static void efi_console_init ( void ) { */ if ( ( rc = efi_open_unsafe ( efi_systab->ConsoleInHandle, &efi_simple_text_input_ex_protocol_guid, - &u.interface ) ) == 0 ) { - efi_conin_ex = u.wtf; + &efi_conin_ex ) ) == 0 ) { DBG ( "EFI using SimpleTextInputEx\n" ); } else { DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) ); diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index fd4997ccc..026adc25e 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -324,10 +324,7 @@ static const char * efi_driver_name2 ( EFI_COMPONENT_NAME2_PROTOCOL *wtf ) { * @ret name Driver name, or NULL */ static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) { - union { - EFI_COMPONENT_NAME_PROTOCOL *name; - void *interface; - } u; + EFI_COMPONENT_NAME_PROTOCOL *name; EFI_HANDLE image; int rc; @@ -340,13 +337,13 @@ static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) { /* Try to open component name protocol on image handle */ image = binding->ImageHandle; if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid, - &u.interface ) ) != 0 ) { + &name ) ) != 0 ) { DBG ( "[DriverBinding no ComponentName]" ); return NULL; } /* Try to get name from component name protocol */ - return efi_driver_name ( u.name ); + return efi_driver_name ( name ); } /** @@ -357,10 +354,7 @@ static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) { */ static const char * efi_binding_name2 ( EFI_DRIVER_BINDING_PROTOCOL *binding ){ EFI_HANDLE image; - union { - EFI_COMPONENT_NAME2_PROTOCOL *name2; - void *interface; - } u; + EFI_COMPONENT_NAME2_PROTOCOL *name2; int rc; /* Sanity check */ @@ -372,13 +366,13 @@ static const char * efi_binding_name2 ( EFI_DRIVER_BINDING_PROTOCOL *binding ){ /* Try to open component name protocol on image handle */ image = binding->ImageHandle; if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid, - &u.interface ) ) != 0 ) { + &name2 ) ) != 0 ) { DBG ( "[DriverBinding no ComponentName2]" ); return NULL; } /* Try to get name from component name protocol */ - return efi_driver_name2 ( u.name2 ); + return efi_driver_name2 ( name2 ); } /** diff --git a/src/interface/efi/efi_driver.c b/src/interface/efi/efi_driver.c index d143249ca..56918deba 100644 --- a/src/interface/efi/efi_driver.c +++ b/src/interface/efi/efi_driver.c @@ -69,22 +69,19 @@ static int efi_driver_disconnecting; */ struct efi_device * efidev_alloc ( EFI_HANDLE device ) { struct efi_device *efidev = NULL; - union { - EFI_DEVICE_PATH_PROTOCOL *path; - void *interface; - } path; + EFI_DEVICE_PATH_PROTOCOL *path; EFI_DEVICE_PATH_PROTOCOL *path_end; size_t path_len; int rc; /* Open device path */ if ( ( rc = efi_open ( device, &efi_device_path_protocol_guid, - &path.interface ) ) != 0 ) { + &path ) ) != 0 ) { DBGC ( device, "EFIDRV %s could not open device path: %s\n", efi_handle_name ( device ), strerror ( rc ) ); return NULL; } - path_len = ( efi_path_len ( path.path ) + sizeof ( *path_end ) ); + path_len = ( efi_path_len ( path ) + sizeof ( *path_end ) ); /* Allocate and initialise structure */ efidev = zalloc ( sizeof ( *efidev ) + path_len ); @@ -93,7 +90,7 @@ struct efi_device * efidev_alloc ( EFI_HANDLE device ) { efidev->device = device; efidev->dev.desc.bus_type = BUS_TYPE_EFI; efidev->path = ( ( ( void * ) efidev ) + sizeof ( *efidev ) ); - memcpy ( efidev->path, path.path, path_len ); + memcpy ( efidev->path, path, path_len ); INIT_LIST_HEAD ( &efidev->dev.children ); list_add ( &efidev->dev.siblings, &efi_devices ); @@ -365,10 +362,7 @@ static EFI_STATUS EFIAPI efi_driver_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused, EFI_HANDLE device, EFI_HANDLE child, CHAR8 *language, CHAR16 **controller_name ) { - union { - EFI_COMPONENT_NAME2_PROTOCOL *name2; - void *interface; - } name2; + EFI_COMPONENT_NAME2_PROTOCOL *name2; int rc; /* Delegate to the EFI_COMPONENT_NAME2_PROTOCOL instance @@ -376,10 +370,9 @@ efi_driver_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused, */ if ( ( child != NULL ) && ( ( rc = efi_open ( child, &efi_component_name2_protocol_guid, - &name2.interface ) ) == 0 ) ) { - return name2.name2->GetControllerName ( name2.name2, device, - child, language, - controller_name ); + &name2 ) ) == 0 ) ) { + return name2->GetControllerName ( name2, device, child, + language, controller_name ); } /* Otherwise, let EFI use the default Device Path Name */ diff --git a/src/interface/efi/efi_file.c b/src/interface/efi/efi_file.c index d8b9f819c..b7b97aee7 100644 --- a/src/interface/efi/efi_file.c +++ b/src/interface/efi/efi_file.c @@ -982,9 +982,9 @@ static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol = { */ static int efi_file_path_claim ( struct efi_file_path *file ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + EFI_DEVICE_PATH_PROTOCOL *old; EFI_DEVICE_PATH_PROTOCOL *end; EFI_HANDLE handle; - VOID *old; EFI_STATUS efirc; int rc; @@ -1116,10 +1116,7 @@ static void efi_file_path_uninstall ( struct efi_file_path *file ) { */ int efi_file_install ( EFI_HANDLE handle ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - union { - EFI_DISK_IO_PROTOCOL *diskio; - void *interface; - } diskio; + EFI_DISK_IO_PROTOCOL *diskio; struct image *image; EFI_STATUS efirc; int rc; @@ -1168,13 +1165,13 @@ int efi_file_install ( EFI_HANDLE handle ) { * shell. I have no idea why this is. */ if ( ( rc = efi_open_by_driver ( handle, &efi_disk_io_protocol_guid, - &diskio.interface ) ) != 0 ) { + &diskio ) ) != 0 ) { DBGC ( handle, "Could not open disk I/O protocol: %s\n", strerror ( rc ) ); DBGC_EFI_OPENERS ( handle, handle, &efi_disk_io_protocol_guid ); goto err_open; } - assert ( diskio.diskio == &efi_disk_io_protocol ); + assert ( diskio == &efi_disk_io_protocol ); /* Claim Linux initrd fixed device path */ if ( ( rc = efi_file_path_claim ( &efi_file_initrd ) ) != 0 ) diff --git a/src/interface/efi/efi_init.c b/src/interface/efi/efi_init.c index 03506ec5c..1ba144ee7 100644 --- a/src/interface/efi/efi_init.c +++ b/src/interface/efi/efi_init.c @@ -173,8 +173,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle, EFI_BOOT_SERVICES *bs; struct efi_protocol *prot; struct efi_config_table *tab; - void *loaded_image; - void *device_path; + EFI_DEVICE_PATH_PROTOCOL *device_path; void *device_path_copy; size_t device_path_len; EFI_STATUS efirc; @@ -248,13 +247,12 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle, */ if ( ( rc = efi_open_unsafe ( image_handle, &efi_loaded_image_protocol_guid, - &loaded_image ) ) != 0 ) { + &efi_loaded_image ) ) != 0 ) { DBGC ( systab, "EFI could not get loaded image protocol: %s", strerror ( rc ) ); efirc = EFIRC ( rc ); goto err_no_loaded_image; } - efi_loaded_image = loaded_image; DBGC ( systab, "EFI image base address %p\n", efi_loaded_image->ImageBase ); diff --git a/src/interface/efi/efi_local.c b/src/interface/efi/efi_local.c index 80cfb5a22..4564470fc 100644 --- a/src/interface/efi/efi_local.c +++ b/src/interface/efi/efi_local.c @@ -208,23 +208,20 @@ static int efi_local_check_volume_name ( struct efi_local *local, */ static int efi_local_open_root ( struct efi_local *local, EFI_HANDLE device, EFI_FILE_PROTOCOL **root ) { - union { - void *interface; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; - } u; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; EFI_STATUS efirc; int rc; /* Open file system protocol */ if ( ( rc = efi_open ( device, &efi_simple_file_system_protocol_guid, - &u.interface ) ) != 0 ) { + &fs ) ) != 0 ) { DBGC ( local, "LOCAL %p could not open filesystem on %s: %s\n", local, efi_handle_name ( device ), strerror ( rc ) ); return rc; } /* Open root directory */ - if ( ( efirc = u.fs->OpenVolume ( u.fs, root ) ) != 0 ) { + if ( ( efirc = fs->OpenVolume ( fs, root ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( local, "LOCAL %p could not open volume on %s: %s\n", local, efi_handle_name ( device ), strerror ( rc ) ); diff --git a/src/interface/efi/efi_open.c b/src/interface/efi/efi_open.c index c85c027e1..8f8af4ea0 100644 --- a/src/interface/efi/efi_open.c +++ b/src/interface/efi/efi_open.c @@ -93,7 +93,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * @v interface Protocol interface pointer to fill in (or NULL to test) * @ret rc Return status code */ -int efi_open ( EFI_HANDLE handle, EFI_GUID *protocol, void **interface ) { +int efi_open_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE agent = efi_image_handle; EFI_HANDLE controller; @@ -176,8 +177,8 @@ int efi_open ( EFI_HANDLE handle, EFI_GUID *protocol, void **interface ) { * @v interface Protocol interface pointer to fill in * @ret rc Return status code */ -int efi_open_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol, - void **interface ) { +int efi_open_unsafe_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE agent = efi_image_handle; EFI_HANDLE controller; @@ -236,8 +237,8 @@ void efi_close_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol ) { * @v interface Protocol interface pointer to fill in * @ret rc Return status code */ -int efi_open_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol, - void **interface ) { +int efi_open_by_driver_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE agent = efi_image_handle; EFI_HANDLE controller; @@ -297,8 +298,8 @@ void efi_close_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol ) { * @v interface Protocol interface pointer to fill in * @ret rc Return status code */ -int efi_open_by_child ( EFI_HANDLE handle, EFI_GUID *protocol, - EFI_HANDLE child, void **interface ) { +int efi_open_by_child_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + EFI_HANDLE child, void **interface ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE agent = efi_image_handle; EFI_HANDLE controller; diff --git a/src/interface/efi/efi_pci.c b/src/interface/efi/efi_pci.c index 003fa2f4a..0662302d2 100644 --- a/src/interface/efi/efi_pci.c +++ b/src/interface/efi/efi_pci.c @@ -72,10 +72,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, struct pci_range *range ) { - union { - void *interface; - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root; - } root; + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root; union { union acpi_resource *res; void *raw; @@ -94,7 +91,7 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, /* Open root bridge I/O protocol */ if ( ( rc = efi_open ( handle, &efi_pci_root_bridge_io_protocol_guid, - &root.interface ) ) != 0 ) { + &root ) ) != 0 ) { DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n", PCI_ARGS ( pci ), efi_handle_name ( handle ), strerror ( rc ) ); @@ -102,8 +99,7 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, } /* Get ACPI resource descriptors */ - if ( ( efirc = root.root->Configuration ( root.root, - &acpi.raw ) ) != 0 ) { + if ( ( efirc = root->Configuration ( root, &acpi.raw ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for " "%s: %s\n", PCI_ARGS ( pci ), @@ -123,13 +119,13 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, continue; /* Get range for this descriptor */ - start = PCI_BUSDEVFN ( root.root->SegmentNumber, + start = PCI_BUSDEVFN ( root->SegmentNumber, le64_to_cpu ( acpi.res->qword.min ), 0, 0 ); count = PCI_BUSDEVFN ( 0, le64_to_cpu ( acpi.res->qword.len ), 0, 0 ); DBGC2 ( pci, "EFIPCI " PCI_FMT " found %04x:[%02x-%02x] via " - "%s\n", PCI_ARGS ( pci ), root.root->SegmentNumber, + "%s\n", PCI_ARGS ( pci ), root->SegmentNumber, PCI_BUS ( start ), PCI_BUS ( start + count - 1 ), efi_handle_name ( handle ) ); @@ -150,8 +146,7 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, * bridge has a single bus. */ if ( ! range->count ) { - range->start = PCI_BUSDEVFN ( root.root->SegmentNumber, - 0, 0, 0 ); + range->start = PCI_BUSDEVFN ( root->SegmentNumber, 0, 0, 0 ); range->count = PCI_BUSDEVFN ( 0, 1, 0, 0 ); } @@ -259,10 +254,6 @@ static void efipci_discover ( uint32_t busdevfn, struct pci_range *range ) { static int efipci_root_open ( struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root ) { struct pci_range tmp; - union { - void *interface; - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root; - } u; int rc; /* Find matching root bridge I/O protocol handle */ @@ -271,16 +262,13 @@ static int efipci_root_open ( struct pci_device *pci, EFI_HANDLE *handle, /* Open PCI root bridge I/O protocol */ if ( ( rc = efi_open ( *handle, &efi_pci_root_bridge_io_protocol_guid, - &u.interface ) ) != 0 ) { + root ) ) != 0 ) { DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n", PCI_ARGS ( pci ), efi_handle_name ( *handle ), strerror ( rc ) ); return rc; } - /* Return opened protocol */ - *root = u.root; - return 0; } @@ -742,10 +730,7 @@ static struct dma_operations efipci_dma_operations = { * @ret rc Return status code */ int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) { - union { - EFI_PCI_IO_PROTOCOL *pci_io; - void *interface; - } pci_io; + EFI_PCI_IO_PROTOCOL *pci_io; UINTN pci_segment, pci_bus, pci_dev, pci_fn; unsigned int busdevfn; EFI_STATUS efirc; @@ -753,17 +738,16 @@ int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) { /* See if device is a PCI device */ if ( ( rc = efi_open ( device, &efi_pci_io_protocol_guid, - &pci_io.interface ) ) != 0 ) { + &pci_io ) ) != 0 ) { DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n", efi_handle_name ( device ), strerror ( rc ) ); return rc; } - efipci->io = pci_io.pci_io; + efipci->io = pci_io; /* Get PCI bus:dev.fn address */ - if ( ( efirc = pci_io.pci_io->GetLocation ( pci_io.pci_io, &pci_segment, - &pci_bus, &pci_dev, - &pci_fn ) ) != 0 ) { + if ( ( efirc = pci_io->GetLocation ( pci_io, &pci_segment, &pci_bus, + &pci_dev, &pci_fn ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( device, "EFIPCI %s could not get PCI location: %s\n", efi_handle_name ( device ), strerror ( rc ) ); @@ -781,15 +765,12 @@ int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) { * support I/O cycles). Work around any such platforms by * enabling bits individually and simply ignoring any errors. */ - pci_io.pci_io->Attributes ( pci_io.pci_io, - EfiPciIoAttributeOperationEnable, - EFI_PCI_IO_ATTRIBUTE_IO, NULL ); - pci_io.pci_io->Attributes ( pci_io.pci_io, - EfiPciIoAttributeOperationEnable, - EFI_PCI_IO_ATTRIBUTE_MEMORY, NULL ); - pci_io.pci_io->Attributes ( pci_io.pci_io, - EfiPciIoAttributeOperationEnable, - EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, NULL ); + pci_io->Attributes ( pci_io, EfiPciIoAttributeOperationEnable, + EFI_PCI_IO_ATTRIBUTE_IO, NULL ); + pci_io->Attributes ( pci_io, EfiPciIoAttributeOperationEnable, + EFI_PCI_IO_ATTRIBUTE_MEMORY, NULL ); + pci_io->Attributes ( pci_io, EfiPciIoAttributeOperationEnable, + EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, NULL ); /* Populate PCI device */ if ( ( rc = pci_read_config ( &efipci->pci ) ) != 0 ) { @@ -857,7 +838,6 @@ static int efipci_supported ( EFI_HANDLE device ) { static int efipci_start ( struct efi_device *efidev ) { EFI_HANDLE device = efidev->device; struct efi_pci_device *efipci; - void *pci_io; int rc; /* Allocate PCI device */ @@ -873,7 +853,7 @@ static int efipci_start ( struct efi_device *efidev ) { /* Open PCI I/O protocol */ if ( ( rc = efi_open_by_driver ( device, &efi_pci_io_protocol_guid, - &pci_io ) ) != 0 ) { + &efipci->io ) ) != 0 ) { DBGC ( device, "EFIPCI %s could not open PCI device: %s\n", efi_handle_name ( device ), strerror ( rc ) ); DBGC_EFI_OPENERS ( device, device, &efi_pci_io_protocol_guid ); diff --git a/src/interface/efi/efi_service.c b/src/interface/efi/efi_service.c index de7353652..f10733b24 100644 --- a/src/interface/efi/efi_service.c +++ b/src/interface/efi/efi_service.c @@ -45,15 +45,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE *handle ) { - union { - EFI_SERVICE_BINDING_PROTOCOL *sb; - void *interface; - } u; + EFI_SERVICE_BINDING_PROTOCOL *sb; EFI_STATUS efirc; int rc; /* Open service binding protocol */ - if ( ( rc = efi_open ( service, binding, &u.interface ) ) != 0 ) { + if ( ( rc = efi_open ( service, binding, &sb ) ) != 0 ) { DBGC ( service, "EFISVC %s cannot open %s binding: %s\n", efi_handle_name ( service ), efi_guid_ntoa ( binding ), strerror ( rc ) ); @@ -61,7 +58,7 @@ int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding, } /* Create child handle */ - if ( ( efirc = u.sb->CreateChild ( u.sb, handle ) ) != 0 ) { + if ( ( efirc = sb->CreateChild ( sb, handle ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( service, "EFISVC %s could not create %s child: %s\n", efi_handle_name ( service ), efi_guid_ntoa ( binding ), @@ -85,10 +82,7 @@ int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding, */ int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE handle ) { - union { - EFI_SERVICE_BINDING_PROTOCOL *sb; - void *interface; - } u; + EFI_SERVICE_BINDING_PROTOCOL *sb; EFI_STATUS efirc; int rc; @@ -97,7 +91,7 @@ int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding, DBGC ( service, "%s\n", efi_handle_name ( handle ) ); /* Open service binding protocol */ - if ( ( rc = efi_open ( service, binding, &u.interface ) ) != 0 ) { + if ( ( rc = efi_open ( service, binding, &sb ) ) != 0 ) { DBGC ( service, "EFISVC %s cannot open %s binding: %s\n", efi_handle_name ( service ), efi_guid_ntoa ( binding ), strerror ( rc ) ); @@ -105,7 +99,7 @@ int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding, } /* Destroy child handle */ - if ( ( efirc = u.sb->DestroyChild ( u.sb, handle ) ) != 0 ) { + if ( ( efirc = sb->DestroyChild ( sb, handle ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( service, "EFISVC %s could not destroy %s child ", efi_handle_name ( service ), efi_guid_ntoa ( binding ) ); diff --git a/src/interface/efi/efi_shim.c b/src/interface/efi/efi_shim.c index 02bd0791f..4bb6df79f 100644 --- a/src/interface/efi/efi_shim.c +++ b/src/interface/efi/efi_shim.c @@ -272,23 +272,20 @@ static EFIAPI EFI_STATUS efi_shim_get_memory_map ( UINTN *len, * @ret rc Return status code */ static int efi_shim_inhibit_pxe ( EFI_HANDLE handle ) { - union { - EFI_PXE_BASE_CODE_PROTOCOL *pxe; - void *interface; - } u; + EFI_PXE_BASE_CODE_PROTOCOL *pxe; EFI_STATUS efirc; int rc; /* Locate PXE base code */ if ( ( rc = efi_open ( handle, &efi_pxe_base_code_protocol_guid, - &u.interface ) ) != 0 ) { + &pxe ) ) != 0 ) { DBGC ( &efi_shim, "SHIM could not open PXE base code: %s\n", strerror ( rc ) ); return rc; } /* Stop PXE base code */ - if ( ( efirc = u.pxe->Stop ( u.pxe ) ) != 0 ) { + if ( ( efirc = pxe->Stop ( pxe ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( &efi_shim, "SHIM could not stop PXE base code: %s\n", strerror ( rc ) ); diff --git a/src/interface/efi/efi_utils.c b/src/interface/efi/efi_utils.c index 4f081b67f..51da06172 100644 --- a/src/interface/efi/efi_utils.c +++ b/src/interface/efi/efi_utils.c @@ -45,10 +45,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent, unsigned int skip ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - union { - EFI_DEVICE_PATH_PROTOCOL *path; - void *interface; - } u; + EFI_DEVICE_PATH_PROTOCOL *devpath; EFI_DEVICE_PATH_PROTOCOL *path; EFI_DEVICE_PATH_PROTOCOL *end; size_t len; @@ -57,20 +54,20 @@ int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, /* Get device path */ if ( ( rc = efi_open ( device, &efi_device_path_protocol_guid, - &u.interface ) ) != 0 ) { + &devpath ) ) != 0 ) { DBGC ( device, "EFIDEV %s cannot open device path: %s\n", efi_handle_name ( device ), strerror ( rc ) ); goto err_open_device_path; } /* Create modifiable copy of device path */ - len = ( efi_path_len ( u.path ) + sizeof ( EFI_DEVICE_PATH_PROTOCOL )); + len = ( efi_path_len ( devpath ) + sizeof ( *end ) ); path = malloc ( len ); if ( ! path ) { rc = -ENOMEM; goto err_alloc_path; } - memcpy ( path, u.path, len ); + memcpy ( path, devpath, len ); /* Locate parent device(s) */ while ( 1 ) { @@ -111,7 +108,7 @@ int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, * @ret rc Return status code */ int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child ) { - void *devpath; + EFI_DEVICE_PATH_PROTOCOL *devpath; int rc; /* Re-open the device path protocol */ diff --git a/src/interface/efi/efi_veto.c b/src/interface/efi/efi_veto.c index 637eee016..3f9c9940e 100644 --- a/src/interface/efi/efi_veto.c +++ b/src/interface/efi/efi_veto.c @@ -153,16 +153,13 @@ static int efi_veto_disconnect ( struct efi_veto *veto ) { static int efi_veto_uninstall ( struct efi_veto *veto ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE driver = veto->driver; - union { - EFI_DRIVER_BINDING_PROTOCOL *binding; - void *interface; - } binding; + EFI_DRIVER_BINDING_PROTOCOL *binding; EFI_STATUS efirc; int rc; /* Open driver binding protocol */ if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid, - &binding.interface ) ) != 0 ) { + &binding ) ) != 0 ) { DBGC ( driver, "EFIVETO %s could not open driver binding " "protocol: %s\n", efi_handle_name ( driver ), strerror ( rc ) ); @@ -172,7 +169,7 @@ static int efi_veto_uninstall ( struct efi_veto *veto ) { /* Uninstall driver binding protocol */ if ( ( efirc = bs->UninstallMultipleProtocolInterfaces ( driver, &efi_driver_binding_protocol_guid, - binding.binding, NULL ) ) != 0 ) { + binding, NULL ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( driver, "EFIVETO %s could not uninstall driver " "binding protocol: %s\n", @@ -534,22 +531,10 @@ static struct efi_veto_candidate efi_vetoes[] = { */ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer, struct efi_veto *veto ) { - union { - EFI_DRIVER_BINDING_PROTOCOL *binding; - void *interface; - } binding; - union { - EFI_LOADED_IMAGE_PROTOCOL *loaded; - void *interface; - } loaded; - union { - EFI_COMPONENT_NAME2_PROTOCOL *wtf2; - void *interface; - } wtf2; - union { - EFI_COMPONENT_NAME_PROTOCOL *wtf; - void *interface; - } wtf; + EFI_DRIVER_BINDING_PROTOCOL *binding; + EFI_LOADED_IMAGE_PROTOCOL *loaded; + EFI_COMPONENT_NAME2_PROTOCOL *wtf2; + EFI_COMPONENT_NAME_PROTOCOL *wtf; CHAR16 *name; unsigned int i; EFI_HANDLE image; @@ -561,17 +546,17 @@ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer, /* Open driver binding protocol */ if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid, - &binding.interface ) ) != 0 ) { + &binding ) ) != 0 ) { DBGC ( driver, "EFIVETO %s could not open driver binding " "protocol: %s\n", efi_handle_name ( driver ), strerror ( rc ) ); return rc; } - image = binding.binding->ImageHandle; + image = binding->ImageHandle; /* Open loaded image protocol */ if ( ( rc = efi_open ( image, &efi_loaded_image_protocol_guid, - &loaded.interface ) ) != 0 ) { + &loaded ) ) != 0 ) { DBGC ( driver, "EFIVETO %s could not open", efi_handle_name ( driver ) ); DBGC ( driver, " %s loaded image protocol: %s\n", @@ -581,23 +566,21 @@ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer, /* Open component name protocol, if present */ if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid, - &wtf2.interface ) ) != 0 ) { + &wtf2 ) ) != 0 ) { /* Ignore failure; is not required to be present */ } /* Open obsolete component name protocol, if present */ if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid, - &wtf.interface ) ) != 0 ) { + &wtf ) ) != 0 ) { /* Ignore failure; is not required to be present */ } /* Get driver name, if available */ - if ( ( wtf2.wtf2 && - ( ( efirc = wtf2.wtf2->GetDriverName ( wtf2.wtf2, "en", - &name ) == 0 ) ) ) || - ( wtf.wtf && - ( ( efirc = wtf.wtf->GetDriverName ( wtf.wtf, "eng", - &name ) == 0 ) ) ) ) { + if ( ( wtf2 && ( ( efirc = wtf2->GetDriverName ( wtf2, "en", + &name ) == 0 ) ) ) || + ( wtf && ( ( efirc = wtf->GetDriverName ( wtf, "eng", + &name ) == 0 ) ) ) ) { /* Driver has a name */ } else { /* Ignore failure; name is not required to be present */ @@ -606,19 +589,19 @@ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer, /* Check vetoes */ DBGC2 ( &efi_vetoes, "EFIVETO checking %s [%p,%p)\n", - efi_handle_name ( driver ), loaded.loaded->ImageBase, - ( loaded.loaded->ImageBase + loaded.loaded->ImageSize ) ); + efi_handle_name ( driver ), loaded->ImageBase, + ( loaded->ImageBase + loaded->ImageSize ) ); for ( i = 0 ; i < ( sizeof ( efi_vetoes ) / sizeof ( efi_vetoes[0] ) ) ; i++ ) { - if ( efi_vetoes[i].veto ( binding.binding, loaded.loaded, - manufacturer, name ) ) { + if ( efi_vetoes[i].veto ( binding, loaded, manufacturer, + name ) ) { DBGC ( driver, "EFIVETO %s is vetoed (%s)\n", efi_handle_name ( driver ), efi_vetoes[i].name ); veto->driver = driver; - veto->binding = binding.binding; + veto->binding = binding; veto->image = image; - veto->loaded = loaded.loaded; + veto->loaded = loaded; break; } } diff --git a/src/interface/efi/efi_wrap.c b/src/interface/efi/efi_wrap.c index 1cc37f3e3..a806a7c60 100644 --- a/src/interface/efi/efi_wrap.c +++ b/src/interface/efi/efi_wrap.c @@ -248,15 +248,12 @@ static int efi_prescroll ( unsigned int lines ) { * @v handle Image handle */ static void efi_dump_image ( EFI_HANDLE handle ) { - union { - EFI_LOADED_IMAGE_PROTOCOL *image; - void *intf; - } loaded; + EFI_LOADED_IMAGE_PROTOCOL *loaded; int rc; /* Open loaded image protocol */ if ( ( rc = efi_open ( handle, &efi_loaded_image_protocol_guid, - &loaded.intf ) ) != 0 ) { + &loaded ) ) != 0 ) { DBGC ( colour, "WRAP %s could not get loaded image protocol: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); return; @@ -264,14 +261,14 @@ static void efi_dump_image ( EFI_HANDLE handle ) { /* Dump image information */ DBGC ( colour, "WRAP %s at base %p has protocols:\n", - efi_handle_name ( handle ), loaded.image->ImageBase ); + efi_handle_name ( handle ), loaded->ImageBase ); DBGC_EFI_PROTOCOLS ( colour, handle ); DBGC ( colour, "WRAP %s parent", efi_handle_name ( handle ) ); - DBGC ( colour, " %s\n", efi_handle_name ( loaded.image->ParentHandle )); + DBGC ( colour, " %s\n", efi_handle_name ( loaded->ParentHandle ) ); DBGC ( colour, "WRAP %s device", efi_handle_name ( handle ) ); - DBGC ( colour, " %s\n", efi_handle_name ( loaded.image->DeviceHandle )); + DBGC ( colour, " %s\n", efi_handle_name ( loaded->DeviceHandle ) ); DBGC ( colour, "WRAP %s file", efi_handle_name ( handle ) ); - DBGC ( colour, " %s\n", efi_devpath_text ( loaded.image->FilePath ) ); + DBGC ( colour, " %s\n", efi_devpath_text ( loaded->FilePath ) ); } /**