1 /* $NetBSD: autoconf.c,v 1.15 2014/01/11 08:07:16 tsutsui Exp $ */ 2 3 /*- 4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Tohru Nishimura. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 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 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 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 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 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 33 34 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.15 2014/01/11 08:07:16 tsutsui Exp $"); 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/buf.h> 39 #include <sys/conf.h> 40 #include <sys/reboot.h> 41 #include <sys/device.h> 42 43 #include <machine/autoconf.h> 44 #include <machine/bootinfo.h> 45 #include <machine/disklabel.h> 46 #include <machine/cpu.h> 47 48 #include <dev/scsipi/scsi_all.h> 49 #include <dev/scsipi/scsipi_all.h> 50 #include <dev/scsipi/scsiconf.h> 51 52 #include <luna68k/luna68k/isr.h> 53 54 static uint booted_adpt, booted_ctlr, booted_unit, booted_part; 55 56 /* 57 * Determine mass storage and memory configuration for a machine. 58 */ 59 void 60 cpu_configure(void) 61 { 62 63 booted_device = NULL; /* set by device drivers (if found) */ 64 65 booted_adpt = B_ADAPTOR(bootdev); 66 booted_ctlr = B_CONTROLLER(bootdev); 67 booted_unit = B_UNIT(bootdev); 68 booted_part = B_PARTITION(bootdev); 69 70 (void)splhigh(); 71 isrinit(); 72 if (config_rootfound("mainbus", NULL) == NULL) 73 panic("autoconfig failed, no root"); 74 75 spl0(); 76 } 77 78 void 79 device_register(device_t dev, void *aux) 80 { 81 static device_t booted_controller; 82 static bool bootdev_found; 83 84 /* 85 * Check booted device. 86 */ 87 if (bootdev_found) 88 return; 89 90 if (booted_adpt == LUNA68K_BOOTADPT_LANCE && 91 device_is_a(dev, "le")) { 92 struct mainbus_attach_args *ma = aux; 93 94 if (booted_ctlr == 0 && 95 ma->ma_addr == LUNA68K_BOOTADPT_LANCE0_PA) { 96 booted_device = dev; 97 bootdev_found = true; 98 } 99 return; 100 } 101 102 if (booted_adpt == LUNA68K_BOOTADPT_SPC && 103 device_is_a(dev, "spc")) { 104 struct mainbus_attach_args *ma = aux; 105 106 if ((booted_ctlr == 0 && 107 (u_int)ma->ma_addr == LUNA68K_BOOTADPT_SPC0_PA) || 108 (booted_ctlr == 1 && 109 (u_int)ma->ma_addr == LUNA68K_BOOTADPT_SPC1_PA)) { 110 booted_controller = dev; 111 } 112 return; 113 } 114 115 if (booted_controller != NULL && 116 (device_is_a(dev, "sd") || device_is_a(dev, "cd"))) { 117 struct scsipibus_attach_args *sa = aux; 118 device_t parent = device_parent(dev); 119 120 if (device_parent(parent) != booted_controller) 121 return; 122 if (booted_unit != sa->sa_periph->periph_target) 123 return; 124 booted_device = dev; 125 booted_partition = booted_part; 126 bootdev_found = true; 127 return; 128 } 129 } 130 131 void 132 cpu_rootconf(void) 133 { 134 135 printf("boot device: %s\n", 136 (booted_device) ? device_xname(booted_device) : "<unknown>"); 137 138 rootconf(); 139 } 140