From 8a1c77db58ca5dbc6c19d07eef83f7e0f13b1d80 Mon Sep 17 00:00:00 2001 From: TheOddGarlic Date: Tue, 16 Aug 2022 17:09:22 +0300 Subject: [PATCH] IDE: Rename PiixIde to PciIde, use it for all IDE controllers If the controller is not a known PCI IDE controller, then we warn about the controller during PCI device discovery. :^) --- ableos/src/arch/x86_64/interrupts.rs | 1 - ableos/src/devices/pci/device.rs | 3 +- .../src/devices/pci/{piix_ide.rs => ide.rs} | 10 +++---- ableos/src/devices/pci/mod.rs | 30 ++++++++++--------- ableos/src/scratchpad.rs | 4 +-- 5 files changed, 23 insertions(+), 25 deletions(-) rename ableos/src/devices/pci/{piix_ide.rs => ide.rs} (98%) diff --git a/ableos/src/arch/x86_64/interrupts.rs b/ableos/src/arch/x86_64/interrupts.rs index 2370011..9daaaca 100644 --- a/ableos/src/arch/x86_64/interrupts.rs +++ b/ableos/src/arch/x86_64/interrupts.rs @@ -8,7 +8,6 @@ use core::panic::PanicInfo; use crate::{ arch::gdt, - devices::pci::{PciDevice, PCI_DEVICES}, println, rhai_shell::KEYBUFF, }; diff --git a/ableos/src/devices/pci/device.rs b/ableos/src/devices/pci/device.rs index 217c6d3..e9469ef 100644 --- a/ableos/src/devices/pci/device.rs +++ b/ableos/src/devices/pci/device.rs @@ -7,7 +7,6 @@ use core::fmt; -use serde::de::value; use x86_64::instructions::port::Port; use super::{ @@ -16,7 +15,7 @@ use super::{ }; // FIXME: Unknown class -pub const S3INC_TRIO64V2: DeviceID = DeviceID::new(S3Inc, 0x8900); +pub const S3_TRIO64V2: DeviceID = DeviceID::new(S3Inc, 0x8900); // MassStorage_IDE (0x0101) pub const INTEL_PIIX3_IDE: DeviceID = DeviceID::new(IntelCorp, 0x7010); diff --git a/ableos/src/devices/pci/piix_ide.rs b/ableos/src/devices/pci/ide.rs similarity index 98% rename from ableos/src/devices/pci/piix_ide.rs rename to ableos/src/devices/pci/ide.rs index cbe03c0..ecac1cb 100644 --- a/ableos/src/devices/pci/piix_ide.rs +++ b/ableos/src/devices/pci/ide.rs @@ -4,13 +4,11 @@ * SPDX-License-Identifier: MPL-2.0 */ -use core::mem; use core::num::TryFromIntError; -use x86_64::instructions::port::Port; -use x86_64::instructions::{hlt, interrupts}; +// FIXME: platform agnostic-ify these +use x86_64::instructions::{port::Port, interrupts}; use x86_64::structures::paging::{FrameAllocator, FrameDeallocator}; -// FIXME: platform agnostic paging stuff use x86_64::structures::paging::{mapper::MapToError, Mapper, Page, PhysFrame, Size4KiB}; use x86_64::VirtAddr; @@ -75,7 +73,7 @@ const CMD_IDENTIFY: u8 = 0xEC; /// ATA read using LBA48 DMA command const CMD_READ_DMA_EXT: u8 = 0x25; -pub struct PiixIde { +pub struct PciIde { device_info: PciDeviceInfo, ide_devices: Vec, prdt_frame: Option, @@ -83,7 +81,7 @@ pub struct PiixIde { bmiba: u16, } -impl PiixIde { +impl PciIde { // FIXME: make this return a Result pub fn new(bus: u8, device: u8) -> Option { let device_info = check_device(bus, device)?; diff --git a/ableos/src/devices/pci/mod.rs b/ableos/src/devices/pci/mod.rs index 5e301cf..12d18d0 100644 --- a/ableos/src/devices/pci/mod.rs +++ b/ableos/src/devices/pci/mod.rs @@ -9,7 +9,7 @@ pub mod device; pub mod vendors; // MassStorage_IDE (0x0101) -pub mod piix_ide; +pub mod ide; use alloc::sync::Arc; pub use class::*; @@ -20,7 +20,8 @@ use x86_64::structures::paging::{Mapper, Size4KiB}; use crate::arch::memory::BootInfoFrameAllocator; -use self::piix_ide::PiixIde; +// MassStorage_IDE (0x0101) +use self::ide::PciIde; lazy_static! { pub static ref PCI_DEVICES: Mutex>>> = Default::default(); @@ -28,8 +29,7 @@ lazy_static! { #[non_exhaustive] pub enum PciDevice { - // MassStorage_IDE (0x0101) - PiixIde(PiixIde), + Ide(PciIde), // Variant so that we aren't about irrefutable if-let patterns // FIXME: remove as soon as we have other variants _0, @@ -43,24 +43,26 @@ pub fn init(mapper: &mut impl Mapper, frame_allocator: &mut BootInfoFr trace!("{device_info}"); match device_info.device_id { // FIXME: Unknown class - S3INC_TRIO64V2 => {} + S3_TRIO64V2 => {} // MassStorage_IDE (0x0101) - INTEL_PIIX3_IDE | INTEL_PIIX4_IDE => { - let mut piix = PiixIde::new(bus, device).unwrap(); - piix.allocate_dma_frame(mapper, frame_allocator).unwrap(); + 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(); let mut devices = PCI_DEVICES.lock(); - devices.push(Arc::new(Mutex::new(PciDevice::PiixIde(piix)))); + devices.push(Arc::new(Mutex::new(PciDevice::Ide(ide)))); } // Display_VGA (0x0300) VMWARE_SVGA2 => {} _ => { - trace!( - "PCI device {} on bus {} unsupported", - device_info.device, - device_info.bus - ) + trace!("Unknown PCI device {device} on bus {bus}") } } } diff --git a/ableos/src/scratchpad.rs b/ableos/src/scratchpad.rs index 2b5e71a..8888686 100644 --- a/ableos/src/scratchpad.rs +++ b/ableos/src/scratchpad.rs @@ -119,7 +119,7 @@ pub fn scratchpad() { .iter() .find_map(|device_ref| { let device = device_ref.lock(); - if let PciDevice::PiixIde(_) = &*device { + if let PciDevice::Ide(_) = &*device { Some(device_ref.clone()) } else { None @@ -128,7 +128,7 @@ pub fn scratchpad() { .unwrap() }; let mut piix_ide_device = piix_ide_device.lock(); - if let PciDevice::PiixIde(device) = &mut *piix_ide_device { + if let PciDevice::Ide(device) = &mut *piix_ide_device { device.read().unwrap() } real_shell();