addon_cpuid_features.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Routines to indentify additional cpu features that are scattered in
  3. * cpuid space.
  4. */
  5. #include <linux/cpu.h>
  6. #include <asm/pat.h>
  7. #include <asm/processor.h>
  8. #include <asm/apic.h>
  9. struct cpuid_bit {
  10. u16 feature;
  11. u8 reg;
  12. u8 bit;
  13. u32 level;
  14. };
  15. enum cpuid_regs {
  16. CR_EAX = 0,
  17. CR_ECX,
  18. CR_EDX,
  19. CR_EBX
  20. };
  21. void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c)
  22. {
  23. u32 max_level;
  24. u32 regs[4];
  25. const struct cpuid_bit *cb;
  26. static const struct cpuid_bit __cpuinitconst cpuid_bits[] = {
  27. { X86_FEATURE_IDA, CR_EAX, 1, 0x00000006 },
  28. { X86_FEATURE_ARAT, CR_EAX, 2, 0x00000006 },
  29. { 0, 0, 0, 0 }
  30. };
  31. for (cb = cpuid_bits; cb->feature; cb++) {
  32. /* Verify that the level is valid */
  33. max_level = cpuid_eax(cb->level & 0xffff0000);
  34. if (max_level < cb->level ||
  35. max_level > (cb->level | 0xffff))
  36. continue;
  37. cpuid(cb->level, &regs[CR_EAX], &regs[CR_EBX],
  38. &regs[CR_ECX], &regs[CR_EDX]);
  39. if (regs[cb->reg] & (1 << cb->bit))
  40. set_cpu_cap(c, cb->feature);
  41. }
  42. }
  43. /* leaf 0xb SMT level */
  44. #define SMT_LEVEL 0
  45. /* leaf 0xb sub-leaf types */
  46. #define INVALID_TYPE 0
  47. #define SMT_TYPE 1
  48. #define CORE_TYPE 2
  49. #define LEAFB_SUBTYPE(ecx) (((ecx) >> 8) & 0xff)
  50. #define BITS_SHIFT_NEXT_LEVEL(eax) ((eax) & 0x1f)
  51. #define LEVEL_MAX_SIBLINGS(ebx) ((ebx) & 0xffff)
  52. /*
  53. * Check for extended topology enumeration cpuid leaf 0xb and if it
  54. * exists, use it for populating initial_apicid and cpu topology
  55. * detection.
  56. */
  57. void __cpuinit detect_extended_topology(struct cpuinfo_x86 *c)
  58. {
  59. #ifdef CONFIG_SMP
  60. unsigned int eax, ebx, ecx, edx, sub_index;
  61. unsigned int ht_mask_width, core_plus_mask_width;
  62. unsigned int core_select_mask, core_level_siblings;
  63. if (c->cpuid_level < 0xb)
  64. return;
  65. cpuid_count(0xb, SMT_LEVEL, &eax, &ebx, &ecx, &edx);
  66. /*
  67. * check if the cpuid leaf 0xb is actually implemented.
  68. */
  69. if (ebx == 0 || (LEAFB_SUBTYPE(ecx) != SMT_TYPE))
  70. return;
  71. set_cpu_cap(c, X86_FEATURE_XTOPOLOGY);
  72. /*
  73. * initial apic id, which also represents 32-bit extended x2apic id.
  74. */
  75. c->initial_apicid = edx;
  76. /*
  77. * Populate HT related information from sub-leaf level 0.
  78. */
  79. core_level_siblings = smp_num_siblings = LEVEL_MAX_SIBLINGS(ebx);
  80. core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
  81. sub_index = 1;
  82. do {
  83. cpuid_count(0xb, sub_index, &eax, &ebx, &ecx, &edx);
  84. /*
  85. * Check for the Core type in the implemented sub leaves.
  86. */
  87. if (LEAFB_SUBTYPE(ecx) == CORE_TYPE) {
  88. core_level_siblings = LEVEL_MAX_SIBLINGS(ebx);
  89. core_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
  90. break;
  91. }
  92. sub_index++;
  93. } while (LEAFB_SUBTYPE(ecx) != INVALID_TYPE);
  94. core_select_mask = (~(-1 << core_plus_mask_width)) >> ht_mask_width;
  95. c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, ht_mask_width)
  96. & core_select_mask;
  97. c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, core_plus_mask_width);
  98. /*
  99. * Reinit the apicid, now that we have extended initial_apicid.
  100. */
  101. c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
  102. c->x86_max_cores = (core_level_siblings / smp_num_siblings);
  103. printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
  104. c->phys_proc_id);
  105. if (c->x86_max_cores > 1)
  106. printk(KERN_INFO "CPU: Processor Core ID: %d\n",
  107. c->cpu_core_id);
  108. return;
  109. #endif
  110. }