#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.22 2021/08/07 16:19:00 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kmem.h>
#include <machine/autoconf.h>
#include <sys/bus.h>
#include "pci.h"
#include "opt_pci.h"
#include <dev/pci/pcivar.h>
#include <dev/pci/pciconf.h>
#include <machine/pci_machdep.h>
#include <machine/isa_machdep.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_print(void *, const char *);
static int mainbus_found;
struct powerpc_isa_chipset genppc_ict;
struct genppc_pci_chipset *genppc_pct;
#define PCI_IO_START 0x00008000
#define PCI_IO_END 0x0000ffff
#define PCI_IO_SIZE ((PCI_IO_END - PCI_IO_START) + 1)
#define PCI_MEM_START 0x00000000
#define PCI_MEM_END 0x0fffffff
#define PCI_MEM_SIZE ((PCI_MEM_END - PCI_MEM_START) + 1)
int
mainbus_match(device_t parent, cfdata_t match, void *aux)
{
if (mainbus_found)
return 0;
return 1;
}
void
mainbus_attach(device_t parent, device_t self, void *aux)
{
struct pcibus_attach_args pba;
#if NPCI > 0
struct genppc_pci_chipset_businfo *pbi;
#endif
mainbus_found = 1;
aprint_normal("\n");
config_found(self, NULL, mainbus_print,
CFARGS(.iattr = "mainbus"));
#if NPCI > 0
genppc_pct = kmem_alloc(sizeof(struct genppc_pci_chipset), KM_SLEEP);
mvmeppc_pci_get_chipset_tag(genppc_pct);
pbi = kmem_alloc(sizeof(struct genppc_pci_chipset_businfo), KM_SLEEP);
pbi->pbi_properties = prop_dictionary_create();
KASSERT(pbi->pbi_properties != NULL);
SIMPLEQ_INIT(&genppc_pct->pc_pbi);
SIMPLEQ_INSERT_TAIL(&genppc_pct->pc_pbi, pbi, next);
#ifdef PCI_NETBSD_CONFIGURE
struct pciconf_resources *pcires = pciconf_resource_init();
pciconf_resource_add(pcires, PCICONF_RESOURCE_IO,
PCI_IO_START, PCI_IO_SIZE);
pciconf_resource_add(pcires, PCICONF_RESOURCE_MEM,
PCI_MEM_START, PCI_MEM_SIZE);
pci_configure_bus(genppc_pct, pcires, 0, CACHELINESIZE);
pciconf_resource_fini(pcires);
#endif
pba.pba_iot = &prep_io_space_tag;
pba.pba_memt = &prep_mem_space_tag;
pba.pba_dmat = &pci_bus_dma_tag;
pba.pba_dmat64 = NULL;
pba.pba_pc = genppc_pct;
pba.pba_bus = 0;
pba.pba_bridgetag = NULL;
pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
config_found(self, &pba, pcibusprint,
CFARGS(.iattr = "pcibus"));
#endif
}
int
mainbus_print(void *aux, const char *pnp)
{
if (pnp)
aprint_normal("cpu at %s", pnp);
return (UNCONF);
}