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

70 lines
2.0 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)
2022-08-16 13:35:34 +00:00
pub mod piix_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;
2022-08-16 13:35:34 +00:00
use self::piix_ide::PiixIde;
lazy_static! {
pub static ref PCI_DEVICES: Mutex<Vec<Arc<Mutex<PciDevice>>>> = Default::default();
}
#[non_exhaustive]
pub enum PciDevice {
// MassStorage_IDE (0x0101)
PiixIde(PiixIde),
// 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-08-12 13:48:22 +00:00
match device_info.device_id {
// FIXME: Unknown class
S3INC_TRIO64V2 => {}
// MassStorage_IDE (0x0101)
INTEL_PIIX3_IDE | INTEL_PIIX4_IDE => {
2022-08-16 13:35:34 +00:00
let mut piix = PiixIde::new(bus, device).unwrap();
2022-08-12 13:48:22 +00:00
piix.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::PiixIde(piix))));
2022-08-12 13:48:22 +00:00
}
// Display_VGA (0x0300)
VMWARE_SVGA2 => {}
_ => {
trace!(
"PCI device {} on bus {} unsupported",
device_info.device,
device_info.bus
)
}
2022-04-25 18:39:39 +00:00
}
}
}
}
}