mod.rs 1.03 KB
Newer Older
1 2
use io::Io;

Jeremy Soller's avatar
Jeremy Soller committed
3 4
use self::disk::Disk;
use self::hba::{HbaMem, HbaPortType};
5

Jeremy Soller's avatar
Jeremy Soller committed
6
pub mod disk;
7 8 9
pub mod fis;
pub mod hba;

Jeremy Soller's avatar
Jeremy Soller committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
pub fn disks(base: usize, irq: u8) -> Vec<Disk> {
    println!(" + AHCI on: {:X} IRQ: {}", base as usize, irq);

    let pi = unsafe { &mut *(base as *mut HbaMem) }.pi.read();
    let ret: Vec<Disk> = (0..32)
          .filter(|&i| pi & 1 << i as i32 == 1 << i as i32)
          .filter_map(|i| {
              let port = &mut unsafe { &mut *(base as *mut HbaMem) }.ports[i];
              let port_type = port.probe();
              println!("{}: {:?}", i, port_type);
              match port_type {
                  HbaPortType::SATA => {
                      match Disk::new(i, port) {
                          Ok(disk) => Some(disk),
                          Err(err) => {
                              println!("{}: {}", i, err);
                              None
27 28 29
                          }
                      }
                  }
Jeremy Soller's avatar
Jeremy Soller committed
30 31 32 33
                  _ => None,
              }
          })
          .collect();
34

Jeremy Soller's avatar
Jeremy Soller committed
35
    ret
36
}