qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] sysfs patch for kqemu
@ 2005-02-14  1:24 Matthew Mastracci
  2005-02-14  3:16 ` [Qemu-devel] Re: sysfs patch for kqemu - take 2 Matthew Mastracci
  0 siblings, 1 reply; 2+ messages in thread
From: Matthew Mastracci @ 2005-02-14  1:24 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 367 bytes --]

Here's a patch for supporting sysfs and udev.  There's no conditional 
logic - it needs the sysfs stuff to be present in the kernel headers. 
It dynamically allocates a major number and stuffs it into a global 
variable and uses that to register a device with sysfs.  udev will then 
pick up the new device and automatically create a new "kqemu" device node.

Matt.


[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 1390 bytes --]

--- kqemu/kmod.c	2005-02-10 15:09:09.000000000 -0700
+++ qemu/kqemu/kmod.c	2005-02-13 18:19:14.833684304 -0700
@@ -11,6 +11,7 @@
 #include <linux/version.h>
 #include <linux/ioctl.h>
 #include <linux/smp_lock.h>
+#include <linux/device.h>
 #include <asm/atomic.h>
 #include <asm/processor.h>
 #include <asm/uaccess.h>
@@ -34,6 +35,9 @@
 int page_alloc_count;
 #endif
 
+struct class_simple *kqemu_class;
+int kqemu_major;
+
 /* lock the page at virtual address 'user_addr' and return its
    page index. Return -1 if error */
 unsigned long CDECL kqemu_lock_user_page(unsigned long user_addr)
@@ -297,9 +301,12 @@
 
     ret = register_chrdev(KQEMU_MAJOR, "kqemu", &kqemu_fops);
     if (ret < 0) {
-        printk("kqemu: could not get major %d\n", KQEMU_MAJOR);
+        printk("kqemu: could not get major\n");
         return ret;
     }
+    kqemu_major = ret;
+    kqemu_class = class_simple_create(THIS_MODULE, "kqemu");
+    class_simple_device_add(kqemu_class, MKDEV(kqemu_major,0), NULL, "kqemu");
     printk("KQEMU installed, max_instances=%d max_locked_mem=%dkB.\n",
            KQEMU_MAX_INSTANCES, 
            max_locked_pages * 4);
@@ -308,5 +315,7 @@
 
 void cleanup_module(void)
 {
-    unregister_chrdev(KQEMU_MAJOR, "kqemu");
+    class_simple_device_remove(MKDEV(kqemu_major,0));
+    class_simple_destroy(kqemu_class);
+    unregister_chrdev(kqemu_major, "kqemu");
 }

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

* [Qemu-devel] Re: sysfs patch for kqemu - take 2
  2005-02-14  1:24 [Qemu-devel] sysfs patch for kqemu Matthew Mastracci
@ 2005-02-14  3:16 ` Matthew Mastracci
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Mastracci @ 2005-02-14  3:16 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 813 bytes --]

This new patch is the same as the previous patch, but adds a module 
parameter "major" to specify the major number (0 for automatic 
allocation which is the default).

For instance, to use dynamic major number allocation:
insmod kqemu.ko

To use the major number 12:
insmod kqemu.ko major=12

I hereby place this patch in the public domain, suitable for inclusion 
in any GPL'd or non-GPL'd project.

Matt.

Matthew Mastracci wrote:
> Here's a patch for supporting sysfs and udev.  There's no conditional 
> logic - it needs the sysfs stuff to be present in the kernel headers. It 
> dynamically allocates a major number and stuffs it into a global 
> variable and uses that to register a device with sysfs.  udev will then 
> pick up the new device and automatically create a new "kqemu" device node.
> 
> Matt.

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 2237 bytes --]

--- kqemu/kqemu.h	2005-02-12 07:37:04.000000000 -0700
+++ qemu/kqemu/kqemu.h	2005-02-13 19:06:12.000000000 -0700
@@ -1,8 +1,6 @@
 #ifndef KQEMU_H
 #define KQEMU_H
 
-#define KQEMU_MAJOR 250
-
 #define KQEMU_VERSION 0x010000
 
 struct kqemu_segment_cache {
--- kqemu/kmod.c	2005-02-10 15:09:09.000000000 -0700
+++ qemu/kqemu/kmod.c	2005-02-13 20:03:52.000000000 -0700
@@ -11,6 +11,7 @@
 #include <linux/version.h>
 #include <linux/ioctl.h>
 #include <linux/smp_lock.h>
+#include <linux/device.h>
 #include <asm/atomic.h>
 #include <asm/processor.h>
 #include <asm/uaccess.h>
@@ -34,6 +35,13 @@
 int page_alloc_count;
 #endif
 
+struct class_simple *kqemu_class;
+static int major = 0;
+int kqemu_major;
+
+MODULE_PARM(major, "i");
+MODULE_PARM_DESC(major, "Major device number (1-255 or 0 for autodetect)");
+
 /* lock the page at virtual address 'user_addr' and return its
    page index. Return -1 if error */
 unsigned long CDECL kqemu_lock_user_page(unsigned long user_addr)
@@ -295,18 +303,33 @@
     if (max_locked_pages > 32768)
         max_locked_pages = 32768;
 
-    ret = register_chrdev(KQEMU_MAJOR, "kqemu", &kqemu_fops);
+    ret = register_chrdev(major, "kqemu", &kqemu_fops);
     if (ret < 0) {
-        printk("kqemu: could not get major %d\n", KQEMU_MAJOR);
+        if (major == 0)
+            printk("kqemu: could not get dynamic major\n");
+        else
+            printk("kqemu: could not get requested major %d\n", major);
+
         return ret;
     }
-    printk("KQEMU installed, max_instances=%d max_locked_mem=%dkB.\n",
+
+    if (major == 0)
+        kqemu_major = ret;
+    else
+        kqemu_major = major;
+
+    kqemu_class = class_simple_create(THIS_MODULE, "kqemu");
+    class_simple_device_add(kqemu_class, MKDEV(kqemu_major,0), NULL, "kqemu");
+    printk("KQEMU installed, max_instances=%d max_locked_mem=%dkB major=%d.\n",
            KQEMU_MAX_INSTANCES, 
-           max_locked_pages * 4);
+           max_locked_pages * 4,
+           kqemu_major);
     return 0;
 }
 
 void cleanup_module(void)
 {
-    unregister_chrdev(KQEMU_MAJOR, "kqemu");
+    class_simple_device_remove(MKDEV(kqemu_major,0));
+    class_simple_destroy(kqemu_class);
+    unregister_chrdev(kqemu_major, "kqemu");
 }

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

end of thread, other threads:[~2005-02-14  3:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-14  1:24 [Qemu-devel] sysfs patch for kqemu Matthew Mastracci
2005-02-14  3:16 ` [Qemu-devel] Re: sysfs patch for kqemu - take 2 Matthew Mastracci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).