summaryrefslogtreecommitdiff
blob: 335d6409630d83c05c2b838b211ad134fd4712e2 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
diff -urpN svgalib-1.9.18/kernel/svgalib_helper/Makefile svgalib-1.9.18.new/kernel/svgalib_helper/Makefile
--- svgalib-1.9.18/kernel/svgalib_helper/Makefile	2004-02-23 00:47:43.616320424 +0200
+++ svgalib-1.9.18.new/kernel/svgalib_helper/Makefile	2004-02-23 00:47:58.475061552 +0200
@@ -13,15 +13,32 @@ EXTRA_CFLAGS := -DSVGALIB_HELPER_MAJOR=$
 
 ifeq ($(PATCHLEVEL),4)
   include $(TOPDIR)/Rules.make
+  OBJEXT := o
+else
+  OBJEXT := ko
 endif
 
 else
 
-VER    = $(shell uname -r)
+# Extract version number from headers.
+VER = $(shell awk -F\" '/REL/ {print $$2}' $(INCLUDEDIR)/linux/version.h 2>/dev/null)
+
+# Use version of current running kernel
+ifeq ($(VER),)
+  VER = $(shell uname -r)
+endif
+
+PATCHLEVEL := $(shell echo $(VER) | cut -d. -f2)
 KDIR	:= /lib/modules/$(VER)/build
 PWD	:= $(shell pwd)
 TARGET  := svgalib_helper
 
+ifeq ($(PATCHLEVEL),4)
+  OBJEXT := o
+else
+  OBJEXT := ko
+endif
+
 default:
 	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
 
@@ -49,4 +66,4 @@ install: modules_install
 
 modules_install: $(TARGET).o
 	mkdir -p $(TOPDIR)/lib/modules/$(VER)/kernel/misc
-	install -m 0644 -c $(TARGET).o $(TOPDIR)/lib/modules/$(VER)/kernel/misc
+	install -m 0644 -c $(TARGET).$(OBJEXT) $(TOPDIR)/lib/modules/$(VER)/kernel/misc
diff -urpN svgalib-1.9.18/kernel/svgalib_helper/kernel26compat.h svgalib-1.9.18.new/kernel/svgalib_helper/kernel26compat.h
--- svgalib-1.9.18/kernel/svgalib_helper/kernel26compat.h	2003-10-04 15:42:01.000000000 +0200
+++ svgalib-1.9.18.new/kernel/svgalib_helper/kernel26compat.h	2004-02-23 00:41:03.176196576 +0200
@@ -9,9 +12,11 @@
 
 # define my_io_remap_page_range(vma, start, ofs, len, prot) io_remap_page_range(start,ofs,len,prot)
 
+# ifndef IRQ_NONE
 typedef void irqreturn_t;
-# define IRQ_NONE
-# define IRQ_HANDLED
+#  define IRQ_NONE
+#  define IRQ_HANDLED
+# endif
 
 #else /* Kernel 2.6 */
 
@@ -43,9 +43,36 @@ static inline int devfs_unregister_chrde
 }
 #endif
 
+#if defined(KERNEL_2_6) && !defined(CONFIG_DEVFS_FS)
+#  define SLH_SYSFS_REGISTER                                            \
+     svgalib_helper_class = class_simple_create(THIS_MODULE, "svgalib_helper");
+
+#  define SLH_SYSFS_ADD_CONTROL                                         \
+     class_simple_device_add(svgalib_helper_class,                      \
+                             MKDEV(SVGALIB_HELPER_MAJOR, 0),            \
+                             NULL, "svga");
+
+#  define SLH_SYSFS_ADD_DEVICE(_name, _minor)                           \
+     class_simple_device_add(svgalib_helper_class,                      \
+                             MKDEV(SVGALIB_HELPER_MAJOR, _minor),       \
+                             &sh_pci_devs[_minor]->dev->dev, _name);
+
+#  define SLH_SYSFS_REMOVE_DEVICE(i)                                    \
+     class_simple_device_remove(MKDEV(SVGALIB_HELPER_MAJOR, i));
+
+#  define SLH_SYSFS_UNREGISTER                                          \
+     class_simple_destroy(svgalib_helper_class);
+#else
+#  define SLH_SYSFS_REGISTER
+#  define SLH_SYSFS_ADD_CONTROL
+#  define SLH_SYSFS_ADD_DEVICE(_name, _minor)
+#  define SLH_SYSFS_REMOVE_DEVICE(i)
+#  define SLH_SYSFS_UNREGISTER
+#endif
+
 
 /* Our main.c really do not like MINOR from 2.6 kernels ... */
-#if (defined MINOR) && (!defined KERNEL_2_6)
+#if (defined MINOR)
 # define my_minor(x) MINOR(x)
 #else
 # define my_minor(x) minor(x)
diff -urpN svgalib-1.9.18/kernel/svgalib_helper/main.c svgalib-1.9.18.new/kernel/svgalib_helper/main.c
--- svgalib-1.9.18/kernel/svgalib_helper/main.c	2003-10-04 12:34:20.000000000 +0200
+++ svgalib-1.9.18.new/kernel/svgalib_helper/main.c	2004-02-23 00:42:25.490682872 +0200
@@ -53,6 +53,10 @@ static int irqs[MAX_NR_DEVICES];
 static devfs_handle_t devfs_handle;
 #endif
 
+#if defined(KERNEL_2_6) && !defined(CONFIG_DEVFS_FS)
+struct class_simple *svgalib_helper_class;
+#endif
+
 static int check_io_range(int port, int device) {
     return 1;
 }
