#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.27 2025/10/03 01:04:19 thorpej Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <dev/pci/pcivar.h>
#include <dev/ofw/openfirm.h>
#include <machine/autoconf.h>
#include <powerpc/pic/picvar.h>
int mainbus_match(device_t, cfdata_t, void *);
void mainbus_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(mainbus, 0,
mainbus_match, mainbus_attach, NULL, NULL);
int
mainbus_match(device_t parent, cfdata_t cf, void *aux)
{
return 1;
}
void
mainbus_attach(device_t parent, device_t self, void *aux)
{
struct ofbus_attach_args oba;
struct confargs ca;
int node, cpus, i;
u_int32_t reg[4];
char name[32];
node = OF_finddevice("/");
if (node) {
if (OF_getprop(node, "model", name, sizeof(name)) > 0) {
aprint_normal(": %s\n", name);
} else {
node = 0;
}
}
if (node == 0) {
aprint_normal("\n");
}
aprint_naive("\n");
devhandle_t selfh = device_handle(self);
cpus = OF_finddevice("/cpus");
if ((cpus != -1) && (cpus != 0)) {
node = OF_child(cpus);
while (node != 0) {
ca.ca_name = "cpu";
ca.ca_reg = reg;
ca.ca_nreg = OF_getprop(node, "reg", reg, sizeof(reg));
config_found(self, &ca, NULL,
CFARGS(.devhandle = devhandle_from_of(selfh,
node)));
node = OF_peer(node);
}
} else {
for (i = 0; i < 2; i++) {
ca.ca_name = "cpu";
ca.ca_reg = reg;
reg[0] = i;
config_found(self, &ca, NULL, CFARGS_NONE);
}
}
pic_finish_setup();
node = OF_peer(0);
if (node) {
oba.oba_busname = "ofw";
oba.oba_phandle = node;
config_found(self, &oba, NULL,
CFARGS(.devhandle = devhandle_from_of(selfh, node)));
}
for (node = OF_child(OF_finddevice("/")); node; node = OF_peer(node)) {
memset(name, 0, sizeof(name));
if (OF_getprop(node, "name", name, sizeof(name)) == -1)
continue;
ca.ca_name = name;
ca.ca_node = node;
ca.ca_nreg = OF_getprop(node, "reg", reg, sizeof(reg));
ca.ca_reg = reg;
config_found(self, &ca, NULL,
CFARGS(.devhandle = devhandle_from_of(selfh, node)));
}
#ifdef MAMBO
ca.ca_name="com";
config_found(self, &ca, NULL, CFARGS_NONE);
#endif
}