[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>
This commit is contained in:
Michael Brown
2025-03-24 14:24:47 +00:00
parent 37897fbd40
commit 32a9408217
23 changed files with 215 additions and 277 deletions
+1 -6
View 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 );
+2 -9
View 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 );
+2 -2
View 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;
+7 -27
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 *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 );