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