From 4ca93ada922ec6cbc06e08b693723cb13d742cb3 Mon Sep 17 00:00:00 2001 From: Mathieu Strypsteen Date: Thu, 31 Oct 2024 17:40:23 +0100 Subject: [PATCH] Split acpica-rs into a separate library --- .gitignore | 2 +- Cargo.lock | 9 ++++++++- Cargo.toml | 2 +- kernel/Cargo.toml | 6 ++---- kernel/src/main.rs | 3 ++- kernel/src/sys/acpica_osl.rs | 3 +-- kernel/src/sys/hpet.rs | 11 +++-------- kernel/src/sys/madt.rs | 2 +- kernel/src/sys/mod.rs | 1 - lib/acpica-rs/Cargo.toml | 8 ++++++++ {kernel => lib/acpica-rs}/build.rs | 6 +++--- kernel/src/sys/acpica.rs => lib/acpica-rs/src/lib.rs | 2 +- 12 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 lib/acpica-rs/Cargo.toml rename {kernel => lib/acpica-rs}/build.rs (65%) rename kernel/src/sys/acpica.rs => lib/acpica-rs/src/lib.rs (60%) diff --git a/.gitignore b/.gitignore index be03433..5eecb78 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.a *.o -kernel/src/sys/acpica-bindings.rs +lib/acpica-rs/src/acpica-bindings.rs img target diff --git a/Cargo.lock b/Cargo.lock index d13022a..b996c10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,13 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "acpica-rs" +version = "0.0.1" +dependencies = [ + "bindgen", +] + [[package]] name = "aho-corasick" version = "1.1.3" @@ -145,7 +152,7 @@ dependencies = [ name = "kernel" version = "0.0.1" dependencies = [ - "bindgen", + "acpica-rs", "bitfield", "bitvec", "buddy_system_allocator", diff --git a/Cargo.toml b/Cargo.toml index 87e0c17..806b474 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["lib/kernel-common", "loader", "kernel"] +members = ["lib/acpica-rs", "lib/kernel-common", "loader", "kernel"] [profile.release] lto = true diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 0d6e8a4..9676c3b 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -2,15 +2,13 @@ name = "kernel" version = "0.0.1" edition = "2021" -license = "Unlicense AND BSD-3-Clause-acpica" +license = "Unlicense" [dependencies] +acpica-rs = {path = "../lib/acpica-rs"} bitfield = "0.17.0" bitvec = {version = "1.0.1", default-features = false, features = ["alloc", "atomic"]} buddy_system_allocator = "0.11.0" kernel-common = {path = "../lib/kernel-common"} log = "0.4.22" spin = "0.9.8" - -[build-dependencies] -bindgen = "0.70.1" diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 2723ef5..80a2c93 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -12,6 +12,7 @@ use core::{ sync::atomic::{AtomicU64, Ordering}, }; +use acpica_rs::AcpiInitializeTables; use buddy_system_allocator::LockedHeap; use cpu::{gdt::setup_gdt, idt::setup_idt, paging::setup_paging}; use kernel_common::{ @@ -21,7 +22,7 @@ use kernel_common::{ paging::{KERNEL_HEAP_INITIAL_SIZE, KERNEL_HEAP_START}, }; use log::{error, info}; -use sys::{acpica::AcpiInitializeTables, acpica_osl::AE_OK, hpet::setup_hpet, lapic::setup_lapic_timer, madt::parse_madt, pic::disable_pic}; +use sys::{acpica_osl::AE_OK, hpet::setup_hpet, lapic::setup_lapic_timer, madt::parse_madt, pic::disable_pic}; mod cpu; mod misc; diff --git a/kernel/src/sys/acpica_osl.rs b/kernel/src/sys/acpica_osl.rs index 2a1926e..83ba8e2 100644 --- a/kernel/src/sys/acpica_osl.rs +++ b/kernel/src/sys/acpica_osl.rs @@ -5,6 +5,7 @@ use core::{ sync::atomic::Ordering, }; +use acpica_rs::{ACPI_PHYSICAL_ADDRESS, ACPI_PREDEFINED_NAMES, ACPI_SIZE, ACPI_STATUS, ACPI_STRING, ACPI_TABLE_HEADER, UINT32, UINT64}; use kernel_common::log::log_raw; use crate::{ @@ -13,8 +14,6 @@ use crate::{ RSDP_ADDRESS, }; -use super::acpica::{ACPI_PHYSICAL_ADDRESS, ACPI_PREDEFINED_NAMES, ACPI_SIZE, ACPI_STATUS, ACPI_STRING, ACPI_TABLE_HEADER, UINT32, UINT64}; - pub const AE_OK: ACPI_STATUS = 0; #[no_mangle] diff --git a/kernel/src/sys/hpet.rs b/kernel/src/sys/hpet.rs index 6296a14..61a33b8 100644 --- a/kernel/src/sys/hpet.rs +++ b/kernel/src/sys/hpet.rs @@ -3,18 +3,13 @@ use core::{ sync::atomic::{AtomicBool, AtomicPtr, AtomicU64, Ordering}, }; +use acpica_rs::{acpi_table_header, acpi_table_hpet, AcpiGetTable}; use kernel_common::instructions::pause; use log::warn; -use crate::{ - cpu::paging::map_physical, - sys::{ - acpica::{acpi_table_header, AcpiGetTable}, - acpica_osl::AE_OK, - }, -}; +use crate::{cpu::paging::map_physical, sys::acpica_osl::AE_OK}; -use super::{acpica::acpi_table_hpet, ioapic::register_isa_irq_handler}; +use super::ioapic::register_isa_irq_handler; const REGISTER_CAPABILITIES: usize = 0; const REGISTER_CONFIG: usize = 2; diff --git a/kernel/src/sys/madt.rs b/kernel/src/sys/madt.rs index dff1f1b..5b2a8b7 100644 --- a/kernel/src/sys/madt.rs +++ b/kernel/src/sys/madt.rs @@ -1,11 +1,11 @@ use core::mem::size_of; +use acpica_rs::{acpi_madt_interrupt_override, acpi_madt_io_apic, acpi_madt_local_apic_override, acpi_subtable_header, acpi_table_header, acpi_table_madt, AcpiGetTable}; use kernel_common::instructions::sti; use crate::sys::acpica_osl::AE_OK; use super::{ - acpica::{acpi_madt_interrupt_override, acpi_madt_io_apic, acpi_madt_local_apic_override, acpi_subtable_header, acpi_table_header, acpi_table_madt, AcpiGetTable}, ioapic::{set_irq_override, setup_ioapic}, lapic::setup_lapic, }; diff --git a/kernel/src/sys/mod.rs b/kernel/src/sys/mod.rs index 60c6593..9f13c0a 100644 --- a/kernel/src/sys/mod.rs +++ b/kernel/src/sys/mod.rs @@ -1,4 +1,3 @@ -pub mod acpica; pub mod acpica_osl; pub mod hpet; mod ioapic; diff --git a/lib/acpica-rs/Cargo.toml b/lib/acpica-rs/Cargo.toml new file mode 100644 index 0000000..753c4f3 --- /dev/null +++ b/lib/acpica-rs/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "acpica-rs" +version = "0.0.1" +edition = "2021" +license = "BSD-3-Clause-acpica" + +[build-dependencies] +bindgen = "0.70.1" diff --git a/kernel/build.rs b/lib/acpica-rs/build.rs similarity index 65% rename from kernel/build.rs rename to lib/acpica-rs/build.rs index 5596a5e..ac9ac99 100644 --- a/kernel/build.rs +++ b/lib/acpica-rs/build.rs @@ -5,10 +5,10 @@ fn main() { println!("cargo::rustc-link-lib=acpica"); let bindings = Builder::default() .use_core() - .clang_arg("-I../lib/acpica-build") - .header("../lib/acpica-build/acpica.h") + .clang_arg("-I../acpica-build") + .header("../acpica-build/acpica.h") .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) .generate() .unwrap(); - bindings.write_to_file("src/sys/acpica-bindings.rs").unwrap(); + bindings.write_to_file("src/acpica-bindings.rs").unwrap(); } diff --git a/kernel/src/sys/acpica.rs b/lib/acpica-rs/src/lib.rs similarity index 60% rename from kernel/src/sys/acpica.rs rename to lib/acpica-rs/src/lib.rs index b0bc3fb..42c1cb2 100644 --- a/kernel/src/sys/acpica.rs +++ b/lib/acpica-rs/src/lib.rs @@ -1,3 +1,3 @@ +#![no_std] #![allow(warnings)] -#![allow(unsafe_op_in_unsafe_fn)] include!("acpica-bindings.rs");