xref: /DragonOS/kernel/src/arch/x86_64/acpi.rs (revision 83ed0ebc293d5a10245089f627f52770fd5b9dd4)
1 use crate::{driver::acpi::acpi_manager, kinfo, mm::percpu::PerCpu, syscall::SystemError};
2 
3 use super::smp::SMP_BOOT_DATA;
4 
5 pub(super) fn early_acpi_boot_init() -> Result<(), SystemError> {
6     // 在这里解析madt,初始化smp boot data
7 
8     let platform_info = acpi_manager().platform_info().ok_or(SystemError::ENODEV)?;
9     let processor_info = platform_info.processor_info.ok_or(SystemError::ENODEV)?;
10 
11     unsafe {
12         SMP_BOOT_DATA.set_phys_id(0, processor_info.boot_processor.local_apic_id as usize);
13         let mut cnt = 1;
14         for ap in processor_info.application_processors.iter() {
15             if cnt >= PerCpu::MAX_CPU_NUM {
16                 break;
17             }
18             SMP_BOOT_DATA.set_phys_id(cnt, ap.local_apic_id as usize);
19             cnt += 1;
20         }
21         SMP_BOOT_DATA.set_cpu_count(cnt);
22         SMP_BOOT_DATA.mark_initialized();
23     }
24     kinfo!(
25         "early_acpi_boot_init: cpu_count: {}\n",
26         SMP_BOOT_DATA.cpu_count()
27     );
28 
29     // todo!("early_acpi_boot_init")
30     return Ok(());
31 }
32