xref: /DragonOS/kernel/src/driver/acpi/pmtmr.rs (revision fae6e9ade46a52976ad5d099643d51cc20876448)
1 #[allow(dead_code)]
2 pub const ACPI_PM_OVERRUN: u64 = 1 << 24;
3 
4 /// Number of PMTMR ticks expected during calibration run
5 pub const PMTMR_TICKS_PER_SEC: u64 = 3579545;
6 
7 /// 用于掩码ACPI_PM_READ_ERALY返回值的前24位
8 pub const ACPI_PM_MASK: u64 = 0xffffff;
9 
10 #[inline(always)]
11 #[cfg(target_arch = "x86_64")]
12 pub fn acpi_pm_read_early() -> u32 {
13     use crate::driver::clocksource::acpi_pm::{acpi_pm_read_verified, PMTMR_IO_PORT};
14     use core::sync::atomic::Ordering;
15     let port = 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 #[allow(dead_code)]
29 pub fn acpi_pm_read_early() -> u32 {
30     return 0;
31 }
32