Sun Jun 10 17:05:19 2012 UTC ()
Make detection of root on wedges (dk(4)) machine independent. Remove
MD code for x86, xen, sparc64.


(mlelstv)
diff -r1.186 -r1.187 src/sys/arch/sparc64/sparc64/autoconf.c
diff -r1.62 -r1.63 src/sys/arch/x86/x86/x86_autoconf.c
diff -r1.13 -r1.14 src/sys/arch/xen/x86/autoconf.c
diff -r1.63 -r1.64 src/sys/dev/dkwedge/dk.c
diff -r1.442 -r1.443 src/sys/kern/init_main.c
diff -r1.212 -r1.213 src/sys/kern/kern_subr.c
diff -r1.140 -r1.141 src/sys/sys/device.h
diff -r1.56 -r1.57 src/sys/sys/disk.h

cvs diff -r1.186 -r1.187 src/sys/arch/sparc64/sparc64/autoconf.c (expand / switch to unified diff)

--- src/sys/arch/sparc64/sparc64/autoconf.c 2012/05/28 19:24:30 1.186
+++ src/sys/arch/sparc64/sparc64/autoconf.c 2012/06/10 17:05:18 1.187
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: autoconf.c,v 1.186 2012/05/28 19:24:30 martin Exp $ */ 1/* $NetBSD: autoconf.c,v 1.187 2012/06/10 17:05:18 mlelstv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 4 * Copyright (c) 1996
5 * The President and Fellows of Harvard College. All rights reserved. 5 * The President and Fellows of Harvard College. All rights reserved.
6 * Copyright (c) 1992, 1993 6 * Copyright (c) 1992, 1993
7 * The Regents of the University of California. All rights reserved. 7 * The Regents of the University of California. All rights reserved.
8 * 8 *
9 * This software was developed by the Computer Systems Engineering group 9 * This software was developed by the Computer Systems Engineering group
10 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 10 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
11 * contributed to Berkeley. 11 * contributed to Berkeley.
12 * 12 *
13 * All advertising materials mentioning features or use of this software 13 * All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement: 14 * must display the following acknowledgement:
@@ -38,27 +38,27 @@ @@ -38,27 +38,27 @@
38 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 38 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE. 45 * SUCH DAMAGE.
46 * 46 *
47 * @(#)autoconf.c 8.4 (Berkeley) 10/1/93 47 * @(#)autoconf.c 8.4 (Berkeley) 10/1/93
48 */ 48 */
49 49
50#include <sys/cdefs.h> 50#include <sys/cdefs.h>
51__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.186 2012/05/28 19:24:30 martin Exp $"); 51__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.187 2012/06/10 17:05:18 mlelstv Exp $");
52 52
53#include "opt_ddb.h" 53#include "opt_ddb.h"
54#include "opt_kgdb.h" 54#include "opt_kgdb.h"
55#include "opt_modular.h" 55#include "opt_modular.h"
56#include "opt_multiprocessor.h" 56#include "opt_multiprocessor.h"
57 57
58#include <sys/param.h> 58#include <sys/param.h>
59#include <sys/kernel.h> 59#include <sys/kernel.h>
60#include <sys/systm.h> 60#include <sys/systm.h>
61#include <sys/buf.h> 61#include <sys/buf.h>
62#include <sys/disklabel.h> 62#include <sys/disklabel.h>
63#include <sys/device.h> 63#include <sys/device.h>
64#include <sys/disk.h> 64#include <sys/disk.h>
@@ -498,30 +498,27 @@ cpu_configure(void) @@ -498,30 +498,27 @@ cpu_configure(void)
498 (void)spl0(); 498 (void)spl0();
499} 499}
500 500
501void 501void
502cpu_rootconf(void) 502cpu_rootconf(void)
503{ 503{
504 if (booted_device == NULL) { 504 if (booted_device == NULL) {
505 printf("FATAL: boot device not found, check your firmware " 505 printf("FATAL: boot device not found, check your firmware "
506 "settings!\n"); 506 "settings!\n");
507 setroot(NULL, 0); 507 setroot(NULL, 0);
508 return; 508 return;
509 } 509 }
510 510
511 if (config_handle_wedges(booted_device, booted_partition) == 0) 511 setroot(booted_device, booted_partition);
512 setroot(booted_wedge, 0); 
513 else 
514 setroot(booted_device, booted_partition); 
515} 512}
516 513
517char * 514char *
518clockfreq(long freq) 515clockfreq(long freq)
519{ 516{
520 char *p; 517 char *p;
521 static char sbuf[10]; 518 static char sbuf[10];
522 519
523 freq /= 1000; 520 freq /= 1000;
524 sprintf(sbuf, "%ld", freq / 1000); 521 sprintf(sbuf, "%ld", freq / 1000);
525 freq %= 1000; 522 freq %= 1000;
526 if (freq) { 523 if (freq) {
527 freq += 1000; /* now in 1000..1999 */ 524 freq += 1000; /* now in 1000..1999 */

cvs diff -r1.62 -r1.63 src/sys/arch/x86/x86/x86_autoconf.c (expand / switch to unified diff)

--- src/sys/arch/x86/x86/x86_autoconf.c 2011/10/18 23:43:36 1.62
+++ src/sys/arch/x86/x86/x86_autoconf.c 2012/06/10 17:05:18 1.63
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: x86_autoconf.c,v 1.62 2011/10/18 23:43:36 dyoung Exp $ */ 1/* $NetBSD: x86_autoconf.c,v 1.63 2012/06/10 17:05:18 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1990 The Regents of the University of California. 4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * William Jolitz. 8 * William Jolitz.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 * 33 *
34 * @(#)autoconf.c 7.1 (Berkeley) 5/9/91 34 * @(#)autoconf.c 7.1 (Berkeley) 5/9/91
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.62 2011/10/18 23:43:36 dyoung Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.63 2012/06/10 17:05:18 mlelstv Exp $");
39 39
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/device.h> 42#include <sys/device.h>
43#include <sys/disklabel.h> 43#include <sys/disklabel.h>
44#include <sys/conf.h> 44#include <sys/conf.h>
45#include <sys/malloc.h> 45#include <sys/malloc.h>
46#include <sys/vnode.h> 46#include <sys/vnode.h>
47#include <sys/fcntl.h> 47#include <sys/fcntl.h>
48#include <sys/disk.h> 48#include <sys/disk.h>
49#include <sys/proc.h> 49#include <sys/proc.h>
50#include <sys/md5.h> 50#include <sys/md5.h>
51#include <sys/kauth.h> 51#include <sys/kauth.h>
@@ -54,35 +54,26 @@ __KERNEL_RCSID(0, "$NetBSD: x86_autoconf @@ -54,35 +54,26 @@ __KERNEL_RCSID(0, "$NetBSD: x86_autoconf
54#include <machine/bootinfo.h> 54#include <machine/bootinfo.h>
55#include <machine/pio.h> 55#include <machine/pio.h>
56 56
57#include "acpica.h" 57#include "acpica.h"
58#include "wsdisplay.h" 58#include "wsdisplay.h"
59 59
60#if NACPICA > 0 60#if NACPICA > 0
61#include <dev/acpi/acpivar.h> 61#include <dev/acpi/acpivar.h>
62#endif 62#endif
63 63
64struct disklist *x86_alldisks; 64struct disklist *x86_alldisks;
65int x86_ndisks; 65int x86_ndisks;
66 66
67static void 
68handle_wedges(device_t dv, int par) 
69{ 
70 if (config_handle_wedges(dv, par) == 0) 
71 return; 
72 booted_device = dv; 
73 booted_partition = par; 
74} 
75 
76static int 67static int
77is_valid_disk(device_t dv) 68is_valid_disk(device_t dv)
78{ 69{
79 70
80 if (device_class(dv) != DV_DISK) 71 if (device_class(dv) != DV_DISK)
81 return (0); 72 return (0);
82  73
83 return (device_is_a(dv, "dk") || 74 return (device_is_a(dv, "dk") ||
84 device_is_a(dv, "sd") || 75 device_is_a(dv, "sd") ||
85 device_is_a(dv, "wd") || 76 device_is_a(dv, "wd") ||
86 device_is_a(dv, "ld") || 77 device_is_a(dv, "ld") ||
87 device_is_a(dv, "ed")); 78 device_is_a(dv, "ed"));
88} 79}
@@ -334,27 +325,29 @@ findroot(void) @@ -334,27 +325,29 @@ findroot(void)
334 dv != NULL; 325 dv != NULL;
335 dv = deviter_next(&di)) { 326 dv = deviter_next(&di)) {
336 cfdata_t cd; 327 cfdata_t cd;
337 size_t len; 328 size_t len;
338 329
339 if (device_class(dv) != DV_DISK) 330 if (device_class(dv) != DV_DISK)
340 continue; 331 continue;
341 332
342 cd = device_cfdata(dv); 333 cd = device_cfdata(dv);
343 len = strlen(cd->cf_name); 334 len = strlen(cd->cf_name);
344 335
345 if (strncmp(cd->cf_name, biv->devname, len) == 0 && 336 if (strncmp(cd->cf_name, biv->devname, len) == 0 &&
346 biv->devname[len] - '0' == device_unit(dv)) { 337 biv->devname[len] - '0' == device_unit(dv)) {
347 handle_wedges(dv, biv->devname[len + 1] - 'a'); 338 booted_device = dv;
 339 booted_partition = biv->devname[len + 1] - 'a';
 340 booted_nblks = 0;
348 break; 341 break;
349 } 342 }
350 } 343 }
351 deviter_release(&di); 344 deviter_release(&di);
352 if (dv != NULL) 345 if (dv != NULL)
353 return; 346 return;
354 } 347 }
355 348
356 if ((biw = lookup_bootinfo(BTINFO_BOOTWEDGE)) != NULL) { 349 if ((biw = lookup_bootinfo(BTINFO_BOOTWEDGE)) != NULL) {
357 /* 350 /*
358 * Scan all disk devices for ones that match the passed data. 351 * Scan all disk devices for ones that match the passed data.
359 * Don't break if one is found, to get possible multiple 352 * Don't break if one is found, to get possible multiple
360 * matches - for problem tracking. Use the first match anyway 353 * matches - for problem tracking. Use the first match anyway
@@ -378,31 +371,34 @@ findroot(void) @@ -378,31 +371,34 @@ findroot(void)
378 continue; 371 continue;
379 goto bootwedge_found; 372 goto bootwedge_found;
380 } 373 }
381 374
382 continue; 375 continue;
383 bootwedge_found: 376 bootwedge_found:
384 if (booted_device) { 377 if (booted_device) {
385 printf("WARNING: double match for boot " 378 printf("WARNING: double match for boot "
386 "device (%s, %s)\n", 379 "device (%s, %s)\n",
387 device_xname(booted_device), 380 device_xname(booted_device),
388 device_xname(dv)); 381 device_xname(dv));
389 continue; 382 continue;
390 } 383 }
391 dkwedge_set_bootwedge(dv, biw->startblk, biw->nblks); 384 booted_device = dv;
 385 booted_partition = 0;
 386 booted_nblks = biw->nblks;
 387 booted_startblk = biw->startblk;
392 } 388 }
393 deviter_release(&di); 389 deviter_release(&di);
394 390
395 if (booted_wedge) 391 if (booted_nblks)
396 return; 392 return;
397 } 393 }
398 394
399 if ((bid = lookup_bootinfo(BTINFO_BOOTDISK)) != NULL) { 395 if ((bid = lookup_bootinfo(BTINFO_BOOTDISK)) != NULL) {
400 /* 396 /*
401 * Scan all disk devices for ones that match the passed data. 397 * Scan all disk devices for ones that match the passed data.
402 * Don't break if one is found, to get possible multiple 398 * Don't break if one is found, to get possible multiple
403 * matches - for problem tracking. Use the first match anyway 399 * matches - for problem tracking. Use the first match anyway
404 * because lower device numbers are more likely to be the 400 * because lower device numbers are more likely to be the
405 * boot device. 401 * boot device.
406 */ 402 */
407 for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST); 403 for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
408 dv != NULL; 404 dv != NULL;
@@ -435,27 +431,29 @@ findroot(void) @@ -435,27 +431,29 @@ findroot(void)
435 continue; 431 continue;
436 goto bootdisk_found; 432 goto bootdisk_found;
437 } 433 }
438 434
439 continue; 435 continue;
440 bootdisk_found: 436 bootdisk_found:
441 if (booted_device) { 437 if (booted_device) {
442 printf("WARNING: double match for boot " 438 printf("WARNING: double match for boot "
443 "device (%s, %s)\n", 439 "device (%s, %s)\n",
444 device_xname(booted_device), 440 device_xname(booted_device),
445 device_xname(dv)); 441 device_xname(dv));
446 continue; 442 continue;
447 } 443 }
448 handle_wedges(dv, bid->partition); 444 booted_device = dv;
 445 booted_partition = bid->partition;
 446 booted_nblks = 0;
449 } 447 }
450 deviter_release(&di); 448 deviter_release(&di);
451 449
452 if (booted_device) 450 if (booted_device)
453 return; 451 return;
454 452
455 /* 453 /*
456 * No booted device found; check CD-ROM boot at last. 454 * No booted device found; check CD-ROM boot at last.
457 * 455 *
458 * Our bootloader assumes CD-ROM boot if biosdev is larger 456 * Our bootloader assumes CD-ROM boot if biosdev is larger
459 * than the number of hard drives recognized by the BIOS. 457 * than the number of hard drives recognized by the BIOS.
460 * The number of drives can be found in BTINFO_BIOSGEOM here. 458 * The number of drives can be found in BTINFO_BIOSGEOM here.
461 * 459 *
@@ -467,51 +465,45 @@ findroot(void) @@ -467,51 +465,45 @@ findroot(void)
467 /* 465 /*
468 * XXX 466 * XXX
469 * There is no proper way to detect which unit is 467 * There is no proper way to detect which unit is
470 * recognized as a bootable CD-ROM drive by the BIOS. 468 * recognized as a bootable CD-ROM drive by the BIOS.
471 * Assume the first unit is the one. 469 * Assume the first unit is the one.
472 */ 470 */
473 for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST); 471 for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
474 dv != NULL; 472 dv != NULL;
475 dv = deviter_next(&di)) { 473 dv = deviter_next(&di)) {
476 if (device_class(dv) == DV_DISK && 474 if (device_class(dv) == DV_DISK &&
477 device_is_a(dv, "cd")) { 475 device_is_a(dv, "cd")) {
478 booted_device = dv; 476 booted_device = dv;
479 booted_partition = 0; 477 booted_partition = 0;
 478 booted_nblks = 0;
480 break; 479 break;
481 } 480 }
482 } 481 }
483 deviter_release(&di); 482 deviter_release(&di);
484 } 483 }
485 } 484 }
486} 485}
487 486
488void 487void
489cpu_rootconf(void) 488cpu_rootconf(void)
490{ 489{
491 490
492 findroot(); 491 findroot();
493 matchbiosdisks(); 492 matchbiosdisks();
494 493
495 if (booted_wedge) { 494 aprint_normal("boot device: %s\n",
496 KASSERT(booted_device != NULL); 495 booted_device ? device_xname(booted_device) : "<unknown>");
497 aprint_normal("boot device: %s (%s)\n", 496 setroot(booted_device, booted_partition);
498 device_xname(booted_wedge), device_xname(booted_device)); 
499 setroot(booted_wedge, 0); 
500 } else { 
501 aprint_normal("boot device: %s\n", 
502 booted_device ? device_xname(booted_device) : "<unknown>"); 
503 setroot(booted_device, booted_partition); 
504 } 
505} 497}
506 498
507void 499void
508device_register(device_t dev, void *aux) 500device_register(device_t dev, void *aux)
509{ 501{
510 device_t isaboot, pciboot; 502 device_t isaboot, pciboot;
511 503
512 isaboot = device_isa_register(dev, aux); 504 isaboot = device_isa_register(dev, aux);
513 pciboot = device_pci_register(dev, aux); 505 pciboot = device_pci_register(dev, aux);
514 506
515 if (isaboot == NULL && pciboot == NULL) 507 if (isaboot == NULL && pciboot == NULL)
516 return; 508 return;
517 509

cvs diff -r1.13 -r1.14 src/sys/arch/xen/x86/autoconf.c (expand / switch to unified diff)

--- src/sys/arch/xen/x86/autoconf.c 2009/11/27 03:23:15 1.13
+++ src/sys/arch/xen/x86/autoconf.c 2012/06/10 17:05:19 1.14
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: autoconf.c,v 1.13 2009/11/27 03:23:15 rmind Exp $ */ 1/* $NetBSD: autoconf.c,v 1.14 2012/06/10 17:05:19 mlelstv Exp $ */
2/* NetBSD: autoconf.c,v 1.75 2003/12/30 12:33:22 pk Exp */ 2/* NetBSD: autoconf.c,v 1.75 2003/12/30 12:33:22 pk Exp */
3 3
4/*- 4/*-
5 * Copyright (c) 1990 The Regents of the University of California. 5 * Copyright (c) 1990 The Regents of the University of California.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to Berkeley by 8 * This code is derived from software contributed to Berkeley by
9 * William Jolitz. 9 * William Jolitz.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -35,27 +35,27 @@ @@ -35,27 +35,27 @@
35 * @(#)autoconf.c 7.1 (Berkeley) 5/9/91 35 * @(#)autoconf.c 7.1 (Berkeley) 5/9/91
36 */ 36 */
37 37
38/* 38/*
39 * Setup the system to run on the current machine. 39 * Setup the system to run on the current machine.
40 * 40 *
41 * Configure() is called at boot time and initializes the vba 41 * Configure() is called at boot time and initializes the vba
42 * device tables and the memory controller monitoring. Available 42 * device tables and the memory controller monitoring. Available
43 * devices are determined (from possibilities mentioned in ioconf.c), 43 * devices are determined (from possibilities mentioned in ioconf.c),
44 * and the drivers are initialized. 44 * and the drivers are initialized.
45 */ 45 */
46 46
47#include <sys/cdefs.h> 47#include <sys/cdefs.h>
48__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.13 2009/11/27 03:23:15 rmind Exp $"); 48__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.14 2012/06/10 17:05:19 mlelstv Exp $");
49 49
50#include "opt_xen.h" 50#include "opt_xen.h"
51#include "opt_compat_oldboot.h" 51#include "opt_compat_oldboot.h"
52#include "opt_multiprocessor.h" 52#include "opt_multiprocessor.h"
53#include "opt_nfs_boot.h" 53#include "opt_nfs_boot.h"
54 54
55#include <sys/param.h> 55#include <sys/param.h>
56#include <sys/systm.h> 56#include <sys/systm.h>
57#include <sys/buf.h> 57#include <sys/buf.h>
58#include <sys/disklabel.h> 58#include <sys/disklabel.h>
59#include <sys/disk.h> 59#include <sys/disk.h>
60#include <sys/conf.h> 60#include <sys/conf.h>
61#ifdef COMPAT_OLDBOOT 61#ifdef COMPAT_OLDBOOT
@@ -78,27 +78,26 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v @@ -78,27 +78,26 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v
78#include <nfs/nfsmount.h> 78#include <nfs/nfsmount.h>
79#include <nfs/nfsdiskless.h> 79#include <nfs/nfsdiskless.h>
80#include <xen/if_xennetvar.h> 80#include <xen/if_xennetvar.h>
81#endif 81#endif
82 82
83#include <machine/pte.h> 83#include <machine/pte.h>
84#include <machine/cpu.h> 84#include <machine/cpu.h>
85#include <machine/gdt.h> 85#include <machine/gdt.h>
86#include <machine/pcb.h> 86#include <machine/pcb.h>
87#include <machine/bootinfo.h> 87#include <machine/bootinfo.h>
88 88
89static void findroot(void); 89static void findroot(void);
90static int is_valid_disk(device_t); 90static int is_valid_disk(device_t);
91static void handle_wedges(device_t, int); 
92 91
93struct disklist *x86_alldisks; 92struct disklist *x86_alldisks;
94int x86_ndisks; 93int x86_ndisks;
95 94
96#include "bios32.h" 95#include "bios32.h"
97#if NBIOS32 > 0 96#if NBIOS32 > 0
98#include <machine/bios32.h> 97#include <machine/bios32.h>
99#endif 98#endif
100 99
101#include "opt_pcibios.h" 100#include "opt_pcibios.h"
102#ifdef PCIBIOS 101#ifdef PCIBIOS
103#include <dev/pci/pcireg.h> 102#include <dev/pci/pcireg.h>
104#include <dev/pci/pcivar.h> 103#include <dev/pci/pcivar.h>
@@ -145,36 +144,29 @@ cpu_configure(void) @@ -145,36 +144,29 @@ cpu_configure(void)
145#ifdef MULTIPROCESSOR 144#ifdef MULTIPROCESSOR
146 /* propagate this to the idle pcb's. */ 145 /* propagate this to the idle pcb's. */
147 cpu_init_idle_lwps(); 146 cpu_init_idle_lwps();
148#endif 147#endif
149 148
150 spl0(); 149 spl0();
151} 150}
152 151
153void 152void
154cpu_rootconf(void) 153cpu_rootconf(void)
155{ 154{
156 findroot(); 155 findroot();
157 156
158 if (booted_wedge) { 157 printf("boot device: %s\n",
159 KASSERT(booted_device != NULL); 158 booted_device ? device_xname(booted_device) : "<unknown>");
160 printf("boot device: %s (%s)\n", 159 setroot(booted_device, booted_partition);
161 device_xname(booted_wedge), device_xname(booted_device)); 
162 setroot(booted_wedge, 0); 
163 } else { 
164 printf("boot device: %s\n", 
165 booted_device ? device_xname(booted_device) : "<unknown>"); 
166 setroot(booted_device, booted_partition); 
167 } 
168} 160}
169 161
170 162
171/* 163/*
172 * Attempt to find the device from which we were booted. 164 * Attempt to find the device from which we were booted.
173 * If we can do so, and not instructed not to do so, 165 * If we can do so, and not instructed not to do so,
174 * change rootdev to correspond to the load device. 166 * change rootdev to correspond to the load device.
175 */ 167 */
176void 168void
177findroot(void) 169findroot(void)
178{ 170{
179 device_t dv; 171 device_t dv;
180 deviter_t di; 172 deviter_t di;
@@ -189,27 +181,27 @@ findroot(void) @@ -189,27 +181,27 @@ findroot(void)
189 dv != NULL; 181 dv != NULL;
190 dv = deviter_next(&di)) { 182 dv = deviter_next(&di)) {
191 bool is_ifnet, is_disk; 183 bool is_ifnet, is_disk;
192 const char *devname; 184 const char *devname;
193 185
194 is_ifnet = (device_class(dv) == DV_IFNET); 186 is_ifnet = (device_class(dv) == DV_IFNET);
195 is_disk = is_valid_disk(dv); 187 is_disk = is_valid_disk(dv);
196 devname = device_xname(dv); 188 devname = device_xname(dv);
197 189
198 if (!is_ifnet && !is_disk) 190 if (!is_ifnet && !is_disk)
199 continue; 191 continue;
200 192
201 if (is_disk && xcp.xcp_bootdev[0] == 0) { 193 if (is_disk && xcp.xcp_bootdev[0] == 0) {
202 handle_wedges(dv, 0); 194 booted_device = dv;
203 break; 195 break;
204 } 196 }
205 197
206 if (strncmp(xcp.xcp_bootdev, devname, strlen(devname))) 198 if (strncmp(xcp.xcp_bootdev, devname, strlen(devname)))
207 continue; 199 continue;
208 200
209 if (is_disk && strlen(xcp.xcp_bootdev) > strlen(devname)) { 201 if (is_disk && strlen(xcp.xcp_bootdev) > strlen(devname)) {
210 booted_partition = toupper( 202 booted_partition = toupper(
211 xcp.xcp_bootdev[strlen(devname)]) - 'A'; 203 xcp.xcp_bootdev[strlen(devname)]) - 'A';
212 } 204 }
213 205
214 booted_device = dv; 206 booted_device = dv;
215 break; 207 break;
@@ -344,35 +336,26 @@ device_register(device_t dev, void *aux) @@ -344,35 +336,26 @@ device_register(device_t dev, void *aux)
344 } 336 }
345 return; 337 return;
346 338
347found: 339found:
348 if (booted_device) { 340 if (booted_device) {
349 /* XXX should be a "panic()" */ 341 /* XXX should be a "panic()" */
350 printf("warning: double match for boot device (%s, %s)\n", 342 printf("warning: double match for boot device (%s, %s)\n",
351 device_xname(booted_device), device_xname(dev)); 343 device_xname(booted_device), device_xname(dev));
352 return; 344 return;
353 } 345 }
354 booted_device = dev; 346 booted_device = dev;
355} 347}
356 348
357static void 
358handle_wedges(device_t dv, int par) 
359{ 
360 if (config_handle_wedges(dv, par) == 0) 
361 return; 
362 booted_device = dv; 
363 booted_partition = par; 
364} 
365 
366static int 349static int
367is_valid_disk(device_t dv) 350is_valid_disk(device_t dv)
368{ 351{
369 352
370 if (device_class(dv) != DV_DISK) 353 if (device_class(dv) != DV_DISK)
371 return (0); 354 return (0);
372 355
373 return (device_is_a(dv, "dk") || 356 return (device_is_a(dv, "dk") ||
374 device_is_a(dv, "sd") || 357 device_is_a(dv, "sd") ||
375 device_is_a(dv, "wd") || 358 device_is_a(dv, "wd") ||
376 device_is_a(dv, "ld") || 359 device_is_a(dv, "ld") ||
377 device_is_a(dv, "ed") || 360 device_is_a(dv, "ed") ||
378 device_is_a(dv, "xbd")); 361 device_is_a(dv, "xbd"));

cvs diff -r1.63 -r1.64 src/sys/dev/dkwedge/dk.c (expand / switch to unified diff)

--- src/sys/dev/dkwedge/dk.c 2012/04/27 18:15:55 1.63
+++ src/sys/dev/dkwedge/dk.c 2012/06/10 17:05:19 1.64
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dk.c,v 1.63 2012/04/27 18:15:55 drochner Exp $ */ 1/* $NetBSD: dk.c,v 1.64 2012/06/10 17:05:19 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe. 8 * by Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.63 2012/04/27 18:15:55 drochner Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.64 2012/06/10 17:05:19 mlelstv Exp $");
34 34
35#ifdef _KERNEL_OPT 35#ifdef _KERNEL_OPT
36#include "opt_dkwedge.h" 36#include "opt_dkwedge.h"
37#endif 37#endif
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/systm.h> 40#include <sys/systm.h>
41#include <sys/proc.h> 41#include <sys/proc.h>
42#include <sys/errno.h> 42#include <sys/errno.h>
43#include <sys/pool.h> 43#include <sys/pool.h>
44#include <sys/ioctl.h> 44#include <sys/ioctl.h>
45#include <sys/disklabel.h> 45#include <sys/disklabel.h>
46#include <sys/disk.h> 46#include <sys/disk.h>
@@ -738,64 +738,26 @@ dkwedge_print_wnames(void) @@ -738,64 +738,26 @@ dkwedge_print_wnames(void)
738 struct dkwedge_softc *sc; 738 struct dkwedge_softc *sc;
739 int i; 739 int i;
740 740
741 rw_enter(&dkwedges_lock, RW_WRITER); 741 rw_enter(&dkwedges_lock, RW_WRITER);
742 for (i = 0; i < ndkwedges; i++) { 742 for (i = 0; i < ndkwedges; i++) {
743 if ((sc = dkwedges[i]) == NULL) 743 if ((sc = dkwedges[i]) == NULL)
744 continue; 744 continue;
745 printf(" wedge:%s", sc->sc_wname); 745 printf(" wedge:%s", sc->sc_wname);
746 } 746 }
747 rw_exit(&dkwedges_lock); 747 rw_exit(&dkwedges_lock);
748} 748}
749 749
750/* 750/*
751 * dkwedge_set_bootwedge 
752 * 
753 * Set the booted_wedge global based on the specified parent name 
754 * and offset/length. 
755 */ 
756void 
757dkwedge_set_bootwedge(device_t parent, daddr_t startblk, uint64_t nblks) 
758{ 
759 struct dkwedge_softc *sc; 
760 int i; 
761 
762 rw_enter(&dkwedges_lock, RW_WRITER); 
763 for (i = 0; i < ndkwedges; i++) { 
764 if ((sc = dkwedges[i]) == NULL) 
765 continue; 
766 if (strcmp(sc->sc_parent->dk_name, device_xname(parent)) == 0 && 
767 sc->sc_offset == startblk && 
768 sc->sc_size == nblks) { 
769 if (booted_wedge) { 
770 printf("WARNING: double match for boot wedge " 
771 "(%s, %s)\n", 
772 device_xname(booted_wedge), 
773 device_xname(sc->sc_dev)); 
774 continue; 
775 } 
776 booted_device = parent; 
777 booted_wedge = sc->sc_dev; 
778 booted_partition = 0; 
779 } 
780 } 
781 /* 
782 * XXX What if we don't find one? Should we create a special 
783 * XXX root wedge? 
784 */ 
785 rw_exit(&dkwedges_lock); 
786} 
787 
788/* 
789 * We need a dummy object to stuff into the dkwedge discovery method link 751 * We need a dummy object to stuff into the dkwedge discovery method link
790 * set to ensure that there is always at least one object in the set. 752 * set to ensure that there is always at least one object in the set.
791 */ 753 */
792static struct dkwedge_discovery_method dummy_discovery_method; 754static struct dkwedge_discovery_method dummy_discovery_method;
793__link_set_add_bss(dkwedge_methods, dummy_discovery_method); 755__link_set_add_bss(dkwedge_methods, dummy_discovery_method);
794 756
795/* 757/*
796 * dkwedge_init: 758 * dkwedge_init:
797 * 759 *
798 * Initialize the disk wedge subsystem. 760 * Initialize the disk wedge subsystem.
799 */ 761 */
800void 762void
801dkwedge_init(void) 763dkwedge_init(void)
@@ -1456,75 +1418,48 @@ dkdump(dev_t dev, daddr_t blkno, void *v @@ -1456,75 +1418,48 @@ dkdump(dev_t dev, daddr_t blkno, void *v
1456 rv = (*bdev->d_dump)(sc->sc_pdev, blkno + sc->sc_offset, va, size); 1418 rv = (*bdev->d_dump)(sc->sc_pdev, blkno + sc->sc_offset, va, size);
1457 1419
1458out: 1420out:
1459 mutex_exit(&sc->sc_parent->dk_rawlock); 1421 mutex_exit(&sc->sc_parent->dk_rawlock);
1460 mutex_exit(&sc->sc_dk.dk_openlock); 1422 mutex_exit(&sc->sc_dk.dk_openlock);
1461 1423
1462 return rv; 1424 return rv;
1463} 1425}
1464 1426
1465/* 1427/*
1466 * config glue 1428 * config glue
1467 */ 1429 */
1468 1430
1469int 1431/*
1470config_handle_wedges(struct device *dv, int par) 1432 * dkwedge_find_partition
 1433 *
 1434 * Find wedge corresponding to the specified parent name
 1435 * and offset/length.
 1436 */
 1437device_t
 1438dkwedge_find_partition(device_t parent, daddr_t startblk, uint64_t nblks)
1471{ 1439{
1472 struct dkwedge_list wl; 1440 struct dkwedge_softc *sc;
1473 struct dkwedge_info *wi; 1441 int i;
1474 struct vnode *vn; 1442 device_t wedge = NULL;
1475 char diskname[16]; 
1476 int i, error; 
1477 
1478 if ((vn = opendisk(dv)) == NULL) 
1479 return -1; 
1480 
1481 wl.dkwl_bufsize = sizeof(*wi) * 16; 
1482 wl.dkwl_buf = wi = malloc(wl.dkwl_bufsize, M_TEMP, M_WAITOK); 
1483 
1484 error = VOP_IOCTL(vn, DIOCLWEDGES, &wl, FREAD, NOCRED); 
1485 VOP_CLOSE(vn, FREAD, NOCRED); 
1486 vput(vn); 
1487 if (error) { 
1488#ifdef DEBUG_WEDGE 
1489 printf("%s: List wedges returned %d\n", 
1490 device_xname(dv), error); 
1491#endif 
1492 free(wi, M_TEMP); 
1493 return -1; 
1494 } 
1495 
1496#ifdef DEBUG_WEDGE 
1497 printf("%s: Returned %u(%u) wedges\n", device_xname(dv), 
1498 wl.dkwl_nwedges, wl.dkwl_ncopied); 
1499#endif 
1500 snprintf(diskname, sizeof(diskname), "%s%c", device_xname(dv), 
1501 par + 'a'); 
1502 
1503 for (i = 0; i < wl.dkwl_ncopied; i++) { 
1504#ifdef DEBUG_WEDGE 
1505 printf("%s: Looking for %s in %s\n",  
1506 device_xname(dv), diskname, wi[i].dkw_wname); 
1507#endif 
1508 if (strcmp(wi[i].dkw_wname, diskname) == 0) 
1509 break; 
1510 } 
1511 1443
1512 if (i == wl.dkwl_ncopied) { 1444 rw_enter(&dkwedges_lock, RW_READER);
1513#ifdef DEBUG_WEDGE 1445 for (i = 0; i < ndkwedges; i++) {
1514 printf("%s: Cannot find wedge with parent %s\n", 1446 if ((sc = dkwedges[i]) == NULL)
1515 device_xname(dv), diskname); 1447 continue;
1516#endif 1448 if (strcmp(sc->sc_parent->dk_name, device_xname(parent)) == 0 &&
1517 free(wi, M_TEMP); 1449 sc->sc_offset == startblk &&
1518 return -1; 1450 sc->sc_size == nblks) {
 1451 if (wedge) {
 1452 printf("WARNING: double match for boot wedge "
 1453 "(%s, %s)\n",
 1454 device_xname(wedge),
 1455 device_xname(sc->sc_dev));
 1456 continue;
 1457 }
 1458 wedge = sc->sc_dev;
 1459 }
1519 } 1460 }
 1461 rw_exit(&dkwedges_lock);
1520 1462
1521#ifdef DEBUG_WEDGE 1463 return wedge;
1522 printf("%s: Setting boot wedge %s (%s) at %llu %llu\n",  
1523 device_xname(dv), wi[i].dkw_devname, wi[i].dkw_wname, 
1524 (unsigned long long)wi[i].dkw_offset, 
1525 (unsigned long long)wi[i].dkw_size); 
1526#endif 
1527 dkwedge_set_bootwedge(dv, wi[i].dkw_offset, wi[i].dkw_size); 
1528 free(wi, M_TEMP); 
1529 return 0; 
1530} 1464}
 1465

