coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
tsc_freq.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <cpu/x86/msr.h>
4 #include <cpu/amd/msr.h>
5 #include <cpu/x86/tsc.h>
6 #include <console/console.h>
7 #include <soc/pci_devs.h>
8 #include <device/pci_ops.h>
9 
10 unsigned long tsc_freq_mhz(void)
11 {
12  msr_t msr;
13  uint8_t cpufid;
14  uint8_t cpudid;
15  uint8_t boost_states;
16 
17  /*
18  * See the Family 15h Models 70h-7Fh BKDG (PID 55072) definition for
19  * MSR0000_0010. The TSC increments at the P0 frequency. According
20  * to the "Software P-state Numbering" section, P0 is the highest
21  * non-boosted state. freq = 100MHz * (CpuFid + 10h) / (2^(CpuDid)).
22  */
24  >> 2) & 0x7;
25 
26  msr = rdmsr(PSTATE_0_MSR + boost_states);
27  if (!(msr.hi & 0x80000000))
28  die("Unknown error: cannot determine P-state 0\n");
29 
30  cpufid = (msr.lo & 0x3f);
31  cpudid = (msr.lo & 0x1c0) >> 6;
32 
33  return (100 * (cpufid + 0x10)) / (0x01 << cpudid);
34 }
unsigned long tsc_freq_mhz(void)
Definition: tsc_freq.c:14
void __noreturn die(const char *fmt,...)
Definition: die.c:17
#define CORE_PERF_BOOST_CTRL
Definition: msr.h:83
#define PSTATE_0_MSR
Definition: msr.h:42
static __always_inline msr_t rdmsr(unsigned int index)
Definition: msr.h:146
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
#define SOC_PM_DEV
Definition: pci_devs.h:138
unsigned char uint8_t
Definition: stdint.h:8
unsigned int hi
Definition: msr.h:112
unsigned int lo
Definition: msr.h:111