iPXE
Data Structures | Functions | Variables
efi_veto.c File Reference

EFI driver vetoes. More...

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ipxe/settings.h>
#include <ipxe/pci.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/DriverBinding.h>
#include <ipxe/efi/Protocol/LoadedImage.h>
#include <ipxe/efi/Protocol/ComponentName.h>
#include <ipxe/efi/efi_veto.h>

Go to the source code of this file.

Data Structures

struct  efi_veto
 A driver veto. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int efi_veto_unload (EFI_HANDLE driver)
 Unload an EFI driver. More...
 
static int efi_veto_disconnect (EFI_HANDLE driver)
 Disconnect an EFI driver from all handles. More...
 
static int efi_veto_uninstall (EFI_HANDLE driver)
 Uninstall an EFI driver binding protocol. More...
 
static int efi_veto_close_protocol (EFI_HANDLE driver, EFI_HANDLE handle, EFI_GUID *protocol)
 Close protocol on handle potentially opened by an EFI driver. More...
 
static int efi_veto_close_handle (EFI_HANDLE driver, EFI_HANDLE handle)
 Close handle potentially opened by an EFI driver. More...
 
static int efi_veto_close (EFI_HANDLE driver)
 Close all remaining handles opened by an EFI driver. More...
 
static int efi_veto_destroy (EFI_HANDLE driver)
 Terminate an EFI driver with extreme prejudice. More...
 
static int efi_veto_driver (EFI_HANDLE driver)
 Veto an EFI driver. More...
 
static int efi_veto_ip4config (EFI_DRIVER_BINDING_PROTOCOL *binding __unused, EFI_LOADED_IMAGE_PROTOCOL *loaded __unused, EFI_COMPONENT_NAME_PROTOCOL *wtf __unused, const char *manufacturer, const CHAR16 *name)
 Veto Ip4ConfigDxe driver on some platforms. More...
 
static int efi_veto_hp_xhci (EFI_DRIVER_BINDING_PROTOCOL *binding __unused, EFI_LOADED_IMAGE_PROTOCOL *loaded __unused, EFI_COMPONENT_NAME_PROTOCOL *wtf __unused, const char *manufacturer, const CHAR16 *name)
 Veto HP XhciDxe driver. More...
 
static int efi_veto_find (EFI_HANDLE driver, const char *manufacturer, struct efi_veto **veto)
 Find driver veto, if any. More...
 
void efi_veto (void)
 Remove any vetoed drivers. More...
 

Variables

static struct efi_veto efi_vetoes []
 Driver vetoes. More...
 

Detailed Description

EFI driver vetoes.

Definition in file efi_veto.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_veto_unload()

static int efi_veto_unload ( EFI_HANDLE  driver)
static

Unload an EFI driver.

Parameters
driverDriver binding handle
Return values
rcReturn status code

Definition at line 66 of file efi_veto.c.