cvs diff -r1.442 -r1.443 src/sys/kern/init_main.c (expand / switch to unified diff)

--- src/sys/kern/init_main.c 2012/02/19 21:06:47 1.442
+++ src/sys/kern/init_main.c 2012/06/10 17:05:18 1.443
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: init_main.c,v 1.442 2012/02/19 21:06:47 rmind Exp $ */ 1/* $NetBSD: init_main.c,v 1.443 2012/06/10 17:05:18 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -87,27 +87,27 @@ @@ -87,27 +87,27 @@
87 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 87 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
88 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 88 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
89 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 89 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
90 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 90 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
91 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 91 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
92 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 92 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
93 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 93 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
94 * SUCH DAMAGE. 94 * SUCH DAMAGE.
95 * 95 *
96 * @(#)init_main.c 8.16 (Berkeley) 5/14/95 96 * @(#)init_main.c 8.16 (Berkeley) 5/14/95
97 */ 97 */
98 98
99#include <sys/cdefs.h> 99#include <sys/cdefs.h>
100__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.442 2012/02/19 21:06:47 rmind Exp $"); 100__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.443 2012/06/10 17:05:18 mlelstv Exp $");
101 101
102#include "opt_ddb.h" 102#include "opt_ddb.h"
103#include "opt_ipsec.h" 103#include "opt_ipsec.h"
104#include "opt_modular.h" 104#include "opt_modular.h"
105#include "opt_ntp.h" 105#include "opt_ntp.h"
106#include "opt_pipe.h" 106#include "opt_pipe.h"
107#include "opt_syscall_debug.h" 107#include "opt_syscall_debug.h"
108#include "opt_sysv.h" 108#include "opt_sysv.h"
109#include "opt_fileassoc.h" 109#include "opt_fileassoc.h"
110#include "opt_ktrace.h" 110#include "opt_ktrace.h"
111#include "opt_pax.h" 111#include "opt_pax.h"
112#include "opt_compat_netbsd.h" 112#include "opt_compat_netbsd.h"
113#include "opt_wapbl.h" 113#include "opt_wapbl.h"
@@ -249,26 +249,27 @@ extern time_t rootfstime; @@ -249,26 +249,27 @@ extern time_t rootfstime;
249struct lwp *curlwp = &lwp0; 249struct lwp *curlwp = &lwp0;
250#endif 250#endif
251struct proc *initproc; 251struct proc *initproc;
252 252
253struct vnode *rootvp, *swapdev_vp; 253struct vnode *rootvp, *swapdev_vp;
254int boothowto; 254int boothowto;
255int cold = 1; /* still working on startup */ 255int cold = 1; /* still working on startup */
256struct timespec boottime; /* time at system startup - will only follow settime deltas */ 256struct timespec boottime; /* time at system startup - will only follow settime deltas */
257 257
258int start_init_exec; /* semaphore for start_init() */ 258int start_init_exec; /* semaphore for start_init() */
259 259
260cprng_strong_t *kern_cprng; 260cprng_strong_t *kern_cprng;
261 261
 262static void rootconf(void);
