-
-
Notifications
You must be signed in to change notification settings - Fork 170
uefi: Add safe protocol wrapper for EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL #1594
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6fe9e0b
uefi-raw: Use stronger typing for flag/attr fields of NvmePassThru
seijikun 5e41ba6
uefi: Add nvme request builder infrastructure
seijikun 5226f3b
uefi: Add safe protocol implementation for NVM_EXPRESS_PASS_THRU_PROT…
seijikun ff49771
uefi: Add integration test for NVM_EXPRESS_PASS_THRU_PROTOCOL
seijikun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
mod pass_thru; | ||
|
||
pub fn test() { | ||
pass_thru::test(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
use core::time::Duration; | ||
use uefi::boot; | ||
use uefi::proto::device_path::text::{AllowShortcuts, DisplayOnly}; | ||
use uefi::proto::device_path::DevicePath; | ||
use uefi::proto::media::block::BlockIO; | ||
use uefi::proto::nvme::pass_thru::NvmePassThru; | ||
use uefi::proto::nvme::{NvmeQueueType, NvmeRequestBuilder}; | ||
|
||
pub fn test() { | ||
info!("Running NVMe PassThru tests"); | ||
|
||
assert!(has_nvme_drive()); | ||
} | ||
|
||
fn has_nvme_drive() -> bool { | ||
let block_io_handles = boot::find_handles::<BlockIO>().unwrap(); | ||
for handle in block_io_handles { | ||
let Ok(device_path) = boot::open_protocol_exclusive::<DevicePath>(handle) else { | ||
continue; | ||
}; | ||
let mut device_path = &*device_path; | ||
|
||
let Ok(nvme_pt_handle) = boot::locate_device_path::<NvmePassThru>(&mut device_path) else { | ||
continue; | ||
}; | ||
let nvme_pt = boot::open_protocol_exclusive::<NvmePassThru>(nvme_pt_handle).unwrap(); | ||
let device_path_str = device_path | ||
.to_string(DisplayOnly(true), AllowShortcuts(false)) | ||
.unwrap(); | ||
info!("- Successfully opened NVMe: {}", device_path_str); | ||
let mut nvme_ctrl = nvme_pt.controller(); | ||
|
||
let request = NvmeRequestBuilder::new(nvme_pt.io_align(), 0x06, NvmeQueueType::ADMIN) | ||
.with_timeout(Duration::from_millis(500)) | ||
.with_cdw10(1) // we want info about controller | ||
seijikun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.with_transfer_buffer(4096) | ||
.unwrap() | ||
.build(); | ||
let result = nvme_ctrl.execute_command(request); | ||
if let Ok(result) = result { | ||
let bfr = result.transfer_buffer().unwrap(); | ||
let serial = core::str::from_utf8(&bfr[4..24]).unwrap().trim(); | ||
info!("Found NVMe with serial: '{}'", serial); | ||
if serial == "uefi-rsNvmePassThru" { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.