defs.h revision 1.14 1 /* $NetBSD: defs.h,v 1.14 2006/09/03 07:45:40 dsl Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratories.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * from: @(#)config.h 8.1 (Berkeley) 6/6/93
41 */
42
43 /*
44 * defs.h: Global definitions for "config"
45 */
46
47 #if HAVE_NBTOOL_CONFIG_H
48 #include "nbtool_config.h"
49 #endif
50
51 #include <sys/types.h>
52 #include <sys/param.h>
53 #include <sys/queue.h>
54
55 #if !defined(MAKE_BOOTSTRAP) && defined(BSD)
56 #include <sys/cdefs.h>
57 #include <paths.h>
58 #endif
59
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <unistd.h>
63
64 /* These are really for MAKE_BOOTSTRAP but harmless. */
65 #ifndef __dead
66 #define __dead
67 #endif
68 #ifndef _PATH_DEVNULL
69 #define _PATH_DEVNULL "/dev/null"
70 #endif
71
72 #ifdef MAKE_BOOTSTRAP
73 #undef dev_t
74 #undef NODEV
75 #undef major
76 #undef minor
77 #undef makedev
78 #define dev_t int /* XXX: assumes int is 32 bits */
79 #define NODEV ((dev_t)-1)
80 #define major(x) ((int)((((x) & 0x000fff00) >> 8)))
81 #define minor(x) ((int)((((x) & 0xfff00000) >> 12) | \
82 (((x) & 0x000000ff) >> 0)))
83 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
84 (((y) << 12) & 0xfff00000) | \
85 (((y) << 0) & 0x000000ff)))
86 #define __attribute__(x)
87 #endif /* MAKE_BOOTSTRAP */
88
89 #undef setprogname
90 #undef getprogname
91 extern const char *progname;
92 #define setprogname(s) ((void)(progname = (s)))
93 #define getprogname() (progname)
94
95 #define ARRCHR '#'
96
97 /*
98 * The next two lines define the current version of the config(1) binary,
99 * and the minimum version of the configuration files it supports.
100 */
101 #define CONFIG_VERSION 20060830
102 #define CONFIG_MINVERSION 0
103
104 /*
105 * Name/value lists. Values can be strings or pointers and/or can carry
106 * integers. The names can be NULL, resulting in simple value lists.
107 */
108 struct nvlist {
109 struct nvlist *nv_next;
110 const char *nv_name;
111 const char *nv_str;
112 void *nv_ptr;
113 int nv_int;
114 int nv_ifunit; /* XXX XXX XXX */
115 int nv_flags;
116 #define NV_DEPENDED 1
117 #define NV_OBSOLETE 2
118 };
119
120 /*
121 * Kernel configurations.
122 */
123 struct config {
124 TAILQ_ENTRY(config) cf_next;
125 const char *cf_name; /* "netbsd" */
126 int cf_lineno; /* source line */
127 const char *cf_fstype; /* file system type */
128 struct nvlist *cf_root; /* "root on ra0a" */
129 struct nvlist *cf_swap; /* "swap on ra0b and ra1b" */
130 struct nvlist *cf_dump; /* "dumps on ra0b" */
131 };
132
133 /*
134 * Attributes. These come in three flavors: "plain", "device class,"
135 * and "interface". Plain attributes (e.g., "ether") simply serve
136 * to pull in files. Device class attributes are like plain
137 * attributes, but additionally specify a device class (e.g., the
138 * "disk" device class attribute specifies that devices with the
139 * attribute belong to the "DV_DISK" class) and are mutually exclusive.
140 * Interface attributes (e.g., "scsi") carry three lists: locators,
141 * child devices, and references. The locators are those things
142 * that must be specified in order to configure a device instance
143 * using this attribute (e.g., "tg0 at scsi0"). The a_devs field
144 * lists child devices that can connect here (e.g., "tg"s), while
145 * the a_refs are parents that carry the attribute (e.g., actual
146 * SCSI host adapter drivers such as the SPARC "esp").
147 */
148 struct attr {
149 const char *a_name; /* name of this attribute */
150 int a_iattr; /* true => allows children */
151 const char *a_devclass; /* device class described */
152 struct nvlist *a_locs; /* locators required */
153 int a_loclen; /* length of above list */
154 struct nvlist *a_devs; /* children */
155 struct nvlist *a_refs; /* parents */
156 struct nvlist *a_deps; /* we depend on these other attrs */
157 int a_expanding; /* to detect cycles in attr graph */
158 };
159
160 /*
161 * Parent specification. Multiple device instances may share a
162 * given parent spec. Parent specs are emitted only if there are
163 * device instances which actually reference it.
164 */
165 struct pspec {
166 TAILQ_ENTRY(pspec) p_list; /* link on parent spec list */
167 struct attr *p_iattr; /* interface attribute of parent */
168 struct devbase *p_atdev; /* optional parent device base */
169 int p_atunit; /* optional parent device unit */
170 struct nvlist *p_devs; /* children using it */
171 int p_inst; /* parent spec instance */
172 int p_active; /* parent spec is actively used */
173 };
174
175 /*
176 * The "base" part (struct devbase) of a device ("uba", "sd"; but not
177 * "uba2" or "sd0"). It may be found "at" one or more attributes,
178 * including "at root" (this is represented by a NULL attribute), as
179 * specified by the device attachments (struct deva).
180 *
181 * Each device may also export attributes. If any provide an output
182 * interface (e.g., "esp" provides "scsi"), other devices (e.g.,
183 * "tg"s) can be found at instances of this one (e.g., "esp"s).
184 * Such a connection must provide locators as specified by that
185 * interface attribute (e.g., "target"). The base device can
186 * export both output (aka `interface') attributes, as well as
187 * import input (`plain') attributes. Device attachments may
188 * only import input attributes; it makes no sense to have a
189 * specific attachment export a new interface to other devices.
190 *
191 * Each base carries a list of instances (via d_ihead). Note that this
192 * list "skips over" aliases; those must be found through the instances
193 * themselves. Each base also carries a list of possible attachments,
194 * each of which specify a set of devices that the device can attach
195 * to, as well as the device instances that are actually using that
196 * attachment.
197 */
198 struct devbase {
199 const char *d_name; /* e.g., "sd" */
200 TAILQ_ENTRY(devbase) d_next;
201 int d_isdef; /* set once properly defined */
202 int d_ispseudo; /* is a pseudo-device */
203 int d_major; /* used for "root on sd0", e.g. */
204 struct nvlist *d_attrs; /* attributes, if any */
205 int d_umax; /* highest unit number + 1 */
206 struct devi *d_ihead; /* first instance, if any */
207 struct devi **d_ipp; /* used for tacking on more instances */
208 struct deva *d_ahead; /* first attachment, if any */
209 struct deva **d_app; /* used for tacking on attachments */
210 struct attr *d_classattr; /* device class attribute (if any) */
211 };
212
213 struct deva {
214 const char *d_name; /* name of attachment, e.g. "com_isa" */
215 TAILQ_ENTRY(deva) d_next; /* list of all instances */
216 struct deva *d_bsame; /* list on same base */
217 int d_isdef; /* set once properly defined */
218 struct devbase *d_devbase; /* the base device */
219 struct nvlist *d_atlist; /* e.g., "at tg" (attr list) */
220 struct nvlist *d_attrs; /* attributes, if any */
221 struct devi *d_ihead; /* first instance, if any */
222 struct devi **d_ipp; /* used for tacking on more instances */
223 };
224
225 /*
226 * An "instance" of a device. The same instance may be listed more
227 * than once, e.g., "xx0 at isa? port FOO" + "xx0 at isa? port BAR".
228 *
229 * After everything has been read in and verified, the devi's are
230 * "packed" to collect all the information needed to generate ioconf.c.
231 * In particular, we try to collapse multiple aliases into a single entry.
232 * We then assign each "primary" (non-collapsed) instance a cfdata index.
233 * Note that there may still be aliases among these.
234 */
235 struct devi {
236 /* created while parsing config file */
237 const char *i_name; /* e.g., "sd0" */
238 int i_unit; /* unit from name, e.g., 0 */
239 struct devbase *i_base;/* e.g., pointer to "sd" base */
240 TAILQ_ENTRY(devi) i_next; /* list of all instances */
241 struct devi *i_bsame; /* list on same base */
242 struct devi *i_asame; /* list on same base attachment */
243 struct devi *i_alias; /* other aliases of this instance */
244 const char *i_at; /* where this is "at" (NULL if at root) */
245 struct pspec *i_pspec; /* parent spec (NULL if at root) */
246 struct deva *i_atdeva;
247 const char **i_locs; /* locators (as given by pspec's iattr) */
248 int i_cfflags; /* flags from config line */
249 int i_lineno; /* line # in config, for later errors */
250 const char *i_srcfile; /* file it appears in */
251 int i_level; /* position between negated instances */
252 int i_active;
253 #define DEVI_ORPHAN 0 /* instance has no active parent */
254 #define DEVI_ACTIVE 1 /* instance has an active parent */
255 #define DEVI_IGNORED 2 /* instance's parent has been removed */
256 #define DEVI_BROKEN 3 /* instance is broken (syntax error) */
257
258 /* created during packing or ioconf.c generation */
259 short i_collapsed; /* set => this alias no longer needed */
260 short i_cfindex; /* our index in cfdata */
261 short i_locoff; /* offset in locators.vec */
262
263 };
264 /* special units */
265 #define STAR (-1) /* unit number for, e.g., "sd*" */
266 #define WILD (-2) /* unit number for, e.g., "sd?" */
267
268 /*
269 * Files or objects. This structure defines the common fields
270 * between the two.
271 */
272 struct filetype
273 {
274 const char *fit_srcfile; /* the name of the "files" file that got us */
275 u_short fit_srcline; /* and the line number */
276 u_char fit_flags; /* as below */
277 char fit_lastc; /* last char from path */
278 const char *fit_path; /* full file path */
279 const char *fit_prefix; /* any file prefix */
280 };
281 /* Anything less than 0x10 is sub-type specific */
282 #define FIT_NOPROLOGUE 0x10 /* Don't prepend $S/ */
283 #define FIT_FORCESELECT 0x20 /* Always include this file */
284
285 /*
286 * Files. Each file is either standard (always included) or optional,
287 * depending on whether it has names on which to *be* optional. The
288 * options field (fi_optx) is actually an expression tree, with nodes
289 * for OR, AND, and NOT, as well as atoms (words) representing some
290 * particular option. The node type is stored in the nv_int field.
291 * Subexpressions appear in the `next' field; for the binary operators
292 * AND and OR, the left subexpression is first stored in the nv_ptr field.
293 *
294 * For any file marked as needs-count or needs-flag, fixfiles() will
295 * build fi_optf, a `flat list' of the options with nv_int fields that
296 * contain counts or `need' flags; this is used in mkheaders().
297 */
298 struct files {
299 struct filetype fi_fit;
300 TAILQ_ENTRY(files) fi_next;
301 const char *fi_tail; /* name, i.e., strrchr(fi_path, '/') + 1 */
302 const char *fi_base; /* tail minus ".c" (or whatever) */
303 struct nvlist *fi_optx; /* options expression */
304 struct nvlist *fi_optf; /* flattened version of above, if needed */
305 const char *fi_mkrule; /* special make rule, if any */
306 };
307 #define fi_srcfile fi_fit.fit_srcfile
308 #define fi_srcline fi_fit.fit_srcline
309 #define fi_flags fi_fit.fit_flags
310 #define fi_lastc fi_fit.fit_lastc
311 #define fi_path fi_fit.fit_path
312 #define fi_prefix fi_fit.fit_prefix
313
314 /* flags */
315 #define FI_SEL 0x01 /* selected */
316 #define FI_NEEDSCOUNT 0x02 /* needs-count */
317 #define FI_NEEDSFLAG 0x04 /* needs-flag */
318 #define FI_HIDDEN 0x08 /* obscured by other(s), base names overlap */
319
320 /*
321 * Objects and libraries. This allows precompiled object and library
322 * files (e.g. binary-only device drivers) to be linked in.
323 */
324 struct objects {
325 struct filetype oi_fit;
326 TAILQ_ENTRY(objects) oi_next;
327 struct nvlist *oi_optx;/* options expression */
328 struct nvlist *oi_optf;/* flattened version of above, if needed */
329 };
330
331 #define oi_srcfile oi_fit.fit_srcfile
332 #define oi_srcline oi_fit.fit_srcline
333 #define oi_flags oi_fit.fit_flags
334 #define oi_lastc oi_fit.fit_lastc
335 #define oi_path oi_fit.fit_path
336 #define oi_prefix oi_fit.fit_prefix
337
338 /* flags */
339 #define OI_SEL 0x01 /* selected */
340 #define OI_NEEDSFLAG 0x02 /* needs-flag */
341
342 #define FX_ATOM 0 /* atom (in nv_name) */
343 #define FX_NOT 1 /* NOT expr (subexpression in nv_next) */
344 #define FX_AND 2 /* AND expr (lhs in nv_ptr, rhs in nv_next) */
345 #define FX_OR 3 /* OR expr (lhs in nv_ptr, rhs in nv_next) */
346
347 /*
348 * File/object prefixes. These are arranged in a stack, and affect
349 * the behavior of the source path.
350 */
351 struct prefix {
352 SLIST_ENTRY(prefix) pf_next; /* next prefix in stack */
353 const char *pf_prefix; /* the actual prefix */
354 };
355
356 /*
357 * Device major informations.
358 */
359 struct devm {
360 TAILQ_ENTRY(devm) dm_next;
361 const char *dm_srcfile; /* the name of the "majors" file */
362 u_short dm_srcline; /* the line number */
363 const char *dm_name; /* [bc]devsw name */
364 int dm_cmajor; /* character major */
365 int dm_bmajor; /* block major */
366 struct nvlist *dm_opts; /* options */
367 };
368
369 /*
370 * Hash tables look up name=value pairs. The pointer value of the name
371 * is assumed to be constant forever; this can be arranged by interning
372 * the name. (This is fairly convenient since our lexer does this for
373 * all identifier-like strings---it has to save them anyway, lest yacc's
374 * look-ahead wipe out the current one.)
375 */
376 struct hashtab;
377
378 int lkmmode;
379 const char *conffile; /* source file, e.g., "GENERIC.sparc" */
380 const char *machine; /* machine type, e.g., "sparc" or "sun3" */
381 const char *machinearch; /* machine arch, e.g., "sparc" or "m68k" */
382 struct nvlist *machinesubarches;
383 /* machine subarches, e.g., "sun68k" or "hpc" */
384 const char *srcdir; /* path to source directory (rel. to build) */
385 const char *builddir; /* path to build directory */
386 const char *defbuilddir; /* default build directory */
387 const char *ident; /* kernel "ident"ification string */
388 int errors; /* counts calls to error() */
389 int minmaxusers; /* minimum "maxusers" parameter */
390 int defmaxusers; /* default "maxusers" parameter */
391 int maxmaxusers; /* default "maxusers" parameter */
392 int maxusers; /* configuration's "maxusers" parameter */
393 int maxpartitions; /* configuration's "maxpartitions" parameter */
394 int version; /* version of the configuration file */
395 struct nvlist *options; /* options */
396 struct nvlist *fsoptions; /* filesystems */
397 struct nvlist *mkoptions; /* makeoptions */
398 struct nvlist *appmkoptions; /* appending mkoptions */
399 struct hashtab *condmkopttab; /* conditional makeoption table */
400 struct hashtab *devbasetab; /* devbase lookup */
401 struct hashtab *devroottab; /* attach at root lookup */
402 struct hashtab *devatab; /* devbase attachment lookup */
403 struct hashtab *devitab; /* device instance lookup */
404 struct hashtab *deaddevitab; /* removed instances lookup */
405 struct hashtab *selecttab; /* selects things that are "optional foo" */
406 struct hashtab *needcnttab; /* retains names marked "needs-count" */
407 struct hashtab *opttab; /* table of configured options */
408 struct hashtab *fsopttab; /* table of configured file systems */
409 struct hashtab *defopttab; /* options that have been "defopt"'d */
410 struct hashtab *defflagtab; /* options that have been "defflag"'d */
411 struct hashtab *defparamtab; /* options that have been "defparam"'d */
412 struct hashtab *deffstab; /* defined file systems */
413 struct hashtab *optfiletab; /* "defopt"'d option .h files */
414 struct hashtab *attrtab; /* attributes (locators, etc.) */
415 struct hashtab *bdevmtab; /* block devm lookup */
416 struct hashtab *cdevmtab; /* character devm lookup */
417
418 TAILQ_HEAD(, devbase) allbases; /* list of all devbase structures */
419 TAILQ_HEAD(, deva) alldevas; /* list of all devbase attachments */
420 TAILQ_HEAD(, config) allcf; /* list of configured kernels */
421 TAILQ_HEAD(, devi) alldevi, /* list of all instances */
422 allpseudo; /* list of all pseudo-devices */
423 TAILQ_HEAD(, devm) alldevms; /* list of all device-majors */
424 TAILQ_HEAD(, pspec) allpspecs; /* list of all parent specs */
425 int ndevi; /* number of devi's (before packing) */
426 int npspecs; /* number of parent specs */
427 int maxbdevm; /* max number of block major */
428 int maxcdevm; /* max number of character major */
429 int do_devsw; /* 0 if pre-devsw config */
430 int oktopackage; /* 0 before setmachine() */
431 int devilevel; /* used for devi->i_level */
432
433 TAILQ_HEAD(, files) allfiles; /* list of all kernel source files */
434 TAILQ_HEAD(, objects) allobjects; /* list of all kernel object and
435 library files */
436
437 SLIST_HEAD(, prefix) prefixes, /* prefix stack */
438 allprefixes; /* all prefixes used (after popped) */
439 SLIST_HEAD(, prefix) curdirs; /* curdir stack */
440
441 struct devi **packed; /* arrayified table for packed devi's */
442 int npacked; /* size of packed table, <= ndevi */
443
444 struct { /* loc[] table for config */
445 const char **vec;
446 int used;
447 } locators;
448
449 struct numconst {
450 int64_t val;
451 int fmt;
452 };
453
454 /* files.c */
455 void initfiles(void);
456 void checkfiles(void);
457 int fixfiles(void); /* finalize */
458 int fixobjects(void);
459 int fixdevsw(void);
460 void addfile(const char *, struct nvlist *, int, const char *);
461 void addobject(const char *, struct nvlist *, int);
462
463 /* hash.c */
464 struct hashtab *ht_new(void);
465 int ht_insrep(struct hashtab *, const char *, void *, int);
466 #define ht_insert(ht, nam, val) ht_insrep(ht, nam, val, 0)
467 #define ht_replace(ht, nam, val) ht_insrep(ht, nam, val, 1)
468 int ht_remove(struct hashtab *, const char *);
469 void *ht_lookup(struct hashtab *, const char *);
470 void initintern(void);
471 const char *intern(const char *);
472 typedef int (*ht_callback)(const char *, void *, void *);
473 int ht_enumerate(struct hashtab *, ht_callback, void *);
474
475 /* main.c */
476 void addoption(const char *, const char *);
477 void addfsoption(const char *);
478 void addmkoption(const char *, const char *);
479 void appendmkoption(const char *, const char *);
480 void appendcondmkoption(const char *, const char *, const char *);
481 void deffilesystem(const char *, struct nvlist *, struct nvlist *);
482 void defoption(const char *, struct nvlist *, struct nvlist *);
483 void defflag(const char *, struct nvlist *, struct nvlist *, int);
484 void defparam(const char *, struct nvlist *, struct nvlist *, int);
485 void deloption(const char *);
486 void delfsoption(const char *);
487 void delmkoption(const char *);
488 int devbase_has_instances(struct devbase *, int);
489 struct nvlist * find_declared_option(const char *);
490 int deva_has_instances(struct deva *, int);
491 void setupdirs(void);
492
493 /* tests on option types */
494 #define OPT_FSOPT(n) (ht_lookup(deffstab, (n)) != NULL)
495 #define OPT_DEFOPT(n) (ht_lookup(defopttab, (n)) != NULL)
496 #define OPT_DEFFLAG(n) (ht_lookup(defflagtab, (n)) != NULL)
497 #define OPT_DEFPARAM(n) (ht_lookup(defparamtab, (n)) != NULL)
498 #define OPT_OBSOLETE(n) (ht_lookup(obsopttab, (n)) != NULL)
499 #define DEFINED_OPTION(n) (find_declared_option((n)) != NULL)
500
501 /* main.c */
502 void logconfig_include(FILE *, const char *);
503
504 /* mkdevsw.c */
505 int mkdevsw(void);
506
507 /* mkheaders.c */
508 int mkheaders(void);
509 int moveifchanged(const char *, const char *);
510
511 /* mkioconf.c */
512 int mkioconf(void);
513
514 /* mkmakefile.c */
515 int mkmakefile(void);
516
517 /* mkswap.c */
518 int mkswap(void);
519
520 /* pack.c */
521 void pack(void);
522
523 /* scan.l */
524 int currentline(void);
525 int firstfile(const char *);
526 void package(const char *);
527 int include(const char *, int, int, int);
528
529 /* sem.c, other than for yacc actions */
530 void initsem(void);
531
532 /* util.c */
533 void *ecalloc(size_t, size_t);
534 void *emalloc(size_t);
535 void *erealloc(void *, size_t);
536 char *estrdup(const char *);
537 void prefix_push(const char *);
538 void prefix_pop(void);
539 char *sourcepath(const char *);
540 void warn(const char *, ...) /* immediate warns */
541 __attribute__((__format__(__printf__, 1, 2)));
542 void xwarn(const char *, int, const char *, ...) /* delayed warns */
543 __attribute__((__format__(__printf__, 3, 4)));
544 void error(const char *, ...) /* immediate errs */
545 __attribute__((__format__(__printf__, 1, 2)));
546 void xerror(const char *, int, const char *, ...) /* delayed errs */
547 __attribute__((__format__(__printf__, 3, 4)));
548 __dead void panic(const char *, ...)
549 __attribute__((__format__(__printf__, 1, 2)));
550 struct nvlist *newnv(const char *, const char *, void *, int, struct nvlist *);
551 void nvfree(struct nvlist *);
552 void nvfreel(struct nvlist *);
553
554 /* liby */
555 void yyerror(const char *);
556 int yylex(void);
557