scattered.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_APERFMPERF, CR_ECX, 0, 0x00000006, 0 },
  29. { X86_FEATURE_EPB, CR_ECX, 3, 0x00000006, 0 },
  30. { X86_FEATURE_HW_PSTATE, CR_EDX, 7, 0x80000007, 0 },
  31. { X86_FEATURE_CPB, CR_EDX, 9, 0x80000007, 0 },
  32. { X86_FEATURE_PROC_FEEDBACK, CR_EDX,11, 0x80000007, 0 },
  33. { 0, 0, 0, 0, 0 }
  34. };
  35. for (cb = cpuid_bits; cb->feature; cb++) {
  36. /* Verify that the level is valid */
  37. max_level = cpuid_eax(cb->level & 0xffff0000);
  38. if (max_level < cb->level ||
  39. max_level > (cb->level | 0xffff))
  40. continue;
  41. cpuid_count(cb->level, cb->sub_leaf, &regs[CR_EAX],
  42. &regs[CR_EBX], &regs[CR_ECX], &regs[CR_EDX]);
  43. if (regs[cb->reg] & (1 << cb->bit))
  44. set_cpu_cap(c, cb->feature);
  45. }
  46. }