pci cleaned up

pls-build-on-my-machine
Able 2022-02-28 06:48:56 -06:00
parent 09f172fcb4
commit 86251abda4
Signed by untrusted user: able
GPG Key ID: D164AF5F5700BE51
5 changed files with 75 additions and 49 deletions

View File

@ -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",

12
ableos/src/devices/id.rs Normal file
View File

@ -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,
}
}

View File

@ -1,4 +1,5 @@
pub mod character_devs;
pub mod id;
pub mod pci_inner;
use alloc::{

View File

@ -1,4 +1,6 @@
//! map the DeviceClass via <https://pci-ids.ucw.cz/read/PD>
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);
}
}

View File

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