match.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <asm/cpu_device_id.h>
  2. #include <asm/processor.h>
  3. #include <linux/cpu.h>
  4. #include <linux/module.h>
  5. /**
  6. * x86_match_cpu - match current CPU again an array of x86_cpu_ids
  7. * @match: Pointer to array of x86_cpu_ids. Last entry terminated with
  8. * {}.
  9. *
  10. * Return the entry if the current CPU matches the entries in the
  11. * passed x86_cpu_id match table. Otherwise NULL. The match table
  12. * contains vendor (X86_VENDOR_*), family, model and feature bits or
  13. * respective wildcard entries.
  14. *
  15. * A typical table entry would be to match a specific CPU
  16. * { X86_VENDOR_INTEL, 6, 0x12 }
  17. * or to match a specific CPU feature
  18. * { X86_FEATURE_MATCH(X86_FEATURE_FOOBAR) }
  19. *
  20. * Fields can be wildcarded with %X86_VENDOR_ANY, %X86_FAMILY_ANY,
  21. * %X86_MODEL_ANY, %X86_FEATURE_ANY or 0 (except for vendor)
  22. *
  23. * Arrays used to match for this should also be declared using
  24. * MODULE_DEVICE_TABLE(x86_cpu, ...)
  25. *
  26. * This always matches against the boot cpu, assuming models and features are
  27. * consistent over all CPUs.
  28. */
  29. const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)
  30. {
  31. const struct x86_cpu_id *m;
  32. struct cpuinfo_x86 *c = &boot_cpu_data;
  33. for (m = match; m->vendor | m->family | m->model | m->feature; m++) {
  34. if (m->vendor != X86_VENDOR_ANY && c->x86_vendor != m->vendor)
  35. continue;
  36. if (m->family != X86_FAMILY_ANY && c->x86 != m->family)
  37. continue;
  38. if (m->model != X86_MODEL_ANY && c->x86_model != m->model)
  39. continue;
  40. if (m->feature != X86_FEATURE_ANY && !cpu_has(c, m->feature))
  41. continue;
  42. return m;
  43. }
  44. return NULL;
  45. }
  46. EXPORT_SYMBOL(x86_match_cpu);