Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uefi-raw: Add DriverBindingProtocol #1487

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

crawfxrd
Copy link

@crawfxrd crawfxrd commented Nov 30, 2024

Add the interface for EFI_DRIVER_BINDING_PROTOCOL.

Ref: UEFI 2.10: 11.1 EFI Driver Binding Protocol

Example usage
#![no_main]
#![no_std]

use uefi::prelude::*;
use uefi_raw::protocol::device_path::DevicePathProtocol;
use uefi_raw::protocol::driver::DriverBindingProtocol;

// EFI_DRIVER_BINDING_SUPPORTED
unsafe extern "efiapi" fn supported(
    _this: *const DriverBindingProtocol,
    _controller: uefi_raw::Handle,
    _remaining: *const DevicePathProtocol,
) -> Status {
    log::info!("DriverBindingSupported called");
    Status::SUCCESS
}

// EFI_DRIVER_BINDING_START
unsafe extern "efiapi" fn start(
    _this: *const DriverBindingProtocol,
    _controller: uefi_raw::Handle,
    _remaining: *const DevicePathProtocol,
) -> Status {
    log::info!("DriverBindingStart called");
    Status::SUCCESS
}

// EFI_DRIVER_BINDING_STOP
unsafe extern "efiapi" fn stop(
    _this: *const DriverBindingProtocol,
    _controller: uefi_raw::Handle,
    _number_of_children: usize,
    _child_handle_buffer: *const uefi_raw::Handle,
) -> Status {
    log::info!("DriverBindingStop called");
    Status::SUCCESS
}

// EFI_DRIVER_BINDING_PROTOCOL
static mut DRIVER_BINDING: DriverBindingProtocol = DriverBindingProtocol {
    supported,
    start,
    stop,
    version: 1,
    image_handle: core::ptr::null_mut(),
    driver_binding_handle: core::ptr::null_mut(),
};

#[entry]
fn main() -> Status {
    uefi::helpers::init().unwrap();
    let image = boot::image_handle();

    log::info!("driver run");

    unsafe {
        DRIVER_BINDING.image_handle = image.as_ptr();
        DRIVER_BINDING.driver_binding_handle = image.as_ptr();
    }

    unsafe {
        boot::install_protocol_interface(
            Some(image),
            &DriverBindingProtocol::GUID,
            core::ptr::addr_of!(DRIVER_BINDING).cast(),
        )
        .unwrap();
    }

    log::info!("DriverBindingProtocol installed");
    Status::SUCCESS
}

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

Add the interface for EFI_DRIVER_BINDING_PROTOCOL.

Ref: UEFI 2.10: 11.1 EFI Driver Binding Protocol
Signed-off-by: Tim Crawford <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant