2019-02-19 18:47:12 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2019 Michael Brown <mbrown@fensystems.co.uk>.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
* License, or any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
* 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <ipxe/settings.h>
|
|
|
|
|
#include <ipxe/efi/efi.h>
|
|
|
|
|
#include <ipxe/efi/Protocol/DriverBinding.h>
|
|
|
|
|
#include <ipxe/efi/Protocol/LoadedImage.h>
|
|
|
|
|
#include <ipxe/efi/Protocol/ComponentName.h>
|
2020-11-07 11:25:00 -05:00
|
|
|
#include <ipxe/efi/efi_veto.h>
|
2019-02-19 18:47:12 +00:00
|
|
|
|
|
|
|
|
/** @file
|
|
|
|
|
*
|
2020-11-07 11:25:00 -05:00
|
|
|
* EFI driver vetoes
|
2019-02-19 18:47:12 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-11-07 11:25:00 -05:00
|
|
|
/** A driver veto */
|
|
|
|
|
struct efi_veto {
|
|
|
|
|
/** Veto name (for debugging) */
|
2019-02-19 18:47:12 +00:00
|
|
|
const char *name;
|
|
|
|
|
/**
|
2020-11-07 11:25:00 -05:00
|
|
|
* Check if driver is vetoed
|
2019-02-19 18:47:12 +00:00
|
|
|
*
|
|
|
|
|
* @v binding Driver binding protocol
|
|
|
|
|
* @v loaded Loaded image protocol
|
|
|
|
|
* @v wtf Component name protocol, if present
|
2020-11-07 11:25:00 -05:00
|
|
|
* @ret vetoed Driver is to be vetoed
|
2019-02-19 18:47:12 +00:00
|
|
|
*/
|
2020-11-07 11:25:00 -05:00
|
|
|
int ( * veto ) ( EFI_DRIVER_BINDING_PROTOCOL *binding,
|
|
|
|
|
EFI_LOADED_IMAGE_PROTOCOL *loaded,
|
|
|
|
|
EFI_COMPONENT_NAME_PROTOCOL *wtf );
|
2019-02-19 18:47:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2020-11-07 11:25:00 -05:00
|
|
|
* Veto Dell Ip4ConfigDxe driver
|
2019-02-19 18:47:12 +00:00
|
|
|
*
|
|
|
|
|
* @v binding Driver binding protocol
|
|
|
|
|
* @v loaded Loaded image protocol
|
|
|
|
|
* @v wtf Component name protocol, if present
|
2020-11-07 11:25:00 -05:00
|
|
|
* @ret vetoed Driver is to be vetoed
|
2019-02-19 18:47:12 +00:00
|
|
|
*/
|
|
|
|
|
static int
|
2020-11-07 11:25:00 -05:00
|
|
|
efi_veto_dell_ip4config ( EFI_DRIVER_BINDING_PROTOCOL *binding __unused,
|
|
|
|
|
EFI_LOADED_IMAGE_PROTOCOL *loaded __unused,
|
|
|
|
|
EFI_COMPONENT_NAME_PROTOCOL *wtf ) {
|
2019-02-19 18:47:12 +00:00
|
|
|
static const CHAR16 ip4cfg[] = L"IP4 CONFIG Network Service Driver";
|
|
|
|
|
static const char dell[] = "Dell Inc.";
|
|
|
|
|
char manufacturer[ sizeof ( dell ) ];
|
|
|
|
|
CHAR16 *name;
|
|
|
|
|
|
|
|
|
|
/* Check driver name */
|
|
|
|
|
if ( ! wtf )
|
|
|
|
|
return 0;
|
|
|
|
|
if ( wtf->GetDriverName ( wtf, "eng", &name ) != 0 )
|
|
|
|
|
return 0;
|
|
|
|
|
if ( memcmp ( name, ip4cfg, sizeof ( ip4cfg ) ) != 0 )
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* Check manufacturer */
|
|
|
|
|
fetch_string_setting ( NULL, &manufacturer_setting, manufacturer,
|
|
|
|
|
sizeof ( manufacturer ) );
|
|
|
|
|
if ( strcmp ( manufacturer, dell ) != 0 )
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-07 11:25:00 -05:00
|
|
|
/** Driver vetoes */
|
|
|
|
|
static struct efi_veto efi_vetoes[] = {
|
2019-02-19 18:47:12 +00:00
|
|
|
{
|
|
|
|
|
.name = "Dell Ip4Config",
|
2020-11-07 11:25:00 -05:00
|
|
|
.veto = efi_veto_dell_ip4config,
|
2019-02-19 18:47:12 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2020-11-07 11:25:00 -05:00
|
|
|
* Find driver veto, if any
|
2019-02-19 18:47:12 +00:00
|
|
|
*
|
|
|
|
|
* @v driver Driver binding handle
|
2020-11-07 11:25:00 -05:00
|
|
|
* @ret veto Driver veto, or NULL
|
2019-02-19 18:47:12 +00:00
|
|
|
* @ret rc Return status code
|
|
|
|
|
*/
|
2020-11-07 11:25:00 -05:00
|
|
|
static int efi_veto ( EFI_HANDLE driver, struct efi_veto **veto ) {
|
2019-02-19 18:47:12 +00:00
|
|
|
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
|
|
|
|
union {
|
|
|
|
|
EFI_DRIVER_BINDING_PROTOCOL *binding;
|
|
|
|
|
void *interface;
|
|
|
|
|
} binding;
|
|
|
|
|
union {
|
|
|
|
|
EFI_LOADED_IMAGE_PROTOCOL *loaded;
|
|
|
|
|
void *interface;
|
|
|
|
|
} loaded;
|
|
|
|
|
union {
|
|
|
|
|
EFI_COMPONENT_NAME_PROTOCOL *wtf;
|
|
|
|
|
void *interface;
|
|
|
|
|
} wtf;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
EFI_HANDLE image;
|
|
|
|
|
EFI_STATUS efirc;
|
|
|
|
|
int rc;
|
|
|
|
|
|
2020-11-07 11:25:00 -05:00
|
|
|
DBGC2 ( &efi_vetoes, "EFIVETO checking %s\n",
|
2019-02-19 18:47:12 +00:00
|
|
|
efi_handle_name ( driver ) );
|
|
|
|
|
|
2020-11-07 11:25:00 -05:00
|
|
|
/* Mark as not vetoed */
|
|
|
|
|
*veto = NULL;
|
2019-02-19 18:47:12 +00:00
|
|
|
|
|
|
|
|
/* 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 );
|
2020-11-07 11:25:00 -05:00
|
|
|
DBGC ( driver, "EFIVETO %s could not open driver binding "
|
2019-02-19 18:47:12 +00:00
|
|
|
"protocol: %s\n", efi_handle_name ( driver ),
|
|
|
|
|
strerror ( rc ) );
|
|
|
|
|
goto err_binding;
|
|
|
|
|
}
|
|
|
|
|
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 );
|
2020-11-07 11:25:00 -05:00
|
|
|
DBGC ( driver, "EFIVETO %s could not open",
|
2019-02-19 18:47:12 +00:00
|
|
|
efi_handle_name ( driver ) );
|
|
|
|
|
DBGC ( driver, " %s loaded image protocol: %s\n",
|
|
|
|
|
efi_handle_name ( image ), strerror ( rc ) );
|
|
|
|
|
goto err_loaded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Open component name protocol, if present*/
|
|
|
|
|
if ( ( efirc = bs->OpenProtocol (
|
|
|
|
|
driver, &efi_component_name_protocol_guid,
|
|
|
|
|
&wtf.interface, efi_image_handle, driver,
|
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
|
|
|
|
|
/* Ignore failure; is not required to be present */
|
|
|
|
|
wtf.interface = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-07 11:25:00 -05:00
|
|
|
/* Check vetoes */
|
|
|
|
|
for ( i = 0 ; i < ( sizeof ( efi_vetoes ) /
|
|
|
|
|
sizeof ( efi_vetoes[0] ) ) ; i++ ) {
|
|
|
|
|
if ( efi_vetoes[i].veto ( binding.binding, loaded.loaded,
|
|
|
|
|
wtf.wtf ) ) {
|
|
|
|
|
*veto = &efi_vetoes[i];
|
2019-02-19 18:47:12 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Success */
|
|
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
|
|
/* Close protocols */
|
|
|
|
|
if ( wtf.wtf ) {
|
|
|
|
|
bs->CloseProtocol ( driver, &efi_component_name_protocol_guid,
|
|
|
|
|
efi_image_handle, driver );
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-11-07 11:25:00 -05:00
|
|
|
* Unload any vetoed drivers
|
2019-02-19 18:47:12 +00:00
|
|
|
*
|
|
|
|
|
*/
|
2020-11-07 11:25:00 -05:00
|
|
|
void efi_veto_unload ( void ) {
|
2019-02-19 18:47:12 +00:00
|
|
|
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
2020-11-07 11:25:00 -05:00
|
|
|
struct efi_veto *veto;
|
2019-02-19 18:47:12 +00:00
|
|
|
EFI_HANDLE *drivers;
|
|
|
|
|
EFI_HANDLE driver;
|
|
|
|
|
UINTN num_drivers;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
EFI_STATUS efirc;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
/* Locate all driver binding protocol handles */
|
|
|
|
|
if ( ( efirc = bs->LocateHandleBuffer (
|
|
|
|
|
ByProtocol, &efi_driver_binding_protocol_guid,
|
|
|
|
|
NULL, &num_drivers, &drivers ) ) != 0 ) {
|
|
|
|
|
rc = -EEFI ( efirc );
|
2020-11-07 11:25:00 -05:00
|
|
|
DBGC ( &efi_vetoes, "EFIVETO could not list all drivers: "
|
2019-02-19 18:47:12 +00:00
|
|
|
"%s\n", strerror ( rc ) );
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-07 11:25:00 -05:00
|
|
|
/* Unload any vetoed drivers */
|
2019-02-19 18:47:12 +00:00
|
|
|
for ( i = 0 ; i < num_drivers ; i++ ) {
|
|
|
|
|
driver = drivers[i];
|
2020-11-07 11:25:00 -05:00
|
|
|
if ( ( rc = efi_veto ( driver, &veto ) ) != 0 ) {
|
|
|
|
|
DBGC ( driver, "EFIVETO could not determine "
|
|
|
|
|
"vetoing for %s: %s\n",
|
2019-02-19 18:47:12 +00:00
|
|
|
efi_handle_name ( driver ), strerror ( rc ) );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-11-07 11:25:00 -05:00
|
|
|
if ( ! veto )
|
2019-02-19 18:47:12 +00:00
|
|
|
continue;
|
2020-11-07 11:25:00 -05:00
|
|
|
DBGC ( driver, "EFIVETO unloading %s (%s)\n",
|
|
|
|
|
efi_handle_name ( driver ), veto->name );
|
2019-02-19 18:47:12 +00:00
|
|
|
if ( ( efirc = bs->UnloadImage ( driver ) ) != 0 ) {
|
2020-11-24 15:42:43 +00:00
|
|
|
rc = -EEFI ( efirc );
|
2020-11-07 11:25:00 -05:00
|
|
|
DBGC ( driver, "EFIVETO could not unload %s: %s\n",
|
2019-02-19 18:47:12 +00:00
|
|
|
efi_handle_name ( driver ), strerror ( rc ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free handle list */
|
|
|
|
|
bs->FreePool ( drivers );
|
|
|
|
|
}
|