Commit cca24737 authored by Hanna V. Linder's avatar Hanna V. Linder Committed by Greg Kroah-Hartman

[PATCH] Add class support to cpuid.c

This patch adds class support to arch/i386/kernel/cpuid.c. This enables udev
support. I have tested on a 2-way SMP system and on a 2-way built as UP.
Here are the results for the SMP:

[hlinder@w-hlinder2 hlinder]$ tree /sys/class/cpuid
/sys/class/cpuid
|-- cpu0
|   `-- dev
`-- cpu1
    `-- dev

2 directories, 2 files
[hlinder@w-hlinder2 hlinder]$ more /sys/class/cpuid/cpu0/dev
203:0
[hlinder@w-hlinder2 hlinder]$ more /sys/class/cpuid/cpu1/dev
203:1
[hlinder@w-hlinder2 hlinder]$

And for the UP:

[root@w-hlinder2 root]# tree /sys/class/cpuid
/sys/class/cpuid
`-- cpu0
    `-- dev

1 directory, 1 file
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent c5819000
......@@ -36,12 +36,15 @@
#include <linux/fs.h>
#include <linux/smp_lock.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <asm/processor.h>
#include <asm/msr.h>
#include <asm/uaccess.h>
#include <asm/system.h>
static struct class_simple *cpuid_class;
#ifdef CONFIG_SMP
struct cpuid_command {
......@@ -155,17 +158,48 @@ static struct file_operations cpuid_fops = {
int __init cpuid_init(void)
{
int i, err = 0;
struct class_device *class_err;
i = 0;
if (register_chrdev(CPUID_MAJOR, "cpu/cpuid", &cpuid_fops)) {
printk(KERN_ERR "cpuid: unable to get major %d for cpuid\n",
CPUID_MAJOR);
return -EBUSY;
err = -EBUSY;
goto out;
}
return 0;
cpuid_class = class_simple_create(THIS_MODULE, "cpuid");
if (IS_ERR(cpuid_class)) {
err = PTR_ERR(cpuid_class);
goto out_chrdev;
}
for_each_online_cpu(i) {
class_err = class_simple_device_add(cpuid_class, MKDEV(CPUID_MAJOR, i), NULL, "cpu%d",i);
if (IS_ERR(class_err)) {
err = PTR_ERR(class_err);
goto out_class;
}
}
err = 0;
goto out;
out_class:
i = 0;
for_each_online_cpu(i)
class_simple_device_remove(MKDEV(CPUID_MAJOR, i));
class_simple_destroy(cpuid_class);
out_chrdev:
unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");
out:
return err;
}
void __exit cpuid_exit(void)
{
int i = 0;
for_each_online_cpu(i)
class_simple_device_remove(MKDEV(CPUID_MAJOR, i));
class_simple_destroy(cpuid_class);
unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment