Home | History | Annotate | Line # | Download | only in mvme68k
      1 /*	$NetBSD: autoconf.c,v 1.49 2026/01/10 21:35:12 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988 University of Utah.
      5  * Copyright (c) 1982, 1986, 1990, 1993
      6  * 	The Regents of the University of California. All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * the Systems Programming Group of the University of Utah Computer
     10  * Science Department.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  * from: Utah $Hdr: autoconf.c 1.36 92/12/20$
     37  *
     38  *	@(#)autoconf.c  8.2 (Berkeley) 1/12/94
     39  */
     40 
     41 /*
     42  * Setup the system to run on the current machine.
     43  *
     44  * Configure() is called at boot time.
     45  */
     46 
     47 #include <sys/cdefs.h>
     48 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.49 2026/01/10 21:35:12 thorpej Exp $");
     49 
     50 #include "opt_mvmeconf.h"
     51 
     52 #include <sys/param.h>
     53 #include <sys/systm.h>
     54 #include <sys/buf.h>
     55 #include <sys/conf.h>
     56 #include <sys/reboot.h>
     57 #include <sys/device.h>
     58 
     59 #include <machine/vmparam.h>
     60 #include <machine/disklabel.h>
     61 #include <machine/cpu.h>
     62 #include <machine/autoconf.h>
     63 #include <machine/pte.h>
     64 
     65 #include <dev/scsipi/scsi_all.h>
     66 #include <dev/scsipi/scsipi_all.h>
     67 #include <dev/scsipi/scsiconf.h>
     68 
     69 #include <mvme68k/mvme68k/isr.h>
     70 
     71 #ifdef MVME147
     72 #include <mvme68k/dev/pccreg.h>
     73 #endif
     74 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177)
     75 #include <dev/mvme/pcctworeg.h>
     76 #endif
     77 
     78 
     79 /*
     80  * Determine mass storage and memory configuration for a machine.
     81  */
     82 void
     83 cpu_configure(void)
     84 {
     85 
     86 	booted_device = NULL;	/* set by device drivers (if found) */
     87 
     88 	/* Initialise interrupt handlers */
     89 	isrinit();
     90 
     91 	if (config_rootfound("mainbus", NULL) == NULL)
     92 		panic("autoconfig failed, no root");
     93 }
     94 
     95 void
     96 cpu_rootconf(void)
     97 {
     98 
     99 	printf("boot device: %s",
    100 		(booted_device) ? device_xname(booted_device) : "<unknown>");
    101 
    102 	if (bootpart)
    103 		printf(" (partition %d)\n", bootpart);
    104 	else
    105 		printf("\n");
    106 
    107 	booted_partition = bootpart;
    108 	rootconf();
    109 }
    110 
    111 void
    112 device_register(device_t dev, void *aux)
    113 {
    114 	static device_t controller;
    115 	device_t parent = device_parent(dev);
    116 
    117 	if (booted_device)
    118 		return;
    119 
    120 	if (controller == NULL && parent) {
    121 		switch (machineid) {
    122 #ifdef MVME147
    123 		case MVME_147:
    124 			/*
    125 			 * We currently only support booting from the 147's
    126 			 * onboard scsi and ethernet. So ensure this
    127 			 * device's parent is the PCC driver.
    128 			 */
    129 			if (!device_is_a(parent, "pcc"))
    130 				return;
    131 
    132 			if (bootaddr == PCC_PADDR(PCC_WDSC_OFF) &&
    133 			    device_is_a(dev, "wdsc")) {
    134 				controller = dev;
    135 				return;
    136 			}
    137 
    138 			if (bootaddr == PCC_PADDR(PCC_LE_OFF) &&
    139 			    device_is_a(dev, "le")) {
    140 				booted_device = dev;
    141 				return;
    142 			}
    143 
    144 			break;
    145 #endif /* MVME_147 */
    146 
    147 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177)
    148 		case MVME_162:
    149 		case MVME_167:
    150 		case MVME_172:
    151 		case MVME_177:
    152 			/*
    153 			 * We currently only support booting from the 16x and
    154 			 * 17x onboard scsi and ethernet. So ensure this
    155 			 * device's parent is the PCCTWO driver.
    156 			 */
    157 			if (!device_is_a(parent, "pcctwo"))
    158 				return;
    159 
    160 			if (bootaddr == PCCTWO_PADDR(PCCTWO_NCRSC_OFF) &&
    161 			    device_is_a(dev, "osiop")) {
    162 				controller = dev;
    163 				return;
    164 			}
    165 
    166 			if (bootaddr == PCCTWO_PADDR(PCCTWO_IE_OFF) &&
    167 			    device_is_a(dev, "ie")) {
    168 				booted_device = dev;
    169 				return;
    170 			}
    171 
    172 			break;
    173 #endif /* MVME_162 || MVME_167 || MVME_172 || MVME_177 */
    174 
    175 		default:
    176 			break;
    177 		}
    178 
    179 		return;
    180 	}
    181 
    182 	/*
    183 	 * Find out which device on the scsibus we booted from
    184 	 */
    185 	if (device_is_a(dev, "sd") ||
    186 	    device_is_a(dev, "cd") ||
    187 	    device_is_a(dev, "st")) {
    188 		struct scsipibus_attach_args *sa = aux;
    189 		struct scsipi_periph *periph = sa->sa_periph;
    190 
    191 		if (device_parent(parent) != controller)
    192 			return;
    193 
    194 		/*
    195 		 * bootdevlun is formatted like so:
    196 		 *
    197 		 *	tttt.llll
    198 		 *
    199 		 * So, a disk at SCSI ID 5 would have 0x50 as the
    200 		 * bootdevlun value.
    201 		 *
    202 		 * XXX True for all Bug revisions???
    203 		 */
    204 		int targ = (bootdevlun >> 4) & 0xf;
    205 		/* int lun  =  bootdevlun       & 0xf; */
    206 
    207 		if (periph->periph_target != targ)
    208 			return;
    209 
    210 		/* XXX Check LUN? */
    211 
    212 		booted_device = dev;
    213 	}
    214 }
    215