x86: use cpuinfo to check for interrupt pending message msr
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86 / kernel / cpu / amd_64.c
blobf5fc161d8f2a48979782ad78ee25227830094059
1 #include <linux/init.h>
2 #include <linux/mm.h>
4 #include <asm/numa_64.h>
5 #include <asm/mmconfig.h>
6 #include <asm/cacheflush.h>
8 #include <mach_apic.h>
9 #include "cpu.h"
11 extern int __cpuinit get_model_name(struct cpuinfo_x86 *c);
12 extern void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c);
14 int force_mwait __cpuinitdata;
16 #ifdef CONFIG_NUMA
17 static int __cpuinit nearby_node(int apicid)
19 int i, node;
21 for (i = apicid - 1; i >= 0; i--) {
22 node = apicid_to_node[i];
23 if (node != NUMA_NO_NODE && node_online(node))
24 return node;
26 for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
27 node = apicid_to_node[i];
28 if (node != NUMA_NO_NODE && node_online(node))
29 return node;
31 return first_node(node_online_map); /* Shouldn't happen */
33 #endif
36 * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
37 * Assumes number of cores is a power of two.
39 static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)
41 #ifdef CONFIG_SMP
42 unsigned bits;
43 #ifdef CONFIG_NUMA
44 int cpu = smp_processor_id();
45 int node = 0;
46 unsigned apicid = hard_smp_processor_id();
47 #endif
48 bits = c->x86_coreid_bits;
50 /* Low order bits define the core id (index of core in socket) */
51 c->cpu_core_id = c->initial_apicid & ((1 << bits)-1);
52 /* Convert the initial APIC ID into the socket ID */
53 c->phys_proc_id = c->initial_apicid >> bits;
55 #ifdef CONFIG_NUMA
56 node = c->phys_proc_id;
57 if (apicid_to_node[apicid] != NUMA_NO_NODE)
58 node = apicid_to_node[apicid];
59 if (!node_online(node)) {
60 /* Two possibilities here:
61 - The CPU is missing memory and no node was created.
62 In that case try picking one from a nearby CPU
63 - The APIC IDs differ from the HyperTransport node IDs
64 which the K8 northbridge parsing fills in.
65 Assume they are all increased by a constant offset,
66 but in the same order as the HT nodeids.
67 If that doesn't result in a usable node fall back to the
68 path for the previous case. */
70 int ht_nodeid = c->initial_apicid;
72 if (ht_nodeid >= 0 &&
73 apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
74 node = apicid_to_node[ht_nodeid];
75 /* Pick a nearby node */
76 if (!node_online(node))
77 node = nearby_node(apicid);
79 numa_set_node(cpu, node);
81 printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
82 #endif
83 #endif
86 static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)
88 #ifdef CONFIG_SMP
89 unsigned bits, ecx;
91 /* Multi core CPU? */
92 if (c->extended_cpuid_level < 0x80000008)
93 return;
95 ecx = cpuid_ecx(0x80000008);
97 c->x86_max_cores = (ecx & 0xff) + 1;
99 /* CPU telling us the core id bits shift? */
100 bits = (ecx >> 12) & 0xF;
102 /* Otherwise recompute */
103 if (bits == 0) {
104 while ((1 << bits) < c->x86_max_cores)
105 bits++;
108 c->x86_coreid_bits = bits;
110 #endif
113 /* AMD systems with C1E don't have a working lAPIC timer. Check for that. */
114 static __cpuinit int amd_apic_timer_broken(struct cpuinfo_x86 *c)
116 u32 lo, hi;
118 if (c->x86 < 0x0F)
119 return 0;
121 /* Family 0x0f models < rev F do not have this MSR */
122 if (c->x86 == 0x0f && c->x86_model < 0x40)
123 return 0;
125 rdmsr(MSR_K8_INT_PENDING_MSG, lo, hi);
126 if (lo & K8_INTP_C1E_ACTIVE_MASK) {
127 if (smp_processor_id() != boot_cpu_physical_apicid)
128 printk(KERN_INFO "AMD C1E detected late. "
129 "Force timer broadcast.\n");
130 return 1;
132 return 0;
135 void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
137 early_init_amd_mc(c);
139 /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
140 if (c->x86_power & (1<<8))
141 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
144 void __cpuinit init_amd(struct cpuinfo_x86 *c)
146 unsigned level;
148 #ifdef CONFIG_SMP
149 unsigned long value;
152 * Disable TLB flush filter by setting HWCR.FFDIS on K8
153 * bit 6 of msr C001_0015
155 * Errata 63 for SH-B3 steppings
156 * Errata 122 for all steppings (F+ have it disabled by default)
158 if (c->x86 == 15) {
159 rdmsrl(MSR_K8_HWCR, value);
160 value |= 1 << 6;
161 wrmsrl(MSR_K8_HWCR, value);
163 #endif
165 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
166 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
167 clear_cpu_cap(c, 0*32+31);
169 /* On C+ stepping K8 rep microcode works well for copy/memset */
170 level = cpuid_eax(1);
171 if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) ||
172 level >= 0x0f58))
173 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
174 if (c->x86 == 0x10 || c->x86 == 0x11)
175 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
177 /* Enable workaround for FXSAVE leak */
178 if (c->x86 >= 6)
179 set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
181 level = get_model_name(c);
182 if (!level) {
183 switch (c->x86) {
184 case 15:
185 /* Should distinguish Models here, but this is only
186 a fallback anyways. */
187 strcpy(c->x86_model_id, "Hammer");
188 break;
191 display_cacheinfo(c);
193 /* Multi core CPU? */
194 if (c->extended_cpuid_level >= 0x80000008)
195 amd_detect_cmp(c);
197 if (c->extended_cpuid_level >= 0x80000006 &&
198 (cpuid_edx(0x80000006) & 0xf000))
199 num_cache_leaves = 4;
200 else
201 num_cache_leaves = 3;
203 if (c->x86 == 0xf || c->x86 == 0x10 || c->x86 == 0x11)
204 set_cpu_cap(c, X86_FEATURE_K8);
206 /* MFENCE stops RDTSC speculation */
207 set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
209 if (c->x86 == 0x10)
210 fam10h_check_enable_mmcfg();
212 if (c->x86 == 0x10)
213 amd_enable_pci_ext_cfg(c);
215 if (amd_apic_timer_broken(c))
216 disable_apic_timer = 1;
218 if (c == &boot_cpu_data && c->x86 >= 0xf && c->x86 <= 0x11) {
219 unsigned long long tseg;
222 * Split up direct mapping around the TSEG SMM area.
223 * Don't do it for gbpages because there seems very little
224 * benefit in doing so.
226 if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg) &&
227 (tseg >> PMD_SHIFT) <
228 (max_pfn_mapped >> (PMD_SHIFT-PAGE_SHIFT)))
229 set_memory_4k((unsigned long)__va(tseg), 1);