amd.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. #include <linux/init.h>
  2. #include <linux/bitops.h>
  3. #include <linux/elf.h>
  4. #include <linux/mm.h>
  5. #include <linux/io.h>
  6. #include <asm/processor.h>
  7. #include <asm/apic.h>
  8. #include <asm/cpu.h>
  9. #include <asm/pci-direct.h>
  10. #ifdef CONFIG_X86_64
  11. # include <asm/numa_64.h>
  12. # include <asm/mmconfig.h>
  13. # include <asm/cacheflush.h>
  14. #endif
  15. #include "cpu.h"
  16. #ifdef CONFIG_X86_32
  17. /*
  18. * B step AMD K6 before B 9730xxxx have hardware bugs that can cause
  19. * misexecution of code under Linux. Owners of such processors should
  20. * contact AMD for precise details and a CPU swap.
  21. *
  22. * See http://www.multimania.com/poulot/k6bug.html
  23. * http://www.amd.com/K6/k6docs/revgd.html
  24. *
  25. * The following test is erm.. interesting. AMD neglected to up
  26. * the chip setting when fixing the bug but they also tweaked some
  27. * performance at the same time..
  28. */
  29. extern void vide(void);
  30. __asm__(".align 4\nvide: ret");
  31. static void __cpuinit init_amd_k5(struct cpuinfo_x86 *c)
  32. {
  33. /*
  34. * General Systems BIOSen alias the cpu frequency registers
  35. * of the Elan at 0x000df000. Unfortuantly, one of the Linux
  36. * drivers subsequently pokes it, and changes the CPU speed.
  37. * Workaround : Remove the unneeded alias.
  38. */
  39. #define CBAR (0xfffc) /* Configuration Base Address (32-bit) */
  40. #define CBAR_ENB (0x80000000)
  41. #define CBAR_KEY (0X000000CB)
  42. if (c->x86_model == 9 || c->x86_model == 10) {
  43. if (inl(CBAR) & CBAR_ENB)
  44. outl(0 | CBAR_KEY, CBAR);
  45. }
  46. }
  47. static void __cpuinit init_amd_k6(struct cpuinfo_x86 *c)
  48. {
  49. u32 l, h;
  50. int mbytes = num_physpages >> (20-PAGE_SHIFT);
  51. if (c->x86_model < 6) {
  52. /* Based on AMD doc 20734R - June 2000 */
  53. if (c->x86_model == 0) {
  54. clear_cpu_cap(c, X86_FEATURE_APIC);
  55. set_cpu_cap(c, X86_FEATURE_PGE);
  56. }
  57. return;
  58. }
  59. if (c->x86_model == 6 && c->x86_mask == 1) {
  60. const int K6_BUG_LOOP = 1000000;
  61. int n;
  62. void (*f_vide)(void);
  63. unsigned long d, d2;
  64. printk(KERN_INFO "AMD K6 stepping B detected - ");
  65. /*
  66. * It looks like AMD fixed the 2.6.2 bug and improved indirect
  67. * calls at the same time.
  68. */
  69. n = K6_BUG_LOOP;
  70. f_vide = vide;
  71. rdtscl(d);
  72. while (n--)
  73. f_vide();
  74. rdtscl(d2);
  75. d = d2-d;
  76. if (d > 20*K6_BUG_LOOP)
  77. printk(KERN_CONT
  78. "system stability may be impaired when more than 32 MB are used.\n");
  79. else
  80. printk(KERN_CONT "probably OK (after B9730xxxx).\n");
  81. printk(KERN_INFO "Please see http://membres.lycos.fr/poulot/k6bug.html\n");
  82. }
  83. /* K6 with old style WHCR */
  84. if (c->x86_model < 8 ||
  85. (c->x86_model == 8 && c->x86_mask < 8)) {
  86. /* We can only write allocate on the low 508Mb */
  87. if (mbytes > 508)
  88. mbytes = 508;
  89. rdmsr(MSR_K6_WHCR, l, h);
  90. if ((l&0x0000FFFF) == 0) {
  91. unsigned long flags;
  92. l = (1<<0)|((mbytes/4)<<1);
  93. local_irq_save(flags);
  94. wbinvd();
  95. wrmsr(MSR_K6_WHCR, l, h);
  96. local_irq_restore(flags);
  97. printk(KERN_INFO "Enabling old style K6 write allocation for %d Mb\n",
  98. mbytes);
  99. }
  100. return;
  101. }
  102. if ((c->x86_model == 8 && c->x86_mask > 7) ||
  103. c->x86_model == 9 || c->x86_model == 13) {
  104. /* The more serious chips .. */
  105. if (mbytes > 4092)
  106. mbytes = 4092;
  107. rdmsr(MSR_K6_WHCR, l, h);
  108. if ((l&0xFFFF0000) == 0) {
  109. unsigned long flags;
  110. l = ((mbytes>>2)<<22)|(1<<16);
  111. local_irq_save(flags);
  112. wbinvd();
  113. wrmsr(MSR_K6_WHCR, l, h);
  114. local_irq_restore(flags);
  115. printk(KERN_INFO "Enabling new style K6 write allocation for %d Mb\n",
  116. mbytes);
  117. }
  118. return;
  119. }
  120. if (c->x86_model == 10) {
  121. /* AMD Geode LX is model 10 */
  122. /* placeholder for any needed mods */
  123. return;
  124. }
  125. }
  126. static void __cpuinit amd_k7_smp_check(struct cpuinfo_x86 *c)
  127. {
  128. #ifdef CONFIG_SMP
  129. /* calling is from identify_secondary_cpu() ? */
  130. if (!c->cpu_index)
  131. return;
  132. /*
  133. * Certain Athlons might work (for various values of 'work') in SMP
  134. * but they are not certified as MP capable.
  135. */
  136. /* Athlon 660/661 is valid. */
  137. if ((c->x86_model == 6) && ((c->x86_mask == 0) ||
  138. (c->x86_mask == 1)))
  139. goto valid_k7;
  140. /* Duron 670 is valid */
  141. if ((c->x86_model == 7) && (c->x86_mask == 0))
  142. goto valid_k7;
  143. /*
  144. * Athlon 662, Duron 671, and Athlon >model 7 have capability
  145. * bit. It's worth noting that the A5 stepping (662) of some
  146. * Athlon XP's have the MP bit set.
  147. * See http://www.heise.de/newsticker/data/jow-18.10.01-000 for
  148. * more.
  149. */
  150. if (((c->x86_model == 6) && (c->x86_mask >= 2)) ||
  151. ((c->x86_model == 7) && (c->x86_mask >= 1)) ||
  152. (c->x86_model > 7))
  153. if (cpu_has_mp)
  154. goto valid_k7;
  155. /* If we get here, not a certified SMP capable AMD system. */
  156. /*
  157. * Don't taint if we are running SMP kernel on a single non-MP
  158. * approved Athlon
  159. */
  160. WARN_ONCE(1, "WARNING: This combination of AMD"
  161. " processors is not suitable for SMP.\n");
  162. if (!test_taint(TAINT_UNSAFE_SMP))
  163. add_taint(TAINT_UNSAFE_SMP);
  164. valid_k7:
  165. ;
  166. #endif
  167. }
  168. static void __cpuinit init_amd_k7(struct cpuinfo_x86 *c)
  169. {
  170. u32 l, h;
  171. /*
  172. * Bit 15 of Athlon specific MSR 15, needs to be 0
  173. * to enable SSE on Palomino/Morgan/Barton CPU's.
  174. * If the BIOS didn't enable it already, enable it here.
  175. */
  176. if (c->x86_model >= 6 && c->x86_model <= 10) {
  177. if (!cpu_has(c, X86_FEATURE_XMM)) {
  178. printk(KERN_INFO "Enabling disabled K7/SSE Support.\n");
  179. rdmsr(MSR_K7_HWCR, l, h);
  180. l &= ~0x00008000;
  181. wrmsr(MSR_K7_HWCR, l, h);
  182. set_cpu_cap(c, X86_FEATURE_XMM);
  183. }
  184. }
  185. /*
  186. * It's been determined by AMD that Athlons since model 8 stepping 1
  187. * are more robust with CLK_CTL set to 200xxxxx instead of 600xxxxx
  188. * As per AMD technical note 27212 0.2
  189. */
  190. if ((c->x86_model == 8 && c->x86_mask >= 1) || (c->x86_model > 8)) {
  191. rdmsr(MSR_K7_CLK_CTL, l, h);
  192. if ((l & 0xfff00000) != 0x20000000) {
  193. printk(KERN_INFO
  194. "CPU: CLK_CTL MSR was %x. Reprogramming to %x\n",
  195. l, ((l & 0x000fffff)|0x20000000));
  196. wrmsr(MSR_K7_CLK_CTL, (l & 0x000fffff)|0x20000000, h);
  197. }
  198. }
  199. set_cpu_cap(c, X86_FEATURE_K7);
  200. amd_k7_smp_check(c);
  201. }
  202. #endif
  203. #ifdef CONFIG_NUMA
  204. /*
  205. * To workaround broken NUMA config. Read the comment in
  206. * srat_detect_node().
  207. */
  208. static int __cpuinit nearby_node(int apicid)
  209. {
  210. int i, node;
  211. for (i = apicid - 1; i >= 0; i--) {
  212. node = __apicid_to_node[i];
  213. if (node != NUMA_NO_NODE && node_online(node))
  214. return node;
  215. }
  216. for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
  217. node = __apicid_to_node[i];
  218. if (node != NUMA_NO_NODE && node_online(node))
  219. return node;
  220. }
  221. return first_node(node_online_map); /* Shouldn't happen */
  222. }
  223. #endif
  224. /*
  225. * Fixup core topology information for
  226. * (1) AMD multi-node processors
  227. * Assumption: Number of cores in each internal node is the same.
  228. * (2) AMD processors supporting compute units
  229. */
  230. #ifdef CONFIG_X86_HT
  231. static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c)
  232. {
  233. u32 nodes, cores_per_cu = 1;
  234. u8 node_id;
  235. int cpu = smp_processor_id();
  236. /* get information required for multi-node processors */
  237. if (cpu_has(c, X86_FEATURE_TOPOEXT)) {
  238. u32 eax, ebx, ecx, edx;
  239. cpuid(0x8000001e, &eax, &ebx, &ecx, &edx);
  240. nodes = ((ecx >> 8) & 7) + 1;
  241. node_id = ecx & 7;
  242. /* get compute unit information */
  243. smp_num_siblings = ((ebx >> 8) & 3) + 1;
  244. c->compute_unit_id = ebx & 0xff;
  245. cores_per_cu += ((ebx >> 8) & 3);
  246. } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) {
  247. u64 value;
  248. rdmsrl(MSR_FAM10H_NODE_ID, value);
  249. nodes = ((value >> 3) & 7) + 1;
  250. node_id = value & 7;
  251. } else
  252. return;
  253. /* fixup multi-node processor information */
  254. if (nodes > 1) {
  255. u32 cores_per_node;
  256. u32 cus_per_node;
  257. set_cpu_cap(c, X86_FEATURE_AMD_DCM);
  258. cores_per_node = c->x86_max_cores / nodes;
  259. cus_per_node = cores_per_node / cores_per_cu;
  260. /* store NodeID, use llc_shared_map to store sibling info */
  261. per_cpu(cpu_llc_id, cpu) = node_id;
  262. /* core id has to be in the [0 .. cores_per_node - 1] range */
  263. c->cpu_core_id %= cores_per_node;
  264. c->compute_unit_id %= cus_per_node;
  265. }
  266. }
  267. #endif
  268. /*
  269. * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
  270. * Assumes number of cores is a power of two.
  271. */
  272. static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)
  273. {
  274. #ifdef CONFIG_X86_HT
  275. unsigned bits;
  276. int cpu = smp_processor_id();
  277. bits = c->x86_coreid_bits;
  278. /* Low order bits define the core id (index of core in socket) */
  279. c->cpu_core_id = c->initial_apicid & ((1 << bits)-1);
  280. /* Convert the initial APIC ID into the socket ID */
  281. c->phys_proc_id = c->initial_apicid >> bits;
  282. /* use socket ID also for last level cache */
  283. per_cpu(cpu_llc_id, cpu) = c->phys_proc_id;
  284. amd_get_topology(c);
  285. #endif
  286. }
  287. int amd_get_nb_id(int cpu)
  288. {
  289. int id = 0;
  290. #ifdef CONFIG_SMP
  291. id = per_cpu(cpu_llc_id, cpu);
  292. #endif
  293. return id;
  294. }
  295. EXPORT_SYMBOL_GPL(amd_get_nb_id);
  296. static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c)
  297. {
  298. #ifdef CONFIG_NUMA
  299. int cpu = smp_processor_id();
  300. int node;
  301. unsigned apicid = c->apicid;
  302. node = numa_cpu_node(cpu);
  303. if (node == NUMA_NO_NODE)
  304. node = per_cpu(cpu_llc_id, cpu);
  305. if (!node_online(node)) {
  306. /*
  307. * Two possibilities here:
  308. *
  309. * - The CPU is missing memory and no node was created. In
  310. * that case try picking one from a nearby CPU.
  311. *
  312. * - The APIC IDs differ from the HyperTransport node IDs
  313. * which the K8 northbridge parsing fills in. Assume
  314. * they are all increased by a constant offset, but in
  315. * the same order as the HT nodeids. If that doesn't
  316. * result in a usable node fall back to the path for the
  317. * previous case.
  318. *
  319. * This workaround operates directly on the mapping between
  320. * APIC ID and NUMA node, assuming certain relationship
  321. * between APIC ID, HT node ID and NUMA topology. As going
  322. * through CPU mapping may alter the outcome, directly
  323. * access __apicid_to_node[].
  324. */
  325. int ht_nodeid = c->initial_apicid;
  326. if (ht_nodeid >= 0 &&
  327. __apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
  328. node = __apicid_to_node[ht_nodeid];
  329. /* Pick a nearby node */
  330. if (!node_online(node))
  331. node = nearby_node(apicid);
  332. }
  333. numa_set_node(cpu, node);
  334. #endif
  335. }
  336. static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)
  337. {
  338. #ifdef CONFIG_X86_HT
  339. unsigned bits, ecx;
  340. /* Multi core CPU? */
  341. if (c->extended_cpuid_level < 0x80000008)
  342. return;
  343. ecx = cpuid_ecx(0x80000008);
  344. c->x86_max_cores = (ecx & 0xff) + 1;
  345. /* CPU telling us the core id bits shift? */
  346. bits = (ecx >> 12) & 0xF;
  347. /* Otherwise recompute */
  348. if (bits == 0) {
  349. while ((1 << bits) < c->x86_max_cores)
  350. bits++;
  351. }
  352. c->x86_coreid_bits = bits;
  353. #endif
  354. }
  355. static void __cpuinit bsp_init_amd(struct cpuinfo_x86 *c)
  356. {
  357. if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
  358. if (c->x86 > 0x10 ||
  359. (c->x86 == 0x10 && c->x86_model >= 0x2)) {
  360. u64 val;
  361. rdmsrl(MSR_K7_HWCR, val);
  362. if (!(val & BIT(24)))
  363. printk(KERN_WARNING FW_BUG "TSC doesn't count "
  364. "with P0 frequency!\n");
  365. }
  366. }
  367. if (c->x86 == 0x15) {
  368. unsigned long upperbit;
  369. u32 cpuid, assoc;
  370. cpuid = cpuid_edx(0x80000005);
  371. assoc = cpuid >> 16 & 0xff;
  372. upperbit = ((cpuid >> 24) << 10) / assoc;
  373. va_align.mask = (upperbit - 1) & PAGE_MASK;
  374. va_align.flags = ALIGN_VA_32 | ALIGN_VA_64;
  375. }
  376. }
  377. static void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
  378. {
  379. early_init_amd_mc(c);
  380. /*
  381. * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
  382. * with P/T states and does not stop in deep C-states
  383. */
  384. if (c->x86_power & (1 << 8)) {
  385. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  386. set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
  387. }
  388. #ifdef CONFIG_X86_64
  389. set_cpu_cap(c, X86_FEATURE_SYSCALL32);
  390. #else
  391. /* Set MTRR capability flag if appropriate */
  392. if (c->x86 == 5)
  393. if (c->x86_model == 13 || c->x86_model == 9 ||
  394. (c->x86_model == 8 && c->x86_mask >= 8))
  395. set_cpu_cap(c, X86_FEATURE_K6_MTRR);
  396. #endif
  397. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_PCI)
  398. /* check CPU config space for extended APIC ID */
  399. if (cpu_has_apic && c->x86 >= 0xf) {
  400. unsigned int val;
  401. val = read_pci_config(0, 24, 0, 0x68);
  402. if ((val & ((1 << 17) | (1 << 18))) == ((1 << 17) | (1 << 18)))
  403. set_cpu_cap(c, X86_FEATURE_EXTD_APICID);
  404. }
  405. #endif
  406. }
  407. static void __cpuinit init_amd(struct cpuinfo_x86 *c)
  408. {
  409. #ifdef CONFIG_SMP
  410. unsigned long long value;
  411. /*
  412. * Disable TLB flush filter by setting HWCR.FFDIS on K8
  413. * bit 6 of msr C001_0015
  414. *
  415. * Errata 63 for SH-B3 steppings
  416. * Errata 122 for all steppings (F+ have it disabled by default)
  417. */
  418. if (c->x86 == 0xf) {
  419. rdmsrl(MSR_K7_HWCR, value);
  420. value |= 1 << 6;
  421. wrmsrl(MSR_K7_HWCR, value);
  422. }
  423. #endif
  424. early_init_amd(c);
  425. /*
  426. * Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  427. * 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway
  428. */
  429. clear_cpu_cap(c, 0*32+31);
  430. #ifdef CONFIG_X86_64
  431. /* On C+ stepping K8 rep microcode works well for copy/memset */
  432. if (c->x86 == 0xf) {
  433. u32 level;
  434. level = cpuid_eax(1);
  435. if ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58)
  436. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  437. /*
  438. * Some BIOSes incorrectly force this feature, but only K8
  439. * revision D (model = 0x14) and later actually support it.
  440. * (AMD Erratum #110, docId: 25759).
  441. */
  442. if (c->x86_model < 0x14 && cpu_has(c, X86_FEATURE_LAHF_LM)) {
  443. u64 val;
  444. clear_cpu_cap(c, X86_FEATURE_LAHF_LM);
  445. if (!rdmsrl_amd_safe(0xc001100d, &val)) {
  446. val &= ~(1ULL << 32);
  447. wrmsrl_amd_safe(0xc001100d, val);
  448. }
  449. }
  450. }
  451. if (c->x86 >= 0x10)
  452. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  453. /* get apicid instead of initial apic id from cpuid */
  454. c->apicid = hard_smp_processor_id();
  455. #else
  456. /*
  457. * FIXME: We should handle the K5 here. Set up the write
  458. * range and also turn on MSR 83 bits 4 and 31 (write alloc,
  459. * no bus pipeline)
  460. */
  461. switch (c->x86) {
  462. case 4:
  463. init_amd_k5(c);
  464. break;
  465. case 5:
  466. init_amd_k6(c);
  467. break;
  468. case 6: /* An Athlon/Duron */
  469. init_amd_k7(c);
  470. break;
  471. }
  472. /* K6s reports MCEs but don't actually have all the MSRs */
  473. if (c->x86 < 6)
  474. clear_cpu_cap(c, X86_FEATURE_MCE);
  475. #endif
  476. /* Enable workaround for FXSAVE leak */
  477. if (c->x86 >= 6)
  478. set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
  479. if (!c->x86_model_id[0]) {
  480. switch (c->x86) {
  481. case 0xf:
  482. /* Should distinguish Models here, but this is only
  483. a fallback anyways. */
  484. strcpy(c->x86_model_id, "Hammer");
  485. break;
  486. }
  487. }
  488. cpu_detect_cache_sizes(c);
  489. /* Multi core CPU? */
  490. if (c->extended_cpuid_level >= 0x80000008) {
  491. amd_detect_cmp(c);
  492. srat_detect_node(c);
  493. }
  494. #ifdef CONFIG_X86_32
  495. detect_ht(c);
  496. #endif
  497. if (c->extended_cpuid_level >= 0x80000006) {
  498. if (cpuid_edx(0x80000006) & 0xf000)
  499. num_cache_leaves = 4;
  500. else
  501. num_cache_leaves = 3;
  502. }
  503. if (c->x86 >= 0xf)
  504. set_cpu_cap(c, X86_FEATURE_K8);
  505. if (cpu_has_xmm2) {
  506. /* MFENCE stops RDTSC speculation */
  507. set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
  508. }
  509. #ifdef CONFIG_X86_64
  510. if (c->x86 == 0x10) {
  511. /* do this for boot cpu */
  512. if (c == &boot_cpu_data)
  513. check_enable_amd_mmconf_dmi();
  514. fam10h_check_enable_mmcfg();
  515. }
  516. if (c == &boot_cpu_data && c->x86 >= 0xf) {
  517. unsigned long long tseg;
  518. /*
  519. * Split up direct mapping around the TSEG SMM area.
  520. * Don't do it for gbpages because there seems very little
  521. * benefit in doing so.
  522. */
  523. if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg)) {
  524. printk(KERN_DEBUG "tseg: %010llx\n", tseg);
  525. if ((tseg>>PMD_SHIFT) <
  526. (max_low_pfn_mapped>>(PMD_SHIFT-PAGE_SHIFT)) ||
  527. ((tseg>>PMD_SHIFT) <
  528. (max_pfn_mapped>>(PMD_SHIFT-PAGE_SHIFT)) &&
  529. (tseg>>PMD_SHIFT) >= (1ULL<<(32 - PMD_SHIFT))))
  530. set_memory_4k((unsigned long)__va(tseg), 1);
  531. }
  532. }
  533. #endif
  534. /*
  535. * Family 0x12 and above processors have APIC timer
  536. * running in deep C states.
  537. */
  538. if (c->x86 > 0x11)
  539. set_cpu_cap(c, X86_FEATURE_ARAT);
  540. /*
  541. * Disable GART TLB Walk Errors on Fam10h. We do this here
  542. * because this is always needed when GART is enabled, even in a
  543. * kernel which has no MCE support built in.
  544. */
  545. if (c->x86 == 0x10) {
  546. /*
  547. * BIOS should disable GartTlbWlk Errors themself. If
  548. * it doesn't do it here as suggested by the BKDG.
  549. *
  550. * Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=33012
  551. */
  552. u64 mask;
  553. int err;
  554. err = rdmsrl_safe(MSR_AMD64_MCx_MASK(4), &mask);
  555. if (err == 0) {
  556. mask |= (1 << 10);
  557. checking_wrmsrl(MSR_AMD64_MCx_MASK(4), mask);
  558. }
  559. }
  560. }
  561. #ifdef CONFIG_X86_32
  562. static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
  563. unsigned int size)
  564. {
  565. /* AMD errata T13 (order #21922) */
  566. if ((c->x86 == 6)) {
  567. /* Duron Rev A0 */
  568. if (c->x86_model == 3 && c->x86_mask == 0)
  569. size = 64;
  570. /* Tbird rev A1/A2 */
  571. if (c->x86_model == 4 &&
  572. (c->x86_mask == 0 || c->x86_mask == 1))
  573. size = 256;
  574. }
  575. return size;
  576. }
  577. #endif
  578. static const struct cpu_dev __cpuinitconst amd_cpu_dev = {
  579. .c_vendor = "AMD",
  580. .c_ident = { "AuthenticAMD" },
  581. #ifdef CONFIG_X86_32
  582. .c_models = {
  583. { .vendor = X86_VENDOR_AMD, .family = 4, .model_names =
  584. {
  585. [3] = "486 DX/2",
  586. [7] = "486 DX/2-WB",
  587. [8] = "486 DX/4",
  588. [9] = "486 DX/4-WB",
  589. [14] = "Am5x86-WT",
  590. [15] = "Am5x86-WB"
  591. }
  592. },
  593. },
  594. .c_size_cache = amd_size_cache,
  595. #endif
  596. .c_early_init = early_init_amd,
  597. .c_bsp_init = bsp_init_amd,
  598. .c_init = init_amd,
  599. .c_x86_vendor = X86_VENDOR_AMD,
  600. };
  601. cpu_dev_register(amd_cpu_dev);
  602. /*
  603. * AMD errata checking
  604. *
  605. * Errata are defined as arrays of ints using the AMD_LEGACY_ERRATUM() or
  606. * AMD_OSVW_ERRATUM() macros. The latter is intended for newer errata that
  607. * have an OSVW id assigned, which it takes as first argument. Both take a
  608. * variable number of family-specific model-stepping ranges created by
  609. * AMD_MODEL_RANGE(). Each erratum also has to be declared as extern const
  610. * int[] in arch/x86/include/asm/processor.h.
  611. *
  612. * Example:
  613. *
  614. * const int amd_erratum_319[] =
  615. * AMD_LEGACY_ERRATUM(AMD_MODEL_RANGE(0x10, 0x2, 0x1, 0x4, 0x2),
  616. * AMD_MODEL_RANGE(0x10, 0x8, 0x0, 0x8, 0x0),
  617. * AMD_MODEL_RANGE(0x10, 0x9, 0x0, 0x9, 0x0));
  618. */
  619. const int amd_erratum_400[] =
  620. AMD_OSVW_ERRATUM(1, AMD_MODEL_RANGE(0xf, 0x41, 0x2, 0xff, 0xf),
  621. AMD_MODEL_RANGE(0x10, 0x2, 0x1, 0xff, 0xf));
  622. EXPORT_SYMBOL_GPL(amd_erratum_400);
  623. const int amd_erratum_383[] =
  624. AMD_OSVW_ERRATUM(3, AMD_MODEL_RANGE(0x10, 0, 0, 0xff, 0xf));
  625. EXPORT_SYMBOL_GPL(amd_erratum_383);
  626. bool cpu_has_amd_erratum(const int *erratum)
  627. {
  628. struct cpuinfo_x86 *cpu = __this_cpu_ptr(&cpu_info);
  629. int osvw_id = *erratum++;
  630. u32 range;
  631. u32 ms;
  632. /*
  633. * If called early enough that current_cpu_data hasn't been initialized
  634. * yet, fall back to boot_cpu_data.
  635. */
  636. if (cpu->x86 == 0)
  637. cpu = &boot_cpu_data;
  638. if (cpu->x86_vendor != X86_VENDOR_AMD)
  639. return false;
  640. if (osvw_id >= 0 && osvw_id < 65536 &&
  641. cpu_has(cpu, X86_FEATURE_OSVW)) {
  642. u64 osvw_len;
  643. rdmsrl(MSR_AMD64_OSVW_ID_LENGTH, osvw_len);
  644. if (osvw_id < osvw_len) {
  645. u64 osvw_bits;
  646. rdmsrl(MSR_AMD64_OSVW_STATUS + (osvw_id >> 6),
  647. osvw_bits);
  648. return osvw_bits & (1ULL << (osvw_id & 0x3f));
  649. }
  650. }
  651. /* OSVW unavailable or ID unknown, match family-model-stepping range */
  652. ms = (cpu->x86_model << 4) | cpu->x86_mask;
  653. while ((range = *erratum++))
  654. if ((cpu->x86 == AMD_MODEL_RANGE_FAMILY(range)) &&
  655. (ms >= AMD_MODEL_RANGE_START(range)) &&
  656. (ms <= AMD_MODEL_RANGE_END(range)))
  657. return true;
  658. return false;
  659. }
  660. EXPORT_SYMBOL_GPL(cpu_has_amd_erratum);