From ae0d48d9ab8cfedb1d2a3800ef9b7c893a79e761 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Tue, 1 Mar 2022 12:52:06 -0700
Subject: [PATCH] Identity map ACPI

---
 src/arch/x86_64/rmm.rs   | 15 ++++++++++++++-
 src/arch/x86_64/start.rs |  6 +++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/arch/x86_64/rmm.rs b/src/arch/x86_64/rmm.rs
index 1e4b7074..328a922d 100644
--- a/src/arch/x86_64/rmm.rs
+++ b/src/arch/x86_64/rmm.rs
@@ -80,7 +80,7 @@ unsafe fn inner<A: Arch>(
     kernel_base: usize, kernel_size_aligned: usize,
     stack_base: usize, stack_size_aligned: usize,
     env_base: usize, env_size_aligned: usize,
-    acpi_base: usize, acpi_size: usize
+    acpi_base: usize, acpi_size_aligned: usize
 ) -> BuddyAllocator<A> {
     // First, calculate how much memory we have
     let mut size = 0;
@@ -163,6 +163,19 @@ unsafe fn inner<A: Arch>(
             flush.ignore(); // Not the active table
         }
 
+        // Map acpi with identity mapping
+        for i in 0..acpi_size_aligned / A::PAGE_SIZE {
+            let phys = PhysicalAddress::new(acpi_base + i * A::PAGE_SIZE);
+            let virt = A::phys_to_virt(phys);
+            let flags = page_flags::<A>(virt);
+            let flush = mapper.map_phys(
+                virt,
+                phys,
+                flags
+            ).expect("failed to map frame");
+            flush.ignore(); // Not the active table
+        }
+
         println!("Table: {:X}", mapper.table().phys().data());
         for i in 0..512 {
             if let Some(entry) = mapper.table().entry(i) {
diff --git a/src/arch/x86_64/start.rs b/src/arch/x86_64/start.rs
index 65993ea0..508ad809 100644
--- a/src/arch/x86_64/start.rs
+++ b/src/arch/x86_64/start.rs
@@ -172,7 +172,11 @@ pub unsafe extern fn kstart(args_ptr: *const KernelArgs) -> ! {
         // Read ACPI tables, starts APs
         #[cfg(feature = "acpi")]
         {
-            acpi::init(&mut active_table, if acpi_rsdps_base != 0 && acpi_rsdps_size > 0 { Some((acpi_rsdps_base, acpi_rsdps_size)) } else { None });
+            acpi::init(&mut active_table, if acpi_rsdps_base != 0 && acpi_rsdps_size > 0 {
+                Some((acpi_rsdps_base + crate::PHYS_OFFSET as u64, acpi_rsdps_size))
+            } else {
+                None
+            });
             device::init_after_acpi(&mut active_table);
         }
 
-- 
GitLab