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