mirror of https://github.com/vinc/moros.git
Skip ATA drive selection when not needed (#576)
* Skip select drive when not needed * Add comments
This commit is contained in:
parent
aff91aefcf
commit
86e43e0999
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue