xref: /original-bsd/usr.sbin/config.new/config.h (revision a043e977)
1 /*
2  * Copyright (c) 1992 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This software was developed by the Computer Systems Engineering group
6  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7  * contributed to Berkeley.
8  *
9  * All advertising materials mentioning features or use of this software
10  * must display the following acknowledgement:
11  *	This product includes software developed by the University of
12  *	California, Lawrence Berkeley Laboratories.
13  *
14  * %sccs.include.redist.c%
15  *
16  *	@(#)config.h	5.1 (Berkeley) 01/12/93
17  *
18  * from: $Header: config.h,v 1.4 93/01/12 03:54:25 torek Exp $
19  */
20 
21 /*
22  * Name/value lists.  Values can be strings or pointers and/or can carry
23  * integers.  The names can be NULL, resulting in simple value lists.
24  */
25 struct nvlist {
26 	struct	nvlist *nv_next;
27 	const char *nv_name;
28 	union {
29 		const char *un_str;
30 		void *un_ptr;
31 	} nv_un;
32 #define	nv_str	nv_un.un_str
33 #define	nv_ptr	nv_un.un_ptr
34 	int	nv_int;
35 };
36 
37 /*
38  * Kernel configurations.
39  */
40 struct config {
41 	struct	config *cf_next;	/* linked list */
42 	const char *cf_name;		/* "vmunix" */
43 	int	cf_lineno;		/* source line */
44 	struct	nvlist *cf_root;	/* "root on ra0a" */
45 	struct	nvlist *cf_swap;	/* "swap on ra0b and ra1b" */
46 	struct	nvlist *cf_dump;	/* "dumps on ra0b" */
47 };
48 
49 /*
50  * Attributes.  These come in two flavors: "plain" and "interface".
51  * Plain attributes (e.g., "ether") simply serve to pull in files.
52  * Interface attributes (e.g., "scsi") carry three lists: locators,
53  * child devices, and references.  The locators are those things
54  * that must be specified in order to configure a device instance
55  * using this attribute (e.g., "tg0 at scsi0").  The a_devs field
56  * lists child devices that can connect here (e.g., "tg"s), while
57  * the a_refs are parents that carry the attribute (e.g., actual
58  * SCSI host adapter drivers such as the SPARC "esp").
59  */
60 struct attr {
61 	const char *a_name;		/* name of this attribute */
62 	int	a_iattr;		/* true => allows children */
63 	struct	nvlist *a_locs;		/* locators required */
64 	int	a_loclen;		/* length of above list */
65 	struct	nvlist *a_devs;		/* children */
66 	struct	nvlist *a_refs;		/* parents */
67 };
68 
69 /*
70  * The "base" part of a device ("uba", "sd"; but not "uba2" or
71  * "sd0").  It may be found "at" one or more attributes, including
72  * "at root" (this is represented by a NULL attribute).
73  *
74  * Each device may also export attributes.  If any provide an output
75  * interface (e.g., "esp" provides "scsi"), other devices (e.g.,
76  * "tg"s) can be found at instances of this one (e.g., "esp"s).
77  * Such a connection must provide locators as specified by that
78  * interface attribute (e.g., "target").
79  *
80  * Each base carries a list of instances (via d_ihead).  Note that this
81  * list "skips over" aliases; those must be found through the instances
82  * themselves.
83  */
84 struct devbase {
85 	const char *d_name;		/* e.g., "sd" */
86 	struct	devbase *d_next;	/* linked list */
87 	int	d_isdef;		/* set once properly defined */
88 	int	d_ispseudo;		/* is a pseudo-device */
89 	int	d_major;		/* used for "root on sd0", e.g. */
90 	struct	nvlist *d_atlist;	/* e.g., "at tg" (attr list) */
91 	struct	nvlist *d_vectors;	/* interrupt vectors, if any */
92 	struct	nvlist *d_attrs;	/* attributes, if any */
93 	struct	devi *d_ihead;		/* first instance, if any */
94 	struct	devi **d_ipp;		/* used for tacking on more instances */
95 	int	d_umax;			/* highest unit number + 1 */
96 };
97 
98 /*
99  * An "instance" of a device.  The same instance may be listed more
100  * than once, e.g., "xx0 at isa? port FOO" + "xx0 at isa? port BAR".
101  *
102  * After everything has been read in and verified, the devi's are
103  * "packed" to collect all the information needed to generate ioconf.c.
104  * In particular, we try to collapse multiple aliases into a single entry.
105  * We then assign each "primary" (non-collapsed) instance a cfdata index.
106  * Note that there may still be aliases among these.
107  */
108 struct devi {
109 	/* created while parsing config file */
110 	const char *i_name;	/* e.g., "sd0" */
111 	int	i_unit;		/* unit from name, e.g., 0 */
112 	struct	devbase *i_base;/* e.g., pointer to "sd" base */
113 	struct	devi *i_next;	/* list of all instances */
114 	struct	devi *i_bsame;	/* list on same base */
115 	struct	devi *i_alias;	/* other aliases of this instance */
116 	const char *i_at;	/* where this is "at" (NULL if at root) */
117 	struct	attr *i_atattr;	/* attr that allowed attach */
118 	struct	devbase *i_atdev;/* dev if "at <devname><unit>", else NULL */
119 	const char **i_locs;	/* locators (as given by i_atattr) */
120 	int	i_atunit;	/* unit from "at" */
121 	int	i_cfflags;	/* flags from config line */
122 	int	i_lineno;	/* line # in config, for later errors */
123 
124 	/* created during packing or ioconf.c generation */
125 /* 		i_loclen	   via i_atattr->a_loclen */
126 	short	i_collapsed;	/* set => this alias no longer needed */
127 	short	i_cfindex;	/* our index in cfdata */
128 	short	i_pvlen;	/* number of parents */
129 	short	i_pvoff;	/* offset in parents.vec */
130 	short	i_locoff;	/* offset in locators.vec */
131 	short	i_ivoff;	/* offset in interrupt vectors, if any */
132 	struct	devi **i_parents;/* the parents themselves */
133 
134 };
135 /* special units */
136 #define	STAR	(-1)		/* unit number for, e.g., "sd*" */
137 #define	WILD	(-2)		/* unit number for, e.g., "sd?" */
138 
139 /*
140  * Files.  Each file is either standard (always included) or optional,
141  * depending on whether it has names on which to *be* optional.
142  */
143 struct files {
144 	struct	files *fi_next;	/* linked list */
145 	const char *fi_srcfile;	/* the name of the "files" file that got us */
146 	u_short	fi_srcline;	/* and the line number */
147 	u_char	fi_flags;	/* as below */
148 	char	fi_lastc;	/* last char from path */
149 	const char *fi_path;	/* full file path */
150 	const char *fi_tail;	/* name, i.e., rindex(fi_path, '/') + 1 */
151 	const char *fi_base;	/* tail minus ".c" (or whatever) */
152 	struct	nvlist *fi_opt;	/* optional on ... */
153 	const char *fi_mkrule;	/* special make rule, if any */
154 };
155 
156 /* flags */
157 #define	FI_SEL		0x01	/* selected */
158 #define	FI_CONFIGDEP	0x02	/* config-dependent */
159 #define	FI_DRIVER	0x04	/* device-driver */
160 #define	FI_NEEDSCOUNT	0x08	/* needs-count */
161 #define	FI_NEEDSFLAG	0x10	/* needs-flag */
162 #define	FI_HIDDEN	0x20	/* obscured by other(s), base names overlap */
163 
164 /*
165  * Hash tables look up name=value pairs.  The pointer value of the name
166  * is assumed to be constant forever; this can be arranged by interning
167  * the name.  (This is fairly convenient since our lexer does this for
168  * all identifier-like strings---it has to save them anyway, lest yacc's
169  * look-ahead wipe out the current one.)
170  */
171 struct hashtab;
172 
173 const char *conffile;		/* source file, e.g., "GENERIC.sparc" */
174 const char *confdirbase;	/* basename of compile directory, usu. same */
175 const char *machine;		/* machine type, e.g., "sparc" */
176 int	errors;			/* counts calls to error() */
177 int	minmaxusers;		/* minimum "maxusers" parameter */
178 int	defmaxusers;		/* default "maxusers" parameter */
179 int	maxmaxusers;		/* default "maxusers" parameter */
180 int	maxusers;		/* configuration's "maxusers" parameter */
181 struct	nvlist *options;	/* options */
182 struct	nvlist *mkoptions;	/* makeoptions */
183 struct	hashtab *devbasetab;	/* devbase lookup */
184 struct	hashtab *selecttab;	/* selects things that are "optional foo" */
185 struct	hashtab *needcnttab;	/* retains names marked "needs-count" */
186 
187 struct	devbase *allbases;	/* list of all devbase structures */
188 struct	config *allcf;		/* list of configured kernels */
189 struct	devi *alldevi;		/* list of all instances */
190 struct	devi *allpseudo;	/* list of all pseudo-devices */
191 int	ndevi;			/* number of devi's (before packing) */
192 int	npseudo;		/* number of pseudo's */
193 
194 struct	files *allfiles;	/* list of all kernel source files */
195 
196 struct	devi **packed;		/* arrayified table for packed devi's */
197 int	npacked;		/* size of packed table, <= ndevi */
198 
199 struct {			/* pv[] table for config */
200 	short	*vec;
201 	int	used;
202 } parents;
203 struct {			/* loc[] table for config */
204 	const char **vec;
205 	int	used;
206 } locators;
207 
208 /* files.c */
209 void	initfiles __P((void));
210 void	checkfiles __P((void));
211 int	fixfiles __P((void));	/* finalize */
212 void	addfile __P((const char *, struct nvlist *, int, const char *));
213 
214 /* hash.c */
215 struct	hashtab *ht_new __P((void));
216 int	ht_insrep __P((struct hashtab *, const char *, void *, int));
217 #define	ht_insert(ht, nam, val) ht_insrep(ht, nam, val, 0)
218 #define	ht_replace(ht, nam, val) ht_insrep(ht, nam, val, 1)
219 void	*ht_lookup __P((struct hashtab *, const char *));
220 void	initintern __P((void));
221 const char *intern __P((const char *));
222 
223 /* main.c */
224 void	addoption __P((const char *name, const char *value));
225 void	addmkoption __P((const char *name, const char *value));
226 
227 /* mkheaders.c */
228 int	mkheaders __P((void));
229 
230 /* mkioconf.c */
231 int	mkioconf __P((void));
232 
233 /* mkmakefile.c */
234 int	mkmakefile __P((void));
235 
236 /* mkswap.c */
237 int	mkswap __P((void));
238 
239 /* pack.c */
240 void	pack __P((void));
241 
242 /* scan.l */
243 int	currentline __P((void));
244 
245 /* sem.c, other than for yacc actions */
246 void	initsem __P((void));
247 
248 /* util.c */
249 void	*emalloc __P((size_t));
250 void	*erealloc __P((void *, size_t));
251 char	*path __P((const char *));
252 void	error __P((const char *, ...));			/* immediate errs */
253 void	xerror __P((const char *, int, const char *, ...)); /* delayed errs */
254 __dead void panic __P((const char *, ...));
255 struct nvlist *newnv __P((const char *, const char *, void *, int));
256 void	nvfree __P((struct nvlist *));
257 void	nvfreel __P((struct nvlist *));
258