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