1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <commonlib/helpers.h>
4 #include <console/console.h>
6 #include <cpu/intel/fsb.h>
7 #include <cpu/intel/speedstep.h>
8 #include <cpu/x86/msr.h>
9 #include <cpu/x86/tsc.h>
16 /* This is not an architectural MSR. */
17 #define MSR_PLATFORM_INFO 0xce
19 static int get_fsb_tsc(int *fsb
, int *ratio
)
22 static const short core_fsb
[8] = { -1, 133, -1, 166, -1, 100, -1, -1 };
23 static const short core2_fsb
[8] = { 266, 133, 200, 166, 333, 100, 400, -1 };
24 static const short f2x_fsb
[8] = { 100, 133, 200, 166, 333, -1, -1, -1 };
25 static const short rangeley_fsb
[4] = { 83, 100, 133, 116 };
28 get_fms(&c
, cpuid_eax(1));
31 switch (c
.x86_model
) {
32 case 0xe: /* Core Solo/Duo */
34 *fsb
= core_fsb
[rdmsr(MSR_FSB_FREQ
).lo
& 7];
35 *ratio
= (rdmsr(IA32_PERF_STATUS
).hi
>> 8) & 0x1f;
37 case 0xf: /* Core 2 or Xeon */
38 case 0x17: /* Enhanced Core */
39 *fsb
= core2_fsb
[rdmsr(MSR_FSB_FREQ
).lo
& 7];
40 *ratio
= (rdmsr(IA32_PERF_STATUS
).hi
>> 8) & 0x1f;
42 case 0x25: /* Arrandale BCLK fixed at 133MHz */
44 *ratio
= (rdmsr(MSR_PLATFORM_INFO
).lo
>> 8) & 0xff;
46 case 0x2a: /* SandyBridge BCLK fixed at 100MHz */
47 case 0x3a: /* IvyBridge BCLK fixed at 100MHz */
48 case 0x3c: /* Haswell BCLK fixed at 100MHz */
49 case 0x3d: /* Broadwell-ULT BCLK fixed at 100MHz */
50 case 0x45: /* Haswell-ULT BCLK fixed at 100MHz */
51 case 0x46: /* Haswell-GT3e BCLK fixed at 100MHz */
52 case 0x47: /* Broadwell BCLK fixed at 100MHz */
54 *ratio
= (rdmsr(MSR_PLATFORM_INFO
).lo
>> 8) & 0xff;
56 case 0x4d: /* Rangeley */
57 *fsb
= rangeley_fsb
[rdmsr(MSR_FSB_FREQ
).lo
& 3];
58 *ratio
= (rdmsr(MSR_PLATFORM_INFO
).lo
>> 8) & 0xff;
64 case 0xf: /* Netburst */
65 msr
= rdmsr(MSR_EBC_FREQUENCY_ID
);
66 *ratio
= msr
.lo
>> 24;
67 switch (c
.x86_model
) {
69 *fsb
= f2x_fsb
[(msr
.lo
>> 16) & 7];
74 *fsb
= core2_fsb
[(msr
.lo
>> 16) & 7];
88 static void resolve_timebase(void)
92 ret
= get_fsb_tsc(&fsb
, &ratio
);
94 u32 tsc
= 100 * DIV_ROUND_CLOSEST(ratio
* fsb
, 100);
101 printk(BIOS_ERR
, "FSB not found\n");
103 printk(BIOS_ERR
, "CPU not supported\n");
105 /* Set some semi-ridiculous defaults. */
110 u32
get_timer_fsb(void)
119 unsigned long tsc_freq_mhz(void)
129 * @brief Returns three times the FSB clock in MHz
131 * The result of calculations with the returned value shall be divided by 3.
132 * This helps to avoid rounding errors.
134 int get_ia32_fsb_x3(void)
136 const int fsb
= get_timer_fsb();
139 return 100 * DIV_ROUND_CLOSEST(3 * fsb
, 100);
141 printk(BIOS_ERR
, "FSB not supported or not found\n");