157487Storek /*
2*61818Sbostic  * Copyright (c) 1992, 1993
3*61818Sbostic  *	The Regents of the University of California.  All rights reserved.
457487Storek  *
557487Storek  * This software was developed by the Computer Systems Engineering group
657487Storek  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
757487Storek  * contributed to Berkeley.
857487Storek  *
957487Storek  * All advertising materials mentioning features or use of this software
1057487Storek  * must display the following acknowledgement:
1157487Storek  *	This product includes software developed by the University of
1257487Storek  *	California, Lawrence Berkeley Laboratories.
1357487Storek  *
1457487Storek  * %sccs.include.redist.c%
1557487Storek  *
16*61818Sbostic  *	@(#)config.h	8.1 (Berkeley) 06/06/93
1757487Storek  */
1857487Storek 
1957487Storek /*
2057487Storek  * Name/value lists.  Values can be strings or pointers and/or can carry
2157487Storek  * integers.  The names can be NULL, resulting in simple value lists.
2257487Storek  */
2357487Storek struct nvlist {
2457487Storek 	struct	nvlist *nv_next;
2557487Storek 	const char *nv_name;
2657487Storek 	union {
2757487Storek 		const char *un_str;
2857487Storek 		void *un_ptr;
2957487Storek 	} nv_un;
3057487Storek #define	nv_str	nv_un.un_str
3157487Storek #define	nv_ptr	nv_un.un_ptr
3257487Storek 	int	nv_int;
3357487Storek };
3457487Storek 
3557487Storek /*
3657487Storek  * Kernel configurations.
3757487Storek  */
3857487Storek struct config {
3957487Storek 	struct	config *cf_next;	/* linked list */
4057487Storek 	const char *cf_name;		/* "vmunix" */
4157487Storek 	int	cf_lineno;		/* source line */
4257487Storek 	struct	nvlist *cf_root;	/* "root on ra0a" */
4357487Storek 	struct	nvlist *cf_swap;	/* "swap on ra0b and ra1b" */
4457487Storek 	struct	nvlist *cf_dump;	/* "dumps on ra0b" */
4557487Storek };
4657487Storek 
4757487Storek /*
4857487Storek  * Attributes.  These come in two flavors: "plain" and "interface".
4957487Storek  * Plain attributes (e.g., "ether") simply serve to pull in files.
5057487Storek  * Interface attributes (e.g., "scsi") carry three lists: locators,
5157487Storek  * child devices, and references.  The locators are those things
5257487Storek  * that must be specified in order to configure a device instance
5357487Storek  * using this attribute (e.g., "tg0 at scsi0").  The a_devs field
5457487Storek  * lists child devices that can connect here (e.g., "tg"s), while
5557487Storek  * the a_refs are parents that carry the attribute (e.g., actual
5657487Storek  * SCSI host adapter drivers such as the SPARC "esp").
5757487Storek  */
5857487Storek struct attr {
5957487Storek 	const char *a_name;		/* name of this attribute */
6057487Storek 	int	a_iattr;		/* true => allows children */
6157487Storek 	struct	nvlist *a_locs;		/* locators required */
6257487Storek 	int	a_loclen;		/* length of above list */
6357487Storek 	struct	nvlist *a_devs;		/* children */
6457487Storek 	struct	nvlist *a_refs;		/* parents */
6557487Storek };
6657487Storek 
6757487Storek /*
6857487Storek  * The "base" part of a device ("uba", "sd"; but not "uba2" or
6957487Storek  * "sd0").  It may be found "at" one or more attributes, including
7057487Storek  * "at root" (this is represented by a NULL attribute).
7157487Storek  *
7257487Storek  * Each device may also export attributes.  If any provide an output
7357487Storek  * interface (e.g., "esp" provides "scsi"), other devices (e.g.,
7457487Storek  * "tg"s) can be found at instances of this one (e.g., "esp"s).
7557487Storek  * Such a connection must provide locators as specified by that
7657487Storek  * interface attribute (e.g., "target").
7757487Storek  *
7857487Storek  * Each base carries a list of instances (via d_ihead).  Note that this
7957487Storek  * list "skips over" aliases; those must be found through the instances
8057487Storek  * themselves.
8157487Storek  */
8257487Storek struct devbase {
8357487Storek 	const char *d_name;		/* e.g., "sd" */
8457487Storek 	struct	devbase *d_next;	/* linked list */
8557487Storek 	int	d_isdef;		/* set once properly defined */
8657487Storek 	int	d_ispseudo;		/* is a pseudo-device */
8757487Storek 	int	d_major;		/* used for "root on sd0", e.g. */
8857487Storek 	struct	nvlist *d_atlist;	/* e.g., "at tg" (attr list) */
8957487Storek 	struct	nvlist *d_vectors;	/* interrupt vectors, if any */
9057487Storek 	struct	nvlist *d_attrs;	/* attributes, if any */
9157487Storek 	struct	devi *d_ihead;		/* first instance, if any */
9257487Storek 	struct	devi **d_ipp;		/* used for tacking on more instances */
9357487Storek 	int	d_umax;			/* highest unit number + 1 */
9457487Storek };
9557487Storek 
9657487Storek /*
9757487Storek  * An "instance" of a device.  The same instance may be listed more
9857487Storek  * than once, e.g., "xx0 at isa? port FOO" + "xx0 at isa? port BAR".
9957487Storek  *
10057487Storek  * After everything has been read in and verified, the devi's are
10157487Storek  * "packed" to collect all the information needed to generate ioconf.c.
10257487Storek  * In particular, we try to collapse multiple aliases into a single entry.
10357487Storek  * We then assign each "primary" (non-collapsed) instance a cfdata index.
10457487Storek  * Note that there may still be aliases among these.
10557487Storek  */
10657487Storek struct devi {
10757487Storek 	/* created while parsing config file */
10857487Storek 	const char *i_name;	/* e.g., "sd0" */
10957487Storek 	int	i_unit;		/* unit from name, e.g., 0 */
11057487Storek 	struct	devbase *i_base;/* e.g., pointer to "sd" base */
11157487Storek 	struct	devi *i_next;	/* list of all instances */
11257487Storek 	struct	devi *i_bsame;	/* list on same base */
11357487Storek 	struct	devi *i_alias;	/* other aliases of this instance */
11457487Storek 	const char *i_at;	/* where this is "at" (NULL if at root) */
11557487Storek 	struct	attr *i_atattr;	/* attr that allowed attach */
11657487Storek 	struct	devbase *i_atdev;/* dev if "at <devname><unit>", else NULL */
11757487Storek 	const char **i_locs;	/* locators (as given by i_atattr) */
11857487Storek 	int	i_atunit;	/* unit from "at" */
11957487Storek 	int	i_cfflags;	/* flags from config line */
12057487Storek 	int	i_lineno;	/* line # in config, for later errors */
12157487Storek 
12257487Storek 	/* created during packing or ioconf.c generation */
12357487Storek /* 		i_loclen	   via i_atattr->a_loclen */
12457487Storek 	short	i_collapsed;	/* set => this alias no longer needed */
12557487Storek 	short	i_cfindex;	/* our index in cfdata */
12657487Storek 	short	i_pvlen;	/* number of parents */
12757487Storek 	short	i_pvoff;	/* offset in parents.vec */
12857487Storek 	short	i_locoff;	/* offset in locators.vec */
12957487Storek 	short	i_ivoff;	/* offset in interrupt vectors, if any */
13057487Storek 	struct	devi **i_parents;/* the parents themselves */
13157487Storek 
13257487Storek };
13357487Storek /* special units */
13457487Storek #define	STAR	(-1)		/* unit number for, e.g., "sd*" */
13557487Storek #define	WILD	(-2)		/* unit number for, e.g., "sd?" */
13657487Storek 
13757487Storek /*
13857487Storek  * Files.  Each file is either standard (always included) or optional,
13957487Storek  * depending on whether it has names on which to *be* optional.
14057487Storek  */
14157487Storek struct files {
14257487Storek 	struct	files *fi_next;	/* linked list */
14357487Storek 	const char *fi_srcfile;	/* the name of the "files" file that got us */
14457487Storek 	u_short	fi_srcline;	/* and the line number */
14557487Storek 	u_char	fi_flags;	/* as below */
14657487Storek 	char	fi_lastc;	/* last char from path */
14757487Storek 	const char *fi_path;	/* full file path */
14857487Storek 	const char *fi_tail;	/* name, i.e., rindex(fi_path, '/') + 1 */
14957487Storek 	const char *fi_base;	/* tail minus ".c" (or whatever) */
15057487Storek 	struct	nvlist *fi_opt;	/* optional on ... */
15157487Storek 	const char *fi_mkrule;	/* special make rule, if any */
15257487Storek };
15357487Storek 
15457487Storek /* flags */
15557487Storek #define	FI_SEL		0x01	/* selected */
15657487Storek #define	FI_CONFIGDEP	0x02	/* config-dependent */
15757487Storek #define	FI_DRIVER	0x04	/* device-driver */
15857487Storek #define	FI_NEEDSCOUNT	0x08	/* needs-count */
15957487Storek #define	FI_NEEDSFLAG	0x10	/* needs-flag */
16057487Storek #define	FI_HIDDEN	0x20	/* obscured by other(s), base names overlap */
16157487Storek 
16257487Storek /*
16357487Storek  * Hash tables look up name=value pairs.  The pointer value of the name
16457487Storek  * is assumed to be constant forever; this can be arranged by interning
16557487Storek  * the name.  (This is fairly convenient since our lexer does this for
16657487Storek  * all identifier-like strings---it has to save them anyway, lest yacc's
16757487Storek  * look-ahead wipe out the current one.)
16857487Storek  */
16957487Storek struct hashtab;
17057487Storek 
17157487Storek const char *conffile;		/* source file, e.g., "GENERIC.sparc" */
17257487Storek const char *confdirbase;	/* basename of compile directory, usu. same */
17357487Storek const char *machine;		/* machine type, e.g., "sparc" */
17457487Storek int	errors;			/* counts calls to error() */
17557487Storek int	minmaxusers;		/* minimum "maxusers" parameter */
17657487Storek int	defmaxusers;		/* default "maxusers" parameter */
17757487Storek int	maxmaxusers;		/* default "maxusers" parameter */
17857487Storek int	maxusers;		/* configuration's "maxusers" parameter */
17957487Storek struct	nvlist *options;	/* options */
18057487Storek struct	nvlist *mkoptions;	/* makeoptions */
18157487Storek struct	hashtab *devbasetab;	/* devbase lookup */
18257487Storek struct	hashtab *selecttab;	/* selects things that are "optional foo" */
18357487Storek struct	hashtab *needcnttab;	/* retains names marked "needs-count" */
18457487Storek 
18557487Storek struct	devbase *allbases;	/* list of all devbase structures */
18657487Storek struct	config *allcf;		/* list of configured kernels */
18757487Storek struct	devi *alldevi;		/* list of all instances */
18857487Storek struct	devi *allpseudo;	/* list of all pseudo-devices */
18957487Storek int	ndevi;			/* number of devi's (before packing) */
19057487Storek int	npseudo;		/* number of pseudo's */
19157487Storek 
19257487Storek struct	files *allfiles;	/* list of all kernel source files */
19357487Storek 
19457487Storek struct	devi **packed;		/* arrayified table for packed devi's */
19557487Storek int	npacked;		/* size of packed table, <= ndevi */
19657487Storek 
19757487Storek struct {			/* pv[] table for config */
19857487Storek 	short	*vec;
19957487Storek 	int	used;
20057487Storek } parents;
20157487Storek struct {			/* loc[] table for config */
20257487Storek 	const char **vec;
20357487Storek 	int	used;
20457487Storek } locators;
20557487Storek 
20657487Storek /* files.c */
20757487Storek void	initfiles __P((void));
20857487Storek void	checkfiles __P((void));
20957487Storek int	fixfiles __P((void));	/* finalize */
21057487Storek void	addfile __P((const char *, struct nvlist *, int, const char *));
21157487Storek 
21257487Storek /* hash.c */
21357487Storek struct	hashtab *ht_new __P((void));
21457487Storek int	ht_insrep __P((struct hashtab *, const char *, void *, int));
21557487Storek #define	ht_insert(ht, nam, val) ht_insrep(ht, nam, val, 0)
21657487Storek #define	ht_replace(ht, nam, val) ht_insrep(ht, nam, val, 1)
21757487Storek void	*ht_lookup __P((struct hashtab *, const char *));
21857487Storek void	initintern __P((void));
21957487Storek const char *intern __P((const char *));
22057487Storek 
22157487Storek /* main.c */
22257487Storek void	addoption __P((const char *name, const char *value));
22357487Storek void	addmkoption __P((const char *name, const char *value));
22457487Storek 
22557487Storek /* mkheaders.c */
22657487Storek int	mkheaders __P((void));
22757487Storek 
22857487Storek /* mkioconf.c */
22957487Storek int	mkioconf __P((void));
23057487Storek 
23157487Storek /* mkmakefile.c */
23257487Storek int	mkmakefile __P((void));
23357487Storek 
23457487Storek /* mkswap.c */
23557487Storek int	mkswap __P((void));
23657487Storek 
23757487Storek /* pack.c */
23857487Storek void	pack __P((void));
23957487Storek 
24057487Storek /* scan.l */
24157487Storek int	currentline __P((void));
24257487Storek 
24357487Storek /* sem.c, other than for yacc actions */
24457487Storek void	initsem __P((void));
24557487Storek 
24657487Storek /* util.c */
24757487Storek void	*emalloc __P((size_t));
24857487Storek void	*erealloc __P((void *, size_t));
24957487Storek char	*path __P((const char *));
25057487Storek void	error __P((const char *, ...));			/* immediate errs */
25157487Storek void	xerror __P((const char *, int, const char *, ...)); /* delayed errs */
25257487Storek __dead void panic __P((const char *, ...));
25357487Storek struct nvlist *newnv __P((const char *, const char *, void *, int));
25457487Storek void	nvfree __P((struct nvlist *));
25557487Storek void	nvfreel __P((struct nvlist *));
256