262static void check_console(struct lwp *l); 263static void check_console(struct lwp *l);
263static void start_init(void *); 264static void start_init(void *);
264static void configure(void); 265static void configure(void);
265static void configure2(void); 266static void configure2(void);
266static void configure3(void); 267static void configure3(void);
267void main(void); 268void main(void);
268 269
269/* 270/*
270 * System startup; initialize the world, create process 0, mount root 271 * System startup; initialize the world, create process 0, mount root
271 * filesystem, and fork to create init and pagedaemon. Most of the 272 * filesystem, and fork to create init and pagedaemon. Most of the
272 * hard work is done in the lower-level initialization routines including 273 * hard work is done in the lower-level initialization routines including
273 * startup(), which does memory initialization and autoconfiguration. 274 * startup(), which does memory initialization and autoconfiguration.
274 */ 275 */
@@ -623,27 +624,27 @@ main(void) @@ -623,27 +624,27 @@ main(void)
623 /* 624 /*
624 * Finalize configuration now that all real devices have been 625 * Finalize configuration now that all real devices have been
625 * found. This needs to be done before the root device is 626 * found. This needs to be done before the root device is
626 * selected, since finalization may create the root device. 627 * selected, since finalization may create the root device.
627 */ 628 */
628 config_finalize(); 629 config_finalize();
629 630
630 sysctl_finalize(); 631 sysctl_finalize();
631 632
632 /* 633 /*
633 * Now that autoconfiguration has completed, we can determine 634 * Now that autoconfiguration has completed, we can determine
634 * the root and dump devices. 635 * the root and dump devices.
635 */ 636 */
636 cpu_rootconf(); 637 rootconf();
637 cpu_dumpconf(); 638 cpu_dumpconf();
638 639
639 /* Mount the root file system. */ 640 /* Mount the root file system. */
640 do { 641 do {
641 domountroothook(root_device); 642 domountroothook(root_device);
642 if ((error = vfs_mountroot())) { 643 if ((error = vfs_mountroot())) {
643 printf("cannot mount root, error = %d\n", error); 644 printf("cannot mount root, error = %d\n", error);
644 boothowto |= RB_ASKNAME; 645 boothowto |= RB_ASKNAME;
645 setroot(root_device, 646 setroot(root_device,
646 (rootdev != NODEV) ? DISKPART(rootdev) : 0); 647 (rootdev != NODEV) ? DISKPART(rootdev) : 0);
647 } 648 }
648 } while (error != 0); 649 } while (error != 0);
649 mountroothook_destroy(); 650 mountroothook_destroy();
@@ -810,26 +811,94 @@ configure3(void) @@ -810,26 +811,94 @@ configure3(void)
810{ 811{
811 812
812 /* 813 /*
813 * Create threads to call back and finish configuration for 814 * Create threads to call back and finish configuration for
814 * devices that want the mounted root file system. 815 * devices that want the mounted root file system.
815 */ 816 */
816 config_create_mountrootthreads(); 817 config_create_mountrootthreads();
817 818
818 /* Get the threads going and into any sleeps before continuing. */ 819 /* Get the threads going and into any sleeps before continuing. */
819 yield(); 820 yield();
820} 821}
821 822
822static void 823static void
 824rootconf_handle_wedges(void)
 825{
 826 struct partinfo dpart;
 827 struct partition *p;
 828 struct vnode *vp;
 829 daddr_t startblk;
 830 uint64_t nblks;
 831 device_t dev;
 832 int error;
 833
 834 if (booted_nblks) {
 835 /*
 836 * bootloader passed geometry
 837 */
 838 dev = booted_device;
 839 startblk = booted_startblk;
 840 nblks = booted_nblks;
 841
 842 /*
 843 * keep booted_device and booted_partition
 844 * in case the kernel doesn't identify a wedge
 845 */
 846 } else {
 847 /*
 848 * bootloader passed partition number
 849 *
 850 * We cannot ask the partition device directly when it is
 851 * covered by a wedge. Instead we look up the geometry in
 852 * the disklabel.
 853 */
 854 vp = opendisk(booted_device);
 855 error = VOP_IOCTL(vp, DIOCGPART, &dpart, FREAD, NOCRED);
 856 VOP_CLOSE(vp, FREAD, NOCRED);
 857 vput(vp);
 858 if (error)
 859 return;
 860
 861 KASSERT(booted_partition >= 0
 862 && booted_partition < MAXPARTITIONS);
 863
 864 p = &dpart.disklab->d_partitions[booted_partition];
 865
 866 dev = booted_device;
 867 startblk = p->p_offset;
 868 nblks = p->p_size;
 869 }
 870
 871 dev = dkwedge_find_partition(dev, startblk, nblks);
 872 if (dev != NULL) {
 873 booted_device = dev;
 874 booted_partition = 0;
 875 }
 876}
 877
 878static void
 879rootconf(void)
 880{
 881 cpu_rootconf();
 882
 883 if (booted_device == NULL)
 884 return;
 885
 886 rootconf_handle_wedges();
 887
 888 setroot(booted_device, booted_partition);
 889}
 890
 891static void
