Date: Mon, 23 Jun 1997 10:10:33 +0200 (CEST)
From: Geert Uytterhoeven <Geert.Uytterhoeven@cs.kuleuven.ac.be>
To: Linux/m68k <linux-m68k@phil.uni-sb.de>
Subject: L68K: More frame buffer cleanups
Sender: owner-linux-m68k@phil.uni-sb.de
Reply-To: linux-m68k@phil.uni-sb.de


Some more cleanups for the frame buffer devices:

  - __initfunc in vfb.c

  - you can specify the videomemorysize for vfb if the driver is compiled as
    a loadable kernel module:

	insmod vfb videomemorysize=<size_in_bytes>

  - init/setup array for easier maintenance


--- linux-2.1.42/drivers/video/vfb.c.orig	Mon Jun 16 21:44:29 1997
+++ linux-2.1.42/drivers/video/vfb.c	Sun Jun 22 22:47:49 1997
@@ -20,6 +20,7 @@
 #include <linux/interrupt.h>
 #include <asm/uaccess.h>
 #include <linux/fb.h>
+#include <linux/init.h>
 
 
 #define arraysize(x)	(sizeof(x)/sizeof(*(x)))
@@ -29,13 +30,13 @@
      *  RAM we reserve for the frame buffer. This defines the maximum screen
      *  size
      *
-     *  This can be overridden if the driver is compiled as a module
-     *  (Grrr... doesn't work yet :-(
+     *  The default can be overridden if the driver is compiled as a module
      */
 
 #define VIDEOMEMSIZE	(1*1024*1024)	/* 1 MB */
 
 static u_long videomemory, videomemorysize = VIDEOMEMSIZE;
+MODULE_PARM(videomemorysize, "l");
 static int currcon = 0;
 static struct display disp;
 static struct fb_info fb_info;
@@ -347,7 +348,7 @@
 }
 
 
