Skip to content

Conversation

crawfxrd
Copy link
Contributor

@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)

@nicholasbishop
Copy link
Member

Thanks for the PR, looks good (the CI errors are unrelated and should be fixed by #1485).

Could you add your signoff on #1470? We are working on relicensing and need approval from contributors.

@crawfxrd
Copy link
Contributor Author

crawfxrd commented Dec 9, 2024

Done: #1470 (comment)

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]>
@nicholasbishop nicholasbishop added this pull request to the merge queue Dec 9, 2024
Merged via the queue into rust-osdev:main with commit 991296f Dec 9, 2024
15 checks passed
@crawfxrd crawfxrd deleted the driver-binding branch December 9, 2024 18:37
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.

2 participants