interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / uefi-raw / src / protocol / scsi.rs

230 lines · 8549 bytes Raw Blame History
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3use super::device_path::DevicePathProtocol;
4use crate::{Event, Guid, Status, guid, newtype_enum};
5use core::ffi::c_void;
6
7pub const SCSI_TARGET_MAX_BYTES: usize = 0x10;
8
9newtype_enum! {
10 /// Corresponds to the `EFI_SCSI_IO_TYPE_*` defines.
11 #[derive(Default)]
12 pub enum ScsiIoType: u8 => {
13 DISK = 0x00,
14 TAPE = 0x01,
15 PRINTER = 0x02,
16 PROCESSOR = 0x03,
17 WRITE_ONCE_READ_MULTIPLE = 0x04,
18 CDROM = 0x05,
19 SCANNER = 0x06,
20 OPTICAL = 0x07,
21 MEDIUM_CHANGER = 0x08,
22 COMMUNICATION = 0x09,
23 RAID = 0x0c,
24 ENCLOSURE_SERVICES = 0x0d,
25 REDUCED_BLOCK_COMMANDS = 0x0e,
26 OPTICAL_CARD_READER_WRITER = 0x0f,
27 BRIDGE_CONTROLLER = 0x10,
28 OBJECT_BASED_STORAGE = 0x11,
29 RESERVED_LOW = 0x12,
30 RESERVED_HIGH = 0x1e,
31 UNKNOWN = 0x1f,
32 }
33}
34
35newtype_enum! {
36 /// Corresponds to the `EFI_SCSI_IO_DATA_DIRECTION_*` defines.
37 #[derive(Default)]
38 pub enum ScsiIoDataDirection: u8 => {
39 READ = 0,
40 WRITE = 1,
41 BIDIRECTIONAL = 2,
42 }
43}
44
45newtype_enum! {
46 /// Corresponds to the `EFI_SCSI_IO_STATUS_HOST_ADAPTER_*` defines.
47 #[derive(Default)]
48 pub enum ScsiIoHostAdapterStatus: u8 => {
49 OK = 0x00,
50 TIMEOUT_COMMAND = 0x09,
51 TIMEOUT = 0x0b,
52 MESSAGE_REJECT = 0x0d,
53 BUS_RESET = 0x0e,
54 PARITY_ERROR = 0x0f,
55 REQUEST_SENSE_FAILED = 0x10,
56 SELECTION_TIMEOUT = 0x11,
57 DATA_OVERRUN_UNDERRUN = 0x12,
58 BUS_FREE = 0x13,
59 PHASE_ERROR = 0x14,
60 OTHER = 0x7f,
61 }
62}
63
64newtype_enum! {
65 /// Corresponds to the `EFI_SCSI_IO_STATUS_TARGET_*` defines.
66 #[derive(Default)]
67 pub enum ScsiIoTargetStatus: u8 => {
68 GOOD = 0x00,
69 CHECK_CONDITION = 0x02,
70 CONDITION_MET = 0x04,
71 BUSY = 0x08,
72 INTERMEDIATE = 0x10,
73 INTERMEDIATE_CONDITION_MET = 0x14,
74 RESERVATION_CONFLICT = 0x18,
75 COMMAND_TERMINATED = 0x22,
76 QUEUE_FULL = 0x28,
77 }
78}
79
80/// `EFI_SCSI_IO_SCSI_REQUEST_PACKET`.
81///
82/// `EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET` has the same layout, so this
83/// type is used for both protocols. Where the two differ, the field docs say
84/// so.
85#[derive(Debug, Copy, Clone)]
86#[repr(C)]
87pub struct ScsiIoScsiRequestPacket {
88 /// The timeout, in 100 ns units, for the execution of this SCSI Request Packet.
89 ///
90 /// A `timeout` value of 0 indicates that the function will wait indefinitely for
91 /// the execution to complete. If the execution time exceeds the specified `timeout`
92 /// (greater than 0), the function will return `EFI_TIMEOUT`.
93 pub timeout: u64,
94
95 /// A pointer to the data buffer for reading from the device in read and bidirectional commands.
96 ///
97 /// - Extended SCSI Pass Thru: for write and non-data commands where `in_transfer_length` is 0,
98 /// this field is optional and may be `NULL`.
99 /// - SCSI I/O: for write commands, this field must be `NULL`.
100 /// - If not `NULL`, the buffer must meet the alignment requirement given by the `IoAlign` field
101 /// of `EFI_EXT_SCSI_PASS_THRU_MODE` or `EFI_SCSI_IO_PROTOCOL`, respectively.
102 pub in_data_buffer: *mut c_void,
103
104 /// A pointer to the data buffer for writing to the device in write and bidirectional commands.
105 ///
106 /// - Extended SCSI Pass Thru: for read and non-data commands where `out_transfer_length` is 0,
107 /// this field is optional and may be `NULL`.
108 /// - SCSI I/O: for read commands, this field must be `NULL`.
109 /// - If not `NULL`, the buffer must meet the alignment requirement given by the `IoAlign` field
110 /// of `EFI_EXT_SCSI_PASS_THRU_MODE` or `EFI_SCSI_IO_PROTOCOL`, respectively.
111 pub out_data_buffer: *mut c_void,
112
113 /// A pointer to the sense data generated during execution of the SCSI Request Packet.
114 ///
115 /// - If `sense_data_length` is 0, this field is optional and may be `NULL`.
116 /// - It is recommended to allocate a buffer of at least 252 bytes to ensure the entire sense data can be captured.
117 /// - If not `NULL`, the buffer must meet the alignment requirement given by the `IoAlign` field
118 /// of `EFI_EXT_SCSI_PASS_THRU_MODE` or `EFI_SCSI_IO_PROTOCOL`, respectively.
119 pub sense_data: *mut c_void,
120
121 /// A pointer to the Command Data Block (CDB) buffer to be sent to the SCSI device.
122 ///
123 /// The CDB contains the SCSI command to be executed by the device.
124 pub cdb: *mut c_void,
125
126 /// The input size (in bytes) of the `in_data_buffer`, and the number of bytes transferred on output.
127 ///
128 /// - On input: Specifies the size of `in_data_buffer`.
129 /// - On output: Specifies the number of bytes successfully transferred.
130 /// - If the size exceeds the controller's capability, no data is transferred, the field is updated
131 /// with the number of transferable bytes, and `EFI_BAD_BUFFER_SIZE` is returned.
132 pub in_transfer_length: u32,
133
134 /// The input size (in bytes) of the `out_data_buffer`, and the number of bytes transferred on output.
135 ///
136 /// - On input: Specifies the size of `out_data_buffer`.
137 /// - On output: Specifies the number of bytes successfully transferred.
138 /// - If the size exceeds the controller's capability, no data is transferred, the field is updated
139 /// with the number of transferable bytes, and `EFI_BAD_BUFFER_SIZE` is returned.
140 pub out_transfer_length: u32,
141
142 /// The length (in bytes) of the Command Data Block (CDB).
143 ///
144 /// Standard values for CDB length are typically 6, 10, 12, or 16 bytes. Other values are possible
145 /// for variable-length CDBs.
146 pub cdb_length: u8,
147
148 /// The direction of data transfer for the SCSI Request Packet.
149 pub data_direction: ScsiIoDataDirection,
150
151 /// The status of the host adapter when the SCSI Request Packet was executed.
152 pub host_adapter_status: ScsiIoHostAdapterStatus,
153
154 /// The status of the target device when the SCSI Request Packet was executed.
155 pub target_status: ScsiIoTargetStatus,
156
157 /// The size (in bytes) of the `sense_data` buffer on input, and the number of bytes written on output.
158 ///
159 /// - On input: Specifies the size of the `sense_data` buffer.
160 /// - On output: Specifies the number of bytes written to the buffer.
161 pub sense_data_length: u8,
162}
163
164#[derive(Debug)]
165#[repr(C)]
166pub struct ScsiIoProtocol {
167 pub get_device_type:
168 unsafe extern "efiapi" fn(this: *const Self, device_type: *mut ScsiIoType) -> Status,
169 pub get_device_location: unsafe extern "efiapi" fn(
170 this: *const Self,
171 target: *const *mut u8,
172 lun: *mut u64,
173 ) -> Status,
174 pub reset_bus: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
175 pub reset_device: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
176 pub execute_scsi_command: unsafe extern "efiapi" fn(
177 this: *const Self,
178 packet: *mut ScsiIoScsiRequestPacket,
179 event: Event,
180 ) -> Status,
181 pub io_align: u32,
182}
183
184impl ScsiIoProtocol {
185 pub const GUID: Guid = guid!("932f47e6-2362-4002-803e-3cd54b138f85");
186}
187
188#[derive(Clone, Debug)]
189#[repr(C)]
190pub struct ExtScsiPassThruMode {
191 pub adapter_id: u32,
192 pub attributes: u32,
193 pub io_align: u32,
194}
195
196#[derive(Debug)]
197#[repr(C)]
198pub struct ExtScsiPassThruProtocol {
199 pub passthru_mode: *const ExtScsiPassThruMode,
200 pub pass_thru: unsafe extern "efiapi" fn(
201 this: *mut Self,
202 target: *const u8,
203 lun: u64,
204 packet: *mut ScsiIoScsiRequestPacket,
205 event: Event,
206 ) -> Status,
207 pub get_next_target_lun:
208 unsafe extern "efiapi" fn(this: *const Self, target: *mut *mut u8, lun: *mut u64) -> Status,
209 pub build_device_path: unsafe extern "efiapi" fn(
210 this: *const Self,
211 target: *const u8,
212 lun: u64,
213 device_path: *mut *mut DevicePathProtocol,
214 ) -> Status,
215 pub get_target_lun: unsafe extern "efiapi" fn(
216 this: *const Self,
217 device_path: *const DevicePathProtocol,
218 target: *const *mut u8,
219 lun: *mut u64,
220 ) -> Status,
221 pub reset_channel: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
222 pub reset_target_lun:
223 unsafe extern "efiapi" fn(this: *mut Self, target: *const u8, lun: u64) -> Status,
224 pub get_next_target:
225 unsafe extern "efiapi" fn(this: *const Self, target: *mut *mut u8) -> Status,
226}
227
228impl ExtScsiPassThruProtocol {
229 pub const GUID: Guid = guid!("143b7632-b81b-4cb7-abd3-b625a5b9bffe");
230}