match.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include <asm/cpu_device_id.h>
  2. #include <asm/processor.h>
  3. #include <linux/cpu.h>
  4. #include <linux/module.h>
  5. #include <linux/slab.h>
  6. /**
  7. * x86_match_cpu - match current CPU again an array of x86_cpu_ids
  8. * @match: Pointer to array of x86_cpu_ids. Last entry terminated with
  9. * {}.
  10. *
  11. * Return the entry if the current CPU matches the entries in the
  12. * passed x86_cpu_id match table. Otherwise NULL. The match table
  13. * contains vendor (X86_VENDOR_*), family, model and feature bits or
  14. * respective wildcard entries.
  15. *
  16. * A typical table entry would be to match a specific CPU
  17. * { X86_VENDOR_INTEL, 6, 0x12 }
  18. * or to match a specific CPU feature
  19. * { X86_FEATURE_MATCH(X86_FEATURE_FOOBAR) }
  20. *
  21. * Fields can be wildcarded with %X86_VENDOR_ANY, %X86_FAMILY_ANY,
  22. * %X86_MODEL_ANY, %X86_FEATURE_ANY or 0 (except for vendor)
  23. *
  24. * Arrays used to match for this should also be declared using
  25. * MODULE_DEVICE_TABLE(x86_cpu, ...)
  26. *
  27. * This always matches against the boot cpu, assuming models and features are
  28. * consistent over all CPUs.
  29. */
  30. const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)
  31. {
  32. const struct x86_cpu_id *m;
  33. struct cpuinfo_x86 *c = &boot_cpu_data;
  34. for (m = match; m->vendor | m->family | m->model | m->feature; m++) {
  35. if (m->vendor != X86_VENDOR_ANY && c->x86_vendor != m->vendor)
  36. continue;
  37. if (m->family != X86_FAMILY_ANY && c->x86 != m->family)
  38. continue;
  39. if (m->model != X86_MODEL_ANY && c->x86_model != m->model)
  40. continue;
  41. if (m->feature != X86_FEATURE_ANY && !cpu_has(c, m->feature))
  42. continue;
  43. return m;
  44. }
  45. return NULL;
  46. }
  47. EXPORT_SYMBOL(x86_match_cpu);
  48. ssize_t arch_print_cpu_modalias(struct device *dev,
  49. struct device_attribute *attr,
  50. char *bufptr)
  51. {
  52. int size = PAGE_SIZE;
  53. int i, n;
  54. char *buf = bufptr;
  55. n = snprintf(buf, size, "x86cpu:vendor:%04X:family:%04X:"
  56. "model:%04X:feature:",
  57. boot_cpu_data.x86_vendor,
  58. boot_cpu_data.x86,
  59. boot_cpu_data.x86_model);
  60. size -= n;
  61. buf += n;
  62. size -= 1;
  63. for (i = 0; i < NCAPINTS*32; i++) {
  64. if (boot_cpu_has(i)) {
  65. n = snprintf(buf, size, ",%04X", i);
  66. if (n >= size) {
  67. WARN(1, "x86 features overflow page\n");
  68. break;
  69. }
  70. size -= n;
  71. buf += n;
  72. }
  73. }
  74. *buf++ = '\n';
  75. return buf - bufptr;
  76. }
  77. int arch_cpu_uevent(struct device *dev, struct kobj_uevent_env *env)
  78. {
  79. char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
  80. if (buf) {
  81. arch_print_cpu_modalias(NULL, NULL, buf);
  82. add_uevent_var(env, "MODALIAS=%s", buf);
  83. kfree(buf);
  84. }
  85. return 0;
  86. }