From e146e801106a24e0f7113ed30f13f2da1061e013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 9 Oct 2023 10:29:27 +0200 Subject: [PATCH 1/4] refactor: move memory_barrier into arch modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/arch/aarch64/mod.rs | 10 ++++++++++ src/arch/mod.rs | 22 ---------------------- src/arch/x86_64/mod.rs | 10 ++++++++++ 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/arch/aarch64/mod.rs b/src/arch/aarch64/mod.rs index a459fd5479..f6957c9355 100644 --- a/src/arch/aarch64/mod.rs +++ b/src/arch/aarch64/mod.rs @@ -1,2 +1,12 @@ pub mod kernel; pub mod mm; + +/// Force strict CPU ordering, serializes load and store operations. +#[allow(dead_code)] +#[inline(always)] +pub(crate) fn memory_barrier() { + use core::arch::asm; + unsafe { + asm!("dmb ish", options(nostack, nomem, preserves_flags),); + } +} diff --git a/src/arch/mod.rs b/src/arch/mod.rs index aec99a6a95..872e95209e 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -62,28 +62,6 @@ pub use crate::arch::x86_64::kernel::{ #[cfg(target_arch = "x86_64")] pub use crate::arch::x86_64::*; -/// Force strict CPU ordering, serializes load and store operations. -#[allow(dead_code)] -#[cfg(target_arch = "aarch64")] -#[inline(always)] -pub(crate) fn memory_barrier() { - use core::arch::asm; - unsafe { - asm!("dmb ish", options(nostack, nomem, preserves_flags),); - } -} - -/// Force strict CPU ordering, serializes load and store operations. -#[allow(dead_code)] -#[cfg(target_arch = "x86_64")] -#[inline(always)] -pub(crate) fn memory_barrier() { - use core::arch::asm; - unsafe { - asm!("mfence", options(nostack, nomem, preserves_flags),); - } -} - pub fn init_drivers() { // Initialize PCI Drivers for x86_64 #[cfg(feature = "pci")] diff --git a/src/arch/x86_64/mod.rs b/src/arch/x86_64/mod.rs index a459fd5479..656d66c39c 100644 --- a/src/arch/x86_64/mod.rs +++ b/src/arch/x86_64/mod.rs @@ -1,2 +1,12 @@ pub mod kernel; pub mod mm; + +/// Force strict CPU ordering, serializes load and store operations. +#[allow(dead_code)] +#[inline(always)] +pub(crate) fn memory_barrier() { + use core::arch::asm; + unsafe { + asm!("mfence", options(nostack, nomem, preserves_flags),); + } +} From 4cbce460ec733580b579aa4acaf6bfe9a4832a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 9 Oct 2023 10:31:49 +0200 Subject: [PATCH 2/4] refactor: move init_drivers into arch modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/arch/aarch64/mod.rs | 6 ++++++ src/arch/mod.rs | 12 ------------ src/arch/x86_64/mod.rs | 8 ++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/arch/aarch64/mod.rs b/src/arch/aarch64/mod.rs index f6957c9355..f5717c958e 100644 --- a/src/arch/aarch64/mod.rs +++ b/src/arch/aarch64/mod.rs @@ -10,3 +10,9 @@ pub(crate) fn memory_barrier() { asm!("dmb ish", options(nostack, nomem, preserves_flags),); } } + +pub fn init_drivers() { + // Initialize PCI Drivers + #[cfg(feature = "pci")] + crate::drivers::pci::init_drivers(); +} diff --git a/src/arch/mod.rs b/src/arch/mod.rs index 872e95209e..dd149589f7 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -61,15 +61,3 @@ pub use crate::arch::x86_64::kernel::{ }; #[cfg(target_arch = "x86_64")] pub use crate::arch::x86_64::*; - -pub fn init_drivers() { - // Initialize PCI Drivers for x86_64 - #[cfg(feature = "pci")] - crate::drivers::pci::init_drivers(); - #[cfg(all( - target_arch = "x86_64", - not(feature = "pci"), - any(feature = "tcp", feature = "udp") - ))] - crate::arch::x86_64::kernel::mmio::init_drivers(); -} diff --git a/src/arch/x86_64/mod.rs b/src/arch/x86_64/mod.rs index 656d66c39c..7809b7212c 100644 --- a/src/arch/x86_64/mod.rs +++ b/src/arch/x86_64/mod.rs @@ -10,3 +10,11 @@ pub(crate) fn memory_barrier() { asm!("mfence", options(nostack, nomem, preserves_flags),); } } + +pub fn init_drivers() { + // Initialize PCI Drivers + #[cfg(feature = "pci")] + crate::drivers::pci::init_drivers(); + #[cfg(all(not(feature = "pci"), any(feature = "tcp", feature = "udp")))] + crate::arch::x86_64::kernel::mmio::init_drivers(); +} From 2b59c6d9dbb43033dd3d299aa2f64b946004f345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 9 Oct 2023 10:48:26 +0200 Subject: [PATCH 3/4] docs: fix arch module doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/arch/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/arch/mod.rs b/src/arch/mod.rs index dd149589f7..e01e16c5fa 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -1,4 +1,5 @@ -// Platform-specific implementations +//! Architecture-specific architecture abstraction. + #[cfg(target_arch = "aarch64")] pub mod aarch64; From 92e5a339e4eae1a7e159fbcfebb5810ad38652c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 9 Oct 2023 11:16:10 +0200 Subject: [PATCH 4/4] refactor: use cfg-if for arch module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- Cargo.lock | 1 + Cargo.toml | 1 + src/arch/mod.rs | 113 +++++++++++++++++++++++------------------------- 3 files changed, 55 insertions(+), 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 481fa2f488..bf99b433b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -444,6 +444,7 @@ dependencies = [ "arm-gic", "bit_field", "bitflags 2.4.0", + "cfg-if", "crossbeam-utils", "dyn-clone", "float-cmp", diff --git a/Cargo.toml b/Cargo.toml index 0891f453b4..4a46058ba7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,6 +68,7 @@ ahash = { version = "0.8", default-features = false } align-address = "0.1" bit_field = "0.10" bitflags = "2.4" +cfg-if = "1" crossbeam-utils = { version = "0.8", default-features = false } dyn-clone = "1.0" hashbrown = { version = "0.14", default-features = false } diff --git a/src/arch/mod.rs b/src/arch/mod.rs index e01e16c5fa..8d81850e91 100644 --- a/src/arch/mod.rs +++ b/src/arch/mod.rs @@ -1,64 +1,57 @@ //! Architecture-specific architecture abstraction. -#[cfg(target_arch = "aarch64")] -pub mod aarch64; +cfg_if::cfg_if! { + if #[cfg(target_arch = "aarch64")] { + pub mod aarch64; + pub use self::aarch64::*; -#[cfg(target_arch = "x86_64")] -pub mod x86_64; + #[cfg(target_os = "none")] + pub use self::aarch64::kernel::boot_processor_init; + pub use self::aarch64::kernel::core_local; + pub use self::aarch64::kernel::interrupts; + pub use self::aarch64::kernel::interrupts::wakeup_core; + #[cfg(feature = "pci")] + pub use self::aarch64::kernel::pci; + pub use self::aarch64::kernel::processor; + pub use self::aarch64::kernel::processor::set_oneshot_timer; + pub use self::aarch64::kernel::scheduler; + pub use self::aarch64::kernel::switch; + pub use self::aarch64::kernel::systemtime::get_boot_time; + pub use self::aarch64::kernel::{ + application_processor_init, + boot_application_processors, + get_processor_count, + message_output_init, + output_message_buf, + }; + } else if #[cfg(target_arch = "x86_64")] { + pub mod x86_64; + pub use self::x86_64::*; -// Export our platform-specific modules. -#[cfg(all(target_arch = "aarch64", target_os = "none"))] -pub use crate::arch::aarch64::kernel::boot_processor_init; -#[cfg(target_arch = "aarch64")] -pub use crate::arch::aarch64::kernel::core_local; -#[cfg(target_arch = "aarch64")] -pub use crate::arch::aarch64::kernel::interrupts; -#[cfg(target_arch = "aarch64")] -pub use crate::arch::aarch64::kernel::interrupts::wakeup_core; -#[cfg(all(target_arch = "aarch64", feature = "pci"))] -pub use crate::arch::aarch64::kernel::pci; -#[cfg(target_arch = "aarch64")] -pub use crate::arch::aarch64::kernel::processor; -#[cfg(target_arch = "aarch64")] -pub use crate::arch::aarch64::kernel::processor::set_oneshot_timer; -#[cfg(target_arch = "aarch64")] -pub use crate::arch::aarch64::kernel::scheduler; -#[cfg(target_arch = "aarch64")] -pub use crate::arch::aarch64::kernel::switch; -#[cfg(target_arch = "aarch64")] -pub use crate::arch::aarch64::kernel::systemtime::get_boot_time; -#[cfg(target_arch = "aarch64")] -pub use crate::arch::aarch64::kernel::{ - application_processor_init, boot_application_processors, get_processor_count, - message_output_init, output_message_buf, -}; -#[cfg(target_arch = "aarch64")] -pub use crate::arch::aarch64::*; -#[cfg(target_arch = "x86_64")] -pub use crate::arch::x86_64::kernel::apic::{set_oneshot_timer, wakeup_core}; -#[cfg(all(target_arch = "x86_64", target_os = "none", feature = "smp"))] -pub use crate::arch::x86_64::kernel::application_processor_init; -#[cfg(target_arch = "x86_64")] -pub use crate::arch::x86_64::kernel::core_local; -#[cfg(target_arch = "x86_64")] -pub use crate::arch::x86_64::kernel::gdt::set_current_kernel_stack; -#[cfg(target_arch = "x86_64")] -pub use crate::arch::x86_64::kernel::interrupts; -#[cfg(all(target_arch = "x86_64", feature = "pci"))] -pub use crate::arch::x86_64::kernel::pci; -#[cfg(target_arch = "x86_64")] -pub use crate::arch::x86_64::kernel::processor; -#[cfg(target_arch = "x86_64")] -pub use crate::arch::x86_64::kernel::scheduler; -#[cfg(target_arch = "x86_64")] -pub use crate::arch::x86_64::kernel::switch; -#[cfg(target_arch = "x86_64")] -pub use crate::arch::x86_64::kernel::systemtime::get_boot_time; -#[cfg(all(target_arch = "x86_64", target_os = "none"))] -pub use crate::arch::x86_64::kernel::{boot_application_processors, boot_processor_init}; -#[cfg(target_arch = "x86_64")] -pub use crate::arch::x86_64::kernel::{ - get_processor_count, message_output_init, output_message_buf, -}; -#[cfg(target_arch = "x86_64")] -pub use crate::arch::x86_64::*; + pub use self::x86_64::kernel::apic::{ + set_oneshot_timer, + wakeup_core, + }; + #[cfg(all(target_os = "none", feature = "smp"))] + pub use self::x86_64::kernel::application_processor_init; + pub use self::x86_64::kernel::core_local; + pub use self::x86_64::kernel::gdt::set_current_kernel_stack; + pub use self::x86_64::kernel::interrupts; + #[cfg(feature = "pci")] + pub use self::x86_64::kernel::pci; + pub use self::x86_64::kernel::processor; + pub use self::x86_64::kernel::scheduler; + pub use self::x86_64::kernel::switch; + pub use self::x86_64::kernel::systemtime::get_boot_time; + #[cfg(target_os = "none")] + pub use self::x86_64::kernel::{ + boot_application_processors, + boot_processor_init, + }; + pub use self::x86_64::kernel::{ + get_processor_count, + message_output_init, + output_message_buf, + }; + } +}