xref: /DragonOS/kernel/src/arch/x86_64/acpi.rs (revision 7a29d4fcbcd89a226289c7bf541c2c78623de3ad)
1 use system_error::SystemError;
2 
3 use crate::{driver::acpi::acpi_manager, kinfo, mm::percpu::PerCpu};
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(0, processor_info.boot_processor.local_apic_id as usize);
15         let mut cnt = 1;
16         for ap in processor_info.application_processors.iter() {
17             if cnt >= PerCpu::MAX_CPU_NUM {
18                 break;
19             }
20             SMP_BOOT_DATA.set_phys_id(cnt, ap.local_apic_id as usize);
21             cnt += 1;
22         }
23         SMP_BOOT_DATA.set_cpu_count(cnt);
24         SMP_BOOT_DATA.mark_initialized();
25     }
26     kinfo!(
27         "early_acpi_boot_init: cpu_count: {}\n",
28         SMP_BOOT_DATA.cpu_count()
29     );
30 
31     // todo!("early_acpi_boot_init")
32     return Ok(());
33 }
34