xref: /DragonOS/kernel/src/driver/acpi/pmtmr.rs (revision dd8e74ef0d7f91a141bd217736bef4fe7dc6df3d)
1 use crate::driver::clocksource::acpi_pm::{acpi_pm_read_verified, PMTMR_IO_PORT};
2 use core::sync::atomic::Ordering;
3 
4 pub const ACPI_PM_OVERRUN: u64 = 1 << 24;
5 
6 /// Number of PMTMR ticks expected during calibration run
7 pub const PMTMR_TICKS_PER_SEC: u64 = 3579545;
8 
9 /// 用于掩码ACPI_PM_READ_ERALY返回值的前24位
10 pub const ACPI_PM_MASK: u64 = 0xffffff;
11 
12 #[inline(always)]
13 #[cfg(target_arch = "x86_64")]
14 pub fn acpi_pm_read_early() -> u32 {
15     let port = unsafe { PMTMR_IO_PORT.load(Ordering::SeqCst) };
16 
17     // 如果端口为零直接返回
18     if port == 0 {
19         return 0;
20     }
21 
22     // 对读取的pmtmr值进行验证并进行掩码处理
23     return acpi_pm_read_verified() & ACPI_PM_MASK as u32;
24 }
25 
26 #[inline(always)]
27 #[cfg(not(target_arch = "x86_64"))]
28 pub fn acpi_pm_read_early() -> u32 {
29     return 0;
30 }
31