[PATCH][RFC] support for MODULE_PARAM as kernel commandline

Richard Guenther (zxmpm11@student.uni-tuebingen.de)
Sat, 11 Sep 1999 16:46:23 +0200 (METDST)


Hi!

The following patch transforms MODULE_PARAM declarations
to appropriate __setup() functions that are called for
the build-in drivers to get their parameters set up from
the kernel command line.
I'm using this for isapnp to make it not steal my soundcard
irq.

Any comments (apart from misformatted code :) and of course
missing 's' handling,... )

Richard.

--
Richard Guenther <richard.guenther@student.uni-tuebingen.de>
PGP: 2E829319 - 2F 83 FC 93 E9 E4 19 E2 93 7A 32 42 45 37 23 57
WWW: http://www.anatom.uni-tuebingen.de/~richi/

--- linux-2.3.16/lib/Makefile.original Sat Sep 11 15:45:57 1999 +++ linux-2.3.16/lib/Makefile Sat Sep 11 16:29:13 1999 @@ -7,6 +7,6 @@ # L_TARGET := lib.a -L_OBJS := errno.o ctype.o string.o vsprintf.o +L_OBJS := errno.o ctype.o string.o vsprintf.o parse.o include $(TOPDIR)/Rules.make --- linux-2.3.16/lib/parse.c.original Sat Sep 11 16:28:05 1999 +++ linux-2.3.16/lib/parse.c Sat Sep 11 16:14:50 1999 @@ -0,0 +1,65 @@ +/* parameter parse routine for transparent MODULE_PARAM -> kernel command + * line conversion. + * dumb first version + * + * (c) Richard Guenther <richard.guenther@student.uni-tuebingen.de> + */ +#include <linux/kernel.h> +#include <linux/ctype.h> + +/* parse module parameters like insmod */ +int parse_parameters(void *var, char *type, char *str) +{ + char *p, t; + long min, max, val, cnt; + + p = type; + if (isdigit(*p)) { + min = simple_strtoul(p, &p, 0); + if (*p == '-') + max = simple_strtoul(p+1, &p, 0); + else + max = min; + } else + min = max = 1; + t = *p; + + p = str; + cnt = 0; + do { + if (*p == ',') { + p++; + cnt++; + continue; + } + switch (t) { + case 'b': + val = simple_strtol(p, &p, 0); + ((char *)var)[cnt] = (char)val; + break; + case 'h': + val = simple_strtol(p, &p, 0); + ((short *)var)[cnt] = (short)val; + break; + case 'i': + val = simple_strtol(p, &p, 0); + ((int *)var)[cnt] = (int)val; + break; + case 'l': + val = simple_strtol(p, &p, 0); + ((long *)var)[cnt] = (long)val; + break; + case 's': + printk(KERN_INFO "umm, s type parameter not implemented\n"); + break; + default: + printk(KERN_INFO "error in parsing arguments \"%s\" using format %s\n", str, type); + return 0; + } + if (*p == ',') + p++; + cnt++; + } while (*p && cnt < max); + + return 1; +} --- linux-2.3.16/include/linux/module.h.original Sat Sep 11 15:04:03 1999 +++ linux-2.3.16/include/linux/module.h Sat Sep 11 16:08:09 1999 @@ -8,6 +8,7 @@ #define _LINUX_MODULE_H #include <linux/config.h> +#include <linux/init.h> #ifdef __GENKSYMS__ # define _set_ver(sym) sym @@ -207,11 +208,17 @@ #endif #else /* MODULE */ - +extern int parse_parameters(void *var, char *type, char *str); #define MODULE_AUTHOR(name) #define MODULE_DESCRIPTION(desc) #define MODULE_SUPPORTED_DEVICE(name) -#define MODULE_PARM(var,type) +#define MODULE_PARM(var,type) \ +static char *modparm##var##_setup_type __initdata = type;\ +static int __init modparm##var##_setup(char *str)\ +{\ + return parse_parameters(var, modparm##var##_setup_type, str);\ +}\ +__setup(#var "=", modparm##var##_setup); #define MODULE_PARM_DESC(var,desc) #ifndef __GENKSYMS__

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/