Skip to content

Commit 941a1ce

Browse files
sky5454nicholasbishop
authored andcommitted
uefi-raw: Add ScsiIoProtocol
1 parent 3f819f4 commit 941a1ce

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

uefi-raw/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# uefi-raw - [Unreleased]
22

3-
## Changed
3+
## Added
44

55
- Added `protocol::string::UnicodeCollationProtocol`.
66
- Added `protocol::tcg` module, containing the TCG v1 and v2 protocols.
77
- Added `DriverBindingProtocol`.
88
- Added `FirmwareVolume2Protocol`.
99
- Added `FirmwareVolumeBlock2Protocol`.
1010
- Added `HiiDatabaseProtocol`.
11+
- Added `ScsiIoProtocol`.
1112

1213

1314
# uefi-raw - 0.9.0 (2024-10-23)

uefi-raw/src/protocol/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod memory_protection;
1818
pub mod misc;
1919
pub mod network;
2020
pub mod rng;
21+
pub mod scsi;
2122
pub mod shell_params;
2223
pub mod string;
2324
pub mod tcg;

uefi-raw/src/protocol/scsi.rs

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
use crate::{guid, Event, Guid, Status};
2+
use core::ffi::c_void;
3+
4+
newtype_enum! {
5+
/// Corresponds to the `EFI_SCSI_IO_TYPE_*` defines.
6+
#[derive(Default)]
7+
pub enum ScsiIoType: u8 => {
8+
DISK = 0x00,
9+
TAPE = 0x01,
10+
PRINTER = 0x02,
11+
PROCESSOR = 0x03,
12+
WRITE_ONCE_READ_MULTIPLE = 0x04,
13+
CDROM = 0x05,
14+
SCANNER = 0x06,
15+
OPTICAL = 0x07,
16+
MEDIUM_CHANGER = 0x08,
17+
COMMUNICATION = 0x09,
18+
RAID = 0x0c,
19+
ENCLOSURE_SERVICES = 0x0d,
20+
REDUCED_BLOCK_COMMANDS = 0x0e,
21+
OPTICAL_CARD_READER_WRITER = 0x0f,
22+
BRIDGE_CONTROLLER = 0x10,
23+
OBJECT_BASED_STORAGE = 0x11,
24+
RESERVED_LOW = 0x12,
25+
RESERVED_HIGH = 0x1e,
26+
UNKNOWN = 0x1f,
27+
}
28+
}
29+
30+
newtype_enum! {
31+
/// Corresponds to the `EFI_SCSI_IO_DATA_DIRECTION_*` defines.
32+
#[derive(Default)]
33+
pub enum ScsiIoDataDirection: u8 => {
34+
READ = 0,
35+
WRITE = 1,
36+
BIDIRECTIONAL = 2,
37+
}
38+
}
39+
40+
newtype_enum! {
41+
/// Corresponds to the `EFI_SCSI_IO_STATUS_HOST_ADAPTER_*` defines.
42+
#[derive(Default)]
43+
pub enum ScsiIoHostAdapterStatus: u8 => {
44+
OK = 0x00,
45+
TIMEOUT_COMMAND = 0x09,
46+
TIMEOUT = 0x0b,
47+
MESSAGE_REJECT = 0x0d,
48+
BUS_RESET = 0x0e,
49+
PARITY_ERROR = 0x0f,
50+
REQUEST_SENSE_FAILED = 0x10,
51+
SELECTION_TIMEOUT = 0x11,
52+
DATA_OVERRUN_UNDERRUN = 0x12,
53+
BUS_FREE = 0x13,
54+
PHASE_ERROR = 0x14,
55+
OTHER = 0x7f,
56+
}
57+
}
58+
59+
newtype_enum! {
60+
/// Corresponds to the `EFI_SCSI_IO_STATUS_TARGET_*` defines.
61+
#[derive(Default)]
62+
pub enum ScsiIoTargetStatus: u8 => {
63+
GOOD = 0x00,
64+
CHECK_CONDITION = 0x02,
65+
CONDITION_MET = 0x04,
66+
BUSY = 0x08,
67+
INTERMEDIATE = 0x10,
68+
INTERMEDIATE_CONDITION_MET = 0x14,
69+
RESERVATION_CONFLICT = 0x18,
70+
COMMAND_TERMINATED = 0x22,
71+
QUEUE_FULL = 0x28,
72+
}
73+
}
74+
75+
#[derive(Debug, Copy, Clone)]
76+
#[repr(C)]
77+
pub struct ScsiIoScsiRequestPacket {
78+
pub timeout: u64,
79+
pub in_data_buffer: *mut c_void,
80+
pub out_data_buffer: *mut c_void,
81+
pub sense_data: *mut c_void,
82+
pub cdb: *mut c_void,
83+
pub in_transfer_length: u32,
84+
pub out_transfer_length: u32,
85+
pub cdb_length: u8,
86+
pub data_direction: ScsiIoDataDirection,
87+
pub host_adapter_status: ScsiIoHostAdapterStatus,
88+
pub target_status: ScsiIoTargetStatus,
89+
pub sense_data_length: u8,
90+
}
91+
92+
#[derive(Debug)]
93+
#[repr(C)]
94+
pub struct ScsiIoProtocol {
95+
pub get_device_type:
96+
unsafe extern "efiapi" fn(this: *const Self, device_type: *mut ScsiIoType) -> Status,
97+
pub get_device_location:
98+
unsafe extern "efiapi" fn(this: *const Self, target: *mut *mut u8, lun: *mut u64) -> Status,
99+
pub reset_bus: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
100+
pub reset_device: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
101+
pub execute_scsi_command: unsafe extern "efiapi" fn(
102+
this: *const Self,
103+
packet: *mut ScsiIoScsiRequestPacket,
104+
event: Event,
105+
) -> Status,
106+
pub io_align: u32,
107+
}
108+
109+
impl ScsiIoProtocol {
110+
pub const GUID: Guid = guid!("932f47e6-2362-4002-803e-3cd54b138f85");
111+
}

0 commit comments

Comments
 (0)