ableos/ableos/src/devices/pci/mod.rs

74 lines
2.3 KiB
Rust
Raw Normal View History

2022-08-12 13:40:23 +00:00
/*
* Copyright (c) 2022, Umut İnan Erdoğan <umutinanerdogan@pm.me>
*
* SPDX-License-Identifier: MPL-2.0
*/
pub mod class;
pub mod device;
2022-08-06 11:48:40 +00:00
pub mod vendors;
2022-04-25 18:39:39 +00:00
2022-08-08 19:55:28 +00:00
// MassStorage_IDE (0x0101)
pub mod ide;
2022-08-08 19:55:28 +00:00
2022-08-16 13:35:34 +00:00
use alloc::sync::Arc;
2022-08-12 13:40:23 +00:00
pub use class::*;
pub use device::*;
2022-08-16 13:35:34 +00:00
use lazy_static::lazy_static;
use spin::Mutex;
2022-08-12 13:48:22 +00:00
use x86_64::structures::paging::{Mapper, Size4KiB};
use crate::arch::memory::BootInfoFrameAllocator;
// MassStorage_IDE (0x0101)
use self::ide::PciIde;
2022-08-16 13:35:34 +00:00
lazy_static! {
pub static ref PCI_DEVICES: Mutex<Vec<Arc<Mutex<PciDevice>>>> = Default::default();
}
#[non_exhaustive]
2022-11-30 07:47:15 +00:00
#[derive(Debug)]
2022-08-16 13:35:34 +00:00
pub enum PciDevice {
Ide(PciIde),
2022-08-16 13:35:34 +00:00
// Variant so that we aren't about irrefutable if-let patterns
// FIXME: remove as soon as we have other variants
_0,
}
2022-04-25 18:39:39 +00:00
2022-08-12 13:40:23 +00:00
/// Enumerate PCI devices and run initialisation routines on ones we support
2022-08-12 13:48:22 +00:00
pub fn init(mapper: &mut impl Mapper<Size4KiB>, frame_allocator: &mut BootInfoFrameAllocator) {
2022-08-12 13:40:23 +00:00
for bus in 0..=255 {
for device in 0..32 {
if let Some(device_info) = device::check_device(bus, device) {
2022-08-16 13:35:34 +00:00
trace!("{device_info}");
2022-11-30 07:47:15 +00:00
println!("{device_info}");
2022-08-12 13:48:22 +00:00
match device_info.device_id {
// FIXME: Unknown class
S3_TRIO64V2 => {}
2022-08-12 13:48:22 +00:00
// MassStorage_IDE (0x0101)
ide_controller if device_info.full_class == PciFullClass::MassStorage_IDE => {
if !matches!(ide_controller, INTEL_PIIX3_IDE | INTEL_PIIX4_IDE) {
// not one of our tested IDE controllers, but
// we shouldn't have any problems
warn!("Unsupported PCI IDE controller device {device} on bus {bus}")
}
let mut ide = PciIde::new(bus, device).unwrap();
ide.allocate_dma_frame(mapper, frame_allocator).unwrap();
2022-08-16 13:35:34 +00:00
let mut devices = PCI_DEVICES.lock();
devices.push(Arc::new(Mutex::new(PciDevice::Ide(ide))));
2022-08-12 13:48:22 +00:00
}
// Display_VGA (0x0300)
VMWARE_SVGA2 => {}
_ => {
trace!("Unknown PCI device {device} on bus {bus}")
2022-08-12 13:48:22 +00:00
}
2022-04-25 18:39:39 +00:00
}
}
}
}
}