public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2.6.7-rc3] Add's class support to msr.c
@ 2004-06-09 23:23 Hanna Linder
  2004-06-09 23:40 ` Hanna Linder
  0 siblings, 1 reply; 3+ messages in thread
From: Hanna Linder @ 2004-06-09 23:23 UTC (permalink / raw)
  To: linux-kernel; +Cc: hannal, greg, hpa


This patch enables class support in arch/i386/kernel/msr.c. Very simliar
to cpuid (with the fixes Zwane/Greg made, thanks). 

[root@w-hlinder2 root]# tree /sys/class/msr
/sys/class/msr
|-- msr0
|   `-- dev
`-- msr1
    `-- dev

2 directories, 2 files

Please consider for testing/inclusion.

Signed-off-by Hanna Linder <hannal@us.ibm.com>

Thanks.

Hanna Linder
IBM Linux Technology Center
-----------
diff -Nrup linux-2.6.7-rc3/arch/i386/kernel/msr.c linux-2.6.7-rc3p/arch/i386/kernel/msr.c
--- linux-2.6.7-rc3/arch/i386/kernel/msr.c	2004-06-08 16:49:29.000000000 -0700
+++ linux-2.6.7-rc3p/arch/i386/kernel/msr.c	2004-06-09 15:26:31.000000000 -0700
@@ -35,12 +35,17 @@
 #include <linux/smp_lock.h>
 #include <linux/major.h>
 #include <linux/fs.h>
+#include <linux/device.h>
+#include <linux/cpu.h>
+#include <linux/notifier.h>
 
 #include <asm/processor.h>
 #include <asm/msr.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
 
+static struct class_simple *msr_class;
+
 /* Note: "err" is handled in a funny way below.  Otherwise one version
    of gcc or another breaks. */
 
@@ -255,20 +260,82 @@ static struct file_operations msr_fops =
 	.open = msr_open,
 };
 
+static int msr_class_simple_device_add(int i)
+{
+	int err = 0;
+	struct class_device *class_err;
+
+	class_err = class_simple_device_add(msr_class, MKDEV(MSR_MAJOR, i), NULL, "msr%d",i);
+	if (IS_ERR(class_err)) 
+		err = PTR_ERR(class_err);
+	return err;
+}
+
+static int __devinit msr_class_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
+{
+	unsigned int cpu = (unsigned long)hcpu;
+
+	switch (action) {
+	case CPU_ONLINE:
+		msr_class_simple_device_add(cpu);
+		break;
+	case CPU_DEAD:
+		class_simple_device_remove(MKDEV(MSR_MAJOR, cpu));	
+		break;
+	}
+	return NOTIFY_OK;
+}
+
+static struct notifier_block msr_class_cpu_notifier =
+{
+	.notifier_call = msr_class_cpu_callback,
+};
+
 int __init msr_init(void)
 {
+	int i, err = 0;
+	i = 0;
+
 	if (register_chrdev(MSR_MAJOR, "cpu/msr", &msr_fops)) {
 		printk(KERN_ERR "msr: unable to get major %d for msr\n",
 		       MSR_MAJOR);
-		return -EBUSY;
+		err = -EBUSY;
+		goto out;
+	}
+	msr_class = class_simple_create(THIS_MODULE, "msr");
+	if (IS_ERR(msr_class)) {
+		err = PTR_ERR(msr_class);
+		goto out_chrdev;
+	}
+	for_each_online_cpu(i) {
+		err = msr_class_simple_device_add(i);
+		if (err != 0)
+			goto out_class;
 	}
+	register_cpu_notifier(&msr_class_cpu_notifier);
 
-	return 0;
+	err = 0;
+	goto out;
+
+	out_class:
+		i = 0;
+		for_each_online_cpu(i)
+			class_simple_device_remove(MKDEV(MSR_MAJOR, i));
+		class_simple_destroy(msr_class);
+	out_chrdev:
+		unregister_chrdev(MSR_MAJOR, "cpu/msr");
+	out:
+		return err;
 }
 
 void __exit msr_exit(void)
 {
+	int cpu = 0;
+	for_each_online_cpu(cpu)
+		class_simple_device_remove(MKDEV(MSR_MAJOR, cpu));
+	class_simple_destroy(msr_class);
 	unregister_chrdev(MSR_MAJOR, "cpu/msr");
+	unregister_cpu_notifier(&msr_class_cpu_notifier);
 }
 
 module_init(msr_init);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2.6.7-rc3] Add's class support to msr.c
  2004-06-09 23:23 [PATCH 2.6.7-rc3] Add's class support to msr.c Hanna Linder
@ 2004-06-09 23:40 ` Hanna Linder
  2004-06-12  0:18   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Hanna Linder @ 2004-06-09 23:40 UTC (permalink / raw)
  To: linux-kernel; +Cc: Hanna Linder, greg, hpa

--On Wednesday, June 09, 2004 04:23:11 PM -0700 Hanna Linder <hannal@us.ibm.com> wrote:
> 
> This patch enables class support in arch/i386/kernel/msr.c. Very simliar
> to cpuid (with the fixes Zwane/Greg made, thanks). 
> 
> [root@w-hlinder2 root]# tree /sys/class/msr
> /sys/class/msr
>| -- msr0
>|   `-- dev
> `-- msr1
>     `-- dev
> 
> 2 directories, 2 files
> 
> Please consider for testing/inclusion.
> 
> Signed-off-by Hanna Linder <hannal@us.ibm.com>
> 
> Thanks.
> 
> Hanna Linder
> IBM Linux Technology Center

