}
nii->pci_device = pci_device;
- /* Open PCI I/O protocol */
- if ( ( efirc = bs->OpenProtocol ( pci_device, &efi_pci_io_protocol_guid,
- &pci_io.interface, efi_image_handle,
- device,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ /* Open PCI I/O protocol
+ *
+ * We cannot open this safely as a by-driver open, since doing
+ * so would disconnect the underlying NII driver. We must
+ * therefore use an unsafe open.
+ */
+ if ( ( rc = efi_open_unsafe ( pci_device, &efi_pci_io_protocol_guid,
+ &pci_io.interface ) ) != 0 ) {
DBGC ( nii, "NII %s could not open PCI I/O protocol: %s\n",
nii->dev.name, strerror ( rc ) );
goto err_open;
return 0;
err_get_bar_attributes:
- bs->CloseProtocol ( pci_device, &efi_pci_io_protocol_guid,
- efi_image_handle, device );
+ efi_close_unsafe ( pci_device, &efi_pci_io_protocol_guid );
err_open:
err_locate:
return rc;
* @ret rc Return status code
*/
static void nii_pci_close ( struct nii_nic *nii ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
struct nii_mapping *map;
struct nii_mapping *tmp;
}
/* Close protocols */
- bs->CloseProtocol ( nii->pci_device, &efi_pci_io_protocol_guid,
- efi_image_handle, nii->efidev->device );
+ efi_close_unsafe ( nii->pci_device, &efi_pci_io_protocol_guid );
}
/**
}
/* Open PCI I/O protocol */
- if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid,
- &pci_io, efi_image_handle, device,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
- rc = -EEFI ( efirc );
+ if ( ( rc = efi_open_unsafe ( device, &efi_pci_io_protocol_guid,
+ &pci_io ) ) != 0 ) {
DBGC ( device, "EFIBOFM %s cannot open PCI device: %s\n",
efi_handle_name ( device ), strerror ( rc ) );
goto err_open;
err_set_status:
err_locate_bofm:
- bs->CloseProtocol ( device, &efi_pci_io_protocol_guid,
- efi_image_handle, device );
+ efi_close_unsafe ( device, &efi_pci_io_protocol_guid );
err_open:
err_info:
return rc;
*
*/
static void efi_console_init ( void ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_CONSOLE_CONTROL_SCREEN_MODE mode;
union {
void *interface;
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *wtf;
} u;
- EFI_STATUS efirc;
int rc;
/* On some older EFI 1.10 implementations, we must use the
* apparently the expected behaviour for all UEFI
* applications. Don't ask.
*/
- if ( ( efirc = bs->OpenProtocol ( efi_systab->ConsoleInHandle,
- &efi_simple_text_input_ex_protocol_guid,
- &u.interface, efi_image_handle,
- efi_systab->ConsoleInHandle,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) == 0 ) {
+ if ( ( rc = efi_open_unsafe ( efi_systab->ConsoleInHandle,
+ &efi_simple_text_input_ex_protocol_guid,
+ &u.interface ) ) == 0 ) {
efi_conin_ex = u.wtf;
DBG ( "EFI using SimpleTextInputEx\n" );
} else {
- rc = -EEFI ( efirc );
DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) );
}
}
}
}
- /* Get loaded image protocol */
- if ( ( efirc = bs->OpenProtocol ( image_handle,
- &efi_loaded_image_protocol_guid,
- &loaded_image, image_handle, NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
- rc = -EEFI ( efirc );
+ /* Get loaded image protocol
+ *
+ * We assume that our loaded image protocol will not be
+ * uninstalled while our image code is still running.
+ */
+ if ( ( rc = efi_open_unsafe ( image_handle,
+ &efi_loaded_image_protocol_guid,
+ &loaded_image ) ) != 0 ) {
DBGC ( systab, "EFI could not get loaded image protocol: %s",
strerror ( rc ) );
+ efirc = EFIRC ( rc );
goto err_no_loaded_image;
}
efi_loaded_image = loaded_image;