blob: d40996981e8bc8e8dcfde488dc0cc828031a0587 [file] [log] [blame]
Felix Held4a8cd722020-04-18 22:26:39 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Marshall Dawson786bd5d2017-06-16 10:10:17 -06002
Felix Heldad521852023-03-24 17:41:05 +01003#include <amdblocks/cpu.h>
Marshall Dawson786bd5d2017-06-16 10:10:17 -06004#include <cpu/x86/msr.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +02005#include <cpu/amd/msr.h>
Marshall Dawson786bd5d2017-06-16 10:10:17 -06006#include <cpu/x86/tsc.h>
Marshall Dawson786bd5d2017-06-16 10:10:17 -06007#include <console/console.h>
8#include <soc/pci_devs.h>
Felix Heldad521852023-03-24 17:41:05 +01009#include <soc/msr.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020010#include <device/pci_ops.h>
Marshall Dawson786bd5d2017-06-16 10:10:17 -060011
12unsigned long tsc_freq_mhz(void)
13{
Felix Heldad521852023-03-24 17:41:05 +010014 union pstate_msr pstate_reg;
Marshall Dawson786bd5d2017-06-16 10:10:17 -060015
16 /*
17 * See the Family 15h Models 70h-7Fh BKDG (PID 55072) definition for
18 * MSR0000_0010. The TSC increments at the P0 frequency. According
19 * to the "Software P-state Numbering" section, P0 is the highest
20 * non-boosted state. freq = 100MHz * (CpuFid + 10h) / (2^(CpuDid)).
21 */
Felix Held2323aca2023-03-25 02:51:41 +010022 pstate_reg.raw = rdmsr(PSTATE_MSR(get_pstate_0_reg())).raw;
Felix Heldad521852023-03-24 17:41:05 +010023 if (!pstate_reg.pstate_en)
Marshall Dawson786bd5d2017-06-16 10:10:17 -060024 die("Unknown error: cannot determine P-state 0\n");
25
Felix Heldad521852023-03-24 17:41:05 +010026 return get_pstate_core_freq(pstate_reg);
Marshall Dawson786bd5d2017-06-16 10:10:17 -060027}