1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <amdblocks/cpu.h>
4 #include <amdblocks/smn.h>
5 #include <cpu/amd/msr.h>
6 #include <cpu/x86/msr.h>
7 #include <device/pci_ops.h>
9 #include <soc/pci_devs.h>
12 uint32_t get_pstate_0_reg(void)
14 return (pci_read_config32(SOC_PM_DEV
, CORE_PERF_BOOST_CTRL
) >> 2) & 0x7;
17 static bool all_pstates_have_same_frequency_id(void)
19 union pstate_msr pstate_reg
;
22 uint32_t frequency_id
;
24 for (i
= 0; i
< PSTATE_MSR_COUNT
; i
++) {
25 pstate_reg
.raw
= rdmsr(PSTATE_MSR(i
)).raw
;
27 if (!pstate_reg
.pstate_en
)
31 frequency_id
= pstate_reg
.cpu_fid_0_5
;
33 } else if (frequency_id
!= pstate_reg
.cpu_fid_0_5
) {
41 #define CLK_PLL_LOCK_TIMER 0xD82220B8
42 #define CLK_GATER_SEQUENCE_REGISTER 0xD8222114
44 uint32_t get_pstate_latency(void)
48 uint32_t gaters_on_time
, gaters_off_time
;
50 smn_data
= smn_read32(CLK_GATER_SEQUENCE_REGISTER
);
51 gaters_on_time
= (smn_data
& 0xff) * 10;
52 gaters_off_time
= (smn_data
>> 8 & 0xff) * 10;
53 latency
+= DIV_ROUND_UP(15 * gaters_on_time
, 1000);
54 latency
+= DIV_ROUND_UP(15 * gaters_off_time
, 1000);
56 if (!all_pstates_have_same_frequency_id()) {
57 smn_data
= smn_read32(CLK_PLL_LOCK_TIMER
);
58 latency
+= DIV_ROUND_UP(smn_data
& 0x1fff, 100);