@@ -502,6 +506,7 @@ int init_module(void)
 {
     int result, i, j;
     struct pci_dev *dev=NULL;
+    char name[255];
 #ifdef CONFIG_DEVFS_FS
 # ifndef KERNEL_2_6
     devfs_handle_t slave_handle;
@@ -513,9 +518,9 @@ int init_module(void)
      
     printk(KERN_INFO "svgalib_helper: Initializing, version %s\n", versionstr);
 
-	result = devfs_register_chrdev(SVGALIB_HELPER_MAJOR, "svgalib_helper", &svgalib_helper_fops);
+    result = devfs_register_chrdev(SVGALIB_HELPER_MAJOR, "svgalib_helper", &svgalib_helper_fops);
 
-	if (result < 0) {
+    if (result < 0) {
         printk(KERN_WARNING "svgalib_helper: can't get major %d\n",SVGALIB_HELPER_MAJOR);
         return result;
     }
@@ -523,7 +528,7 @@ int init_module(void)
     if((sh_pci_devs[0]=kmalloc(sizeof(struct sh_pci_device),GFP_KERNEL))==NULL) {
         goto nomem_error;
     }
-	
+
     memset(sh_pci_devs[0],0,sizeof(struct sh_pci_device));
     num_devices=1;
     for(i=1;i<MAX_NR_DEVICES;i++) sh_pci_devs[i]=NULL;
@@ -537,19 +542,22 @@ int init_module(void)
     devfs_mk_symlink( NULL, "svga", 0, "svga_helper/0", &slave_handle, NULL );
     devfs_auto_unregister( devfs_handle, slave_handle );
 # else
-	devfs_mk_dir ("svga_helper");
-	for (i = 0; i < 8; i++) {
-		devfs_mk_cdev(MKDEV(SVGALIB_HELPER_MAJOR, i),
-				S_IFCHR |  S_IRUGO | S_IRWXU, "svga_helper/%d", i);
-	}
-	devfs_mk_symlink("svga", "svga_helper/0");
+    devfs_mk_dir ("svga_helper");
+    for (i = 0; i < 8; i++) {
+        devfs_mk_cdev(MKDEV(SVGALIB_HELPER_MAJOR, i),
+                      S_IFCHR |  S_IRUGO | S_IRWXU, "svga_helper/%d", i);
+    }
+    devfs_mk_symlink("svga", "svga_helper/0");
 # endif
 #endif /* devfsd support */
 
+    SLH_SYSFS_REGISTER;
+    SLH_SYSFS_ADD_CONTROL;
+
     if(pci_present()) {
         while((dev= all_devices ? 
-					pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev) :
-					pci_find_class(PCI_CLASS_DISPLAY_VGA<<8,dev)) && 
+                                  pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev) :
+                                  pci_find_class(PCI_CLASS_DISPLAY_VGA<<8,dev)) && 
               (num_devices<=MAX_NR_DEVICES)) {
             if((sh_pci_devs[num_devices]=kmalloc(sizeof(struct sh_pci_device),GFP_KERNEL))==NULL) {
                 goto nomem_error;
@@ -581,6 +589,10 @@ int init_module(void)
                 }
             }
             vga_init_vsync(sh_pci_devs[num_devices]);
+
+            sprintf(name, "svga%d", num_devices);
+            SLH_SYSFS_ADD_DEVICE(name, num_devices);
+
             num_devices++;
         }
     }
@@ -600,39 +612,51 @@ int init_module(void)
     init_waitqueue_head(&vsync_wait);
 
 #ifndef KERNEL_2_6
-	EXPORT_NO_SYMBOLS;
+    EXPORT_NO_SYMBOLS;
 #endif
-	
+
     return 0; /* succeed */
 
 nomem_error:
-    for(i=0;i<MAX_NR_DEVICES;i++) 
-        if(sh_pci_devs[i])kfree(sh_pci_devs[i]);
+    for(i=0;i<MAX_NR_DEVICES;i++) {
+        if(sh_pci_devs[i]) {
+            SLH_SYSFS_REMOVE_DEVICE(i);
+            kfree(sh_pci_devs[i]);
+        }
+    }
+
+    SLH_SYSFS_REMOVE_DEVICE(0);
+    SLH_SYSFS_UNREGISTER;
+    
+    devfs_unregister_chrdev(SVGALIB_HELPER_MAJOR, "svgalib_helper");
 
-	devfs_unregister_chrdev(SVGALIB_HELPER_MAJOR, "svgalib_helper");
-		
-	return result;
+    return result;
 }
 
 void cleanup_module(void)
 {
     int i;
-    for(i=0;i<MAX_NR_DEVICES;i++) 
+    for(i=0;i<MAX_NR_DEVICES;i++) {
         if(sh_pci_devs[i]) {
+            SLH_SYSFS_REMOVE_DEVICE(i);
             kfree(sh_pci_devs[i]);
         }
+    }
+
+    SLH_SYSFS_REMOVE_DEVICE(0);
+    SLH_SYSFS_UNREGISTER;
      
 #ifdef CONFIG_DEVFS_FS
 # ifndef KERNEL_2_6
-	devfs_unregister(devfs_handle);
+    devfs_unregister(devfs_handle);
 # else
-	for (i = 0; i < 8; i++)
-		devfs_remove("svga_helper/%d", i);
-	devfs_remove("svga_helper");
-	devfs_remove("svga");
-# endif	
+    for (i = 0; i < 8; i++)
+        devfs_remove("svga_helper/%d", i);
+    devfs_remove("svga_helper");
+    devfs_remove("svga");
+# endif
 #endif
-	
+
     devfs_unregister_chrdev(SVGALIB_HELPER_MAJOR, "svgalib_helper");
 
 }