#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tc_bootdev.c,v 1.1 2025/03/09 01:06:42 thorpej Exp $");
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/alpha.h>
#include <machine/autoconf.h>
#include <machine/rpb.h>
#include <dev/scsipi/scsiconf.h>
#include <dev/tc/tcvar.h>
#include <dev/tc/tcdsvar.h>
#define DPRINTF(x) if (bootdev_debug) printf x
static inline int
tc_ioasic_slot(void)
{
return cputype == ST_DEC_3000_300 ? 5 : 7;
}
void
tc_find_bootdev(device_t dev, void *aux)
{
static device_t scsidev, tcdsdev;
struct bootdev_data *b = bootdev_data;
device_t parent = device_parent(dev);
if (booted_device != NULL || b == NULL) {
return;
}
if (bootdev_is_disk) {
if (tcdsdev == NULL) {
if (device_is_a(dev, "tcds")) {
struct tc_attach_args *tcargs = aux;
if (b->slot == tcargs->ta_slot) {
tcdsdev = dev;
DPRINTF(("\ntcdsdev = %s\n",
device_xname(dev)));
}
}
return;
}
if (scsidev == NULL) {
if (device_is_a(dev, "asc")) {
struct tcdsdev_attach_args *ta = aux;
if (parent == tcdsdev &&
b->channel == ta->tcdsda_chip) {
scsidev = dev;
DPRINTF(("\nscsidev = %s\n",
device_xname(dev)));
}
}
return;
}
if (device_is_a(dev, "sd") ||
device_is_a(dev, "st") ||
device_is_a(dev, "cd")) {
struct scsipibus_attach_args *sa = aux;
if (device_parent(parent) != scsidev ||
b->unit / 100 != sa->sa_periph->periph_target) {
return;
}
switch (b->boot_dev_type) {
case 0:
if (!device_is_a(dev, "sd") &&
!device_is_a(dev, "cd")) {
return;
}
break;
case 1:
if (!device_is_a(dev, "st")) {
return;
}
break;
default:
return;
}
goto foundit;
}
}
if (bootdev_is_net) {
if (device_is_a(dev, "le") &&
device_is_a(parent, "ioasic") &&
b->slot == tc_ioasic_slot()) {
goto foundit;
}
}
return;
foundit:
booted_device = dev;
DPRINTF(("\nbooted_device = %s\n", device_xname(dev)));
}