1 #include <linux/export.h>
3 #include <linux/bitops.h>
8 #include <linux/sched.h>
9 #include <asm/processor.h>
17 # include <asm/cacheflush.h>
22 static inline int rdmsrl_amd_safe(
unsigned msr,
unsigned long long *
p)
28 WARN_ONCE((c->
x86 != 0xf),
"%s should only be used on K8!\n", __func__);
33 err = rdmsr_safe_regs(gprs);
35 *p = gprs[0] | ((
u64)gprs[2] << 32);
40 static inline int wrmsrl_amd_safe(
unsigned msr,
unsigned long long val)
45 WARN_ONCE((c->
x86 != 0xf),
"%s should only be used on K8!\n", __func__);
52 return wrmsr_safe_regs(gprs);
70 extern void vide(
void);
82 #define CBAR_ENB (0x80000000)
83 #define CBAR_KEY (0X000000CB)
106 const int K6_BUG_LOOP = 1000000;
126 if (d > 20*K6_BUG_LOOP)
128 "system stability may be impaired when more than 32 MB are used.\n");
141 if ((l&0x0000FFFF) == 0) {
143 l = (1<<0)|((mbytes/4)<<1);
162 if ((l&0xFFFF0000) == 0) {
164 l = ((mbytes>>2)<<22)|(1<<16);
221 WARN_ONCE(1,
"WARNING: This combination of AMD"
222 " processors is not suitable for SMP.\n");
256 if ((l & 0xfff00000) != 0x20000000) {
258 "CPU: CLK_CTL MSR was %x. Reprogramming to %x\n",
259 l, ((l & 0x000fffff)|0x20000000));
279 for (i = apicid - 1; i >= 0; i--) {
280 node = __apicid_to_node[
i];
285 node = __apicid_to_node[
i];
302 u32 nodes, cores_per_cu = 1;
310 cpuid(0x8000001e, &eax, &ebx, &ecx, &edx);
311 nodes = ((ecx >> 8) & 7) + 1;
317 cores_per_cu += ((ebx >> 8) & 3);
322 nodes = ((value >> 3) & 7) + 1;
334 cus_per_node = cores_per_node / cores_per_cu;
382 unsigned apicid = c->
apicid;
386 node =
per_cpu(cpu_llc_id, cpu);
418 if (ht_nodeid >= 0 &&
420 node = __apicid_to_node[ht_nodeid];
423 node = nearby_node(apicid);
438 ecx = cpuid_ecx(0x80000008);
443 bits = (ecx >> 12) & 0xF;
464 if (!(val &
BIT(24)))
466 "with P0 frequency!\n");
470 if (c->
x86 == 0x15) {
471 unsigned long upperbit;
474 cpuid = cpuid_edx(0x80000005);
475 assoc = cpuid >> 16 & 0xff;
476 upperbit = ((cpuid >> 24) << 10) / assoc;
485 early_init_amd_mc(c);
495 sched_clock_stable = 1;
507 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_PCI)
509 if (cpu_has_apic && c->
x86 >= 0xf) {
512 if ((val & ((1 << 17) | (1 << 18))) == ((1 << 17) | (1 << 18)))
523 unsigned long long value;
545 clear_cpu_cap(c, 0*32+31);
552 level = cpuid_eax(1);
553 if ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58)
565 if (!rdmsrl_amd_safe(0xc001100d, &val)) {
566 val &= ~(1ULL << 32);
567 wrmsrl_amd_safe(0xc001100d, val);
617 if ((c->
x86 == 0x15) &&
622 if (!rdmsrl_safe(0xc0011005, &val)) {
624 wrmsrl_safe(0xc0011005, val);
625 rdmsrl(0xc0011005, val);
626 if (val & (1ULL << 54)) {
629 "disabled Topology Extensions Support\n");
638 if ((c->
x86 == 0x15) &&
642 if (!rdmsrl_safe(0xc0011021, &val) && !(val & 0x1E)) {
644 wrmsrl_safe(0xc0011021, val);
661 if (cpuid_edx(0x80000006) & 0xf000)
676 if (c->
x86 == 0x10) {
685 unsigned long long tseg;
716 if (c->
x86 == 0x10) {
776 cpuid(0x80000006, &eax, &ebx, &ecx, &edx);
786 cpuid(0x80000005, &eax, &ebx, &ecx, &edx);
791 if (!((eax >> 16) & mask)) {
794 cpuid(0x80000005, &a, &b, &c, &d);
809 cpuid(0x80000005, &eax, &ebx, &ecx, &edx);
817 cpu_set_tlb_flushall_shift(c);
822 .c_ident = {
"AuthenticAMD" },
836 .c_size_cache = amd_size_cache,
838 .c_early_init = early_init_amd,
839 .c_detect_tlb = cpu_detect_tlb_amd,
840 .c_bsp_init = bsp_init_amd,
866 AMD_OSVW_ERRATUM(1, AMD_MODEL_RANGE(0xf, 0x41, 0x2, 0xff, 0xf),
867 AMD_MODEL_RANGE(0x10, 0x2, 0x1, 0xff, 0xf));
871 AMD_OSVW_ERRATUM(3, AMD_MODEL_RANGE(0x10, 0, 0, 0xff, 0xf));
877 int osvw_id = *erratum++;
891 if (osvw_id >= 0 && osvw_id < 65536 &&
896 if (osvw_id < osvw_len) {
901 return osvw_bits & (1ULL << (osvw_id & 0x3f));
907 while ((range = *erratum++))
908 if ((cpu->
x86 == AMD_MODEL_RANGE_FAMILY(range)) &&
909 (ms >= AMD_MODEL_RANGE_START(range)) &&
910 (ms <= AMD_MODEL_RANGE_END(range)))