From c21b1a75f505c636fb88772dcc358795d6f78bbc Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 28 Feb 2022 06:48:56 -0600 Subject: [PATCH] pci cleaned up --- ableos/Cargo.toml | 3 +- ableos/src/devices/id.rs | 12 +++++ ableos/src/devices/mod.rs | 1 + ableos/src/devices/pci_inner.rs | 30 +++++++++++++ ableos/src/scratchpad.rs | 78 +++++++++++++-------------------- 5 files changed, 75 insertions(+), 49 deletions(-) create mode 100644 ableos/src/devices/id.rs diff --git a/ableos/Cargo.toml b/ableos/Cargo.toml index 5f2383f..961bb18 100644 --- a/ableos/Cargo.toml +++ b/ableos/Cargo.toml @@ -19,7 +19,8 @@ run-args = [ # An example gpu used with ableOS "-device", - "virtio-gpu", + # "virtio-gpu", + "ati-vga", # An example disk used with ableOS "-device", diff --git a/ableos/src/devices/id.rs b/ableos/src/devices/id.rs new file mode 100644 index 0000000..6323a5d --- /dev/null +++ b/ableos/src/devices/id.rs @@ -0,0 +1,12 @@ +#[derive(Debug)] +pub enum Vendor { + Unknown = 0, + Ati = 4098, +} + +pub fn match_vendor(id: u16) -> Vendor { + match id { + 4098 => Vendor::Ati, + _ => Vendor::Unknown, + } +} diff --git a/ableos/src/devices/mod.rs b/ableos/src/devices/mod.rs index 132c3f8..5631399 100644 --- a/ableos/src/devices/mod.rs +++ b/ableos/src/devices/mod.rs @@ -1,4 +1,5 @@ pub mod character_devs; +pub mod id; pub mod pci_inner; use alloc::{ diff --git a/ableos/src/devices/pci_inner.rs b/ableos/src/devices/pci_inner.rs index d0f5fc5..c78c9a4 100644 --- a/ableos/src/devices/pci_inner.rs +++ b/ableos/src/devices/pci_inner.rs @@ -1,4 +1,6 @@ //! map the DeviceClass via + +use pci::PortOps; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum DeviceClass { UnclassifiedDevice = 0, @@ -54,3 +56,31 @@ impl DeviceClass { } } } + +pub struct PciIO {} + +impl PortOps for PciIO { + unsafe fn read8(&self, port: u16) -> u8 { + cpuio::inb(port as u16) + } + + unsafe fn read16(&self, port: u16) -> u16 { + cpuio::inw(port as u16) + } + + unsafe fn read32(&self, port: u16) -> u32 { + cpuio::inl(port as u16) + } + + unsafe fn write8(&self, port: u16, val: u8) { + cpuio::outb(val, port as u16); + } + + unsafe fn write16(&self, port: u16, val: u16) { + cpuio::outw(val, port as u16); + } + + unsafe fn write32(&self, port: u16, val: u32) { + cpuio::outl(val, port as u16); + } +} diff --git a/ableos/src/scratchpad.rs b/ableos/src/scratchpad.rs index 85939ac..6062b35 100644 --- a/ableos/src/scratchpad.rs +++ b/ableos/src/scratchpad.rs @@ -1,18 +1,13 @@ -use core::arch::asm; - -use alloc::string::{String, ToString}; -use cpuio::outb; - -use crate::{absi::colorify, messaging::ProcessMessage, rhai_shell::rhai_shell}; - use { crate::{ - devices::{pci_inner::DeviceClass, Device, DEVICE_TABLE}, - proc::PID, - wasm_jumploader::interp, + devices::{ + id::match_vendor, + pci_inner::{DeviceClass, PciIO}, + Device, DEVICE_TABLE, + }, + rhai_shell::rhai_shell, }, alloc::{format, vec::Vec}, - pci::PortOps, }; /// Experimental scratchpad for testing. @@ -29,7 +24,27 @@ pub fn scratchpad() { let device_table = &mut *DEVICE_TABLE.lock(); for x in dev_list { - let device_name = format!("{:?}-{}", DeviceClass::from_u8(x.id.class), x.id.device_id); + let vendor_id_name = match_vendor(x.id.vendor_id); + use crate::devices::id::Vendor::*; + match vendor_id_name { + Unknown => {} + Ati => unsafe { + x.cspace_access_method.write32(&PciIO {}, x.loc, 0x0260, 1); + + x.cspace_access_method + .write32(&PciIO {}, x.loc, 0x0230, 0x00_ff_0000); + + // 0x0260 + }, + } + + let device_name = format!( + "{:?}-{:?}-{}", + vendor_id_name, + DeviceClass::from_u8(x.id.class), + x.id.device_id + ); + // println!("{}", device_name); device_table .devices @@ -37,45 +52,12 @@ pub fn scratchpad() { } /* - for (key, _value) in device_table.devices.iter() { - debug!("{}", key); - } - */ - // interp(); - // crate::experiments::absi::colorify(); - let message = "Hello, world!"; let xyz = ProcessMessage::new_from_string(PID(123), PID(0), message.to_string()); - // print!("{:?}", xyz); + print!("{:?}", xyz); + */ + rhai_shell(); } - -pub struct PciIO {} - -impl PortOps for PciIO { - unsafe fn read8(&self, port: u16) -> u8 { - cpuio::inb(port as u16) - } - - unsafe fn read16(&self, port: u16) -> u16 { - cpuio::inw(port as u16) - } - - unsafe fn read32(&self, port: u16) -> u32 { - cpuio::inl(port as u16) - } - - unsafe fn write8(&self, port: u16, val: u8) { - cpuio::outb(val, port as u16); - } - - unsafe fn write16(&self, port: u16, val: u16) { - cpuio::outw(val, port as u16); - } - - unsafe fn write32(&self, port: u16, val: u32) { - cpuio::outl(val, port as u16); - } -}