Skip to content

Commit dd1a2e3

Browse files
committed
uefi-raw: Add EFI_ATA_PASS_THRU_PROTOCOL bindings
1 parent 691a3ed commit dd1a2e3

File tree

4 files changed

+150
-1
lines changed

4 files changed

+150
-1
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Added `DiskInfoProtocol`.
1111
- Added `ExtScsiPassThruProtocol`.
1212
- Added `NvmExpressPassThruProtocol`.
13+
- Added `AtaPassThruProtocol`.
1314

1415

1516
# uefi-raw - 0.10.0 (2025-02-07)

uefi-raw/src/protocol/ata.rs

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
use core::ffi::c_void;
4+
5+
use crate::Status;
6+
use uguid::{guid, Guid};
7+
8+
use super::device_path::DevicePathProtocol;
9+
10+
#[derive(Debug)]
11+
#[repr(C)]
12+
pub struct AtaPassThruMode {
13+
attributes: u32,
14+
io_align: u32,
15+
}
16+
17+
newtype_enum! {
18+
/// Corresponds to the `EFI_ATA_PASS_THRU_PROTOCOL_*` defines.
19+
#[derive(Default)]
20+
pub enum AtaPassThruCommandProtocol: u8 => {
21+
ATA_HARDWARE_RESET = 0x00,
22+
ATA_SOFTWARE_RESET = 0x01,
23+
ATA_NON_DATA = 0x02,
24+
PIO_DATA_IN = 0x04,
25+
PIO_DATA_OUT = 0x05,
26+
DMA = 0x06,
27+
DMA_QUEUED = 0x07,
28+
DEVICE_DIAGNOSTIC = 0x08,
29+
DEVICE_RESET = 0x09,
30+
UDMA_DATA_IN = 0x0A,
31+
UDMA_DATA_OUT = 0x0B,
32+
FPDMA = 0x0C,
33+
RETURN_RESPONSE = 0xFF,
34+
}
35+
}
36+
37+
newtype_enum! {
38+
/// Corresponds to the `EFI_ATA_PASS_THRU_LENGTH_*` defines.
39+
#[derive(Default)]
40+
pub enum AtaPassThruLength: u8 => {
41+
BYTES = 0x80,
42+
MASK = 0x70,
43+
NO_DATA_TRANSFER = 0x00,
44+
FEATURES = 0x10,
45+
SECTOR_COUNT = 0x20,
46+
TPSIU = 0x30,
47+
COUNT = 0x0F,
48+
}
49+
}
50+
51+
#[derive(Debug)]
52+
#[repr(C)]
53+
pub struct AtaPassThruStatusBlock {
54+
reserved1: [u8; 2],
55+
ata_status: u8,
56+
ata_error: u8,
57+
ata_sector_number: u8,
58+
ata_cylinder_low: u8,
59+
ata_cylinder_high: u8,
60+
ata_device_head: u8,
61+
ata_sector_number_exp: u8,
62+
ata_cylinder_low_exp: u8,
63+
ata_cylinder_high_exp: u8,
64+
reserved2: u8,
65+
ata_sector_count: u8,
66+
ata_sector_count_exp: u8,
67+
reserved3: [u8; 6],
68+
}
69+
70+
#[derive(Debug)]
71+
#[repr(C)]
72+
pub struct AtaPassThruCommandBlock {
73+
reserved1: [u8; 2],
74+
ata_command: u8,
75+
ata_features: u8,
76+
ata_sector_number: u8,
77+
ata_cylinder_low: u8,
78+
ata_cylinder_high: u8,
79+
ata_device_head: u8,
80+
ata_sector_number_exp: u8,
81+
ata_cylinder_low_exp: u8,
82+
ata_cylinder_high_exp: u8,
83+
ata_features_exp: u8,
84+
ata_sector_count: u8,
85+
ata_sector_count_exp: u8,
86+
reserved2: [u8; 6]
87+
}
88+
89+
#[derive(Debug)]
90+
#[repr(C)]
91+
pub struct AtaPassThruCommandPacket {
92+
asb: *mut AtaPassThruStatusBlock,
93+
acb: *const AtaPassThruCommandBlock,
94+
timeout: u64,
95+
in_data_buffer: *mut c_void,
96+
out_data_buffer: *const c_void,
97+
protocol: AtaPassThruCommandProtocol,
98+
length: AtaPassThruLength
99+
}
100+
101+
102+
103+
#[derive(Debug)]
104+
#[repr(C)]
105+
pub struct AtaPassThruProtocol {
106+
pub mode: *const AtaPassThruMode,
107+
pub pass_thru: unsafe extern "efiapi" fn(
108+
this: *const Self,
109+
port: u16,
110+
port_multiplier_port: u16,
111+
packet: *mut AtaPassThruCommandPacket,
112+
event: *mut c_void,
113+
) -> Status,
114+
pub get_next_port: unsafe extern "efiapi" fn(
115+
this: *const Self,
116+
port: *mut u16
117+
) -> Status,
118+
pub get_next_device: unsafe extern "efiapi" fn(
119+
this: *const Self,
120+
port: u16,
121+
port_multiplier_port: *mut u16
122+
) -> Status,
123+
pub build_device_path: unsafe extern "efiapi" fn(
124+
this: *const Self,
125+
port: u16,
126+
port_multiplier_port: u16,
127+
device_path: *mut *mut DevicePathProtocol
128+
) -> Status,
129+
pub get_device: unsafe extern "efiapi" fn(
130+
this: *const Self,
131+
device_path: *const DevicePathProtocol,
132+
port: *mut u16,
133+
port_multiplier_port: *mut u16
134+
) -> Status,
135+
pub reset_port: unsafe extern "efiapi" fn(
136+
this: *const Self,
137+
port: u16
138+
) -> Status,
139+
pub reset_device: unsafe extern "efiapi" fn(
140+
this: *const Self,
141+
port: u16,
142+
port_multiplier_port: u16
143+
) -> Status,
144+
}
145+
impl AtaPassThruProtocol {
146+
pub const GUID: Guid = guid!("1d3de7f0-0807-424f-aa69-11a54e19a46f");
147+
}

uefi-raw/src/protocol/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! ID. They can be implemented by a UEFI driver or occasionally by a
77
//! UEFI application.
88
9+
pub mod ata;
910
pub mod block;
1011
pub mod console;
1112
pub mod device_path;

uefi/src/proto/media/disk_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct DeviceLocationInfo {
4848
/// For AHCI, this returns the port.
4949
pub channel: u32,
5050
/// For IDE, this contains whether the device is master or slave.
51-
/// For AHCI, this returns the port-multiplier.
51+
/// For AHCI, this returns the port multiplier port.
5252
pub device: u32,
5353
}
5454

0 commit comments

Comments
 (0)