| 1 |
|
| 2 |
|
| 3 |
#include <cpu/cpu.h> |
| 4 |
#include <cpu/x86/tsc.h> |
| 5 |
#include <intelblocks/msr.h> |
| 6 |
|
| 7 |
|
| 8 |
#define CPU_MODEL_INTEL_ATOM_DENVERTON 0x5F |
| 9 |
|
| 10 |
static int get_processor_model(void) |
| 11 |
{ |
| 12 |
struct cpuinfo_x86 c; |
| 13 |
|
| 14 |
get_fms(&c, cpuid_eax(1)); |
| 15 |
|
| 16 |
return c.x86_model; |
| 17 |
} |
| 18 |
|
| 19 |
static unsigned long get_hardcoded_crystal_freq(void) |
| 20 |
{ |
| 21 |
unsigned long core_crystal_nominal_freq_khz = 0; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
switch (get_processor_model()) { |
| 28 |
case CPU_MODEL_INTEL_ATOM_DENVERTON: |
| 29 |
core_crystal_nominal_freq_khz = 25000; |
| 30 |
break; |
| 31 |
} |
| 32 |
|
| 33 |
return core_crystal_nominal_freq_khz; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
static unsigned long calculate_tsc_freq_from_core_crystal(void) |
| 52 |
{ |
| 53 |
unsigned long core_crystal_nominal_freq_khz; |
| 54 |
struct cpuid_result cpuidr_15h; |
| 55 |
|
| 56 |
if (cpuid_get_max_func() < 0x15) |
| 57 |
return 0; |
| 58 |
|
| 59 |
|
| 60 |
cpuidr_15h = cpuid(0x15); |
| 61 |
|
| 62 |
if (!cpuidr_15h.ebx || !cpuidr_15h.eax) |
| 63 |
return 0; |
| 64 |
|
| 65 |
core_crystal_nominal_freq_khz = cpuidr_15h.ecx / 1000; |
| 66 |
|
| 67 |
if (!core_crystal_nominal_freq_khz) |
| 68 |
core_crystal_nominal_freq_khz = get_hardcoded_crystal_freq(); |
| 69 |
|
| 70 |
return (core_crystal_nominal_freq_khz * cpuidr_15h.ebx / |
| 71 |
cpuidr_15h.eax) / 1000; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
static unsigned long get_freq_from_cpuid16h(void) |
| 86 |
{ |
| 87 |
if (cpuid_get_max_func() < 0x16) |
| 88 |
return 0; |
| 89 |
|
| 90 |
return cpuid_eax(0x16); |
| 91 |
} |
| 92 |
|
| 93 |
unsigned long tsc_freq_mhz(void) |
| 94 |
{ |
| 95 |
unsigned long tsc_freq; |
| 96 |
|
| 97 |
tsc_freq = calculate_tsc_freq_from_core_crystal(); |
| 98 |
|
| 99 |
if (tsc_freq) |
| 100 |
return tsc_freq; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
return get_freq_from_cpuid16h(); |
| 107 |
} |