From fd564f883ac3b7c2876cad82ba59a4373102af84 Mon Sep 17 00:00:00 2001 From: Markus Ebner Date: Tue, 25 Mar 2025 00:04:46 +0100 Subject: [PATCH] uefi-raw: Add EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL bindings --- uefi-raw/CHANGELOG.md | 1 + uefi-raw/src/protocol/mod.rs | 1 + uefi-raw/src/protocol/nvme.rs | 82 +++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 uefi-raw/src/protocol/nvme.rs diff --git a/uefi-raw/CHANGELOG.md b/uefi-raw/CHANGELOG.md index 590735292..314daabf6 100644 --- a/uefi-raw/CHANGELOG.md +++ b/uefi-raw/CHANGELOG.md @@ -9,6 +9,7 @@ address types. - Added `DiskInfoProtocol`. - Added `ExtScsiPassThruProtocol`. +- Added `NvmExpressPassThruProtocol`. # uefi-raw - 0.10.0 (2025-02-07) diff --git a/uefi-raw/src/protocol/mod.rs b/uefi-raw/src/protocol/mod.rs index 7f322a075..4e250a226 100644 --- a/uefi-raw/src/protocol/mod.rs +++ b/uefi-raw/src/protocol/mod.rs @@ -19,6 +19,7 @@ pub mod media; pub mod memory_protection; pub mod misc; pub mod network; +pub mod nvme; pub mod rng; pub mod scsi; pub mod shell_params; diff --git a/uefi-raw/src/protocol/nvme.rs b/uefi-raw/src/protocol/nvme.rs new file mode 100644 index 000000000..07055469f --- /dev/null +++ b/uefi-raw/src/protocol/nvme.rs @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use super::device_path::DevicePathProtocol; +use crate::Status; +use core::ffi::c_void; +use uguid::{guid, Guid}; + +#[derive(Debug)] +#[repr(C)] +pub struct NvmExpressPassThruMode { + pub attributes: u32, + pub io_align: u32, + pub nvme_version: u32, +} + +/// This structure maps to the NVM Express specification Submission Queue Entry +#[derive(Debug)] +#[repr(C)] +pub struct NvmExpressCommand { + pub cdw0: u32, + pub flags: u8, + pub nsid: u32, + pub cdw2: u32, + pub cdw3: u32, + pub cdw10: u32, + pub cdw11: u32, + pub cdw12: u32, + pub cdw13: u32, + pub cdw14: u32, + pub cdw15: u32, +} + +/// This structure maps to the NVM Express specification Completion Queue Entry +#[derive(Debug)] +#[repr(C)] +pub struct NvmExpressCompletion { + pub dw0: u32, + pub dw1: u32, + pub dw2: u32, + pub dw3: u32, +} + +#[derive(Debug)] +#[repr(C)] +pub struct NvmExpressPassThruCommandPacket { + pub command_timeout: u64, + pub transfer_buffer: *mut c_void, + pub transfer_length: u32, + pub meta_data_buffer: *mut c_void, + pub meta_data_length: u32, + pub queue_type: u8, + pub nvme_cmd: *const NvmExpressCommand, + pub nvme_completion: *mut NvmExpressCompletion, +} + +#[derive(Debug)] +#[repr(C)] +pub struct NvmExpressPassThruProtocol { + pub mode: *const NvmExpressPassThruMode, + pub pass_thru: unsafe extern "efiapi" fn( + this: *const Self, + namespace_id: u32, + packet: *mut NvmExpressPassThruCommandPacket, + event: *mut c_void, + ) -> Status, + pub get_next_namespace: + unsafe extern "efiapi" fn(this: *const Self, namespace_id: *mut u32) -> Status, + pub build_device_path: unsafe extern "efiapi" fn( + this: *const Self, + namespace_id: u32, + device_path: *mut *mut DevicePathProtocol, + ) -> Status, + pub get_namespace: unsafe extern "efiapi" fn( + this: *const Self, + device_path: *const DevicePathProtocol, + namespace_id: *mut u32, + ) -> Status, +} + +impl NvmExpressPassThruProtocol { + pub const GUID: Guid = guid!("52c78312-8edc-4233-98f2-1a1aa5e388a5"); +}