[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>
pull/34/merge
Michael Brown 2025-03-24 14:24:47 +00:00
parent 37897fbd40
commit 32a9408217
23 changed files with 215 additions and 277 deletions

View File

@ -370,10 +370,6 @@ int mnpnet_start ( struct efi_device *efidev ) {
EFI_HANDLE device = efidev->device; EFI_HANDLE device = efidev->device;
EFI_GUID *binding = &efi_managed_network_service_binding_protocol_guid; EFI_GUID *binding = &efi_managed_network_service_binding_protocol_guid;
EFI_SIMPLE_NETWORK_MODE mode; EFI_SIMPLE_NETWORK_MODE mode;
union {
EFI_MANAGED_NETWORK_PROTOCOL *mnp;
void *interface;
} u;
struct net_device *netdev; struct net_device *netdev;
struct mnp_nic *mnp; struct mnp_nic *mnp;
EFI_STATUS efirc; EFI_STATUS efirc;
@ -409,12 +405,11 @@ int mnpnet_start ( struct efi_device *efidev ) {
/* Open MNP protocol */ /* Open MNP protocol */
if ( ( rc = efi_open_by_driver ( efidev->child, if ( ( rc = efi_open_by_driver ( efidev->child,
&efi_managed_network_protocol_guid, &efi_managed_network_protocol_guid,
&u.interface ) ) != 0 ) { &mnp->mnp ) ) != 0 ) {
DBGC ( mnp, "MNP %s could not open MNP protocol: %s\n", DBGC ( mnp, "MNP %s could not open MNP protocol: %s\n",
efi_handle_name ( device ), strerror ( rc ) ); efi_handle_name ( device ), strerror ( rc ) );
goto err_open; goto err_open;
} }
mnp->mnp = u.mnp;
/* Get configuration */ /* Get configuration */
efirc = mnp->mnp->GetModeData ( mnp->mnp, NULL, &mode ); efirc = mnp->mnp->GetModeData ( mnp->mnp, NULL, &mode );

View File

@ -209,10 +209,6 @@ static int nii_pci_open ( struct nii_nic *nii ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE device = nii->efidev->device; EFI_HANDLE device = nii->efidev->device;
EFI_HANDLE pci_device; EFI_HANDLE pci_device;
union {
EFI_PCI_IO_PROTOCOL *pci_io;
void *interface;
} pci_io;
union { union {
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *acpi; EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *acpi;
void *resource; void *resource;
@ -237,12 +233,11 @@ static int nii_pci_open ( struct nii_nic *nii ) {
* therefore use an unsafe open. * therefore use an unsafe open.
*/ */
if ( ( rc = efi_open_unsafe ( pci_device, &efi_pci_io_protocol_guid, 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", DBGC ( nii, "NII %s could not open PCI I/O protocol: %s\n",
nii->dev.name, strerror ( rc ) ); nii->dev.name, strerror ( rc ) );
goto err_open; goto err_open;
} }
nii->pci_io = pci_io.pci_io;
/* Identify memory and I/O BARs */ /* Identify memory and I/O BARs */
nii->mem_bar = PCI_MAX_BAR; nii->mem_bar = PCI_MAX_BAR;
@ -1272,7 +1267,6 @@ int nii_start ( struct efi_device *efidev ) {
EFI_HANDLE device = efidev->device; EFI_HANDLE device = efidev->device;
struct net_device *netdev; struct net_device *netdev;
struct nii_nic *nii; struct nii_nic *nii;
void *interface;
int rc; int rc;
/* Allocate and initialise structure */ /* Allocate and initialise structure */
@ -1298,13 +1292,12 @@ int nii_start ( struct efi_device *efidev ) {
/* Open NII protocol */ /* Open NII protocol */
if ( ( rc = efi_open_by_driver ( device, &efi_nii31_protocol_guid, 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", DBGC ( nii, "NII %s cannot open NII protocol: %s\n",
nii->dev.name, strerror ( rc ) ); nii->dev.name, strerror ( rc ) );
DBGC_EFI_OPENERS ( device, device, &efi_nii31_protocol_guid ); DBGC_EFI_OPENERS ( device, device, &efi_nii31_protocol_guid );
goto err_open_protocol; goto err_open_protocol;
} }
nii->nii = interface;
/* Locate UNDI and entry point */ /* Locate UNDI and entry point */
nii->undi = ( ( void * ) ( intptr_t ) nii->nii->Id ); nii->undi = ( ( void * ) ( intptr_t ) nii->nii->Id );

View File

@ -504,7 +504,7 @@ int snpnet_supported ( EFI_HANDLE device, EFI_GUID *protocol ) {
} }
/* Test for presence of 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", DBGCP ( device, "HANDLE %s is not a %s device\n",
efi_handle_name ( device ), efi_handle_name ( device ),
efi_guid_ntoa ( protocol ) ); efi_guid_ntoa ( protocol ) );
@ -536,10 +536,10 @@ int snpnet_supported ( EFI_HANDLE device, EFI_GUID *protocol ) {
*/ */
int snpnet_start ( struct efi_device *efidev ) { int snpnet_start ( struct efi_device *efidev ) {
EFI_HANDLE device = efidev->device; EFI_HANDLE device = efidev->device;
EFI_SIMPLE_NETWORK_PROTOCOL *interface;
EFI_SIMPLE_NETWORK_MODE *mode; EFI_SIMPLE_NETWORK_MODE *mode;
struct net_device *netdev; struct net_device *netdev;
struct snp_nic *snp; struct snp_nic *snp;
void *interface;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; int rc;

View 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 *path;
EFI_DEVICE_PATH_PROTOCOL *end; EFI_DEVICE_PATH_PROTOCOL *end;
USB_DEVICE_PATH *usbpath; USB_DEVICE_PATH *usbpath;
union {
void *interface;
EFI_USB_IO_PROTOCOL *io;
} u;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; 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 */ /* Open USB I/O protocol on this handle */
if ( ( rc = efi_open_by_driver ( intf->handle, if ( ( rc = efi_open_by_driver ( intf->handle,
&efi_usb_io_protocol_guid, &efi_usb_io_protocol_guid,
&u.interface ) ) != 0 ) { &intf->io ) ) != 0 ) {
DBGC ( usbio, "USBIO %s cannot open ", DBGC ( usbio, "USBIO %s cannot open ",
efi_handle_name ( handle ) ); efi_handle_name ( handle ) );
DBGC ( usbio, "%s: %s\n", 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 ); &efi_usb_io_protocol_guid );
return rc; return rc;
} }
intf->io = u.io;
/* Increment usage count */ /* Increment usage count */
intf->count++; intf->count++;
@ -1296,24 +1291,20 @@ static int usbio_supported ( EFI_HANDLE handle ) {
struct usb_function_descriptor desc; struct usb_function_descriptor desc;
struct usb_driver *driver; struct usb_driver *driver;
struct usb_device_id *id; struct usb_device_id *id;
union { EFI_USB_IO_PROTOCOL *io;
void *interface;
EFI_USB_IO_PROTOCOL *io;
} usb;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; int rc;
/* Get protocol */ /* Get protocol */
if ( ( rc = efi_open ( handle, &efi_usb_io_protocol_guid, 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", DBGCP ( handle, "USB %s is not a USB device\n",
efi_handle_name ( handle ) ); efi_handle_name ( handle ) );
return rc; return rc;
} }
/* Get device descriptor */ /* Get device descriptor */
if ( ( efirc = usb.io->UsbGetDeviceDescriptor ( usb.io, if ( ( efirc = io->UsbGetDeviceDescriptor ( io, &device ) ) != 0 ) {
&device ) ) != 0 ) {
rc = -EEFI ( efirc ); rc = -EEFI ( efirc );
DBGC ( handle, "USB %s could not get device descriptor: " DBGC ( handle, "USB %s could not get device descriptor: "
"%s\n", efi_handle_name ( handle ), strerror ( rc ) ); "%s\n", efi_handle_name ( handle ), strerror ( rc ) );
@ -1324,8 +1315,7 @@ static int usbio_supported ( EFI_HANDLE handle ) {
desc.product = device.IdProduct; desc.product = device.IdProduct;
/* Get interface descriptor */ /* Get interface descriptor */
if ( ( efirc = usb.io->UsbGetInterfaceDescriptor ( usb.io, if ( ( efirc = io->UsbGetInterfaceDescriptor ( io, &interface ) ) != 0){
&interface ) ) !=0){
rc = -EEFI ( efirc ); rc = -EEFI ( efirc );
DBGC ( handle, "USB %s could not get interface descriptor: " DBGC ( handle, "USB %s could not get interface descriptor: "
"%s\n", efi_handle_name ( handle ), strerror ( rc ) ); "%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 *path;
EFI_DEVICE_PATH_PROTOCOL *end; EFI_DEVICE_PATH_PROTOCOL *end;
USB_DEVICE_PATH *usbpath; USB_DEVICE_PATH *usbpath;
union {
void *interface;
EFI_DEVICE_PATH_PROTOCOL *path;
} u;
size_t len; size_t len;
int rc; int rc;
/* Open device path protocol */ /* Open device path protocol */
if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid,
&u.interface ) ) != 0 ) { &path ) ) != 0 ) {
DBGC ( usbio, "USBIO %s cannot open device path protocol: " DBGC ( usbio, "USBIO %s cannot open device path protocol: "
"%s\n", efi_handle_name ( handle ), strerror ( rc ) ); "%s\n", efi_handle_name ( handle ), strerror ( rc ) );
return rc; return rc;
} }
path = u.interface;
/* Locate end of device path and sanity check */ /* Locate end of device path and sanity check */
len = efi_path_len ( path ); len = efi_path_len ( path );
@ -1567,10 +1552,6 @@ static int usbio_start ( struct efi_device *efidev ) {
EFI_HANDLE handle = efidev->device; EFI_HANDLE handle = efidev->device;
struct usbio_device *usbio; struct usbio_device *usbio;
struct usb_port *port; struct usb_port *port;
union {
void *interface;
EFI_USB_IO_PROTOCOL *io;
} u;
int rc; int rc;
/* Allocate and initialise structure */ /* Allocate and initialise structure */
@ -1585,13 +1566,12 @@ static int usbio_start ( struct efi_device *efidev ) {
/* Open USB I/O protocol */ /* Open USB I/O protocol */
if ( ( rc = efi_open_by_driver ( handle, &efi_usb_io_protocol_guid, 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", DBGC ( usbio, "USBIO %s cannot open USB I/O protocol: %s\n",
efi_handle_name ( handle ), strerror ( rc ) ); efi_handle_name ( handle ), strerror ( rc ) );
DBGC_EFI_OPENERS ( usbio, handle, &efi_usb_io_protocol_guid ); DBGC_EFI_OPENERS ( usbio, handle, &efi_usb_io_protocol_guid );
goto err_open_usbio; goto err_open_usbio;
} }
usbio->io = u.io;
/* Describe generic device */ /* Describe generic device */
efi_device_info ( handle, "USB", &usbio->dev ); efi_device_info ( handle, "USB", &usbio->dev );

View File

@ -132,10 +132,7 @@ static int efi_image_exec ( struct image *image ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_snp_device *snpdev; struct efi_snp_device *snpdev;
EFI_DEVICE_PATH_PROTOCOL *path; EFI_DEVICE_PATH_PROTOCOL *path;
union { EFI_LOADED_IMAGE_PROTOCOL *loaded;
EFI_LOADED_IMAGE_PROTOCOL *image;
void *interface;
} loaded;
struct image *shim; struct image *shim;
struct image *exec; struct image *exec;
EFI_HANDLE handle; 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 */ /* Get the loaded image protocol for the newly loaded image */
if ( ( rc = efi_open ( handle, &efi_loaded_image_protocol_guid, if ( ( rc = efi_open ( handle, &efi_loaded_image_protocol_guid,
&loaded.interface ) ) != 0 ) { &loaded ) ) != 0 ) {
/* Should never happen */ /* Should never happen */
goto err_open_protocol; goto err_open_protocol;
} }
/* Some EFI 1.10 implementations seem not to fill in DeviceHandle */ /* 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", DBGC ( image, "EFIIMAGE %s filling in missing DeviceHandle\n",
image->name ); image->name );
loaded.image->DeviceHandle = snpdev->handle; loaded->DeviceHandle = snpdev->handle;
} }
/* Sanity checks */ /* Sanity checks */
assert ( loaded.image->ParentHandle == efi_image_handle ); assert ( loaded->ParentHandle == efi_image_handle );
assert ( loaded.image->DeviceHandle == snpdev->handle ); assert ( loaded->DeviceHandle == snpdev->handle );
assert ( loaded.image->LoadOptionsSize == 0 ); assert ( loaded->LoadOptionsSize == 0 );
assert ( loaded.image->LoadOptions == NULL ); assert ( loaded->LoadOptions == NULL );
/* Record image code type */ /* Record image code type */
type = loaded.image->ImageCodeType; type = loaded->ImageCodeType;
/* Set command line */ /* Set command line */
loaded.image->LoadOptions = cmdline; loaded->LoadOptions = cmdline;
loaded.image->LoadOptionsSize = loaded->LoadOptionsSize =
( ( wcslen ( cmdline ) + 1 /* NUL */ ) * sizeof ( wchar_t ) ); ( ( wcslen ( cmdline ) + 1 /* NUL */ ) * sizeof ( wchar_t ) );
/* Release network devices for use via SNP */ /* Release network devices for use via SNP */

View File

@ -389,17 +389,88 @@ extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
EFI_SYSTEM_TABLE *systab ); EFI_SYSTEM_TABLE *systab );
extern void efi_raise_tpl ( struct efi_saved_tpl *tpl ); extern void efi_raise_tpl ( struct efi_saved_tpl *tpl );
extern void efi_restore_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, extern int efi_open_untyped ( EFI_HANDLE handle, EFI_GUID *protocol,
void **interface ); void **interface );
extern int efi_open_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol, extern int efi_open_unsafe_untyped ( EFI_HANDLE handle, EFI_GUID *protocol,
void **interface ); void **interface );
extern void efi_close_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol ); extern void efi_close_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol );
extern int efi_open_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol, extern int efi_open_by_driver_untyped ( EFI_HANDLE handle, EFI_GUID *protocol,
void **interface ); void **interface );
extern void efi_close_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol ); extern void efi_close_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol );
extern int efi_open_by_child ( EFI_HANDLE handle, EFI_GUID *protocol, extern int efi_open_by_child_untyped ( EFI_HANDLE handle, EFI_GUID *protocol,
EFI_HANDLE child, void **interface ); EFI_HANDLE child, void **interface );
extern void efi_close_by_child ( EFI_HANDLE handle, EFI_GUID *protocol, extern void efi_close_by_child ( EFI_HANDLE handle, EFI_GUID *protocol,
EFI_HANDLE child ); 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 */ #endif /* _IPXE_EFI_H */

View File

@ -48,24 +48,21 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*/ */
int efi_set_autoboot_ll_addr ( EFI_HANDLE device, int efi_set_autoboot_ll_addr ( EFI_HANDLE device,
EFI_DEVICE_PATH_PROTOCOL *path ) { EFI_DEVICE_PATH_PROTOCOL *path ) {
union { EFI_SIMPLE_NETWORK_PROTOCOL *snp;
EFI_SIMPLE_NETWORK_PROTOCOL *snp;
void *interface;
} snp;
EFI_SIMPLE_NETWORK_MODE *mode; EFI_SIMPLE_NETWORK_MODE *mode;
unsigned int vlan; unsigned int vlan;
int rc; int rc;
/* Look for an SNP instance on the image's device handle */ /* Look for an SNP instance on the image's device handle */
if ( ( rc = efi_open ( device, &efi_simple_network_protocol_guid, 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", DBGC ( device, "EFI %s has no SNP instance: %s\n",
efi_handle_name ( device ), strerror ( rc ) ); efi_handle_name ( device ), strerror ( rc ) );
return rc; return rc;
} }
/* Record autoboot device */ /* Record autoboot device */
mode = snp.snp->Mode; mode = snp->Mode;
vlan = efi_path_vlan ( path ); vlan = efi_path_vlan ( path );
set_autoboot_ll_addr ( &mode->CurrentAddress, mode->HwAddressSize, set_autoboot_ll_addr ( &mode->CurrentAddress, mode->HwAddressSize,
vlan ); vlan );

View File

@ -518,23 +518,20 @@ static int efi_block_describe ( void ) {
*/ */
static int efi_block_root ( unsigned int drive, EFI_HANDLE handle, static int efi_block_root ( unsigned int drive, EFI_HANDLE handle,
EFI_FILE_PROTOCOL **root ) { EFI_FILE_PROTOCOL **root ) {
union { EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
void *interface;
} u;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; int rc;
/* Open filesystem protocol */ /* Open filesystem protocol */
if ( ( rc = efi_open ( handle, &efi_simple_file_system_protocol_guid, 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", DBGC ( drive, "EFIBLK %#02x could not open %s filesystem: %s\n",
drive, efi_handle_name ( handle ), strerror ( rc ) ); drive, efi_handle_name ( handle ), strerror ( rc ) );
return rc; return rc;
} }
/* Open root volume */ /* Open root volume */
if ( ( efirc = u.fs->OpenVolume ( u.fs, root ) ) != 0 ) { if ( ( efirc = fs->OpenVolume ( fs, root ) ) != 0 ) {
rc = -EEFI ( efirc ); rc = -EEFI ( efirc );
DBGC ( drive, "EFIBLK %#02x could not open %s root: %s\n", DBGC ( drive, "EFIBLK %#02x could not open %s root: %s\n",
drive, efi_handle_name ( handle ), strerror ( rc ) ); 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, EFI_DEVICE_PATH_PROTOCOL *path,
struct san_boot_config *config, struct san_boot_config *config,
EFI_DEVICE_PATH_PROTOCOL **fspath ) { EFI_DEVICE_PATH_PROTOCOL **fspath ) {
union {
EFI_DEVICE_PATH_PROTOCOL *path;
void *interface;
} u;
EFI_FILE *root; EFI_FILE *root;
union uuid guid; union uuid guid;
int rc; int rc;
/* Identify device path */ /* Identify device path */
if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, 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: " DBGC ( drive, "EFIBLK %#02x could not open %s device path: "
"%s\n", drive, efi_handle_name ( handle ), "%s\n", drive, efi_handle_name ( handle ),
strerror ( rc ) ); strerror ( rc ) );
goto err_open; goto err_open;
} }
*fspath = u.path;
/* Check if filesystem is a child of this block device */ /* 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 */ /* Not a child device */
rc = -ENOTTY; rc = -ENOTTY;
DBGC2 ( drive, "EFIBLK %#02x is not parent of %s\n", 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; goto err_not_child;
} }
DBGC ( drive, "EFIBLK %#02x contains filesystem %s\n", 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 */ /* Check if filesystem matches GUID, if applicable */
if ( config->uuid ) { 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: " DBGC ( drive, "EFIBLK %#02x could not determine GUID: "
"%s\n", drive, strerror ( rc ) ); "%s\n", drive, strerror ( rc ) );
goto err_no_guid; goto err_no_guid;
@ -760,10 +752,7 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle,
struct san_boot_config *config, struct san_boot_config *config,
EFI_DEVICE_PATH_PROTOCOL **fspath ) { EFI_DEVICE_PATH_PROTOCOL **fspath ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union { EFI_DEVICE_PATH_PROTOCOL *path;
EFI_DEVICE_PATH_PROTOCOL *path;
void *interface;
} u;
EFI_HANDLE *handles; EFI_HANDLE *handles;
UINTN count; UINTN count;
unsigned int i; unsigned int i;
@ -775,7 +764,7 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle,
/* Identify device path */ /* Identify device path */
if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, 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", DBGC ( drive, "EFIBLK %#02x could not open device path: %s\n",
drive, strerror ( rc ) ); drive, strerror ( rc ) );
goto err_open; goto err_open;
@ -796,7 +785,7 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle,
for ( i = 0 ; i < count ; i++ ) { for ( i = 0 ; i < count ; i++ ) {
/* Check for a matching filesystem */ /* 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 ) config, fspath ) ) != 0 )
continue; continue;
@ -903,10 +892,7 @@ static int efi_block_exec ( unsigned int drive,
static int efi_block_local ( EFI_HANDLE handle ) { static int efi_block_local ( EFI_HANDLE handle ) {
struct san_device *sandev; struct san_device *sandev;
struct efi_block_data *block; struct efi_block_data *block;
union { EFI_BLOCK_IO_PROTOCOL *blockio;
EFI_BLOCK_IO_PROTOCOL *blockio;
void *interface;
} u;
int rc; int rc;
/* Check if handle belongs to a SAN device */ /* 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 */ /* Open block I/O protocol */
if ( ( rc = efi_open ( handle, &efi_block_io_protocol_guid, 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", DBGC ( handle, "EFIBLK %s could not open block I/O: %s\n",
efi_handle_name ( handle ), strerror ( rc ) ); efi_handle_name ( handle ), strerror ( rc ) );
return rc; return rc;
} }
/* Do not assign drive numbers for partitions */ /* Do not assign drive numbers for partitions */
if ( u.blockio->Media->LogicalPartition ) { if ( blockio->Media->LogicalPartition ) {
DBGC2 ( handle, "EFLBLK %s is a partition\n", DBGC2 ( handle, "EFLBLK %s is a partition\n",
efi_handle_name ( handle ) ); efi_handle_name ( handle ) );
return -ENOTTY; return -ENOTTY;

View File

@ -228,7 +228,6 @@ static int efi_bofm_start ( struct efi_device *efidev ) {
struct efi_pci_device efipci; struct efi_pci_device efipci;
IBM_BOFM_TABLE *bofmtab; IBM_BOFM_TABLE *bofmtab;
IBM_BOFM_TABLE *bofmtab2; IBM_BOFM_TABLE *bofmtab2;
void *pci_io;
int bofmrc; int bofmrc;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; int rc;
@ -242,7 +241,7 @@ static int efi_bofm_start ( struct efi_device *efidev ) {
/* Open PCI I/O protocol */ /* Open PCI I/O protocol */
if ( ( rc = efi_open_unsafe ( device, &efi_pci_io_protocol_guid, 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", DBGC ( device, "EFIBOFM %s cannot open PCI device: %s\n",
efi_handle_name ( device ), strerror ( rc ) ); efi_handle_name ( device ), strerror ( rc ) );
goto err_open; goto err_open;

View File

@ -47,10 +47,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
int efi_cachedhcp_record ( EFI_HANDLE device, int efi_cachedhcp_record ( EFI_HANDLE device,
EFI_DEVICE_PATH_PROTOCOL *path ) { EFI_DEVICE_PATH_PROTOCOL *path ) {
unsigned int vlan; unsigned int vlan;
union { EFI_PXE_BASE_CODE_PROTOCOL *pxe;
EFI_PXE_BASE_CODE_PROTOCOL *pxe;
void *interface;
} pxe;
EFI_PXE_BASE_CODE_MODE *mode; EFI_PXE_BASE_CODE_MODE *mode;
int rc; 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 */ /* Look for a PXE base code instance on the image's device handle */
if ( ( rc = efi_open ( device, &efi_pxe_base_code_protocol_guid, 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", DBGC ( device, "EFI %s has no PXE base code instance: %s\n",
efi_handle_name ( device ), strerror ( rc ) ); efi_handle_name ( device ), strerror ( rc ) );
return rc; return rc;
} }
/* Do not attempt to cache IPv6 packets */ /* Do not attempt to cache IPv6 packets */
mode = pxe.pxe->Mode; mode = pxe->Mode;
if ( mode->UsingIpv6 ) { if ( mode->UsingIpv6 ) {
DBGC ( device, "EFI %s has IPv6 PXE base code\n", DBGC ( device, "EFI %s has IPv6 PXE base code\n",
efi_handle_name ( device ) ); efi_handle_name ( device ) );

View File

@ -416,10 +416,6 @@ struct console_driver efi_console __console_driver = {
*/ */
static void efi_console_init ( void ) { static void efi_console_init ( void ) {
EFI_CONSOLE_CONTROL_SCREEN_MODE mode; EFI_CONSOLE_CONTROL_SCREEN_MODE mode;
union {
void *interface;
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *wtf;
} u;
int rc; int rc;
/* On some older EFI 1.10 implementations, we must use the /* 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, if ( ( rc = efi_open_unsafe ( efi_systab->ConsoleInHandle,
&efi_simple_text_input_ex_protocol_guid, &efi_simple_text_input_ex_protocol_guid,
&u.interface ) ) == 0 ) { &efi_conin_ex ) ) == 0 ) {
efi_conin_ex = u.wtf;
DBG ( "EFI using SimpleTextInputEx\n" ); DBG ( "EFI using SimpleTextInputEx\n" );
} else { } else {
DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) ); DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) );

View File

@ -324,10 +324,7 @@ static const char * efi_driver_name2 ( EFI_COMPONENT_NAME2_PROTOCOL *wtf ) {
* @ret name Driver name, or NULL * @ret name Driver name, or NULL
*/ */
static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) { static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) {
union { EFI_COMPONENT_NAME_PROTOCOL *name;
EFI_COMPONENT_NAME_PROTOCOL *name;
void *interface;
} u;
EFI_HANDLE image; EFI_HANDLE image;
int rc; 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 */ /* Try to open component name protocol on image handle */
image = binding->ImageHandle; image = binding->ImageHandle;
if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid, if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid,
&u.interface ) ) != 0 ) { &name ) ) != 0 ) {
DBG ( "[DriverBinding no ComponentName]" ); DBG ( "[DriverBinding no ComponentName]" );
return NULL; return NULL;
} }
/* Try to get name from component name protocol */ /* 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 ){ static const char * efi_binding_name2 ( EFI_DRIVER_BINDING_PROTOCOL *binding ){
EFI_HANDLE image; EFI_HANDLE image;
union { EFI_COMPONENT_NAME2_PROTOCOL *name2;
EFI_COMPONENT_NAME2_PROTOCOL *name2;
void *interface;
} u;
int rc; int rc;
/* Sanity check */ /* 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 */ /* Try to open component name protocol on image handle */
image = binding->ImageHandle; image = binding->ImageHandle;
if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid, if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid,
&u.interface ) ) != 0 ) { &name2 ) ) != 0 ) {
DBG ( "[DriverBinding no ComponentName2]" ); DBG ( "[DriverBinding no ComponentName2]" );
return NULL; return NULL;
} }
/* Try to get name from component name protocol */ /* Try to get name from component name protocol */
return efi_driver_name2 ( u.name2 ); return efi_driver_name2 ( name2 );
} }
/** /**

View File

@ -69,22 +69,19 @@ static int efi_driver_disconnecting;
*/ */
struct efi_device * efidev_alloc ( EFI_HANDLE device ) { struct efi_device * efidev_alloc ( EFI_HANDLE device ) {
struct efi_device *efidev = NULL; struct efi_device *efidev = NULL;
union { EFI_DEVICE_PATH_PROTOCOL *path;
EFI_DEVICE_PATH_PROTOCOL *path;
void *interface;
} path;
EFI_DEVICE_PATH_PROTOCOL *path_end; EFI_DEVICE_PATH_PROTOCOL *path_end;
size_t path_len; size_t path_len;
int rc; int rc;
/* Open device path */ /* Open device path */
if ( ( rc = efi_open ( device, &efi_device_path_protocol_guid, 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", DBGC ( device, "EFIDRV %s could not open device path: %s\n",
efi_handle_name ( device ), strerror ( rc ) ); efi_handle_name ( device ), strerror ( rc ) );
return NULL; 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 */ /* Allocate and initialise structure */
efidev = zalloc ( sizeof ( *efidev ) + path_len ); efidev = zalloc ( sizeof ( *efidev ) + path_len );
@ -93,7 +90,7 @@ struct efi_device * efidev_alloc ( EFI_HANDLE device ) {
efidev->device = device; efidev->device = device;
efidev->dev.desc.bus_type = BUS_TYPE_EFI; efidev->dev.desc.bus_type = BUS_TYPE_EFI;
efidev->path = ( ( ( void * ) efidev ) + sizeof ( *efidev ) ); 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 ); INIT_LIST_HEAD ( &efidev->dev.children );
list_add ( &efidev->dev.siblings, &efi_devices ); 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_driver_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused,
EFI_HANDLE device, EFI_HANDLE child, EFI_HANDLE device, EFI_HANDLE child,
CHAR8 *language, CHAR16 **controller_name ) { CHAR8 *language, CHAR16 **controller_name ) {
union { EFI_COMPONENT_NAME2_PROTOCOL *name2;
EFI_COMPONENT_NAME2_PROTOCOL *name2;
void *interface;
} name2;
int rc; int rc;
/* Delegate to the EFI_COMPONENT_NAME2_PROTOCOL instance /* 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 ) && if ( ( child != NULL ) &&
( ( rc = efi_open ( child, &efi_component_name2_protocol_guid, ( ( rc = efi_open ( child, &efi_component_name2_protocol_guid,
&name2.interface ) ) == 0 ) ) { &name2 ) ) == 0 ) ) {
return name2.name2->GetControllerName ( name2.name2, device, return name2->GetControllerName ( name2, device, child,
child, language, language, controller_name );
controller_name );
} }
/* Otherwise, let EFI use the default Device Path Name */ /* Otherwise, let EFI use the default Device Path Name */

View 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 ) { static int efi_file_path_claim ( struct efi_file_path *file ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_DEVICE_PATH_PROTOCOL *old;
EFI_DEVICE_PATH_PROTOCOL *end; EFI_DEVICE_PATH_PROTOCOL *end;
EFI_HANDLE handle; EFI_HANDLE handle;
VOID *old;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; int rc;
@ -1116,10 +1116,7 @@ static void efi_file_path_uninstall ( struct efi_file_path *file ) {
*/ */
int efi_file_install ( EFI_HANDLE handle ) { int efi_file_install ( EFI_HANDLE handle ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union { EFI_DISK_IO_PROTOCOL *diskio;
EFI_DISK_IO_PROTOCOL *diskio;
void *interface;
} diskio;
struct image *image; struct image *image;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; int rc;
@ -1168,13 +1165,13 @@ int efi_file_install ( EFI_HANDLE handle ) {
* shell. I have no idea why this is. * shell. I have no idea why this is.
*/ */
if ( ( rc = efi_open_by_driver ( handle, &efi_disk_io_protocol_guid, 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", DBGC ( handle, "Could not open disk I/O protocol: %s\n",
strerror ( rc ) ); strerror ( rc ) );
DBGC_EFI_OPENERS ( handle, handle, &efi_disk_io_protocol_guid ); DBGC_EFI_OPENERS ( handle, handle, &efi_disk_io_protocol_guid );
goto err_open; goto err_open;
} }
assert ( diskio.diskio == &efi_disk_io_protocol ); assert ( diskio == &efi_disk_io_protocol );
/* Claim Linux initrd fixed device path */ /* Claim Linux initrd fixed device path */
if ( ( rc = efi_file_path_claim ( &efi_file_initrd ) ) != 0 ) if ( ( rc = efi_file_path_claim ( &efi_file_initrd ) ) != 0 )

View File

@ -173,8 +173,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
EFI_BOOT_SERVICES *bs; EFI_BOOT_SERVICES *bs;
struct efi_protocol *prot; struct efi_protocol *prot;
struct efi_config_table *tab; struct efi_config_table *tab;
void *loaded_image; EFI_DEVICE_PATH_PROTOCOL *device_path;
void *device_path;
void *device_path_copy; void *device_path_copy;
size_t device_path_len; size_t device_path_len;
EFI_STATUS efirc; EFI_STATUS efirc;
@ -248,13 +247,12 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle,
*/ */
if ( ( rc = efi_open_unsafe ( image_handle, if ( ( rc = efi_open_unsafe ( image_handle,
&efi_loaded_image_protocol_guid, &efi_loaded_image_protocol_guid,
&loaded_image ) ) != 0 ) { &efi_loaded_image ) ) != 0 ) {
DBGC ( systab, "EFI could not get loaded image protocol: %s", DBGC ( systab, "EFI could not get loaded image protocol: %s",
strerror ( rc ) ); strerror ( rc ) );
efirc = EFIRC ( rc ); efirc = EFIRC ( rc );
goto err_no_loaded_image; goto err_no_loaded_image;
} }
efi_loaded_image = loaded_image;
DBGC ( systab, "EFI image base address %p\n", DBGC ( systab, "EFI image base address %p\n",
efi_loaded_image->ImageBase ); efi_loaded_image->ImageBase );

View 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, static int efi_local_open_root ( struct efi_local *local, EFI_HANDLE device,
EFI_FILE_PROTOCOL **root ) { EFI_FILE_PROTOCOL **root ) {
union { EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
void *interface;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
} u;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; int rc;
/* Open file system protocol */ /* Open file system protocol */
if ( ( rc = efi_open ( device, &efi_simple_file_system_protocol_guid, 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", DBGC ( local, "LOCAL %p could not open filesystem on %s: %s\n",
local, efi_handle_name ( device ), strerror ( rc ) ); local, efi_handle_name ( device ), strerror ( rc ) );
return rc; return rc;
} }
/* Open root directory */ /* Open root directory */
if ( ( efirc = u.fs->OpenVolume ( u.fs, root ) ) != 0 ) { if ( ( efirc = fs->OpenVolume ( fs, root ) ) != 0 ) {
rc = -EEFI ( efirc ); rc = -EEFI ( efirc );
DBGC ( local, "LOCAL %p could not open volume on %s: %s\n", DBGC ( local, "LOCAL %p could not open volume on %s: %s\n",
local, efi_handle_name ( device ), strerror ( rc ) ); local, efi_handle_name ( device ), strerror ( rc ) );

View File

@ -93,7 +93,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
* @v interface Protocol interface pointer to fill in (or NULL to test) * @v interface Protocol interface pointer to fill in (or NULL to test)
* @ret rc Return status code * @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_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE agent = efi_image_handle; EFI_HANDLE agent = efi_image_handle;
EFI_HANDLE controller; 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 * @v interface Protocol interface pointer to fill in
* @ret rc Return status code * @ret rc Return status code
*/ */
int efi_open_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol, int efi_open_unsafe_untyped ( EFI_HANDLE handle, EFI_GUID *protocol,
void **interface ) { void **interface ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE agent = efi_image_handle; EFI_HANDLE agent = efi_image_handle;
EFI_HANDLE controller; 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 * @v interface Protocol interface pointer to fill in
* @ret rc Return status code * @ret rc Return status code
*/ */
int efi_open_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol, int efi_open_by_driver_untyped ( EFI_HANDLE handle, EFI_GUID *protocol,
void **interface ) { void **interface ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE agent = efi_image_handle; EFI_HANDLE agent = efi_image_handle;
EFI_HANDLE controller; 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 * @v interface Protocol interface pointer to fill in
* @ret rc Return status code * @ret rc Return status code
*/ */
int efi_open_by_child ( EFI_HANDLE handle, EFI_GUID *protocol, int efi_open_by_child_untyped ( EFI_HANDLE handle, EFI_GUID *protocol,
EFI_HANDLE child, void **interface ) { EFI_HANDLE child, void **interface ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE agent = efi_image_handle; EFI_HANDLE agent = efi_image_handle;
EFI_HANDLE controller; EFI_HANDLE controller;

View File

@ -72,10 +72,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*/ */
static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle,
struct pci_range *range ) { struct pci_range *range ) {
union { EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root;
void *interface;
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root;
} root;
union { union {
union acpi_resource *res; union acpi_resource *res;
void *raw; void *raw;
@ -94,7 +91,7 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle,
/* Open root bridge I/O protocol */ /* Open root bridge I/O protocol */
if ( ( rc = efi_open ( handle, &efi_pci_root_bridge_io_protocol_guid, 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", DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
PCI_ARGS ( pci ), efi_handle_name ( handle ), PCI_ARGS ( pci ), efi_handle_name ( handle ),
strerror ( rc ) ); strerror ( rc ) );
@ -102,8 +99,7 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle,
} }
/* Get ACPI resource descriptors */ /* Get ACPI resource descriptors */
if ( ( efirc = root.root->Configuration ( root.root, if ( ( efirc = root->Configuration ( root, &acpi.raw ) ) != 0 ) {
&acpi.raw ) ) != 0 ) {
rc = -EEFI ( efirc ); rc = -EEFI ( efirc );
DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for " DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for "
"%s: %s\n", PCI_ARGS ( pci ), "%s: %s\n", PCI_ARGS ( pci ),
@ -123,13 +119,13 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle,
continue; continue;
/* Get range for this descriptor */ /* Get range for this descriptor */
start = PCI_BUSDEVFN ( root.root->SegmentNumber, start = PCI_BUSDEVFN ( root->SegmentNumber,
le64_to_cpu ( acpi.res->qword.min ), le64_to_cpu ( acpi.res->qword.min ),
0, 0 ); 0, 0 );
count = PCI_BUSDEVFN ( 0, le64_to_cpu ( acpi.res->qword.len ), count = PCI_BUSDEVFN ( 0, le64_to_cpu ( acpi.res->qword.len ),
0, 0 ); 0, 0 );
DBGC2 ( pci, "EFIPCI " PCI_FMT " found %04x:[%02x-%02x] via " 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 ), PCI_BUS ( start ), PCI_BUS ( start + count - 1 ),
efi_handle_name ( handle ) ); 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. * bridge has a single bus.
*/ */
if ( ! range->count ) { if ( ! range->count ) {
range->start = PCI_BUSDEVFN ( root.root->SegmentNumber, range->start = PCI_BUSDEVFN ( root->SegmentNumber, 0, 0, 0 );
0, 0, 0 );
range->count = PCI_BUSDEVFN ( 0, 1, 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, static int efipci_root_open ( struct pci_device *pci, EFI_HANDLE *handle,
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root ) { EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root ) {
struct pci_range tmp; struct pci_range tmp;
union {
void *interface;
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root;
} u;
int rc; int rc;
/* Find matching root bridge I/O protocol handle */ /* 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 */ /* Open PCI root bridge I/O protocol */
if ( ( rc = efi_open ( *handle, &efi_pci_root_bridge_io_protocol_guid, 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", DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
PCI_ARGS ( pci ), efi_handle_name ( *handle ), PCI_ARGS ( pci ), efi_handle_name ( *handle ),
strerror ( rc ) ); strerror ( rc ) );
return rc; return rc;
} }
/* Return opened protocol */
*root = u.root;
return 0; return 0;
} }
@ -742,10 +730,7 @@ static struct dma_operations efipci_dma_operations = {
* @ret rc Return status code * @ret rc Return status code
*/ */
int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) { int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) {
union { EFI_PCI_IO_PROTOCOL *pci_io;
EFI_PCI_IO_PROTOCOL *pci_io;
void *interface;
} pci_io;
UINTN pci_segment, pci_bus, pci_dev, pci_fn; UINTN pci_segment, pci_bus, pci_dev, pci_fn;
unsigned int busdevfn; unsigned int busdevfn;
EFI_STATUS efirc; 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 */ /* See if device is a PCI device */
if ( ( rc = efi_open ( device, &efi_pci_io_protocol_guid, 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", DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n",
efi_handle_name ( device ), strerror ( rc ) ); efi_handle_name ( device ), strerror ( rc ) );
return rc; return rc;
} }
efipci->io = pci_io.pci_io; efipci->io = pci_io;
/* Get PCI bus:dev.fn address */ /* Get PCI bus:dev.fn address */
if ( ( efirc = pci_io.pci_io->GetLocation ( pci_io.pci_io, &pci_segment, if ( ( efirc = pci_io->GetLocation ( pci_io, &pci_segment, &pci_bus,
&pci_bus, &pci_dev, &pci_dev, &pci_fn ) ) != 0 ) {
&pci_fn ) ) != 0 ) {
rc = -EEFI ( efirc ); rc = -EEFI ( efirc );
DBGC ( device, "EFIPCI %s could not get PCI location: %s\n", DBGC ( device, "EFIPCI %s could not get PCI location: %s\n",
efi_handle_name ( device ), strerror ( rc ) ); 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 * support I/O cycles). Work around any such platforms by
* enabling bits individually and simply ignoring any errors. * enabling bits individually and simply ignoring any errors.
*/ */
pci_io.pci_io->Attributes ( pci_io.pci_io, pci_io->Attributes ( pci_io, EfiPciIoAttributeOperationEnable,
EfiPciIoAttributeOperationEnable, EFI_PCI_IO_ATTRIBUTE_IO, NULL );
EFI_PCI_IO_ATTRIBUTE_IO, NULL ); pci_io->Attributes ( pci_io, EfiPciIoAttributeOperationEnable,
pci_io.pci_io->Attributes ( pci_io.pci_io, EFI_PCI_IO_ATTRIBUTE_MEMORY, NULL );
EfiPciIoAttributeOperationEnable, pci_io->Attributes ( pci_io, EfiPciIoAttributeOperationEnable,
EFI_PCI_IO_ATTRIBUTE_MEMORY, NULL ); EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, NULL );
pci_io.pci_io->Attributes ( pci_io.pci_io,
EfiPciIoAttributeOperationEnable,
EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, NULL );
/* Populate PCI device */ /* Populate PCI device */
if ( ( rc = pci_read_config ( &efipci->pci ) ) != 0 ) { 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 ) { static int efipci_start ( struct efi_device *efidev ) {
EFI_HANDLE device = efidev->device; EFI_HANDLE device = efidev->device;
struct efi_pci_device *efipci; struct efi_pci_device *efipci;
void *pci_io;
int rc; int rc;
/* Allocate PCI device */ /* Allocate PCI device */
@ -873,7 +853,7 @@ static int efipci_start ( struct efi_device *efidev ) {
/* Open PCI I/O protocol */ /* Open PCI I/O protocol */
if ( ( rc = efi_open_by_driver ( device, &efi_pci_io_protocol_guid, 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", DBGC ( device, "EFIPCI %s could not open PCI device: %s\n",
efi_handle_name ( device ), strerror ( rc ) ); efi_handle_name ( device ), strerror ( rc ) );
DBGC_EFI_OPENERS ( device, device, &efi_pci_io_protocol_guid ); DBGC_EFI_OPENERS ( device, device, &efi_pci_io_protocol_guid );

View File

@ -45,15 +45,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*/ */
int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding, int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding,
EFI_HANDLE *handle ) { EFI_HANDLE *handle ) {
union { EFI_SERVICE_BINDING_PROTOCOL *sb;
EFI_SERVICE_BINDING_PROTOCOL *sb;
void *interface;
} u;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; int rc;
/* Open service binding protocol */ /* 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", DBGC ( service, "EFISVC %s cannot open %s binding: %s\n",
efi_handle_name ( service ), efi_guid_ntoa ( binding ), efi_handle_name ( service ), efi_guid_ntoa ( binding ),
strerror ( rc ) ); strerror ( rc ) );
@ -61,7 +58,7 @@ int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding,
} }
/* Create child handle */ /* Create child handle */
if ( ( efirc = u.sb->CreateChild ( u.sb, handle ) ) != 0 ) { if ( ( efirc = sb->CreateChild ( sb, handle ) ) != 0 ) {
rc = -EEFI ( efirc ); rc = -EEFI ( efirc );
DBGC ( service, "EFISVC %s could not create %s child: %s\n", DBGC ( service, "EFISVC %s could not create %s child: %s\n",
efi_handle_name ( service ), efi_guid_ntoa ( binding ), 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, int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding,
EFI_HANDLE handle ) { EFI_HANDLE handle ) {
union { EFI_SERVICE_BINDING_PROTOCOL *sb;
EFI_SERVICE_BINDING_PROTOCOL *sb;
void *interface;
} u;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; int rc;
@ -97,7 +91,7 @@ int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding,
DBGC ( service, "%s\n", efi_handle_name ( handle ) ); DBGC ( service, "%s\n", efi_handle_name ( handle ) );
/* Open service binding protocol */ /* 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", DBGC ( service, "EFISVC %s cannot open %s binding: %s\n",
efi_handle_name ( service ), efi_guid_ntoa ( binding ), efi_handle_name ( service ), efi_guid_ntoa ( binding ),
strerror ( rc ) ); strerror ( rc ) );
@ -105,7 +99,7 @@ int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding,
} }
/* Destroy child handle */ /* Destroy child handle */
if ( ( efirc = u.sb->DestroyChild ( u.sb, handle ) ) != 0 ) { if ( ( efirc = sb->DestroyChild ( sb, handle ) ) != 0 ) {
rc = -EEFI ( efirc ); rc = -EEFI ( efirc );
DBGC ( service, "EFISVC %s could not destroy %s child ", DBGC ( service, "EFISVC %s could not destroy %s child ",
efi_handle_name ( service ), efi_guid_ntoa ( binding ) ); efi_handle_name ( service ), efi_guid_ntoa ( binding ) );

View File

@ -272,23 +272,20 @@ static EFIAPI EFI_STATUS efi_shim_get_memory_map ( UINTN *len,
* @ret rc Return status code * @ret rc Return status code
*/ */
static int efi_shim_inhibit_pxe ( EFI_HANDLE handle ) { static int efi_shim_inhibit_pxe ( EFI_HANDLE handle ) {
union { EFI_PXE_BASE_CODE_PROTOCOL *pxe;
EFI_PXE_BASE_CODE_PROTOCOL *pxe;
void *interface;
} u;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; int rc;
/* Locate PXE base code */ /* Locate PXE base code */
if ( ( rc = efi_open ( handle, &efi_pxe_base_code_protocol_guid, 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", DBGC ( &efi_shim, "SHIM could not open PXE base code: %s\n",
strerror ( rc ) ); strerror ( rc ) );
return rc; return rc;
} }
/* Stop PXE base code */ /* Stop PXE base code */
if ( ( efirc = u.pxe->Stop ( u.pxe ) ) != 0 ) { if ( ( efirc = pxe->Stop ( pxe ) ) != 0 ) {
rc = -EEFI ( efirc ); rc = -EEFI ( efirc );
DBGC ( &efi_shim, "SHIM could not stop PXE base code: %s\n", DBGC ( &efi_shim, "SHIM could not stop PXE base code: %s\n",
strerror ( rc ) ); strerror ( rc ) );

View File

@ -45,10 +45,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
EFI_HANDLE *parent, unsigned int skip ) { EFI_HANDLE *parent, unsigned int skip ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union { EFI_DEVICE_PATH_PROTOCOL *devpath;
EFI_DEVICE_PATH_PROTOCOL *path;
void *interface;
} u;
EFI_DEVICE_PATH_PROTOCOL *path; EFI_DEVICE_PATH_PROTOCOL *path;
EFI_DEVICE_PATH_PROTOCOL *end; EFI_DEVICE_PATH_PROTOCOL *end;
size_t len; size_t len;
@ -57,20 +54,20 @@ int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
/* Get device path */ /* Get device path */
if ( ( rc = efi_open ( device, &efi_device_path_protocol_guid, 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", DBGC ( device, "EFIDEV %s cannot open device path: %s\n",
efi_handle_name ( device ), strerror ( rc ) ); efi_handle_name ( device ), strerror ( rc ) );
goto err_open_device_path; goto err_open_device_path;
} }
/* Create modifiable copy of 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 ); path = malloc ( len );
if ( ! path ) { if ( ! path ) {
rc = -ENOMEM; rc = -ENOMEM;
goto err_alloc_path; goto err_alloc_path;
} }
memcpy ( path, u.path, len ); memcpy ( path, devpath, len );
/* Locate parent device(s) */ /* Locate parent device(s) */
while ( 1 ) { while ( 1 ) {
@ -111,7 +108,7 @@ int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol,
* @ret rc Return status code * @ret rc Return status code
*/ */
int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child ) { int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child ) {
void *devpath; EFI_DEVICE_PATH_PROTOCOL *devpath;
int rc; int rc;
/* Re-open the device path protocol */ /* Re-open the device path protocol */

View File

@ -153,16 +153,13 @@ static int efi_veto_disconnect ( struct efi_veto *veto ) {
static int efi_veto_uninstall ( struct efi_veto *veto ) { static int efi_veto_uninstall ( struct efi_veto *veto ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE driver = veto->driver; EFI_HANDLE driver = veto->driver;
union { EFI_DRIVER_BINDING_PROTOCOL *binding;
EFI_DRIVER_BINDING_PROTOCOL *binding;
void *interface;
} binding;
EFI_STATUS efirc; EFI_STATUS efirc;
int rc; int rc;
/* Open driver binding protocol */ /* Open driver binding protocol */
if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid, if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid,
&binding.interface ) ) != 0 ) { &binding ) ) != 0 ) {
DBGC ( driver, "EFIVETO %s could not open driver binding " DBGC ( driver, "EFIVETO %s could not open driver binding "
"protocol: %s\n", efi_handle_name ( driver ), "protocol: %s\n", efi_handle_name ( driver ),
strerror ( rc ) ); strerror ( rc ) );
@ -172,7 +169,7 @@ static int efi_veto_uninstall ( struct efi_veto *veto ) {
/* Uninstall driver binding protocol */ /* Uninstall driver binding protocol */
if ( ( efirc = bs->UninstallMultipleProtocolInterfaces ( if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
driver, &efi_driver_binding_protocol_guid, driver, &efi_driver_binding_protocol_guid,
binding.binding, NULL ) ) != 0 ) { binding, NULL ) ) != 0 ) {
rc = -EEFI ( efirc ); rc = -EEFI ( efirc );
DBGC ( driver, "EFIVETO %s could not uninstall driver " DBGC ( driver, "EFIVETO %s could not uninstall driver "
"binding protocol: %s\n", "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, static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer,
struct efi_veto *veto ) { struct efi_veto *veto ) {
union { EFI_DRIVER_BINDING_PROTOCOL *binding;
EFI_DRIVER_BINDING_PROTOCOL *binding; EFI_LOADED_IMAGE_PROTOCOL *loaded;
void *interface; EFI_COMPONENT_NAME2_PROTOCOL *wtf2;
} binding; EFI_COMPONENT_NAME_PROTOCOL *wtf;
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;
CHAR16 *name; CHAR16 *name;
unsigned int i; unsigned int i;
EFI_HANDLE image; EFI_HANDLE image;
@ -561,17 +546,17 @@ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer,
/* Open driver binding protocol */ /* Open driver binding protocol */
if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid, if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid,
&binding.interface ) ) != 0 ) { &binding ) ) != 0 ) {
DBGC ( driver, "EFIVETO %s could not open driver binding " DBGC ( driver, "EFIVETO %s could not open driver binding "
"protocol: %s\n", efi_handle_name ( driver ), "protocol: %s\n", efi_handle_name ( driver ),
strerror ( rc ) ); strerror ( rc ) );
return rc; return rc;
} }
image = binding.binding->ImageHandle; image = binding->ImageHandle;
/* Open loaded image protocol */ /* Open loaded image protocol */
if ( ( rc = efi_open ( image, &efi_loaded_image_protocol_guid, if ( ( rc = efi_open ( image, &efi_loaded_image_protocol_guid,
&loaded.interface ) ) != 0 ) { &loaded ) ) != 0 ) {
DBGC ( driver, "EFIVETO %s could not open", DBGC ( driver, "EFIVETO %s could not open",
efi_handle_name ( driver ) ); efi_handle_name ( driver ) );
DBGC ( driver, " %s loaded image protocol: %s\n", 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 */ /* Open component name protocol, if present */
if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid, if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid,
&wtf2.interface ) ) != 0 ) { &wtf2 ) ) != 0 ) {
/* Ignore failure; is not required to be present */ /* Ignore failure; is not required to be present */
} }
/* Open obsolete component name protocol, if present */ /* Open obsolete component name protocol, if present */
if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid, if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid,
&wtf.interface ) ) != 0 ) { &wtf ) ) != 0 ) {
/* Ignore failure; is not required to be present */ /* Ignore failure; is not required to be present */
} }
/* Get driver name, if available */ /* Get driver name, if available */
if ( ( wtf2.wtf2 && if ( ( wtf2 && ( ( efirc = wtf2->GetDriverName ( wtf2, "en",
( ( efirc = wtf2.wtf2->GetDriverName ( wtf2.wtf2, "en", &name ) == 0 ) ) ) ||
&name ) == 0 ) ) ) || ( wtf && ( ( efirc = wtf->GetDriverName ( wtf, "eng",
( wtf.wtf && &name ) == 0 ) ) ) ) {
( ( efirc = wtf.wtf->GetDriverName ( wtf.wtf, "eng",
&name ) == 0 ) ) ) ) {
/* Driver has a name */ /* Driver has a name */
} else { } else {
/* Ignore failure; name is not required to be present */ /* 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 */ /* Check vetoes */
DBGC2 ( &efi_vetoes, "EFIVETO checking %s [%p,%p)\n", DBGC2 ( &efi_vetoes, "EFIVETO checking %s [%p,%p)\n",
efi_handle_name ( driver ), loaded.loaded->ImageBase, efi_handle_name ( driver ), loaded->ImageBase,
( loaded.loaded->ImageBase + loaded.loaded->ImageSize ) ); ( loaded->ImageBase + loaded->ImageSize ) );
for ( i = 0 ; i < ( sizeof ( efi_vetoes ) / for ( i = 0 ; i < ( sizeof ( efi_vetoes ) /
sizeof ( efi_vetoes[0] ) ) ; i++ ) { sizeof ( efi_vetoes[0] ) ) ; i++ ) {
if ( efi_vetoes[i].veto ( binding.binding, loaded.loaded, if ( efi_vetoes[i].veto ( binding, loaded, manufacturer,
manufacturer, name ) ) { name ) ) {
DBGC ( driver, "EFIVETO %s is vetoed (%s)\n", DBGC ( driver, "EFIVETO %s is vetoed (%s)\n",
efi_handle_name ( driver ), efi_handle_name ( driver ),
efi_vetoes[i].name ); efi_vetoes[i].name );
veto->driver = driver; veto->driver = driver;
veto->binding = binding.binding; veto->binding = binding;
veto->image = image; veto->image = image;
veto->loaded = loaded.loaded; veto->loaded = loaded;
break; break;
} }
} }

View File

@ -248,15 +248,12 @@ static int efi_prescroll ( unsigned int lines ) {
* @v handle Image handle * @v handle Image handle
*/ */
static void efi_dump_image ( EFI_HANDLE handle ) { static void efi_dump_image ( EFI_HANDLE handle ) {
union { EFI_LOADED_IMAGE_PROTOCOL *loaded;
EFI_LOADED_IMAGE_PROTOCOL *image;
void *intf;
} loaded;
int rc; int rc;
/* Open loaded image protocol */ /* Open loaded image protocol */
if ( ( rc = efi_open ( handle, &efi_loaded_image_protocol_guid, 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: " DBGC ( colour, "WRAP %s could not get loaded image protocol: "
"%s\n", efi_handle_name ( handle ), strerror ( rc ) ); "%s\n", efi_handle_name ( handle ), strerror ( rc ) );
return; return;
@ -264,14 +261,14 @@ static void efi_dump_image ( EFI_HANDLE handle ) {
/* Dump image information */ /* Dump image information */
DBGC ( colour, "WRAP %s at base %p has protocols:\n", 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_EFI_PROTOCOLS ( colour, handle );
DBGC ( colour, "WRAP %s parent", efi_handle_name ( 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, "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, "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 ) );
} }
/** /**