Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using bigger instruction port to get more throughput on data register ATA read/write #557

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/sys/ata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum Command {
}

enum IdentifyResponse {
Ata([u16; 256]),
Ata([u32; 128]),
Atapi,
Sata,
None,
Expand All @@ -48,7 +48,7 @@ pub struct Bus {
id: u8,
irq: u8,

data_register: Port<u16>,
data_register: Port<u32>,
error_register: PortReadOnly<u8>,
features_register: PortWriteOnly<u8>,
sector_count_register: Port<u8>,
Expand Down Expand Up @@ -113,11 +113,11 @@ impl Bus {
unsafe { self.lba2_register.read() }
}

fn read_data(&mut self) -> u16 {
fn read_data(&mut self) -> u32 {
unsafe { self.data_register.read() }
}

fn write_data(&mut self, data: u16) {
fn write_data(&mut self, data: u32) {
unsafe { self.data_register.write(data) }
}

Expand Down Expand Up @@ -198,7 +198,7 @@ impl Bus {
debug_assert!(buf.len() == BLOCK_SIZE);
self.setup_pio(drive, block)?;
self.write_command(Command::Read)?;
for chunk in buf.chunks_mut(2) {
for chunk in buf.chunks_mut(4) {
let data = self.read_data().to_le_bytes();
chunk.clone_from_slice(&data);
}
Expand All @@ -215,8 +215,8 @@ impl Bus {
debug_assert!(buf.len() == BLOCK_SIZE);
self.setup_pio(drive, block)?;
self.write_command(Command::Write)?;
for chunk in buf.chunks(2) {
let data = u16::from_le_bytes(chunk.try_into().unwrap());
for chunk in buf.chunks(4) {
let data = u32::from_le_bytes(chunk.try_into().unwrap());
self.write_data(data);
}
if self.is_error() {
Expand All @@ -242,7 +242,7 @@ impl Bus {
}
}
match (self.lba1(), self.lba2()) {
(0x00, 0x00) => Ok(IdentifyResponse::Ata([(); 256].map(|_| { self.read_data() }))),
(0x00, 0x00) => Ok(IdentifyResponse::Ata([(); 128].map(|_| { self.read_data() }))),
(0x14, 0xEB) => Ok(IdentifyResponse::Atapi),
(0x3C, 0xC3) => Ok(IdentifyResponse::Sata),
(_, _) => Err(()),
Expand Down Expand Up @@ -297,7 +297,7 @@ impl Drive {
pub fn open(bus: u8, dsk: u8) -> Option<Self> {
let mut buses = BUSES.lock();
if let Ok(IdentifyResponse::Ata(res)) = buses[bus as usize].identify_drive(dsk) {
let buf = res.map(u16::to_be_bytes).concat();
let buf = res.map(u32::to_be_bytes).concat();
let serial = String::from_utf8_lossy(&buf[20..40]).trim().into();
let model = String::from_utf8_lossy(&buf[54..94]).trim().into();
let blocks = u32::from_be_bytes(buf[120..124].try_into().unwrap()).rotate_left(16);
Expand Down