#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.28 2025/10/13 15:40:14 thorpej Exp $");
#include "opt_md.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/disklabel.h>
#include <sys/device.h>
#include <sys/bus.h>
#include <sh3/exception.h>
#include <machine/intr.h>
#include <machine/config_hook.h>
#include <machine/autoconf.h>
#include <machine/platid.h>
#include <machine/platid_mask.h>
#include <hpcsh/dev/hd64461/hd64461var.h>
#include <hpcsh/dev/hd64465/hd64465var.h>
static char booted_device_name[16];
#ifndef MEMORY_DISK_IS_ROOT
static void get_device(char *name);
#endif
void
cpu_configure(void)
{
config_hook_init();
hd6446x_intr_init();
#ifdef SH3
if (CPU_IS_SH3)
intc_intr_establish(SH7709_INTEVT2_IRQ4, IST_LEVEL, IPL_TTY,
(void *)1, 0);
#endif
#ifdef SH4
if (CPU_IS_SH4)
intc_intr_establish(SH_INTEVT_IRL11, IST_LEVEL, IPL_TTY,
(void *)1, 0);
#endif
splhigh();
if (config_rootfound("mainbus", NULL) == NULL)
panic("no mainbus found");
spl0();
}
void
cpu_rootconf(void)
{
#ifndef MEMORY_DISK_IS_ROOT
get_device(booted_device_name);
printf("boot device: %s\n",
booted_device ? device_xname(booted_device) : "<unknown>");
#endif
rootconf();
}
void
makebootdev(const char *cp)
{
strncpy(booted_device_name, cp, 16);
}
#define HPW50PAD_RTC_BASE 1996
void
device_register(device_t dev, void *aux)
{
device_t parent;
parent = device_parent(dev);
if (device_is_a(dev, "rtc") &&
parent != NULL && device_is_a(parent, "shb") &&
platid_match(&platid, &platid_mask_MACH_HITACHI_PERSONA_HPW50PAD)) {
if (! device_setprop_uint(dev, "start-year",
HPW50PAD_RTC_BASE)) {
printf("WARNING: unable to set start-year "
"property for %s\n", device_xname(dev));
}
return;
}
}
#ifndef MEMORY_DISK_IS_ROOT
static void
get_device(char *name)
{
int unit, part;
char devname[16], *cp;
device_t dv;
if (strncmp(name, "/dev/", 5) == 0)
name += 5;
if (devsw_name2blk(name, devname, sizeof(devname)) == -1)
return;
name += strlen(devname);
unit = part = 0;
cp = name;
while (*cp >= '0' && *cp <= '9')
unit = (unit * 10) + (*cp++ - '0');
if (cp == name)
return;
if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS))
part = *cp - 'a';
else if (*cp != '\0' && *cp != ' ')
return;
if ((dv = device_find_by_driver_unit(devname, unit)) != NULL) {
booted_device = dv;
booted_partition = part;
}
}
#endif