| 1 |
|
| 2 |
|
| 3 |
#include <amdblocks/cpu.h> |
| 4 |
#include <cpu/x86/msr.h> |
| 5 |
#include <cpu/amd/msr.h> |
| 6 |
#include <cpu/x86/tsc.h> |
| 7 |
#include <console/console.h> |
| 8 |
#include <soc/msr.h> |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#define TSC_DEFAULT_FREQ_MHZ 4000 |
| 13 |
|
| 14 |
unsigned long tsc_freq_mhz(void) |
| 15 |
{ |
| 16 |
union pstate_msr pstate_reg; |
| 17 |
uint8_t high_state; |
| 18 |
static unsigned long mhz; |
| 19 |
|
| 20 |
if (mhz) |
| 21 |
return mhz; |
| 22 |
|
| 23 |
high_state = rdmsr(PS_LIM_REG).lo & 0x7; |
| 24 |
pstate_reg.raw = rdmsr(PSTATE_MSR(high_state)).raw; |
| 25 |
if (!pstate_reg.pstate_en) |
| 26 |
die("Unknown error: cannot determine P-state 0\n"); |
| 27 |
|
| 28 |
mhz = get_pstate_core_freq(pstate_reg); |
| 29 |
|
| 30 |
if (!mhz) { |
| 31 |
mhz = TSC_DEFAULT_FREQ_MHZ; |
| 32 |
printk(BIOS_ERR, "Invalid divisor, set TSC frequency to %ldMHz\n", mhz); |
| 33 |
} |
| 34 |
|
| 35 |
return mhz; |
| 36 |
} |