123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
-
-
- FILE_LICENCE ( GPL2_OR_LATER );
-
- #include <stddef.h>
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <ipxe/version.h>
- #include <ipxe/efi/efi.h>
- #include <ipxe/efi/Protocol/DriverBinding.h>
- #include <ipxe/efi/Protocol/ComponentName2.h>
- #include <ipxe/efi/efi_strings.h>
- #include <ipxe/efi/efi_driver.h>
-
-
-
-
- static EFI_GUID efi_driver_binding_protocol_guid
- = EFI_DRIVER_BINDING_PROTOCOL_GUID;
-
-
- static EFI_GUID efi_component_name2_protocol_guid
- = EFI_COMPONENT_NAME2_PROTOCOL_GUID;
-
-
- EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
-
- while ( path->Type != END_DEVICE_PATH_TYPE ) {
- path = ( ( ( void * ) path ) +
-
-
- ( ( path->Length[1] << 8 ) | path->Length[0] ) );
- }
-
- return path;
- }
-
-
- static EFI_STATUS EFIAPI
- efi_driver_get_driver_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf,
- CHAR8 *language __unused, CHAR16 **driver_name ) {
- struct efi_driver *efidrv =
- container_of ( wtf, struct efi_driver, wtf );
-
- *driver_name = efidrv->wname;
- return 0;
- }
-
-
- static EFI_STATUS EFIAPI
- efi_driver_get_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;
-
-
-
- if ( ( child != NULL ) &&
- ( ( efirc = bs->OpenProtocol (
- child, &efi_component_name2_protocol_guid,
- &name2.interface, NULL, NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) == 0 ) ) {
- return name2.name2->GetControllerName ( name2.name2, device,
- child, language,
- controller_name );
- }
-
-
- return EFI_UNSUPPORTED;
- }
-
-
- static void efi_driver_connect ( struct efi_driver *efidrv, EFI_HANDLE handle ){
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- EFI_HANDLE drivers[2] = { efidrv->driver.DriverBindingHandle, NULL };
-
- bs->ConnectController ( handle, drivers, NULL, FALSE );
- }
-
-
- static void efi_driver_disconnect ( struct efi_driver *efidrv,
- EFI_HANDLE handle ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
-
- bs->DisconnectController ( handle, efidrv->driver.DriverBindingHandle,
- NULL );
- }
-
-
- static int efi_driver_handles ( struct efi_driver *efidrv,
- void ( * method ) ( struct efi_driver *efidrv,
- EFI_HANDLE handle ) ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- EFI_HANDLE *handles;
- UINTN num_handles;
- EFI_STATUS efirc;
- UINTN i;
- int rc;
-
-
- if ( ( efirc = bs->LocateHandleBuffer ( AllHandles, NULL, NULL,
- &num_handles,
- &handles ) ) != 0 ) {
- rc = -EEFI ( efirc );
- DBGC ( efidrv, "EFIDRV %s could not list handles: %s\n",
- efidrv->name, strerror ( rc ) );
- return rc;
- }
-
-
- for ( i = 0 ; i < num_handles ; i++ )
- method ( efidrv, handles[i] );
-
-
- bs->FreePool ( handles );
-
- return 0;
- }
-
-
- int efi_driver_install ( struct efi_driver *efidrv ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- EFI_DRIVER_BINDING_PROTOCOL *driver = &efidrv->driver;
- EFI_COMPONENT_NAME2_PROTOCOL *wtf = &efidrv->wtf;
- EFI_STATUS efirc;
- int rc;
-
-
- driver->ImageHandle = efi_image_handle;
-
-
- wtf->GetDriverName = efi_driver_get_driver_name;
- wtf->GetControllerName = efi_driver_get_controller_name;
- wtf->SupportedLanguages = "en";
-
-
- efi_snprintf ( efidrv->wname,
- ( sizeof ( efidrv->wname ) /
- sizeof ( efidrv->wname[0] ) ),
- "%s%s%s", product_short_name,
- ( efidrv->name ? " - " : "" ),
- ( efidrv->name ? efidrv->name : "" ) );
-
-
- if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
- &driver->DriverBindingHandle,
- &efi_driver_binding_protocol_guid, driver,
- &efi_component_name2_protocol_guid, wtf,
- NULL ) ) != 0 ) {
- rc = -EEFI ( efirc );
- DBGC ( efidrv, "EFIDRV %s could not install protocol: %s\n",
- efidrv->name, strerror ( rc ) );
- return rc;
- }
-
-
- DBGC ( efidrv, "EFIDRV %s connecting devices\n", efidrv->name );
- efi_driver_handles ( efidrv, efi_driver_connect );
-
- DBGC ( efidrv, "EFIDRV %s installed\n", efidrv->name );
- return 0;
- }
-
-
- void efi_driver_uninstall ( struct efi_driver *efidrv ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
-
-
- DBGC ( efidrv, "EFIDRV %s disconnecting devices\n", efidrv->name );
- efi_driver_handles ( efidrv, efi_driver_disconnect );
-
-
- bs->UninstallMultipleProtocolInterfaces (
- efidrv->driver.DriverBindingHandle,
- &efi_driver_binding_protocol_guid, &efidrv->driver,
- &efi_component_name2_protocol_guid, &efidrv->wtf,
- NULL );
- DBGC ( efidrv, "EFIDRV %s uninstalled\n", efidrv->name );
- }
|