forked from koniifer/ableos
pci work
This commit is contained in:
parent
88df078d56
commit
4518e7ef5e
|
@ -22,10 +22,18 @@ run-args = [
|
||||||
|
|
||||||
"-soundhw",
|
"-soundhw",
|
||||||
"pcspk",
|
"pcspk",
|
||||||
|
|
||||||
|
|
||||||
|
# "-device",
|
||||||
|
# "VGA",
|
||||||
|
# "-device",
|
||||||
|
# "virtio-gpu-pci",
|
||||||
|
|
||||||
"-device",
|
"-device",
|
||||||
"VGA",
|
"vmware-svga",
|
||||||
|
|
||||||
"-device",
|
"-device",
|
||||||
"virtio-gpu-pci",
|
"sb16",
|
||||||
|
|
||||||
|
|
||||||
# "-machine", "pcspk-audiodev=0",
|
# "-machine", "pcspk-audiodev=0",
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, able <abl3theabove@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
pub mod drivers;
|
pub mod drivers;
|
||||||
pub mod gdt;
|
pub mod gdt;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
|
@ -10,7 +16,10 @@ use crate::arch::drivers::allocator;
|
||||||
use bootloader::{entry_point, BootInfo};
|
use bootloader::{entry_point, BootInfo};
|
||||||
use x86_64::{instructions::hlt, VirtAddr};
|
use x86_64::{instructions::hlt, VirtAddr};
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
entry_point![start];
|
entry_point![start];
|
||||||
|
|
||||||
|
#[cfg(not(test))]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn start(boot_info: &'static BootInfo) -> ! {
|
pub fn start(boot_info: &'static BootInfo) -> ! {
|
||||||
let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
|
let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
|
||||||
|
|
19
ableos/src/devices/pci/devices.rs
Normal file
19
ableos/src/devices/pci/devices.rs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, able <abl3theabove@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
use super::vendors::Vendor::{self, *};
|
||||||
|
#[derive(PartialEq, Clone, Eq, Debug)]
|
||||||
|
pub struct DeviceID {
|
||||||
|
pub vendor: Vendor,
|
||||||
|
pub id: u16,
|
||||||
|
}
|
||||||
|
impl DeviceID {
|
||||||
|
pub const fn new(vendor: Vendor, id: u16) -> Self {
|
||||||
|
Self { vendor, id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const VMWARE_SVGA2: DeviceID = DeviceID::new(VMware, 0x0405);
|
|
@ -1,3 +1,11 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, able <abl3theabove@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
use core::fmt::Display;
|
||||||
|
|
||||||
/// The major class specification for a PCI device.
|
/// The major class specification for a PCI device.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Hash)]
|
||||||
|
@ -176,3 +184,63 @@ impl From<u16> for PciFullClass {
|
||||||
Self::from_u16(n)
|
Self::from_u16(n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for PciFullClass {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
write!(f, " Class: ")?;
|
||||||
|
|
||||||
|
match self {
|
||||||
|
PciFullClass::Unclassified_NonVgaCompatible => write!(f, "\0LIGHTBLUE\0")?,
|
||||||
|
PciFullClass::Unclassified_VgaCompatible => write!(f, "\0LIGHTBLUE\0")?,
|
||||||
|
PciFullClass::MassStorage_ScsiBus => write!(f, "\0CYAN\0")?,
|
||||||
|
PciFullClass::MassStorage_IDE => write!(f, "\0CYAN\0")?,
|
||||||
|
PciFullClass::MassStorage_Floppy => write!(f, "\0CYAN\0")?,
|
||||||
|
PciFullClass::MassStorage_IpiBus => write!(f, "\0CYAN\0")?,
|
||||||
|
PciFullClass::MassStorage_RAID => write!(f, "\0CYAN\0")?,
|
||||||
|
PciFullClass::MassStorage_ATA => write!(f, "\0CYAN\0")?,
|
||||||
|
PciFullClass::MassStorage_SATA => write!(f, "\0CYAN\0")?,
|
||||||
|
PciFullClass::MassStorage_SerialSCSI => write!(f, "\0CYAN\0")?,
|
||||||
|
PciFullClass::MassStorage_NVM => write!(f, "\0CYAN\0")?,
|
||||||
|
PciFullClass::MassStorage_Other => write!(f, "\0CYAN\0")?,
|
||||||
|
PciFullClass::Network_Ethernet => write!(f, "\0MAGENTA\0")?,
|
||||||
|
PciFullClass::Network_TokenRing => write!(f, "\0MAGENTA\0")?,
|
||||||
|
PciFullClass::Network_FDDI => write!(f, "\0MAGENTA\0")?,
|
||||||
|
PciFullClass::Network_ATM => write!(f, "\0MAGENTA\0")?,
|
||||||
|
PciFullClass::Network_ISDN => write!(f, "\0MAGENTA\0")?,
|
||||||
|
PciFullClass::Network_WorldFlip => write!(f, "\0MAGENTA\0")?,
|
||||||
|
PciFullClass::Network_PICMG => write!(f, "\0MAGENTA\0")?,
|
||||||
|
PciFullClass::Network_Infiniband => write!(f, "\0MAGENTA\0")?,
|
||||||
|
PciFullClass::Network_Fabric => write!(f, "\0MAGENTA\0")?,
|
||||||
|
PciFullClass::Network_Other => write!(f, "\0MAGENTA\0")?,
|
||||||
|
PciFullClass::Display_VGA => write!(f, "\0YELLOW\0")?,
|
||||||
|
PciFullClass::Display_XGA => write!(f, "\0YELLOW\0")?,
|
||||||
|
PciFullClass::Display_3D => write!(f, "\0YELLOW\0")?,
|
||||||
|
PciFullClass::Display_Other => write!(f, "\0YELLOW\0")?,
|
||||||
|
PciFullClass::Multimedia_Video => write!(f, "\0LIGHTBLUE\0")?,
|
||||||
|
PciFullClass::Multimedia_AudioController => write!(f, "\0LIGHTBLUE\0")?,
|
||||||
|
PciFullClass::Multimedia_Telephony => write!(f, "\0LIGHTBLUE\0")?,
|
||||||
|
PciFullClass::Multimedia_AudioDevice => write!(f, "\0LIGHTBLUE\0")?,
|
||||||
|
PciFullClass::Multimedia_Other => write!(f, "\0LIGHTBLUE\0")?,
|
||||||
|
PciFullClass::Memory_RAM => write!(f, "\0BLUE\0")?,
|
||||||
|
PciFullClass::Memory_Flash => write!(f, "\0WHITE\0")?,
|
||||||
|
PciFullClass::Memory_Other => write!(f, "\0LIGHTGREY\0")?,
|
||||||
|
PciFullClass::Bridge_Host => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Bridge_ISA => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Bridge_EISA => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Bridge_MCA => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Bridge_PciToPci => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Bridge_PCMCIA => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Bridge_NuBus => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Bridge_CardBus => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Bridge_RACEway => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Bridge_PciToPciSemiTransparent => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Bridge_InfinibandToPci => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Bridge_Other => write!(f, "\0GREEN\0")?,
|
||||||
|
PciFullClass::Unknown => write!(f, "\0RED\0")?,
|
||||||
|
}
|
||||||
|
|
||||||
|
write!(f, "{:?} ({:#06X})\0RESET\0", self, self.as_u16())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,12 +10,17 @@ use core::fmt::{Display, Error, Formatter};
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
|
pub mod devices;
|
||||||
mod enums;
|
mod enums;
|
||||||
|
pub mod support;
|
||||||
|
pub mod vendors;
|
||||||
pub use enums::*;
|
pub use enums::*;
|
||||||
|
|
||||||
pub mod port;
|
pub mod port;
|
||||||
use port::*;
|
use port::*;
|
||||||
|
|
||||||
|
use self::devices::DeviceID;
|
||||||
|
|
||||||
// PciDeviceInfo ///////////////////////////////////////////////////////////////
|
// PciDeviceInfo ///////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -25,8 +30,7 @@ use port::*;
|
||||||
pub struct PciDeviceInfo {
|
pub struct PciDeviceInfo {
|
||||||
pub device: u8,
|
pub device: u8,
|
||||||
pub bus: u8,
|
pub bus: u8,
|
||||||
pub device_id: u16,
|
pub device_id: DeviceID,
|
||||||
pub vendor_id: u16,
|
|
||||||
pub full_class: PciFullClass,
|
pub full_class: PciFullClass,
|
||||||
pub header_type: u8,
|
pub header_type: u8,
|
||||||
pub bars: [u32; 6],
|
pub bars: [u32; 6],
|
||||||
|
@ -46,18 +50,13 @@ impl PciDeviceInfo {
|
||||||
}
|
}
|
||||||
impl Display for PciDeviceInfo {
|
impl Display for PciDeviceInfo {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
|
||||||
let vendor_name = name_for_vendor_id(self.vendor_id);
|
let vendor_name = &self.device_id.vendor;
|
||||||
writeln!(
|
writeln!(
|
||||||
f,
|
f,
|
||||||
"Device {} | Bus {:X} | Vendor: {}",
|
"Device {} | Bus {:X} | Vendor: {}",
|
||||||
self.device, self.bus, vendor_name
|
self.device, self.bus, vendor_name
|
||||||
)?;
|
)?;
|
||||||
writeln!(
|
writeln!(f, "{}", self.full_class)?;
|
||||||
f,
|
|
||||||
" Class: {:?} ({:#06X})",
|
|
||||||
self.full_class,
|
|
||||||
self.full_class.as_u16()
|
|
||||||
)?;
|
|
||||||
writeln!(f, " Header type: {:X}", self.header_type)?;
|
writeln!(f, " Header type: {:X}", self.header_type)?;
|
||||||
write!(f, " Supported functions: 0")?;
|
write!(f, " Supported functions: 0")?;
|
||||||
for (i, b) in self.supported_fns.iter().enumerate().skip(1) {
|
for (i, b) in self.supported_fns.iter().enumerate().skip(1) {
|
||||||
|
@ -86,22 +85,6 @@ impl Display for PciDeviceInfo {
|
||||||
|
|
||||||
// Public functions ////////////////////////////////////////////////////////////
|
// Public functions ////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/// Converts a u16 vendor id into a human-readable name.
|
|
||||||
pub fn name_for_vendor_id(vendor_id: u16) -> String {
|
|
||||||
let mut ret = match vendor_id {
|
|
||||||
0x1234 => "\0PINK\0QEMU (0x1234)".into(),
|
|
||||||
0x1AF4 => "\0PINK\0VirtIO (0x1AF4)".into(),
|
|
||||||
|
|
||||||
0x5333 => "\0YELLOW\0S3 Incorporated (0x5333)".into(),
|
|
||||||
0x8086 => "\0BLUE\0Intel Corp. (0x8086)".into(),
|
|
||||||
_ => format!("\0BROWN\0Unknown({:#06X})", vendor_id),
|
|
||||||
};
|
|
||||||
|
|
||||||
// trace!("{}", ret);
|
|
||||||
ret.push_str("\0RESET\0");
|
|
||||||
ret
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Brute force scans for devices 0-31 on buses 0-255.
|
/// Brute force scans for devices 0-31 on buses 0-255.
|
||||||
pub fn brute_force_scan() -> Vec<PciDeviceInfo> {
|
pub fn brute_force_scan() -> Vec<PciDeviceInfo> {
|
||||||
let mut infos = Vec::new();
|
let mut infos = Vec::new();
|
||||||
|
@ -159,8 +142,11 @@ fn check_device(bus: u8, device: u8) -> Option<PciDeviceInfo> {
|
||||||
Some(PciDeviceInfo {
|
Some(PciDeviceInfo {
|
||||||
device,
|
device,
|
||||||
bus,
|
bus,
|
||||||
device_id,
|
device_id: DeviceID {
|
||||||
vendor_id,
|
vendor: vendor_id.into(),
|
||||||
|
id: device_id,
|
||||||
|
},
|
||||||
|
// vendor_id,
|
||||||
full_class: pci_class,
|
full_class: pci_class,
|
||||||
header_type,
|
header_type,
|
||||||
bars,
|
bars,
|
||||||
|
|
15
ableos/src/devices/pci/support.rs
Normal file
15
ableos/src/devices/pci/support.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, able <abl3theabove@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
use super::devices::*;
|
||||||
|
|
||||||
|
pub fn check_pci_support(device_id: DeviceID) -> bool {
|
||||||
|
match device_id {
|
||||||
|
VMWARE_SVGA2 => true,
|
||||||
|
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
68
ableos/src/devices/pci/vendors.rs
Normal file
68
ableos/src/devices/pci/vendors.rs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, able <abl3theabove@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MPL-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
use core::fmt::Display;
|
||||||
|
|
||||||
|
#[derive(PartialEq, Debug, Clone, Eq)]
|
||||||
|
#[repr(u16)]
|
||||||
|
pub enum Vendor {
|
||||||
|
Qemu = 0x1234,
|
||||||
|
VMware = 0x15AD,
|
||||||
|
VirtIO = 0x1AF4,
|
||||||
|
Ati = 1002,
|
||||||
|
Intel = 0x8086,
|
||||||
|
S3Inc = 0x5333,
|
||||||
|
Unknown(u16),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u16> for Vendor {
|
||||||
|
fn from(vendor_id: u16) -> Self {
|
||||||
|
use Vendor::*;
|
||||||
|
match vendor_id {
|
||||||
|
0x15AD => VMware,
|
||||||
|
0x8086 => Intel,
|
||||||
|
1002 => Ati,
|
||||||
|
id => Unknown(id),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<u16> for Vendor {
|
||||||
|
fn into(self) -> u16 {
|
||||||
|
use Vendor::*;
|
||||||
|
match self {
|
||||||
|
VMware => 0x15AD,
|
||||||
|
Ati => 1002,
|
||||||
|
Qemu => 0x1234,
|
||||||
|
VirtIO => 0x1AF4,
|
||||||
|
Intel => 0x8086,
|
||||||
|
S3Inc => 0x5333,
|
||||||
|
Unknown(id) => id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Vendor {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
use Vendor::*;
|
||||||
|
|
||||||
|
let mut ret: String = match self {
|
||||||
|
Qemu => "\0PINK\0QEMU (0x1234)".into(),
|
||||||
|
VirtIO => "\0PINK\0VirtIO (0x1AF4)".into(),
|
||||||
|
VMware => "\0PINK\0VMWARE (0x15AD)".into(),
|
||||||
|
S3Inc => "\0YELLOW\0S3 Incorporated (0x5333)".into(),
|
||||||
|
Intel => "\0BLUE\0Intel Corp. (0x8086)".into(),
|
||||||
|
Ati => "\0RED\0ATI (0x1002)".into(),
|
||||||
|
|
||||||
|
Unknown(id) => format!("\0RED\0Unknown ({:#6})", id),
|
||||||
|
};
|
||||||
|
|
||||||
|
ret.push_str("\0RESET\0");
|
||||||
|
|
||||||
|
write!(f, "{}", ret)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,9 +17,10 @@
|
||||||
naked_functions,
|
naked_functions,
|
||||||
prelude_import,
|
prelude_import,
|
||||||
)]
|
)]
|
||||||
|
#![feature(arbitrary_enum_discriminant)]
|
||||||
#![feature(custom_test_frameworks)]
|
#![feature(custom_test_frameworks)]
|
||||||
#![test_runner(crate::test_runner)]
|
|
||||||
#![reexport_test_harness_main = "test_main"]
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
#![test_runner(crate::test_runner)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub extern crate log;
|
pub extern crate log;
|
||||||
|
|
|
@ -67,4 +67,4 @@ pub fn test_kernel_main(boot_info: &'static BootInfo) -> ! {
|
||||||
}
|
}
|
||||||
use bootloader::{entry_point, BootInfo};
|
use bootloader::{entry_point, BootInfo};
|
||||||
|
|
||||||
// use crate::test_main;
|
use crate::test_main;
|
||||||
|
|
Loading…
Reference in a new issue