#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: imc.c,v 1.38 2025/10/19 20:35:02 thorpej Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <machine/cpu.h>
#include <machine/locore.h>
#include <machine/autoconf.h>
#include <sys/bus.h>
#include <machine/machtype.h>
#include <machine/sysconf.h>
#include <sgimips/dev/imcreg.h>
#include <sgimips/dev/imcvar.h>
#include <sgimips/gio/giovar.h>
#include "locators.h"
struct imc_softc {
bus_space_tag_t iot;
bus_space_handle_t ioh;
int eisa_present;
};
static int imc_match(device_t, cfdata_t, void *);
static void imc_attach(device_t, device_t, void *);
static int imc_print(void *, const char *);
static void imc_bus_reset(void);
static void imc_bus_error(vaddr_t, uint32_t, uint32_t);
static void imc_watchdog_reset(void);
static void imc_watchdog_disable(void);
static void imc_watchdog_enable(void);
CFATTACH_DECL_NEW(imc, sizeof(struct imc_softc),
imc_match, imc_attach, NULL, NULL);
struct imc_attach_args {
const char* iaa_name;
bus_space_tag_t iaa_st;
bus_space_handle_t iaa_sh;
long iaa_offset;
int iaa_intr;
#if 0
int iaa_stride;
#endif
};
int imc_gio64_arb_config(int, uint32_t);
struct imc_softc isc;
static int
imc_match(device_t parent, cfdata_t match, void *aux)
{
if ((mach_type == MACH_SGI_IP22) || (mach_type == MACH_SGI_IP20))
return 1;
return 0;
}
static void
imc_attach(device_t parent, device_t self, void *aux)
{
uint32_t reg;
struct imc_attach_args iaa;
struct mainbus_attach_args *ma = aux;
uint32_t sysid;
isc.iot = normal_memt;
if (bus_space_map(isc.iot, ma->ma_addr, 0x100,
BUS_SPACE_MAP_LINEAR, &isc.ioh))
panic("imc_attach: could not map registers\n");
platform.bus_reset = imc_bus_reset;
platform.watchdog_reset = imc_watchdog_reset;
platform.watchdog_disable = imc_watchdog_disable;
platform.watchdog_enable = imc_watchdog_enable;
sysid = bus_space_read_4(isc.iot, isc.ioh, IMC_SYSID);
if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
isc.eisa_present = (sysid & IMC_SYSID_HAVEISA);
else
isc.eisa_present = 0;
printf(": revision %d", (sysid & IMC_SYSID_REVMASK));
if (isc.eisa_present)
printf(", EISA bus present");
printf("\n");
imc_bus_reset();
platform.intr4 = imc_bus_error;
reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
reg &= ~IMC_CPUCTRL0_NCHKMEMPAR;
reg |= (IMC_CPUCTRL0_GPR | IMC_CPUCTRL0_MPR | IMC_CPUCTRL0_INTENA);
bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL1);
reg = (reg & ~IMC_CPUCTRL1_MCHWMSK) | 13;
if (mach_type == MACH_SGI_IP20 || (mach_type == MACH_SGI_IP22 &&
mach_subtype == MACH_SGI_IP22_GUINNESS)) {
reg |= IMC_CPUCTRL1_HPCFX;
reg |= IMC_CPUCTRL1_EXP0FX;
reg |= IMC_CPUCTRL1_EXP1FX;
reg &= ~IMC_CPUCTRL1_HPCLITTLE;
reg &= ~IMC_CPUCTRL1_EXP0LITTLE;
reg &= ~IMC_CPUCTRL1_EXP1LITTLE;
}
bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL1, reg);
reg = bus_space_read_4(isc.iot, isc.ioh, IMC_GIO64ARB);
reg &= (IMC_GIO64ARB_GRX64 | IMC_GIO64ARB_GRXRT | IMC_GIO64ARB_GRXMST);
if (mach_type == MACH_SGI_IP20) {
reg |= IMC_GIO64ARB_ONEGIO;
reg |= (IMC_GIO64ARB_EXP0RT | IMC_GIO64ARB_EXP1RT);
reg |= (IMC_GIO64ARB_EXP0MST | IMC_GIO64ARB_EXP1MST);
reg &= ~(IMC_GIO64ARB_HPC64 |
IMC_GIO64ARB_HPCEXP64 | IMC_GIO64ARB_EISA64 |
IMC_GIO64ARB_EXP064 | IMC_GIO64ARB_EXP164 |
IMC_GIO64ARB_EXP0PIPE | IMC_GIO64ARB_EXP1PIPE);
} else {
reg |= IMC_GIO64ARB_ONEGIO | IMC_GIO64ARB_HPC64;
switch (mach_subtype) {
case MACH_SGI_IP22_GUINNESS:
reg |= (IMC_GIO64ARB_EXP0RT | IMC_GIO64ARB_EXP1RT);
reg |= (IMC_GIO64ARB_EXP0MST | IMC_GIO64ARB_EXP1MST);
reg |= (IMC_GIO64ARB_EISAMST | IMC_GIO64ARB_EISA64);
break;
case MACH_SGI_IP22_FULLHOUSE:
reg |= (IMC_GIO64ARB_HPCEXP64 | IMC_GIO64ARB_EXP0PIPE);
if (mach_boardrev < 2) {
reg |= (IMC_GIO64ARB_EXP0RT |
IMC_GIO64ARB_EXP1MST);
} else {
reg |= (IMC_GIO64ARB_EXP1PIPE |
IMC_GIO64ARB_EISAMST);
}
break;
}
}
bus_space_write_4(isc.iot, isc.ioh, IMC_GIO64ARB, reg);
if (isc.eisa_present) {
#if notyet
memset(&iaa, 0, sizeof(iaa));
eisabus_attach(self, &iaa);
#endif
}
memset(&iaa, 0, sizeof(iaa));
config_found(self, &iaa, imc_print,
CFARGS(.iattr = "giobus"));
imc_watchdog_enable();
}
static int
imc_print(void *aux, const char *name)
{
if (name)
aprint_normal("gio at %s", name);
return UNCONF;
}
static void
imc_bus_reset(void)
{
bus_space_write_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT, 0);
bus_space_write_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT, 0);
}
static void
imc_bus_error(vaddr_t pc, uint32_t status, uint32_t ipending)
{
printf("bus error: cpu_stat %08x addr %08x, gio_stat %08x addr %08x\n",
bus_space_read_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT),
bus_space_read_4(isc.iot, isc.ioh, IMC_CPU_ERRADDR),
bus_space_read_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT),
bus_space_read_4(isc.iot, isc.ioh, IMC_GIO_ERRADDR) );
imc_bus_reset();
}
static void
imc_watchdog_reset(void)
{
bus_space_write_4(isc.iot, isc.ioh, IMC_WDOG, 0);
}
static void
imc_watchdog_disable(void)
{
uint32_t reg;
bus_space_write_4(isc.iot, isc.ioh, IMC_WDOG, 0);
reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
reg &= ~(IMC_CPUCTRL0_WDOG);
bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
}
static void
imc_watchdog_enable(void)
{
uint32_t reg;
reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
reg |= IMC_CPUCTRL0_WDOG;
bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
imc_watchdog_reset();
}
int
imc_gio64_arb_config(int slot, uint32_t flags)
{
uint32_t reg;
if (slot == GIO_SLOT_EXP1 && mach_subtype == MACH_SGI_IP22_FULLHOUSE)
return EINVAL;
if (slot == GIO_SLOT_GFX && mach_subtype != MACH_SGI_IP22_FULLHOUSE)
return EINVAL;
if (slot == GIO_SLOT_GFX && (flags & GIO_ARB_NOPIPE))
return EINVAL;
if (((flags & GIO_ARB_PIPE) || (flags & GIO_ARB_NOPIPE)) &&
mach_type == MACH_SGI_IP20)
return EINVAL;
reg = bus_space_read_4(isc.iot, isc.ioh, IMC_GIO64ARB);
if (flags & GIO_ARB_RT) {
if (slot == GIO_SLOT_EXP0)
reg |= IMC_GIO64ARB_EXP0RT;
else if (slot == GIO_SLOT_EXP1)
reg |= IMC_GIO64ARB_EXP1RT;
else if (slot == GIO_SLOT_GFX)
reg |= IMC_GIO64ARB_GRXRT;
}
if (flags & GIO_ARB_MST) {
if (slot == GIO_SLOT_EXP0)
reg |= IMC_GIO64ARB_EXP0MST;
else if (slot == GIO_SLOT_EXP1)
reg |= IMC_GIO64ARB_EXP1MST;
else if (slot == GIO_SLOT_GFX)
reg |= IMC_GIO64ARB_GRXMST;
}
if (flags & GIO_ARB_PIPE) {
if (slot == GIO_SLOT_EXP0)
reg |= IMC_GIO64ARB_EXP0PIPE;
else if (slot == GIO_SLOT_EXP1)
reg |= IMC_GIO64ARB_EXP1PIPE;
}
if (flags & GIO_ARB_LB) {
if (slot == GIO_SLOT_EXP0)
reg &= ~IMC_GIO64ARB_EXP0RT;
else if (slot == GIO_SLOT_EXP1)
reg &= ~IMC_GIO64ARB_EXP1RT;
else if (slot == GIO_SLOT_GFX)
reg &= ~IMC_GIO64ARB_GRXRT;
}
if (flags & GIO_ARB_SLV) {
if (slot == GIO_SLOT_EXP0)
reg &= ~IMC_GIO64ARB_EXP0MST;
else if (slot == GIO_SLOT_EXP1)
reg &= ~IMC_GIO64ARB_EXP1MST;
else if (slot == GIO_SLOT_GFX)
reg &= ~IMC_GIO64ARB_GRXMST;
}
if (flags & GIO_ARB_NOPIPE) {
if (slot == GIO_SLOT_EXP0)
reg &= ~IMC_GIO64ARB_EXP0PIPE;
else if (slot == GIO_SLOT_EXP1)
reg &= ~IMC_GIO64ARB_EXP1PIPE;
}
if (flags & GIO_ARB_32BIT) {
if (slot == GIO_SLOT_EXP0)
reg &= ~IMC_GIO64ARB_EXP064;
else if (slot == GIO_SLOT_EXP1)
reg &= ~IMC_GIO64ARB_EXP164;
}
if (flags & GIO_ARB_64BIT) {
if (slot == GIO_SLOT_EXP0)
reg |= IMC_GIO64ARB_EXP064;
else if (slot == GIO_SLOT_EXP1)
reg |= IMC_GIO64ARB_EXP164;
}
if (flags & GIO_ARB_HPC2_32BIT)
reg &= ~IMC_GIO64ARB_HPCEXP64;
if (flags & GIO_ARB_HPC2_64BIT)
reg |= IMC_GIO64ARB_HPCEXP64;
bus_space_write_4(isc.iot, isc.ioh, IMC_GIO64ARB, reg);
return 0;
}
void
imc_disable_sysad_parity(void)
{
uint32_t reg;
if (mach_type != MACH_SGI_IP20 && mach_type != MACH_SGI_IP22)
return;
reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
reg |= IMC_CPUCTRL0_NCHKMEMPAR;
bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
}
void
imc_enable_sysad_parity(void)
{
uint32_t reg;
if (mach_type != MACH_SGI_IP20 && mach_type != MACH_SGI_IP22)
return;
reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
reg &= ~IMC_CPUCTRL0_NCHKMEMPAR;
bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
}
int
imc_is_sysad_parity_enabled(void)
{
uint32_t reg;
if (mach_type != MACH_SGI_IP20 && mach_type != MACH_SGI_IP22)
return 0;
reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
return reg & IMC_CPUCTRL0_NCHKMEMPAR;
}