#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/iomod.h>
#include <machine/autoconf.h>
#include <dev/wscons/wsdisplayvar.h>
#include <dev/wscons/wsconsio.h>
#include <dev/ic/stireg.h>
#include <dev/ic/stivar.h>
#include <hppa/dev/cpudevs.h>
#define STI_ROMSIZE (sizeof(struct sti_dd) * 4)
#define STI_ID_FDDI 0x280b31af
const char sti_sgc_opt[] = { 0x17, 0x20, 0x30, 0x40, 0x70, 0xc0, 0xd0 };
extern struct cfdriver sti_cd;
int sti_sgc_probe(struct device *, void *, void *);
void sti_sgc_attach(struct device *, struct device *, void *);
paddr_t sti_sgc_getrom(int, struct confargs *);
const struct cfattach sti_gedoens_ca = {
sizeof(struct sti_softc), sti_sgc_probe, sti_sgc_attach
};
paddr_t
sti_sgc_getrom(int unit, struct confargs *ca)
{
paddr_t rom = PAGE0->pd_resv2[1];
int i;
if (unit) {
i = -1;
if (ca->ca_type.iodc_sv_model == HPPA_FIO_GSGC)
for (i = sizeof(sti_sgc_opt); i-- &&
sti_sgc_opt[i] != ca->ca_type.iodc_revision; )
;
if (i < 0)
rom = 0;
}
if (rom < HPPA_IOBEGIN) {
if (ca->ca_naddrs > 0)
rom = ca->ca_addrs[0].addr;
else
rom = ca->ca_hpa;
}
return (rom);
}
int
sti_sgc_probe(struct device *parent, void *match, void *aux)
{
struct cfdata *cf = match;
struct confargs *ca = aux;
bus_space_handle_t romh;
paddr_t rom;
u_int32_t id;
u_char devtype;
int rv = 0, romunmapped = 0;
if (cf->cf_unit > sti_cd.cd_ndevs)
return (0);
if (ca->ca_type.iodc_type != HPPA_TYPE_FIO)
return (0);
if (ca->ca_type.iodc_sv_model != HPPA_FIO_GSGC &&
ca->ca_type.iodc_sv_model != HPPA_FIO_SGC)
return 0;
rom = sti_sgc_getrom(cf->cf_unit, ca);
#ifdef STIDEBUG
printf ("sti: hpa=%lx, rom=%lx\n", ca->ca_hpa, rom);
#endif
if ((rv = bus_space_map(ca->ca_iot, rom, STI_ROMSIZE, 0, &romh))) {
#ifdef STIDEBUG
printf ("sti: cannot map rom space (%d)\n", rv);
#endif
if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) {
romh = rom;
romunmapped++;
} else {
return 0;
}
}
devtype = bus_space_read_1(ca->ca_iot, romh, 3);
#ifdef STIDEBUG
printf("sti: devtype=%d\n", devtype);
#endif
rv = 1;
switch (devtype) {
case STI_DEVTYPE4:
id = bus_space_read_4(ca->ca_iot, romh, 0x8);
break;
case STI_DEVTYPE1:
id = (bus_space_read_1(ca->ca_iot, romh, 0x10 + 3) << 24) |
(bus_space_read_1(ca->ca_iot, romh, 0x10 + 7) << 16) |
(bus_space_read_1(ca->ca_iot, romh, 0x10 + 11) << 8) |
(bus_space_read_1(ca->ca_iot, romh, 0x10 + 15));
break;
default:
#ifdef STIDEBUG
printf("sti: unknown type (%x)\n", devtype);
#endif
rv = 0;
}
if (rv &&
ca->ca_type.iodc_sv_model == HPPA_FIO_SGC && id == STI_ID_FDDI) {
#ifdef STIDEBUG
printf("sti: not a graphics device\n");
#endif
rv = 0;
}
if (ca->ca_naddrs >= sizeof(ca->ca_addrs)/sizeof(ca->ca_addrs[0])) {
printf("sti: address list overflow\n");
return (0);
}
ca->ca_addrs[ca->ca_naddrs].addr = rom;
ca->ca_addrs[ca->ca_naddrs].size = sti_rom_size(ca->ca_iot, romh);
ca->ca_naddrs++;
if (!romunmapped)
bus_space_unmap(ca->ca_iot, romh, STI_ROMSIZE);
return (rv);
}
void
sti_sgc_attach(struct device *parent, struct device *self, void *aux)
{
struct sti_softc *sc = (void *)self;
struct confargs *ca = aux;
bus_space_handle_t romh;
paddr_t rom;
u_int32_t romlen;
int rv;
int i;
rom = ca->ca_addrs[ca->ca_naddrs - 1].addr;
romlen = ca->ca_addrs[ca->ca_naddrs - 1].size;
if ((rv = bus_space_map(ca->ca_iot, rom, romlen, 0, &romh))) {
if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN)
romh = rom;
else {
printf (": cannot map rom space (%d)\n", rv);
return;
}
}
sc->bases[0] = romh;
for (i = 1; i < STI_REGION_MAX; i++)
sc->bases[i] = ca->ca_hpa;
#ifdef HP7300LC_CPU
if (cpu_type == hpcxl2)
eaio_l2(0x8 >> (((ca->ca_hpa >> 25) & 3) - 2));
#endif
if (ca->ca_hpa == (hppa_hpa_t)PAGE0->mem_cons.pz_hpa)
sc->sc_flags |= STI_CONSOLE;
if (sti_attach_common(sc, ca->ca_iot, ca->ca_iot, romh,
STI_CODEBASE_PA) == 0)
startuphook_establish(sti_end_attach, sc);
}