scattered.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Routines to identify 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. u32 sub_leaf;
  15. };
  16. enum cpuid_regs {
  17. CR_EAX = 0,
  18. CR_ECX,
  19. CR_EDX,
  20. CR_EBX
  21. };
  22. void init_scattered_cpuid_features(struct cpuinfo_x86 *c)
  23. {
  24. u32 max_level;
  25. u32 regs[4];
  26. const struct cpuid_bit *cb;
  27. static const struct cpuid_bit cpuid_bits[] = {
  28. { X86_FEATURE_INTEL_PT, CR_EBX,25, 0x00000007, 0 },
  29. { X86_FEATURE_AVX512_4VNNIW, CR_EDX, 2, 0x00000007, 0 },
  30. { X86_FEATURE_AVX512_4FMAPS, CR_EDX, 3, 0x00000007, 0 },
  31. { X86_FEATURE_APERFMPERF, CR_ECX, 0, 0x00000006, 0 },
  32. { X86_FEATURE_EPB, CR_ECX, 3, 0x00000006, 0 },
  33. { X86_FEATURE_HW_PSTATE, CR_EDX, 7, 0x80000007, 0 },
  34. { X86_FEATURE_CPB, CR_EDX, 9, 0x80000007, 0 },
  35. { X86_FEATURE_PROC_FEEDBACK, CR_EDX,11, 0x80000007, 0 },
  36. { 0, 0, 0, 0, 0 }
  37. };
  38. for (cb = cpuid_bits; cb->feature; cb++) {
  39. /* Verify that the level is valid */
  40. max_level = cpuid_eax(cb->level & 0xffff0000);
  41. if (max_level < cb->level ||
  42. max_level > (cb->level | 0xffff))
  43. continue;
  44. cpuid_count(cb->level, cb->sub_leaf, &regs[CR_EAX],
  45. &regs[CR_EBX], &regs[CR_ECX], &regs[CR_EDX]);
  46. if (regs[cb->reg] & (1 << cb->bit))
  47. set_cpu_cap(c, cb->feature);
  48. }
  49. }