* @ret rc Return status code
*/
int snpnet_supported ( EFI_HANDLE device, EFI_GUID *protocol ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE parent;
- EFI_STATUS efirc;
int rc;
/* Check that this is not a device we are providing ourselves */
}
/* Test for presence of protocol */
- if ( ( efirc = bs->OpenProtocol ( device, protocol,
- NULL, efi_image_handle, device,
- EFI_OPEN_PROTOCOL_TEST_PROTOCOL))!=0){
+ if ( ( rc = efi_open ( device, protocol, NULL ) ) != 0 ) {
DBGCP ( device, "HANDLE %s is not a %s device\n",
efi_handle_name ( device ),
efi_guid_ntoa ( protocol ) );
- return -EEFI ( efirc );
+ return rc;
}
/* Check that there are no instances of this protocol further
* @v chained Chainloaded protocol
*/
static void chained_locate ( struct chained_protocol *chained ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE device = efi_loaded_image->DeviceHandle;
EFI_HANDLE handle;
void *match = NULL;
void *interface;
unsigned int skip;
- EFI_STATUS efirc;
int rc;
/* Identify target device handle */
}
/* Get protocol instance */
- if ( ( efirc = bs->OpenProtocol (
- handle, chained->protocol, &interface,
- efi_image_handle, handle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL )) != 0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( handle, chained->protocol,
+ &interface ) ) != 0 ) {
DBGC ( device, "CHAINED %s could not open %s on ",
efi_handle_name ( device ),
efi_guid_ntoa ( chained->protocol ) );
efi_handle_name ( handle ), strerror ( rc ) );
break;
}
- bs->CloseProtocol ( handle, chained->protocol,
- efi_image_handle, handle );
/* Stop if we reach a non-matching protocol instance */
if ( match && ( match != interface ) ) {
*/
static int chained_supported ( EFI_HANDLE device,
struct chained_protocol *chained ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
void *interface;
- EFI_STATUS efirc;
int rc;
/* Get protocol */
- if ( ( efirc = bs->OpenProtocol ( device, chained->protocol, &interface,
- efi_image_handle, device,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( device, chained->protocol,
+ &interface ) ) != 0 ) {
DBGCP ( device, "CHAINED %s is not a %s device\n",
efi_handle_name ( device ),
efi_guid_ntoa ( chained->protocol ) );
- goto err_open_protocol;
+ return rc;
}
/* Ignore non-matching handles */
DBGC2 ( device, "CHAINED %s is not the chainloaded %s\n",
efi_handle_name ( device ),
efi_guid_ntoa ( chained->protocol ) );
- rc = -ENOTTY;
- goto err_no_match;
+ return -ENOTTY;
}
- /* Success */
- rc = 0;
DBGC ( device, "CHAINED %s is the chainloaded %s\n",
efi_handle_name ( device ),
efi_guid_ntoa ( chained->protocol ) );
-
- err_no_match:
- bs->CloseProtocol ( device, chained->protocol, efi_image_handle,
- device );
- err_open_protocol:
- return rc;
+ return 0;
}
/**
* @ret rc Return status code
*/
static int usbio_supported ( EFI_HANDLE handle ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_USB_DEVICE_DESCRIPTOR device;
EFI_USB_INTERFACE_DESCRIPTOR interface;
struct usb_function_descriptor desc;
int rc;
/* Get protocol */
- if ( ( efirc = bs->OpenProtocol ( handle, &efi_usb_io_protocol_guid,
- &usb.interface, efi_image_handle,
- handle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( handle, &efi_usb_io_protocol_guid,
+ &usb.interface ) ) != 0 ) {
DBGCP ( handle, "USB %s is not a USB device\n",
efi_handle_name ( handle ) );
- goto err_open_protocol;
+ return rc;
}
/* Get device descriptor */
rc = -EEFI ( efirc );
DBGC ( handle, "USB %s could not get device descriptor: "
"%s\n", efi_handle_name ( handle ), strerror ( rc ) );
- goto err_get_device_descriptor;
+ return rc;
}
memset ( &desc, 0, sizeof ( desc ) );
desc.vendor = device.IdVendor;
rc = -EEFI ( efirc );
DBGC ( handle, "USB %s could not get interface descriptor: "
"%s\n", efi_handle_name ( handle ), strerror ( rc ) );
- goto err_get_interface_descriptor;
+ return rc;
}
desc.class.class.class = interface.InterfaceClass;
desc.class.class.subclass = interface.InterfaceSubClass;
/* Look for a driver for this interface */
driver = usb_find_driver ( &desc, &id );
- if ( ! driver ) {
- rc = -ENOTSUP;
- goto err_unsupported;
- }
-
- /* Success */
- rc = 0;
+ if ( ! driver )
+ return -ENOTSUP;
- err_unsupported:
- err_get_interface_descriptor:
- err_get_device_descriptor:
- bs->CloseProtocol ( handle, &efi_usb_io_protocol_guid,
- efi_image_handle, handle );
- err_open_protocol:
- return rc;
+ return 0;
}
/**
* @ret rc Return status code
*/
static int usbio_path ( struct usbio_device *usbio ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE handle = usbio->handle;
EFI_DEVICE_PATH_PROTOCOL *path;
EFI_DEVICE_PATH_PROTOCOL *end;
EFI_DEVICE_PATH_PROTOCOL *path;
} u;
size_t len;
- EFI_STATUS efirc;
int rc;
/* Open device path protocol */
- if ( ( efirc = bs->OpenProtocol ( handle,
- &efi_device_path_protocol_guid,
- &u.interface, efi_image_handle,
- handle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid,
+ &u.interface ) ) != 0 ) {
DBGC ( usbio, "USBIO %s cannot open device path protocol: "
"%s\n", efi_handle_name ( handle ), strerror ( rc ) );
- goto err_open_protocol;
+ return rc;
}
path = u.interface;
if ( len < sizeof ( *usbpath ) ) {
DBGC ( usbio, "USBIO %s underlength device path\n",
efi_handle_name ( handle ) );
- rc = -EINVAL;
- goto err_underlength;
+ return -EINVAL;
}
usbpath = ( ( ( void * ) path ) + len - sizeof ( *usbpath ) );
if ( ! ( ( usbpath->Header.Type == MESSAGING_DEVICE_PATH ) &&
DBGC ( usbio, "USBIO %s not a USB device path: ",
efi_handle_name ( handle ) );
DBGC ( usbio, "%s\n", efi_devpath_text ( path ) );
- rc = -EINVAL;
- goto err_non_usb;
+ return -EINVAL;
}
/* Allocate copy of device path */
usbio->path = malloc ( len + sizeof ( *end ) );
- if ( ! usbio->path ) {
- rc = -ENOMEM;
- goto err_alloc;
- }
+ if ( ! usbio->path )
+ return -ENOMEM;
memcpy ( usbio->path, path, ( len + sizeof ( *end ) ) );
usbio->usbpath = ( ( ( void * ) usbio->path ) + len -
sizeof ( *usbpath ) );
- /* Close protocol */
- bs->CloseProtocol ( handle, &efi_device_path_protocol_guid,
- efi_image_handle, handle );
-
return 0;
-
- free ( usbio->path );
- err_alloc:
- err_non_usb:
- err_underlength:
- bs->CloseProtocol ( handle, &efi_device_path_protocol_guid,
- efi_image_handle, handle );
- err_open_protocol:
- return rc;
}
/**
}
/* Get the loaded image protocol for the newly loaded image */
- efirc = bs->OpenProtocol ( handle, &efi_loaded_image_protocol_guid,
- &loaded.interface, efi_image_handle,
- NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL );
- if ( efirc ) {
+ if ( ( rc = efi_open ( handle, &efi_loaded_image_protocol_guid,
+ &loaded.interface ) ) != 0 ) {
/* Should never happen */
- rc = -EEFI ( efirc );
goto err_open_protocol;
}
*/
int efi_set_autoboot_ll_addr ( EFI_HANDLE device,
EFI_DEVICE_PATH_PROTOCOL *path ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_SIMPLE_NETWORK_PROTOCOL *snp;
void *interface;
} snp;
EFI_SIMPLE_NETWORK_MODE *mode;
- EFI_STATUS efirc;
unsigned int vlan;
int rc;
/* Look for an SNP instance on the image's device handle */
- if ( ( efirc = bs->OpenProtocol ( device,
- &efi_simple_network_protocol_guid,
- &snp.interface, efi_image_handle,
- NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( device, &efi_simple_network_protocol_guid,
+ &snp.interface ) ) != 0 ) {
DBGC ( device, "EFI %s has no SNP instance: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
return rc;
efi_handle_name ( device ), vlan );
}
- /* Close protocol */
- bs->CloseProtocol ( device, &efi_simple_network_protocol_guid,
- efi_image_handle, NULL );
-
return 0;
}
*/
static int efi_block_root ( unsigned int drive, EFI_HANDLE handle,
EFI_FILE_PROTOCOL **root ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- EFI_GUID *protocol = &efi_simple_file_system_protocol_guid;
union {
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
void *interface;
int rc;
/* Open filesystem protocol */
- if ( ( efirc = bs->OpenProtocol ( handle, protocol, &u.interface,
- efi_image_handle, handle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( handle, &efi_simple_file_system_protocol_guid,
+ &u.interface ) ) != 0 ) {
DBGC ( drive, "EFIBLK %#02x could not open %s filesystem: %s\n",
drive, efi_handle_name ( handle ), strerror ( rc ) );
- goto err_open;
+ return rc;
}
/* Open root volume */
rc = -EEFI ( efirc );
DBGC ( drive, "EFIBLK %#02x could not open %s root: %s\n",
drive, efi_handle_name ( handle ), strerror ( rc ) );
- goto err_volume;
+ return rc;
}
- /* Success */
- rc = 0;
-
- err_volume:
- bs->CloseProtocol ( handle, protocol, efi_image_handle, handle );
- err_open:
- return rc;
+ return 0;
}
/**
EFI_DEVICE_PATH_PROTOCOL *path,
struct san_boot_config *config,
EFI_DEVICE_PATH_PROTOCOL **fspath ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- EFI_GUID *protocol = &efi_device_path_protocol_guid;
union {
EFI_DEVICE_PATH_PROTOCOL *path;
void *interface;
} u;
EFI_FILE *root;
union uuid guid;
- EFI_STATUS efirc;
int rc;
/* Identify device path */
- if ( ( efirc = bs->OpenProtocol ( handle, protocol, &u.interface,
- efi_image_handle, handle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid,
+ &u.interface ) ) != 0 ) {
DBGC ( drive, "EFIBLK %#02x could not open %s device path: "
"%s\n", drive, efi_handle_name ( handle ),
strerror ( rc ) );
err_wrong_guid:
err_no_guid:
err_not_child:
- bs->CloseProtocol ( handle, protocol, efi_image_handle, handle );
err_open:
return rc;
}
struct san_boot_config *config,
EFI_DEVICE_PATH_PROTOCOL **fspath ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- EFI_GUID *protocol = &efi_device_path_protocol_guid;
union {
EFI_DEVICE_PATH_PROTOCOL *path;
void *interface;
efi_block_connect ( drive, handle );
/* Identify device path */
- if ( ( efirc = bs->OpenProtocol ( handle, protocol, &u.interface,
- efi_image_handle, handle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid,
+ &u.interface ) ) != 0 ) {
DBGC ( drive, "EFIBLK %#02x could not open device path: %s\n",
drive, strerror ( rc ) );
goto err_open;
bs->FreePool ( handles );
err_locate:
- bs->CloseProtocol ( handle, protocol, efi_image_handle, handle );
err_open:
return rc;
}
* equivalent functionality to BIOS drive numbers.
*/
static int efi_block_local ( EFI_HANDLE handle ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- EFI_GUID *protocol = &efi_block_io_protocol_guid;
struct san_device *sandev;
struct efi_block_data *block;
union {
EFI_BLOCK_IO_PROTOCOL *blockio;
void *interface;
} u;
- EFI_STATUS efirc;
int rc;
/* Check if handle belongs to a SAN device */
for_each_sandev ( sandev ) {
block = sandev->priv;
- if ( handle == block->handle ) {
- rc = -ENOTTY;
- goto err_sandev;
- }
+ if ( handle == block->handle )
+ return -ENOTTY;
}
/* Open block I/O protocol */
- if ( ( efirc = bs->OpenProtocol ( handle, protocol, &u.interface,
- efi_image_handle, handle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( handle, &efi_block_io_protocol_guid,
+ &u.interface ) ) != 0 ) {
DBGC ( handle, "EFIBLK %s could not open block I/O: %s\n",
efi_handle_name ( handle ), strerror ( rc ) );
- goto err_open;
+ return rc;
}
/* Do not assign drive numbers for partitions */
if ( u.blockio->Media->LogicalPartition ) {
- rc = -ENOTTY;
DBGC2 ( handle, "EFLBLK %s is a partition\n",
efi_handle_name ( handle ) );
- goto err_partition;
+ return -ENOTTY;
}
- /* Success */
- rc = 0;
-
- err_partition:
- bs->CloseProtocol ( handle, protocol, efi_image_handle, handle );
- err_open:
- err_sandev:
- return rc;
+ return 0;
}
/**
*/
int efi_cachedhcp_record ( EFI_HANDLE device,
EFI_DEVICE_PATH_PROTOCOL *path ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
unsigned int vlan;
union {
EFI_PXE_BASE_CODE_PROTOCOL *pxe;
void *interface;
} pxe;
EFI_PXE_BASE_CODE_MODE *mode;
- EFI_STATUS efirc;
int rc;
/* Get VLAN tag, if any */
vlan = efi_path_vlan ( path );
/* Look for a PXE base code instance on the image's device handle */
- if ( ( efirc = bs->OpenProtocol ( device,
- &efi_pxe_base_code_protocol_guid,
- &pxe.interface, efi_image_handle,
- NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( device, &efi_pxe_base_code_protocol_guid,
+ &pxe.interface ) ) != 0 ) {
DBGC ( device, "EFI %s has no PXE base code instance: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
- goto err_open;
+ return rc;
}
/* Do not attempt to cache IPv6 packets */
mode = pxe.pxe->Mode;
if ( mode->UsingIpv6 ) {
- rc = -ENOTSUP;
DBGC ( device, "EFI %s has IPv6 PXE base code\n",
efi_handle_name ( device ) );
- goto err_ipv6;
+ return -ENOTSUP;
}
/* Record DHCPACK, if present */
sizeof ( mode->DhcpAck ) ) ) != 0 ) ) {
DBGC ( device, "EFI %s could not record DHCPACK: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
- goto err_dhcpack;
+ return rc;
}
/* Record ProxyDHCPOFFER, if present */
sizeof ( mode->ProxyOffer ) ) ) != 0)){
DBGC ( device, "EFI %s could not record ProxyDHCPOFFER: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
- goto err_proxydhcp;
+ return rc;
}
/* Record PxeBSACK, if present */
sizeof ( mode->PxeReply ) ) ) != 0)){
DBGC ( device, "EFI %s could not record PXEBSACK: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
- goto err_pxebs;
+ return rc;
}
- /* Success */
- rc = 0;
-
- err_pxebs:
- err_proxydhcp:
- err_dhcpack:
- err_ipv6:
- bs->CloseProtocol ( device, &efi_pxe_base_code_protocol_guid,
- efi_image_handle, NULL );
- err_open:
- return rc;
+ return 0;
}
* @ret name Driver name, or NULL
*/
static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_COMPONENT_NAME_PROTOCOL *name;
void *interface;
} u;
EFI_HANDLE image;
- const char *name;
- EFI_STATUS efirc;
+ int rc;
/* Sanity check */
if ( ! binding ) {
/* Try to open component name protocol on image handle */
image = binding->ImageHandle;
- if ( ( efirc = bs->OpenProtocol ( image,
- &efi_component_name_protocol_guid,
- &u.interface, efi_image_handle, image,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL)) !=0){
+ if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid,
+ &u.interface ) ) != 0 ) {
DBG ( "[DriverBinding no ComponentName]" );
return NULL;
}
/* Try to get name from component name protocol */
- name = efi_driver_name ( u.name );
-
- /* Close component name protocol */
- bs->CloseProtocol ( image, &efi_component_name_protocol_guid,
- efi_image_handle, image );
-
- return name;
+ return efi_driver_name ( u.name );
}
/**
* @ret name Driver name, or NULL
*/
static const char * efi_binding_name2 ( EFI_DRIVER_BINDING_PROTOCOL *binding ){
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_HANDLE image;
union {
EFI_COMPONENT_NAME2_PROTOCOL *name2;
void *interface;
} u;
- const char *name;
- EFI_STATUS efirc;
+ int rc;
/* Sanity check */
if ( ! binding ) {
/* Try to open component name protocol on image handle */
image = binding->ImageHandle;
- if ( ( efirc = bs->OpenProtocol ( image,
- &efi_component_name2_protocol_guid,
- &u.interface, efi_image_handle, image,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL)) !=0){
+ if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid,
+ &u.interface ) ) != 0 ) {
DBG ( "[DriverBinding no ComponentName2]" );
return NULL;
}
/* Try to get name from component name protocol */
- name = efi_driver_name2 ( u.name2 );
-
- /* Close component name protocol */
- bs->CloseProtocol ( image, &efi_component_name2_protocol_guid,
- efi_image_handle, image );
-
- return name;
+ return efi_driver_name2 ( u.name2 );
}
/**
void *interface;
const char *name;
EFI_STATUS efirc;
+ int rc;
/* Fail immediately for NULL handles */
if ( ! handle )
DBG2 ( "<%d", i );
/* Try to open the applicable protocol */
- efirc = bs->OpenProtocol ( handle, type->protocol, &interface,
- efi_image_handle, handle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL );
- if ( efirc != 0 ) {
+ if ( ( rc = efi_open ( handle, type->protocol,
+ &interface ) ) != 0 ) {
DBG2 ( ">" );
continue;
}
/* Try to get name from this protocol */
DBG2 ( "-" );
name = type->name ( interface );
- DBG2 ( "%c", ( name ? ( name[0] ? 'Y' : 'E' ) : 'N' ) );
-
- /* Close protocol */
- bs->CloseProtocol ( handle, type->protocol,
- efi_image_handle, handle );
- DBG2 ( ">" );
+ DBG2 ( "%c>", ( name ? ( name[0] ? 'Y' : 'E' ) : 'N' ) );
/* Use this name, if possible */
if ( name && name[0] )
* @ret efidev EFI device, or NULL on error
*/
struct efi_device * efidev_alloc ( EFI_HANDLE device ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct efi_device *efidev = NULL;
union {
EFI_DEVICE_PATH_PROTOCOL *path;
} path;
EFI_DEVICE_PATH_PROTOCOL *path_end;
size_t path_len;
- EFI_STATUS efirc;
int rc;
/* Open device path */
- if ( ( efirc = bs->OpenProtocol ( device,
- &efi_device_path_protocol_guid,
- &path.interface, efi_image_handle,
- device,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( device, &efi_device_path_protocol_guid,
+ &path.interface ) ) != 0 ) {
DBGC ( device, "EFIDRV %s could not open device path: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
- goto err_open_path;
+ return NULL;
}
path_len = ( efi_path_len ( path.path ) + sizeof ( *path_end ) );
/* Allocate and initialise structure */
efidev = zalloc ( sizeof ( *efidev ) + path_len );
if ( ! efidev )
- goto err_alloc;
+ return NULL;
efidev->device = device;
efidev->dev.desc.bus_type = BUS_TYPE_EFI;
efidev->path = ( ( ( void * ) efidev ) + sizeof ( *efidev ) );
INIT_LIST_HEAD ( &efidev->dev.children );
list_add ( &efidev->dev.siblings, &efi_devices );
- err_alloc:
- bs->CloseProtocol ( device, &efi_device_path_protocol_guid,
- efi_image_handle, device );
- err_open_path:
return efidev;
}
efi_driver_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused,
EFI_HANDLE device, EFI_HANDLE child,
CHAR8 *language, CHAR16 **controller_name ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_COMPONENT_NAME2_PROTOCOL *name2;
void *interface;
} name2;
- EFI_STATUS efirc;
+ int rc;
/* Delegate to the EFI_COMPONENT_NAME2_PROTOCOL instance
* installed on child handle, if present.
*/
if ( ( child != NULL ) &&
- ( ( efirc = bs->OpenProtocol (
- child, &efi_component_name2_protocol_guid,
- &name2.interface, NULL, NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) == 0 ) ) {
+ ( ( rc = efi_open ( child, &efi_component_name2_protocol_guid,
+ &name2.interface ) ) == 0 ) ) {
return name2.name2->GetControllerName ( name2.name2, device,
child, language,
controller_name );
efi_cmdline_len = efi_loaded_image->LoadOptionsSize;
/* Get loaded image's device handle's device path */
- if ( ( efirc = bs->OpenProtocol ( efi_loaded_image->DeviceHandle,
- &efi_device_path_protocol_guid,
- &device_path, image_handle, NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( efi_loaded_image->DeviceHandle,
+ &efi_device_path_protocol_guid,
+ &device_path ) ) != 0 ) {
DBGC ( systab, "EFI could not get loaded image's device path: "
"%s", strerror ( rc ) );
+ efirc = EFIRC ( rc );
goto err_no_device_path;
}
*/
static int efi_local_open_root ( struct efi_local *local, EFI_HANDLE device,
EFI_FILE_PROTOCOL **root ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
void *interface;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs;
int rc;
/* Open file system protocol */
- if ( ( efirc = bs->OpenProtocol ( device,
- &efi_simple_file_system_protocol_guid,
- &u.interface, efi_image_handle,
- device,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( device, &efi_simple_file_system_protocol_guid,
+ &u.interface ) ) != 0 ) {
DBGC ( local, "LOCAL %p could not open filesystem on %s: %s\n",
local, efi_handle_name ( device ), strerror ( rc ) );
- goto err_filesystem;
+ return rc;
}
/* Open root directory */
rc = -EEFI ( efirc );
DBGC ( local, "LOCAL %p could not open volume on %s: %s\n",
local, efi_handle_name ( device ), strerror ( rc ) );
- goto err_volume;
+ return rc;
}
- /* Success */
- rc = 0;
-
- err_volume:
- bs->CloseProtocol ( device, &efi_simple_file_system_protocol_guid,
- efi_image_handle, device );
- err_filesystem:
- return rc;
+ return 0;
}
/**
*/
static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle,
struct pci_range *range ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
void *interface;
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root;
range->count = 0;
/* Open root bridge I/O protocol */
- if ( ( efirc = bs->OpenProtocol ( handle,
- &efi_pci_root_bridge_io_protocol_guid,
- &root.interface, efi_image_handle, handle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( handle, &efi_pci_root_bridge_io_protocol_guid,
+ &root.interface ) ) != 0 ) {
DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
PCI_ARGS ( pci ), efi_handle_name ( handle ),
strerror ( rc ) );
- goto err_open;
+ return rc;
}
/* Get ACPI resource descriptors */
DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for "
"%s: %s\n", PCI_ARGS ( pci ),
efi_handle_name ( handle ), strerror ( rc ) );
- goto err_config;
+ return rc;
}
/* Parse resource descriptors */
range->count = PCI_BUSDEVFN ( 0, 1, 0, 0 );
}
- /* Success */
- rc = 0;
-
- err_config:
- bs->CloseProtocol ( handle, &efi_pci_root_bridge_io_protocol_guid,
- efi_image_handle, handle );
- err_open:
- return rc;
+ return 0;
}
/**
}
/**
- * Open EFI PCI root bridge I/O protocol
+ * Open EFI PCI root bridge I/O protocol for ephemeral use
*
* @v pci PCI device
* @ret handle EFI PCI root bridge handle
*/
static int efipci_root_open ( struct pci_device *pci, EFI_HANDLE *handle,
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct pci_range tmp;
union {
void *interface;
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root;
} u;
- EFI_STATUS efirc;
int rc;
/* Find matching root bridge I/O protocol handle */
if ( ( rc = efipci_discover_any ( pci, &tmp, handle ) ) != 0 )
return rc;
- /* (Re)open PCI root bridge I/O protocol */
- if ( ( efirc = bs->OpenProtocol ( *handle,
- &efi_pci_root_bridge_io_protocol_guid,
- &u.interface, efi_image_handle, *handle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
- rc = -EEFI ( efirc );
+ /* Open PCI root bridge I/O protocol */
+ if ( ( rc = efi_open ( *handle, &efi_pci_root_bridge_io_protocol_guid,
+ &u.interface ) ) != 0 ) {
DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
PCI_ARGS ( pci ), efi_handle_name ( *handle ),
strerror ( rc ) );
return 0;
}
-/**
- * Close EFI PCI root bridge I/O protocol
- *
- * @v handle EFI PCI root bridge handle
- */
-static void efipci_root_close ( EFI_HANDLE handle ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
-
- /* Close protocol */
- bs->CloseProtocol ( handle, &efi_pci_root_bridge_io_protocol_guid,
- efi_image_handle, handle );
-}
-
/**
* Calculate EFI PCI configuration space address
*
/* Open root bridge */
if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
- goto err_root;
+ return rc;
/* Read from configuration space */
if ( ( efirc = root->Pci.Read ( root, EFIPCI_WIDTH ( location ),
DBGC ( pci, "EFIPCI " PCI_FMT " config read from offset %02lx "
"failed: %s\n", PCI_ARGS ( pci ),
EFIPCI_OFFSET ( location ), strerror ( rc ) );
- goto err_read;
+ return rc;
}
- err_read:
- efipci_root_close ( handle );
- err_root:
- return rc;
+ return 0;
}
/**
/* Open root bridge */
if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 )
- goto err_root;
+ return rc;
/* Read from configuration space */
if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ),
DBGC ( pci, "EFIPCI " PCI_FMT " config write to offset %02lx "
"failed: %s\n", PCI_ARGS ( pci ),
EFIPCI_OFFSET ( location ), strerror ( rc ) );
- goto err_write;
+ return rc;
}
- err_write:
- efipci_root_close ( handle );
- err_root:
- return rc;
+ return 0;
}
/**
}
err_config:
- efipci_root_close ( handle );
err_root:
return ioremap ( bus_addr, len );
}
* @ret rc Return status code
*/
int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_PCI_IO_PROTOCOL *pci_io;
void *interface;
int rc;
/* See if device is a PCI device */
- if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid,
- &pci_io.interface,
- efi_image_handle, device,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI_PCI ( efirc );
+ if ( ( rc = efi_open ( device, &efi_pci_io_protocol_guid,
+ &pci_io.interface ) ) != 0 ) {
DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
- goto err_open_protocol;
+ return rc;
}
efipci->io = pci_io.pci_io;
rc = -EEFI ( efirc );
DBGC ( device, "EFIPCI %s could not get PCI location: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
- goto err_get_location;
+ return rc;
}
busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn );
pci_init ( &efipci->pci, busdevfn );
DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI "
"configuration: %s\n",
PCI_ARGS ( &efipci->pci ), strerror ( rc ) );
- goto err_pci_read_config;
+ return rc;
}
return 0;
-
- err_pci_read_config:
- err_get_location:
- bs->CloseProtocol ( device, &efi_pci_io_protocol_guid,
- efi_image_handle, device );
- err_open_protocol:
- return rc;
}
/******************************************************************************
*/
int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding,
EFI_HANDLE *handle ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_SERVICE_BINDING_PROTOCOL *sb;
void *interface;
int rc;
/* Open service binding protocol */
- if ( ( efirc = bs->OpenProtocol ( service, binding, &u.interface,
- efi_image_handle, service,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( service, binding, &u.interface ) ) != 0 ) {
DBGC ( service, "EFISVC %s cannot open %s binding: %s\n",
efi_handle_name ( service ), efi_guid_ntoa ( binding ),
strerror ( rc ) );
- goto err_open;
+ return rc;
}
/* Create child handle */
DBGC ( service, "EFISVC %s could not create %s child: %s\n",
efi_handle_name ( service ), efi_guid_ntoa ( binding ),
strerror ( rc ) );
- goto err_create;
+ return rc;
}
- /* Success */
- rc = 0;
DBGC ( service, "EFISVC %s created %s child ",
efi_handle_name ( service ), efi_guid_ntoa ( binding ) );
DBGC ( service, "%s\n", efi_handle_name ( *handle ) );
-
- err_create:
- bs->CloseProtocol ( service, binding, efi_image_handle, service );
- err_open:
- return rc;
+ return 0;
}
/**
*/
int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding,
EFI_HANDLE handle ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_SERVICE_BINDING_PROTOCOL *sb;
void *interface;
DBGC ( service, "%s\n", efi_handle_name ( handle ) );
/* Open service binding protocol */
- if ( ( efirc = bs->OpenProtocol ( service, binding, &u.interface,
- efi_image_handle, service,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( service, binding, &u.interface ) ) != 0 ) {
DBGC ( service, "EFISVC %s cannot open %s binding: %s\n",
efi_handle_name ( service ), efi_guid_ntoa ( binding ),
strerror ( rc ) );
- goto err_open;
+ return rc;
}
/* Destroy child handle */
efi_handle_name ( service ), efi_guid_ntoa ( binding ) );
DBGC ( service, "%s: %s\n",
efi_handle_name ( handle ), strerror ( rc ) );
- goto err_destroy;
+ return rc;
}
- /* Success */
- rc = 0;
-
- err_destroy:
- bs->CloseProtocol ( service, binding, efi_image_handle, service );
- err_open:
- return rc;
+ return 0;
}
* @ret rc Return status code
*/
static int efi_shim_inhibit_pxe ( EFI_HANDLE handle ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_PXE_BASE_CODE_PROTOCOL *pxe;
void *interface;
int rc;
/* Locate PXE base code */
- if ( ( efirc = bs->OpenProtocol ( handle,
- &efi_pxe_base_code_protocol_guid,
- &u.interface, efi_image_handle, NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( handle, &efi_pxe_base_code_protocol_guid,
+ &u.interface ) ) != 0 ) {
DBGC ( &efi_shim, "SHIM could not open PXE base code: %s\n",
strerror ( rc ) );
- goto err_no_base;
+ return rc;
}
/* Stop PXE base code */
rc = -EEFI ( efirc );
DBGC ( &efi_shim, "SHIM could not stop PXE base code: %s\n",
strerror ( rc ) );
- goto err_stop;
+ return rc;
}
- /* Success */
- rc = 0;
DBGC ( &efi_shim, "SHIM stopped PXE base code\n" );
-
- err_stop:
- bs->CloseProtocol ( handle, &efi_pxe_base_code_protocol_guid,
- efi_image_handle, NULL );
- err_no_base:
- return rc;
+ return 0;
}
/**
int rc;
/* Get device path */
- if ( ( efirc = bs->OpenProtocol ( device,
- &efi_device_path_protocol_guid,
- &u.interface,
- efi_image_handle, device,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( device, &efi_device_path_protocol_guid,
+ &u.interface ) ) != 0 ) {
DBGC ( device, "EFIDEV %s cannot open device path: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
goto err_open_device_path;
efi_path_terminate ( end );
}
- /* Success */
- rc = 0;
-
err_locate_protocol:
free ( path );
err_alloc_path:
- bs->CloseProtocol ( device, &efi_device_path_protocol_guid,
- efi_image_handle, device );
err_open_device_path:
return rc;
}
int rc;
/* Open driver binding protocol */
- if ( ( efirc = bs->OpenProtocol (
- driver, &efi_driver_binding_protocol_guid,
- &binding.interface, efi_image_handle, driver,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid,
+ &binding.interface ) ) != 0 ) {
DBGC ( driver, "EFIVETO %s could not open driver binding "
"protocol: %s\n", efi_handle_name ( driver ),
strerror ( rc ) );
return rc;
}
- /* Close driver binding protocol */
- bs->CloseProtocol ( driver, &efi_driver_binding_protocol_guid,
- efi_image_handle, driver );
-
/* Uninstall driver binding protocol */
if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
driver, &efi_driver_binding_protocol_guid,
*/
static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer,
struct efi_veto *veto ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_DRIVER_BINDING_PROTOCOL *binding;
void *interface;
memset ( veto, 0, sizeof ( *veto ) );
/* Open driver binding protocol */
- if ( ( efirc = bs->OpenProtocol (
- driver, &efi_driver_binding_protocol_guid,
- &binding.interface, efi_image_handle, driver,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid,
+ &binding.interface ) ) != 0 ) {
DBGC ( driver, "EFIVETO %s could not open driver binding "
"protocol: %s\n", efi_handle_name ( driver ),
strerror ( rc ) );
- goto err_binding;
+ return rc;
}
image = binding.binding->ImageHandle;
/* Open loaded image protocol */
- if ( ( efirc = bs->OpenProtocol (
- image, &efi_loaded_image_protocol_guid,
- &loaded.interface, efi_image_handle, image,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( image, &efi_loaded_image_protocol_guid,
+ &loaded.interface ) ) != 0 ) {
DBGC ( driver, "EFIVETO %s could not open",
efi_handle_name ( driver ) );
DBGC ( driver, " %s loaded image protocol: %s\n",
efi_handle_name ( image ), strerror ( rc ) );
- goto err_loaded;
+ return rc;
}
/* Open component name protocol, if present */
- if ( ( efirc = bs->OpenProtocol (
- image, &efi_component_name2_protocol_guid,
- &wtf2.interface, efi_image_handle, image,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
+ if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid,
+ &wtf2.interface ) ) != 0 ) {
/* Ignore failure; is not required to be present */
- wtf2.interface = NULL;
}
/* Open obsolete component name protocol, if present */
- if ( ( efirc = bs->OpenProtocol (
- image, &efi_component_name_protocol_guid,
- &wtf.interface, efi_image_handle, image,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
+ if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid,
+ &wtf.interface ) ) != 0 ) {
/* Ignore failure; is not required to be present */
- wtf.interface = NULL;
}
/* Get driver name, if available */
}
}
- /* Success */
- rc = 0;
-
- /* Close protocols */
- if ( wtf.wtf ) {
- bs->CloseProtocol ( image, &efi_component_name_protocol_guid,
- efi_image_handle, image );
- }
- if ( wtf2.wtf2 ) {
- bs->CloseProtocol ( image, &efi_component_name2_protocol_guid,
- efi_image_handle, image );
- }
- bs->CloseProtocol ( image, &efi_loaded_image_protocol_guid,
- efi_image_handle, image );
- err_loaded:
- bs->CloseProtocol ( driver, &efi_driver_binding_protocol_guid,
- efi_image_handle, driver );
- err_binding:
- return rc;
+ return 0;
}
/**
* @v handle Image handle
*/
static void efi_dump_image ( EFI_HANDLE handle ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_LOADED_IMAGE_PROTOCOL *image;
void *intf;
} loaded;
- EFI_STATUS efirc;
int rc;
/* Open loaded image protocol */
- if ( ( efirc = bs->OpenProtocol ( handle,
- &efi_loaded_image_protocol_guid,
- &loaded.intf, efi_image_handle, NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open ( handle, &efi_loaded_image_protocol_guid,
+ &loaded.intf ) ) != 0 ) {
DBGC ( colour, "WRAP %s could not get loaded image protocol: "
"%s\n", efi_handle_name ( handle ), strerror ( rc ) );
return;
DBGC ( colour, " %s\n", efi_handle_name ( loaded.image->DeviceHandle ));
DBGC ( colour, "WRAP %s file", efi_handle_name ( handle ) );
DBGC ( colour, " %s\n", efi_devpath_text ( loaded.image->FilePath ) );
-
- /* Close loaded image protocol */
- bs->CloseProtocol ( handle, &efi_loaded_image_protocol_guid,
- efi_image_handle, NULL );
}
/**