This commit is contained in:
parent
d718473886
commit
b9ab8da576
4 changed files with 13 additions and 11 deletions
|
@ -24,6 +24,7 @@ static SCI_HANDLER: Mutex<Option<unsafe extern "C" fn(context: *mut c_void) -> U
|
|||
static SCI_CONTEXT: AtomicPtr<c_void> = AtomicPtr::new(null_mut());
|
||||
|
||||
use super::{
|
||||
hpet::get_current_time,
|
||||
sync::{create_semaphore, lock_semaphore, unlock_semaphore, Semaphore, Spinlock},
|
||||
task::{CURRENT_TASK, CURRENT_TASK_LOCK, MULTITASKING_ENABLED},
|
||||
};
|
||||
|
@ -100,8 +101,8 @@ extern "C" fn AcpiOsGetThreadId() -> UINT64 {
|
|||
task_id as UINT64
|
||||
}
|
||||
#[no_mangle]
|
||||
extern "C" fn AcpiOsGetTimer() {
|
||||
unimplemented!();
|
||||
extern "C" fn AcpiOsGetTimer() -> UINT64 {
|
||||
get_current_time() as UINT64 * 10
|
||||
}
|
||||
#[no_mangle]
|
||||
extern "C" fn AcpiOsInitialize() -> ACPI_STATUS {
|
||||
|
|
|
@ -89,7 +89,7 @@ fn handler() {
|
|||
SLEEP_LOCK.unlock();
|
||||
}
|
||||
}
|
||||
fn get_current_time() -> usize {
|
||||
pub fn get_current_time() -> usize {
|
||||
let address = ADDRESS.load(Ordering::SeqCst);
|
||||
let current_counter = unsafe { address.add(REGISTER_COUNTER).read_volatile() };
|
||||
ticks_to_us(current_counter as usize)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use core::{
|
||||
ptr::null_mut,
|
||||
sync::atomic::{AtomicPtr, AtomicU32, Ordering},
|
||||
sync::atomic::{AtomicPtr, AtomicU32, AtomicUsize, Ordering},
|
||||
};
|
||||
|
||||
use bitfield::bitfield;
|
||||
|
@ -36,6 +36,7 @@ const REGISTER_VERSION: u8 = 1;
|
|||
const REGISTER_REDIRECTION: u8 = 0x10;
|
||||
|
||||
static IOAPICS: [IOAPIC; 32] = [EMPTY_IOAPIC; 32];
|
||||
static NEXT_IOAPIC_ID: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
fn read_register(apic_i: usize, reg_i: u8) -> u32 {
|
||||
unsafe {
|
||||
|
@ -92,13 +93,13 @@ pub fn register_irq_handler(vector: usize, handler: fn()) {
|
|||
}
|
||||
}
|
||||
}
|
||||
pub fn setup_ioapic(apic_i: u8, phys: u64, gsi_base: u32) {
|
||||
let apic_i = apic_i as usize;
|
||||
pub fn setup_ioapic(phys: u64, gsi_base: u32) {
|
||||
let address = unsafe { map_physical(phys, 0x14, false) as *mut u32 };
|
||||
IOAPICS[apic_i].address.store(address, Ordering::SeqCst);
|
||||
IOAPICS[apic_i].start_gsi.store(gsi_base, Ordering::SeqCst);
|
||||
let max_ints = (read_register(apic_i, REGISTER_VERSION) >> 16) & 0xff;
|
||||
IOAPICS[apic_i].end_gsi.store(gsi_base + max_ints, Ordering::SeqCst);
|
||||
let next_id = NEXT_IOAPIC_ID.fetch_add(1, Ordering::SeqCst);
|
||||
IOAPICS[next_id].address.store(address, Ordering::SeqCst);
|
||||
IOAPICS[next_id].start_gsi.store(gsi_base, Ordering::SeqCst);
|
||||
let max_ints = (read_register(next_id, REGISTER_VERSION) >> 16) & 0xff;
|
||||
IOAPICS[next_id].end_gsi.store(gsi_base + max_ints, Ordering::SeqCst);
|
||||
assert!(gsi_base + max_ints < 128);
|
||||
for i in gsi_base..gsi_base + max_ints {
|
||||
let mut redirection = RedirectionEntry(0);
|
||||
|
|
|
@ -21,7 +21,7 @@ pub fn parse_madt(tables: &AcpiTables<EarlyACPIHandler>) {
|
|||
setup_lapic(lapic_address);
|
||||
for i in madt.entries() {
|
||||
if let MadtEntry::IoApic(ioapic) = i {
|
||||
setup_ioapic(ioapic.io_apic_id, ioapic.io_apic_address as u64, ioapic.global_system_interrupt_base);
|
||||
setup_ioapic(ioapic.io_apic_address as u64, ioapic.global_system_interrupt_base);
|
||||
}
|
||||
}
|
||||
for i in madt.entries() {
|
||||
|
|
Loading…
Add table
Reference in a new issue