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. :^)
This commit is contained in:
TheOddGarlic 2022-08-16 17:09:22 +03:00
parent f140938ee6
commit 8a1c77db58
5 changed files with 23 additions and 25 deletions

View file

@ -8,7 +8,6 @@ use core::panic::PanicInfo;
use crate::{
arch::gdt,
devices::pci::{PciDevice, PCI_DEVICES},
println,
rhai_shell::KEYBUFF,
};

View file

@ -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);

View file

@ -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<IdeDevice>,
prdt_frame: Option<PhysFrame>,
@ -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<Self> {
let device_info = check_device(bus, device)?;

View file

@ -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<Vec<Arc<Mutex<PciDevice>>>> = 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<Size4KiB>, 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}")
}
}
}

View file

@ -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();