Home | History | Annotate | Line # | Download | only in tc
      1 /* $NetBSD: tc_bootdev.c,v 1.1 2025/03/09 01:06:42 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     31 
     32 __KERNEL_RCSID(0, "$NetBSD: tc_bootdev.c,v 1.1 2025/03/09 01:06:42 thorpej Exp $");
     33 
     34 #include <sys/systm.h>
     35 #include <sys/device.h>
     36 
     37 #include <machine/alpha.h>
     38 #include <machine/autoconf.h>
     39 #include <machine/rpb.h>
     40 
     41 #include <dev/scsipi/scsiconf.h>
     42 
     43 #include <dev/tc/tcvar.h>
     44 #include <dev/tc/tcdsvar.h>
     45 
     46 #define	DPRINTF(x)	if (bootdev_debug) printf x
     47 
     48 static inline int
     49 tc_ioasic_slot(void)
     50 {
     51 	/* 5 on 3000/300, 7 on everything else. */
     52 	return cputype == ST_DEC_3000_300 ? 5 : 7;
     53 }
     54 
     55 void
     56 tc_find_bootdev(device_t dev, void *aux)
     57 {
     58 	static device_t scsidev, tcdsdev;
     59 	struct bootdev_data *b = bootdev_data;
     60 	device_t parent = device_parent(dev);
     61 
     62 	if (booted_device != NULL || b == NULL) {
     63 		return;
     64 	}
     65 
     66 	/*
     67 	 * For SCSI boot, we look for "tcds", make sure it has the
     68 	 * right slot number, then find the "asc" on this tcds that
     69 	 * has the right channel.  Then we find the actual SCSI
     70 	 * device we came from.  NOTE: No SCSI LUN support (yet).
     71 	 */
     72 	if (bootdev_is_disk) {
     73 		if (tcdsdev == NULL) {
     74 			if (device_is_a(dev, "tcds")) {
     75 				struct tc_attach_args *tcargs = aux;
     76 
     77 				if (b->slot == tcargs->ta_slot) {
     78 					tcdsdev = dev;
     79 					DPRINTF(("\ntcdsdev = %s\n",
     80 					    device_xname(dev)));
     81 				}
     82 			}
     83 			return;
     84 		}
     85 		if (scsidev == NULL) {
     86 			if (device_is_a(dev, "asc")) {
     87 				struct tcdsdev_attach_args *ta = aux;
     88 
     89 				if (parent == tcdsdev &&
     90 				    b->channel == ta->tcdsda_chip) {
     91 					scsidev = dev;
     92 					DPRINTF(("\nscsidev = %s\n",
     93 					    device_xname(dev)));
     94 				}
     95 			}
     96 			return;
     97 		}
     98 		if (device_is_a(dev, "sd") ||
     99 		    device_is_a(dev, "st") ||
    100 		    device_is_a(dev, "cd")) {
    101 			struct scsipibus_attach_args *sa = aux;
    102 
    103 			if (device_parent(parent) != scsidev ||
    104 			    b->unit / 100 != sa->sa_periph->periph_target) {
    105 				return;
    106 			}
    107 
    108 			/* XXX LUN */
    109 
    110 			switch (b->boot_dev_type) {
    111 			case 0:
    112 				if (!device_is_a(dev, "sd") &&
    113 				    !device_is_a(dev, "cd")) {
    114 					return;
    115 				}
    116 				break;
    117 
    118 			case 1:
    119 				if (!device_is_a(dev, "st")) {
    120 					return;
    121 				}
    122 				break;
    123 
    124 			default:
    125 				return;
    126 			}
    127 			goto foundit;
    128 		}
    129 	}
    130 
    131 	if (bootdev_is_net) {
    132 		if (device_is_a(dev, "le") &&
    133 		    device_is_a(parent, "ioasic") &&
    134 		    b->slot == tc_ioasic_slot()) {
    135 			/*
    136 			 * No need to check ioasic_attach_args, since only
    137 			 * one le on ioasic.
    138 			 */
    139 			goto foundit;
    140 		}
    141 
    142 		/*
    143 		 * XXX GENERIC SUPPORT FOR TC NETWORK BOARDS
    144 		 */
    145 	}
    146 
    147 	return;
    148 
    149  foundit:
    150 	booted_device = dev;
    151 	DPRINTF(("\nbooted_device = %s\n", device_xname(dev)));
    152 }
    153