66  {
68  EFI_STATUS efirc;
69  int rc;
70 
71  /* Unload the driver */
72  if ( ( efirc = bs->UnloadImage ( driver ) ) != 0 ) {
73  rc = -EEFI ( efirc );
74  DBGC ( driver, "EFIVETO %s could not unload: %s\n",
75  efi_handle_name ( driver ), strerror ( rc ) );
76  return rc;
77  }
78 
79  return 0;
80 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
#define DBGC(...)
Definition: compiler.h:505
EFI_IMAGE_UNLOAD UnloadImage
Definition: UefiSpec.h:1886
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab

References EFI_SYSTEM_TABLE::BootServices, DBGC, EEFI, efi_handle_name(), efi_systab, rc, strerror(), and EFI_BOOT_SERVICES::UnloadImage.

Referenced by efi_veto_driver().

◆ efi_veto_disconnect()

static int efi_veto_disconnect ( EFI_HANDLE  driver)
static

Disconnect an EFI driver from all handles.

Parameters
driverDriver binding handle
Return values
rcReturn status code

Definition at line 88 of file efi_veto.c.

88  {
90  EFI_HANDLE *handles;
92  UINTN count;
93  unsigned int i;
94  EFI_STATUS efirc;
95  int rc;
96 
97  /* Enumerate all handles */
98  if ( ( efirc = bs->LocateHandleBuffer ( AllHandles, NULL, NULL,
99  &count, &handles ) ) != 0 ) {
100  rc = -EEFI ( efirc );
101  DBGC ( driver, "EFIVETO %s could not enumerate handles: %s\n",
102  efi_handle_name ( driver ), strerror ( rc ) );
103  goto err_list;
104  }
105 
106  /* Disconnect driver from all handles, in reverse order */
107  for ( i = 0 ; i < count ; i++ ) {
108  handle = handles[ count - i - 1 ];
109  efirc = bs->DisconnectController ( handle, driver, NULL );
110  if ( ( efirc != 0 ) && ( efirc != EFI_NOT_FOUND ) ) {
111  rc = -EEFI ( efirc );
112  DBGC ( driver, "EFIVETO %s could not disconnect",
113  efi_handle_name ( driver ) );
114  DBGC ( driver, " %s: %s\n",
115  efi_handle_name ( handle ), strerror ( rc ) );
116  goto err_disconnect;
117  }
118  }
119 
120  /* Success */
121  rc = 0;
122  DBGC2 ( driver, "EFIVETO %s disconnected all handles\n",
123  efi_handle_name ( driver ) );
124 
125  err_disconnect:
126  bs->FreePool ( handles );
127  err_list:
128  return rc;
129 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
Retrieve all the handles in the handle database.
Definition: UefiSpec.h:1439
#define DBGC(...)
Definition: compiler.h:505
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
#define EFI_NOT_FOUND
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:134
#define DBGC2(...)
Definition: compiler.h:522
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
uint16_t count
Number of entries.
Definition: ena.h:22
EFI_SYSTEM_TABLE * efi_systab
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
Definition: efi.h:50
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:1913
EFI_DISCONNECT_CONTROLLER DisconnectController
Definition: UefiSpec.h:1900

References AllHandles, EFI_SYSTEM_TABLE::BootServices, count, DBGC, DBGC2, EFI_BOOT_SERVICES::DisconnectController, EEFI, efi_handle_name(), EFI_NOT_FOUND, efi_systab, EFI_BOOT_SERVICES::FreePool, handle, EFI_BOOT_SERVICES::LocateHandleBuffer, NULL, rc, and strerror().

Referenced by efi_veto_destroy().

◆ efi_veto_uninstall()

static int efi_veto_uninstall ( EFI_HANDLE  driver)
static

Uninstall an EFI driver binding protocol.

Parameters
driverDriver binding handle
Return values
rcReturn status code

Definition at line 137 of file efi_veto.c.

137  {
139  union {
141  void *interface;
142  } binding;
143  EFI_STATUS efirc;
144  int rc;
145 
146  /* Open driver binding protocol */
147  if ( ( efirc = bs->OpenProtocol (
149  &binding.interface, efi_image_handle, driver,
150  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
151  rc = -EEFI ( efirc );
152  DBGC ( driver, "EFIVETO %s could not open driver binding "
153  "protocol: %s\n", efi_handle_name ( driver ),
154  strerror ( rc ) );
155  return rc;
156  }
157 
158  /* Close driver binding protocol */
160  efi_image_handle, driver );
161 
162  /* Uninstall driver binding protocol */
163  if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
165  binding.binding, NULL ) ) != 0 ) {
166  rc = -EEFI ( efirc );
167  DBGC ( driver, "EFIVETO %s could not uninstall driver "
168  "binding protocol: %s\n",
169  efi_handle_name ( driver ), strerror ( rc ) );
170  return rc;
171  }
172 
173  DBGC2 ( driver, "EFIVETO %s uninstalled driver binding protocol\n",
174  efi_handle_name ( driver ) );
175  return 0;
176 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
An object interface.
Definition: interface.h:124
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1916
This protocol provides the services required to determine if a driver supports a given controller.
#define DBGC2(...)
Definition: compiler.h:522
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
EFI_GUID efi_driver_binding_protocol_guid
Driver binding protocol GUID.
Definition: efi_guid.c:148
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGC2, EEFI, efi_driver_binding_protocol_guid, efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_systab, NULL, EFI_BOOT_SERVICES::OpenProtocol, rc, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_veto_destroy().

◆ efi_veto_close_protocol()

static int efi_veto_close_protocol ( EFI_HANDLE  driver,
EFI_HANDLE  handle,
EFI_GUID protocol 
)
static

Close protocol on handle potentially opened by an EFI driver.

Parameters
driverDriver binding handle
handlePotentially opened handle
protocolOpened protocol
Return values
rcReturn status code

Definition at line 186 of file efi_veto.c.

187  {
192  UINTN count;
193  unsigned int i;
194  EFI_STATUS efirc;
195  int rc;
196 
197  /* Retrieve list of openers */
198  if ( ( efirc = bs->OpenProtocolInformation ( handle, protocol, &openers,
199  &count ) ) != 0 ) {
200  rc = -EEFI ( efirc );
201  DBGC ( driver, "EFIVETO %s could not retrieve openers",
202  efi_handle_name ( driver ) );
203  DBGC ( driver, " of %s %s: %s", efi_handle_name ( handle ),
204  efi_guid_ntoa ( protocol ), strerror ( rc ) );
205  goto err_list;
206  }
207 
208  /* Close anything opened by this driver */
209  for ( i = 0 ; i < count ; i++ ) {
210  opener = &openers[i];
211  if ( opener->AgentHandle != driver )
212  continue;
213  controller = opener->ControllerHandle;
214  DBGC_EFI_OPENER ( driver, handle, protocol, opener );
215  if ( ( efirc = bs->CloseProtocol ( handle, protocol, driver,
216  controller ) ) != 0 ) {
217  rc = -EEFI ( efirc );
218  DBGC ( driver, "EFIVETO %s could not close stray open",
219  efi_handle_name ( driver ) );
220  DBGC ( driver, " of %s: %s\n",
221  efi_handle_name ( handle ), strerror ( rc ) );
222  goto err_close;
223  }
224  }
225 
226  /* Success */
227  rc = 0;
228 
229  err_close:
230  bs->FreePool ( openers );
231  err_list:
232  return rc;
233 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
EFI Oprn Protocol Information Entry.
Definition: UefiSpec.h:1349
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
EFI_HANDLE ControllerHandle
Definition: UefiSpec.h:1351
EFI_HANDLE AgentHandle
Definition: UefiSpec.h:1350
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:192
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation
Definition: UefiSpec.h:1907
uint8_t controller
CD-ROM controller number.
Definition: int13.h:18
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
uint16_t count
Number of entries.
Definition: ena.h:22
EFI_SYSTEM_TABLE * efi_systab
uint16_t protocol
Protocol ID.
Definition: stp.h:18
uint16_t handle
Handle.
Definition: smbios.h:16
Definition: efi.h:50
#define DBGC_EFI_OPENER(...)
Definition: efi.h:284

References EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::AgentHandle, EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, controller, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::ControllerHandle, count, DBGC, DBGC_EFI_OPENER, EEFI, efi_guid_ntoa(), efi_handle_name(), efi_systab, EFI_BOOT_SERVICES::FreePool, handle, EFI_BOOT_SERVICES::OpenProtocolInformation, protocol, rc, and strerror().

Referenced by efi_veto_close_handle().

◆ efi_veto_close_handle()

static int efi_veto_close_handle ( EFI_HANDLE  driver,
EFI_HANDLE  handle 
)
static

Close handle potentially opened by an EFI driver.

Parameters
driverDriver binding handle
handlePotentially opened handle
Return values
rcReturn status code

Definition at line 242 of file efi_veto.c.

242  {
244  EFI_GUID **protocols;
245  UINTN count;
246  unsigned int i;
247  EFI_STATUS efirc;
248  int rc;
249 
250  /* Retrieve list of protocols */
251  if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
252  &count ) ) != 0 ) {
253  rc = -EEFI ( efirc );
254  DBGC ( driver, "EFIVETO %s could not retrieve protocols",
255  efi_handle_name ( driver ) );
256  DBGC ( driver, " for %s: %s\n",
257  efi_handle_name ( handle ), strerror ( rc ) );
258  goto err_list;
259  }
260 
261  /* Close each protocol */
262  for ( i = 0 ; i < count ; i++ ) {
263  if ( ( rc = efi_veto_close_protocol ( driver, handle,
264  protocols[i] ) ) != 0 )
265  goto err_close;
266  }
267 
268  /* Success */
269  rc = 0;
270 
271  err_close:
272  bs->FreePool ( protocols );
273  err_list:
274  return rc;
275 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
128 bit buffer containing a unique identifier value.
Definition: Base.h:263
#define DBGC(...)
Definition: compiler.h:505
static int efi_veto_close_protocol(EFI_HANDLE driver, EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol on handle potentially opened by an EFI driver.
Definition: efi_veto.c:186
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
EFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle
Definition: UefiSpec.h:1912
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
uint16_t count
Number of entries.
Definition: ena.h:22
EFI_SYSTEM_TABLE * efi_systab
uint16_t handle
Handle.
Definition: smbios.h:16

References EFI_SYSTEM_TABLE::BootServices, count, DBGC, EEFI, efi_handle_name(), efi_systab, efi_veto_close_protocol(), EFI_BOOT_SERVICES::FreePool, handle, EFI_BOOT_SERVICES::ProtocolsPerHandle, rc, and strerror().

Referenced by efi_veto_close().

◆ efi_veto_close()

static int efi_veto_close ( EFI_HANDLE  driver)
static

Close all remaining handles opened by an EFI driver.

Parameters
driverDriver binding handle
Return values
rcReturn status code

Definition at line 283 of file efi_veto.c.

283  {
285  EFI_HANDLE *handles;
286  UINTN count;
287  unsigned int i;
288  EFI_STATUS efirc;
289  int rc;
290 
291  /* Enumerate all handles */
292  if ( ( efirc = bs->LocateHandleBuffer ( AllHandles, NULL, NULL,
293  &count, &handles ) ) != 0 ) {
294  rc = -EEFI ( efirc );
295  DBGC ( driver, "EFIVETO %s could not enumerate handles: %s\n",
296  efi_handle_name ( driver ), strerror ( rc ) );
297  goto err_list;
298  }
299 
300  /* Close each handle */
301  for ( i = 0 ; i < count ; i++ ) {
302  if ( ( rc = efi_veto_close_handle ( driver,
303  handles[i] ) ) != 0 )
304  goto err_close;
305  }
306 
307  /* Success */
308  rc = 0;
309  DBGC2 ( driver, "EFIVETO %s closed all remaining handles\n",
310  efi_handle_name ( driver ) );
311 
312  err_close:
313  bs->FreePool ( handles );
314  err_list:
315  return rc;
316 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static int efi_veto_close_handle(EFI_HANDLE driver, EFI_HANDLE handle)
Close handle potentially opened by an EFI driver.
Definition: efi_veto.c:242
Retrieve all the handles in the handle database.
Definition: UefiSpec.h:1439
#define DBGC(...)
Definition: compiler.h:505
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
#define DBGC2(...)
Definition: compiler.h:522
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
uint16_t count
Number of entries.
Definition: ena.h:22
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
Definition: efi.h:50
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:1913

References AllHandles, EFI_SYSTEM_TABLE::BootServices, count, DBGC, DBGC2, EEFI, efi_handle_name(), efi_systab, efi_veto_close_handle(), EFI_BOOT_SERVICES::FreePool, EFI_BOOT_SERVICES::LocateHandleBuffer, NULL, rc, and strerror().

Referenced by efi_veto_destroy().

◆ efi_veto_destroy()

static int efi_veto_destroy ( EFI_HANDLE  driver)
static

Terminate an EFI driver with extreme prejudice.

Parameters
driverDriver binding handle
Return values
rcReturn status code

Definition at line 324 of file efi_veto.c.

324  {
325  int rc;
326 
327  /* Disconnect driver from all handles */
328  if ( ( rc = efi_veto_disconnect ( driver ) ) != 0 )
329  return rc;
330 
331  /* Uninstall driver binding protocol */
332  if ( ( rc = efi_veto_uninstall ( driver ) ) != 0 )
333  return rc;
334 
335  /* Close any remaining opened handles */
336  if ( ( rc = efi_veto_close ( driver ) ) != 0 )
337  return rc;
338 
339  DBGC ( driver, "EFIVETO %s forcibly removed\n",
340  efi_handle_name ( driver ) );
341  return 0;
342 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static int efi_veto_close(EFI_HANDLE driver)
Close all remaining handles opened by an EFI driver.
Definition: efi_veto.c:283
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
static int efi_veto_uninstall(EFI_HANDLE driver)
Uninstall an EFI driver binding protocol.
Definition: efi_veto.c:137
static int efi_veto_disconnect(EFI_HANDLE driver)
Disconnect an EFI driver from all handles.
Definition: efi_veto.c:88

References DBGC, efi_handle_name(), efi_veto_close(), efi_veto_disconnect(), efi_veto_uninstall(), and rc.

Referenced by efi_veto_driver().

◆ efi_veto_driver()

static int efi_veto_driver ( EFI_HANDLE  driver)
static

Veto an EFI driver.

Parameters
driverDriver binding handle
Return values
rcReturn status code

Definition at line 350 of file efi_veto.c.

350  {
351  int rc;
352 
353  /* Try gracefully unloading the driver */
354  if ( ( rc = efi_veto_unload ( driver ) ) == 0 )
355  return 0;
356 
357  /* If that fails, use a hammer */
358  if ( ( rc = efi_veto_destroy ( driver ) ) == 0 )
359  return 0;
360 
361  return rc;
362 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int efi_veto_destroy(EFI_HANDLE driver)
Terminate an EFI driver with extreme prejudice.
Definition: efi_veto.c:324
static int efi_veto_unload(EFI_HANDLE driver)
Unload an EFI driver.
Definition: efi_veto.c:66

References efi_veto_destroy(), efi_veto_unload(), and rc.

Referenced by efi_veto().

◆ efi_veto_ip4config()

static int efi_veto_ip4config ( EFI_DRIVER_BINDING_PROTOCOL *binding  __unused,
EFI_LOADED_IMAGE_PROTOCOL *loaded  __unused,
EFI_COMPONENT_NAME_PROTOCOL *wtf  __unused,
const char *  manufacturer,
const CHAR16 name 
)
static

Veto Ip4ConfigDxe driver on some platforms.

Parameters
bindingDriver binding protocol
loadedLoaded image protocol
wtfComponent name protocol, if present
manufacturerManufacturer name, if present
nameDriver name, if present
Return values
vetoedDriver is to be vetoed

Definition at line 375 of file efi_veto.c.

378  {
379  static const CHAR16 ip4cfg[] = L"IP4 CONFIG Network Service Driver";
380  static const char *dell = "Dell Inc.";
381  static const char *itautec = "Itautec S.A.";
382 
383  /* Check manufacturer and driver name */
384  if ( ! manufacturer )
385  return 0;
386  if ( ! name )
387  return 0;
388  if ( ( strcmp ( manufacturer, dell ) != 0 ) &&
389  ( strcmp ( manufacturer, itautec ) != 0 ) )
390  return 0;
391  if ( memcmp ( name, ip4cfg, sizeof ( ip4cfg ) ) != 0 )
392  return 0;
393 
394  return 1;
395 }
const char * name
Definition: ath9k_hw.c:1984
unsigned short CHAR16
Definition: ProcessorBind.h:59
uint8_t manufacturer
Manufacturer string.
Definition: smbios.h:14
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114

References manufacturer, memcmp(), name, and strcmp().

◆ efi_veto_hp_xhci()

static int efi_veto_hp_xhci ( EFI_DRIVER_BINDING_PROTOCOL *binding  __unused,
EFI_LOADED_IMAGE_PROTOCOL *loaded  __unused,
EFI_COMPONENT_NAME_PROTOCOL *wtf  __unused,
const char *  manufacturer,
const CHAR16 name 
)
static

Veto HP XhciDxe driver.

Parameters
bindingDriver binding protocol
loadedLoaded image protocol
wtfComponent name protocol, if present
manufacturerManufacturer name, if present
nameDriver name, if present
Return values
vetoedDriver is to be vetoed

Definition at line 408 of file efi_veto.c.

411  {
412  static const CHAR16 xhci[] = L"Usb Xhci Driver";
413  static const char *hp = "HP";
414  struct pci_driver *driver;
415 
416  /* Check manufacturer and driver name */
417  if ( ! manufacturer )
418  return 0;
419  if ( ! name )
420  return 0;
421  if ( strcmp ( manufacturer, hp ) != 0 )
422  return 0;
423  if ( memcmp ( name, xhci, sizeof ( xhci ) ) != 0 )
424  return 0;
425 
426  /* Veto driver only if we have our own xHCI driver */
427  for_each_table_entry ( driver, PCI_DRIVERS ) {
428  if ( driver->class.class ==
431  return 1;
432  }
433  }
434 
435  return 0;
436 }
const char * name
Definition: ath9k_hw.c:1984
struct pci_class_id class
PCI class ID.
Definition: pci.h:236
A PCI driver.
Definition: pci.h:230
unsigned short CHAR16
Definition: ProcessorBind.h:59
uint32_t class
Class.
Definition: pci.h:172
#define PCI_CLASS_SERIAL_USB_XHCI
xHCI USB controller
Definition: pci.h:136
#define PCI_CLASS_SERIAL
Definition: Pci22.h:272
#define PCI_CLASS(base, sub, progif)
Construct PCI class.
Definition: pci.h:147
#define PCI_CLASS_SERIAL_USB
Definition: Pci22.h:278
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
uint8_t manufacturer
Manufacturer string.
Definition: smbios.h:14
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
#define PCI_DRIVERS
PCI driver table.
Definition: pci.h:253

References pci_class_id::class, pci_driver::class, for_each_table_entry, manufacturer, memcmp(), name, PCI_CLASS, PCI_CLASS_SERIAL, PCI_CLASS_SERIAL_USB, PCI_CLASS_SERIAL_USB_XHCI, PCI_DRIVERS, and strcmp().

◆ efi_veto_find()

static int efi_veto_find ( EFI_HANDLE  driver,
const char *  manufacturer,
struct efi_veto **  veto 
)
static

Find driver veto, if any.

Parameters
driverDriver binding handle
manufacturerManufacturer name, if present
Return values
vetoDriver veto, or NULL
rcReturn status code

Definition at line 458 of file efi_veto.c.

459  {
461  union {
463  void *interface;
464  } binding;
465  union {
467  void *interface;
468  } loaded;
469  union {
471  void *interface;
472  } wtf;
473  CHAR16 *name;
474  unsigned int i;
476  EFI_STATUS efirc;
477  int rc;
478 
479  DBGC2 ( &efi_vetoes, "EFIVETO checking %s\n",
480  efi_handle_name ( driver ) );
481 
482  /* Mark as not vetoed */
483  *veto = NULL;
484 
485  /* Open driver binding protocol */
486  if ( ( efirc = bs->OpenProtocol (
488  &binding.interface, efi_image_handle, driver,
489  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
490  rc = -EEFI ( efirc );
491  DBGC ( driver, "EFIVETO %s could not open driver binding "
492  "protocol: %s\n", efi_handle_name ( driver ),
493  strerror ( rc ) );
494  goto err_binding;
495  }
496  image = binding.binding->ImageHandle;
497 
498  /* Open loaded image protocol */
499  if ( ( efirc = bs->OpenProtocol (
501  &loaded.interface, efi_image_handle, image,
502  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
503  rc = -EEFI ( efirc );
504  DBGC ( driver, "EFIVETO %s could not open",
505  efi_handle_name ( driver ) );
506  DBGC ( driver, " %s loaded image protocol: %s\n",
507  efi_handle_name ( image ), strerror ( rc ) );
508  goto err_loaded;
509  }
510 
511  /* Open component name protocol, if present*/
512  if ( ( efirc = bs->OpenProtocol (
514  &wtf.interface, efi_image_handle, driver,
515  EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
516  /* Ignore failure; is not required to be present */
517  wtf.interface = NULL;
518  }
519 
520  /* Get driver name, if available */
521  if ( wtf.wtf &&
522  ( ( efirc = wtf.wtf->GetDriverName ( wtf.wtf, "eng",
523  &name ) == 0 ) ) ) {
524  /* Driver has a name */
525  } else {
526  /* Ignore failure; name is not required to be present */
527  name = NULL;
528  }
529 
530  /* Check vetoes */
531  for ( i = 0 ; i < ( sizeof ( efi_vetoes ) /
532  sizeof ( efi_vetoes[0] ) ) ; i++ ) {
533  if ( efi_vetoes[i].veto ( binding.binding, loaded.loaded,
534  wtf.wtf, manufacturer, name ) ) {
535  *veto = &efi_vetoes[i];
536  break;
537  }
538  }
539 
540  /* Success */
541  rc = 0;
542 
543  /* Close protocols */
544  if ( wtf.wtf ) {
546  efi_image_handle, driver );
547  }
550  err_loaded:
552  efi_image_handle, driver );
553  err_binding:
554  return rc;
555 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
This protocol is used to retrieve user readable names of drivers and controllers managed by UEFI Driv...
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static struct efi_veto efi_vetoes[]
Driver vetoes.
Definition: efi_veto.c:439
#define DBGC(...)
Definition: compiler.h:505
EFI_GUID efi_loaded_image_protocol_guid
Loaded image protocol GUID.
Definition: efi_guid.c:184
unsigned short CHAR16
Definition: ProcessorBind.h:59
An executable image.
Definition: image.h:24
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
Can be used on any image handle to obtain information about the loaded image.
Definition: LoadedImage.h:51
An object interface.
Definition: interface.h:124
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
This protocol provides the services required to determine if a driver supports a given controller.
uint8_t manufacturer
Manufacturer string.
Definition: smbios.h:14
#define DBGC2(...)
Definition: compiler.h:522
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
EFI_GUID efi_component_name_protocol_guid
Component name protocol GUID.
Definition: efi_guid.c:120
EFI_GUID efi_driver_binding_protocol_guid
Driver binding protocol GUID.
Definition: efi_guid.c:148
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
Definition: efi.h:50

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGC2, EEFI, efi_component_name_protocol_guid, efi_driver_binding_protocol_guid, efi_handle_name(), efi_image_handle, efi_loaded_image_protocol_guid, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_systab, efi_vetoes, manufacturer, name, NULL, EFI_BOOT_SERVICES::OpenProtocol, rc, and strerror().

Referenced by efi_veto().

◆ efi_veto()

void efi_veto ( void  )

Remove any vetoed drivers.

Definition at line 561 of file efi_veto.c.

561  {
563  struct efi_veto *veto;
564  EFI_HANDLE *drivers;
565  EFI_HANDLE driver;
566  UINTN num_drivers;
567  unsigned int i;
568  char *manufacturer;
569  EFI_STATUS efirc;
570  int rc;
571 
572  /* Locate all driver binding protocol handles */
573  if ( ( efirc = bs->LocateHandleBuffer (
575  NULL, &num_drivers, &drivers ) ) != 0 ) {
576  rc = -EEFI ( efirc );
577  DBGC ( &efi_vetoes, "EFIVETO could not list all drivers: "
578  "%s\n", strerror ( rc ) );
579  return;
580  }
581 
582  /* Get manufacturer name */
583  fetch_string_setting_copy ( NULL, &manufacturer_setting,
584  &manufacturer );
585 
586  /* Unload any vetoed drivers */
587  for ( i = 0 ; i < num_drivers ; i++ ) {
588  driver = drivers[i];
589  if ( ( rc = efi_veto_find ( driver, manufacturer,
590  &veto ) ) != 0 ) {
591  DBGC ( driver, "EFIVETO %s could not determine "
592  "vetoing: %s\n",
593  efi_handle_name ( driver ), strerror ( rc ) );
594  continue;
595  }
596  if ( ! veto )
597  continue;
598  DBGC ( driver, "EFIVETO %s is vetoed (%s)\n",
599  efi_handle_name ( driver ), veto->name );
600  if ( ( rc = efi_veto_driver ( driver ) ) != 0 ) {
601  DBGC ( driver, "EFIVETO %s could not veto: %s\n",
602  efi_handle_name ( driver ), strerror ( rc ) );
603  }
604  }
605 
606  /* Free manufacturer name */
607  free ( manufacturer );
608 
609  /* Free handle list */
610  bs->FreePool ( drivers );
611 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static struct efi_veto efi_vetoes[]
Driver vetoes.
Definition: efi_veto.c:439
#define DBGC(...)
Definition: compiler.h:505
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition: settings.c:877
int(* veto)(EFI_DRIVER_BINDING_PROTOCOL *binding, EFI_LOADED_IMAGE_PROTOCOL *loaded, EFI_COMPONENT_NAME_PROTOCOL *wtf, const char *manufacturer, const CHAR16 *name)
Check if driver is vetoed.
Definition: efi_veto.c:54
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static int efi_veto_find(EFI_HANDLE driver, const char *manufacturer, struct efi_veto **veto)
Find driver veto, if any.
Definition: efi_veto.c:458
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
EFI Boot Services Table.
Definition: UefiSpec.h:1836
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
uint8_t manufacturer
Manufacturer string.
Definition: smbios.h:14
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
Retrieve the set of handles from the handle database that support a specified protocol.
Definition: UefiSpec.h:1448
EFI_SYSTEM_TABLE * efi_systab
static int efi_veto_driver(EFI_HANDLE driver)
Veto an EFI driver.
Definition: efi_veto.c:350
EFI_GUID efi_driver_binding_protocol_guid
Driver binding protocol GUID.
Definition: efi_guid.c:148
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A driver veto.
Definition: efi_veto.c:41
Definition: efi.h:50
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:1913

References EFI_SYSTEM_TABLE::BootServices, ByProtocol, DBGC, EEFI, efi_driver_binding_protocol_guid, efi_handle_name(), efi_systab, efi_veto_driver(), efi_veto_find(), efi_vetoes, fetch_string_setting_copy(), free, EFI_BOOT_SERVICES::FreePool, EFI_BOOT_SERVICES::LocateHandleBuffer, manufacturer, NULL, rc, strerror(), and efi_veto::veto.

Referenced by efi_probe().

Variable Documentation

◆ efi_vetoes

struct efi_veto efi_vetoes[]
static
Initial value:
= {
{
.name = "Ip4Config",
},
{
.name = "HP Xhci",
},
}
static int efi_veto_hp_xhci(EFI_DRIVER_BINDING_PROTOCOL *binding __unused, EFI_LOADED_IMAGE_PROTOCOL *loaded __unused, EFI_COMPONENT_NAME_PROTOCOL *wtf __unused, const char *manufacturer, const CHAR16 *name)
Veto HP XhciDxe driver.
Definition: efi_veto.c:408
static int efi_veto_ip4config(EFI_DRIVER_BINDING_PROTOCOL *binding __unused, EFI_LOADED_IMAGE_PROTOCOL *loaded __unused, EFI_COMPONENT_NAME_PROTOCOL *wtf __unused, const char *manufacturer, const CHAR16 *name)
Veto Ip4ConfigDxe driver on some platforms.
Definition: efi_veto.c:375

Driver vetoes.

Definition at line 439 of file efi_veto.c.

Referenced by efi_veto(), and efi_veto_find().