defs.h revision 1.9 1 /* $NetBSD: defs.h,v 1.9 2005/11/07 03:26:20 erh 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 20051003
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 union {
112 const char *un_str;
113 void *un_ptr;
114 } nv_un;
115 #define nv_str nv_un.un_str
116 #define nv_ptr nv_un.un_ptr
117 int nv_int;
118 int nv_ifunit; /* XXX XXX XXX */
119 int nv_flags;
120 #define NV_DEPENDED 1
121 };
122
123 /*
124 * Kernel configurations.
125 */
126 struct config {
127 TAILQ_ENTRY(config) cf_next;
128 const char *cf_name; /* "netbsd" */
129 int cf_lineno; /* source line */
130 const char *cf_fstype; /* file system type */
131 struct nvlist *cf_root; /* "root on ra0a" */
132 struct nvlist *cf_swap; /* "swap on ra0b and ra1b" */
133 struct nvlist *cf_dump; /* "dumps on ra0b" */
134 };
135
136 /*
137 * Attributes. These come in three flavors: "plain", "device class,"
138 * and "interface". Plain attributes (e.g., "ether") simply serve
139 * to pull in files. Device class attributes are like plain
140 * attributes, but additionally specify a device class (e.g., the
141 * "disk" device class attribute specifies that devices with the
142 * attribute belong to the "DV_DISK" class) and are mutually exclusive.
143 * Interface attributes (e.g., "scsi") carry three lists: locators,
144 * child devices, and references. The locators are those things
145 * that must be specified in order to configure a device instance
146 * using this attribute (e.g., "tg0 at scsi0"). The a_devs field
147 * lists child devices that can connect here (e.g., "tg"s), while
148 * the a_refs are parents that carry the attribute (e.g., actual
149 * SCSI host adapter drivers such as the SPARC "esp").
150 */
151 struct attr {
152 const char *a_name; /* name of this attribute */
153 int a_iattr; /* true => allows children */
154 const char *a_devclass; /* device class described */
155 struct nvlist *a_locs; /* locators required */
156 int a_loclen; /* length of above list */
157 struct nvlist *a_devs; /* children */
158 struct nvlist *a_refs; /* parents */
159 struct nvlist *a_deps; /* we depend on these other attrs */
160 int a_expanding; /* to detect cycles in attr graph */
161 };
162
163 /*
164 * Parent specification. Multiple device instances may share a
165 * given parent spec. Parent specs are emitted only if there are
166 * device instances which actually reference it.
167 */
168 struct pspec {
169 TAILQ_ENTRY(pspec) p_list; /* link on parent spec list */
170 struct attr *p_iattr; /* interface attribute of parent */
171 struct devbase *p_atdev; /* optional parent device base */
172 int p_atunit; /* optional parent device unit */
173 struct nvlist *p_devs; /* children using it */
174 int p_inst; /* parent spec instance */
175 int p_active; /* parent spec is actively used */
176 };
177
178 /*
179 * The "base" part (struct devbase) of a device ("uba", "sd"; but not
180 * "uba2" or "sd0"). It may be found "at" one or more attributes,
181 * including "at root" (this is represented by a NULL attribute), as
182 * specified by the device attachments (struct deva).
183 *
184 * Each device may also export attributes. If any provide an output
185 * interface (e.g., "esp" provides "scsi"), other devices (e.g.,
186 * "tg"s) can be found at instances of this one (e.g., "esp"s).
187 * Such a connection must provide locators as specified by that
188 * interface attribute (e.g., "target"). The base device can
189 * export both output (aka `interface') attributes, as well as
190 * import input (`plain') attributes. Device attachments may
191 * only import input attributes; it makes no sense to have a
192 * specific attachment export a new interface to other devices.
193 *
194 * Each base carries a list of instances (via d_ihead). Note that this
195 * list "skips over" aliases; those must be found through the instances
196 * themselves. Each base also carries a list of possible attachments,
197 * each of which specify a set of devices that the device can attach
198 * to, as well as the device instances that are actually using that
199 * attachment.
200 */
201 struct devbase {
202 const char *d_name; /* e.g., "sd" */
203 TAILQ_ENTRY(devbase) d_next;
204 int d_isdef; /* set once properly defined */
205 int d_ispseudo; /* is a pseudo-device */
206 int d_major; /* used for "root on sd0", e.g. */
207 struct nvlist *d_attrs; /* attributes, if any */
208 int d_umax; /* highest unit number + 1 */
209 struct devi *d_ihead; /* first instance, if any */
210 struct devi **d_ipp; /* used for tacking on more instances */
211 struct deva *d_ahead; /* first attachment, if any */
212 struct deva **d_app; /* used for tacking on attachments */
213 struct attr *d_classattr; /* device class attribute (if any) */
214 };
215
216 struct deva {
217 const char *d_name; /* name of attachment, e.g. "com_isa" */
218 TAILQ_ENTRY(deva) d_next; /* list of all instances */
219 struct deva *d_bsame; /* list on same base */
220 int d_isdef; /* set once properly defined */
221 struct devbase *d_devbase; /* the base device */
222 struct nvlist *d_atlist; /* e.g., "at tg" (attr list) */
223 struct nvlist *d_attrs; /* attributes, if any */
224 struct devi *d_ihead; /* first instance, if any */
225 struct devi **d_ipp; /* used for tacking on more instances */
226 };
227
228 /*
229 * An "instance" of a device. The same instance may be listed more
230 * than once, e.g., "xx0 at isa? port FOO" + "xx0 at isa? port BAR".
231 *
232 * After everything has been read in and verified, the devi's are
233 * "packed" to collect all the information needed to generate ioconf.c.
234 * In particular, we try to collapse multiple aliases into a single entry.
235 * We then assign each "primary" (non-collapsed) instance a cfdata index.
236 * Note that there may still be aliases among these.
237 */
238 struct devi {
239 /* created while parsing config file */
240 const char *i_name; /* e.g., "sd0" */
241 int i_unit; /* unit from name, e.g., 0 */
242 struct devbase *i_base;/* e.g., pointer to "sd" base */
243 TAILQ_ENTRY(devi) i_next; /* list of all instances */
244 struct devi *i_bsame; /* list on same base */
245 struct devi *i_asame; /* list on same base attachment */
246 struct devi *i_alias; /* other aliases of this instance */
247 const char *i_at; /* where this is "at" (NULL if at root) */
248 struct pspec *i_pspec; /* parent spec (NULL if at root) */
249 struct deva *i_atdeva;
250 const char **i_locs; /* locators (as given by pspec's iattr) */
251 int i_cfflags; /* flags from config line */
252 int i_lineno; /* line # in config, for later errors */
253 const char *i_srcfile; /* file it appears in */
254 int i_level; /* position between negated instances */
255 int i_active;
256 #define DEVI_ORPHAN 0 /* instance has no active parent */
257 #define DEVI_ACTIVE 1 /* instance has an active parent */
258 #define DEVI_IGNORED 2 /* instance's parent has been removed */
259 #define DEVI_BROKEN 3 /* instance is broken (syntax error) */
260
261 /* created during packing or ioconf.c generation */
262 short i_collapsed; /* set => this alias no longer needed */
263 short i_cfindex; /* our index in cfdata */
264 short i_locoff; /* offset in locators.vec */
265
266 };
267 /* special units */
268 #define STAR (-1) /* unit number for, e.g., "sd*" */
269 #define WILD (-2) /* unit number for, e.g., "sd?" */
270
271 /*
272 * Files or objects. This structure defines the common fields
273 * between the two.
274 */
275 struct filetype
276 {
277 const char *fit_srcfile; /* the name of the "files" file that got us */
278 u_short fit_srcline; /* and the line number */
279 u_char fit_flags; /* as below */
280 char fit_lastc; /* last char from path */
281 const char *fit_path; /* full file path */
282 const char *fit_prefix; /* any file prefix */
283 };
284 /* Anything less than 0x10 is sub-type specific */
285 #define FIT_NOPROLOGUE 0x10 /* Don't prepend $S/ */
286 #define FIT_FORCESELECT 0x20 /* Always include this file */
287
288 /*
289 * Files. Each file is either standard (always included) or optional,
290 * depending on whether it has names on which to *be* optional. The
291 * options field (fi_optx) is actually an expression tree, with nodes
292 * for OR, AND, and NOT, as well as atoms (words) representing some
293 * particular option. The node type is stored in the nv_int field.
294 * Subexpressions appear in the `next' field; for the binary operators
295 * AND and OR, the left subexpression is first stored in the nv_ptr field.
296 *
297 * For any file marked as needs-count or needs-flag, fixfiles() will
298 * build fi_optf, a `flat list' of the options with nv_int fields that
299 * contain counts or `need' flags; this is used in mkheaders().
300 */
301 struct files {
302 struct filetype fi_fit;
303 TAILQ_ENTRY(files) fi_next;
304 const char *fi_tail; /* name, i.e., strrchr(fi_path, '/') + 1 */
305 const char *fi_base; /* tail minus ".c" (or whatever) */
306 struct nvlist *fi_optx; /* options expression */
307 struct nvlist *fi_optf; /* flattened version of above, if needed */
308 const char *fi_mkrule; /* special make rule, if any */
309 };
310 #define fi_srcfile fi_fit.fit_srcfile
311 #define fi_srcline fi_fit.fit_srcline
312 #define fi_flags fi_fit.fit_flags
313 #define fi_lastc fi_fit.fit_lastc
314 #define fi_path fi_fit.fit_path
315 #define fi_prefix fi_fit.fit_prefix
316
317 /* flags */
318 #define FI_SEL 0x01 /* selected */
319 #define FI_NEEDSCOUNT 0x02 /* needs-count */
320 #define FI_NEEDSFLAG 0x04 /* needs-flag */
321 #define FI_HIDDEN 0x08 /* obscured by other(s), base names overlap */
322
323 /*
324 * Objects and libraries. This allows precompiled object and library
325 * files (e.g. binary-only device drivers) to be linked in.
326 */
327 struct objects {
328 struct filetype oi_fit;
329 TAILQ_ENTRY(objects) oi_next;
330 struct nvlist *oi_optx;/* options expression */
331 struct nvlist *oi_optf;/* flattened version of above, if needed */
332 };
333
334 #define oi_srcfile oi_fit.fit_srcfile
335 #define oi_srcline oi_fit.fit_srcline
336 #define oi_flags oi_fit.fit_flags
337 #define oi_lastc oi_fit.fit_lastc
338 #define oi_path oi_fit.fit_path
339 #define oi_prefix oi_fit.fit_prefix
340
341 /* flags */
342 #define OI_SEL 0x01 /* selected */
343 #define OI_NEEDSFLAG 0x02 /* needs-flag */
344
345 #define FX_ATOM 0 /* atom (in nv_name) */
346 #define FX_NOT 1 /* NOT expr (subexpression in nv_next) */
347 #define FX_AND 2 /* AND expr (lhs in nv_ptr, rhs in nv_next) */
348 #define FX_OR 3 /* OR expr (lhs in nv_ptr, rhs in nv_next) */
349
350 /*
351 * File/object prefixes. These are arranged in a stack, and affect
352 * the behavior of the source path.
353 */
354 struct prefix {
355 SLIST_ENTRY(prefix) pf_next; /* next prefix in stack */
356 const char *pf_prefix; /* the actual prefix */
357 };
358
359 /*
360 * Device major informations.
361 */
362 struct devm {
363 TAILQ_ENTRY(devm) dm_next;
364 const char *dm_srcfile; /* the name of the "majors" file */
365 u_short dm_srcline; /* the line number */
366 const char *dm_name; /* [bc]devsw name */
367 int dm_cmajor; /* character major */
368 int dm_bmajor; /* block major */
369 struct nvlist *dm_opts; /* options */
370 };
371
372 /*
373 * Hash tables look up name=value pairs. The pointer value of the name
374 * is assumed to be constant forever; this can be arranged by interning
375 * the name. (This is fairly convenient since our lexer does this for
376 * all identifier-like strings---it has to save them anyway, lest yacc's
377 * look-ahead wipe out the current one.)
378 */
379 struct hashtab;
380
381 int lkmmode;
382 const char *conffile; /* source file, e.g., "GENERIC.sparc" */
383 const char *machine; /* machine type, e.g., "sparc" or "sun3" */
384 const char *machinearch; /* machine arch, e.g., "sparc" or "m68k" */
385 struct nvlist *machinesubarches;
386 /* machine subarches, e.g., "sun68k" or "hpc" */
387 const char *srcdir; /* path to source directory (rel. to build) */
388 const char *builddir; /* path to build directory */
389 const char *defbuilddir; /* default build directory */
390 const char *ident; /* kernel "ident"ification string */
391 int errors; /* counts calls to error() */
392 int minmaxusers; /* minimum "maxusers" parameter */
393 int defmaxusers; /* default "maxusers" parameter */
394 int maxmaxusers; /* default "maxusers" parameter */
395 int maxusers; /* configuration's "maxusers" parameter */
396 int maxpartitions; /* configuration's "maxpartitions" parameter */
397 int version; /* version of the configuration file */
398 struct nvlist *options; /* options */
399 struct nvlist *fsoptions; /* filesystems */
400 struct nvlist *mkoptions; /* makeoptions */
401 struct nvlist *appmkoptions; /* appending mkoptions */
402 struct hashtab *condmkopttab; /* conditional makeoption table */
403 struct hashtab *devbasetab; /* devbase lookup */
404 struct hashtab *devroottab; /* attach at root lookup */
405 struct hashtab *devatab; /* devbase attachment lookup */
406 struct hashtab *devitab; /* device instance lookup */
407 struct hashtab *deaddevitab; /* removed instances lookup */
408 struct hashtab *selecttab; /* selects things that are "optional foo" */
409 struct hashtab *needcnttab; /* retains names marked "needs-count" */
410 struct hashtab *opttab; /* table of configured options */
411 struct hashtab *fsopttab; /* table of configured file systems */
412 struct hashtab *defopttab; /* options that have been "defopt"'d */
413 struct hashtab *defflagtab; /* options that have been "defflag"'d */
414 struct hashtab *defparamtab; /* options that have been "defparam"'d */
415 struct hashtab *deffstab; /* defined file systems */
416 struct hashtab *optfiletab; /* "defopt"'d option .h files */
417 struct hashtab *attrtab; /* attributes (locators, etc.) */
418 struct hashtab *bdevmtab; /* block devm lookup */
419 struct hashtab *cdevmtab; /* character devm lookup */
420
421 TAILQ_HEAD(, devbase) allbases; /* list of all devbase structures */
422 TAILQ_HEAD(, deva) alldevas; /* list of all devbase attachments */
423 TAILQ_HEAD(, config) allcf; /* list of configured kernels */
424 TAILQ_HEAD(, devi) alldevi, /* list of all instances */
425 allpseudo; /* list of all pseudo-devices */
426 TAILQ_HEAD(, devm) alldevms; /* list of all device-majors */
427 TAILQ_HEAD(, pspec) allpspecs; /* list of all parent specs */
428 int ndevi; /* number of devi's (before packing) */
429 int npspecs; /* number of parent specs */
430 int maxbdevm; /* max number of block major */
431 int maxcdevm; /* max number of character major */
432 int do_devsw; /* 0 if pre-devsw config */
433 int oktopackage; /* 0 before setmachine() */
434 int devilevel; /* used for devi->i_level */
435
436 TAILQ_HEAD(, files) allfiles; /* list of all kernel source files */
437 TAILQ_HEAD(, objects) allobjects; /* list of all kernel object and
438 library files */
439
440 SLIST_HEAD(, prefix) prefixes, /* prefix stack */
441 allprefixes; /* all prefixes used (after popped) */
442 SLIST_HEAD(, prefix) curdirs; /* curdir stack */
443
444 struct devi **packed; /* arrayified table for packed devi's */
445 int npacked; /* size of packed table, <= ndevi */
446
447 struct { /* loc[] table for config */
448 const char **vec;
449 int used;
450 } locators;
451
452 struct numconst {
453 int64_t val;
454 int fmt;
455 };
456
457 /* files.c */
458 void initfiles(void);
459 void checkfiles(void);
460 int fixfiles(void); /* finalize */
461 int fixobjects(void);
462 int fixdevsw(void);
463 void addfile(const char *, struct nvlist *, int, const char *);
464 void addobject(const char *, struct nvlist *, int);
465
466 /* hash.c */
467 struct hashtab *ht_new(void);
468 int ht_insrep(struct hashtab *, const char *, void *, int);
469 #define ht_insert(ht, nam, val) ht_insrep(ht, nam, val, 0)
470 #define ht_replace(ht, nam, val) ht_insrep(ht, nam, val, 1)
471 int ht_remove(struct hashtab *, const char *);
472 void *ht_lookup(struct hashtab *, const char *);
473 void initintern(void);
474 const char *intern(const char *);
475 typedef int (*ht_callback)(const char *, void *, void *);
476 int ht_enumerate(struct hashtab *, ht_callback, void *);
477
478 /* main.c */
479 void addoption(const char *, const char *);
480 void addfsoption(const char *);
481 void addmkoption(const char *, const char *);
482 void appendmkoption(const char *, const char *);
483 void appendcondmkoption(const char *, const char *, const char *);
484 void deffilesystem(const char *, struct nvlist *);
485 void defoption(const char *, struct nvlist *, struct nvlist *);
486 void defflag(const char *, struct nvlist *, struct nvlist *);
487 void defparam(const char *, struct nvlist *, struct nvlist *);
488 void deloption(const char *);
489 void delfsoption(const char *);
490 void delmkoption(const char *);
491 int devbase_has_instances(struct devbase *, int);
492 struct nvlist * find_declared_option(const char *);
493 int deva_has_instances(struct deva *, int);
494 void setupdirs(void);
495
496 /* tests on option types */
497 #define OPT_FSOPT(n) (ht_lookup(deffstab, (n)) != NULL)
498 #define OPT_DEFOPT(n) (ht_lookup(defopttab, (n)) != NULL)
499 #define OPT_DEFFLAG(n) (ht_lookup(defflagtab, (n)) != NULL)
500 #define OPT_DEFPARAM(n) (ht_lookup(defparamtab, (n)) != NULL)
501 #define DEFINED_OPTION(n) (find_declared_option((n)) != NULL)
502
503 /* main.c */
504 void logconfig_include(FILE *, const char *);
505
506 /* mkdevsw.c */
507 int mkdevsw(void);
508
509 /* mkheaders.c */
510 int mkheaders(void);
511 int moveifchanged(const char *, const char *);
512
513 /* mkioconf.c */
514 int mkioconf(void);
515
516 /* mkmakefile.c */
517 int mkmakefile(void);
518
519 /* mkswap.c */
520 int mkswap(void);
521
522 /* pack.c */
523 void pack(void);
524
525 /* scan.l */
526 int currentline(void);
527 int firstfile(const char *);
528 void package(const char *);
529 int include(const char *, int, int, int);
530
531 /* sem.c, other than for yacc actions */
532 void initsem(void);
533
534 /* util.c */
535 void *ecalloc(size_t, size_t);
536 void *emalloc(size_t);
537 void *erealloc(void *, size_t);
538 char *estrdup(const char *);
539 void prefix_push(const char *);
540 void prefix_pop(void);
541 char *sourcepath(const char *);
542 void warn(const char *, ...) /* immediate warns */
543 __attribute__((__format__(__printf__, 1, 2)));
544 void xwarn(const char *, int, const char *, ...) /* delayed warns */
545 __attribute__((__format__(__printf__, 3, 4)));
546 void error(const char *, ...) /* immediate errs */
547 __attribute__((__format__(__printf__, 1, 2)));
548 void xerror(const char *, int, const char *, ...) /* delayed errs */
549 __attribute__((__format__(__printf__, 3, 4)));
550 __dead void panic(const char *, ...)
551 __attribute__((__format__(__printf__, 1, 2)));
552 struct nvlist *newnv(const char *, const char *, void *, int, struct nvlist *);
553 void nvfree(struct nvlist *);
554 void nvfreel(struct nvlist *);
555
556 /* liby */
557 void yyerror(const char *);
558 int yylex(void);
559