823check_console(struct lwp *l) 892check_console(struct lwp *l)
824{ 893{
825 struct vnode *vp; 894 struct vnode *vp;
826 int error; 895 int error;
827 896
828 error = namei_simple_kernel("/dev/console", 897 error = namei_simple_kernel("/dev/console",
829 NSM_FOLLOW_NOEMULROOT, &vp); 898 NSM_FOLLOW_NOEMULROOT, &vp);
830 if (error == 0) 899 if (error == 0)
831 vrele(vp); 900 vrele(vp);
832 else if (error == ENOENT) 901 else if (error == ENOENT)
833 printf("warning: no /dev/console\n"); 902 printf("warning: no /dev/console\n");
834 else 903 else
835 printf("warning: lookup /dev/console: error %d\n", error); 904 printf("warning: lookup /dev/console: error %d\n", error);

cvs diff -r1.212 -r1.213 src/sys/kern/kern_subr.c (expand / switch to unified diff)

--- src/sys/kern/kern_subr.c 2011/09/19 23:54:29 1.212
+++ src/sys/kern/kern_subr.c 2012/06/10 17:05:18 1.213
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_subr.c,v 1.212 2011/09/19 23:54:29 christos Exp $ */ 1/* $NetBSD: kern_subr.c,v 1.213 2012/06/10 17:05:18 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, and by Luke Mewburn. 9 * NASA Ames Research Center, and by Luke Mewburn.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -69,27 +69,27 @@ @@ -69,27 +69,27 @@
69 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 69 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
70 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 70 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
71 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 71 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
72 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 72 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
73 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 73 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
74 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 74 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
75 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 75 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
76 * SUCH DAMAGE. 76 * SUCH DAMAGE.
77 * 77 *
78 * @(#)kern_subr.c 8.4 (Berkeley) 2/14/95 78 * @(#)kern_subr.c 8.4 (Berkeley) 2/14/95
79 */ 79 */
80 80
81#include <sys/cdefs.h> 81#include <sys/cdefs.h>
82__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.212 2011/09/19 23:54:29 christos Exp $"); 82__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.213 2012/06/10 17:05:18 mlelstv Exp $");
83 83
84#include "opt_ddb.h" 84#include "opt_ddb.h"
85#include "opt_md.h" 85#include "opt_md.h"
86#include "opt_syscall_debug.h" 86#include "opt_syscall_debug.h"
87#include "opt_ktrace.h" 87#include "opt_ktrace.h"
88#include "opt_ptrace.h" 88#include "opt_ptrace.h"
89#include "opt_tftproot.h" 89#include "opt_tftproot.h"
90 90
91#include <sys/param.h> 91#include <sys/param.h>
92#include <sys/systm.h> 92#include <sys/systm.h>
93#include <sys/proc.h> 93#include <sys/proc.h>
94#include <sys/mount.h> 94#include <sys/mount.h>
95#include <sys/device.h> 95#include <sys/device.h>
@@ -148,32 +148,32 @@ isswap(device_t dv) @@ -148,32 +148,32 @@ isswap(device_t dv)
148} 148}
149 149
150/* 150/*
151 * Determine the root device and, if instructed to, the root file system. 151 * Determine the root device and, if instructed to, the root file system.
152 */ 152 */
153 153
154#ifdef MEMORY_DISK_IS_ROOT 154#ifdef MEMORY_DISK_IS_ROOT
155int md_is_root = 1; 155int md_is_root = 1;
156#else 156#else
157int md_is_root = 0; 157int md_is_root = 0;
158#endif 158#endif
159 159
160/* 160/*
161 * The device and wedge that we booted from. If booted_wedge is NULL, 161 * The device and partition that we booted from.
162 * the we might consult booted_partition. 
163 */ 162 */
164device_t booted_device; 163device_t booted_device;
165device_t booted_wedge; 
166int booted_partition; 164int booted_partition;
 165daddr_t booted_startblk;
 166uint64_t booted_nblks;
