Print this page
9696 add /etc/system.d support
Reviewed by: Dan Fields <dan.fields@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Cynthia Eastham <cynthia.eastham@nexenta.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Peter Tribble <peter.tribble@gmail.com>
Reviewed by: Andy Fiddaman <andy@omniosce.org>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/os/modsysfile.c
+++ new/usr/src/uts/common/os/modsysfile.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 - * Copyright 2016 Nexenta Systems, Inc.
25 + * Copyright 2017 Nexenta Systems, Inc.
26 26 */
27 27
28 28 #include <sys/types.h>
29 29 #include <sys/inttypes.h>
30 30 #include <sys/param.h>
31 31 #include <sys/systm.h>
32 32 #include <sys/user.h>
33 33 #include <sys/disp.h>
34 34 #include <sys/conf.h>
35 35 #include <sys/bootconf.h>
36 36 #include <sys/sysconf.h>
37 37 #include <sys/sunddi.h>
38 38 #include <sys/esunddi.h>
39 39 #include <sys/ddi_impldefs.h>
40 40 #include <sys/kmem.h>
41 41 #include <sys/vmem.h>
42 42 #include <sys/fs/ufs_fsdir.h>
43 43 #include <sys/hwconf.h>
44 44 #include <sys/modctl.h>
45 45 #include <sys/cmn_err.h>
46 46 #include <sys/kobj.h>
47 47 #include <sys/kobj_lex.h>
48 48 #include <sys/errno.h>
49 49 #include <sys/debug.h>
50 50 #include <sys/autoconf.h>
51 51 #include <sys/callb.h>
52 52 #include <sys/sysmacros.h>
53 53 #include <sys/dacf.h>
54 54 #include <vm/seg_kmem.h>
55 55
56 56 struct hwc_class *hcl_head; /* head of list of classes */
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
57 57 static kmutex_t hcl_lock; /* for accessing list of classes */
58 58
59 59 #define DAFILE "/etc/driver_aliases"
60 60 #define CLASSFILE "/etc/driver_classes"
61 61 #define DACFFILE "/etc/dacf.conf"
62 62
63 63 static char class_file[] = CLASSFILE;
64 64 static char dafile[] = DAFILE;
65 65 static char dacffile[] = DACFFILE;
66 66
67 +char *self_assembly = "/etc/system.d/.self-assembly";
67 68 char *systemfile = "/etc/system"; /* name of ascii system file */
68 69
69 70 static struct sysparam *sysparam_hd; /* head of parameters list */
70 71 static struct sysparam *sysparam_tl; /* tail of parameters list */
71 72 static vmem_t *mod_sysfile_arena; /* parser memory */
72 73
73 74 char obp_bootpath[BO_MAXOBJNAME]; /* bootpath from obp */
74 75
75 76 #if defined(_PSM_MODULES)
76 77
77 78 struct psm_mach {
78 79 struct psm_mach *m_next;
79 80 char *m_machname;
80 81 };
81 82
82 83 static struct psm_mach *pmach_head; /* head of list of classes */
83 84
84 85 #define MACHFILE "/etc/mach"
85 86 static char mach_file[] = MACHFILE;
86 87
87 88 #endif /* _PSM_MODULES */
88 89
89 90 #if defined(_RTC_CONFIG)
90 91 static char rtc_config_file[] = "/etc/rtc_config";
91 92 #endif
92 93
93 94 static void sys_set_var(int, struct sysparam *, void *);
94 95
95 96 static void setparams(void);
96 97
97 98 /*
98 99 * driver.conf parse thread control structure
99 100 */
100 101 struct hwc_parse_mt {
101 102 ksema_t sema;
102 103 char *name; /* name of .conf files */
103 104 struct par_list **pl; /* parsed parent list */
104 105 ddi_prop_t **props; /* parsed properties */
105 106 int rv; /* return value */
106 107 };
107 108
108 109 static int hwc_parse_now(char *, struct par_list **, ddi_prop_t **);
109 110 static void hwc_parse_thread(struct hwc_parse_mt *);
110 111 static struct hwc_parse_mt *hwc_parse_mtalloc(char *, struct par_list **,
111 112 ddi_prop_t **);
112 113 static void hwc_parse_mtfree(struct hwc_parse_mt *);
113 114 static void add_spec(struct hwc_spec *, struct par_list **);
114 115 static void add_props(struct hwc_spec *, ddi_prop_t **);
115 116
116 117 static void check_system_file(void);
117 118 static int sysparam_compare_entry(struct sysparam *, struct sysparam *);
118 119 static char *sysparam_type_to_str(int);
119 120 static void sysparam_count_entry(struct sysparam *, int *, u_longlong_t *);
120 121 static void sysparam_print_warning(struct sysparam *, u_longlong_t);
121 122
122 123 #ifdef DEBUG
123 124 static int parse_debug_on = 0;
124 125
125 126 /*VARARGS1*/
126 127 static void
127 128 parse_debug(struct _buf *file, char *fmt, ...)
128 129 {
129 130 va_list adx;
130 131
131 132 if (parse_debug_on) {
132 133 va_start(adx, fmt);
133 134 vprintf(fmt, adx);
134 135 if (file)
135 136 printf(" on line %d of %s\n", kobj_linenum(file),
136 137 kobj_filename(file));
137 138 va_end(adx);
138 139 }
139 140 }
140 141 #endif /* DEBUG */
141 142
142 143 #define FE_BUFLEN 256
143 144
144 145 /*PRINTFLIKE3*/
145 146 void
146 147 kobj_file_err(int type, struct _buf *file, char *fmt, ...)
147 148 {
148 149 va_list ap;
149 150 /*
150 151 * If we're in trouble, we might be short on stack... be paranoid
151 152 */
152 153 char *buf = kmem_alloc(FE_BUFLEN, KM_SLEEP);
153 154 char *trailer = kmem_alloc(FE_BUFLEN, KM_SLEEP);
154 155 char *fmt_str = kmem_alloc(FE_BUFLEN, KM_SLEEP);
155 156 char prefix = '\0';
156 157
157 158 va_start(ap, fmt);
158 159 if (strchr("^!?", fmt[0]) != NULL) {
159 160 prefix = fmt[0];
160 161 fmt++;
161 162 }
162 163 (void) vsnprintf(buf, FE_BUFLEN, fmt, ap);
163 164 va_end(ap);
164 165 (void) snprintf(trailer, FE_BUFLEN, " on line %d of %s",
165 166 kobj_linenum(file), kobj_filename(file));
166 167
167 168 /*
168 169 * If prefixed with !^?, prepend that character
169 170 */
170 171 if (prefix != '\0') {
171 172 (void) snprintf(fmt_str, FE_BUFLEN, "%c%%s%%s", prefix);
172 173 } else {
173 174 (void) strncpy(fmt_str, "%s%s", FE_BUFLEN);
174 175 }
175 176
176 177 cmn_err(type, fmt_str, buf, trailer);
177 178 kmem_free(buf, FE_BUFLEN);
178 179 kmem_free(trailer, FE_BUFLEN);
179 180 kmem_free(fmt_str, FE_BUFLEN);
180 181 }
181 182
182 183 #ifdef DEBUG
183 184 char *tokennames[] = {
184 185 "UNEXPECTED",
185 186 "EQUALS",
186 187 "AMPERSAND",
187 188 "BIT_OR",
188 189 "STAR",
189 190 "POUND",
190 191 "COLON",
191 192 "SEMICOLON",
192 193 "COMMA",
193 194 "SLASH",
194 195 "WHITE_SPACE",
195 196 "NEWLINE",
196 197 "EOF",
197 198 "STRING",
198 199 "HEXVAL",
199 200 "DECVAL",
200 201 "NAME"
201 202 };
202 203 #endif /* DEBUG */
203 204
204 205 token_t
205 206 kobj_lex(struct _buf *file, char *val, size_t size)
206 207 {
207 208 char *cp;
208 209 int ch, oval, badquote;
209 210 size_t remain;
210 211 token_t token = UNEXPECTED;
211 212
212 213 if (size < 2)
213 214 return (token); /* this token is UNEXPECTED */
214 215
215 216 cp = val;
216 217 while ((ch = kobj_getc(file)) == ' ' || ch == '\t')
217 218 ;
218 219
219 220 remain = size - 1;
220 221 *cp++ = (char)ch;
221 222 switch (ch) {
222 223 case '=':
223 224 token = EQUALS;
224 225 break;
225 226 case '&':
226 227 token = AMPERSAND;
227 228 break;
228 229 case '|':
229 230 token = BIT_OR;
230 231 break;
231 232 case '*':
232 233 token = STAR;
233 234 break;
234 235 case '#':
235 236 token = POUND;
236 237 break;
237 238 case ':':
238 239 token = COLON;
239 240 break;
240 241 case ';':
241 242 token = SEMICOLON;
242 243 break;
243 244 case ',':
244 245 token = COMMA;
245 246 break;
246 247 case '/':
247 248 token = SLASH;
248 249 break;
249 250 case ' ':
250 251 case '\t':
251 252 case '\f':
252 253 while ((ch = kobj_getc(file)) == ' ' ||
253 254 ch == '\t' || ch == '\f') {
254 255 if (--remain == 0) {
255 256 token = UNEXPECTED;
256 257 goto out;
257 258 }
258 259 *cp++ = (char)ch;
259 260 }
260 261 (void) kobj_ungetc(file);
261 262 token = WHITE_SPACE;
262 263 break;
263 264 case '\n':
264 265 case '\r':
265 266 token = NEWLINE;
266 267 break;
267 268 case '"':
268 269 remain++;
269 270 cp--;
270 271 badquote = 0;
271 272 while (!badquote && (ch = kobj_getc(file)) != '"') {
272 273 switch (ch) {
273 274 case '\n':
274 275 case -1:
275 276 kobj_file_err(CE_WARN, file, "Missing \"");
276 277 remain = size - 1;
277 278 cp = val;
278 279 *cp++ = '\n';
279 280 badquote = 1;
280 281 /* since we consumed the newline/EOF */
281 282 (void) kobj_ungetc(file);
282 283 break;
283 284
284 285 case '\\':
285 286 if (--remain == 0) {
286 287 token = UNEXPECTED;
287 288 goto out;
288 289 }
289 290 ch = (char)kobj_getc(file);
290 291 if (!isdigit(ch)) {
291 292 /* escape the character */
292 293 *cp++ = (char)ch;
293 294 break;
294 295 }
295 296 oval = 0;
296 297 while (ch >= '0' && ch <= '7') {
297 298 ch -= '0';
298 299 oval = (oval << 3) + ch;
299 300 ch = (char)kobj_getc(file);
300 301 }
301 302 (void) kobj_ungetc(file);
302 303 /* check for character overflow? */
303 304 if (oval > 127) {
304 305 cmn_err(CE_WARN,
305 306 "Character "
306 307 "overflow detected.");
307 308 }
308 309 *cp++ = (char)oval;
309 310 break;
310 311 default:
311 312 if (--remain == 0) {
312 313 token = UNEXPECTED;
313 314 goto out;
314 315 }
315 316 *cp++ = (char)ch;
316 317 break;
317 318 }
318 319 }
319 320 token = STRING;
320 321 break;
321 322
322 323 case -1:
323 324 token = EOF;
324 325 break;
325 326
326 327 default:
327 328 /*
328 329 * detect a lone '-' (including at the end of a line), and
329 330 * identify it as a 'name'
330 331 */
331 332 if (ch == '-') {
332 333 if (--remain == 0) {
333 334 token = UNEXPECTED;
334 335 goto out;
335 336 }
336 337 *cp++ = (char)(ch = kobj_getc(file));
337 338 if (iswhite(ch) || (ch == '\n')) {
338 339 (void) kobj_ungetc(file);
339 340 remain++;
340 341 cp--;
341 342 token = NAME;
342 343 break;
343 344 }
344 345 } else if (isunary(ch)) {
345 346 if (--remain == 0) {
346 347 token = UNEXPECTED;
347 348 goto out;
348 349 }
349 350 *cp++ = (char)(ch = kobj_getc(file));
350 351 }
351 352
352 353
353 354 if (isdigit(ch)) {
354 355 if (ch == '0') {
355 356 if ((ch = kobj_getc(file)) == 'x') {
356 357 if (--remain == 0) {
357 358 token = UNEXPECTED;
358 359 goto out;
359 360 }
360 361 *cp++ = (char)ch;
361 362 ch = kobj_getc(file);
362 363 while (isxdigit(ch)) {
363 364 if (--remain == 0) {
364 365 token = UNEXPECTED;
365 366 goto out;
366 367 }
367 368 *cp++ = (char)ch;
368 369 ch = kobj_getc(file);
369 370 }
370 371 (void) kobj_ungetc(file);
371 372 token = HEXVAL;
372 373 } else {
373 374 goto digit;
374 375 }
375 376 } else {
376 377 ch = kobj_getc(file);
377 378 digit:
378 379 while (isdigit(ch)) {
379 380 if (--remain == 0) {
380 381 token = UNEXPECTED;
381 382 goto out;
382 383 }
383 384 *cp++ = (char)ch;
384 385 ch = kobj_getc(file);
385 386 }
386 387 (void) kobj_ungetc(file);
387 388 token = DECVAL;
388 389 }
389 390 } else if (isalpha(ch) || ch == '\\' || ch == '_') {
390 391 if (ch != '\\') {
391 392 ch = kobj_getc(file);
392 393 } else {
393 394 /*
394 395 * if the character was a backslash,
395 396 * back up so we can overwrite it with
396 397 * the next (i.e. escaped) character.
397 398 */
398 399 remain++;
399 400 cp--;
400 401 }
401 402 while (isnamechar(ch) || ch == '\\') {
402 403 if (ch == '\\')
403 404 ch = kobj_getc(file);
404 405 if (--remain == 0) {
405 406 token = UNEXPECTED;
406 407 goto out;
407 408 }
408 409 *cp++ = (char)ch;
409 410 ch = kobj_getc(file);
410 411 }
411 412 (void) kobj_ungetc(file);
412 413 token = NAME;
413 414 } else {
414 415 token = UNEXPECTED;
415 416 }
416 417 break;
417 418 }
418 419 out:
419 420 *cp = '\0';
420 421
421 422 #ifdef DEBUG
422 423 /*
423 424 * The UNEXPECTED token is the first element of the tokennames array,
424 425 * but its token value is -1. Adjust the value by adding one to it
425 426 * to change it to an index of the array.
426 427 */
427 428 parse_debug(NULL, "kobj_lex: token %s value '%s'\n",
428 429 tokennames[token+1], val);
429 430 #endif
430 431 return (token);
431 432 }
432 433
433 434 /*
434 435 * Leave NEWLINE as the next character.
435 436 */
436 437
437 438 void
438 439 kobj_find_eol(struct _buf *file)
439 440 {
440 441 int ch;
441 442
442 443 while ((ch = kobj_getc(file)) != -1) {
443 444 if (isnewline(ch)) {
444 445 (void) kobj_ungetc(file);
445 446 break;
446 447 }
447 448 }
448 449 }
449 450
450 451 /*
451 452 * The ascii system file is read and processed.
452 453 *
453 454 * The syntax of commands is as follows:
454 455 *
455 456 * '*' in column 1 is a comment line.
456 457 * <command> : <value>
457 458 *
458 459 * command is EXCLUDE, INCLUDE, FORCELOAD, ROOTDEV, ROOTFS,
459 460 * SWAPDEV, SWAPFS, MODDIR, SET
460 461 *
461 462 * value is an ascii string meaningful for the command.
462 463 */
463 464
464 465 /*
465 466 * Table of commands
466 467 */
467 468 static struct modcmd modcmd[] = {
468 469 { "EXCLUDE", MOD_EXCLUDE },
469 470 { "exclude", MOD_EXCLUDE },
470 471 { "INCLUDE", MOD_INCLUDE },
471 472 { "include", MOD_INCLUDE },
472 473 { "FORCELOAD", MOD_FORCELOAD },
473 474 { "forceload", MOD_FORCELOAD },
474 475 { "ROOTDEV", MOD_ROOTDEV },
475 476 { "rootdev", MOD_ROOTDEV },
476 477 { "ROOTFS", MOD_ROOTFS },
477 478 { "rootfs", MOD_ROOTFS },
478 479 { "SWAPDEV", MOD_SWAPDEV },
479 480 { "swapdev", MOD_SWAPDEV },
480 481 { "SWAPFS", MOD_SWAPFS },
481 482 { "swapfs", MOD_SWAPFS },
482 483 { "MODDIR", MOD_MODDIR },
483 484 { "moddir", MOD_MODDIR },
484 485 { "SET", MOD_SET },
485 486 { "set", MOD_SET },
486 487 { "SET32", MOD_SET32 },
487 488 { "set32", MOD_SET32 },
488 489 { "SET64", MOD_SET64 },
489 490 { "set64", MOD_SET64 },
490 491 { NULL, MOD_UNKNOWN }
491 492 };
492 493
493 494
494 495 static char bad_op[] = "illegal operator '%s' used on a string";
495 496 static char colon_err[] = "A colon (:) must follow the '%s' command";
496 497 static char tok_err[] = "Unexpected token '%s'";
497 498 static char extra_err[] = "extraneous input ignored starting at '%s'";
498 499 static char oversize_err[] = "value too long";
499 500
500 501 static struct sysparam *
501 502 do_sysfile_cmd(struct _buf *file, const char *cmd)
502 503 {
503 504 struct sysparam *sysp;
504 505 struct modcmd *mcp;
505 506 token_t token, op;
506 507 char *cp;
507 508 int ch;
508 509 char tok1[MOD_MAXPATH + 1]; /* used to read the path set by 'moddir' */
509 510 char tok2[64];
510 511
511 512 for (mcp = modcmd; mcp->mc_cmdname != NULL; mcp++) {
512 513 if (strcmp(mcp->mc_cmdname, cmd) == 0)
513 514 break;
514 515 }
515 516 sysp = vmem_alloc(mod_sysfile_arena, sizeof (struct sysparam),
516 517 VM_SLEEP);
517 518 bzero(sysp, sizeof (struct sysparam));
518 519 sysp->sys_op = SETOP_NONE; /* set op to noop initially */
519 520
520 521 switch (sysp->sys_type = mcp->mc_type) {
521 522 case MOD_INCLUDE:
522 523 case MOD_EXCLUDE:
523 524 case MOD_FORCELOAD:
524 525 /*
525 526 * Are followed by colon.
526 527 */
527 528 case MOD_ROOTFS:
528 529 case MOD_SWAPFS:
529 530 if ((token = kobj_lex(file, tok1, sizeof (tok1))) == COLON) {
530 531 token = kobj_lex(file, tok1, sizeof (tok1));
531 532 } else {
532 533 kobj_file_err(CE_WARN, file, colon_err, cmd);
533 534 }
534 535 if (token != NAME) {
535 536 kobj_file_err(CE_WARN, file, "value expected");
536 537 goto bad;
537 538 }
538 539
539 540 cp = tok1 + strlen(tok1);
540 541 while ((ch = kobj_getc(file)) != -1 && !iswhite(ch) &&
541 542 !isnewline(ch)) {
542 543 if (cp - tok1 >= sizeof (tok1) - 1) {
543 544 kobj_file_err(CE_WARN, file, oversize_err);
544 545 goto bad;
545 546 }
546 547 *cp++ = (char)ch;
547 548 }
548 549 *cp = '\0';
549 550
550 551 if (ch != -1)
551 552 (void) kobj_ungetc(file);
552 553 if (sysp->sys_type == MOD_INCLUDE)
553 554 return (NULL);
554 555 sysp->sys_ptr = vmem_alloc(mod_sysfile_arena, strlen(tok1) + 1,
555 556 VM_SLEEP);
556 557 (void) strcpy(sysp->sys_ptr, tok1);
557 558 break;
558 559 case MOD_SET:
559 560 case MOD_SET64:
560 561 case MOD_SET32:
561 562 {
562 563 char *var;
563 564 token_t tok3;
564 565
565 566 if (kobj_lex(file, tok1, sizeof (tok1)) != NAME) {
566 567 kobj_file_err(CE_WARN, file, "value expected");
567 568 goto bad;
568 569 }
569 570
570 571 /*
571 572 * If the next token is a colon (:),
572 573 * we have the <modname>:<variable> construct.
573 574 */
574 575 if ((token = kobj_lex(file, tok2, sizeof (tok2))) == COLON) {
575 576 if ((token = kobj_lex(file, tok2,
576 577 sizeof (tok2))) == NAME) {
577 578 var = tok2;
578 579 /*
579 580 * Save the module name.
580 581 */
581 582 sysp->sys_modnam = vmem_alloc(mod_sysfile_arena,
582 583 strlen(tok1) + 1, VM_SLEEP);
583 584 (void) strcpy(sysp->sys_modnam, tok1);
584 585 op = kobj_lex(file, tok1, sizeof (tok1));
585 586 } else {
586 587 kobj_file_err(CE_WARN, file, "value expected");
587 588 goto bad;
588 589 }
589 590 } else {
590 591 /* otherwise, it was the op */
591 592 var = tok1;
592 593 op = token;
593 594 }
594 595 /*
595 596 * kernel param - place variable name in sys_ptr.
596 597 */
597 598 sysp->sys_ptr = vmem_alloc(mod_sysfile_arena, strlen(var) + 1,
598 599 VM_SLEEP);
599 600 (void) strcpy(sysp->sys_ptr, var);
600 601 /* set operation */
601 602 switch (op) {
602 603 case EQUALS:
603 604 /* simple assignment */
604 605 sysp->sys_op = SETOP_ASSIGN;
605 606 break;
606 607 case AMPERSAND:
607 608 /* bitwise AND */
608 609 sysp->sys_op = SETOP_AND;
609 610 break;
610 611 case BIT_OR:
611 612 /* bitwise OR */
612 613 sysp->sys_op = SETOP_OR;
613 614 break;
614 615 default:
615 616 /* unsupported operation */
616 617 kobj_file_err(CE_WARN, file,
617 618 "unsupported operator %s", tok2);
618 619 goto bad;
619 620 }
620 621
621 622 switch ((tok3 = kobj_lex(file, tok1, sizeof (tok1)))) {
622 623 case STRING:
623 624 /* string variable */
624 625 if (sysp->sys_op != SETOP_ASSIGN) {
625 626 kobj_file_err(CE_WARN, file, bad_op, tok1);
626 627 goto bad;
627 628 }
628 629 if (kobj_get_string(&sysp->sys_info, tok1) == 0) {
629 630 kobj_file_err(CE_WARN, file, "string garbled");
630 631 goto bad;
631 632 }
632 633 /*
633 634 * Set SYSPARAM_STR_TOKEN in sys_flags to notify
634 635 * sysparam_print_warning() that this is a string
635 636 * token.
636 637 */
637 638 sysp->sys_flags |= SYSPARAM_STR_TOKEN;
638 639 break;
639 640 case HEXVAL:
640 641 case DECVAL:
641 642 if (kobj_getvalue(tok1, &sysp->sys_info) == -1) {
642 643 kobj_file_err(CE_WARN, file,
643 644 "invalid number '%s'", tok1);
644 645 goto bad;
645 646 }
646 647
647 648 /*
648 649 * Set the appropriate flag (hexadecimal or decimal)
649 650 * in sys_flags for sysparam_print_warning() to be
650 651 * able to print the number with the correct format.
651 652 */
652 653 if (tok3 == HEXVAL) {
653 654 sysp->sys_flags |= SYSPARAM_HEX_TOKEN;
654 655 } else {
655 656 sysp->sys_flags |= SYSPARAM_DEC_TOKEN;
656 657 }
657 658 break;
658 659 default:
659 660 kobj_file_err(CE_WARN, file, "bad rvalue '%s'", tok1);
660 661 goto bad;
661 662 } /* end switch */
662 663
663 664 /*
664 665 * Now that we've parsed it to check the syntax, consider
665 666 * discarding it (because it -doesn't- apply to this flavor
666 667 * of the kernel)
667 668 */
668 669 #ifdef _LP64
669 670 if (sysp->sys_type == MOD_SET32)
670 671 return (NULL);
671 672 #else
672 673 if (sysp->sys_type == MOD_SET64)
673 674 return (NULL);
674 675 #endif
675 676 sysp->sys_type = MOD_SET;
676 677 break;
677 678 }
678 679 case MOD_MODDIR:
679 680 if ((token = kobj_lex(file, tok1, sizeof (tok1))) != COLON) {
680 681 kobj_file_err(CE_WARN, file, colon_err, cmd);
681 682 goto bad;
682 683 }
683 684
684 685 cp = tok1;
685 686 while ((token = kobj_lex(file, cp,
686 687 sizeof (tok1) - (cp - tok1))) != NEWLINE && token != EOF) {
687 688 if (token == -1) {
688 689 kobj_file_err(CE_WARN, file, oversize_err);
689 690 goto bad;
690 691 }
691 692 cp += strlen(cp);
692 693 while ((ch = kobj_getc(file)) != -1 && !iswhite(ch) &&
693 694 !isnewline(ch) && ch != ':') {
694 695 if (cp - tok1 >= sizeof (tok1) - 1) {
695 696 kobj_file_err(CE_WARN, file,
696 697 oversize_err);
697 698 goto bad;
698 699 }
699 700 *cp++ = (char)ch;
700 701 }
701 702 *cp++ = ' ';
702 703 if (isnewline(ch)) {
703 704 cp--;
704 705 (void) kobj_ungetc(file);
705 706 }
706 707 }
707 708 (void) kobj_ungetc(file);
708 709 *cp = '\0';
709 710 sysp->sys_ptr = vmem_alloc(mod_sysfile_arena, strlen(tok1) + 1,
710 711 VM_SLEEP);
711 712 (void) strcpy(sysp->sys_ptr, tok1);
712 713 break;
713 714
714 715 case MOD_SWAPDEV:
715 716 case MOD_ROOTDEV:
716 717 if ((token = kobj_lex(file, tok1, sizeof (tok1))) != COLON) {
717 718 kobj_file_err(CE_WARN, file, colon_err, cmd);
718 719 goto bad;
719 720 }
720 721 while ((ch = kobj_getc(file)) == ' ' || ch == '\t')
721 722 ;
722 723 cp = tok1;
723 724 while (!iswhite(ch) && !isnewline(ch) && ch != -1) {
724 725 if (cp - tok1 >= sizeof (tok1) - 1) {
725 726 kobj_file_err(CE_WARN, file, oversize_err);
726 727 goto bad;
727 728 }
728 729
729 730 *cp++ = (char)ch;
730 731 ch = kobj_getc(file);
731 732 }
732 733 if (ch != -1)
733 734 (void) kobj_ungetc(file);
734 735 *cp = '\0';
735 736
736 737 sysp->sys_ptr = vmem_alloc(mod_sysfile_arena, strlen(tok1) + 1,
737 738 VM_SLEEP);
738 739 (void) strcpy(sysp->sys_ptr, tok1);
739 740 break;
740 741
741 742 case MOD_UNKNOWN:
742 743 default:
743 744 kobj_file_err(CE_WARN, file, "unknown command '%s'", cmd);
↓ open down ↓ |
667 lines elided |
↑ open up ↑ |
744 745 goto bad;
745 746 }
746 747
747 748 return (sysp);
748 749
749 750 bad:
750 751 kobj_find_eol(file);
751 752 return (NULL);
752 753 }
753 754
754 -void
755 -mod_read_system_file(int ask)
755 +static void
756 +read_system_file(char *name)
756 757 {
757 758 register struct sysparam *sp;
758 759 register struct _buf *file;
759 760 register token_t token, last_tok;
760 761 char tokval[MAXLINESIZE];
761 762
762 - mod_sysfile_arena = vmem_create("mod_sysfile", NULL, 0, 8,
763 - segkmem_alloc, segkmem_free, heap_arena, 0, VM_SLEEP);
764 -
765 - if (ask)
766 - mod_askparams();
767 -
768 - if (systemfile != NULL) {
769 -
770 - if ((file = kobj_open_file(systemfile)) ==
771 - (struct _buf *)-1) {
763 + if ((file = kobj_open_file(name)) ==
764 + (struct _buf *)-1) {
765 + if (strcmp(name, systemfile) == 0)
772 766 cmn_err(CE_WARN, "cannot open system file: %s",
773 - systemfile);
774 - } else {
767 + name);
768 + } else {
769 + if (sysparam_tl == NULL)
775 770 sysparam_tl = (struct sysparam *)&sysparam_hd;
776 771
777 - last_tok = NEWLINE;
778 - while ((token = kobj_lex(file, tokval,
779 - sizeof (tokval))) != EOF) {
780 - switch (token) {
781 - case STAR:
782 - case POUND:
783 - /*
784 - * Skip comments.
785 - */
772 + last_tok = NEWLINE;
773 + while ((token = kobj_lex(file, tokval,
774 + sizeof (tokval))) != EOF) {
775 + switch (token) {
776 + case STAR:
777 + case POUND:
778 + /*
779 + * Skip comments.
780 + */
781 + kobj_find_eol(file);
782 + break;
783 + case NEWLINE:
784 + kobj_newline(file);
785 + last_tok = NEWLINE;
786 + break;
787 + case NAME:
788 + if (last_tok != NEWLINE) {
789 + kobj_file_err(CE_WARN, file,
790 + extra_err, tokval);
786 791 kobj_find_eol(file);
787 - break;
788 - case NEWLINE:
789 - kobj_newline(file);
790 - last_tok = NEWLINE;
791 - break;
792 - case NAME:
793 - if (last_tok != NEWLINE) {
794 - kobj_file_err(CE_WARN, file,
795 - extra_err, tokval);
796 - kobj_find_eol(file);
797 - } else if ((sp = do_sysfile_cmd(file,
798 - tokval)) != NULL) {
799 - sp->sys_next = NULL;
800 - sysparam_tl->sys_next = sp;
801 - sysparam_tl = sp;
802 - }
803 - last_tok = NAME;
804 - break;
805 - default:
806 - kobj_file_err(CE_WARN,
807 - file, tok_err, tokval);
808 - kobj_find_eol(file);
809 - break;
792 + } else if ((sp = do_sysfile_cmd(file,
793 + tokval)) != NULL) {
794 + sp->sys_next = NULL;
795 + sysparam_tl->sys_next = sp;
796 + sysparam_tl = sp;
810 797 }
798 + last_tok = NAME;
799 + break;
800 + default:
801 + kobj_file_err(CE_WARN,
802 + file, tok_err, tokval);
803 + kobj_find_eol(file);
804 + break;
811 805 }
812 - kobj_close_file(file);
813 806 }
807 + kobj_close_file(file);
814 808 }
809 +}
815 810
811 +void
812 +mod_read_system_file(int ask)
813 +{
814 + mod_sysfile_arena = vmem_create("mod_sysfile", NULL, 0, 8,
815 + segkmem_alloc, segkmem_free, heap_arena, 0, VM_SLEEP);
816 +
817 + if (ask)
818 + mod_askparams();
819 +
816 820 /*
821 + * Read the user self-assembly file first
822 + * to preserve existing system settings.
823 + */
824 + if (self_assembly != NULL)
825 + read_system_file(self_assembly);
826 +
827 + if (systemfile != NULL)
828 + read_system_file(systemfile);
829 +
830 + /*
817 831 * Sanity check of /etc/system.
818 832 */
819 833 check_system_file();
820 834
821 835 param_preset();
822 836 (void) mod_sysctl(SYS_SET_KVAR, NULL);
823 837 param_check();
824 838
825 839 if (ask == 0)
826 840 setparams();
827 841 }
828 842
829 843 /*
830 844 * Search for a specific module variable assignment in /etc/system. If
831 845 * successful, 1 is returned and the value is stored in '*value'.
832 846 * Otherwise 0 is returned and '*value' isn't modified. If 'module' is
833 847 * NULL we look for global definitions.
834 848 *
835 849 * This is useful if the value of an assignment is needed before a
836 850 * module is loaded (e.g. to obtain a default privileged rctl limit).
837 851 */
838 852 int
839 853 mod_sysvar(const char *module, const char *name, u_longlong_t *value)
840 854 {
841 855 struct sysparam *sysp;
842 856 int cnt = 0; /* dummy */
843 857
844 858 ASSERT(name != NULL);
845 859 ASSERT(value != NULL);
846 860 for (sysp = sysparam_hd; sysp != NULL; sysp = sysp->sys_next) {
847 861
848 862 if ((sysp->sys_type == MOD_SET) &&
849 863 (((module == NULL) && (sysp->sys_modnam == NULL)) ||
850 864 ((module != NULL) && (sysp->sys_modnam != NULL) &&
851 865 (strcmp(module, sysp->sys_modnam) == 0)))) {
852 866
853 867 ASSERT(sysp->sys_ptr != NULL);
854 868
855 869 if (strcmp(name, sysp->sys_ptr) == 0) {
856 870 sysparam_count_entry(sysp, &cnt, value);
857 871 if ((sysp->sys_flags & SYSPARAM_TERM) != 0)
858 872 return (1);
859 873 continue;
860 874 }
861 875 }
862 876 }
863 877 ASSERT(cnt == 0);
864 878 return (0);
865 879 }
866 880
867 881 /*
868 882 * This function scans sysparam records, which are created from the
869 883 * contents of /etc/system, for entries which are logical duplicates,
870 884 * and prints warning messages as appropriate. When multiple "set"
871 885 * commands are encountered, the pileup of values with "&", "|"
872 886 * and "=" operators results in the final value.
873 887 */
874 888 static void
875 889 check_system_file(void)
876 890 {
877 891 struct sysparam *sysp;
878 892
879 893 for (sysp = sysparam_hd; sysp != NULL; sysp = sysp->sys_next) {
880 894 struct sysparam *entry, *final;
881 895 u_longlong_t value = 0;
882 896 int cnt = 1;
883 897 /*
884 898 * If the entry is already checked, skip it.
885 899 */
886 900 if ((sysp->sys_flags & SYSPARAM_DUP) != 0)
887 901 continue;
888 902 /*
889 903 * Check if there is a duplicate entry by doing a linear
890 904 * search.
891 905 */
892 906 final = sysp;
893 907 for (entry = sysp->sys_next; entry != NULL;
894 908 entry = entry->sys_next) {
895 909 /*
896 910 * Check the entry. if it's different, skip this.
897 911 */
898 912 if (sysparam_compare_entry(sysp, entry) != 0)
899 913 continue;
900 914 /*
901 915 * Count the entry and put the mark.
902 916 */
903 917 sysparam_count_entry(entry, &cnt, &value);
904 918 entry->sys_flags |= SYSPARAM_DUP;
905 919 final = entry;
906 920 }
907 921 final->sys_flags |= SYSPARAM_TERM;
908 922 /*
909 923 * Print the warning if it's duplicated.
910 924 */
911 925 if (cnt >= 2)
912 926 sysparam_print_warning(final, value);
913 927 }
914 928 }
915 929
916 930 /*
917 931 * Compare the sysparam records.
918 932 * Return 0 if they are the same, return 1 if not.
919 933 */
920 934 static int
921 935 sysparam_compare_entry(struct sysparam *sysp, struct sysparam *entry)
922 936 {
923 937 ASSERT(sysp->sys_ptr != NULL && entry->sys_ptr != NULL);
924 938
925 939 /*
926 940 * If the command is rootdev, rootfs, swapdev, swapfs or moddir,
927 941 * the record with the same type is treated as a duplicate record.
928 942 * In other cases, the record is treated as a duplicate record when
929 943 * its type, its module name (if it exists), and its variable name
930 944 * are the same.
931 945 */
932 946 switch (sysp->sys_type) {
933 947 case MOD_ROOTDEV:
934 948 case MOD_ROOTFS:
935 949 case MOD_SWAPDEV:
936 950 case MOD_SWAPFS:
937 951 case MOD_MODDIR:
938 952 return (sysp->sys_type == entry->sys_type ? 0 : 1);
939 953 default: /* In other cases, just go through it. */
940 954 break;
941 955 }
942 956
943 957 if (sysp->sys_type != entry->sys_type)
944 958 return (1);
945 959
946 960 if (sysp->sys_modnam != NULL && entry->sys_modnam == NULL)
947 961 return (1);
948 962
949 963 if (sysp->sys_modnam == NULL && entry->sys_modnam != NULL)
950 964 return (1);
951 965
952 966 if (sysp->sys_modnam != NULL && entry->sys_modnam != NULL &&
953 967 strcmp(sysp->sys_modnam, entry->sys_modnam) != 0)
954 968 return (1);
955 969
956 970 return (strcmp(sysp->sys_ptr, entry->sys_ptr));
957 971 }
958 972
959 973 /*
960 974 * Translate a sysparam type value to a string.
961 975 */
962 976 static char *
963 977 sysparam_type_to_str(int type)
964 978 {
965 979 struct modcmd *mcp;
966 980
967 981 for (mcp = modcmd; mcp->mc_cmdname != NULL; mcp++) {
968 982 if (mcp->mc_type == type)
969 983 break;
970 984 }
971 985 ASSERT(mcp->mc_type == type);
972 986
973 987 if (type != MOD_UNKNOWN)
974 988 return ((++mcp)->mc_cmdname); /* lower case */
975 989 else
976 990 return (""); /* MOD_UNKNOWN */
977 991 }
978 992
979 993 /*
980 994 * Check the entry and accumulate the number of entries.
981 995 */
982 996 static void
983 997 sysparam_count_entry(struct sysparam *sysp, int *cnt, u_longlong_t *value)
984 998 {
985 999 u_longlong_t ul = sysp->sys_info;
986 1000
987 1001 switch (sysp->sys_op) {
988 1002 case SETOP_ASSIGN:
989 1003 *value = ul;
990 1004 (*cnt)++;
991 1005 return;
992 1006 case SETOP_AND:
993 1007 *value &= ul;
994 1008 return;
995 1009 case SETOP_OR:
996 1010 *value |= ul;
997 1011 return;
998 1012 default: /* Not MOD_SET */
999 1013 (*cnt)++;
1000 1014 return;
1001 1015 }
1002 1016 }
1003 1017
1004 1018 /*
1005 1019 * Print out the warning if multiple entries are found in the system file.
1006 1020 */
1007 1021 static void
1008 1022 sysparam_print_warning(struct sysparam *sysp, u_longlong_t value)
1009 1023 {
1010 1024 char *modnam = sysp->sys_modnam;
1011 1025 char *varnam = sysp->sys_ptr;
1012 1026 int type = sysp->sys_type;
1013 1027 char *typenam = sysparam_type_to_str(type);
1014 1028 boolean_t str_token = ((sysp->sys_flags & SYSPARAM_STR_TOKEN) != 0);
1015 1029 boolean_t hex_number = ((sysp->sys_flags & SYSPARAM_HEX_TOKEN) != 0);
1016 1030 #define warn_format1 " is set more than once in /%s. "
1017 1031 #define warn_format2 " applied as the current setting.\n"
1018 1032
1019 1033 ASSERT(varnam != NULL);
1020 1034
1021 1035 if (type == MOD_SET) {
1022 1036 /*
1023 1037 * If a string token is set, print out the string
1024 1038 * instead of its pointer value. In other cases,
1025 1039 * print out the value with the appropriate format
1026 1040 * for a hexadecimal number or a decimal number.
1027 1041 */
1028 1042 if (modnam == NULL) {
1029 1043 if (str_token == B_TRUE) {
1030 1044 cmn_err(CE_WARN, "%s" warn_format1
1031 1045 "\"%s %s = %s\"" warn_format2,
1032 1046 varnam, systemfile, typenam,
1033 1047 varnam, (char *)(uintptr_t)value);
1034 1048 } else if (hex_number == B_TRUE) {
1035 1049 cmn_err(CE_WARN, "%s" warn_format1
1036 1050 "\"%s %s = 0x%llx\"" warn_format2,
1037 1051 varnam, systemfile, typenam,
1038 1052 varnam, value);
1039 1053 } else {
1040 1054 cmn_err(CE_WARN, "%s" warn_format1
1041 1055 "\"%s %s = %lld\"" warn_format2,
1042 1056 varnam, systemfile, typenam,
1043 1057 varnam, value);
1044 1058 }
1045 1059 } else {
1046 1060 if (str_token == B_TRUE) {
1047 1061 cmn_err(CE_WARN, "%s:%s" warn_format1
1048 1062 "\"%s %s:%s = %s\"" warn_format2,
1049 1063 modnam, varnam, systemfile,
1050 1064 typenam, modnam, varnam,
1051 1065 (char *)(uintptr_t)value);
1052 1066 } else if (hex_number == B_TRUE) {
1053 1067 cmn_err(CE_WARN, "%s:%s" warn_format1
1054 1068 "\"%s %s:%s = 0x%llx\"" warn_format2,
1055 1069 modnam, varnam, systemfile,
1056 1070 typenam, modnam, varnam, value);
1057 1071 } else {
1058 1072 cmn_err(CE_WARN, "%s:%s" warn_format1
1059 1073 "\"%s %s:%s = %lld\"" warn_format2,
1060 1074 modnam, varnam, systemfile,
1061 1075 typenam, modnam, varnam, value);
1062 1076 }
1063 1077 }
1064 1078 } else {
1065 1079 /*
1066 1080 * If the type is MOD_ROOTDEV, MOD_ROOTFS, MOD_SWAPDEV,
1067 1081 * MOD_SWAPFS or MOD_MODDIR, the entry is treated as
1068 1082 * a duplicate one if it has the same type regardless
1069 1083 * of its variable name.
1070 1084 */
1071 1085 switch (type) {
1072 1086 case MOD_ROOTDEV:
1073 1087 case MOD_ROOTFS:
1074 1088 case MOD_SWAPDEV:
1075 1089 case MOD_SWAPFS:
1076 1090 case MOD_MODDIR:
1077 1091 cmn_err(CE_WARN, "\"%s\" appears more than once "
1078 1092 "in /%s.", typenam, systemfile);
1079 1093 break;
1080 1094 default:
1081 1095 cmn_err(CE_NOTE, "\"%s: %s\" appears more than once "
1082 1096 "in /%s.", typenam, varnam, systemfile);
1083 1097 break;
1084 1098 }
1085 1099 }
1086 1100 }
1087 1101
1088 1102 /*
1089 1103 * Process the system file commands.
1090 1104 */
1091 1105 int
1092 1106 mod_sysctl(int fcn, void *p)
1093 1107 {
1094 1108 static char wmesg[] = "forceload of %s failed";
1095 1109 struct sysparam *sysp;
1096 1110 char *name;
1097 1111 struct modctl *modp;
1098 1112
1099 1113 if (sysparam_hd == NULL)
1100 1114 return (0);
1101 1115
1102 1116 for (sysp = sysparam_hd; sysp != NULL; sysp = sysp->sys_next) {
1103 1117
1104 1118 switch (fcn) {
1105 1119
1106 1120 case SYS_FORCELOAD:
1107 1121 if (sysp->sys_type == MOD_FORCELOAD) {
1108 1122 name = sysp->sys_ptr;
1109 1123 if (modload(NULL, name) == -1)
1110 1124 cmn_err(CE_WARN, wmesg, name);
1111 1125 /*
1112 1126 * The following works because it
1113 1127 * runs before autounloading is started!!
1114 1128 */
1115 1129 modp = mod_find_by_filename(NULL, name);
1116 1130 if (modp != NULL)
1117 1131 modp->mod_loadflags |= MOD_NOAUTOUNLOAD;
1118 1132 /*
1119 1133 * For drivers, attempt to install it.
1120 1134 */
1121 1135 if (strncmp(sysp->sys_ptr, "drv", 3) == 0) {
1122 1136 (void) ddi_install_driver(name + 4);
1123 1137 }
1124 1138 }
1125 1139 break;
1126 1140
1127 1141 case SYS_SET_KVAR:
1128 1142 case SYS_SET_MVAR:
1129 1143 if (sysp->sys_type == MOD_SET)
1130 1144 sys_set_var(fcn, sysp, p);
1131 1145 break;
1132 1146
1133 1147 case SYS_CHECK_EXCLUDE:
1134 1148 if (sysp->sys_type == MOD_EXCLUDE) {
1135 1149 if (p == NULL || sysp->sys_ptr == NULL)
1136 1150 return (0);
1137 1151 if (strcmp((char *)p, sysp->sys_ptr) == 0)
1138 1152 return (1);
1139 1153 }
1140 1154 }
1141 1155 }
1142 1156
1143 1157 return (0);
1144 1158 }
1145 1159
1146 1160 /*
1147 1161 * Process the system file commands, by type.
1148 1162 */
1149 1163 int
1150 1164 mod_sysctl_type(int type, int (*func)(struct sysparam *, void *), void *p)
1151 1165 {
1152 1166 struct sysparam *sysp;
1153 1167 int err;
1154 1168
1155 1169 for (sysp = sysparam_hd; sysp != NULL; sysp = sysp->sys_next)
1156 1170 if (sysp->sys_type == type)
1157 1171 if (err = (*(func))(sysp, p))
1158 1172 return (err);
1159 1173 return (0);
1160 1174 }
1161 1175
1162 1176
1163 1177 static char seterr[] = "Symbol %s has size of 0 in symbol table. %s";
1164 1178 static char assumption[] = "Assuming it is an 'int'";
1165 1179 static char defmsg[] = "Trying to set a variable that is of size %d";
1166 1180
1167 1181 static void set_int8_var(uintptr_t, struct sysparam *);
1168 1182 static void set_int16_var(uintptr_t, struct sysparam *);
1169 1183 static void set_int32_var(uintptr_t, struct sysparam *);
1170 1184 static void set_int64_var(uintptr_t, struct sysparam *);
1171 1185
1172 1186 static void
1173 1187 sys_set_var(int fcn, struct sysparam *sysp, void *p)
1174 1188 {
1175 1189 uintptr_t symaddr;
1176 1190 int size;
1177 1191
1178 1192 if (fcn == SYS_SET_KVAR && sysp->sys_modnam == NULL) {
1179 1193 symaddr = kobj_getelfsym(sysp->sys_ptr, NULL, &size);
1180 1194 } else if (fcn == SYS_SET_MVAR) {
1181 1195 if (sysp->sys_modnam == (char *)NULL ||
1182 1196 strcmp(((struct modctl *)p)->mod_modname,
1183 1197 sysp->sys_modnam) != 0)
1184 1198 return;
1185 1199 symaddr = kobj_getelfsym(sysp->sys_ptr,
1186 1200 ((struct modctl *)p)->mod_mp, &size);
1187 1201 } else
1188 1202 return;
1189 1203
1190 1204 if (symaddr != NULL) {
1191 1205 switch (size) {
1192 1206 case 1:
1193 1207 set_int8_var(symaddr, sysp);
1194 1208 break;
1195 1209 case 2:
1196 1210 set_int16_var(symaddr, sysp);
1197 1211 break;
1198 1212 case 0:
1199 1213 cmn_err(CE_WARN, seterr, sysp->sys_ptr, assumption);
1200 1214 /*FALLTHROUGH*/
1201 1215 case 4:
1202 1216 set_int32_var(symaddr, sysp);
1203 1217 break;
1204 1218 case 8:
1205 1219 set_int64_var(symaddr, sysp);
1206 1220 break;
1207 1221 default:
1208 1222 cmn_err(CE_WARN, defmsg, size);
1209 1223 break;
1210 1224 }
1211 1225 } else {
1212 1226 printf("sorry, variable '%s' is not defined in the '%s' ",
1213 1227 sysp->sys_ptr,
1214 1228 sysp->sys_modnam ? sysp->sys_modnam : "kernel");
1215 1229 if (sysp->sys_modnam)
1216 1230 printf("module");
1217 1231 printf("\n");
1218 1232 }
1219 1233 }
1220 1234
1221 1235 static void
1222 1236 set_int8_var(uintptr_t symaddr, struct sysparam *sysp)
1223 1237 {
1224 1238 uint8_t uc = (uint8_t)sysp->sys_info;
1225 1239
1226 1240 if (moddebug & MODDEBUG_LOADMSG)
1227 1241 printf("OP: %x: param '%s' was '0x%" PRIx8
1228 1242 "' in module: '%s'.\n", sysp->sys_op, sysp->sys_ptr,
1229 1243 *(uint8_t *)symaddr, sysp->sys_modnam);
1230 1244
1231 1245 switch (sysp->sys_op) {
1232 1246 case SETOP_ASSIGN:
1233 1247 *(uint8_t *)symaddr = uc;
1234 1248 break;
1235 1249 case SETOP_AND:
1236 1250 *(uint8_t *)symaddr &= uc;
1237 1251 break;
1238 1252 case SETOP_OR:
1239 1253 *(uint8_t *)symaddr |= uc;
1240 1254 break;
1241 1255 }
1242 1256
1243 1257 if (moddebug & MODDEBUG_LOADMSG)
1244 1258 printf("now it is set to '0x%" PRIx8 "'.\n",
1245 1259 *(uint8_t *)symaddr);
1246 1260 }
1247 1261
1248 1262 static void
1249 1263 set_int16_var(uintptr_t symaddr, struct sysparam *sysp)
1250 1264 {
1251 1265 uint16_t us = (uint16_t)sysp->sys_info;
1252 1266
1253 1267 if (moddebug & MODDEBUG_LOADMSG)
1254 1268 printf("OP: %x: param '%s' was '0x%" PRIx16
1255 1269 "' in module: '%s'.\n", sysp->sys_op, sysp->sys_ptr,
1256 1270 *(uint16_t *)symaddr, sysp->sys_modnam);
1257 1271
1258 1272 switch (sysp->sys_op) {
1259 1273 case SETOP_ASSIGN:
1260 1274 *(uint16_t *)symaddr = us;
1261 1275 break;
1262 1276 case SETOP_AND:
1263 1277 *(uint16_t *)symaddr &= us;
1264 1278 break;
1265 1279 case SETOP_OR:
1266 1280 *(uint16_t *)symaddr |= us;
1267 1281 break;
1268 1282 }
1269 1283
1270 1284 if (moddebug & MODDEBUG_LOADMSG)
1271 1285 printf("now it is set to '0x%" PRIx16 "'.\n",
1272 1286 *(uint16_t *)symaddr);
1273 1287 }
1274 1288
1275 1289 static void
1276 1290 set_int32_var(uintptr_t symaddr, struct sysparam *sysp)
1277 1291 {
1278 1292 uint32_t ui = (uint32_t)sysp->sys_info;
1279 1293
1280 1294 if (moddebug & MODDEBUG_LOADMSG)
1281 1295 printf("OP: %x: param '%s' was '0x%" PRIx32
1282 1296 "' in module: '%s'.\n", sysp->sys_op, sysp->sys_ptr,
1283 1297 *(uint32_t *)symaddr, sysp->sys_modnam);
1284 1298
1285 1299 switch (sysp->sys_op) {
1286 1300 case SETOP_ASSIGN:
1287 1301 *(uint32_t *)symaddr = ui;
1288 1302 break;
1289 1303 case SETOP_AND:
1290 1304 *(uint32_t *)symaddr &= ui;
1291 1305 break;
1292 1306 case SETOP_OR:
1293 1307 *(uint32_t *)symaddr |= ui;
1294 1308 break;
1295 1309 }
1296 1310
1297 1311 if (moddebug & MODDEBUG_LOADMSG)
1298 1312 printf("now it is set to '0x%" PRIx32 "'.\n",
1299 1313 *(uint32_t *)symaddr);
1300 1314 }
1301 1315
1302 1316 static void
1303 1317 set_int64_var(uintptr_t symaddr, struct sysparam *sysp)
1304 1318 {
1305 1319 uint64_t ul = sysp->sys_info;
1306 1320
1307 1321 if (moddebug & MODDEBUG_LOADMSG)
1308 1322 printf("OP: %x: param '%s' was '0x%" PRIx64
1309 1323 "' in module: '%s'.\n", sysp->sys_op, sysp->sys_ptr,
1310 1324 *(uint64_t *)symaddr, sysp->sys_modnam);
1311 1325
1312 1326 switch (sysp->sys_op) {
1313 1327 case SETOP_ASSIGN:
1314 1328 *(uint64_t *)symaddr = ul;
1315 1329 break;
1316 1330 case SETOP_AND:
1317 1331 *(uint64_t *)symaddr &= ul;
1318 1332 break;
1319 1333 case SETOP_OR:
1320 1334 *(uint64_t *)symaddr |= ul;
1321 1335 break;
1322 1336 }
1323 1337
1324 1338 if (moddebug & MODDEBUG_LOADMSG)
1325 1339 printf("now it is set to '0x%" PRIx64 "'.\n",
1326 1340 *(uint64_t *)symaddr);
1327 1341 }
1328 1342
1329 1343 /*
1330 1344 * The next item on the line is a string value. Allocate memory for
1331 1345 * it and copy the string. Return 1, and set arg ptr to newly allocated
1332 1346 * and initialized buffer, or NULL if an error occurs.
1333 1347 */
1334 1348 int
1335 1349 kobj_get_string(u_longlong_t *llptr, char *tchar)
1336 1350 {
1337 1351 char *cp;
1338 1352 char *start = (char *)0;
1339 1353 int len = 0;
1340 1354
1341 1355 len = strlen(tchar);
1342 1356 start = tchar;
1343 1357 /* copy string */
1344 1358 cp = vmem_alloc(mod_sysfile_arena, len + 1, VM_SLEEP);
1345 1359 bzero(cp, len + 1);
1346 1360 *llptr = (u_longlong_t)(uintptr_t)cp;
1347 1361 for (; len > 0; len--) {
1348 1362 /* convert some common escape sequences */
1349 1363 if (*start == '\\') {
1350 1364 switch (*(start + 1)) {
1351 1365 case 't':
1352 1366 /* tab */
1353 1367 *cp++ = '\t';
1354 1368 len--;
1355 1369 start += 2;
1356 1370 break;
1357 1371 case 'n':
1358 1372 /* new line */
1359 1373 *cp++ = '\n';
1360 1374 len--;
1361 1375 start += 2;
1362 1376 break;
1363 1377 case 'b':
1364 1378 /* back space */
1365 1379 *cp++ = '\b';
1366 1380 len--;
1367 1381 start += 2;
1368 1382 break;
1369 1383 default:
1370 1384 /* simply copy it */
1371 1385 *cp++ = *start++;
1372 1386 break;
1373 1387 }
1374 1388 } else
1375 1389 *cp++ = *start++;
1376 1390 }
1377 1391 *cp = '\0';
1378 1392 return (1);
1379 1393 }
1380 1394
1381 1395
1382 1396 /*
1383 1397 * this function frees the memory allocated by kobj_get_string
1384 1398 */
1385 1399 void
1386 1400 kobj_free_string(void *ptr, int len)
1387 1401 {
1388 1402 vmem_free(mod_sysfile_arena, ptr, len);
1389 1403 }
1390 1404
1391 1405
1392 1406 /*
1393 1407 * get a decimal octal or hex number. Handle '~' for one's complement.
1394 1408 */
1395 1409 int
1396 1410 kobj_getvalue(const char *token, u_longlong_t *valuep)
1397 1411 {
1398 1412 int radix;
1399 1413 u_longlong_t retval = 0;
1400 1414 int onescompl = 0;
1401 1415 int negate = 0;
1402 1416 char c;
1403 1417
1404 1418 if (*token == '~') {
1405 1419 onescompl++; /* perform one's complement on result */
1406 1420 token++;
1407 1421 } else if (*token == '-') {
1408 1422 negate++;
1409 1423 token++;
1410 1424 }
1411 1425 if (*token == '0') {
1412 1426 token++;
1413 1427 c = *token;
1414 1428
1415 1429 if (c == '\0') {
1416 1430 *valuep = 0; /* value is 0 */
1417 1431 return (0);
1418 1432 }
1419 1433
1420 1434 if (c == 'x' || c == 'X') {
1421 1435 radix = 16;
1422 1436 token++;
1423 1437 } else
1424 1438 radix = 8;
1425 1439 } else
1426 1440 radix = 10;
1427 1441
1428 1442 while ((c = *token++)) {
1429 1443 switch (radix) {
1430 1444 case 8:
1431 1445 if (c >= '0' && c <= '7')
1432 1446 c -= '0';
1433 1447 else
1434 1448 return (-1); /* invalid number */
1435 1449 retval = (retval << 3) + c;
1436 1450 break;
1437 1451 case 10:
1438 1452 if (c >= '0' && c <= '9')
1439 1453 c -= '0';
1440 1454 else
1441 1455 return (-1); /* invalid number */
1442 1456 retval = (retval * 10) + c;
1443 1457 break;
1444 1458 case 16:
1445 1459 if (c >= 'a' && c <= 'f')
1446 1460 c = c - 'a' + 10;
1447 1461 else if (c >= 'A' && c <= 'F')
1448 1462 c = c - 'A' + 10;
1449 1463 else if (c >= '0' && c <= '9')
1450 1464 c -= '0';
1451 1465 else
1452 1466 return (-1); /* invalid number */
1453 1467 retval = (retval << 4) + c;
1454 1468 break;
1455 1469 }
1456 1470 }
1457 1471 if (onescompl)
1458 1472 retval = ~retval;
1459 1473 if (negate)
1460 1474 retval = -retval;
1461 1475 *valuep = retval;
1462 1476 return (0);
1463 1477 }
1464 1478
1465 1479 /*
1466 1480 * Path to the root device and root filesystem type from
1467 1481 * property information derived from the boot subsystem
1468 1482 */
1469 1483 void
1470 1484 setbootpath(char *path)
1471 1485 {
1472 1486 rootfs.bo_flags |= BO_VALID;
1473 1487 (void) copystr(path, rootfs.bo_name, BO_MAXOBJNAME, NULL);
1474 1488 BMDPRINTF(("rootfs bootpath: %s\n", rootfs.bo_name));
1475 1489 }
1476 1490
1477 1491 void
1478 1492 setbootfstype(char *fstype)
1479 1493 {
1480 1494 (void) copystr(fstype, rootfs.bo_fstype, BO_MAXFSNAME, NULL);
1481 1495 BMDPRINTF(("rootfs fstype: %s\n", rootfs.bo_fstype));
1482 1496 }
1483 1497
1484 1498 /*
1485 1499 * set parameters that can be set early during initialization.
1486 1500 */
1487 1501 static void
1488 1502 setparams()
1489 1503 {
1490 1504 struct sysparam *sysp;
1491 1505 struct bootobj *bootobjp;
1492 1506
1493 1507 for (sysp = sysparam_hd; sysp != NULL; sysp = sysp->sys_next) {
1494 1508
1495 1509 if (sysp->sys_type == MOD_MODDIR) {
1496 1510 default_path = sysp->sys_ptr;
1497 1511 continue;
1498 1512 }
1499 1513
1500 1514 if (sysp->sys_type == MOD_SWAPDEV ||
1501 1515 sysp->sys_type == MOD_SWAPFS)
1502 1516 bootobjp = &swapfile;
1503 1517 else if (sysp->sys_type == MOD_ROOTFS)
1504 1518 bootobjp = &rootfs;
1505 1519
1506 1520 switch (sysp->sys_type) {
1507 1521 case MOD_SWAPDEV:
1508 1522 bootobjp->bo_flags |= BO_VALID;
1509 1523 (void) copystr(sysp->sys_ptr, bootobjp->bo_name,
1510 1524 BO_MAXOBJNAME, NULL);
1511 1525 break;
1512 1526 case MOD_ROOTFS:
1513 1527 case MOD_SWAPFS:
1514 1528 bootobjp->bo_flags |= BO_VALID;
1515 1529 (void) copystr(sysp->sys_ptr, bootobjp->bo_fstype,
1516 1530 BO_MAXOBJNAME, NULL);
1517 1531 break;
1518 1532 case MOD_ROOTDEV:
1519 1533 default:
1520 1534 break;
1521 1535 }
1522 1536 }
1523 1537 }
1524 1538
1525 1539 /*
1526 1540 * clean up after an error.
1527 1541 */
1528 1542 static void
1529 1543 hwc_free(struct hwc_spec *hwcp)
1530 1544 {
1531 1545 char *name;
1532 1546
1533 1547 if ((name = hwcp->hwc_parent_name) != NULL)
1534 1548 kmem_free(name, strlen(name) + 1);
1535 1549 if ((name = hwcp->hwc_class_name) != NULL)
1536 1550 kmem_free(name, strlen(name) + 1);
1537 1551 if ((name = hwcp->hwc_devi_name) != NULL)
1538 1552 kmem_free(name, strlen(name) + 1);
1539 1553 i_ddi_prop_list_delete(hwcp->hwc_devi_sys_prop_ptr);
1540 1554 kmem_free(hwcp, sizeof (struct hwc_spec));
1541 1555 }
1542 1556
1543 1557 /*
1544 1558 * Free a list of specs
1545 1559 */
1546 1560 void
1547 1561 hwc_free_spec_list(struct hwc_spec *list)
1548 1562 {
1549 1563 while (list) {
1550 1564 struct hwc_spec *tmp = list;
1551 1565 list = tmp->hwc_next;
1552 1566 hwc_free(tmp);
1553 1567 }
1554 1568 }
1555 1569
1556 1570 struct val_list {
1557 1571 struct val_list *val_next;
1558 1572 enum {
1559 1573 VAL_STRING,
1560 1574 VAL_INTEGER
1561 1575 } val_type;
1562 1576 int val_size;
1563 1577 union {
1564 1578 char *string;
1565 1579 int integer;
1566 1580 } val;
1567 1581 };
1568 1582
1569 1583 static struct val_list *
1570 1584 add_val(struct val_list **val_listp, struct val_list *tail,
1571 1585 int val_type, caddr_t val)
1572 1586 {
1573 1587 struct val_list *new_val;
1574 1588 #ifdef DEBUG
1575 1589 struct val_list *listp = *val_listp;
1576 1590 #endif
1577 1591
1578 1592 new_val = kmem_alloc(sizeof (struct val_list), KM_SLEEP);
1579 1593 new_val->val_next = NULL;
1580 1594 if ((new_val->val_type = val_type) == VAL_STRING) {
1581 1595 new_val->val_size = strlen((char *)val) + 1;
1582 1596 new_val->val.string = kmem_alloc(new_val->val_size, KM_SLEEP);
1583 1597 (void) strcpy(new_val->val.string, (char *)val);
1584 1598 } else {
1585 1599 new_val->val_size = sizeof (int);
1586 1600 new_val->val.integer = (int)(uintptr_t)val;
1587 1601 }
1588 1602
1589 1603 ASSERT((listp == NULL && tail == NULL) ||
1590 1604 (listp != NULL && tail != NULL));
1591 1605
1592 1606 if (tail != NULL) {
1593 1607 ASSERT(tail->val_next == NULL);
1594 1608 tail->val_next = new_val;
1595 1609 } else {
1596 1610 *val_listp = new_val;
1597 1611 }
1598 1612
1599 1613 return (new_val);
1600 1614 }
1601 1615
1602 1616 static void
1603 1617 free_val_list(struct val_list *head)
1604 1618 {
1605 1619 struct val_list *tval_list;
1606 1620
1607 1621 for (/* CSTYLED */; head != NULL; /* CSTYLED */) {
1608 1622 tval_list = head;
1609 1623 head = head->val_next;
1610 1624 if (tval_list->val_type == VAL_STRING)
1611 1625 kmem_free(tval_list->val.string, tval_list->val_size);
1612 1626 kmem_free(tval_list, sizeof (struct val_list));
1613 1627 }
1614 1628 }
1615 1629
1616 1630 /*
1617 1631 * make sure there are no reserved IEEE 1275 characters (except
1618 1632 * for uppercase characters).
1619 1633 */
1620 1634 static int
1621 1635 valid_prop_name(char *name)
1622 1636 {
1623 1637 int i;
1624 1638 int len = strlen(name);
1625 1639
1626 1640 for (i = 0; i < len; i++) {
1627 1641 if (name[i] < 0x21 ||
1628 1642 name[i] == '/' ||
1629 1643 name[i] == '\\' ||
1630 1644 name[i] == ':' ||
1631 1645 name[i] == '[' ||
1632 1646 name[i] == ']' ||
1633 1647 name[i] == '@')
1634 1648 return (0);
1635 1649 }
1636 1650 return (1);
1637 1651 }
1638 1652
1639 1653 static void
1640 1654 make_prop(struct _buf *file, dev_info_t *devi, char *name, struct val_list *val)
1641 1655 {
1642 1656 int propcnt = 0, val_type;
1643 1657 struct val_list *vl, *tvl;
1644 1658 caddr_t valbuf = NULL;
1645 1659 char **valsp;
1646 1660 int *valip;
1647 1661
1648 1662 if (name == NULL)
1649 1663 return;
1650 1664
1651 1665 #ifdef DEBUG
1652 1666 parse_debug(NULL, "%s", name);
1653 1667 #endif
1654 1668 if (!valid_prop_name(name)) {
1655 1669 cmn_err(CE_WARN, "invalid property name '%s'", name);
1656 1670 return;
1657 1671 }
1658 1672 if (val) {
1659 1673 for (vl = val, val_type = vl->val_type; vl; vl = vl->val_next) {
1660 1674 if (val_type != vl->val_type) {
1661 1675 cmn_err(CE_WARN, "Mixed types in value list");
1662 1676 return;
1663 1677 }
1664 1678 propcnt++;
1665 1679 }
1666 1680
1667 1681 vl = val;
1668 1682
1669 1683 if (val_type == VAL_INTEGER) {
1670 1684 valip = (int *)kmem_alloc(
1671 1685 (propcnt * sizeof (int)), KM_SLEEP);
1672 1686 valbuf = (caddr_t)valip;
1673 1687 while (vl) {
1674 1688 tvl = vl;
1675 1689 vl = vl->val_next;
1676 1690 #ifdef DEBUG
1677 1691 parse_debug(NULL, " %x", tvl->val.integer);
1678 1692 #endif
1679 1693 *valip = tvl->val.integer;
1680 1694 valip++;
1681 1695 }
1682 1696 /* restore valip */
1683 1697 valip = (int *)valbuf;
1684 1698
1685 1699 /* create the property */
1686 1700 if (e_ddi_prop_update_int_array(DDI_DEV_T_NONE, devi,
1687 1701 name, valip, propcnt) != DDI_PROP_SUCCESS) {
1688 1702 kobj_file_err(CE_WARN, file,
1689 1703 "cannot create property %s", name);
1690 1704 }
1691 1705 /* cleanup */
1692 1706 kmem_free(valip, (propcnt * sizeof (int)));
1693 1707 } else if (val_type == VAL_STRING) {
1694 1708 valsp = (char **)kmem_alloc(
1695 1709 ((propcnt + 1) * sizeof (char *)), KM_SLEEP);
1696 1710 valbuf = (caddr_t)valsp;
1697 1711 while (vl) {
1698 1712 tvl = vl;
1699 1713 vl = vl->val_next;
1700 1714 #ifdef DEBUG
1701 1715 parse_debug(NULL, " %s", tvl->val.string);
1702 1716 #endif
1703 1717 *valsp = tvl->val.string;
1704 1718 valsp++;
1705 1719 }
1706 1720 /* terminate array with NULL */
1707 1721 *valsp = NULL;
1708 1722
1709 1723 /* restore valsp */
1710 1724 valsp = (char **)valbuf;
1711 1725
1712 1726 /* create the property */
1713 1727 if (e_ddi_prop_update_string_array(DDI_DEV_T_NONE,
1714 1728 devi, name, valsp, propcnt)
1715 1729 != DDI_PROP_SUCCESS) {
1716 1730 kobj_file_err(CE_WARN, file,
1717 1731 "cannot create property %s", name);
1718 1732 }
1719 1733 /* Clean up */
1720 1734 kmem_free(valsp, ((propcnt + 1) * sizeof (char *)));
1721 1735 } else {
1722 1736 cmn_err(CE_WARN, "Invalid property type");
1723 1737 return;
1724 1738 }
1725 1739 } else {
1726 1740 /*
1727 1741 * No value was passed in with property so we will assume
1728 1742 * it is a "boolean" property and create an integer
1729 1743 * property with 0 value.
1730 1744 */
1731 1745 #ifdef DEBUG
1732 1746 parse_debug(NULL, "\n");
1733 1747 #endif
1734 1748 if (e_ddi_prop_update_int(DDI_DEV_T_NONE, devi, name, 0)
1735 1749 != DDI_PROP_SUCCESS) {
1736 1750 kobj_file_err(CE_WARN, file,
1737 1751 "cannot create property %s", name);
1738 1752 }
1739 1753 }
1740 1754 }
1741 1755
1742 1756 static char omit_err[] = "(the ';' may have been omitted on previous spec!)";
1743 1757 static char prnt_err[] = "'parent' property already specified";
1744 1758 static char nm_err[] = "'name' property already specified";
1745 1759 static char class_err[] = "'class' property already specified";
1746 1760
1747 1761 typedef enum {
1748 1762 hwc_begin, parent, drvname, drvclass, prop,
1749 1763 parent_equals, name_equals, drvclass_equals,
1750 1764 parent_equals_string, name_equals_string,
1751 1765 drvclass_equals_string,
1752 1766 prop_equals, prop_equals_string, prop_equals_integer,
1753 1767 prop_equals_string_comma, prop_equals_integer_comma
1754 1768 } hwc_state_t;
1755 1769
1756 1770 static struct hwc_spec *
1757 1771 get_hwc_spec(struct _buf *file, char *tokbuf, size_t linesize)
1758 1772 {
1759 1773 char *prop_name;
1760 1774 token_t token;
1761 1775 struct hwc_spec *hwcp;
1762 1776 struct dev_info *devi;
1763 1777 struct val_list *val_list, *tail;
1764 1778 hwc_state_t state;
1765 1779 u_longlong_t ival;
1766 1780
1767 1781 hwcp = kmem_zalloc(sizeof (*hwcp), KM_SLEEP);
1768 1782 devi = kmem_zalloc(sizeof (*devi), KM_SLEEP);
1769 1783
1770 1784 state = hwc_begin;
1771 1785 token = NAME;
1772 1786 prop_name = NULL;
1773 1787 val_list = NULL;
1774 1788 tail = NULL;
1775 1789 do {
1776 1790 #ifdef DEBUG
1777 1791 parse_debug(NULL, "state 0x%x\n", state);
1778 1792 #endif
1779 1793 switch (token) {
1780 1794 case NAME:
1781 1795 switch (state) {
1782 1796 case prop:
1783 1797 case prop_equals_string:
1784 1798 case prop_equals_integer:
1785 1799 make_prop(file, (dev_info_t *)devi,
1786 1800 prop_name, val_list);
1787 1801 if (prop_name) {
1788 1802 kmem_free(prop_name,
1789 1803 strlen(prop_name) + 1);
1790 1804 prop_name = NULL;
1791 1805 }
1792 1806 if (val_list) {
1793 1807 free_val_list(val_list);
1794 1808 val_list = NULL;
1795 1809 }
1796 1810 tail = NULL;
1797 1811 /*FALLTHROUGH*/
1798 1812 case hwc_begin:
1799 1813 if (strcmp(tokbuf, "PARENT") == 0 ||
1800 1814 strcmp(tokbuf, "parent") == 0) {
1801 1815 state = parent;
1802 1816 } else if (strcmp(tokbuf, "NAME") == 0 ||
1803 1817 strcmp(tokbuf, "name") == 0) {
1804 1818 state = drvname;
1805 1819 } else if (strcmp(tokbuf, "CLASS") == 0 ||
1806 1820 strcmp(tokbuf, "class") == 0) {
1807 1821 state = drvclass;
1808 1822 prop_name = kmem_alloc(strlen(tokbuf) +
1809 1823 1, KM_SLEEP);
1810 1824 (void) strcpy(prop_name, tokbuf);
1811 1825 } else {
1812 1826 state = prop;
1813 1827 prop_name = kmem_alloc(strlen(tokbuf) +
1814 1828 1, KM_SLEEP);
1815 1829 (void) strcpy(prop_name, tokbuf);
1816 1830 }
1817 1831 break;
1818 1832 default:
1819 1833 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
1820 1834 }
1821 1835 break;
1822 1836 case EQUALS:
1823 1837 switch (state) {
1824 1838 case drvname:
1825 1839 state = name_equals;
1826 1840 break;
1827 1841 case parent:
1828 1842 state = parent_equals;
1829 1843 break;
1830 1844 case drvclass:
1831 1845 state = drvclass_equals;
1832 1846 break;
1833 1847 case prop:
1834 1848 state = prop_equals;
1835 1849 break;
1836 1850 default:
1837 1851 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
1838 1852 }
1839 1853 break;
1840 1854 case STRING:
1841 1855 switch (state) {
1842 1856 case name_equals:
1843 1857 if (ddi_get_name((dev_info_t *)devi)) {
1844 1858 kobj_file_err(CE_WARN, file, "%s %s",
1845 1859 nm_err, omit_err);
1846 1860 goto bad;
1847 1861 }
1848 1862 devi->devi_name = kmem_alloc(strlen(tokbuf) + 1,
1849 1863 KM_SLEEP);
1850 1864 (void) strcpy(devi->devi_name, tokbuf);
1851 1865 state = hwc_begin;
1852 1866 break;
1853 1867 case parent_equals:
1854 1868 if (hwcp->hwc_parent_name) {
1855 1869 kobj_file_err(CE_WARN, file, "%s %s",
1856 1870 prnt_err, omit_err);
1857 1871 goto bad;
1858 1872 }
1859 1873 hwcp->hwc_parent_name = kmem_alloc(strlen
1860 1874 (tokbuf) + 1, KM_SLEEP);
1861 1875 (void) strcpy(hwcp->hwc_parent_name, tokbuf);
1862 1876 state = hwc_begin;
1863 1877 break;
1864 1878 case drvclass_equals:
1865 1879 if (hwcp->hwc_class_name) {
1866 1880 kobj_file_err(CE_WARN, file, class_err);
1867 1881 goto bad;
1868 1882 }
1869 1883 hwcp->hwc_class_name = kmem_alloc(
1870 1884 strlen(tokbuf) + 1, KM_SLEEP);
1871 1885 (void) strcpy(hwcp->hwc_class_name, tokbuf);
1872 1886 /*FALLTHROUGH*/
1873 1887 case prop_equals:
1874 1888 case prop_equals_string_comma:
1875 1889 tail = add_val(&val_list, tail, VAL_STRING,
1876 1890 tokbuf);
1877 1891 state = prop_equals_string;
1878 1892 break;
1879 1893 default:
1880 1894 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
1881 1895 }
1882 1896 break;
1883 1897 case HEXVAL:
1884 1898 case DECVAL:
1885 1899 switch (state) {
1886 1900 case prop_equals:
1887 1901 case prop_equals_integer_comma:
1888 1902 (void) kobj_getvalue(tokbuf, &ival);
1889 1903 tail = add_val(&val_list, tail,
1890 1904 VAL_INTEGER, (caddr_t)(uintptr_t)ival);
1891 1905 state = prop_equals_integer;
1892 1906 break;
1893 1907 default:
1894 1908 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
1895 1909 }
1896 1910 break;
1897 1911 case COMMA:
1898 1912 switch (state) {
1899 1913 case prop_equals_string:
1900 1914 state = prop_equals_string_comma;
1901 1915 break;
1902 1916 case prop_equals_integer:
1903 1917 state = prop_equals_integer_comma;
1904 1918 break;
1905 1919 default:
1906 1920 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
1907 1921 }
1908 1922 break;
1909 1923 case NEWLINE:
1910 1924 kobj_newline(file);
1911 1925 break;
1912 1926 case POUND:
1913 1927 /*
1914 1928 * Skip comments.
1915 1929 */
1916 1930 kobj_find_eol(file);
1917 1931 break;
1918 1932 case EOF:
1919 1933 kobj_file_err(CE_WARN, file, "Unexpected EOF");
1920 1934 goto bad;
1921 1935 default:
1922 1936 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
1923 1937 goto bad;
1924 1938 }
1925 1939 } while ((token = kobj_lex(file, tokbuf, linesize)) != SEMICOLON);
1926 1940
1927 1941 switch (state) {
1928 1942 case prop:
1929 1943 case prop_equals_string:
1930 1944 case prop_equals_integer:
1931 1945 make_prop(file, (dev_info_t *)devi,
1932 1946 prop_name, val_list);
1933 1947 break;
1934 1948
1935 1949 case hwc_begin:
1936 1950 break;
1937 1951 default:
1938 1952 kobj_file_err(CE_WARN, file, "Unexpected end of line");
1939 1953 break;
1940 1954 }
1941 1955
1942 1956 /* copy 2 relevant members of devi to hwcp */
1943 1957 hwcp->hwc_devi_sys_prop_ptr = devi->devi_sys_prop_ptr;
1944 1958 hwcp->hwc_devi_name = devi->devi_name;
1945 1959
1946 1960 if (prop_name)
1947 1961 kmem_free(prop_name, strlen(prop_name) + 1);
1948 1962 if (val_list)
1949 1963 free_val_list(val_list);
1950 1964
1951 1965 kmem_free(devi, sizeof (struct dev_info));
1952 1966
1953 1967 return (hwcp);
1954 1968
1955 1969 bad:
1956 1970 if (prop_name)
1957 1971 kmem_free(prop_name, strlen(prop_name) + 1);
1958 1972 if (val_list)
1959 1973 free_val_list(val_list);
1960 1974
1961 1975 hwc_free(hwcp);
1962 1976
1963 1977 if (devi->devi_name)
1964 1978 kmem_free(devi->devi_name, strlen(devi->devi_name) + 1);
1965 1979
1966 1980 kmem_free(devi, sizeof (struct dev_info));
1967 1981
1968 1982 return (NULL);
1969 1983 }
1970 1984
1971 1985 /*
1972 1986 * This is the primary kernel interface to parse driver.conf files.
1973 1987 *
1974 1988 * Yet another bigstk thread handoff due to deep kernel stacks when booting
1975 1989 * cache-only-clients.
1976 1990 */
1977 1991 int
1978 1992 hwc_parse(char *fname, struct par_list **pl, ddi_prop_t **props)
1979 1993 {
1980 1994 int ret;
1981 1995 struct hwc_parse_mt *pltp = hwc_parse_mtalloc(fname, pl, props);
1982 1996
1983 1997 if (curthread != &t0) {
1984 1998 (void) thread_create(NULL, DEFAULTSTKSZ * 2,
1985 1999 hwc_parse_thread, pltp, 0, &p0, TS_RUN, maxclsyspri);
1986 2000 sema_p(&pltp->sema);
1987 2001 } else {
1988 2002 pltp->rv = hwc_parse_now(fname, pl, props);
1989 2003 }
1990 2004 ret = pltp->rv;
1991 2005 hwc_parse_mtfree(pltp);
1992 2006 return (ret);
1993 2007 }
1994 2008
1995 2009 /*
1996 2010 * Calls to hwc_parse() are handled off to this routine in a separate
1997 2011 * thread.
1998 2012 */
1999 2013 static void
2000 2014 hwc_parse_thread(struct hwc_parse_mt *pltp)
2001 2015 {
2002 2016 kmutex_t cpr_lk;
2003 2017 callb_cpr_t cpr_i;
2004 2018
2005 2019 mutex_init(&cpr_lk, NULL, MUTEX_DEFAULT, NULL);
2006 2020 CALLB_CPR_INIT(&cpr_i, &cpr_lk, callb_generic_cpr, "hwc_parse");
2007 2021
2008 2022 /*
2009 2023 * load and parse the .conf file
2010 2024 * return the hwc_spec list (if any) to the creator of this thread
2011 2025 */
2012 2026 pltp->rv = hwc_parse_now(pltp->name, pltp->pl, pltp->props);
2013 2027 sema_v(&pltp->sema);
2014 2028 mutex_enter(&cpr_lk);
2015 2029 CALLB_CPR_EXIT(&cpr_i);
2016 2030 mutex_destroy(&cpr_lk);
2017 2031 thread_exit();
2018 2032 }
2019 2033
2020 2034 /*
2021 2035 * allocate and initialize a hwc_parse thread control structure
2022 2036 */
2023 2037 static struct hwc_parse_mt *
2024 2038 hwc_parse_mtalloc(char *name, struct par_list **pl, ddi_prop_t **props)
2025 2039 {
2026 2040 struct hwc_parse_mt *pltp = kmem_zalloc(sizeof (*pltp), KM_SLEEP);
2027 2041
2028 2042 ASSERT(name != NULL);
2029 2043
2030 2044 pltp->name = kmem_alloc(strlen(name) + 1, KM_SLEEP);
2031 2045 bcopy(name, pltp->name, strlen(name) + 1);
2032 2046 pltp->pl = pl;
2033 2047 pltp->props = props;
2034 2048
2035 2049 sema_init(&pltp->sema, 0, NULL, SEMA_DEFAULT, NULL);
2036 2050 return (pltp);
2037 2051 }
2038 2052
2039 2053 /*
2040 2054 * free a hwc_parse thread control structure
2041 2055 */
2042 2056 static void
2043 2057 hwc_parse_mtfree(struct hwc_parse_mt *pltp)
2044 2058 {
2045 2059 sema_destroy(&pltp->sema);
2046 2060
2047 2061 kmem_free(pltp->name, strlen(pltp->name) + 1);
2048 2062 kmem_free(pltp, sizeof (*pltp));
2049 2063 }
2050 2064
2051 2065 /*
2052 2066 * hwc_parse -- parse an hwconf file. Ignore error lines and parse
2053 2067 * as much as possible.
2054 2068 */
2055 2069 static int
2056 2070 hwc_parse_now(char *fname, struct par_list **pl, ddi_prop_t **props)
2057 2071 {
2058 2072 struct _buf *file;
2059 2073 struct hwc_spec *hwcp;
2060 2074 char *tokval;
2061 2075 token_t token;
2062 2076
2063 2077 /*
2064 2078 * Don't use kobj_open_path's use_moddir_suffix option, we only
2065 2079 * expect to find conf files in the base module directory, not
2066 2080 * an ISA-specific subdirectory.
2067 2081 */
2068 2082 if ((file = kobj_open_path(fname, 1, 0)) == (struct _buf *)-1) {
2069 2083 if (moddebug & MODDEBUG_ERRMSG)
2070 2084 cmn_err(CE_WARN, "Cannot open %s", fname);
2071 2085 return (-1);
2072 2086 }
2073 2087
2074 2088 /*
2075 2089 * Initialize variables
2076 2090 */
2077 2091 tokval = kmem_alloc(MAX_HWC_LINESIZE, KM_SLEEP);
2078 2092
2079 2093 while ((token = kobj_lex(file, tokval, MAX_HWC_LINESIZE)) != EOF) {
2080 2094 switch (token) {
2081 2095 case POUND:
2082 2096 /*
2083 2097 * Skip comments.
2084 2098 */
2085 2099 kobj_find_eol(file);
2086 2100 break;
2087 2101 case NAME:
2088 2102 hwcp = get_hwc_spec(file, tokval, MAX_HWC_LINESIZE);
2089 2103 if (hwcp == NULL)
2090 2104 break;
2091 2105 /*
2092 2106 * No devi_name indicates global property.
2093 2107 * Make sure parent and class not NULL.
2094 2108 */
2095 2109 if (hwcp->hwc_devi_name == NULL) {
2096 2110 if (hwcp->hwc_parent_name ||
2097 2111 hwcp->hwc_class_name) {
2098 2112 kobj_file_err(CE_WARN, file,
2099 2113 "missing name attribute");
2100 2114 hwc_free(hwcp);
2101 2115 continue;
2102 2116 }
2103 2117 /* Add to global property list */
2104 2118 add_props(hwcp, props);
2105 2119 break;
2106 2120 }
2107 2121
2108 2122 /*
2109 2123 * This is a node spec, either parent or class
2110 2124 * must be specified.
2111 2125 */
2112 2126 if ((hwcp->hwc_parent_name == NULL) &&
2113 2127 (hwcp->hwc_class_name == NULL)) {
2114 2128 kobj_file_err(CE_WARN, file,
2115 2129 "missing parent or class attribute");
2116 2130 hwc_free(hwcp);
2117 2131 continue;
2118 2132 }
2119 2133
2120 2134 /* add to node spec list */
2121 2135 add_spec(hwcp, pl);
2122 2136 break;
2123 2137 case NEWLINE:
2124 2138 kobj_newline(file);
2125 2139 break;
2126 2140 default:
2127 2141 kobj_file_err(CE_WARN, file, tok_err, tokval);
2128 2142 break;
2129 2143 }
2130 2144 }
2131 2145 /*
2132 2146 * XXX - Check for clean termination.
2133 2147 */
2134 2148 kmem_free(tokval, MAX_HWC_LINESIZE);
2135 2149 kobj_close_file(file);
2136 2150 return (0); /* always return success */
2137 2151 }
2138 2152
2139 2153 void
2140 2154 make_aliases(struct bind **bhash)
2141 2155 {
2142 2156 enum {
2143 2157 AL_NEW, AL_DRVNAME, AL_DRVNAME_COMMA, AL_ALIAS, AL_ALIAS_COMMA
2144 2158 } state;
2145 2159
2146 2160 struct _buf *file;
2147 2161 char tokbuf[MAXPATHLEN];
2148 2162 char drvbuf[MAXPATHLEN];
2149 2163 token_t token;
2150 2164 major_t major;
2151 2165 int done = 0;
2152 2166 static char dupwarn[] = "!Driver alias \"%s\" conflicts with "
2153 2167 "an existing driver name or alias.";
2154 2168
2155 2169 if ((file = kobj_open_file(dafile)) == (struct _buf *)-1)
2156 2170 return;
2157 2171
2158 2172 state = AL_NEW;
2159 2173 major = DDI_MAJOR_T_NONE;
2160 2174 while (!done) {
2161 2175 token = kobj_lex(file, tokbuf, sizeof (tokbuf));
2162 2176 switch (token) {
2163 2177 case POUND:
2164 2178 /*
2165 2179 * Skip comments.
2166 2180 */
2167 2181 kobj_find_eol(file);
2168 2182 break;
2169 2183 case NAME:
2170 2184 case STRING:
2171 2185 switch (state) {
2172 2186 case AL_NEW:
2173 2187 (void) strcpy(drvbuf, tokbuf);
2174 2188 state = AL_DRVNAME;
2175 2189 break;
2176 2190 case AL_DRVNAME_COMMA:
2177 2191 (void) strcat(drvbuf, tokbuf);
2178 2192 state = AL_DRVNAME;
2179 2193 break;
2180 2194 case AL_ALIAS_COMMA:
2181 2195 (void) strcat(drvbuf, tokbuf);
2182 2196 state = AL_ALIAS;
2183 2197 break;
2184 2198 case AL_DRVNAME:
2185 2199 major = mod_name_to_major(drvbuf);
2186 2200 if (major == DDI_MAJOR_T_NONE) {
2187 2201 kobj_find_eol(file);
2188 2202 state = AL_NEW;
2189 2203 } else {
2190 2204 (void) strcpy(drvbuf, tokbuf);
2191 2205 state = AL_ALIAS;
2192 2206 }
2193 2207 break;
2194 2208 case AL_ALIAS:
2195 2209 if (make_mbind(drvbuf, major, NULL, bhash)
2196 2210 != 0) {
2197 2211 cmn_err(CE_WARN, dupwarn, drvbuf);
2198 2212 }
2199 2213 /*
2200 2214 * copy this token just in case that there
2201 2215 * are multiple names on the same line.
2202 2216 */
2203 2217 (void) strcpy(drvbuf, tokbuf);
2204 2218 break;
2205 2219 }
2206 2220 break;
2207 2221 case COMMA:
2208 2222 (void) strcat(drvbuf, tokbuf);
2209 2223 switch (state) {
2210 2224 case AL_DRVNAME:
2211 2225 state = AL_DRVNAME_COMMA;
2212 2226 break;
2213 2227 case AL_ALIAS:
2214 2228 state = AL_ALIAS_COMMA;
2215 2229 break;
2216 2230 default:
2217 2231 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
2218 2232 }
2219 2233 break;
2220 2234 case EOF:
2221 2235 done = 1;
2222 2236 /*FALLTHROUGH*/
2223 2237 case NEWLINE:
2224 2238 if (state == AL_ALIAS) {
2225 2239 if (make_mbind(drvbuf, major, NULL, bhash)
2226 2240 != 0) {
2227 2241 cmn_err(CE_WARN, dupwarn, drvbuf);
2228 2242 }
2229 2243 } else if (state != AL_NEW) {
2230 2244 kobj_file_err(CE_WARN, file,
2231 2245 "Missing alias for %s", drvbuf);
2232 2246 }
2233 2247
2234 2248 kobj_newline(file);
2235 2249 state = AL_NEW;
2236 2250 major = DDI_MAJOR_T_NONE;
2237 2251 break;
2238 2252 default:
2239 2253 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
2240 2254 }
2241 2255 }
2242 2256
2243 2257 kobj_close_file(file);
2244 2258 }
2245 2259
2246 2260
2247 2261 /*
2248 2262 * It is called for parsing these files:
2249 2263 * - /etc/path_to_inst
2250 2264 * - /etc/name_to_major
2251 2265 * - /etc/name_to_sysnum
2252 2266 * A callback "int (*line_parser)(char *, int, char *, struct bind **)"
2253 2267 * is invoked for each line of the file.
2254 2268 * The callback can inhash the entry into a hashtable by supplying
2255 2269 * a pre-allocated hashtable in "struct bind **hashtab".
2256 2270 */
2257 2271 int
2258 2272 read_binding_file(char *bindfile, struct bind **hashtab,
2259 2273 int (*line_parser)(char *, int, char *, struct bind **))
2260 2274 {
2261 2275 enum {
2262 2276 B_NEW, B_NAME, B_VAL, B_BIND_NAME
2263 2277 } state;
2264 2278 struct _buf *file;
2265 2279 char tokbuf[MAXNAMELEN];
2266 2280 token_t token;
2267 2281 int maxnum = 0;
2268 2282 char *bind_name = NULL, *name = NULL, *bn = NULL;
2269 2283 u_longlong_t val;
2270 2284 int done = 0;
2271 2285
2272 2286 static char num_err[] = "Missing number on preceding line?";
2273 2287 static char dupwarn[] = "!The binding file entry \"%s %u\" conflicts "
2274 2288 "with a previous entry";
2275 2289
2276 2290 if (hashtab != NULL) {
2277 2291 clear_binding_hash(hashtab);
2278 2292 }
2279 2293
2280 2294 if ((file = kobj_open_file(bindfile)) == (struct _buf *)-1)
2281 2295 panic("read_binding_file: %s file not found", bindfile);
2282 2296
2283 2297 state = B_NEW;
2284 2298
2285 2299 while (!done) {
2286 2300 token = kobj_lex(file, tokbuf, sizeof (tokbuf));
2287 2301
2288 2302 switch (token) {
2289 2303 case POUND:
2290 2304 /*
2291 2305 * Skip comments.
2292 2306 */
2293 2307 kobj_find_eol(file);
2294 2308 break;
2295 2309 case NAME:
2296 2310 case STRING:
2297 2311 switch (state) {
2298 2312 case B_NEW:
2299 2313 /*
2300 2314 * This case is for the first name and
2301 2315 * possibly only name in an entry.
2302 2316 */
2303 2317 ASSERT(name == NULL);
2304 2318 name = kmem_alloc(strlen(tokbuf) + 1, KM_SLEEP);
2305 2319 (void) strcpy(name, tokbuf);
2306 2320 state = B_NAME;
2307 2321 break;
2308 2322 case B_VAL:
2309 2323 /*
2310 2324 * This case is for a second name, which
2311 2325 * would be the binding name if the first
2312 2326 * name was actually a generic name.
2313 2327 */
2314 2328 ASSERT(bind_name == NULL);
2315 2329 bind_name = kmem_alloc(strlen(tokbuf) + 1,
2316 2330 KM_SLEEP);
2317 2331 (void) strcpy(bind_name, tokbuf);
2318 2332 state = B_BIND_NAME;
2319 2333 break;
2320 2334 default:
2321 2335 kobj_file_err(CE_WARN, file, num_err);
2322 2336 }
2323 2337 break;
2324 2338 case HEXVAL:
2325 2339 case DECVAL:
2326 2340 if (state != B_NAME) {
2327 2341 kobj_file_err(CE_WARN, file, "Missing name?");
2328 2342 state = B_NEW;
2329 2343 continue;
2330 2344 }
2331 2345 (void) kobj_getvalue(tokbuf, &val);
2332 2346 if (val > (u_longlong_t)INT_MAX) {
2333 2347 kobj_file_err(CE_WARN, file,
2334 2348 "value %llu too large", val);
2335 2349 state = B_NEW;
2336 2350 continue;
2337 2351 }
2338 2352 state = B_VAL;
2339 2353 break;
2340 2354 case EOF:
2341 2355 done = 1;
2342 2356 /*FALLTHROUGH*/
2343 2357 case NEWLINE:
2344 2358 if ((state == B_BIND_NAME) || (state == B_VAL)) {
2345 2359 if (state == B_BIND_NAME)
2346 2360 bn = bind_name;
2347 2361 else
2348 2362 bn = NULL;
2349 2363
2350 2364 if (line_parser != NULL) {
2351 2365 if ((*line_parser)(name, (int)val, bn,
2352 2366 hashtab) == 0)
2353 2367 maxnum = MAX((int)val, maxnum);
2354 2368 else
2355 2369 kobj_file_err(CE_WARN, file,
2356 2370 dupwarn, name, (uint_t)val);
2357 2371 }
2358 2372 } else if (state != B_NEW)
2359 2373 kobj_file_err(CE_WARN, file, "Syntax error?");
2360 2374
2361 2375 if (name) {
2362 2376 kmem_free(name, strlen(name) + 1);
2363 2377 name = NULL;
2364 2378 }
2365 2379 if (bind_name) {
2366 2380 kmem_free(bind_name, strlen(bind_name) + 1);
2367 2381 bind_name = NULL;
2368 2382 }
2369 2383 state = B_NEW;
2370 2384 kobj_newline(file);
2371 2385 break;
2372 2386 default:
2373 2387 kobj_file_err(CE_WARN, file, "Missing name/number?");
2374 2388 break;
2375 2389 }
2376 2390 }
2377 2391
2378 2392 ASSERT(name == NULL); /* any leaks? */
2379 2393 ASSERT(bind_name == NULL);
2380 2394
2381 2395 kobj_close_file(file);
2382 2396 return (maxnum);
2383 2397 }
2384 2398
2385 2399 /*
2386 2400 * read_dacf_binding_file()
2387 2401 * Read the /etc/dacf.conf file and build the dacf_rule_t database from it.
2388 2402 *
2389 2403 * The syntax of a line in the dacf.conf file is:
2390 2404 * dev-spec [module:]op-set operation options [config-args];
2391 2405 *
2392 2406 * Where:
2393 2407 * 1. dev-spec is of the format: name="data"
2394 2408 * 2. operation is the operation that this rule matches. (i.e. pre-detach)
2395 2409 * 3. options is a comma delimited list of options (i.e. debug,foobar)
2396 2410 * 4. config-data is a whitespace delimited list of the format: name="data"
2397 2411 */
2398 2412 int
2399 2413 read_dacf_binding_file(char *filename)
2400 2414 {
2401 2415 enum {
2402 2416 DACF_BEGIN,
2403 2417 /* minor_nodetype="ddi_mouse:serial" */
2404 2418 DACF_NT_SPEC, DACF_NT_EQUALS, DACF_NT_DATA,
2405 2419 /* consconfig:mouseconfig */
2406 2420 DACF_MN_MODNAME, DACF_MN_COLON, DACF_MN_OPSET,
2407 2421 /* op */
2408 2422 DACF_OP_NAME,
2409 2423 /* [ option1, option2, option3... | - ] */
2410 2424 DACF_OPT_OPTION, DACF_OPT_COMMA, DACF_OPT_END,
2411 2425 /* argname1="argval1" argname2="argval2" ... */
2412 2426 DACF_OPARG_SPEC, DACF_OPARG_EQUALS, DACF_OPARG_DATA,
2413 2427 DACF_ERR, DACF_ERR_NEWLINE, DACF_COMMENT
2414 2428 } state = DACF_BEGIN;
2415 2429
2416 2430 struct _buf *file;
2417 2431 char *fname;
2418 2432 token_t token;
2419 2433
2420 2434 char tokbuf[MAXNAMELEN];
2421 2435 char mn_modname_buf[MAXNAMELEN], *mn_modnamep = NULL;
2422 2436 char mn_opset_buf[MAXNAMELEN], *mn_opsetp = NULL;
2423 2437 char nt_data_buf[MAXNAMELEN], *nt_datap = NULL;
2424 2438 char arg_spec_buf[MAXNAMELEN];
2425 2439
2426 2440 uint_t opts = 0;
2427 2441 dacf_devspec_t nt_spec_type = DACF_DS_ERROR;
2428 2442
2429 2443 dacf_arg_t *arg_list = NULL;
2430 2444 dacf_opid_t opid = DACF_OPID_ERROR;
2431 2445 int done = 0;
2432 2446
2433 2447 static char w_syntax[] = "'%s' unexpected";
2434 2448 static char w_equals[] = "'=' is illegal in the current context";
2435 2449 static char w_baddevspec[] = "device specification '%s' unrecognized";
2436 2450 static char w_badop[] = "operation '%s' unrecognized";
2437 2451 static char w_badopt[] = "option '%s' unrecognized, ignoring";
2438 2452 static char w_newline[] = "rule is incomplete";
2439 2453 static char w_insert[] = "failed to register rule";
2440 2454 static char w_comment[] = "'#' not allowed except at start of line";
2441 2455 static char w_dupargs[] =
2442 2456 "argument '%s' duplicates a previous argument, skipping";
2443 2457 static char w_nt_empty[] = "empty device specification not allowed";
2444 2458
2445 2459 if (filename == NULL) {
2446 2460 fname = dacffile; /* default binding file */
2447 2461 } else {
2448 2462 fname = filename; /* user specified */
2449 2463 }
2450 2464
2451 2465 if ((file = kobj_open_file(fname)) == (struct _buf *)-1) {
2452 2466 return (ENOENT);
2453 2467 }
2454 2468
2455 2469 if (dacfdebug & DACF_DBG_MSGS) {
2456 2470 printf("dacf debug: clearing rules database\n");
2457 2471 }
2458 2472
2459 2473 mutex_enter(&dacf_lock);
2460 2474 dacf_clear_rules();
2461 2475
2462 2476 if (dacfdebug & DACF_DBG_MSGS) {
2463 2477 printf("dacf debug: parsing %s\n", fname);
2464 2478 }
2465 2479
2466 2480 while (!done) {
2467 2481 token = kobj_lex(file, tokbuf, sizeof (tokbuf));
2468 2482
2469 2483 switch (token) {
2470 2484 case POUND: /* comment line */
2471 2485 if (state != DACF_BEGIN) {
2472 2486 kobj_file_err(CE_WARN, file, w_comment);
2473 2487 state = DACF_ERR;
2474 2488 break;
2475 2489 }
2476 2490 state = DACF_COMMENT;
2477 2491 kobj_find_eol(file);
2478 2492 break;
2479 2493
2480 2494 case EQUALS:
2481 2495 switch (state) {
2482 2496 case DACF_NT_SPEC:
2483 2497 state = DACF_NT_EQUALS;
2484 2498 break;
2485 2499 case DACF_OPARG_SPEC:
2486 2500 state = DACF_OPARG_EQUALS;
2487 2501 break;
2488 2502 default:
2489 2503 kobj_file_err(CE_WARN, file, w_equals);
2490 2504 state = DACF_ERR;
2491 2505 }
2492 2506 break;
2493 2507
2494 2508 case NAME:
2495 2509 switch (state) {
2496 2510 case DACF_BEGIN:
2497 2511 nt_spec_type = dacf_get_devspec(tokbuf);
2498 2512 if (nt_spec_type == DACF_DS_ERROR) {
2499 2513 kobj_file_err(CE_WARN, file,
2500 2514 w_baddevspec, tokbuf);
2501 2515 state = DACF_ERR;
2502 2516 break;
2503 2517 }
2504 2518 state = DACF_NT_SPEC;
2505 2519 break;
2506 2520 case DACF_NT_DATA:
2507 2521 (void) strncpy(mn_modname_buf, tokbuf,
2508 2522 sizeof (mn_modname_buf));
2509 2523 mn_modnamep = mn_modname_buf;
2510 2524 state = DACF_MN_MODNAME;
2511 2525 break;
2512 2526 case DACF_MN_MODNAME:
2513 2527 /*
2514 2528 * This handles the 'optional' modname.
2515 2529 * What we thought was the modname is really
2516 2530 * the op-set. So it is copied over.
2517 2531 */
2518 2532 ASSERT(mn_modnamep);
2519 2533 (void) strncpy(mn_opset_buf, mn_modnamep,
2520 2534 sizeof (mn_opset_buf));
2521 2535 mn_opsetp = mn_opset_buf;
2522 2536 mn_modnamep = NULL;
2523 2537 /*
2524 2538 * Now, the token we just read is the opset,
2525 2539 * so look that up and fill in opid
2526 2540 */
2527 2541 if ((opid = dacf_get_op(tokbuf)) ==
2528 2542 DACF_OPID_ERROR) {
2529 2543 kobj_file_err(CE_WARN, file, w_badop,
2530 2544 tokbuf);
2531 2545 state = DACF_ERR;
2532 2546 break;
2533 2547 }
2534 2548 state = DACF_OP_NAME;
2535 2549 break;
2536 2550 case DACF_MN_COLON:
2537 2551 (void) strncpy(mn_opset_buf, tokbuf,
2538 2552 sizeof (mn_opset_buf));
2539 2553 mn_opsetp = mn_opset_buf;
2540 2554 state = DACF_MN_OPSET;
2541 2555 break;
2542 2556 case DACF_MN_OPSET:
2543 2557 if ((opid = dacf_get_op(tokbuf)) ==
2544 2558 DACF_OPID_ERROR) {
2545 2559 kobj_file_err(CE_WARN, file, w_badop,
2546 2560 tokbuf);
2547 2561 state = DACF_ERR;
2548 2562 break;
2549 2563 }
2550 2564 state = DACF_OP_NAME;
2551 2565 break;
2552 2566 case DACF_OP_NAME:
2553 2567 /*
2554 2568 * This case is just like DACF_OPT_COMMA below,
2555 2569 * but we check for the sole '-' argument
2556 2570 */
2557 2571 if (strcmp(tokbuf, "-") == 0) {
2558 2572 state = DACF_OPT_END;
2559 2573 break;
2560 2574 }
2561 2575 /*FALLTHROUGH*/
2562 2576 case DACF_OPT_COMMA:
2563 2577 /*
2564 2578 * figure out what option was given, but don't
2565 2579 * make a federal case if invalid, just skip it
2566 2580 */
2567 2581 if (dacf_getopt(tokbuf, &opts) != 0) {
2568 2582 kobj_file_err(CE_WARN, file, w_badopt,
2569 2583 tokbuf);
2570 2584 }
2571 2585 state = DACF_OPT_OPTION;
2572 2586 break;
2573 2587 case DACF_OPT_END:
2574 2588 case DACF_OPT_OPTION:
2575 2589 case DACF_OPARG_DATA:
2576 2590 (void) strncpy(arg_spec_buf, tokbuf,
2577 2591 sizeof (arg_spec_buf));
2578 2592 state = DACF_OPARG_SPEC;
2579 2593 break;
2580 2594 case DACF_OPARG_EQUALS:
2581 2595 /*
2582 2596 * Add the arg. Warn if it's a duplicate
2583 2597 */
2584 2598 if (dacf_arg_insert(&arg_list, arg_spec_buf,
2585 2599 tokbuf) != 0) {
2586 2600 kobj_file_err(CE_WARN, file, w_dupargs,
2587 2601 arg_spec_buf);
2588 2602 }
2589 2603 state = DACF_OPARG_DATA;
2590 2604 break;
2591 2605 default:
2592 2606 kobj_file_err(CE_WARN, file, w_syntax, tokbuf);
2593 2607 state = DACF_ERR;
2594 2608 break;
2595 2609 }
2596 2610 break;
2597 2611
2598 2612 case STRING:
2599 2613 /*
2600 2614 * We need to check to see if the string has a \n in it.
2601 2615 * If so, we had an unmatched " mark error, and lex has
2602 2616 * already emitted an error for us, so we need to enter
2603 2617 * the error state. Stupid lex.
2604 2618 */
2605 2619 if (strchr(tokbuf, '\n')) {
2606 2620 state = DACF_ERR;
2607 2621 break;
2608 2622 }
2609 2623 switch (state) {
2610 2624 case DACF_NT_EQUALS:
2611 2625 if (strlen(tokbuf) == 0) {
2612 2626 kobj_file_err(CE_WARN, file,
2613 2627 w_nt_empty);
2614 2628 state = DACF_ERR;
2615 2629 break;
2616 2630 }
2617 2631 state = DACF_NT_DATA;
2618 2632 nt_datap = nt_data_buf;
2619 2633 (void) strncpy(nt_datap, tokbuf,
2620 2634 sizeof (nt_data_buf));
2621 2635 break;
2622 2636 case DACF_OPARG_EQUALS:
2623 2637 /*
2624 2638 * Add the arg. Warn if it's a duplicate
2625 2639 */
2626 2640 if (dacf_arg_insert(&arg_list, arg_spec_buf,
2627 2641 tokbuf) != 0) {
2628 2642 kobj_file_err(CE_WARN, file, w_dupargs,
2629 2643 arg_spec_buf);
2630 2644 }
2631 2645 state = DACF_OPARG_DATA;
2632 2646 break;
2633 2647 default:
2634 2648 kobj_file_err(CE_WARN, file, w_syntax, tokbuf);
2635 2649 state = DACF_ERR;
2636 2650 break;
2637 2651 }
2638 2652 break;
2639 2653
2640 2654 case COMMA:
2641 2655 switch (state) {
2642 2656 case DACF_OPT_OPTION:
2643 2657 state = DACF_OPT_COMMA;
2644 2658 break;
2645 2659 default:
2646 2660 kobj_file_err(CE_WARN, file, w_syntax, ",");
2647 2661 state = DACF_ERR;
2648 2662 break;
2649 2663 }
2650 2664 break;
2651 2665
2652 2666 case COLON:
2653 2667 if (state == DACF_MN_MODNAME)
2654 2668 state = DACF_MN_COLON;
2655 2669 else {
2656 2670 kobj_file_err(CE_WARN, file, w_syntax, ":");
2657 2671 state = DACF_ERR;
2658 2672 }
2659 2673 break;
2660 2674
2661 2675 case EOF:
2662 2676 done = 1;
2663 2677 /*FALLTHROUGH*/
2664 2678 case NEWLINE:
2665 2679 if (state == DACF_COMMENT || state == DACF_BEGIN) {
2666 2680 state = DACF_BEGIN;
2667 2681 kobj_newline(file);
2668 2682 break;
2669 2683 }
2670 2684 if ((state != DACF_OPT_OPTION) &&
2671 2685 (state != DACF_OPARG_DATA) &&
2672 2686 (state != DACF_OPT_END)) {
2673 2687 kobj_file_err(CE_WARN, file, w_newline);
2674 2688 /*
2675 2689 * We can't just do DACF_ERR here, since we'll
2676 2690 * wind up eating the _next_ newline if so.
2677 2691 */
2678 2692 state = DACF_ERR_NEWLINE;
2679 2693 kobj_newline(file);
2680 2694 break;
2681 2695 }
2682 2696
2683 2697 /*
2684 2698 * insert the rule.
2685 2699 */
2686 2700 if (dacf_rule_insert(nt_spec_type, nt_datap,
2687 2701 mn_modnamep, mn_opsetp, opid, opts, arg_list) < 0) {
2688 2702 /*
2689 2703 * We can't just do DACF_ERR here, since we'll
2690 2704 * wind up eating the _next_ newline if so.
2691 2705 */
2692 2706 kobj_file_err(CE_WARN, file, w_insert);
2693 2707 state = DACF_ERR_NEWLINE;
2694 2708 kobj_newline(file);
2695 2709 break;
2696 2710 }
2697 2711
2698 2712 state = DACF_BEGIN;
2699 2713 kobj_newline(file);
2700 2714 break;
2701 2715
2702 2716 default:
2703 2717 kobj_file_err(CE_WARN, file, w_syntax, tokbuf);
2704 2718 break;
2705 2719 } /* switch */
2706 2720
2707 2721 /*
2708 2722 * Clean up after ourselves, either after a line has terminated
2709 2723 * successfully or because of a syntax error; or when we reach
2710 2724 * EOF (remember, we may reach EOF without being 'done' with
2711 2725 * handling a particular line).
2712 2726 */
2713 2727 if (state == DACF_ERR) {
2714 2728 kobj_find_eol(file);
2715 2729 }
2716 2730 if ((state == DACF_BEGIN) || (state == DACF_ERR) ||
2717 2731 (state == DACF_ERR_NEWLINE) || done) {
2718 2732 nt_datap = NULL;
2719 2733 mn_modnamep = mn_opsetp = NULL;
2720 2734 opts = 0;
2721 2735 opid = DACF_OPID_ERROR;
2722 2736 nt_spec_type = DACF_DS_ERROR;
2723 2737 dacf_arglist_delete(&arg_list);
2724 2738 state = DACF_BEGIN;
2725 2739 }
2726 2740 } /* while */
2727 2741
2728 2742 if (dacfdebug & DACF_DBG_MSGS) {
2729 2743 printf("\ndacf debug: done!\n");
2730 2744 }
2731 2745
2732 2746 mutex_exit(&dacf_lock);
2733 2747
2734 2748 kobj_close_file(file);
2735 2749 return (0);
2736 2750 }
2737 2751
2738 2752 void
2739 2753 lock_hw_class_list()
2740 2754 {
2741 2755 mutex_enter(&hcl_lock);
2742 2756 }
2743 2757
2744 2758 void
2745 2759 unlock_hw_class_list()
2746 2760 {
2747 2761 mutex_exit(&hcl_lock);
2748 2762 }
2749 2763
2750 2764 void
2751 2765 add_class(char *exporter, char *class)
2752 2766 {
2753 2767 struct hwc_class *hcl;
2754 2768
2755 2769 /*
2756 2770 * If exporter's major is not registered in /etc/name_to_major,
2757 2771 * don't update hwc_class, but just return here.
2758 2772 */
2759 2773 if (ddi_name_to_major(exporter) >= devcnt) {
2760 2774 cmn_err(CE_WARN, "No major number for driver %s"
2761 2775 " in class %s", exporter, class);
2762 2776 return;
2763 2777 }
2764 2778 hcl = kmem_zalloc(sizeof (struct hwc_class), KM_SLEEP);
2765 2779 hcl->class_exporter = kmem_alloc(strlen(exporter) + 1, KM_SLEEP);
2766 2780 hcl->class_name = kmem_alloc(strlen(class) + 1, KM_SLEEP);
2767 2781 (void) strcpy(hcl->class_exporter, exporter);
2768 2782 (void) strcpy(hcl->class_name, class);
2769 2783 lock_hw_class_list();
2770 2784 hcl->class_next = hcl_head;
2771 2785 hcl_head = hcl;
2772 2786 unlock_hw_class_list();
2773 2787 }
2774 2788
2775 2789 /*
2776 2790 * Return the number of classes exported. If buf is not NULL, fill in
2777 2791 * the array of the class names as well.
2778 2792 *
2779 2793 * Caller must hold hcl_lock to ensure the class list unmodified while
2780 2794 * it is accessed. A typical caller will get a count first and then
2781 2795 * allocate buf. The lock should be held by the caller.
2782 2796 */
2783 2797 int
2784 2798 get_class(const char *exporter, char **buf)
2785 2799 {
2786 2800 int n = 0;
2787 2801 struct hwc_class *hcl;
2788 2802
2789 2803 ASSERT(mutex_owned(&hcl_lock));
2790 2804 for (hcl = hcl_head; hcl != NULL; hcl = hcl->class_next) {
2791 2805 if (strcmp(exporter, hcl->class_exporter) == 0) {
2792 2806 if (buf)
2793 2807 buf[n] = hcl->class_name;
2794 2808 ++n;
2795 2809 }
2796 2810 }
2797 2811
2798 2812 return (n);
2799 2813 }
2800 2814
2801 2815 void
2802 2816 read_class_file(void)
2803 2817 {
2804 2818 struct _buf *file;
2805 2819 struct hwc_class *hcl, *hcl1;
2806 2820 char tokbuf[MAXNAMELEN];
2807 2821 enum {
2808 2822 C_BEGIN, C_EXPORTER, C_END
2809 2823 } state;
2810 2824 token_t token;
2811 2825 int done = 0;
2812 2826 char *exporter = NULL, *class = NULL, *name = NULL;
2813 2827
2814 2828 if (hcl_head != NULL) {
2815 2829 hcl = hcl_head;
2816 2830 while (hcl != NULL) {
2817 2831 kmem_free(hcl->class_exporter,
2818 2832 strlen(hcl->class_exporter) + 1);
2819 2833 hcl1 = hcl;
2820 2834 hcl = hcl->class_next;
2821 2835 kmem_free(hcl1, sizeof (struct hwc_class));
2822 2836 }
2823 2837 hcl_head = NULL;
2824 2838 }
2825 2839
2826 2840 if ((file = kobj_open_file(class_file)) == (struct _buf *)-1)
2827 2841 return;
2828 2842
2829 2843 state = C_BEGIN;
2830 2844 while (!done) {
2831 2845 token = kobj_lex(file, tokbuf, sizeof (tokbuf));
2832 2846
2833 2847 switch (token) {
2834 2848 case POUND:
2835 2849 /*
2836 2850 * Skip comments.
2837 2851 */
2838 2852 kobj_find_eol(file);
2839 2853 break;
2840 2854 case NAME:
2841 2855 case STRING:
2842 2856 name = kmem_alloc(strlen(tokbuf) + 1, KM_SLEEP);
2843 2857 (void) strcpy(name, tokbuf);
2844 2858 switch (state) {
2845 2859 case C_BEGIN:
2846 2860 exporter = name;
2847 2861 state = C_EXPORTER;
2848 2862 break;
2849 2863 case C_EXPORTER:
2850 2864 class = name;
2851 2865 add_class(exporter, class);
2852 2866 state = C_END;
2853 2867 break;
2854 2868 case C_END:
2855 2869 kobj_file_err(CE_WARN, file,
2856 2870 "Extra noise after entry");
2857 2871 kmem_free(name, strlen(name) + 1);
2858 2872 kobj_find_eol(file);
2859 2873 break;
2860 2874 } /* End Switch */
2861 2875 break;
2862 2876 case EOF:
2863 2877 done = 1;
2864 2878 /*FALLTHROUGH*/
2865 2879 case NEWLINE:
2866 2880 kobj_newline(file);
2867 2881 if (state == C_EXPORTER)
2868 2882 kobj_file_err(CE_WARN, file,
2869 2883 "Partial entry ignored");
2870 2884 state = C_BEGIN;
2871 2885 if (exporter)
2872 2886 kmem_free(exporter, strlen(exporter) + 1);
2873 2887 if (class)
2874 2888 kmem_free(class, strlen(class) + 1);
2875 2889 exporter = NULL;
2876 2890 class = NULL;
2877 2891 break;
2878 2892 default:
2879 2893 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
2880 2894 break;
2881 2895 }
2882 2896 }
2883 2897 kobj_close_file(file);
2884 2898 }
2885 2899
2886 2900 /*
2887 2901 * Given par_list, get a list of parent major number
2888 2902 */
2889 2903 int
2890 2904 impl_parlist_to_major(struct par_list *pl, char parents[])
2891 2905 {
2892 2906 struct hwc_spec *hwcp;
2893 2907 struct hwc_class *hcl;
2894 2908 major_t major;
2895 2909 int nmajor = 0;
2896 2910 extern int devcnt;
2897 2911
2898 2912 for (; pl != NULL; pl = pl->par_next) {
2899 2913 if ((pl->par_major < devcnt) && (parents[pl->par_major] == 0)) {
2900 2914 parents[pl->par_major] = 1;
2901 2915 nmajor++;
2902 2916 continue;
2903 2917 }
2904 2918
2905 2919 /* parent specs cannot be mapped to a driver */
2906 2920 if (pl->par_major != DDI_MAJOR_T_NONE)
2907 2921 continue;
2908 2922
2909 2923 /* class spec */
2910 2924 hwcp = pl->par_specs;
2911 2925 ASSERT(hwcp->hwc_class_name);
2912 2926 ASSERT(hwcp->hwc_parent_name == NULL);
2913 2927
2914 2928 for (hcl = hcl_head; hcl != NULL; hcl = hcl->class_next) {
2915 2929 if (strcmp(hwcp->hwc_class_name, hcl->class_name) != 0)
2916 2930 continue;
2917 2931 major = ddi_name_to_major(hcl->class_exporter);
2918 2932 ASSERT(major != DDI_MAJOR_T_NONE);
2919 2933 if (parents[major] == 0) {
2920 2934 parents[major] = 1;
2921 2935 nmajor++;
2922 2936 }
2923 2937 }
2924 2938 }
2925 2939 return (nmajor);
2926 2940 }
2927 2941
2928 2942 /*
2929 2943 * delete a parent list and all its hwc specs
2930 2944 */
2931 2945 void
2932 2946 impl_delete_par_list(struct par_list *pl)
2933 2947 {
2934 2948 struct par_list *saved_pl;
2935 2949 struct hwc_spec *hp, *hp1;
2936 2950
2937 2951 while (pl) {
2938 2952 hp = pl->par_specs;
2939 2953 while (hp) {
2940 2954 hp1 = hp;
2941 2955 hp = hp->hwc_next;
2942 2956 hwc_free(hp1);
2943 2957 }
2944 2958 saved_pl = pl;
2945 2959 pl = pl->par_next;
2946 2960 kmem_free(saved_pl, sizeof (*saved_pl));
2947 2961 }
2948 2962 }
2949 2963
2950 2964 #if defined(_PSM_MODULES)
2951 2965 void
2952 2966 open_mach_list(void)
2953 2967 {
2954 2968 struct _buf *file;
2955 2969 char tokbuf[MAXNAMELEN];
2956 2970 token_t token;
2957 2971 struct psm_mach *machp;
2958 2972
2959 2973 if ((file = kobj_open_file(mach_file)) == (struct _buf *)-1)
2960 2974 return;
2961 2975
2962 2976 while ((token = kobj_lex(file, tokbuf, sizeof (tokbuf))) != EOF) {
2963 2977 switch (token) {
2964 2978 case POUND:
2965 2979 /*
2966 2980 * Skip comments.
2967 2981 */
2968 2982 kobj_find_eol(file);
2969 2983 break;
2970 2984 case NAME:
2971 2985 case STRING:
2972 2986 machp = kmem_alloc((sizeof (struct psm_mach) +
2973 2987 strlen(tokbuf) + 1), KM_SLEEP);
2974 2988 machp->m_next = pmach_head;
2975 2989 machp->m_machname = (char *)(machp + 1);
2976 2990 (void) strcpy(machp->m_machname, tokbuf);
2977 2991 pmach_head = machp;
2978 2992 break;
2979 2993 case NEWLINE:
2980 2994 kobj_newline(file);
2981 2995 break;
2982 2996 default:
2983 2997 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
2984 2998 break;
2985 2999 }
2986 3000 }
2987 3001 kobj_close_file(file);
2988 3002 }
2989 3003
2990 3004 void *
2991 3005 get_next_mach(void *handle, char *buf)
2992 3006 {
2993 3007 struct psm_mach *machp;
2994 3008
2995 3009 machp = (struct psm_mach *)handle;
2996 3010 if (machp)
2997 3011 machp = machp->m_next;
2998 3012 else
2999 3013 machp = pmach_head;
3000 3014 if (machp)
3001 3015 (void) strcpy(buf, machp->m_machname);
3002 3016 return (machp);
3003 3017 }
3004 3018
3005 3019 void
3006 3020 close_mach_list(void)
3007 3021 {
3008 3022 struct psm_mach *machp;
3009 3023
3010 3024 while (pmach_head) {
3011 3025 machp = pmach_head;
3012 3026 pmach_head = machp->m_next;
3013 3027 kmem_free(machp, sizeof (struct psm_mach) +
3014 3028 strlen(machp->m_machname) + 1);
3015 3029 }
3016 3030 }
3017 3031 #endif /* _PSM_MODULES */
3018 3032
3019 3033 #if defined(_RTC_CONFIG)
3020 3034 /*
3021 3035 * Read in the 'zone_lag' value from the rtc configuration file,
3022 3036 * and return the value to the caller. Note that there is other information
3023 3037 * in this file (zone_info), so we ignore unknown values. We do spit out
3024 3038 * warnings if the line doesn't begin with an identifier, or if we don't find
3025 3039 * exactly "zone_lag=value". No one should be editing this file by hand
3026 3040 * (use the rtc command instead), but it's better to be careful.
3027 3041 */
3028 3042 long
3029 3043 process_rtc_config_file(void)
3030 3044 {
3031 3045 enum {
3032 3046 R_NEW, R_NAME, R_EQUALS, R_VALUE
3033 3047 } state;
3034 3048 struct _buf *file;
3035 3049 char tokbuf[MAXNAMELEN];
3036 3050 token_t token;
3037 3051 long zone_lag = 0;
3038 3052 u_longlong_t tmp;
3039 3053 int done = 0;
3040 3054
3041 3055 if ((file = kobj_open_file(rtc_config_file)) == (struct _buf *)-1)
3042 3056 return (0);
3043 3057
3044 3058 state = R_NEW;
3045 3059
3046 3060 while (!done) {
3047 3061 token = kobj_lex(file, tokbuf, sizeof (tokbuf));
3048 3062
3049 3063 switch (token) {
3050 3064 case POUND:
3051 3065 /*
3052 3066 * Skip comments.
3053 3067 */
3054 3068 kobj_find_eol(file);
3055 3069 break;
3056 3070 case NAME:
3057 3071 case STRING:
3058 3072 if (state == R_NEW) {
3059 3073 if (strcmp(tokbuf, "zone_lag") == 0)
3060 3074 state = R_NAME;
3061 3075 else
3062 3076 kobj_find_eol(file); /* Ignore */
3063 3077 } else
3064 3078 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
3065 3079 break;
3066 3080 case EQUALS:
3067 3081 if (state == R_NAME)
3068 3082 state = R_EQUALS;
3069 3083 else
3070 3084 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
3071 3085 break;
3072 3086 case DECVAL:
3073 3087 if (state == R_EQUALS) {
3074 3088 if (kobj_getvalue(tokbuf, &tmp) != 0)
3075 3089 kobj_file_err(CE_WARN, file,
3076 3090 "Bad value %s for zone_lag",
3077 3091 tokbuf);
3078 3092 else
3079 3093 zone_lag = (long)tmp;
3080 3094 state = R_VALUE;
3081 3095 } else
3082 3096 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
3083 3097 break;
3084 3098 case EOF:
3085 3099 done = 1;
3086 3100 /*FALLTHROUGH*/
3087 3101 case NEWLINE:
3088 3102 if (state != R_NEW && state != R_VALUE)
3089 3103 kobj_file_err(CE_WARN, file,
3090 3104 "Partial zone_lag entry ignored");
3091 3105 kobj_newline(file);
3092 3106 state = R_NEW;
3093 3107 break;
3094 3108 default:
3095 3109 kobj_file_err(CE_WARN, file, tok_err, tokbuf);
3096 3110 break;
3097 3111 }
3098 3112 }
3099 3113 kobj_close_file(file);
3100 3114 return (zone_lag);
3101 3115 }
3102 3116 #endif /* _RTC_CONFIG */
3103 3117
3104 3118
3105 3119 /*
3106 3120 * Append node spec to the end of par_list
3107 3121 */
3108 3122 static void
3109 3123 append(struct hwc_spec *spec, struct par_list *par)
3110 3124 {
3111 3125 struct hwc_spec *hwc, *last;
3112 3126
3113 3127 ASSERT(par->par_specs);
3114 3128 for (hwc = par->par_specs; hwc; hwc = hwc->hwc_next)
3115 3129 last = hwc;
3116 3130 last->hwc_next = spec;
3117 3131 }
3118 3132
3119 3133 /*
3120 3134 * Given a parent=/full-pathname, see if the platform
3121 3135 * can resolve the pathname to driver, otherwise, try
3122 3136 * the leaf node name.
3123 3137 */
3124 3138 static major_t
3125 3139 get_major(char *parent)
3126 3140 {
3127 3141 major_t major = DDI_MAJOR_T_NONE;
3128 3142 char *tmp, *driver = NULL;
3129 3143
3130 3144 if (*parent == '/')
3131 3145 major = path_to_major(parent);
3132 3146
3133 3147 if (major != DDI_MAJOR_T_NONE)
3134 3148 return (major);
3135 3149
3136 3150 /* extract the name between '/' and '@' */
3137 3151 if (*parent == '/')
3138 3152 driver = strrchr(parent, '/') + 1;
3139 3153 else
3140 3154 driver = parent;
3141 3155 if ((tmp = strchr(driver, '@')) != NULL)
3142 3156 *tmp = '\0';
3143 3157 major = ddi_name_to_major(driver);
3144 3158 if (tmp)
3145 3159 *tmp = '@';
3146 3160 return (major);
3147 3161 }
3148 3162
3149 3163 /*
3150 3164 * Chain together specs whose parent's module name is the same.
3151 3165 */
3152 3166 static void
3153 3167 add_spec(struct hwc_spec *spec, struct par_list **par)
3154 3168 {
3155 3169 major_t maj;
3156 3170 struct par_list *pl, *par_last = NULL;
3157 3171 char *parent = spec->hwc_parent_name;
3158 3172 char *class = spec->hwc_class_name;
3159 3173
3160 3174 ASSERT(parent || class);
3161 3175
3162 3176 /*
3163 3177 * If given a parent=/full-pathname, see if the platform
3164 3178 * can resolve the pathname to driver, otherwise, try
3165 3179 * the leaf node name.
3166 3180 *
3167 3181 * If parent=/full-pathname doesn't resolve to a driver,
3168 3182 * this could be cause by DR removal of the device.
3169 3183 * We put it on the major=-2 list in case the device
3170 3184 * is brought back into the system by DR.
3171 3185 */
3172 3186 if (parent) {
3173 3187 maj = get_major(parent);
3174 3188 if (maj == DDI_MAJOR_T_NONE) {
3175 3189 if ((*parent == '/') &&
3176 3190 (strncmp(parent, "/pseudo", 7) != 0)) {
3177 3191 maj = (major_t)-2;
3178 3192 } else {
3179 3193 cmn_err(CE_WARN,
3180 3194 "add_spec: No major number for %s",
3181 3195 parent);
3182 3196 hwc_free(spec);
3183 3197 return;
3184 3198 }
3185 3199 }
3186 3200 } else
3187 3201 maj = DDI_MAJOR_T_NONE;
3188 3202
3189 3203 /*
3190 3204 * Scan the list looking for a matching parent. When parent is
3191 3205 * not NULL, we match the parent by major. If parent is NULL but
3192 3206 * class is not NULL, we mache the pl by class name.
3193 3207 */
3194 3208 for (pl = *par; pl; pl = pl->par_next) {
3195 3209 if ((parent && (maj == pl->par_major)) || ((parent == NULL) &&
3196 3210 class && pl->par_specs->hwc_class_name && (strncmp(class,
3197 3211 pl->par_specs->hwc_class_name, strlen(class)) == 0))) {
3198 3212 append(spec, pl);
3199 3213 return;
3200 3214 }
3201 3215 par_last = pl;
3202 3216 }
3203 3217
3204 3218 /*
3205 3219 * Didn't find a match on the list. Make a new parent list.
3206 3220 */
3207 3221 pl = kmem_zalloc(sizeof (*pl), KM_SLEEP);
3208 3222 pl->par_major = maj;
3209 3223 pl->par_specs = spec;
3210 3224 if (*par == NULL) { /* null par list */
3211 3225 *par = pl;
3212 3226 return;
3213 3227 }
3214 3228 /* put "class=" entries last (lower pri if dups) */
3215 3229 if (maj == DDI_MAJOR_T_NONE) {
3216 3230 par_last->par_next = pl;
3217 3231 return;
3218 3232 }
3219 3233
3220 3234 /* ensure unresolved "parent=/full-path" goes first */
3221 3235 if ((maj != (major_t)-2) && ((*par)->par_major == (major_t)-2))
3222 3236 par = &(*par)->par_next;
3223 3237 pl->par_next = *par;
3224 3238 *par = pl;
3225 3239 }
3226 3240
3227 3241 /*
3228 3242 * Add property spec to property list in original order
3229 3243 */
3230 3244 static void
3231 3245 add_props(struct hwc_spec *spec, ddi_prop_t **props)
3232 3246 {
3233 3247 ASSERT(spec->hwc_devi_name == NULL);
3234 3248
3235 3249 if (spec->hwc_devi_sys_prop_ptr) {
3236 3250 while (*props)
3237 3251 props = &(*props)->prop_next;
3238 3252 *props = spec->hwc_devi_sys_prop_ptr;
3239 3253
3240 3254 /* remove these properties from the spec */
3241 3255 spec->hwc_devi_sys_prop_ptr = NULL;
3242 3256 }
3243 3257 hwc_free(spec);
3244 3258 }
↓ open down ↓ |
2418 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX