From 998a1d30cf97b95250ab7086c213b79752df9a7b Mon Sep 17 00:00:00 2001 From: TheOddGarlic Date: Fri, 12 Aug 2022 16:48:22 +0300 Subject: [PATCH] PCI: device discovery --- ableos/src/devices/pci/device.rs | 26 ++++++-------------------- ableos/src/devices/pci/mod.rs | 29 ++++++++++++++++++++++++++--- ableos/src/devices/pci/vendors.rs | 2 +- ableos/src/kmain.rs | 2 +- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/ableos/src/devices/pci/device.rs b/ableos/src/devices/pci/device.rs index 1b4371c..922a241 100644 --- a/ableos/src/devices/pci/device.rs +++ b/ableos/src/devices/pci/device.rs @@ -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 { assert!(device < 32); let (device_id, vendor_id) = get_ids(bus, device, 0); diff --git a/ableos/src/devices/pci/mod.rs b/ableos/src/devices/pci/mod.rs index 3338c2a..f14a264 100644 --- a/ableos/src/devices/pci/mod.rs +++ b/ableos/src/devices/pci/mod.rs @@ -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, 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 + ) + } } } } diff --git a/ableos/src/devices/pci/vendors.rs b/ableos/src/devices/pci/vendors.rs index 0a4c973..486b32a 100644 --- a/ableos/src/devices/pci/vendors.rs +++ b/ableos/src/devices/pci/vendors.rs @@ -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, diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index 9a37c3f..5bf23c6 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -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();