167 167
168/* 168/*
169 * Use partition letters if it's a disk class but not a wedge. 169 * Use partition letters if it's a disk class but not a wedge.
170 * XXX Check for wedge is kinda gross. 170 * XXX Check for wedge is kinda gross.
171 */ 171 */
172#define DEV_USES_PARTITIONS(dv) \ 172#define DEV_USES_PARTITIONS(dv) \
173 (device_class((dv)) == DV_DISK && \ 173 (device_class((dv)) == DV_DISK && \
174 !device_is_a((dv), "dk")) 174 !device_is_a((dv), "dk"))
175 175
176void 176void
177setroot(device_t bootdv, int bootpartition) 177setroot(device_t bootdv, int bootpartition)
178{ 178{
179 device_t dv; 179 device_t dv;

cvs diff -r1.140 -r1.141 src/sys/sys/device.h (expand / switch to unified diff)

--- src/sys/sys/device.h 2011/11/13 22:05:58 1.140
+++ src/sys/sys/device.h 2012/06/10 17:05:18 1.141
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: device.h,v 1.140 2011/11/13 22:05:58 christos Exp $ */ 1/* $NetBSD: device.h,v 1.141 2012/06/10 17:05:18 mlelstv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 2000 Christopher G. Demetriou 4 * Copyright (c) 1996, 2000 Christopher G. Demetriou
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -413,34 +413,34 @@ typedef int (*cfprint_t)(void *, const c @@ -413,34 +413,34 @@ typedef int (*cfprint_t)(void *, const c
413struct pdevinit { 413struct pdevinit {
414 void (*pdev_attach)(int); 414 void (*pdev_attach)(int);
415 int pdev_count; 415 int pdev_count;
416}; 416};
417 417
418/* This allows us to wildcard a device unit. */ 418/* This allows us to wildcard a device unit. */
419#define DVUNIT_ANY -1 419#define DVUNIT_ANY -1
420 420
421#ifdef _KERNEL 421#ifdef _KERNEL
422 422
423extern struct cfdriverlist allcfdrivers;/* list of all cfdrivers */ 423extern struct cfdriverlist allcfdrivers;/* list of all cfdrivers */
424extern struct cftablelist allcftables; /* list of all cfdata tables */ 424extern struct cftablelist allcftables; /* list of all cfdata tables */
425extern device_t booted_device; /* the device we booted from */ 425extern device_t booted_device; /* the device we booted from */
426extern device_t booted_wedge; /* the wedge on that device */ 426extern int booted_partition; /* the partition on that device */
427extern int booted_partition; /* or the partition on that device */ 427extern daddr_t booted_startblk; /* or the start of a wedge */
 428extern uint64_t booted_nblks; /* and the size of that wedge */
428 429
429struct vnode *opendisk(struct device *); 430struct vnode *opendisk(struct device *);
430int getdisksize(struct vnode *, uint64_t *, unsigned *); 431int getdisksize(struct vnode *, uint64_t *, unsigned *);
431struct dkwedge_info; 432struct dkwedge_info;
432int getdiskinfo(struct vnode *, struct dkwedge_info *); 433int getdiskinfo(struct vnode *, struct dkwedge_info *);
433int config_handle_wedges(struct device *, int); 
434 434
435void config_init(void); 435void config_init(void);
436int config_init_component(struct cfdriver *const*, 436int config_init_component(struct cfdriver *const*,
437 const struct cfattachinit *, struct cfdata *); 437 const struct cfattachinit *, struct cfdata *);
438int config_fini_component(struct cfdriver *const*, 438int config_fini_component(struct cfdriver *const*,
439 const struct cfattachinit *, struct cfdata *); 439 const struct cfattachinit *, struct cfdata *);
440void config_init_mi(void); 440void config_init_mi(void);
441void drvctl_init(void); 441void drvctl_init(void);
442 442
443int config_cfdriver_attach(struct cfdriver *); 443int config_cfdriver_attach(struct cfdriver *);
444int config_cfdriver_detach(struct cfdriver *); 444int config_cfdriver_detach(struct cfdriver *);
445 445
446int config_cfattach_attach(const char *, struct cfattach *); 446int config_cfattach_attach(const char *, struct cfattach *);

cvs diff -r1.56 -r1.57 src/sys/sys/disk.h (expand / switch to unified diff)

--- src/sys/sys/disk.h 2012/01/16 18:47:58 1.56
+++ src/sys/sys/disk.h 2012/06/10 17:05:18 1.57
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: disk.h,v 1.56 2012/01/16 18:47:58 christos Exp $ */ 1/* $NetBSD: disk.h,v 1.57 2012/06/10 17:05:18 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1996, 1997, 2004 The NetBSD Foundation, Inc. 4 * Copyright (c) 1996, 1997, 2004 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -520,20 +520,20 @@ void disk_destroy(struct disk *); @@ -520,20 +520,20 @@ void disk_destroy(struct disk *);
520void disk_busy(struct disk *); 520void disk_busy(struct disk *);
521void disk_unbusy(struct disk *, long, int); 521void disk_unbusy(struct disk *, long, int);
522bool disk_isbusy(struct disk *); 522bool disk_isbusy(struct disk *);
523void disk_blocksize(struct disk *, int); 523void disk_blocksize(struct disk *, int);
524struct disk *disk_find(const char *); 524struct disk *disk_find(const char *);
525int disk_ioctl(struct disk *, u_long, void *, int, struct lwp *); 525int disk_ioctl(struct disk *, u_long, void *, int, struct lwp *);
526 526
527void dkwedge_init(void); 527void dkwedge_init(void);
528int dkwedge_add(struct dkwedge_info *); 528int dkwedge_add(struct dkwedge_info *);
529int dkwedge_del(struct dkwedge_info *); 529int dkwedge_del(struct dkwedge_info *);
530void dkwedge_delall(struct disk *); 530void dkwedge_delall(struct disk *);
531int dkwedge_list(struct disk *, struct dkwedge_list *, struct lwp *); 531int dkwedge_list(struct disk *, struct dkwedge_list *, struct lwp *);
532void dkwedge_discover(struct disk *); 532void dkwedge_discover(struct disk *);
533void dkwedge_set_bootwedge(device_t, daddr_t, uint64_t); 
534int dkwedge_read(struct disk *, struct vnode *, daddr_t, void *, size_t); 533int dkwedge_read(struct disk *, struct vnode *, daddr_t, void *, size_t);
535device_t dkwedge_find_by_wname(const char *); 534device_t dkwedge_find_by_wname(const char *);
536void dkwedge_print_wnames(void); 535void dkwedge_print_wnames(void);
 536device_t dkwedge_find_partition(device_t, daddr_t, uint64_t);
537#endif 537#endif
538 538
539#endif /* _SYS_DISK_H_ */ 539#endif /* _SYS_DISK_H_ */