summaryrefslogtreecommitdiffstats
path: root/src/interface/efi
diff options
context:
space:
mode:
authorMichael Brown2025-03-24 15:24:47 +0100
committerMichael Brown2025-03-24 16:43:56 +0100
commit32a9408217810498deeeae3d2564ab15468c9c39 (patch)
treee39162f48abd5a12dd664af9ba057bb6131bb626 /src/interface/efi
parent[efi] Eliminate uses of HandleProtocol() (diff)
downloadipxe-32a9408217810498deeeae3d2564ab15468c9c39.tar.gz
ipxe-32a9408217810498deeeae3d2564ab15468c9c39.tar.xz
ipxe-32a9408217810498deeeae3d2564ab15468c9c39.zip
[efi] Allow use of typed pointers for efi_open() et al
Provide wrapper macros to allow efi_open() and related functions to accept a pointer to any pointer type as the "interface" argument, in order to allow a substantial amount of type adjustment boilerplate to be removed. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/interface/efi')
-rw-r--r--src/interface/efi/efi_autoboot.c9
-rw-r--r--src/interface/efi/efi_block.c40
-rw-r--r--src/interface/efi/efi_bofm.c3
-rw-r--r--src/interface/efi/efi_cachedhcp.c9
-rw-r--r--src/interface/efi/efi_console.c7
-rw-r--r--src/interface/efi/efi_debug.c18
-rw-r--r--src/interface/efi/efi_driver.c23
-rw-r--r--src/interface/efi/efi_file.c11
-rw-r--r--src/interface/efi/efi_init.c6
-rw-r--r--src/interface/efi/efi_local.c9
-rw-r--r--src/interface/efi/efi_open.c15
-rw-r--r--src/interface/efi/efi_pci.c58
-rw-r--r--src/interface/efi/efi_service.c18
-rw-r--r--src/interface/efi/efi_shim.c9
-rw-r--r--src/interface/efi/efi_utils.c13
-rw-r--r--src/interface/efi/efi_veto.c61
-rw-r--r--src/interface/efi/efi_wrap.c15
17 files changed, 113 insertions, 211 deletions
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 ) );
}
/**