iPXE
efi_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19 
20 FILE_LICENCE ( GPL2_OR_LATER );
21 
22 #include <stddef.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <errno.h>
27 #include <ipxe/version.h>
28 #include <ipxe/efi/efi.h>
32 #include <ipxe/efi/efi_strings.h>
33 #include <ipxe/efi/efi_path.h>
34 #include <ipxe/efi/efi_driver.h>
35 
36 /** @file
37  *
38  * EFI driver interface
39  *
40  */
41 
43 
44 /** List of controlled EFI devices */
45 static LIST_HEAD ( efi_devices );
46 
47 /** We are currently disconnecting drivers */
49 
50 /**
51  * Allocate new EFI device
52  *
53  * @v device EFI device handle
54  * @ret efidev EFI device, or NULL on error
55  */
57  struct efi_device *efidev = NULL;
59  EFI_DEVICE_PATH_PROTOCOL *path_end;
60  size_t path_len;
61  int rc;
62 
63  /* Open device path */
65  &path ) ) != 0 ) {
66  DBGC ( device, "EFIDRV %s could not open device path: %s\n",
67  efi_handle_name ( device ), strerror ( rc ) );
68  return NULL;
69  }
70  path_len = ( efi_path_len ( path ) + sizeof ( *path_end ) );
71 
72  /* Allocate and initialise structure */
73  efidev = zalloc ( sizeof ( *efidev ) + path_len );
74  if ( ! efidev )
75  return NULL;
76  efidev->device = device;
77  efidev->dev.desc.bus_type = BUS_TYPE_EFI;
78  efidev->path = ( ( ( void * ) efidev ) + sizeof ( *efidev ) );
79  memcpy ( efidev->path, path, path_len );
80  INIT_LIST_HEAD ( &efidev->dev.children );
81  list_add ( &efidev->dev.siblings, &efi_devices );
82 
83  return efidev;
84 }
85 
86 /**
87  * Free EFI device
88  *
89  * @v efidev EFI device
90  */
91 void efidev_free ( struct efi_device *efidev ) {
92 
93  assert ( list_empty ( &efidev->dev.children ) );
94  list_del ( &efidev->dev.siblings );
95  free ( efidev );
96 }
97 
98 /**
99  * Find EFI device
100  *
101  * @v device EFI device handle (or child handle)
102  * @ret efidev EFI device, or NULL if not found
103  */
105  struct efi_device *efidev;
106 
107  /* Avoid false positive matches against NULL children */
108  if ( ! device )
109  return NULL;
110 
111  /* Look for an existing EFI device */
112  list_for_each_entry ( efidev, &efi_devices, dev.siblings ) {
113  if ( ( device == efidev->device ) ||
114  ( device == efidev->child ) ) {
115  return efidev;
116  }
117  }
118 
119  return NULL;
120 }
121 
122 /**
123  * Get parent EFI device
124  *
125  * @v dev Generic device
126  * @ret efidev Parent EFI device, or NULL
127  */
128 struct efi_device * efidev_parent ( struct device *dev ) {
129  struct device *parent;
130  struct efi_device *efidev;
131 
132  /* Walk upwards until we find a registered EFI device */
133  while ( ( parent = dev->parent ) ) {
134  list_for_each_entry ( efidev, &efi_devices, dev.siblings ) {
135  if ( parent == &efidev->dev )
136  return efidev;
137  }
138  dev = parent;
139  }
140 
141  return NULL;
142 }
143 
144 /**
145  * Check to see if driver supports a device
146  *
147  * @v driver EFI driver
148  * @v device EFI device
149  * @v child Path to child device, if any
150  * @ret efirc EFI status code
151  */
152 static EFI_STATUS EFIAPI
155  struct efi_driver *efidrv;
156  unsigned int count;
157  int rc;
158 
159  DBGCP ( device, "EFIDRV %s DRIVER_SUPPORTED",
160  efi_handle_name ( device ) );
161  if ( child )
162  DBGCP ( device, " (child %s)", efi_devpath_text ( child ) );
163  DBGCP ( device, "\n" );
164 
165  /* Do nothing if we are already driving this device */
166  if ( efidev_find ( device ) != NULL ) {
167  DBGCP ( device, "EFIDRV %s is already started\n",
168  efi_handle_name ( device ) );
169  return EFI_ALREADY_STARTED;
170  }
171 
172  /* Count drivers claiming to support this device */
173  count = 0;
174  for_each_table_entry ( efidrv, EFI_DRIVERS ) {
175  if ( ( rc = efidrv->supported ( device ) ) == 0 ) {
176  DBGC ( device, "EFIDRV %s has driver \"%s\"\n",
177  efi_handle_name ( device ), efidrv->name );
178  count++;
179  }
180  }
181 
182  /* Check that we have at least one driver */
183  if ( ! count ) {
184  DBGCP ( device, "EFIDRV %s has no driver\n",
185  efi_handle_name ( device ) );
186  return EFI_UNSUPPORTED;
187  }
188 
189  return 0;
190 }
191 
192 /**
193  * Attach driver to device
194  *
195  * @v driver EFI driver
196  * @v device EFI device
197  * @v child Path to child device, if any
198  * @ret efirc EFI status code
199  */
200 static EFI_STATUS EFIAPI
203  struct efi_driver *efidrv;
204  struct efi_device *efidev;
205  struct efi_saved_tpl tpl;
206  EFI_STATUS efirc;
207  int rc;
208 
209  DBGC ( device, "EFIDRV %s DRIVER_START", efi_handle_name ( device ) );
210  if ( child )
211  DBGC ( device, " (child %s)", efi_devpath_text ( child ) );
212  DBGC ( device, "\n" );
213 
214  /* Do nothing if we are already driving this device */
215  efidev = efidev_find ( device );
216  if ( efidev ) {
217  DBGCP ( device, "EFIDRV %s is already started\n",
218  efi_handle_name ( device ) );
219  efirc = EFI_ALREADY_STARTED;
220  goto err_already_started;
221  }
222 
223  /* Raise TPL */
224  efi_raise_tpl ( &tpl );
225 
226  /* Do nothing if we are currently disconnecting drivers */
227  if ( efi_driver_disconnecting ) {
228  DBGC ( device, "EFIDRV %s refusing to start during "
229  "disconnection\n", efi_handle_name ( device ) );
230  efirc = EFI_NOT_READY;
231  goto err_disconnecting;
232  }
233 
234  /* Add new device */
235  efidev = efidev_alloc ( device );
236  if ( ! efidev ) {
237  efirc = EFI_OUT_OF_RESOURCES;
238  goto err_alloc;
239  }
240 
241  /* Try to start this device */
242  for_each_table_entry ( efidrv, EFI_DRIVERS ) {
243  if ( ( rc = efidrv->supported ( device ) ) != 0 ) {
244  DBGC ( device, "EFIDRV %s is not supported by driver "
245  "\"%s\": %s\n", efi_handle_name ( device ),
246  efidrv->name,
247  strerror ( rc ) );
248  continue;
249  }
250  if ( ( rc = efidrv->start ( efidev ) ) == 0 ) {
251  efidev->driver = efidrv;
252  DBGC ( device, "EFIDRV %s using driver \"%s\"\n",
254  efidev->driver->name );
255  efi_restore_tpl ( &tpl );
256  return 0;
257  }
258  DBGC ( device, "EFIDRV %s could not start driver \"%s\": %s\n",
259  efi_handle_name ( device ), efidrv->name,
260  strerror ( rc ) );
261  }
262  efirc = EFI_UNSUPPORTED;
263 
264  efidev_free ( efidev );
265  err_alloc:
266  err_disconnecting:
267  efi_restore_tpl ( &tpl );
268  err_already_started:
269  return efirc;
270 }
271 
272 /**
273  * Detach driver from device
274  *
275  * @v driver EFI driver
276  * @v device EFI device
277  * @v pci PCI device
278  * @v num_children Number of child devices
279  * @v children List of child devices
280  * @ret efirc EFI status code
281  */
282 static EFI_STATUS EFIAPI
284  EFI_HANDLE device, UINTN num_children,
285  EFI_HANDLE *children ) {
286  struct efi_driver *efidrv;
287  struct efi_device *efidev;
288  struct efi_saved_tpl tpl;
289  UINTN i;
290 
291  DBGC ( device, "EFIDRV %s DRIVER_STOP", efi_handle_name ( device ) );
292  for ( i = 0 ; i < num_children ; i++ ) {
293  DBGC ( device, "%s%s", ( i ? ", " : " child " ),
294  efi_handle_name ( children[i] ) );
295  }
296  DBGC ( device, "\n" );
297 
298  /* Do nothing unless we are driving this device */
299  efidev = efidev_find ( device );
300  if ( ! efidev ) {
301  DBGCP ( device, "EFIDRV %s is not started\n",
302  efi_handle_name ( device ) );
303  return 0;
304  }
305 
306  /* Raise TPL */
307  efi_raise_tpl ( &tpl );
308 
309  /* Stop this device */
310  efidrv = efidev->driver;
311  assert ( efidrv != NULL );
312  efidrv->stop ( efidev );
313  efidev_free ( efidev );
314 
315  efi_restore_tpl ( &tpl );
316  return 0;
317 }
318 
319 /** EFI driver binding protocol */
322  .Start = efi_driver_start,
323  .Stop = efi_driver_stop,
324 };
325 
326 /**
327  * Look up driver name
328  *
329  * @v wtf Component name protocol
330  * @v language Language to use
331  * @v driver_name Driver name to fill in
332  * @ret efirc EFI status code
333  */
334 static EFI_STATUS EFIAPI
336  CHAR8 *language __unused, CHAR16 **driver_name ) {
337  const wchar_t *name;
338 
340  *driver_name = ( ( wchar_t * ) name );
341  return 0;
342 }
343 
344 /**
345  * Look up controller name
346  *
347  * @v wtf Component name protocol
348  * @v device Device
349  * @v child Child device, or NULL
350  * @v language Language to use
351  * @v driver_name Device name to fill in
352  * @ret efirc EFI status code
353  */
354 static EFI_STATUS EFIAPI
357  CHAR8 *language, CHAR16 **controller_name ) {
359  int rc;
360 
361  /* Delegate to the EFI_COMPONENT_NAME2_PROTOCOL instance
362  * installed on child handle, if present.
363  */
364  if ( ( child != NULL ) &&
366  &name2 ) ) == 0 ) ) {
367  return name2->GetControllerName ( name2, device, child,
368  language, controller_name );
369  }
370 
371  /* Otherwise, let EFI use the default Device Path Name */
372  return EFI_UNSUPPORTED;
373 }
374 
375 /** EFI component name protocol */
378  .GetControllerName = efi_driver_controller_name,
379  .SupportedLanguages = "en",
380 };
381 
382 /**
383  * Install EFI driver
384  *
385  * @ret rc Return status code
386  */
387 int efi_driver_install ( void ) {
389  EFI_STATUS efirc;
390  int rc;
391 
392  /* Calculate driver version number. We use the build
393  * timestamp (in seconds since the Epoch) shifted right by six
394  * bits: this gives us an approximately one-minute resolution
395  * and a scheme which will last until the year 10680.
396  */
398 
399  /* Install protocols on image handle */
402  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
406  NULL ) ) != 0 ) {
407  rc = -EEFI ( efirc );
408  DBGC ( &efi_driver_binding, "EFIDRV could not install "
409  "protocols: %s\n", strerror ( rc ) );
410  return rc;
411  }
412 
413  return 0;
414 }
415 
416 /**
417  * Uninstall EFI driver
418  *
419  */
420 void efi_driver_uninstall ( void ) {
422 
423  /* Uninstall protocols */
428 }
429 
430 /**
431  * Try to disconnect an existing EFI driver
432  *
433  * @v device EFI device
434  * @v protocol Protocol GUID
435  * @ret rc Return status code
436  */
441  EFI_HANDLE driver;
442  UINTN count;
443  unsigned int i;
444  EFI_STATUS efirc;
445  int rc;
446 
447  /* Retrieve list of openers */
448  if ( ( efirc = bs->OpenProtocolInformation ( device, protocol, &openers,
449  &count ) ) != 0 ) {
450  rc = -EEFI ( efirc );
451  DBGC ( device, "EFIDRV %s could not list %s openers: %s\n",
453  strerror ( rc ) );
454  goto err_list;
455  }
456 
457  /* Identify BY_DRIVER opener */
458  driver = NULL;
459  for ( i = 0 ; i < count ; i++ ) {
460  opener = &openers[i];
461  if ( opener->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER ) {
462  driver = opener->AgentHandle;
463  break;
464  }
465  }
466 
467  /* Try to disconnect driver */
468  DBGC ( device, "EFIDRV %s disconnecting %s drivers\n",
470  if ( driver ) {
471  DBGC ( device, "EFIDRV %s disconnecting %s driver ",
473  DBGC ( device, "%s\n", efi_handle_name ( driver ) );
474  if ( ( rc = efi_disconnect ( device, driver ) ) != 0 ) {
475  DBGC ( device, "EFIDRV %s could not disconnect ",
476  efi_handle_name ( device ) );
477  DBGC ( device, "%s: %s\n",
478  efi_handle_name ( driver ), strerror ( rc ) );
479  goto err_disconnect;
480  }
481  }
482 
483  /* Success */
484  rc = 0;
485 
486  err_disconnect:
487  bs->FreePool ( openers );
488  err_list:
489  return rc;
490 }
491 
492 /**
493  * Try to connect EFI driver
494  *
495  * @v device EFI device
496  * @ret rc Return status code
497  */
500  struct efi_driver *efidrv;
501  EFI_STATUS efirc;
502  int rc;
503 
504  /* Check if we want to drive this device */
506  NULL ) ) != 0 ) {
507  /* Not supported; not an error */
508  return 0;
509  }
510 
511  /* Disconnect any existing drivers */
512  DBGC2 ( device, "EFIDRV %s before disconnecting:\n",
513  efi_handle_name ( device ) );
515  DBGC ( device, "EFIDRV %s disconnecting existing drivers\n",
516  efi_handle_name ( device ) );
519  if ( ! efidrv->exclude )
520  continue;
521  if ( ( rc = efidrv->supported ( device ) ) != 0 )
522  continue;
523  if ( ( rc = efidrv->exclude ( device ) ) != 0 ) {
524  DBGC ( device, "EFIDRV %s could not disconnect "
525  "drivers: %s\n", efi_handle_name ( device ),
526  strerror ( rc ) );
527  /* Ignore the error and attempt to connect anyway */
528  }
529  }
531  DBGC2 ( device, "EFIDRV %s after disconnecting:\n",
532  efi_handle_name ( device ) );
534 
535  /* Connect our driver */
536  DBGC ( device, "EFIDRV %s connecting new drivers\n",
537  efi_handle_name ( device ) );
538  if ( ( rc = efi_connect ( device, driver ) ) != 0 ) {
539  DBGC ( device, "EFIDRV %s could not connect new drivers: "
540  "%s\n", efi_handle_name ( device ), strerror ( rc ) );
541  DBGC ( device, "EFIDRV %s connecting driver directly\n",
542  efi_handle_name ( device ) );
543  if ( ( efirc = efi_driver_start ( &efi_driver_binding, device,
544  NULL ) ) != 0 ) {
545  rc = -EEFI ( efirc );
546  DBGC ( device, "EFIDRV %s could not connect driver "
547  "directly: %s\n", efi_handle_name ( device ),
548  strerror ( rc ) );
549  return rc;
550  }
551  }
552  DBGC2 ( device, "EFIDRV %s after connecting:\n",
553  efi_handle_name ( device ) );
555 
556  return 0;
557 }
558 
559 /**
560  * Try to disconnect EFI driver
561  *
562  * @v device EFI device
563  * @ret rc Return status code
564  */
567 
568  /* Disconnect our driver */
570  efi_disconnect ( device, driver );
572 
573  return 0;
574 }
575 
576 /**
577  * Reconnect original EFI driver
578  *
579  * @v device EFI device
580  * @ret rc Return status code
581  */
583 
584  /* Reconnect any available driver */
585  efi_connect ( device, NULL );
586 
587  return 0;
588 }
589 
590 /**
591  * Connect/disconnect EFI driver from all handles
592  *
593  * @v method Connect/disconnect method
594  * @ret rc Return status code
595  */
596 static int efi_driver_handles ( int ( * method ) ( EFI_HANDLE handle ) ) {
598  EFI_HANDLE *handles;
599  UINTN num_handles;
600  EFI_STATUS efirc;
601  UINTN i;
602  int rc;
603 
604  /* Enumerate all handles */
605  if ( ( efirc = bs->LocateHandleBuffer ( AllHandles, NULL, NULL,
606  &num_handles,
607  &handles ) ) != 0 ) {
608  rc = -EEFI ( efirc );
609  DBGC ( &efi_driver_binding, "EFIDRV could not list handles: "
610  "%s\n", strerror ( rc ) );
611  goto err_locate;
612  }
613 
614  /* Connect/disconnect driver from all handles */
615  for ( i = 0 ; i < num_handles ; i++ ) {
616  if ( ( rc = method ( handles[i] ) ) != 0 ) {
617  /* Ignore errors and continue to process
618  * remaining handles.
619  */
620  }
621  }
622 
623  /* Success */
624  rc = 0;
625 
626  bs->FreePool ( handles );
627  err_locate:
628  return rc;
629 }
630 
631 /**
632  * Connect EFI driver to all possible devices
633  *
634  * @ret rc Return status code
635  */
637 
638  DBGC ( &efi_driver_binding, "EFIDRV connecting our drivers\n" );
640 }
641 
642 /**
643  * Disconnect EFI driver from all possible devices
644  *
645  * @ret rc Return status code
646  */
648 
649  DBGC ( &efi_driver_binding, "EFIDRV disconnecting our drivers\n" );
651 }
652 
653 /**
654  * Reconnect original EFI drivers to all possible devices
655  *
656  * @ret rc Return status code
657  */
659 
660  DBGC ( &efi_driver_binding, "EFIDRV reconnecting old drivers\n" );
662 }
int efi_driver_connect_all(void)
Connect EFI driver to all possible devices.
Definition: efi_driver.c:636
void efi_driver_uninstall(void)
Uninstall EFI driver.
Definition: efi_driver.c:420
UEFI DriverBinding Protocol is defined in UEFI specification.
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:117
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
static int efi_driver_connect(EFI_HANDLE device)
Try to connect EFI driver.
Definition: efi_driver.c:498
EFI Oprn Protocol Information Entry.
Definition: UefiSpec.h:1431
static EFI_STATUS EFIAPI efi_driver_name(EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused, CHAR8 *language __unused, CHAR16 **driver_name)
Look up driver name.
Definition: efi_driver.c:335
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
struct efi_driver * driver
Driver for this device.
Definition: efi_driver.h:27
#define EFI_ALREADY_STARTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:134
The device path protocol as defined in UEFI 2.0.
This protocol is used to retrieve user readable names of drivers and controllers managed by UEFI Driv...
EFI driver interface.
int efi_connect(EFI_HANDLE device, EFI_HANDLE driver)
Connect UEFI driver(s)
Definition: efi_connect.c:57
EFI_HANDLE AgentHandle
Definition: UefiSpec.h:1432
FILE_LICENCE(GPL2_OR_LATER)
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
Error codes.
Retrieve all the handles in the handle database.
Definition: UefiSpec.h:1521
void efi_raise_tpl(struct efi_saved_tpl *tpl)
Raise task priority level to internal level.
Definition: efi_init.c:382
EFI_DRIVER_BINDING_SUPPORTED Supported
EFI strings.
static EFI_STATUS EFIAPI efi_driver_controller_name(EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused, EFI_HANDLE device, EFI_HANDLE child, CHAR8 *language, CHAR16 **controller_name)
Look up controller name.
Definition: efi_driver.c:355
void(* stop)(struct efi_device *efidev)
Detach driver from device.
Definition: efi_driver.h:62
void efidev_free(struct efi_device *efidev)
Free EFI device.
Definition: efi_driver.c:91
static int efi_driver_disconnecting
We are currently disconnecting drivers.
Definition: efi_driver.c:48
static struct efi_device * efidev_find(EFI_HANDLE device)
Find EFI device.
Definition: efi_driver.c:104
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1357
static LIST_HEAD(efi_devices)
List of controlled EFI devices.
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2009
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:173
EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME GetControllerName
unsigned short CHAR16
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
int(* exclude)(EFI_HANDLE device)
Exclude existing drivers.
Definition: efi_driver.h:42
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:45
uint8_t method
Definition: ib_mad.h:14
#define for_each_table_entry_reverse(pointer, table)
Iterate through all entries within a linker table in reverse order.
Definition: tables.h:440
uint16_t device
Device ID.
Definition: ena.h:24
struct device * parent
Bus device.
Definition: device.h:88
#define EFI_OUT_OF_RESOURCES
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:123
int(* supported)(EFI_HANDLE device)
Check if driver supports device.
Definition: efi_driver.h:49
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
static EFI_STATUS EFIAPI efi_driver_supported(EFI_DRIVER_BINDING_PROTOCOL *driver __unused, EFI_HANDLE device, EFI_DEVICE_PATH_PROTOCOL *child)
Check to see if driver supports a device.
Definition: efi_driver.c:153
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
EFI_HANDLE child
EFI child device handle (if present)
Definition: efi_driver.h:23
const wchar_t product_wname[]
Wide-character product name string.
Definition: version.c:85
A hardware device.
Definition: device.h:76
char unsigned long const char unsigned long char ** children
Definition: xenstore.h:25
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void efi_driver_reconnect_all(void)
Reconnect original EFI drivers to all possible devices.
Definition: efi_driver.c:658
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
char wtf[42]
Authenticator response string.
Definition: mschapv2.h:18
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
UEFI Component Name 2 Protocol as defined in the UEFI 2.1 specification.
EFI_COMPONENT_NAME2_GET_DRIVER_NAME GetDriverName
UINT32 Attributes
Definition: UefiSpec.h:1434
struct efi_device * efidev_alloc(EFI_HANDLE device)
Allocate new EFI device.
Definition: efi_driver.c:56
static unsigned int count
Number of entries.
Definition: dwmac.h:225
static EFI_STATUS EFIAPI efi_driver_start(EFI_DRIVER_BINDING_PROTOCOL *driver __unused, EFI_HANDLE device, EFI_DEVICE_PATH_PROTOCOL *child)
Attach driver to device.
Definition: efi_driver.c:201
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
Definition: efi_debug.c:247
unsigned long build_timestamp
Build timestamp.
Definition: version.c:58
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
#define EFIAPI
static int efi_driver_reconnect(EFI_HANDLE device)
Reconnect original EFI driver.
Definition: efi_driver.c:582
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
EFI Boot Services Table.
Definition: UefiSpec.h:1930
static int efi_driver_handles(int(*method)(EFI_HANDLE handle))
Connect/disconnect EFI driver from all handles.
Definition: efi_driver.c:596
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:35
EFI_HANDLE DriverBindingHandle
The handle on which this instance of the EFI_DRIVER_BINDING_PROTOCOL is installed.
struct list_head siblings
Devices on the same bus.
Definition: device.h:84
void efi_driver_disconnect_all(void)
Disconnect EFI driver from all possible devices.
Definition: efi_driver.c:647
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2010
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:443
int efi_driver_exclude(EFI_HANDLE device, EFI_GUID *protocol)
Try to disconnect an existing EFI driver.
Definition: efi_driver.c:437
EFI device paths.
UINT64 UINTN
Unsigned value of native width.
#define EFI_NOT_READY
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:120
An EFI device.
Definition: efi_driver.h:17
This protocol provides the services required to determine if a driver supports a given controller.
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:168
Version number.
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_guid.c:725
EFI_GUID efi_component_name2_protocol_guid
Component name 2 protocol GUID.
Definition: efi_guid.c:160
#define BUS_TYPE_EFI
EFI bus type.
Definition: device.h:61
EFI_HANDLE ImageHandle
The image handle of the UEFI driver that produced this instance of the EFI_DRIVER_BINDING_PROTOCOL.
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1949
EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation
Definition: UefiSpec.h:2001
EFI API.
const wchar_t build_wname[]
Wide-character build name string.
Definition: version.c:91
An EFI driver.
Definition: efi_driver.h:33
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
unsigned int bus_type
Bus type.
Definition: device.h:24
An EFI saved task priority level.
Definition: efi.h:79
#define DBGC2(...)
Definition: compiler.h:522
static EFI_DRIVER_BINDING_PROTOCOL efi_driver_binding
EFI driver binding protocol.
Definition: efi_driver.c:42
char CHAR8
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
struct list_head children
Devices attached to this device.
Definition: device.h:86
#define DBGC2_EFI_PROTOCOLS(...)
Definition: efi.h:357
static EFI_STATUS EFIAPI efi_driver_stop(EFI_DRIVER_BINDING_PROTOCOL *driver __unused, EFI_HANDLE device, UINTN num_children, EFI_HANDLE *children)
Detach driver from device.
Definition: efi_driver.c:283
const char * name
Name.
Definition: efi_driver.h:35
struct device_description desc
Device description.
Definition: device.h:82
#define DBGCP(...)
Definition: compiler.h:539
static int efi_driver_disconnect(EFI_HANDLE device)
Try to disconnect EFI driver.
Definition: efi_driver.c:565
EFI_SYSTEM_TABLE * efi_systab
uint16_t protocol
Protocol ID.
Definition: stp.h:18
EFI_DEVICE_PATH_PROTOCOL * path
EFI device path copy.
Definition: efi_driver.h:25
struct efi_device * efidev_parent(struct device *dev)
Get parent EFI device.
Definition: efi_driver.c:128
static EFI_COMPONENT_NAME2_PROTOCOL efi_wtf
EFI component name protocol.
Definition: efi_driver.c:376
#define EFI_DRIVERS
EFI driver table.
Definition: efi_driver.h:66
struct device dev
Generic device.
Definition: efi_driver.h:19
uint16_t handle
Handle.
Definition: smbios.h:16
EFI_GUID efi_driver_binding_protocol_guid
Driver binding protocol GUID.
Definition: efi_guid.c:208
void efi_restore_tpl(struct efi_saved_tpl *tpl)
Restore task priority level.
Definition: efi_init.c:398
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
String functions.
int efi_driver_install(void)
Install EFI driver.
Definition: efi_driver.c:387
Definition: efi.h:61
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:2007
int(* start)(struct efi_device *efidev)
Attach driver to device.
Definition: efi_driver.h:56
UINT32 Version
The version number of the UEFI driver that produced the EFI_DRIVER_BINDING_PROTOCOL.
int efi_disconnect(EFI_HANDLE device, EFI_HANDLE driver)
Disconnect UEFI driver(s)
Definition: efi_connect.c:89