summaryrefslogtreecommitdiff
blob: 05c49ca67898aef24e5d11d0477cc61ae5f83f1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
--- kqemu/kmod.c	2005-02-10 23:09:09.000000000 +0100
+++ kqemu/kmod-sysfs.c	2005-02-22 19:46:44.000000000 +0100
@@ -15,7 +15,10 @@
 #include <asm/processor.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
-
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
+#include <linux/device.h>
+#endif
+#include <linux/devfs_fs_kernel.h>
 #include "kqemu.h"
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19)
@@ -34,6 +37,10 @@
 int page_alloc_count;
 #endif
 
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
+static struct class_simple *kqemu_class;
+#endif
+
 /* 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)
@@ -296,17 +303,51 @@
         max_locked_pages = 32768;
 
     ret = register_chrdev(KQEMU_MAJOR, "kqemu", &kqemu_fops);
+
     if (ret < 0) {
         printk("kqemu: could not get major %d\n", KQEMU_MAJOR);
         return ret;
     }
+
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
+    kqemu_class = class_simple_create(THIS_MODULE, "kqemu");
+
+    if (IS_ERR(kqemu_class)) {
+	unregister_chrdev(KQEMU_MAJOR, "kqemu");
+	ret = PTR_ERR(kqemu_class);
+	goto out_chrdev;
+    }
+    
+    class_simple_device_add(kqemu_class, MKDEV(KQEMU_MAJOR, 0), NULL, "kqemu");
+#endif
+
+    ret = devfs_mk_cdev(MKDEV(KQEMU_MAJOR, 0),
+			S_IFCHR|S_IRUSR|S_IWUSR, "kqemu");
+    if (ret)
+	    goto out_class;
+    
     printk("KQEMU installed, max_instances=%d max_locked_mem=%dkB.\n",
            KQEMU_MAX_INSTANCES, 
            max_locked_pages * 4);
     return 0;
+
+out_class:
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
+    class_simple_device_remove(MKDEV(KQEMU_MAJOR,0));
+    class_simple_destroy(kqemu_class);
+#endif
+out_chrdev:
+    unregister_chrdev(KQEMU_MAJOR, "kqemu");
+    
+    return ret;
 }
 
 void cleanup_module(void)
 {
     unregister_chrdev(KQEMU_MAJOR, "kqemu");
+    devfs_remove("kqemu");
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
+    class_simple_device_remove(MKDEV(KQEMU_MAJOR, 0));
+    class_simple_destroy(kqemu_class);
+#endif
 }