-void vfb_video_setup(char *options, int *ints)
+__initfunc(void vfb_video_setup(char *options, int *ints))
 {
     char *this_opt;
 
@@ -368,7 +369,7 @@
      *  Initialisation
      */
 
-int virtual_fb_init(u_long *mem_start)
+__initfunc(int virtual_fb_init(u_long *mem_start))
 {
     int err;
 
--- linux-2.1.42/drivers/char/fbmem.c.orig	Mon Jun 16 21:44:26 1997
+++ linux-2.1.42/drivers/char/fbmem.c	Sun Jun 22 23:20:52 1997
@@ -35,36 +35,55 @@
 
 
     /*
-     *  Frame buffer device initialization routines
+     *  Frame buffer device initialization and setup routines
      */
 
-#ifdef CONFIG_FB_AMIGA
 extern int amiga_fb_init(u_long *mem_start);
 extern void amiga_video_setup(char *options, int *ints);
-#endif
-#ifdef CONFIG_FB_ATARI
 extern int atari_fb_init(u_long *mem_start);
 extern void atari_video_setup(char *options, int *ints);
-#endif
-#ifdef CONFIG_FB_CYBER
 extern int Cyber_fb_init(u_long *mem_start);
 extern void Cyber_video_setup(char *options, int *ints);
-#endif
-#ifdef CONFIG_FB_RETINAZ3
 extern int retz3_fb_init(u_long *mem_start);
 extern void retz3_video_setup(char *options, int *ints);
-#endif
-#ifdef CONFIG_FB_CLGEN
 extern int clgen_fb_init(u_long *mem_start);
 extern void clgen_video_setup(char *options, int *ints);
-#endif
-#ifdef CONFIG_FB_VIRTUAL
 extern int virtual_fb_init(u_long *mem_start);
 extern void vfb_video_setup(char *options, int *ints);
+extern void resolver_video_setup(char *options, int *ints);
+
+static struct {
+    const char *name;
+    int (*init)(u_long *mem_start);
+    void (*setup)(char *options, int *ints);
+} builtin_frame_buffers[] __initdata = {
+#ifdef CONFIG_FB_AMIGA
+    { "amifb", amiga_fb_init, amiga_video_setup },
+#endif
+#ifdef CONFIG_FB_ATARI
+    { "atafb", atari_fb_init, atari_video_setup },
+#endif
+#ifdef CONFIG_FB_CYBER
+    { "cyber", Cyber_fb_init, Cyber_video_setup },
+#endif
+#ifdef CONFIG_FB_RETINAZ3
+    { "retz3", retz3_fb_init, retz3_video_setup },
+#endif
+#ifdef CONFIG_FB_CLGEN
+    { "clgen", clgen_fb_init, clgen_video_setup },
+#endif
+#ifdef CONFIG_FB_VIRTUAL
+    { "vfb", virtual_fb_init, vfb_video_setup },
 #endif
 #ifdef CONFIG_GSP_RESOLVER
-extern void resolver_video_setup(char *options, int *ints);
+    /* Not a real frame buffer device... */
+    { "resolver", NULL, resolver_video_setup },
 #endif
+};
+
+#define NUM_BUILTIN_FRAME_BUFFERS	\
+	(sizeof(builtin_frame_buffers)/sizeof(*builtin_frame_buffers))
+
 
 #define GET_INODE(i) MKDEV(FB_MAJOR, (i) << FB_MODES_SHIFT)
 #define GET_FB_IDX(node) (MINOR(node) >> FB_MODES_SHIFT)
@@ -471,26 +490,13 @@
      *  Probe for all builtin frame buffer devices
      */
 
-int probe_framebuffers(u_long *kmem_start)
+__initfunc(int probe_framebuffers(u_long *kmem_start))
 {
-#ifdef CONFIG_FB_AMIGA
-    amiga_fb_init(kmem_start);
-#endif
-#ifdef CONFIG_FB_ATARI
-    atari_fb_init(kmem_start);
-#endif
-#ifdef CONFIG_FB_CYBER
-    Cyber_fb_init(kmem_start);
-#endif
-#ifdef CONFIG_FB_RETINAZ3
-    retz3_fb_init(kmem_start);
-#endif
-#ifdef CONFIG_FB_CLGEN
-    clgen_fb_init(kmem_start);
-#endif
-#ifdef CONFIG_FB_VIRTUAL
-    virtual_fb_init(kmem_start);
-#endif
+    int i;
+
+    for (i = 0; i < NUM_BUILTIN_FRAME_BUFFERS; i++)
+	if (builtin_frame_buffers[i].init)
+	    builtin_frame_buffers[i].init(kmem_start);
     return(num_registered_fb);
 }
 
@@ -501,11 +507,12 @@
 
 __initfunc(void video_setup(char *options, int *ints))
 {
+    int i, j;
+
     if (!options || !*options)
 	return;
 
     if (!strncmp(options, "map:", 4)) {
-	int i, j;
 	options += 4;
 	if (*options)
 	    for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
@@ -516,50 +523,15 @@
 	return;
     }
 
-#ifdef CONFIG_FB_AMIGA
-    if (!strncmp(options, "amifb:", 6)) {
-	amiga_video_setup(options+6, ints);
-	return;
-    }
-#endif
-#ifdef CONFIG_FB_ATARI
-    if (!strncmp(options, "atafb:", 6)) {
-	atari_video_setup(options+6, ints);
-	return;
-    }
-#endif
-#ifdef CONFIG_FB_CYBER
-    if (!strncmp(options, "cyber:", 6)) {
-	Cyber_video_setup(options+6, ints);
-	return;
-    }
-#endif
-#ifdef CONFIG_FB_RETINAZ3
-    if (!strncmp(options, "retz3:", 6)) {
-	retz3_video_setup(options+6, ints);
-	return;
-    }
-#endif
-#ifdef CONFIG_FB_CLGEN
-    if (!strncmp(options, "clgen:", 6)) {
-	clgen_video_setup(options+6, ints);
-	return;
-    }
-#endif
-#ifdef CONFIG_FB_VIRTUAL
-    if (!strncmp(options, "vfb:", 4)) {
-	vfb_video_setup(options+4, ints);
-	return;
-    }
-#endif
-
-    /* Not a real frame buffer device... */
-#ifdef CONFIG_GSP_RESOLVER
-    if (!strncmp(options, "resolver:", 9)) {
-	resolver_video_setup(options+9, ints);
-	return;
-    }
-#endif
+    for (i = 0; i < NUM_BUILTIN_FRAME_BUFFERS; i++)
+	if (builtin_frame_buffers[i].setup) {
+	    j = strlen(builtin_frame_buffers[i].name);
+	    if (!strncmp(options, builtin_frame_buffers[i].name, j) &&
+		options[j] == ':') {
+		builtin_frame_buffers[i].setup(options+j+1, ints);
+		return;
+	    }
+	}
 }
 
 
Greetings,

						Geert

--
Geert Uytterhoeven                     Geert.Uytterhoeven@cs.kuleuven.ac.be
Wavelets, Linux/m68k on Amiga          http://www.cs.kuleuven.ac.be/~geert/
Department of Computer Science -- Katholieke Universiteit Leuven -- Belgium

