Skip to content

uefi-raw: Add EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL bindings #1591

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

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

seijikun
Copy link
Contributor

@seijikun seijikun commented Mar 25, 2025

Added a (only raw for now) binding to EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL [52c78312-8edc-4233-98f2-1a1aa5e388a5].

Checklist

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

@seijikun seijikun marked this pull request as draft March 25, 2025 15:54
@seijikun
Copy link
Contributor Author

seijikun commented Mar 25, 2025

May not make much sense to add this.
Seems like it's not possible to use this interface from a UEFI application outside of a driver context.
Investigating...

Protocol Id is properly announced by Handle, but uefi::boot::open_protocol_exclusive fails with EFI_UNSUPPORTED.

@nicholasbishop
Copy link
Member

Seems like it's not possible to use this interface from a UEFI application outside of a driver context.

That's fine, uefi-raw is intended to be useful for firmware/drivers implementations.

@seijikun seijikun marked this pull request as ready for review March 25, 2025 17:53
@seijikun
Copy link
Contributor Author

Okay, then I'll convert it back to non-draft state.
I don't want to invest too much time into this if it's not usable in app-context though.
I also can't test it...

If you happen to know how to get this to work in an UEFI application context - tell me please, I need it 😅

@phip1611 phip1611 added this pull request to the merge queue Mar 26, 2025
Merged via the queue into rust-osdev:main with commit 691a3ed Mar 26, 2025
16 checks passed
@seijikun
Copy link
Contributor Author

seijikun commented Mar 26, 2025

For the eternal archives:

Doesn't work

let nvme_ctrl_handles = boot::find_handles::<NvmExpressPassThru>().unwrap();
for handle in nvme_ctrl_handles {
    println!("Handle: {:?}\r", handle);
    let nvmept = match boot::open_protocol_exclusive::<NvmExpressPassThru>(handle) {
        Ok(nvmept) => nvmept,
        Err(e) => {
            println!("Failed to open protocol: {}", e);
            continue;
        }
    };
    // this point is never reached -> because of EFI_UNSUPPORED during open
    // [...]
}

Works:

(Stolen from @necauqua's opal-uefi-greeter, thank you! 😗)

let block_io_handles = boot::find_handles::<BlockIO>().unwrap();
for handle in block_io_handles {
    let Ok(device_path) = uefi::boot::open_protocol_exclusive::<DevicePath>(handle) else { continue; };
    let mut device_path = &*device_path;
    
    let Ok(nvmept_handle) = boot::locate_device_path::<NvmExpressPassThru>(&mut device_path) else { continue; };
    
    let mut nvmept = match uefi::boot::open_protocol_exclusive::<NvmExpressPassThru>(nvmept_handle) {
        Ok(nvmept) => nvme_pt,
        Err(e) => {
            println!("Failed to open protocol: {}", e);
            return;
        }
    };
    
    // success
    // [...]
}

image

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.

3 participants