]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Allow use of typed pointers for efi_open() et al
authorMichael Brown <mcb30@ipxe.org>
Mon, 24 Mar 2025 14:24:47 +0000 (14:24 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 24 Mar 2025 15:43:56 +0000 (15:43 +0000)
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>
23 files changed:
src/drivers/net/efi/mnpnet.c
src/drivers/net/efi/nii.c
src/drivers/net/efi/snpnet.c
src/drivers/usb/usbio.c
src/image/efi_image.c
src/include/ipxe/efi/efi.h
src/interface/efi/efi_autoboot.c
src/interface/efi/efi_block.c
src/interface/efi/efi_bofm.c
src/interface/efi/efi_cachedhcp.c
src/interface/efi/efi_console.c
src/interface/efi/efi_debug.c
src/interface/efi/efi_driver.c
src/interface/efi/efi_file.c
src/interface/efi/efi_init.c
src/interface/efi/efi_local.c
src/interface/efi/efi_open.c
src/interface/efi/efi_pci.c
src/interface/efi/efi_service.c
src/interface/efi/efi_shim.c
src/interface/efi/efi_utils.c
src/interface/efi/efi_veto.c
src/interface/efi/efi_wrap.c

index ead8691ff6761f36462ce2a836166d4fbf69947e..902eb91f37d8658f6ce4fbeb40136c849e006341 100644 (file)
@@ -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 );
index 126584effd2649a548881c46d4b0445134655b22..81f1838a4abe0812db24738d8afc15b62064169a 100644 (file)
@@ -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 );
index 93ed8cd95e5d2cf89c74fe63e43d5b8905a0c9f9..c8e2f2f6875eb9a36e9987fe4f19cf15a955a807 100644 (file)
@@ -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;
 
index db3beff215b3a1ddaa540a166af11dbf0f1b2fb6..73151c536f93363b4791023a2fc973d50063a714 100644 (file)
@@ -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 );
index ae9255ce592aa3a7015f8551f9fc44861288ca78..82101d4842d3d48ccb50d4a5a6e57d7e15bd3a06 100644 (file)
@@ -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 */
index 6126d3b8797602d2e8af5db384eab97abb8498e7..5fae87731e76e3d450c7362c6110134202c01da5 100644 (file)
@@ -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 */
index 528b84f1e6caf84aac2672d3a901885009ab965a..e52c857d829e4bc9b25c475ebe0c81af8454d7ca 100644 (file)
@@ -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 );
index 34b73c265e2483c03b8fef90269ce4053fb0a92d..5165bd804bb33bdb90a9ab8aec4477b23c90e1b6 100644 (file)
@@ -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;
index 6d97ff44588f890c5cecdce2dca03508c1bfa717..b64770d8aa5546d9fbdd5d20f4e7b610289f327a 100644 (file)
@@ -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;
index 68671d7c6810f171996293d92f792f00c5fb36bd..eb41a8e43f37708d4885f25adc8ba62a3d9455ef 100644 (file)
@@ -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 ) );
index 41c4dcf2cd9115f4431cb1648a1e68c439b41500..9fc3c65c0efe0bb106761e5c42ad822198645c75 100644 (file)
@@ -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 ) );
index fd4997cccc50b7242639cf203431396d1d91e8fa..026adc25e7a71042f2b5abf1afb8b7889c7857f6 100644 (file)
@@ -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 );
 }
 
 /**
index d143249ca2f054fa2a36fff9188ba5a7fa5ca453..56918deba91a50d4f6430ab6c1965dcb1b395b8d 100644 (file)
@@ -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 */
index d8b9f819c67d1522e13d9f50dc5eb989df04c452..b7b97aee7cce0824a7f501c4713a9642581c11ac 100644 (file)
@@ -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 )
index 03506ec5c9338fa09beefa3a0a826063cf797cea..1ba144ee7459a574092662be5e98d0cebea4eac9 100644 (file)
@@ -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 );
 
index 80cfb5a226cad15342775a8d9a9fd0d781e63e49..4564470fc9441ccf2c44e82f5f06af24b1f6cfb8 100644 (file)
@@ -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 ) );
index c85c027e1b8f4a50e112616a2ec4b179cb681347..8f8af4ea02eab7fd22b5c352000529fdad2743a1 100644 (file)
@@ -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;
index 003fa2f4a2bd199211afc62a5771b277756d40ab..0662302d29763627d999783f39acd62d4d773460 100644 (file)
@@ -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 );
index de73536522404d40b70a22ffb98094ca6a699632..f10733b24f85f4eb64188827c7aa38b72f65e022 100644 (file)
@@ -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 ) );
index 02bd0791fba32b524d3feb8794d2cdcef4032241..4bb6df79f10b05a508d7e720da5254d8a5409e9b 100644 (file)
@@ -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 ) );
index 4f081b67f0faa753961c19ae7e2b4f4814b6c0b2..51da06172ae4938d660270a6571aa5011a3231ae 100644 (file)
@@ -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 */
index 637eee01646263531f6281370e922a5c7e7c3211..3f9c9940e67833ae5b63d2310f1e57938e0e860a 100644 (file)
@@ -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;
                }
        }
index 1cc37f3e37dbdcd949c9e59151b1bd1f654dedb5..a806a7c60c872014f964e246a60956920c54f63f 100644 (file)
@@ -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 ) );
 }
 
 /**