Annotation of qemu/roms/ipxe/src/interface/efi/efi_driver.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (C) 2011 Michael Brown <[email protected]>.
                      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., 675 Mass Ave, Cambridge, MA 02139, USA.
                     17:  */
                     18: 
                     19: FILE_LICENCE ( GPL2_OR_LATER );
                     20: 
                     21: #include <stddef.h>
                     22: #include <stdio.h>
                     23: #include <ipxe/efi/efi.h>
                     24: #include <ipxe/efi/Protocol/DriverBinding.h>
                     25: #include <ipxe/efi/Protocol/ComponentName2.h>
                     26: #include <ipxe/efi/efi_strings.h>
                     27: #include <ipxe/efi/efi_driver.h>
                     28: #include <config/general.h>
                     29: 
                     30: /** @file
                     31:  *
                     32:  * EFI driver interface
                     33:  *
                     34:  */
                     35: 
                     36: /** EFI driver binding protocol GUID */
                     37: static EFI_GUID efi_driver_binding_protocol_guid
                     38:        = EFI_DRIVER_BINDING_PROTOCOL_GUID;
                     39: 
                     40: /** EFI component name protocol GUID */
                     41: static EFI_GUID efi_component_name2_protocol_guid
                     42:        = EFI_COMPONENT_NAME2_PROTOCOL_GUID;
                     43: 
                     44: /**
                     45:  * Find end of device path
                     46:  *
                     47:  * @v path             Path to device
                     48:  * @ret path_end       End of device path
                     49:  */
                     50: EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
                     51: 
                     52:        while ( path->Type != END_DEVICE_PATH_TYPE ) {
                     53:                path = ( ( ( void * ) path ) +
                     54:                         /* There's this amazing new-fangled thing known as
                     55:                          * a UINT16, but who wants to use one of those? */
                     56:                         ( ( path->Length[1] << 8 ) | path->Length[0] ) );
                     57:        }
                     58: 
                     59:        return path;
                     60: }
                     61: 
                     62: /**
                     63:  * Look up driver name
                     64:  *
                     65:  * @v wtf              Component name protocol
                     66:  * @v language         Language to use
                     67:  * @v driver_name      Driver name to fill in
                     68:  * @ret efirc          EFI status code
                     69:  */
                     70: static EFI_STATUS EFIAPI
                     71: efi_driver_get_driver_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf,
                     72:                             CHAR8 *language __unused, CHAR16 **driver_name ) {
                     73:        struct efi_driver *efidrv =
                     74:                container_of ( wtf, struct efi_driver, wtf );
                     75: 
                     76:        *driver_name = efidrv->wname;
                     77:        return 0;
                     78: }
                     79: 
                     80: /**
                     81:  * Look up controller name
                     82:  *
                     83:  * @v wtf              Component name protocol
                     84:  * @v device           Device
                     85:  * @v child            Child device, or NULL
                     86:  * @v language         Language to use
                     87:  * @v driver_name      Device name to fill in
                     88:  * @ret efirc          EFI status code
                     89:  */
                     90: static EFI_STATUS EFIAPI
                     91: efi_driver_get_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused,
                     92:                                 EFI_HANDLE device __unused,
                     93:                                 EFI_HANDLE child __unused,
                     94:                                 CHAR8 *language __unused,
                     95:                                 CHAR16 **controller_name __unused ) {
                     96: 
                     97:        /* Just let EFI use the default Device Path Name */
                     98:        return EFI_UNSUPPORTED;
                     99: }
                    100: 
                    101: /**
                    102:  * Install EFI driver
                    103:  *
                    104:  * @v efidrv           EFI driver
                    105:  * @ret efirc          EFI status code
                    106:  */
                    107: EFI_STATUS efi_driver_install ( struct efi_driver *efidrv ) {
                    108:        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
                    109:        EFI_DRIVER_BINDING_PROTOCOL *driver = &efidrv->driver;
                    110:        EFI_COMPONENT_NAME2_PROTOCOL *wtf = &efidrv->wtf;
                    111:        EFI_STATUS efirc;
                    112: 
                    113:        /* Configure driver binding protocol */
                    114:        driver->ImageHandle = efi_image_handle;
                    115: 
                    116:        /* Configure component name protocol */
                    117:        wtf->GetDriverName = efi_driver_get_driver_name;
                    118:        wtf->GetControllerName = efi_driver_get_controller_name;
                    119:        wtf->SupportedLanguages = "en";
                    120: 
                    121:        /* Fill in driver name */
                    122:        efi_snprintf ( efidrv->wname,
                    123:                       ( sizeof ( efidrv->wname ) /
                    124:                         sizeof ( efidrv->wname[0] ) ),
                    125:                       PRODUCT_SHORT_NAME " - %s", efidrv->name );
                    126: 
                    127:        /* Install driver */
                    128:        if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
                    129:                        &driver->DriverBindingHandle,
                    130:                        &efi_driver_binding_protocol_guid, driver,
                    131:                        &efi_component_name2_protocol_guid, wtf,
                    132:                        NULL ) ) != 0 ) {
                    133:                DBGC ( efidrv, "EFIDRV %s could not install protocol: %s\n",
                    134:                       efidrv->name, efi_strerror ( efirc ) );
                    135:                return efirc;
                    136:        }
                    137: 
                    138:        DBGC ( efidrv, "EFIDRV %s installed\n", efidrv->name );
                    139:        return 0;
                    140: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.