#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.15 2014/01/11 08:07:16 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/conf.h>
#include <sys/reboot.h>
#include <sys/device.h>
#include <machine/autoconf.h>
#include <machine/bootinfo.h>
#include <machine/disklabel.h>
#include <machine/cpu.h>
#include <dev/scsipi/scsi_all.h>
#include <dev/scsipi/scsipi_all.h>
#include <dev/scsipi/scsiconf.h>
#include <luna68k/luna68k/isr.h>
static uint booted_adpt, booted_ctlr, booted_unit, booted_part;
void
cpu_configure(void)
{
booted_device = NULL;
booted_adpt = B_ADAPTOR(bootdev);
booted_ctlr = B_CONTROLLER(bootdev);
booted_unit = B_UNIT(bootdev);
booted_part = B_PARTITION(bootdev);
(void)splhigh();
isrinit();
if (config_rootfound("mainbus", NULL) == NULL)
panic("autoconfig failed, no root");
spl0();
}
void
device_register(device_t dev, void *aux)
{
static device_t booted_controller;
static bool bootdev_found;
if (bootdev_found)
return;
if (booted_adpt == LUNA68K_BOOTADPT_LANCE &&
device_is_a(dev, "le")) {
struct mainbus_attach_args *ma = aux;
if (booted_ctlr == 0 &&
ma->ma_addr == LUNA68K_BOOTADPT_LANCE0_PA) {
booted_device = dev;
bootdev_found = true;
}
return;
}
if (booted_adpt == LUNA68K_BOOTADPT_SPC &&
device_is_a(dev, "spc")) {
struct mainbus_attach_args *ma = aux;
if ((booted_ctlr == 0 &&
(u_int)ma->ma_addr == LUNA68K_BOOTADPT_SPC0_PA) ||
(booted_ctlr == 1 &&
(u_int)ma->ma_addr == LUNA68K_BOOTADPT_SPC1_PA)) {
booted_controller = dev;
}
return;
}
if (booted_controller != NULL &&
(device_is_a(dev, "sd") || device_is_a(dev, "cd"))) {
struct scsipibus_attach_args *sa = aux;
device_t parent = device_parent(dev);
if (device_parent(parent) != booted_controller)
return;
if (booted_unit != sa->sa_periph->periph_target)
return;
booted_device = dev;
booted_partition = booted_part;
bootdev_found = true;
return;
}
}
void
cpu_rootconf(void)
{
printf("boot device: %s\n",
(booted_device) ? device_xname(booted_device) : "<unknown>");
rootconf();
}