#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.69 2024/01/07 07:58:35 isaki Exp $");
#include "opt_compat_netbsd.h"
#include "scsibus.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/reboot.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/disk.h>
#include <sys/disklabel.h>
#include <machine/cpu.h>
#include <machine/bootinfo.h>
#include <machine/autoconf.h>
#include <dev/scsipi/scsi_all.h>
#include <dev/scsipi/scsipi_all.h>
#include <dev/scsipi/scsiconf.h>
static void findroot(void);
static device_t scsi_find(dev_t);
int x68k_realconfig;
void
cpu_configure(void)
{
x68k_realconfig = 1;
if (config_rootfound("mainbus", NULL) == NULL)
panic("no mainbus found");
printf("enabling interrupts\n");
(void) spl0();
}
void
cpu_rootconf(void)
{
findroot();
printf("boot device: %s\n",
booted_device ? device_xname(booted_device) : "<unknown>");
rootconf();
}
void
config_console(void)
{
mfp_config_console();
grf_config_console();
ite_config_console();
}
uint32_t bootdev = 0;
static void
findroot(void)
{
int majdev, unit, part;
const char *name;
if (booted_device)
return;
if (boothowto & RB_ASKNAME)
return;
if ((bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
return;
majdev = B_TYPE(bootdev);
if (X68K_BOOT_DEV_IS_SCSI(majdev)) {
if ((booted_device = scsi_find(bootdev)) != NULL)
booted_partition = B_X68K_SCSI_PART(bootdev);
return;
}
name = devsw_blk2name(majdev);
if (name == NULL)
return;
part = B_PARTITION(bootdev);
unit = B_UNIT(bootdev);
if ((booted_device = device_find_by_driver_unit(name, unit)) != NULL)
booted_partition = part;
}
static const char *const name_netif[] = { X68K_BOOT_NETIF_STRINGS };
void
device_register(device_t dev, void *aux)
{
int majdev;
char tname[16];
if (device_class(dev) == DV_IFNET) {
majdev = B_TYPE(bootdev);
if (X68K_BOOT_DEV_IS_NETIF(majdev)) {
snprintf(tname, sizeof(tname), "%s%d",
name_netif[255 - majdev], B_UNIT(bootdev));
if (!strcmp(tname, device_xname(dev)))
goto found;
}
}
return;
found:
if (booted_device) {
printf("warning: double match for boot device (%s, %s)\n",
device_xname(booted_device), device_xname(dev));
return;
}
booted_device = dev;
}
static const char *const name_scsiif[] = { X68K_BOOT_SCSIIF_STRINGS };
static device_t
scsi_find(dev_t bdev)
{
#if defined(NSCSIBUS) && NSCSIBUS > 0
int ifid;
char tname[16];
device_t scsibus;
deviter_t di;
struct scsibus_softc *sbsc;
struct scsipi_periph *periph;
ifid = B_X68K_SCSI_IF(bdev);
if (ifid >= sizeof name_scsiif/sizeof name_scsiif[0] ||
!name_scsiif[ifid]) {
#ifdef COMPAT_13
printf("warning: scsi_find: can't get boot interface -- "
"update boot loader\n");
scsibus = device_find_by_xname("scsibus0");
#else
return NULL;
#endif
} else {
snprintf(tname, sizeof(tname), "%s%" PRIu64,
name_scsiif[ifid], B_X68K_SCSI_IF_UN(bdev));
for (scsibus = deviter_first(&di, DEVITER_F_ROOT_FIRST);
scsibus != NULL;
scsibus = deviter_next(&di)) {
if (device_parent(scsibus)
&& strcmp(tname, device_xname(device_parent(scsibus))) == 0)
break;
}
deviter_release(&di);
}
if (scsibus == NULL)
return NULL;
sbsc = device_private(scsibus);
periph = scsipi_lookup_periph(sbsc->sc_channel,
B_X68K_SCSI_ID(bdev), B_X68K_SCSI_LUN(bdev));
return periph ? periph->periph_dev : NULL;
#else
return NULL;
#endif
}