PCI: device discovery

master
TheOddGarlic 2022-08-12 16:48:22 +03:00
parent 428a8e8b73
commit 445b5f5f5c
4 changed files with 34 additions and 25 deletions

View File

@ -9,7 +9,10 @@ use core::fmt;
use x86_64::instructions::port::Port;
use super::{vendors::Vendor::{self, *}, PciFullClass, PciClass};
use super::{
vendors::Vendor::{self, *},
PciClass, PciFullClass,
};
// FIXME: Unknown class
pub const S3INC_TRIO64V2: DeviceID = DeviceID::new(S3Inc, 0x8900);
@ -41,9 +44,7 @@ impl PciDeviceInfo {
/// Get the bar, 0-indexed
pub fn bar(&self, bar: u8) -> u32 {
assert!(bar < 6);
unsafe {
self.io_read(0, 0x10 + bar * 4)
}
unsafe { self.io_read(0, 0x10 + bar * 4) }
}
/// Get the interrupt pin
@ -95,7 +96,7 @@ impl fmt::Display for PciDeviceInfo {
}
}
#[derive(PartialEq, Clone, Eq, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct DeviceID {
pub vendor: Vendor,
pub id: u16,
@ -107,21 +108,6 @@ impl DeviceID {
}
}
pub fn check_pci_support(device_id: DeviceID) -> bool {
match device_id {
// FIXME: Unknown class
S3INC_TRIO64V2 => true,
// MassStorage_IDE (0x0101)
INTEL_PIIX3_IDE => true,
INTEL_PIIX4_IDE => true,
// Display_VGA (0x0300)
VMWARE_SVGA2 => true,
_ => false,
}
}
pub fn check_device(bus: u8, device: u8) -> Option<PciDeviceInfo> {
assert!(device < 32);
let (device_id, vendor_id) = get_ids(bus, device, 0);

View File

@ -13,14 +13,37 @@ pub mod piix;
pub use class::*;
pub use device::*;
use x86_64::structures::paging::{Mapper, Size4KiB};
use crate::arch::memory::BootInfoFrameAllocator;
use self::piix::Piix;
/// Enumerate PCI devices and run initialisation routines on ones we support
pub fn init() {
pub fn init(mapper: &mut impl Mapper<Size4KiB>, frame_allocator: &mut BootInfoFrameAllocator) {
for bus in 0..=255 {
for device in 0..32 {
if let Some(device_info) = device::check_device(bus, device) {
if !device::check_pci_support(device_info.device_id) {
trace!("PCI device {} on bus {} unsupported", device_info.device, device_info.bus)
match device_info.device_id {
// FIXME: Unknown class
S3INC_TRIO64V2 => {}
// MassStorage_IDE (0x0101)
INTEL_PIIX3_IDE | INTEL_PIIX4_IDE => {
let mut piix = Piix::new(bus, device).unwrap();
piix.allocate_dma_frame(mapper, frame_allocator).unwrap();
piix.read().unwrap();
}
// Display_VGA (0x0300)
VMWARE_SVGA2 => {}
_ => {
trace!(
"PCI device {} on bus {} unsupported",
device_info.device,
device_info.bus
)
}
}
}
}

View File

@ -6,7 +6,7 @@
use core::fmt::Display;
#[derive(PartialEq, Debug, Clone, Eq)]
#[derive(PartialEq, Debug, Copy, Clone, Eq)]
#[repr(u16)]
pub enum Vendor {
ThreeDfxInteractiveInc = 0x121a,

View File

@ -44,7 +44,7 @@ pub fn kernel_main(
// term.draw_term();
// drop(term);
pci::init();
pci::init(&mut mapper, &mut frame_allocator);
x86_64::instructions::interrupts::without_interrupts(|| {
hardware::init_mouse();