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