diff --git a/src/acpi/srat/aarch64.rs b/src/acpi/srat/aarch64.rs index e69de29bb2..0b32481d20 100644 --- a/src/acpi/srat/aarch64.rs +++ b/src/acpi/srat/aarch64.rs @@ -0,0 +1,5 @@ +use crate::acpi::srat::Srat; + +pub fn init_srat(srat: &Srat) { + // todo +} diff --git a/src/acpi/srat/mod.rs b/src/acpi/srat/mod.rs index ef9484076b..6249c4b9b9 100644 --- a/src/acpi/srat/mod.rs +++ b/src/acpi/srat/mod.rs @@ -77,11 +77,10 @@ impl<'a> Iterator for SratIter<'a> { *(entry.add(2) as *const GiccAffinity) }), // ignore GIC ITS Affinity and Generic Initiator Affinity - 4 | 5 => { + _ => { self.i += entry_len as u32; continue; } - _ => SratEntry::Unknown(unsafe { *entry }), }); self.i += entry_len as u32; return entry; @@ -97,8 +96,7 @@ pub enum SratEntry { ProcessorLocalAffinity(ProcessorLocalAffinity), GiccAffinity(GiccAffinity), // unimplemented: Gic Its Affinity and Generic Initiator Affinity - // our current focus is only on memory and cpus - Unknown(u8), + // our current focus is only on memory and cpus } #[repr(C, packed)] @@ -144,3 +142,17 @@ struct GiccAffinity { flags: u32, clock_domain: u32, } + +#[inline(always)] +pub(crate) fn to_usize(low: u32, high: u32) -> usize { + #[cfg(target_pointer_width = "32")] + return low as usize; + + #[cfg(target_pointer_width = "64")] + { + let mut low_and_high = [0u8; 8]; + low_and_high[0..=3].copy_from_slice(low.to_le_bytes().as_slice()); + low_and_high[4..=7].copy_from_slice(high.to_le_bytes().as_slice()); + usize::from_le_bytes(low_and_high) + } +} diff --git a/src/acpi/srat/x86.rs b/src/acpi/srat/x86.rs index 484e8a2e69..be3b11d6a4 100644 --- a/src/acpi/srat/x86.rs +++ b/src/acpi/srat/x86.rs @@ -1,24 +1,10 @@ use core::iter; use crate::{ - acpi::srat::{Srat, SratEntry}, + acpi::srat::{to_usize, Srat, SratEntry}, numa::{self, NUMA_NODES}, }; -#[inline(always)] -fn to_usize(low: u32, high: u32) -> usize { - #[cfg(target_pointer_width = "32")] - return low as usize; - - #[cfg(target_pointer_width = "64")] - { - let mut low_and_high = [0u8; 8]; - low_and_high[0..=3].copy_from_slice(low.to_le_bytes().as_slice()); - low_and_high[4..=7].copy_from_slice(high.to_le_bytes().as_slice()); - usize::from_le_bytes(low_and_high) - } -} - #[inline(always)] fn to_single_int(high: &[u8; 3], low: u8) -> u32 { let mut high_and_low = [0u8; 4]; diff --git a/src/numa.rs b/src/numa.rs index edf09746cf..c490c3d7d8 100644 --- a/src/numa.rs +++ b/src/numa.rs @@ -54,7 +54,8 @@ pub fn init() { #[cfg(any(target_arch = "riscv64", target_arch = "aarch64"))] { if !flag { - todo!() + // todo!() + return; } } @@ -160,20 +161,42 @@ fn put_for_adoption( distances: Vec<(u32, u8)>, memories: Option>, cpus: Option>, - orphan_node_id: u32, + orphan_node_id: u32, // id of the node containing only memory / CPU (orphan) ) { if let Some(memories) = memories { assert!(cpus.is_none()); - let (nearest_node_id, distance) = distances.first().unwrap(); - let nearest_node = nodes.get_mut(nearest_node_id).unwrap(); - nearest_node.memory.extend(memories); + let foster_node = if !distances.is_empty() { + let (nearest_node_id, distance) = distances.first().unwrap(); + nodes.get_mut(nearest_node_id).unwrap() + } else { + let foster_node_id = { + let mut node_ids = nodes.keys(); + let foster_node = node_ids + .find(|node_id| **node_id != orphan_node_id) + .unwrap(); + *foster_node + }; + nodes.get_mut(&foster_node_id).unwrap() // panic not possible since there must be atleast one other domain with a cpu + }; + foster_node.memory.extend(memories); } else if let Some(cpus) = cpus { assert!(memories.is_none()); - let (nearest_node_id, distance) = distances.first().unwrap(); - let nearest_node = nodes.get_mut(nearest_node_id).unwrap(); - nearest_node.cpus.extend(cpus); + let foster_node = if !distances.is_empty() { + let (nearest_node_id, distance) = distances.first().unwrap(); + nodes.get_mut(nearest_node_id).unwrap() + } else { + let foster_node_id = { + let mut node_ids = nodes.keys(); + let foster_node = node_ids + .find(|node_id| **node_id != orphan_node_id) + .unwrap(); + *foster_node + }; + nodes.get_mut(&foster_node_id).unwrap() // panic not possible since there must be atleast one other domain with memory + }; + foster_node.cpus.extend(cpus); } else { - panic!() + unreachable!() // this should never happen }; for (_, node) in nodes { diff --git a/src/startup/mod.rs b/src/startup/mod.rs index 108ebe635c..f2e48cfe8c 100644 --- a/src/startup/mod.rs +++ b/src/startup/mod.rs @@ -9,7 +9,8 @@ use crate::{ arch::interrupt, context::{self, switch::SwitchResult}, memory::{PhysicalAddress, RmmA, RmmArch}, - numa, profiling, scheme, + numa::{self, NUMA_NODES}, + profiling, scheme, sync::CleanLockToken, };