Skip ATA drive selection when not needed (#576)

* Skip select drive when not needed

* Add comments
This commit is contained in:
Vincent Ollivier 2024-02-24 14:42:49 +01:00 committed by GitHub
parent aff91aefcf
commit 86e43e0999
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 0 deletions

View File

@ -15,6 +15,9 @@ use x86_64::instructions::port::{Port, PortReadOnly, PortWriteOnly};
pub const BLOCK_SIZE: usize = 512;
// Keep track of the last selected bus and drive pair to speed up operations
pub static LAST_SELECTED: Mutex<Option<(u8, u8)>> = Mutex::new(None);
#[repr(u16)]
#[derive(Debug, Clone, Copy)]
enum Command {
@ -145,6 +148,14 @@ impl Bus {
fn select_drive(&mut self, drive: u8) -> Result<(), ()> {
self.poll(Status::BSY, false)?;
self.poll(Status::DRQ, false)?;
// Skip the rest if this drive was already selected
if *LAST_SELECTED.lock() == Some((self.id, drive)) {
return Ok(());
} else {
*LAST_SELECTED.lock() = Some((self.id, drive));
}
unsafe {
// Bit 4 => DEV
// Bit 5 => 1