From: Matt Dainty <matt@bodgit-n-scarper.com>
To: linux-kernel <linux-kernel@vger.kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH] DevFS support for /dev/cpu/X/(cpuid|msr)
Date: Sun, 6 Jan 2002 18:17:49 +0000 [thread overview]
Message-ID: <20020106181749.A714@butterlicious.bodgit-n-scarper.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 499 bytes --]
Hi,
Please find attached a patch to add support for devfs to the i386 cpuid and
msr drivers. Not only that, but it fixes a problem with loading these
drivers as modules in that the exit hooks on the module never run, (simply
changing the function prototypes to include 'static' seems to fix this).
Patch is against 2.4.17. SMP environment isn't tested, but I can't see any
reason why it wouldn't work...
Cheers
Matt
--
"Phased plasma rifle in a forty-watt range?"
"Hey, just what you see, pal"
[-- Attachment #2: patch-2.4.17-cpuid-msr-devfs.patch --]
[-- Type: text/plain, Size: 4306 bytes --]
diff -ur linux-2.4.17.orig/arch/i386/kernel/cpuid.c linux-2.4.17/arch/i386/kernel/cpuid.c
--- linux-2.4.17.orig/arch/i386/kernel/cpuid.c Sat Jan 5 19:20:08 2002
+++ linux-2.4.17/arch/i386/kernel/cpuid.c Sun Jan 6 18:09:08 2002
@@ -23,6 +23,11 @@
*
* This driver uses /dev/cpu/%d/cpuid where %d is the minor number, and on
* an SMP box will direct the access to CPU %d.
+ *
+ * ChangeLog
+ *
+ * 2002-01-06 Matt Dainty <matt@bodgit-n-scarper.com>
+ * Added support for devfs
*/
#include <linux/module.h>
@@ -35,12 +40,16 @@
#include <linux/poll.h>
#include <linux/smp.h>
#include <linux/major.h>
+#include <linux/threads.h>
+#include <linux/devfs_fs_kernel.h>
#include <asm/processor.h>
#include <asm/msr.h>
#include <asm/uaccess.h>
#include <asm/system.h>
+static devfs_handle_t devfs_handle[NR_CPUS];
+
#ifdef CONFIG_SMP
struct cpuid_command {
@@ -140,24 +149,45 @@
open: cpuid_open,
};
-int __init cpuid_init(void)
+static int __init cpuid_init(void)
{
- if (register_chrdev(CPUID_MAJOR, "cpu/cpuid", &cpuid_fops)) {
+ int i;
+ char name[16];
+
+ if (devfs_register_chrdev(CPUID_MAJOR, "cpu/%d/cpuid", &cpuid_fops)) {
printk(KERN_ERR "cpuid: unable to get major %d for cpuid\n",
CPUID_MAJOR);
return -EBUSY;
}
+ for(i = 0; i < NR_CPUS; i++) {
+ sprintf(name, "cpu/%d/cpuid", i);
+ if ((devfs_handle[i] = devfs_register(NULL, name, DEVFS_FL_DEFAULT,
+ CPUID_MAJOR, i,
+ S_IFCHR | S_IRUSR | S_IRGRP,
+ &cpuid_fops, NULL)) == NULL) {
+ printk(KERN_ERR "cpuid: failed to devfs_register()\n");
+ }
+ }
return 0;
}
-void __exit cpuid_exit(void)
+static void __exit cpuid_exit(void)
{
- unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");
+ int i;
+ devfs_handle_t parent;
+
+ for(i = 0; i < NR_CPUS; i++) {
+ parent = devfs_get_parent(devfs_handle[i]);
+ devfs_unregister(devfs_handle[i]);
+ if(devfs_get_first_child(parent) == NULL)
+ devfs_unregister(parent);
+ }
+ devfs_unregister_chrdev(CPUID_MAJOR, "cpu/%d/cpuid");
}
module_init(cpuid_init);
-module_exit(cpuid_exit)
+module_exit(cpuid_exit);
EXPORT_NO_SYMBOLS;
diff -ur linux-2.4.17.orig/arch/i386/kernel/msr.c linux-2.4.17/arch/i386/kernel/msr.c
--- linux-2.4.17.orig/arch/i386/kernel/msr.c Sat Jan 5 19:20:08 2002
+++ linux-2.4.17/arch/i386/kernel/msr.c Sun Jan 6 18:09:18 2002
@@ -22,6 +22,11 @@
*
* This driver uses /dev/cpu/%d/msr where %d is the minor number, and on
* an SMP box will direct the access to CPU %d.
+ *
+ * ChangeLog
+ *
+ * 2002-01-06 Matt Dainty <matt@bodgit-n-scarper.com>
+ * Added support for devfs
*/
#include <linux/module.h>
@@ -34,12 +39,16 @@
#include <linux/poll.h>
#include <linux/smp.h>
#include <linux/major.h>
+#include <linux/threads.h>
+#include <linux/devfs_fs_kernel.h>
#include <asm/processor.h>
#include <asm/msr.h>
#include <asm/uaccess.h>
#include <asm/system.h>
+static devfs_handle_t devfs_handle[NR_CPUS];
+
/* Note: "err" is handled in a funny way below. Otherwise one version
of gcc or another breaks. */
@@ -248,24 +257,45 @@
open: msr_open,
};
-int __init msr_init(void)
+static int __init msr_init(void)
{
- if (register_chrdev(MSR_MAJOR, "cpu/msr", &msr_fops)) {
+ int i;
+ char name[16];
+
+ if (devfs_register_chrdev(MSR_MAJOR, "cpu/%d/msr", &msr_fops)) {
printk(KERN_ERR "msr: unable to get major %d for msr\n",
MSR_MAJOR);
return -EBUSY;
}
+ for(i = 0; i < NR_CPUS; i++) {
+ sprintf(name, "cpu/%d/msr", i);
+ if ((devfs_handle[i] = devfs_register(NULL, name, DEVFS_FL_DEFAULT,
+ MSR_MAJOR, i,
+ S_IFCHR | S_IRUSR | S_IRGRP | S_IWUSR,
+ &msr_fops, NULL)) == NULL) {
+ printk(KERN_ERR "msr: failed to devfs_register()\n");
+ }
+ }
return 0;
}
-void __exit msr_exit(void)
+static void __exit msr_exit(void)
{
- unregister_chrdev(MSR_MAJOR, "cpu/msr");
+ int i;
+ devfs_handle_t parent;
+
+ for(i = 0; i < NR_CPUS; i++) {
+ parent = devfs_get_parent(devfs_handle[i]);
+ devfs_unregister(devfs_handle[i]);
+ if(devfs_get_first_child(parent) == NULL)
+ devfs_unregister(parent);
+ }
+ devfs_unregister_chrdev(MSR_MAJOR, "cpu/%d/msr");
}
module_init(msr_init);
-module_exit(msr_exit)
+module_exit(msr_exit);
EXPORT_NO_SYMBOLS;
next prev reply other threads:[~2002-01-06 18:19 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-08 11:13 Matt Dainty
2002-01-06 18:17 ` Matt Dainty [this message]
2002-01-06 19:34 ` Richard Gooch
2002-01-06 20:43 ` Matt Dainty
2002-01-06 21:08 ` H. Peter Anvin
2002-01-06 21:11 ` Richard Gooch
2002-01-06 21:12 ` H. Peter Anvin
2002-01-06 21:06 ` H. Peter Anvin
2002-01-06 21:08 ` Richard Gooch
2002-01-06 21:10 ` H. Peter Anvin
2002-01-06 21:36 ` Russell King
2002-01-07 0:44 ` H. Peter Anvin
2002-01-07 1:31 ` Richard Gooch
2002-01-07 1:32 ` H. Peter Anvin
2002-01-07 1:40 ` Richard Gooch
2002-01-07 1:44 ` H. Peter Anvin
2002-01-08 9:14 ` Rusty Russell
2002-01-08 12:02 ` Matt Dainty
2002-01-08 17:17 ` H. Peter Anvin
2002-01-08 17:35 ` Richard Gooch
2002-01-09 1:01 ` Rusty Russell
2002-01-09 3:16 ` H. Peter Anvin
2002-01-09 3:28 ` Rusty Russell
2002-01-09 3:30 ` Richard Gooch
2002-01-09 3:47 ` H. Peter Anvin
2002-01-09 5:41 ` Richard Gooch
2002-02-18 10:50 Ishan Jayawardena
2002-02-18 18:25 ` Richard Gooch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020106181749.A714@butterlicious.bodgit-n-scarper.com \
--to=matt@bodgit-n-scarper.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome