Annotation of sys/arch/mac68k/mac68k/autoconf.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: autoconf.c,v 1.30 2007/06/01 19:25:10 deraadt Exp $ */
! 2: /* $NetBSD: autoconf.c,v 1.38 1996/12/18 05:46:09 scottr Exp $ */
! 3:
! 4: /*
! 5: * Copyright (c) 1992, 1993
! 6: * The Regents of the University of California. All rights reserved.
! 7: *
! 8: * This software was developed by the Computer Systems Engineering group
! 9: * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
! 10: * contributed to Berkeley.
! 11: *
! 12: * All advertising materials mentioning features or use of this software
! 13: * must display the following acknowledgement:
! 14: * This product includes software developed by the University of
! 15: * California, Lawrence Berkeley Laboratory.
! 16: *
! 17: * Redistribution and use in source and binary forms, with or without
! 18: * modification, are permitted provided that the following conditions
! 19: * are met:
! 20: * 1. Redistributions of source code must retain the above copyright
! 21: * notice, this list of conditions and the following disclaimer.
! 22: * 2. Redistributions in binary form must reproduce the above copyright
! 23: * notice, this list of conditions and the following disclaimer in the
! 24: * documentation and/or other materials provided with the distribution.
! 25: * 3. Neither the name of the University nor the names of its contributors
! 26: * may be used to endorse or promote products derived from this software
! 27: * without specific prior written permission.
! 28: *
! 29: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 30: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 31: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 32: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 33: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 34: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 35: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 36: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 37: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 38: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 39: * SUCH DAMAGE.
! 40: *
! 41: * @(#)autoconf.c 8.4 (Berkeley) 10/1/93
! 42: */
! 43:
! 44: /*
! 45: * Setup the system to run on the current machine.
! 46: *
! 47: * cpu_configure() is called at boot time. Available
! 48: * devices are determined (from possibilities mentioned in ioconf.c),
! 49: * and the drivers are initialized.
! 50: */
! 51:
! 52: #include <sys/param.h>
! 53: #include <sys/systm.h>
! 54: #include <sys/buf.h>
! 55: #include <sys/disklabel.h>
! 56: #include <sys/conf.h>
! 57: #include <sys/reboot.h>
! 58: #include <sys/device.h>
! 59: #include <sys/disk.h>
! 60:
! 61: #include <dev/cons.h>
! 62:
! 63: #include <machine/autoconf.h>
! 64: #include <machine/viareg.h>
! 65:
! 66: #include <scsi/scsi_all.h>
! 67: #include <scsi/scsiconf.h>
! 68:
! 69: int target_to_unit(u_long, u_long, u_long);
! 70: void findbootdev(void);
! 71:
! 72: struct device *booted_device;
! 73: int booted_partition;
! 74: dev_t bootdev;
! 75:
! 76: /*
! 77: * Yanked from i386/i386/autoconf.c (and tweaked a bit)
! 78: */
! 79: void
! 80: findbootdev()
! 81: {
! 82: struct device *dv;
! 83: int major, unit;
! 84:
! 85: booted_device = NULL;
! 86: booted_partition = 0; /* Assume root is on partition a */
! 87:
! 88: major = B_TYPE(bootdev);
! 89: if (major < 0 || major >= nblkdev)
! 90: return;
! 91:
! 92: unit = B_UNIT(bootdev);
! 93:
! 94: bootdev &= ~(B_UNITMASK << B_UNITSHIFT);
! 95: unit = target_to_unit(-1, unit, 0);
! 96: bootdev |= (unit << B_UNITSHIFT);
! 97:
! 98: if (disk_count <= 0)
! 99: return;
! 100:
! 101: TAILQ_FOREACH(dv, &alldevs, dv_list) {
! 102: if (dv->dv_class == DV_DISK && major == findblkmajor(dv) &&
! 103: unit == dv->dv_unit) {
! 104: booted_device = dv;
! 105: return;
! 106: }
! 107: }
! 108: }
! 109:
! 110: void
! 111: cpu_configure()
! 112: {
! 113: startrtclock();
! 114:
! 115: if (config_rootfound("mainbus", "mainbus") == NULL)
! 116: panic("No mainbus found!");
! 117: spl0();
! 118:
! 119: findbootdev();
! 120: cold = 0;
! 121: }
! 122:
! 123: void
! 124: device_register(struct device *dev, void *aux)
! 125: {
! 126: }
! 127:
! 128: void
! 129: diskconf(void)
! 130: {
! 131: setroot(booted_device, booted_partition, RB_USERREQ);
! 132: dumpconf();
! 133: }
! 134:
! 135: /*
! 136: * Map a SCSI bus, target, lun to a device number.
! 137: * This could be tape, disk, CD. The calling routine, though,
! 138: * assumes DISK. It would be nice to allow CD, too...
! 139: */
! 140: int
! 141: target_to_unit(bus, target, lun)
! 142: u_long bus, target, lun;
! 143: {
! 144: struct scsibus_softc *scsi;
! 145: struct scsi_link *sc_link;
! 146: struct device *sc_dev;
! 147: extern struct cfdriver scsibus_cd;
! 148:
! 149: if (target < 0 || target > 7 || lun < 0 || lun > 7) {
! 150: printf("scsi target to unit, target (%ld) or lun (%ld)"
! 151: " out of range.\n", target, lun);
! 152: return -1;
! 153: }
! 154:
! 155: if (bus == -1) {
! 156: for (bus = 0 ; bus < scsibus_cd.cd_ndevs ; bus++) {
! 157: if (scsibus_cd.cd_devs[bus]) {
! 158: scsi = (struct scsibus_softc *)
! 159: scsibus_cd.cd_devs[bus];
! 160: if (scsi->sc_link[target][lun]) {
! 161: sc_link = scsi->sc_link[target][lun];
! 162: sc_dev = (struct device *)
! 163: sc_link->device_softc;
! 164: return sc_dev->dv_unit;
! 165: }
! 166: }
! 167: }
! 168: return -1;
! 169: }
! 170: if (bus < 0 || bus >= scsibus_cd.cd_ndevs) {
! 171: printf("scsi target to unit, bus (%ld) out of range.\n", bus);
! 172: return -1;
! 173: }
! 174: if (scsibus_cd.cd_devs[bus]) {
! 175: scsi = (struct scsibus_softc *) scsibus_cd.cd_devs[bus];
! 176: if (scsi->sc_link[target][lun]) {
! 177: sc_link = scsi->sc_link[target][lun];
! 178: sc_dev = (struct device *) sc_link->device_softc;
! 179: return sc_dev->dv_unit;
! 180: }
! 181: }
! 182: return -1;
! 183: }
! 184:
! 185: struct nam2blk nam2blk[] = {
! 186: { "sd", 4 },
! 187: { "cd", 6 },
! 188: { "rd", 13 },
! 189: { NULL, -1 }
! 190: };
CVSweb