|
@@ -40,6 +40,7 @@
|
|
|
#include <linux/notifier.h>
|
|
|
#include <linux/uaccess.h>
|
|
|
#include <linux/gfp.h>
|
|
|
+#include <linux/slab.h>
|
|
|
|
|
|
#include <asm/processor.h>
|
|
|
#include <asm/msr.h>
|
|
@@ -138,13 +139,57 @@ static const struct file_operations cpuid_fops = {
|
|
|
.open = cpuid_open,
|
|
|
};
|
|
|
|
|
|
+static ssize_t print_cpu_modalias(struct device *dev,
|
|
|
+ struct device_attribute *attr,
|
|
|
+ char *bufptr)
|
|
|
+{
|
|
|
+ int size = PAGE_SIZE;
|
|
|
+ int i, n;
|
|
|
+ char *buf = bufptr;
|
|
|
+
|
|
|
+ n = snprintf(buf, size, "x86cpu:vendor:%04X:family:"
|
|
|
+ "%04X:model:%04X:feature:",
|
|
|
+ boot_cpu_data.x86_vendor,
|
|
|
+ boot_cpu_data.x86,
|
|
|
+ boot_cpu_data.x86_model);
|
|
|
+ size -= n;
|
|
|
+ buf += n;
|
|
|
+ size -= 2;
|
|
|
+ for (i = 0; i < NCAPINTS*32; i++) {
|
|
|
+ if (boot_cpu_has(i)) {
|
|
|
+ n = snprintf(buf, size, ",%04X", i);
|
|
|
+ if (n < 0) {
|
|
|
+ WARN(1, "x86 features overflow page\n");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ size -= n;
|
|
|
+ buf += n;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ *buf++ = ',';
|
|
|
+ *buf++ = '\n';
|
|
|
+ return buf - bufptr;
|
|
|
+}
|
|
|
+
|
|
|
+static DEVICE_ATTR(modalias, 0444, print_cpu_modalias, NULL);
|
|
|
+
|
|
|
static __cpuinit int cpuid_device_create(int cpu)
|
|
|
{
|
|
|
struct device *dev;
|
|
|
+ int err;
|
|
|
|
|
|
dev = device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu), NULL,
|
|
|
"cpu%d", cpu);
|
|
|
- return IS_ERR(dev) ? PTR_ERR(dev) : 0;
|
|
|
+ if (IS_ERR(dev))
|
|
|
+ return PTR_ERR(dev);
|
|
|
+
|
|
|
+ err = device_create_file(dev, &dev_attr_modalias);
|
|
|
+ if (err) {
|
|
|
+ /* keep device around on error. attribute is optional. */
|
|
|
+ err = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
static void cpuid_device_destroy(int cpu)
|
|
@@ -182,6 +227,17 @@ static char *cpuid_devnode(struct device *dev, umode_t *mode)
|
|
|
return kasprintf(GFP_KERNEL, "cpu/%u/cpuid", MINOR(dev->devt));
|
|
|
}
|
|
|
|
|
|
+static int cpuid_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
|
|
|
+{
|
|
|
+ char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
|
|
|
+ if (buf) {
|
|
|
+ print_cpu_modalias(NULL, NULL, buf);
|
|
|
+ add_uevent_var(env, "MODALIAS=%s", buf);
|
|
|
+ kfree(buf);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
static int __init cpuid_init(void)
|
|
|
{
|
|
|
int i, err = 0;
|
|
@@ -200,6 +256,7 @@ static int __init cpuid_init(void)
|
|
|
goto out_chrdev;
|
|
|
}
|
|
|
cpuid_class->devnode = cpuid_devnode;
|
|
|
+ cpuid_class->dev_uevent = cpuid_dev_uevent;
|
|
|
for_each_online_cpu(i) {
|
|
|
err = cpuid_device_create(i);
|
|
|
if (err != 0)
|