Add definitions and utilities for EFI drivers
This patch adds definitions and utility code for creating EFI drivers using the EFI_DRIVER_BINDING_PROTOCOL. Submitted by: Eric McCorkle Differential Revision: https://reviews.freebsd.org/D11852
This commit is contained in:
parent
fac7b28779
commit
acf82d2659
38
sys/boot/efi/include/efi_driver_utils.h
Normal file
38
sys/boot/efi/include/efi_driver_utils.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*-
|
||||
* Copyright (c) 2017 Eric McCorkle
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _EFI_DRIVER_UTILS_H_
|
||||
#define _EFI_DRIVER_UTILS_H_
|
||||
|
||||
#include <efi.h>
|
||||
#include <efiprot.h>
|
||||
|
||||
extern EFI_STATUS install_driver(EFI_DRIVER_BINDING *driver);
|
||||
extern EFI_STATUS connect_controllers(EFI_GUID *filter);
|
||||
|
||||
#endif
|
45
sys/boot/efi/include/efi_drivers.h
Normal file
45
sys/boot/efi/include/efi_drivers.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*-
|
||||
* Copyright (c) 2016 Eric McCorkle
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _EFI_DRIVERS_H_
|
||||
#define _EFI_DRIVERS_H_
|
||||
|
||||
#include <bootstrap.h>
|
||||
|
||||
typedef struct efi_driver_t {
|
||||
const char *name;
|
||||
void (*init)(void);
|
||||
} efi_driver_t;
|
||||
|
||||
extern struct devsw efipart_dev;
|
||||
extern int efipart_getdesc(struct devdesc *dev, char **out);
|
||||
|
||||
/* EFI drivers. */
|
||||
extern const efi_driver_t fs_driver;
|
||||
|
||||
#endif
|
@ -27,6 +27,8 @@ Revision History
|
||||
|
||||
--*/
|
||||
|
||||
#include <efidef.h>
|
||||
|
||||
//
|
||||
// Device Path protocol
|
||||
//
|
||||
@ -555,4 +557,80 @@ typedef struct _EFI_UNICODE_COLLATION_INTERFACE {
|
||||
CHAR8 *SupportedLanguages;
|
||||
} EFI_UNICODE_COLLATION_INTERFACE;
|
||||
|
||||
//
|
||||
// Driver Binding protocol
|
||||
//
|
||||
|
||||
#define DRIVER_BINDING_PROTOCOL \
|
||||
{ 0x18a031ab, 0xb443, 0x4d1a, {0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71} }
|
||||
|
||||
INTERFACE_DECL(_EFI_DRIVER_BINDING);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_DRIVER_BINDING_SUPPORTED) (
|
||||
IN struct _EFI_DRIVER_BINDING *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH *RemainingPath
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_DRIVER_BINDING_START) (
|
||||
IN struct _EFI_DRIVER_BINDING *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_DEVICE_PATH *RemainingPath
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_DRIVER_BINDING_STOP) (
|
||||
IN struct _EFI_DRIVER_BINDING *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN UINTN NumberOfChildren,
|
||||
IN EFI_HANDLE *ChildHandleBuffer
|
||||
);
|
||||
|
||||
typedef struct _EFI_DRIVER_BINDING {
|
||||
EFI_DRIVER_BINDING_SUPPORTED Supported;
|
||||
EFI_DRIVER_BINDING_START Start;
|
||||
EFI_DRIVER_BINDING_STOP Stop;
|
||||
UINT32 Version;
|
||||
EFI_HANDLE ImageHandle;
|
||||
EFI_HANDLE DriverBindingHandle;
|
||||
} EFI_DRIVER_BINDING;
|
||||
|
||||
//
|
||||
// Component Name Protocol 2
|
||||
//
|
||||
|
||||
#define COMPONENT_NAME2_PROTOCOL \
|
||||
{ 0x6a7a5cff, 0xe8d9, 0x4f70, {0xba, 0xda, 0x75, 0xab, 0x30, 0x25, 0xce, 0x14 } }
|
||||
|
||||
INTERFACE_DECL(_EFI_COMPONENT_NAME2);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_COMPONENT_NAME_GET_DRIVER_NAME) (
|
||||
IN struct _EFI_COMPONENT_NAME2 *This,
|
||||
IN CHAR8 * Language,
|
||||
OUT CHAR16 **DriverName
|
||||
);
|
||||
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *EFI_COMPONENT_NAME_GET_CONTROLLER_NAME) (
|
||||
IN struct _EFI_COMPONENT_NAME2 *This,
|
||||
IN EFI_HANDLE ControllerHandle,
|
||||
IN EFI_HANDLE ChildHandle OPTIONAL,
|
||||
IN CHAR8 *Language,
|
||||
OUT CHAR16 **ControllerName
|
||||
);
|
||||
|
||||
typedef struct _EFI_COMPONENT_NAME2 {
|
||||
EFI_COMPONENT_NAME_GET_DRIVER_NAME GetDriverName;
|
||||
EFI_COMPONENT_NAME_GET_CONTROLLER_NAME GetControllerName;
|
||||
CHAR8 **SupportedLanguages;
|
||||
} EFI_COMPONENT_NAME2;
|
||||
|
||||
#endif
|
||||
|
@ -12,7 +12,7 @@ INTERNALLIB=
|
||||
WARNS?= 2
|
||||
|
||||
SRCS= delay.c devpath.c efi_console.c efinet.c efipart.c env.c errno.c \
|
||||
handles.c wchar.c libefi.c
|
||||
handles.c wchar.c libefi.c efi_driver_utils.c
|
||||
|
||||
.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
|
||||
SRCS+= time.c
|
||||
|
91
sys/boot/efi/libefi/efi_driver_utils.c
Normal file
91
sys/boot/efi/libefi/efi_driver_utils.c
Normal file
@ -0,0 +1,91 @@
|
||||
/*-
|
||||
* Copyright (c) 2017 Eric McCorkle
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
#include "efi_driver_utils.h"
|
||||
|
||||
static EFI_GUID DriverBindingProtocolGUID = DRIVER_BINDING_PROTOCOL;
|
||||
|
||||
EFI_STATUS
|
||||
connect_controllers(EFI_GUID *filter)
|
||||
{
|
||||
EFI_STATUS status;
|
||||
EFI_HANDLE *handles;
|
||||
UINTN nhandles, i, hsize;
|
||||
|
||||
nhandles = 0;
|
||||
hsize = 0;
|
||||
status = BS->LocateHandle(ByProtocol, filter, NULL,
|
||||
&hsize, NULL);
|
||||
|
||||
if(status != EFI_BUFFER_TOO_SMALL) {
|
||||
return (status);
|
||||
}
|
||||
|
||||
handles = malloc(hsize);
|
||||
nhandles = hsize / sizeof(EFI_HANDLE);
|
||||
|
||||
status = BS->LocateHandle(ByProtocol, filter, NULL,
|
||||
&hsize, handles);
|
||||
|
||||
if(EFI_ERROR(status)) {
|
||||
return (status);
|
||||
}
|
||||
|
||||
for(i = 0; i < nhandles; i++) {
|
||||
BS->ConnectController(handles[i], NULL, NULL, true);
|
||||
}
|
||||
|
||||
free(handles);
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
install_driver(EFI_DRIVER_BINDING *driver)
|
||||
{
|
||||
EFI_STATUS status;
|
||||
|
||||
driver->ImageHandle = IH;
|
||||
driver->DriverBindingHandle = NULL;
|
||||
status = BS->InstallMultipleProtocolInterfaces(
|
||||
&(driver->DriverBindingHandle),
|
||||
&DriverBindingProtocolGUID, driver,
|
||||
NULL);
|
||||
|
||||
if (EFI_ERROR(status)) {
|
||||
printf("Failed to install driver (%ld)!\n",
|
||||
EFI_ERROR_CODE(status));
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user