Thanks to Randy Dunlap for pointing out the unnecessary tabs. Fixed.

------
diff -Nrup linux-2.6.7-rc3/arch/i386/kernel/msr.c linux-2.6.7-rc3p/arch/i386/kernel/msr.c
--- linux-2.6.7-rc3/arch/i386/kernel/msr.c	2004-06-08 16:49:29.000000000 -0700
+++ linux-2.6.7-rc3p/arch/i386/kernel/msr.c	2004-06-09 16:33:29.000000000 -0700
@@ -35,12 +35,17 @@
 #include <linux/smp_lock.h>
 #include <linux/major.h>
 #include <linux/fs.h>
+#include <linux/device.h>
+#include <linux/cpu.h>
+#include <linux/notifier.h>
 
 #include <asm/processor.h>
 #include <asm/msr.h>
 #include <asm/uaccess.h>
 #include <asm/system.h>
 
+static struct class_simple *msr_class;
+
 /* Note: "err" is handled in a funny way below.  Otherwise one version
    of gcc or another breaks. */
 
@@ -255,20 +260,82 @@ static struct file_operations msr_fops =
 	.open = msr_open,
 };
 
+static int msr_class_simple_device_add(int i)
+{
+	int err = 0;
+	struct class_device *class_err;
+
+	class_err = class_simple_device_add(msr_class, MKDEV(MSR_MAJOR, i), NULL, "msr%d",i);
+	if (IS_ERR(class_err)) 
+		err = PTR_ERR(class_err);
+	return err;
+}
+
+static int __devinit msr_class_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
+{
+	unsigned int cpu = (unsigned long)hcpu;
+
+	switch (action) {
+	case CPU_ONLINE:
+		msr_class_simple_device_add(cpu);
+		break;
+	case CPU_DEAD:
+		class_simple_device_remove(MKDEV(MSR_MAJOR, cpu));	
+		break;
+	}
+	return NOTIFY_OK;
+}
+
+static struct notifier_block msr_class_cpu_notifier =
+{
+	.notifier_call = msr_class_cpu_callback,
+};
+
 int __init msr_init(void)
 {
+	int i, err = 0;
+	i = 0;
+
 	if (register_chrdev(MSR_MAJOR, "cpu/msr", &msr_fops)) {
 		printk(KERN_ERR "msr: unable to get major %d for msr\n",
 		       MSR_MAJOR);
-		return -EBUSY;
+		err = -EBUSY;
+		goto out;
+	}
+	msr_class = class_simple_create(THIS_MODULE, "msr");
+	if (IS_ERR(msr_class)) {
+		err = PTR_ERR(msr_class);
+		goto out_chrdev;
 	}
+	for_each_online_cpu(i) {
+		err = msr_class_simple_device_add(i);
+		if (err != 0)
+			goto out_class;
+	}
+	register_cpu_notifier(&msr_class_cpu_notifier);
 
-	return 0;
+	err = 0;
+	goto out;
+
+out_class:
+	i = 0;
+	for_each_online_cpu(i)
+		class_simple_device_remove(MKDEV(MSR_MAJOR, i));
+	class_simple_destroy(msr_class);
+out_chrdev:
+	unregister_chrdev(MSR_MAJOR, "cpu/msr");
+out:
+	return err;
 }
 
 void __exit msr_exit(void)
 {
+	int cpu = 0;
+	for_each_online_cpu(cpu)
+		class_simple_device_remove(MKDEV(MSR_MAJOR, cpu));
+	class_simple_destroy(msr_class);
 	unregister_chrdev(MSR_MAJOR, "cpu/msr");
+	unregister_cpu_notifier(&msr_class_cpu_notifier);
 }
 
 module_init(msr_init);




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2.6.7-rc3] Add's class support to msr.c
  2004-06-09 23:40 ` Hanna Linder
@ 2004-06-12  0:18   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2004-06-12  0:18 UTC (permalink / raw)
  To: Hanna Linder; +Cc: linux-kernel, hpa

On Wed, Jun 09, 2004 at 04:40:37PM -0700, Hanna Linder wrote:
> --On Wednesday, June 09, 2004 04:23:11 PM -0700 Hanna Linder <hannal@us.ibm.com> wrote:
> > 
> > This patch enables class support in arch/i386/kernel/msr.c. Very simliar
> > to cpuid (with the fixes Zwane/Greg made, thanks). 
> > 
> > [root@w-hlinder2 root]# tree /sys/class/msr
> > /sys/class/msr
> >| -- msr0
> >|   `-- dev
> > `-- msr1
> >     `-- dev
> > 
> > 2 directories, 2 files
> > 
> > Please consider for testing/inclusion.
> > 
> > Signed-off-by Hanna Linder <hannal@us.ibm.com>
> > 
> > Thanks.
> > 
> > Hanna Linder
> > IBM Linux Technology Center
> 
> Thanks to Randy Dunlap for pointing out the unnecessary tabs. Fixed.

Looks good, applied thanks.

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-06-12  0:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-09 23:23 [PATCH 2.6.7-rc3] Add's class support to msr.c Hanna Linder
2004-06-09 23:40 ` Hanna Linder
2004-06-12  0:18   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox