#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.74 2023/01/06 10:28:27 tsutsui Exp $");
#include "opt_md.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/reboot.h>
#include <sys/conf.h>
#include <sys/buf.h>
#include <sys/device.h>
#include <sys/device_impl.h>
#include <sys/disklabel.h>
#include <sys/disk.h>
#include <sys/kmem.h>
#include <machine/disklabel.h>
#include <machine/cpu.h>
#include <atari/atari/device.h>
#if defined(MEMORY_DISK_HOOKS)
#include <dev/md.h>
#endif
#include "ioconf.h"
static void findroot(void);
static int mbmatch(device_t, cfdata_t, void *);
static void mbattach(device_t, device_t, void *);
#if 0
static int mbprint(void *, const char *);
#endif
int atari_realconfig;
#include <sys/kernel.h>
void
cpu_configure(void)
{
atari_realconfig = 1;
(void)splhigh();
init_sicallback();
if (config_rootfound("mainbus", __UNCONST("mainbus")) == NULL)
panic("no mainbus found");
(void)spl0();
}
void
cpu_rootconf(void)
{
findroot();
#if defined(MEMORY_DISK_HOOKS)
#define RAMD_NDEV 3
if ((boothowto & RB_ASKNAME) != 0) {
int md_major, i;
cfdata_t cf;
struct md_softc *sc;
md_major = devsw_name2blk("md", NULL, 0);
if (md_major >= 0) {
for (i = 0; i < RAMD_NDEV; i++) {
cf = kmem_zalloc(sizeof(*cf), KM_SLEEP);
if (cf == NULL)
break;
cf->cf_name = md_cd.cd_name;
cf->cf_atname = md_cd.cd_name;
cf->cf_unit = i;
cf->cf_fstate = FSTATE_STAR;
sc = device_private(config_attach_pseudo(cf));
if (sc == NULL)
break;
}
}
}
#endif
rootconf();
}
int
simple_devprint(void *aux, const char *pnp)
{
return QUIET;
}
int
atari_config_found(cfdata_t pcfp, device_t parent, void *aux, cfprint_t pfn,
const struct cfargs *cfargs)
{
struct device temp;
cfdata_t cf;
const struct cfattach *ca;
int rv = 0;
if (atari_realconfig) {
rv = config_found(parent, aux, pfn, cfargs) != NULL;
goto out;
}
memset(&temp, 0, sizeof(temp));
if (parent == NULL)
parent = &temp;
parent->dv_cfdata = pcfp;
parent->dv_cfdriver = config_cfdriver_lookup(pcfp->cf_name);
parent->dv_unit = pcfp->cf_unit;
if ((cf = config_search(parent, aux, cfargs)) != NULL) {
ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname);
if (ca != NULL) {
(*ca->ca_attach)(parent, NULL, aux);
rv = 1;
goto out;
}
}
parent->dv_cfdata = NULL;
out:
return rv;
}
void
config_console(void)
{
cfdata_t cf;
config_init();
cf = config_rootsearch(NULL, "mainbus", __UNCONST("mainbus"));
if (cf == NULL)
panic("no mainbus");
atari_config_found(cf, NULL, __UNCONST("pcib") , NULL, CFARGS_NONE);
atari_config_found(cf, NULL, __UNCONST("isab") , NULL, CFARGS_NONE);
atari_config_found(cf, NULL, __UNCONST("grfbus"), NULL, CFARGS_NONE);
}
#include <sys/fcntl.h>
#include <sys/proc.h>
#include "fd.h"
#include "sd.h"
#include "cd.h"
#include "wd.h"
#include "ioconf.h"
struct cfdriver *genericconf[] = {
#if NWD > 0
&wd_cd,
#endif
#if NSD > 0
&sd_cd,
#endif
#if NCD > 0
&cd_cd,
#endif
#if NFD > 0
&fd_cd,
#endif
NULL,
};
void
findroot(void)
{
struct disk *dkp;
struct partition *pp;
device_t *devs;
const struct bdevsw *bdev;
int i, maj, unit;
if (boothowto & RB_ASKNAME)
return;
for (i = 0; genericconf[i] != NULL; i++) {
for (unit = 0; unit < genericconf[i]->cd_ndevs; unit++) {
if (genericconf[i]->cd_devs[unit] == NULL)
continue;
devs = genericconf[i]->cd_devs;
if ((dkp = disk_find(device_xname(devs[unit]))) == NULL)
continue;
if (dkp->dk_driver == NULL ||
dkp->dk_driver->d_strategy == NULL)
continue;
maj = devsw_name2blk(genericconf[i]->cd_name, NULL, 0);
if (maj == -1)
continue;
bdev = bdevsw_lookup(makedev(maj, 0));
#ifdef DIAGNOSTIC
if (bdev == NULL)
panic("findroot: impossible");
#endif
if (bdev == NULL ||
bdev->d_strategy != dkp->dk_driver->d_strategy)
continue;
if ((*bdev->d_open)(MAKEDISKDEV(maj,
unit, 0), FREAD|FNONBLOCK, 0, &lwp0))
continue;
(void)(*bdev->d_close)(MAKEDISKDEV(maj,
unit, 0), FREAD|FNONBLOCK, 0, &lwp0);
pp = &dkp->dk_label->d_partitions[booted_partition];
if (pp->p_size != 0 && pp->p_fstype == FS_BSDFFS) {
booted_device = devs[unit];
return;
}
}
}
}
CFATTACH_DECL_NEW(mainbus, 0,
mbmatch, mbattach, NULL, NULL);
static int mb_attached;
static int
mbmatch(device_t parent, cfdata_t cf, void *aux)
{
if (mb_attached)
return 0;
return 1;
}
static void
mbattach(device_t parent, device_t self, void *aux)
{
mb_attached = 1;
aprint_normal("\n");
config_found(self, __UNCONST("clock") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("grfbus") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("kbd") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("fdc") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("ser") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("zs") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("ncrscsi") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("nvr") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("lpt") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("wdc") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("ne") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("isab") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("pcib") , simple_devprint, CFARGS_NONE);
config_found(self, __UNCONST("avmebus") , simple_devprint, CFARGS_NONE);
}
#if 0
static int
mbprint(void *aux, const char *pnp)
{
if (pnp)
aprint_normal("%s at %s", (char *)aux, pnp);
return UNCONF;
}
#endif