Path: blob/main/stand/efi/libefi/efi_driver_utils.c
105462 views
/*-1* Copyright (c) 2017 Eric McCorkle2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#include "efi.h"27#include "efilib.h"28#include "efi_driver_utils.h"2930static EFI_GUID DriverBindingProtocolGUID = EFI_DRIVER_BINDING_PROTOCOL_GUID;3132EFI_STATUS33connect_controllers(EFI_GUID *filter)34{35EFI_STATUS status;36EFI_HANDLE *handles;37UINTN nhandles, i, hsize;3839nhandles = 0;40hsize = 0;41status = BS->LocateHandle(ByProtocol, filter, NULL,42&hsize, NULL);4344if(status != EFI_BUFFER_TOO_SMALL) {45return (status);46}4748handles = malloc(hsize);49if (handles == NULL)50return (EFI_OUT_OF_RESOURCES);51nhandles = hsize / sizeof(EFI_HANDLE);5253status = BS->LocateHandle(ByProtocol, filter, NULL,54&hsize, handles);5556if(EFI_ERROR(status)) {57return (status);58}5960for(i = 0; i < nhandles; i++) {61BS->ConnectController(handles[i], NULL, NULL, true);62}6364free(handles);6566return (status);67}6869EFI_STATUS70install_driver(EFI_DRIVER_BINDING_PROTOCOL *driver)71{72EFI_STATUS status;7374driver->ImageHandle = IH;75driver->DriverBindingHandle = NULL;76status = BS->InstallMultipleProtocolInterfaces(77&(driver->DriverBindingHandle),78&DriverBindingProtocolGUID, driver,79NULL);8081if (EFI_ERROR(status)) {82printf("Failed to install driver (%ld)!\n",83DECODE_ERROR(status));84}8586return (status);87}888990