2 * Check for extended topology enumeration cpuid leaf 0xb and if it
3 * exists, use it for populating initial_apicid and cpu topology
10 #include <asm/processor.h>
12 /* leaf 0xb SMT level */
15 /* leaf 0xb sub-leaf types */
16 #define INVALID_TYPE 0
20 #define LEAFB_SUBTYPE(ecx) (((ecx) >> 8) & 0xff)
21 #define BITS_SHIFT_NEXT_LEVEL(eax) ((eax) & 0x1f)
22 #define LEVEL_MAX_SIBLINGS(ebx) ((ebx) & 0xffff)
25 * Check for extended topology enumeration cpuid leaf 0xb and if it
26 * exists, use it for populating initial_apicid and cpu topology
29 int detect_extended_topology_early(struct cpuinfo_x86 *c)
32 unsigned int eax, ebx, ecx, edx;
34 if (c->cpuid_level < 0xb)
37 cpuid_count(0xb, SMT_LEVEL, &eax, &ebx, &ecx, &edx);
40 * check if the cpuid leaf 0xb is actually implemented.
42 if (ebx == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE))
45 set_cpu_cap(c, X86_FEATURE_XTOPOLOGY);
48 * initial apic id, which also represents 32-bit extended x2apic id.
50 c->initial_apicid = edx;
51 smp_num_siblings = LEVEL_MAX_SIBLINGS(ebx);
57 * Check for extended topology enumeration cpuid leaf 0xb and if it
58 * exists, use it for populating initial_apicid and cpu topology
61 void detect_extended_topology(struct cpuinfo_x86 *c)
64 unsigned int eax, ebx, ecx, edx, sub_index;
65 unsigned int ht_mask_width, core_plus_mask_width;
66 unsigned int core_select_mask, core_level_siblings;
68 if (detect_extended_topology_early(c) < 0)
72 * Populate HT related information from sub-leaf level 0.
74 cpuid_count(0xb, SMT_LEVEL, &eax, &ebx, &ecx, &edx);
75 core_level_siblings = smp_num_siblings = LEVEL_MAX_SIBLINGS(ebx);
76 core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
80 cpuid_count(0xb, sub_index, &eax, &ebx, &ecx, &edx);
83 * Check for the Core type in the implemented sub leaves.
85 if (LEAFB_SUBTYPE(ecx) == CORE_TYPE) {
86 core_level_siblings = LEVEL_MAX_SIBLINGS(ebx);
87 core_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
92 } while (LEAFB_SUBTYPE(ecx) != INVALID_TYPE);
94 core_select_mask = (~(-1 << core_plus_mask_width)) >> ht_mask_width;
96 c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, ht_mask_width)
98 c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, core_plus_mask_width);
100 * Reinit the apicid, now that we have extended initial_apicid.
102 c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
104 c->x86_max_cores = (core_level_siblings / smp_num_siblings);