Skip to content

Commit 1887e47

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

File tree

4 files changed

+169
-1
lines changed

4 files changed

+169
-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: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
3+
use super::device_path::DevicePathProtocol;
4+
use crate::{Event, Status};
5+
use core::ffi::c_void;
6+
use uguid::{guid, Guid};
7+
8+
bitflags::bitflags! {
9+
/// ATA Controller attributes.
10+
///
11+
/// These flags defines attributes that describe the nature and capabilities
12+
/// of the ATA controller represented by this `EFI_ATA_PASS_THRU_PROTOCOL` instance.
13+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
14+
#[repr(transparent)]
15+
pub struct AtaPassThruAttributes: u32 {
16+
/// The protocol interface is for physical devices on the ATA controller.
17+
///
18+
/// This allows access to hardware-level details of devices directly attached to the controller.
19+
const PHYSICAL = 0x0001;
20+
21+
/// The protocol interface is for logical devices on the ATA controller.
22+
///
23+
/// Logical devices include RAID volumes and other high-level abstractions.
24+
const LOGICAL = 0x0002;
25+
26+
/// The protocol interface supports non-blocking I/O in addition to blocking I/O.
27+
///
28+
/// While all protocol interfaces must support blocking I/O, this attribute indicates
29+
/// the additional capability for non-blocking operations.
30+
const NONBLOCKIO = 0x0004;
31+
}
32+
}
33+
34+
35+
36+
#[derive(Debug)]
37+
#[repr(C)]
38+
pub struct AtaPassThruMode {
39+
pub attributes: AtaPassThruAttributes,
40+
pub io_align: u32,
41+
}
42+
43+
newtype_enum! {
44+
/// Corresponds to the `EFI_ATA_PASS_THRU_PROTOCOL_*` defines.
45+
#[derive(Default)]
46+
pub enum AtaPassThruCommandProtocol: u8 => {
47+
ATA_HARDWARE_RESET = 0x00,
48+
ATA_SOFTWARE_RESET = 0x01,
49+
ATA_NON_DATA = 0x02,
50+
PIO_DATA_IN = 0x04,
51+
PIO_DATA_OUT = 0x05,
52+
DMA = 0x06,
53+
DMA_QUEUED = 0x07,
54+
DEVICE_DIAGNOSTIC = 0x08,
55+
DEVICE_RESET = 0x09,
56+
UDMA_DATA_IN = 0x0A,
57+
UDMA_DATA_OUT = 0x0B,
58+
FPDMA = 0x0C,
59+
RETURN_RESPONSE = 0xFF,
60+
}
61+
}
62+
63+
newtype_enum! {
64+
/// Corresponds to the `EFI_ATA_PASS_THRU_LENGTH_*` defines.
65+
#[derive(Default)]
66+
pub enum AtaPassThruLength: u8 => {
67+
BYTES = 0x80,
68+
MASK = 0x70,
69+
NO_DATA_TRANSFER = 0x00,
70+
FEATURES = 0x10,
71+
SECTOR_COUNT = 0x20,
72+
TPSIU = 0x30,
73+
COUNT = 0x0F,
74+
}
75+
}
76+
77+
#[derive(Debug)]
78+
#[repr(C)]
79+
pub struct AtaStatusBlock {
80+
pub reserved1: [u8; 2],
81+
pub ata_status: u8,
82+
pub ata_error: u8,
83+
pub ata_sector_number: u8,
84+
pub ata_cylinder_low: u8,
85+
pub ata_cylinder_high: u8,
86+
pub ata_device_head: u8,
87+
pub ata_sector_number_exp: u8,
88+
pub ata_cylinder_low_exp: u8,
89+
pub ata_cylinder_high_exp: u8,
90+
pub reserved2: u8,
91+
pub ata_sector_count: u8,
92+
pub ata_sector_count_exp: u8,
93+
pub reserved3: [u8; 6],
94+
}
95+
96+
#[derive(Debug)]
97+
#[repr(C)]
98+
pub struct AtaCommandBlock {
99+
pub reserved1: [u8; 2],
100+
pub ata_command: u8,
101+
pub ata_features: u8,
102+
pub ata_sector_number: u8,
103+
pub ata_cylinder_low: u8,
104+
pub ata_cylinder_high: u8,
105+
pub ata_device_head: u8,
106+
pub ata_sector_number_exp: u8,
107+
pub ata_cylinder_low_exp: u8,
108+
pub ata_cylinder_high_exp: u8,
109+
pub ata_features_exp: u8,
110+
pub ata_sector_count: u8,
111+
pub ata_sector_count_exp: u8,
112+
pub reserved2: [u8; 6],
113+
}
114+
115+
#[derive(Debug)]
116+
#[repr(C)]
117+
pub struct AtaPassThruCommandPacket {
118+
pub asb: *mut AtaStatusBlock,
119+
pub acb: *const AtaCommandBlock,
120+
pub timeout: u64,
121+
pub in_data_buffer: *mut c_void,
122+
pub out_data_buffer: *const c_void,
123+
pub protocol: AtaPassThruCommandProtocol,
124+
pub length: AtaPassThruLength,
125+
}
126+
127+
#[derive(Debug)]
128+
#[repr(C)]
129+
pub struct AtaPassThruProtocol {
130+
pub mode: *const AtaPassThruMode,
131+
pub pass_thru: unsafe extern "efiapi" fn(
132+
this: *mut Self,
133+
port: u16,
134+
port_multiplier_port: u16,
135+
packet: *mut AtaPassThruCommandPacket,
136+
event: *mut Event,
137+
) -> Status,
138+
pub get_next_port: unsafe extern "efiapi" fn(this: *const Self, port: *mut u16) -> Status,
139+
pub get_next_device: unsafe extern "efiapi" fn(
140+
this: *const Self,
141+
port: u16,
142+
port_multiplier_port: *mut u16,
143+
) -> Status,
144+
pub build_device_path: unsafe extern "efiapi" fn(
145+
this: *const Self,
146+
port: u16,
147+
port_multiplier_port: u16,
148+
device_path: *mut *mut DevicePathProtocol,
149+
) -> Status,
150+
pub get_device: unsafe extern "efiapi" fn(
151+
this: *const Self,
152+
device_path: *const DevicePathProtocol,
153+
port: *mut u16,
154+
port_multiplier_port: *mut u16,
155+
) -> Status,
156+
pub reset_port: unsafe extern "efiapi" fn(this: *mut Self, port: u16) -> Status,
157+
pub reset_device: unsafe extern "efiapi" fn(
158+
this: *mut Self,
159+
port: u16,
160+
port_multiplier_port: u16,
161+
) -> Status,
162+
}
163+
164+
impl AtaPassThruProtocol {
165+
pub const GUID: Guid = guid!("1d3de7f0-0807-424f-aa69-11a54e19a46f");
166+
}

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)