From fb6ba5b33ea656a217314bf484992115b15f1911 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 29 Mar 2021 17:40:32 +1100 Subject: [PATCH] Run args and improvements for AHCI --- .gitignore | 3 ++- Cargo.toml | 14 ++++++++++++ Makefile | 6 +++++- hdd.img | 0 src/drivers/ahci.rs | 52 +++++++++++++++++++++++++++++++++------------ src/drivers/pci.rs | 6 +++--- 6 files changed, 62 insertions(+), 19 deletions(-) delete mode 100644 hdd.img diff --git a/.gitignore b/.gitignore index 04f9a2f14ea..1dddad89382 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/log.log \ No newline at end of file +/qemu.log +*.img \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 6847745a9a7..94623c7ac46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,3 +30,17 @@ lto = true [profile.release] lto = true + +[package.metadata.bootimage] +run-args = [ + "-d", + "int,guest_errors", + "-D", + "qemu.log", + "-drive", + "id=disk,file=hdd.img,format=raw,if=none", + "-device", + "ahci,id=ahci", + "-device", + "ide-hd,drive=disk,bus=ahci.0", +] \ No newline at end of file diff --git a/Makefile b/Makefile index c3909e33c86..d28fa88012f 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,8 @@ run: cargo run clean: - cargo clean \ No newline at end of file + cargo clean + +init: + touch hdd.img + \ No newline at end of file diff --git a/hdd.img b/hdd.img deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/drivers/ahci.rs b/src/drivers/ahci.rs index ca71f54face..7721c24e8aa 100644 --- a/src/drivers/ahci.rs +++ b/src/drivers/ahci.rs @@ -9,6 +9,41 @@ use x86_64::{ use super::pci::{Bar, PCIHeader}; use crate::log; +use bitflags::bitflags; + +bitflags! { + #[repr(C)] + pub struct HBACapabilities: u32 { + const SXS_SUPPORT = 1 << 5; + const EMS_SUPPORT = 1 << 6; + const CCC_SUPPORT = 1 << 7; + const PS_CAPABLE = 1 << 13; + const SS_CAPABLE = 1 << 14; + const PIO_MULTI_DRQ_SUPPORT = 1 << 15; + const FBSS_SUPPORT = 1 << 16; + const PM_SUPPORT = 1 << 17; + const AHCI_ONLY = 1 << 18; + const CLO_SUPPORT = 1 << 24; + const AL_SUPPORT = 1 << 25; + const ALP_SUPPORT = 1 << 26; + const SS_SUPPORT = 1 << 27; + const MPS_SUPPORT = 1 << 28; + const SNTF_SUPPORT = 1 << 29; + const NCQ_SUPPORT = 1 << 30; + const SUPPORTS_64_ADDRESSES = 1 << 31; + } +} + +bitflags! { + #[repr(C)] + pub struct GlobalHBAControl: u32 { + const HBA_RESET = 1; + const INT_ENABLE = 1 << 1; + const MRSM = 1 << 2; + const AHCI_ENABLE = 1 << 31; + } +} + const SATA_SIG_ATAPI: u32 = 0xEB140101; const SATA_SIG_ATA: u32 = 0x00000101; const SATA_SIG_SEMB: u32 = 0xC33C0101; @@ -28,8 +63,8 @@ pub enum AHCIPortType { #[repr(C, packed)] struct HBAMemory { - host_capability: u32, - global_host_control: u32, + host_capability: HBACapabilities, + global_host_control: GlobalHBAControl, interrupt_status: u32, ports_implemented: u32, version: u32, @@ -59,17 +94,6 @@ impl HBAMemory { panic!() } } - - pub fn port_count(&self) -> u32 { - self.ports_implemented.count_ones() - } - - pub fn port_slice(&self) -> &[HBAPort] { - let count = self.port_count() as usize; - let slice = &self.ports[..count]; - - unsafe { MaybeUninit::slice_assume_init_ref(slice) } - } } #[repr(C, packed)] @@ -140,7 +164,7 @@ impl AHCI { let port = self.memory.get_port(i); let port_type = self.get_port_type(port); - crate::println!("Found! {:?}{}", port_type, port.signature); + crate::println!("Found! {:?}", port_type); } } } diff --git a/src/drivers/pci.rs b/src/drivers/pci.rs index e5f318592a0..81957268724 100644 --- a/src/drivers/pci.rs +++ b/src/drivers/pci.rs @@ -365,15 +365,15 @@ impl PCIHeader { Self(result) } - fn bus(&self) -> u8 { + pub fn bus(&self) -> u8 { self.0.get_bits(8..16) as u8 } - fn device(&self) -> u8 { + pub fn device(&self) -> u8 { self.0.get_bits(3..8) as u8 } - fn function(&self) -> u8 { + pub fn function(&self) -> u8 { self.0.get_bits(0..3) as u8 }