? diff ? lib/csu/arch/hppa ? sys/cscope.out ? sys/arch/hp700/compile/DEBUG ? sys/arch/hp700/compile/GENERIC ? sys/arch/hp700/stand/boot/lib ? sys/arch/i386/compile/DEBUG ? sys/arch/i386/compile/GENERIC Index: sys/arch/hp700/conf/GENERIC =================================================================== RCS file: /cvsroot/src/sys/arch/hp700/conf/GENERIC,v retrieving revision 1.102 diff -u -p -u -r1.102 GENERIC --- sys/arch/hp700/conf/GENERIC 17 Aug 2010 00:02:28 -0000 1.102 +++ sys/arch/hp700/conf/GENERIC 7 Nov 2010 14:27:15 -0000 @@ -70,10 +70,12 @@ options USERCONF # userconf(4) support #options DEBUG # expensive debugging checks/support #options KMEMSTATS # kernel memory statistics (vmstat -m) options DDB # in-kernel debugger +options DDB_COMMANDONENTER="trace;show registers" options DDB_HISTORY_SIZE=512 # enable history editing in DDB #options KGDB # remote debugger #options KGDB_DEVNAME="\"com\"",KGDBADDR=0xf0822000,KGDBRATE=9600 #makeoptions DEBUG="-g" # compile full symbol table +options STIDEBUG # Compatibility options options COMPAT_20 # compatability with NetBSD 2.0, @@ -231,6 +233,8 @@ lcd0 at mainbus0 # LCD # STI graphics sti* at mainbus0 # [H]CRX-{8,24,48}[Z] and Visualize graphics sti* at phantomas? # [H]CRX-{8,24,48}[Z] and Visualize graphics +sti* at uturn? +sti* at pci? # EG-PCI, FX* # Basic Bus Support lasi* at mainbus0 # LASI host adapter ( LSI PN??? ) Index: sys/arch/hp700/conf/files.hp700 =================================================================== RCS file: /cvsroot/src/sys/arch/hp700/conf/files.hp700,v retrieving revision 1.23 diff -u -p -u -r1.23 files.hp700 --- sys/arch/hp700/conf/files.hp700 1 Jun 2010 10:20:28 -0000 1.23 +++ sys/arch/hp700/conf/files.hp700 7 Nov 2010 14:27:15 -0000 @@ -150,7 +150,8 @@ file arch/hp700/dev/elroy.c elroy file arch/hp700/dev/apic.c elroy attach sti at gedoens with sti_gedoens -file arch/hp700/dev/sti_sgc.c sti_gedoens +file arch/hp700/dev/sti_sgc.c sti_gedoens +file arch/hp700/dev/sti_pci_machdep.c sti_pci attach siop at gedoens with siop_gedoens file arch/hp700/dev/siop_sgc.c siop_gedoens Index: sys/arch/hp700/dev/apic.c =================================================================== RCS file: /cvsroot/src/sys/arch/hp700/dev/apic.c,v retrieving revision 1.7 diff -u -p -u -r1.7 apic.c --- sys/arch/hp700/dev/apic.c 24 Apr 2010 10:41:21 -0000 1.7 +++ sys/arch/hp700/dev/apic.c 7 Nov 2010 14:27:16 -0000 @@ -64,6 +64,12 @@ ((((p) & MPS_INTPO_MASK) << MPS_INTPO_SHIFT) | \ (((t) & MPS_INTTR_MASK) << MPS_INTTR_SHIFT)) +void elroy_write32_debug(void *, volatile uint32_t *, uint32_t); +uint32_t elroy_read32_debug(void *, volatile uint32_t *); + +#define elroy_write32(x, y) elroy_write32_debug(NULL, (x), (y)) +#define elroy_read32(x) elroy_read32_debug(NULL, (x)) + struct apic_iv { struct elroy_softc *sc; pci_intr_handle_t ih; Index: sys/arch/hp700/dev/elroy.c =================================================================== RCS file: /cvsroot/src/sys/arch/hp700/dev/elroy.c,v retrieving revision 1.9 diff -u -p -u -r1.9 elroy.c --- sys/arch/hp700/dev/elroy.c 3 Apr 2010 08:01:42 -0000 1.9 +++ sys/arch/hp700/dev/elroy.c 7 Nov 2010 14:27:17 -0000 @@ -44,6 +44,21 @@ #include #include +#define ELROYDEBUG +#ifdef ELROYDEBUG + +#define DPRINTF(e, s) do { \ + if (elroydebug && (e) == elroytodebug) \ + printf_nolog s; \ +} while(0) + +int elroydebug = 0; +void *elroytodebug = NULL; +#else +#define DPRINTF(s) /* */ +#endif + + #define ELROY_MEM_CHUNK 0x800000 #define ELROY_MEM_WINDOW (2 * ELROY_MEM_CHUNK) @@ -55,8 +70,8 @@ CFATTACH_DECL_NEW(elroy, sizeof(struct e extern struct cfdriver elroy_cd; -void elroy_write32(volatile uint32_t *, uint32_t); -uint32_t elroy_read32(volatile uint32_t *); +void elroy_write32_debug(void *, volatile uint32_t *, uint32_t); +uint32_t elroy_read32_debug(void *, volatile uint32_t *); void elroy_attach_hook(device_t, device_t, struct pcibus_attach_args *); int elroy_maxdevs(void *, int); pcitag_t elroy_make_tag(void *, int, int, int); @@ -206,16 +221,27 @@ elroy_match(device_t parent, cfdata_t cf return (0); } +#define elroy_write32(x, y) elroy_write32_debug(v, (x), (y)) +#define elroy_read32(x) elroy_read32_debug(v, (x)) + void -elroy_write32(volatile uint32_t *p, uint32_t v) +elroy_write32_debug(void *sc, volatile uint32_t *p, uint32_t v) { + DPRINTF(sc, ("%s: %p = 0x%08x\n", __func__, p, v)); + *p = v; } uint32_t -elroy_read32(volatile uint32_t *p) +elroy_read32_debug(void *sc, volatile uint32_t *p) { - return *p; + uint32_t r; + + r = *p; + + DPRINTF(sc, ("%s: 0x%08x from %p\n", __func__, r, p)); + return r; + } void @@ -256,7 +282,6 @@ elroy_conf_read(void *v, pcitag_t tag, i uint32_t arb_mask, err_cfg, control; pcireg_t data, data1; -/* printf("elroy_conf_read(%p, 0x%08x, 0x%x)", v, tag, reg); */ arb_mask = elroy_read32(&r->arb_mask); err_cfg = elroy_read32(&r->err_cfg); control = elroy_read32(&r->control); @@ -279,8 +304,11 @@ elroy_conf_read(void *v, pcitag_t tag, i elroy_write32(&r->arb_mask, arb_mask); data = le32toh(data); -/* printf("=0x%08x (@ 0x%08x)\n", data, le32toh(data1)); */ - return (data); + + DPRINTF(v, ("%s: %p 0x%08x 0x%x = 0x%08x (@ 0x%08x)\n", + __func__, v, (u_int)tag, reg, data, le32toh(data1))); + + return data; } void @@ -291,7 +319,6 @@ elroy_conf_write(void *v, pcitag_t tag, uint32_t arb_mask, err_cfg, control; pcireg_t data1; -/* printf("elroy_conf_write(%p, 0x%08x, 0x%x, 0x%x)\n", v, tag, reg, data); */ arb_mask = elroy_read32(&r->arb_mask); err_cfg = elroy_read32(&r->err_cfg); control = elroy_read32(&r->control); @@ -318,6 +345,9 @@ elroy_conf_write(void *v, pcitag_t tag, elroy_write32(&r->err_cfg, err_cfg); if (!arb_mask) elroy_write32(&r->arb_mask, arb_mask); + + DPRINTF(v, ("%s: %p 0x%08x 0x%x = 0x%x\n", + __func__, v, (u_int)tag, reg, data)); } int @@ -496,43 +526,73 @@ elroy_mmap(void *v, bus_addr_t addr, off uint8_t elroy_r1(void *v, bus_space_handle_t h, bus_size_t o) { + uint8_t ret; + + DPRINTF(v, ("%s: 0x%08x+0x%x (0x%08x) is ", __func__, (u_int)h, (u_int)o, (u_int)(h + o))); + h += o; - return *(volatile uint8_t *)h; + ret = *(volatile uint8_t *)h; + + DPRINTF(v, ("0x%02x\n",ret)); + + return ret; } uint16_t elroy_r2(void *v, bus_space_handle_t h, bus_size_t o) { volatile uint16_t *p; + uint16_t r; h += o; p = (volatile uint16_t *)h; - return (le16toh(*p)); + + r = le16toh(*p); + + DPRINTF(v, ("%s: 0x%02x from 0x%08x+0x%x (0x%08x)\n", + __func__, r, (u_int)(h-o), (u_int)o, (u_int)(h))); + + return r; } uint32_t elroy_r4(void *v, bus_space_handle_t h, bus_size_t o) { uint32_t data; + uint32_t r; h += o; data = *(volatile uint32_t *)h; - return (le32toh(data)); + r = le32toh(data); + + DPRINTF(v, ("%s: 0x%08x from 0x%08x+0x%x (0x%08x)\n", + __func__, r, (u_int)(h-o), (u_int)o, (u_int)(h))); + + return r; } uint64_t elroy_r8(void *v, bus_space_handle_t h, bus_size_t o) { uint64_t data; + uint64_t r; h += o; data = *(volatile uint64_t *)h; - return (le64toh(data)); + r = le64toh(data); + + DPRINTF(v, ("%s: 0x%16llx from 0x%08x+0x%x (0x%08x)\n", + __func__, r, (u_int)(h-o), (u_int)o, (u_int)(h))); + + return r; } void elroy_w1(void *v, bus_space_handle_t h, bus_size_t o, uint8_t vv) { + DPRINTF(v, ("%s: 0x%08x+0x%x (0x%08x) = 0x%08x\n", + __func__, (u_int)h, (u_int)o, (u_int)(h+o), vv)); + h += o; *(volatile uint8_t *)h = vv; } @@ -542,6 +602,9 @@ elroy_w2(void *v, bus_space_handle_t h, { volatile uint16_t *p; + DPRINTF(v, ("%s: 0x%08x+0x%x (0x%08x) = 0x%08x\n", + __func__, (u_int)h, (u_int)o, (u_int)(h+o), vv)); + h += o; p = (volatile uint16_t *)h; *p = htole16(vv); @@ -550,6 +613,9 @@ elroy_w2(void *v, bus_space_handle_t h, void elroy_w4(void *v, bus_space_handle_t h, bus_size_t o, uint32_t vv) { + DPRINTF(v, ("%s: 0x%08x+0x%x (0x%08x) = 0x%08x\n", + __func__, (u_int)h, (u_int)o, (u_int)(h+o), vv)); + h += o; vv = htole32(vv); *(volatile uint32_t *)h = vv; @@ -558,6 +624,9 @@ elroy_w4(void *v, bus_space_handle_t h, void elroy_w8(void *v, bus_space_handle_t h, bus_size_t o, uint64_t vv) { + DPRINTF(v, ("%s: 0x%08x+0x%x (0x%08x) = 0x%16llx\n", + __func__, (u_int)h, (u_int)o, (u_int)(h+o), vv)); + h += o; *(volatile uint64_t *)h = htole64(vv); } @@ -1217,7 +1286,13 @@ elroy_attach(device_t parent, device_t s volatile struct elroy_regs *r; const char *p = NULL, *q; int i; - + void *v = sc; +#if 0 + if (ca->ca_hpa == 0xfed3c000) { + elroytodebug = sc; + elroydebug = 1; + } +#endif sc->sc_dv = self; sc->sc_hpa = ca->ca_hpa; sc->sc_bt = ca->ca_iot; @@ -1286,13 +1361,14 @@ elroy_attach(device_t parent, device_t s /* TODO reserve elroy's pci space ? */ #if 0 -printf("lmm %llx/%llx gmm %llx/%llx wlm %llx/%llx wgm %llx/%llx io %llx/%llx eio %llx/%llx\n", -le64toh(r->lmmio_base), le64toh(r->lmmio_mask), -le64toh(r->gmmio_base), le64toh(r->gmmio_mask), -le64toh(r->wlmmio_base), le64toh(r->wlmmio_mask), -le64toh(r->wgmmio_base), le64toh(r->wgmmio_mask), -le64toh(r->io_base), le64toh(r->io_mask), -le64toh(r->eio_base), le64toh(r->eio_mask)); + DPRINTF(("lmm %llx/%llx gmm %llx/%llx wlm %llx/%llx wgm %llx/%llx " + "io %llx/%llx eio %llx/%llx\n", + le64toh(r->lmmio_base), le64toh(r->lmmio_mask), + le64toh(r->gmmio_base), le64toh(r->gmmio_mask), + le64toh(r->wlmmio_base), le64toh(r->wlmmio_mask), + le64toh(r->wgmmio_base), le64toh(r->wgmmio_mask), + le64toh(r->io_base), le64toh(r->io_mask), + le64toh(r->eio_base), le64toh(r->eio_mask))); #endif /* XXX evil hack! */ Index: sys/arch/hp700/dev/sti_pci_machdep.c =================================================================== RCS file: sys/arch/hp700/dev/sti_pci_machdep.c diff -N sys/arch/hp700/dev/sti_pci_machdep.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sys/arch/hp700/dev/sti_pci_machdep.c 7 Nov 2010 14:27:17 -0000 @@ -0,0 +1,88 @@ +/* $NetBSD$ */ + +/* $OpenBSD: sti_pci_machdep.c,v 1.2 2009/04/10 17:11:27 miod Exp $ */ + +/* + * Copyright (c) 2007, 2009 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include +#include + +#include + +#include + +int sti_pci_is_console(struct pci_attach_args *, bus_addr_t *); + +int +sti_pci_is_console(struct pci_attach_args *paa, bus_addr_t *bases) +{ + hppa_hpa_t consaddr; + uint32_t cf; + int pagezero_cookie; + int bar; + int rc; + + KASSERT(paa != NULL); + + pagezero_cookie = hp700_pagezero_map(); + consaddr = (hppa_hpa_t)PAGE0->mem_cons.pz_hpa; + hp700_pagezero_unmap(pagezero_cookie); + /* + * PAGE0 console information will point to one of our BARs, + * but depending on the particular sti model, this might not + * be the BAR mapping the rom (region #0). + * + * For example, on Visualize FXe, regions #0, #2 and #3 are + * mapped by BAR 0x18, while region #1 is mapped by BAR 0x10, + * which matches PAGE0 console address. + * + * Rather than trying to be smart, reread the region->BAR array + * again, and compare the BAR mapping region #1 against PAGE0 + * values, we simply try all the valid BARs; if any of them + * matches what PAGE0 says, then we are the console, and it + * doesn't matter which BAR matched. + */ + for (bar = PCI_MAPREG_START; bar <= PCI_MAPREG_PPB_END; ) { + bus_addr_t addr; + bus_size_t size; + + cf = pci_conf_read(paa->pa_pc, paa->pa_tag, bar); + + rc = pci_mapreg_info(paa->pa_pc, paa->pa_tag, bar, PCI_MAPREG_TYPE(cf), + &addr, &size, NULL); + + if (PCI_MAPREG_TYPE(cf) == PCI_MAPREG_TYPE_IO) { + bar += 4; + } else { + if (PCI_MAPREG_MEM_TYPE(cf) == + PCI_MAPREG_MEM_TYPE_64BIT) + bar += 8; + else + bar += 4; + } + + if (rc == 0 && (hppa_hpa_t)addr == consaddr) + return 1; + } + + return 0; +} Index: sys/arch/hp700/dev/sti_sgc.c =================================================================== RCS file: /cvsroot/src/sys/arch/hp700/dev/sti_sgc.c,v retrieving revision 1.19 diff -u -p -u -r1.19 sti_sgc.c --- sys/arch/hp700/dev/sti_sgc.c 6 Mar 2010 19:36:33 -0000 1.19 +++ sys/arch/hp700/dev/sti_sgc.c 7 Nov 2010 14:27:17 -0000 @@ -1,6 +1,6 @@ /* $NetBSD: sti_sgc.c,v 1.19 2010/03/06 19:36:33 skrll Exp $ */ -/* $OpenBSD: sti_sgc.c,v 1.21 2003/12/22 23:39:06 mickey Exp $ */ +/* $OpenBSD: sti_sgc.c,v 1.38 2009/02/06 22:51:04 miod Exp $ */ /* * Copyright (c) 2000-2003 Michael Shalayeff @@ -71,6 +71,16 @@ __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v #define STI_GOPT6_REV 0x40 #define STI_GOPT7_REV 0x30 +const char sti_sgc_opt[] = { + STI_GOPT1_REV, + STI_GOPT2_REV, + STI_GOPT3_REV, + STI_GOPT4_REV, + STI_GOPT5_REV, + STI_GOPT6_REV, + STI_GOPT7_REV +}; + /* internal EG */ #define STI_INEG_REV 0x60 #define STI_INEG_PROM 0xf0011000 @@ -78,45 +88,48 @@ __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v int sti_sgc_probe(device_t, cfdata_t, void *); void sti_sgc_attach(device_t, device_t, void *); +void sti_sgc_end_attach(device_t); + +extern struct cfdriver sti_cd; + CFATTACH_DECL_NEW(sti_gedoens, sizeof(struct sti_softc), sti_sgc_probe, sti_sgc_attach, NULL, NULL); -paddr_t sti_sgc_getrom(struct confargs *); +paddr_t sti_sgc_getrom(int, struct confargs *); /* * Locate STI ROM. * On some machines it may not be part of the HPA space. */ paddr_t -sti_sgc_getrom(struct confargs *ca) +sti_sgc_getrom(int unit, struct confargs *ca) { paddr_t rom; int pagezero_cookie; + int i; - rom = ca->ca_hpa; + pagezero_cookie = hp700_pagezero_map(); + rom = PAGE0->pd_resv2[1]; + hp700_pagezero_unmap(pagezero_cookie); - if (ca->ca_type.iodc_sv_model != HPPA_FIO_GSGC) { - return rom; - } + 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; ) + ; - switch (ca->ca_type.iodc_revision) { - case STI_GOPT1_REV: - case STI_GOPT2_REV: - case STI_GOPT3_REV: - case STI_GOPT4_REV: - case STI_GOPT5_REV: - case STI_GOPT6_REV: - case STI_GOPT7_REV: - /* these share the onboard's prom */ - pagezero_cookie = hp700_pagezero_map(); - rom = PAGE0->pd_resv2[1]; - hp700_pagezero_unmap(pagezero_cookie); - break; - - case STI_INEG_REV: - rom = STI_INEG_PROM; - break; + 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; } @@ -130,15 +143,19 @@ sti_sgc_probe(device_t parent, cfdata_t u_char devtype; int rv = 0, romunmapped = 0; + /* due to the graphic nature of this program do probe only one */ + if (cf->cf_unit > sti_cd.cd_ndevs) + return 0; + if (ca->ca_type.iodc_type != HPPA_TYPE_FIO) - return (0); + return 0; - /* these need futher checking for the graphics id */ + /* these need further checking for the graphics id */ 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(ca); + rom = sti_sgc_getrom(cf->cf_unit, ca); #ifdef STIDEBUG printf ("sti: hpa=%x, rom=%x\n", (uint)ca->ca_hpa, (uint)rom); #endif @@ -166,7 +183,6 @@ sti_sgc_probe(device_t parent, cfdata_t switch (devtype) { case STI_DEVTYPE4: id = bus_space_read_4(ca->ca_iot, romh, STI_DEV4_DD_GRID); - romend = bus_space_read_4(ca->ca_iot, romh, STI_DEV4_DD_ROMEND); break; case STI_DEVTYPE1: id = (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID @@ -177,14 +193,6 @@ sti_sgc_probe(device_t parent, cfdata_t + 11) << 8) | (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID + 15)); - romend = (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND - + 3) << 24) | - (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND - + 7) << 16) | - (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND - + 11) << 8) | - (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND - + 15)); break; default: #ifdef STIDEBUG @@ -208,7 +216,7 @@ sti_sgc_probe(device_t parent, cfdata_t } ca->ca_addrs[ca->ca_naddrs].addr = rom; - ca->ca_addrs[ca->ca_naddrs].size = round_page(romend); + ca->ca_addrs[ca->ca_naddrs].size = sti_rom_size(ca->ca_iot, romh); ca->ca_naddrs++; if (!romunmapped) @@ -221,27 +229,31 @@ sti_sgc_attach(device_t parent, device_t { struct sti_softc *sc = device_private(self); struct confargs *ca = aux; + bus_space_handle_t romh; paddr_t rom; uint32_t romlen; int rv; + int i; int pagezero_cookie; pagezero_cookie = hp700_pagezero_map(); sc->sc_dev = self; - sc->memt = sc->iot = ca->ca_iot; - sc->base = ca->ca_hpa; /* we stashed rom addr/len into the last slot during probe */ 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, &sc->romh))) { + if ((rv = bus_space_map(ca->ca_iot, rom, romlen, 0, &romh))) { if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) - sc->romh = rom; + romh = rom; else { aprint_error(": can't 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 /* @@ -255,9 +267,18 @@ sti_sgc_attach(device_t parent, device_t eaio_l2(PCXL2_ACCEL_IO_ADDR2MASK(ca->ca_hpa)); #endif /* HP7300LC_CPU */ - sc->sc_devtype = bus_space_read_1(sc->iot, sc->romh, 3); if (ca->ca_hpa == (hppa_hpa_t)PAGE0->mem_cons.pz_hpa) sc->sc_flags |= STI_CONSOLE; hp700_pagezero_unmap(pagezero_cookie); - sti_attach_common(sc); + if (sti_attach_common(sc, ca->ca_iot, ca->ca_iot, romh, + STI_CODEBASE_PA) == 0) + config_defer(self, sti_sgc_end_attach); +} + +void +sti_sgc_end_attach(device_t dev) +{ + struct sti_softc *sc = device_private(dev); + + sti_end_attach(sc); } Index: sys/arch/hp700/hp700/mainbus.c =================================================================== RCS file: /cvsroot/src/sys/arch/hp700/hp700/mainbus.c,v retrieving revision 1.71 diff -u -p -u -r1.71 mainbus.c --- sys/arch/hp700/hp700/mainbus.c 30 Jun 2010 06:33:52 -0000 1.71 +++ sys/arch/hp700/hp700/mainbus.c 7 Nov 2010 14:27:18 -0000 @@ -88,6 +88,7 @@ static struct pdc_chassis_info pdc_chass static struct pdc_chassis_lcd pdc_chassis_lcd PDC_ALIGNMENT; #endif +#define MBUSDEBUG #ifdef MBUSDEBUG #define DPRINTF(s) do { \ @@ -95,7 +96,7 @@ static struct pdc_chassis_lcd pdc_chassi printf s; \ } while(0) -int mbusdebug = 1; +int mbusdebug = 0; #else #define DPRINTF(s) /* */ #endif Index: sys/arch/hppa/hppa/pmap.c =================================================================== RCS file: /cvsroot/src/sys/arch/hppa/hppa/pmap.c,v retrieving revision 1.77 diff -u -p -u -r1.77 pmap.c --- sys/arch/hppa/hppa/pmap.c 30 Oct 2010 17:20:43 -0000 1.77 +++ sys/arch/hppa/hppa/pmap.c 7 Nov 2010 14:27:20 -0000 @@ -93,6 +93,7 @@ __KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.7 #define VM_PAGE_TO_MD(pg) (&(pg)->mdpage) +#define PMAPDEBUG #ifdef PMAPDEBUG #define static /**/ @@ -124,6 +125,7 @@ __KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.7 #define PDB_POOL 0x00040000 #define PDB_ALIAS 0x00080000 int pmapdebug = 0 +#if 0 | PDB_INIT | PDB_FOLLOW | PDB_VP @@ -134,6 +136,7 @@ int pmapdebug = 0 | PDB_PROTECT | PDB_PHYS | PDB_ALIAS +#endif ; #else #define DPRINTF(l,s) /* */ Index: sys/arch/hppa/hppa/trap.S =================================================================== RCS file: /cvsroot/src/sys/arch/hppa/hppa/trap.S,v retrieving revision 1.50 diff -u -p -u -r1.50 trap.S --- sys/arch/hppa/hppa/trap.S 6 Jun 2010 12:13:36 -0000 1.50 +++ sys/arch/hppa/hppa/trap.S 7 Nov 2010 14:27:21 -0000 @@ -1605,6 +1605,21 @@ EXIT(TLABEL(dtlb_l)) #if defined(HP8000_CPU) || defined(HP8200_CPU) || defined(HP8500_CPU) .level 2.0w + .section .data + .export tlbdu_lastr17, data + .export tlbdu_lastr25, data + .export dtlbu_lastr17, data + .export dtlbu_lastr25, data +tlbdu_lastr17: + .block 8 +tlbdu_lastr25: + .block 8 +dtlbu_lastr17: + .block 8 +dtlbu_lastr25: + .block 8 + .text + /* xlate 32bit->64bit pte */ #define TLB_PCX2PCXU \ extrw,u %r25, 14, 13, %r16 ! \ @@ -1638,11 +1653,29 @@ EXIT(TLABEL(dtlb_l)) LEAF_ENTRY_NOPROFILE(TLABEL(tlbd_u)) TLB_STATS_PRE(tlbd) TLB_PULL_L(1, TLABEL(all)) + + extrd,s %r17, 42, 4, %r1 + addi,= 1, %r1, %r0 + b,n 1f + nop + + TLB_PCX2PCXU + ldil L%tlbdu_lastr17, %r16 + std %r17, R%tlbdu_lastr17(%r16) + ldil L%tlbdu_lastr25, %r16 + std %r25, R%tlbdu_lastr25(%r16) + idtlbt %r17, %r25 + TLB_STATS_AFT(tlbd) + rfir + nop + +1: TLB_PCX2PCXU idtlbt %r17, %r25 TLB_STATS_AFT(tlbd) rfir nop + EXIT(TLABEL(tlbd_u)) /* @@ -1730,6 +1763,22 @@ EXIT(TLABEL(dtlbna_u)) LEAF_ENTRY_NOPROFILE(TLABEL(dtlb_u)) TLB_STATS_PRE(dtlb) TLB_PULL_L(0, TLABEL(all)) + + extrd,s %r17, 42, 4, %r1 + addi,= 1, %r1, %r0 + b,n 1f + nop + + TLB_PCX2PCXU + ldil L%dtlbu_lastr17, %r16 + std %r17, R%dtlbu_lastr17(%r16) + ldil L%dtlbu_lastr25, %r16 + std %r25, R%dtlbu_lastr25(%r16) + idtlbt %r17, %r25 + TLB_STATS_AFT(dtlb) + rfir + nop +1: TLB_PCX2PCXU idtlbt %r17, %r25 TLB_STATS_AFT(dtlb) Index: sys/arch/hppa/hppa/trap.c =================================================================== RCS file: /cvsroot/src/sys/arch/hppa/hppa/trap.c,v retrieving revision 1.93 diff -u -p -u -r1.93 trap.c --- sys/arch/hppa/hppa/trap.c 7 Jul 2010 01:18:39 -0000 1.93 +++ sys/arch/hppa/hppa/trap.c 7 Nov 2010 14:27:22 -0000 @@ -445,11 +445,12 @@ do { \ */ if ((type & ~T_USER) == T_INTERRUPT) goto out; - +#if 0 SANITY(tf->tf_iioq_head >= (u_int) &kernel_text); SANITY(tf->tf_iioq_head < (u_int) &etext); SANITY(tf->tf_iioq_tail >= (u_int) &kernel_text); SANITY(tf->tf_iioq_tail < (u_int) &etext); +#endif maxsp = uv + USPACE + PAGE_SIZE; minsp = uv + PAGE_SIZE; Index: sys/dev/ic/sti.c =================================================================== RCS file: /cvsroot/src/sys/dev/ic/sti.c,v retrieving revision 1.12 diff -u -p -u -r1.12 sti.c --- sys/dev/ic/sti.c 1 Nov 2010 06:41:50 -0000 1.12 +++ sys/dev/ic/sti.c 7 Nov 2010 14:27:32 -0000 @@ -1,6 +1,6 @@ /* $NetBSD: sti.c,v 1.12 2010/11/01 06:41:50 skrll Exp $ */ -/* $OpenBSD: sti.c,v 1.35 2003/12/16 06:07:13 mickey Exp $ */ +/* $OpenBSD: sti.c,v 1.61 2009/09/05 14:09:35 miod Exp $ */ /* * Copyright (c) 2000-2003 Michael Shalayeff @@ -54,6 +54,8 @@ __KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.12 #include #include +#include "sti_pci.h" + void sti_cursor(void *, int, int, int); int sti_mapchar(void *, int, u_int *); void sti_putchar(void *, int, int, u_int, long); @@ -111,44 +113,136 @@ enum sti_bmove_funcs { bmf_clear, bmf_copy, bmf_invert, bmf_underline }; -int sti_init(struct sti_softc *, int); -int sti_inqcfg(struct sti_softc *, struct sti_inqconfout *); -void sti_bmove(struct sti_softc *, int, int, int, int, int, int, - enum sti_bmove_funcs); -int sti_setcment(struct sti_softc *, u_int, u_char, u_char, u_char); -int sti_fetchfonts(struct sti_softc *, struct sti_inqconfout *, uint32_t); -void sti_attach_deferred(device_t); +int sti_init(struct sti_screen *, int); +#define STI_TEXTMODE 0x01 +#define STI_CLEARSCR 0x02 +int sti_inqcfg(struct sti_screen *, struct sti_inqconfout *); +void sti_bmove(struct sti_screen *, int, int, int, int, int, int, + enum sti_bmove_funcs); +int sti_setcment(struct sti_screen *, u_int, u_char, u_char, u_char); + +struct sti_screen *sti_attach_screen(struct sti_softc *, int); +void sti_describe_screen(struct sti_softc *, struct sti_screen *); + +int sti_fetchfonts(struct sti_screen *, struct sti_inqconfout *, uint32_t, + u_int); +void sti_region_setup(struct sti_screen *); +int sti_rom_setup(struct sti_rom *, bus_space_tag_t, bus_space_tag_t, + bus_space_handle_t, bus_addr_t *, u_int); +int sti_screen_setup(struct sti_screen *, int); + +#if NSTI_PCI > 0 +#define STI_ENABLE_ROM(sc) \ +do { \ + if ((sc) != NULL && (sc)->sc_enable_rom != NULL) { \ + (*(sc)->sc_enable_rom)(sc); \ + } \ +} while (0) +#define STI_DISABLE_ROM(sc) \ +do { \ + if ((sc) != NULL && (sc)->sc_disable_rom != NULL) \ + (*(sc)->sc_disable_rom)(sc); \ +} while (0) +#else +#define STI_ENABLE_ROM(sc) do { /* nothing */ } while (0) +#define STI_DISABLE_ROM(sc) do { /* nothing */ } while (0) +#endif -void -sti_attach_common(struct sti_softc *sc) +/* Macros to read larger than 8 bit values from byte roms */ +#define parseshort(o) \ + ((bus_space_read_1(memt, romh, (o) + 3) << 8) | \ + (bus_space_read_1(memt, romh, (o) + 7))) +#define parseword(o) \ + ((bus_space_read_1(memt, romh, (o) + 3) << 24) | \ + (bus_space_read_1(memt, romh, (o) + 7) << 16) | \ + (bus_space_read_1(memt, romh, (o) + 11) << 8) | \ + (bus_space_read_1(memt, romh, (o) + 15))) + +int +sti_attach_common(struct sti_softc *sc, bus_space_tag_t iot, + bus_space_tag_t memt, bus_space_handle_t romh, u_int codebase) +{ + struct sti_rom *rom; + int rc; + + rom = (struct sti_rom *)malloc(sizeof(*rom), M_DEVBUF, + M_NOWAIT | M_ZERO); + if (rom == NULL) { + aprint_error("cannot allocate rom data\n"); + return ENOMEM; + } + + rom->rom_softc = sc; + rc = sti_rom_setup(rom, iot, memt, romh, sc->bases, codebase); + if (rc != 0) { + free(rom, M_DEVBUF); + return rc; + } + + sc->sc_rom = rom; + + sti_describe(sc); + + sc->sc_scr = sti_attach_screen(sc, + sc->sc_flags & STI_CONSOLE ? 0 : STI_CLEARSCR); + if (sc->sc_scr == NULL) + rc = ENOMEM; + + return rc; +} + +struct sti_screen * +sti_attach_screen(struct sti_softc *sc, int flags) +{ + struct sti_screen *scr; + int rc; + + scr = (struct sti_screen *)malloc(sizeof(*scr), M_DEVBUF, + M_NOWAIT | M_ZERO); + if (scr == NULL) { + aprint_error("cannot allocate screen data\n"); + return NULL; + } + + scr->scr_rom = sc->sc_rom; + rc = sti_screen_setup(scr, flags); + if (rc != 0) { + free(scr, M_DEVBUF); + return NULL; + } + + sti_describe_screen(sc, scr); + + return scr; +} + +int +sti_rom_setup(struct sti_rom *rom, bus_space_tag_t iot, bus_space_tag_t memt, + bus_space_handle_t romh, bus_addr_t *bases, u_int codebase) { - struct sti_inqconfout cfg; - struct sti_einqconfout ecfg; - bus_space_handle_t fbh; struct sti_dd *dd; - struct sti_cfg *cc; int error, size, i; - uint8_t *p = (uint8_t *)sc->sc_code; - uint32_t addr, eaddr; - struct sti_region r; - uint32_t *q; - uint32_t tmp; - dd = &sc->sc_dd; - if (sc->sc_devtype == STI_DEVTYPE1) { -#define parseshort(o) \ - ((bus_space_read_1(sc->memt, sc->romh, (o) + 3) << 8) | \ - (bus_space_read_1(sc->memt, sc->romh, (o) + 7))) -#define parseword(o) \ - ((bus_space_read_1(sc->memt, sc->romh, (o) + 3) << 24) | \ - (bus_space_read_1(sc->memt, sc->romh, (o) + 7) << 16) | \ - (bus_space_read_1(sc->memt, sc->romh, (o) + 11) << 8) | \ - (bus_space_read_1(sc->memt, sc->romh, (o) + 15))) - - dd->dd_type = bus_space_read_1(sc->memt, sc->romh, 0x03); - dd->dd_nmon = bus_space_read_1(sc->memt, sc->romh, 0x07); - dd->dd_grrev = bus_space_read_1(sc->memt, sc->romh, 0x0b); - dd->dd_lrrev = bus_space_read_1(sc->memt, sc->romh, 0x0f); + KASSERT(rom != NULL); + KASSERT(rom->rom_softc->sc_enable_rom != NULL); + STI_ENABLE_ROM(rom->rom_softc); + + rom->iot = iot; + rom->memt = memt; + rom->romh = romh; + rom->bases = bases; + + /* + * Get ROM header and code function pointers. + */ + + dd = &rom->rom_dd; + rom->rom_devtype = bus_space_read_1(memt, romh, 3); + if (rom->rom_devtype == STI_DEVTYPE1) { + dd->dd_type = bus_space_read_1(memt, romh, 0x03); + dd->dd_nmon = bus_space_read_1(memt, romh, 0x07); + dd->dd_grrev = bus_space_read_1(memt, romh, 0x0b); + dd->dd_lrrev = bus_space_read_1(memt, romh, 0x0f); dd->dd_grid[0] = parseword(0x10); dd->dd_grid[1] = parseword(0x20); dd->dd_fntaddr = parseword(0x30) & ~3; @@ -162,33 +256,40 @@ sti_attach_common(struct sti_softc *sc) dd->dd_stimemreq=parseword(0xa0); dd->dd_udsize = parseword(0xb0); dd->dd_pwruse = parseshort(0xc0); - dd->dd_bussup = bus_space_read_1(sc->memt, sc->romh, 0xcb); - dd->dd_ebussup = bus_space_read_1(sc->memt, sc->romh, 0xcf); - dd->dd_altcodet= bus_space_read_1(sc->memt, sc->romh, 0xd3); - dd->dd_eddst[0]= bus_space_read_1(sc->memt, sc->romh, 0xd7); - dd->dd_eddst[1]= bus_space_read_1(sc->memt, sc->romh, 0xdb); - dd->dd_eddst[2]= bus_space_read_1(sc->memt, sc->romh, 0xdf); + dd->dd_bussup = bus_space_read_1(memt, romh, 0xcb); + dd->dd_ebussup = bus_space_read_1(memt, romh, 0xcf); + dd->dd_altcodet= bus_space_read_1(memt, romh, 0xd3); + dd->dd_eddst[0]= bus_space_read_1(memt, romh, 0xd7); + dd->dd_eddst[1]= bus_space_read_1(memt, romh, 0xdb); + dd->dd_eddst[2]= bus_space_read_1(memt, romh, 0xdf); dd->dd_cfbaddr = parseword(0xe0) & ~3; - dd->dd_pacode[0x0] = parseword(0x100) & ~3; - dd->dd_pacode[0x1] = parseword(0x110) & ~3; - dd->dd_pacode[0x2] = parseword(0x120) & ~3; - dd->dd_pacode[0x3] = parseword(0x130) & ~3; - dd->dd_pacode[0x4] = parseword(0x140) & ~3; - dd->dd_pacode[0x5] = parseword(0x150) & ~3; - dd->dd_pacode[0x6] = parseword(0x160) & ~3; - dd->dd_pacode[0x7] = parseword(0x170) & ~3; - dd->dd_pacode[0x8] = parseword(0x180) & ~3; - dd->dd_pacode[0x9] = parseword(0x190) & ~3; - dd->dd_pacode[0xa] = parseword(0x1a0) & ~3; - dd->dd_pacode[0xb] = parseword(0x1b0) & ~3; - dd->dd_pacode[0xc] = parseword(0x1c0) & ~3; - dd->dd_pacode[0xd] = parseword(0x1d0) & ~3; - dd->dd_pacode[0xe] = parseword(0x1e0) & ~3; - dd->dd_pacode[0xf] = parseword(0x1f0) & ~3; - } else /* STI_DEVTYPE4 */ - bus_space_read_region_4(sc->memt, sc->romh, 0, (uint32_t *)dd, - sizeof(*dd) / 4); + codebase <<= 2; + dd->dd_pacode[0x0] = parseword(codebase + 0x00) & ~3; + dd->dd_pacode[0x1] = parseword(codebase + 0x10) & ~3; + dd->dd_pacode[0x2] = parseword(codebase + 0x20) & ~3; + dd->dd_pacode[0x3] = parseword(codebase + 0x30) & ~3; + dd->dd_pacode[0x4] = parseword(codebase + 0x40) & ~3; + dd->dd_pacode[0x5] = parseword(codebase + 0x50) & ~3; + dd->dd_pacode[0x6] = parseword(codebase + 0x60) & ~3; + dd->dd_pacode[0x7] = parseword(codebase + 0x70) & ~3; + dd->dd_pacode[0x8] = parseword(codebase + 0x80) & ~3; + dd->dd_pacode[0x9] = parseword(codebase + 0x90) & ~3; + dd->dd_pacode[0xa] = parseword(codebase + 0xa0) & ~3; + dd->dd_pacode[0xb] = parseword(codebase + 0xb0) & ~3; + dd->dd_pacode[0xc] = parseword(codebase + 0xc0) & ~3; + dd->dd_pacode[0xd] = parseword(codebase + 0xd0) & ~3; + dd->dd_pacode[0xe] = parseword(codebase + 0xe0) & ~3; + dd->dd_pacode[0xf] = parseword(codebase + 0xf0) & ~3; + } else { /* STI_DEVTYPE4 */ + bus_space_read_region_stream_4(memt, romh, 0, (uint32_t *)dd, + sizeof(*dd) ); + /* fix pacode... */ + bus_space_read_region_stream_4(memt, romh, codebase, + (uint32_t *)dd->dd_pacode, sizeof(dd->dd_pacode)); + } + + STI_DISABLE_ROM(rom->rom_softc); #ifdef STIDEBUG printf("dd:\n" @@ -209,184 +310,444 @@ sti_attach_common(struct sti_softc *sc) dd->dd_pacode[0xc], dd->dd_pacode[0xd], dd->dd_pacode[0xe], dd->dd_pacode[0xf]); #endif - /* divise code size, could be less than STI_END entries */ - for (i = STI_END; !dd->dd_pacode[i]; i--); + /* + * Figure out how many bytes we need for the STI code. + * Note there could be feer than STI_END pointer entries + * populated, especially on older devices. + */ + for (i = STI_END; !dd->dd_pacode[i]; i--) + ; + size = dd->dd_pacode[i] - dd->dd_pacode[STI_BEGIN]; - if (sc->sc_devtype == STI_DEVTYPE1) + if (rom->rom_devtype == STI_DEVTYPE1) size = (size + 3) / 4; - if (!(sc->sc_code = uvm_km_alloc(kernel_map, round_page(size), 0, + if (size == 0) { + aprint_error(": no code for the requested platform\n"); + return EINVAL; + } + + if (!(rom->rom_code = uvm_km_alloc(kernel_map, round_page(size), 0, UVM_KMF_WIRED))) { - printf(": cannot allocate %u bytes for code\n", size); - return; + aprint_error(": cannot allocate %u bytes for code\n", size); + return ENOMEM; } #ifdef STIDEBUG - printf("code=0x%x[%x]\n", (uint)sc->sc_code, size); + printf("code=0x%x[%x]\n", (uint)rom->rom_code, size); #endif - /* copy code into memory */ - if (sc->sc_devtype == STI_DEVTYPE1) { - p = (uint8_t *)sc->sc_code; + /* + * Copy code into memory and make it executable. + */ + + STI_ENABLE_ROM(rom->rom_softc); + + if (rom->rom_devtype == STI_DEVTYPE1) { + uint8_t *p = (uint8_t *)rom->rom_code; + uint32_t addr, eaddr; + for (addr = dd->dd_pacode[STI_BEGIN], eaddr = addr + size * 4; addr < eaddr; addr += 4 ) - *p++ = bus_space_read_4(sc->memt, sc->romh, addr) + *p++ = bus_space_read_1(memt, romh, addr) & 0xff; } else /* STI_DEVTYPE4 */ - bus_space_read_region_4(sc->memt, sc->romh, - dd->dd_pacode[STI_BEGIN], (uint32_t *)sc->sc_code, - size / 4); - -#define O(i) (dd->dd_pacode[(i)] ? (sc->sc_code + \ - (dd->dd_pacode[(i)] - dd->dd_pacode[0]) / \ - (sc->sc_devtype == STI_DEVTYPE1 ? 4 : 1)) : 0) - sc->init = (sti_init_t) O(STI_INIT_GRAPH); - sc->mgmt = (sti_mgmt_t) O(STI_STATE_MGMT); - sc->unpmv = (sti_unpmv_t) O(STI_FONT_UNPMV); - sc->blkmv = (sti_blkmv_t) O(STI_BLOCK_MOVE); - sc->test = (sti_test_t) O(STI_SELF_TEST); - sc->exhdl = (sti_exhdl_t) O(STI_EXCEP_HDLR); - sc->inqconf = (sti_inqconf_t)O(STI_INQ_CONF); - sc->scment = (sti_scment_t)O(STI_SCM_ENT); - sc->dmac = (sti_dmac_t) O(STI_DMA_CTRL); - sc->flowc = (sti_flowc_t) O(STI_FLOW_CTRL); - sc->utiming = (sti_utiming_t)O(STI_UTIMING); - sc->pmgr = (sti_pmgr_t) O(STI_PROC_MGR); - sc->util = (sti_util_t) O(STI_UTIL); - - if ((error = uvm_map_protect(kernel_map, sc->sc_code, - sc->sc_code + round_page(size), UVM_PROT_RX, FALSE))) { - printf(": uvm_map_protect failed (%d)\n", error); - uvm_km_free(kernel_map, sc->sc_code, round_page(size), + bus_space_read_region_stream_4(memt, romh, + dd->dd_pacode[STI_BEGIN], (uint32_t *)rom->rom_code, + size); + + STI_DISABLE_ROM(rom->rom_softc); + + if ((error = uvm_map_protect(kernel_map, rom->rom_code, + rom->rom_code + round_page(size), UVM_PROT_RX, FALSE))) { + aprint_error(": uvm_map_protect failed (%d)\n", error); + uvm_km_free(kernel_map, rom->rom_code, round_page(size), UVM_KMF_WIRED); - return; + return error; } - cc = &sc->sc_cfg; - memset(cc, 0, sizeof (*cc)); - i = dd->dd_reglst; -#ifdef STIDEBUG - printf("stiregions @%d:\n", i); -#endif - r.last = 0; - for (q = cc->regions; !r.last && - q < &cc->regions[STI_REGION_MAX]; q++) { + /* + * Setup code function pointers. + */ - if (sc->sc_devtype == STI_DEVTYPE1) - tmp = parseword(i), i += 16; - else - tmp = bus_space_read_4(sc->memt, sc->romh, i), i += 4; - memcpy(&r, &tmp, sizeof (r)); +#define O(i) \ + (dd->dd_pacode[(i)] == 0 ? 0 : \ + (rom->rom_code + (dd->dd_pacode[(i)] - dd->dd_pacode[0]) / \ + (rom->rom_devtype == STI_DEVTYPE1 ? 4 : 1))) + rom->init = (sti_init_t) O(STI_INIT_GRAPH); + rom->mgmt = (sti_mgmt_t) O(STI_STATE_MGMT); + rom->unpmv = (sti_unpmv_t) O(STI_FONT_UNPMV); + rom->blkmv = (sti_blkmv_t) O(STI_BLOCK_MOVE); + rom->test = (sti_test_t) O(STI_SELF_TEST); + rom->exhdl = (sti_exhdl_t) O(STI_EXCEP_HDLR); + rom->inqconf = (sti_inqconf_t)O(STI_INQ_CONF); + rom->scment = (sti_scment_t)O(STI_SCM_ENT); + rom->dmac = (sti_dmac_t) O(STI_DMA_CTRL); + rom->flowc = (sti_flowc_t) O(STI_FLOW_CTRL); + rom->utiming = (sti_utiming_t)O(STI_UTIMING); + rom->pmgr = (sti_pmgr_t) O(STI_PROC_MGR); + rom->util = (sti_util_t) O(STI_UTIL); + +#undef O + /* + * Set colormap entry is not implemented until 8.04, so force + * a NULL pointer here. + */ + + if (dd->dd_grrev < STI_REVISION(8,4)) { + rom->scment = NULL; + } + + return 0; +} + +/* + * Map all regions. + */ +void +sti_region_setup(struct sti_screen *scr) +{ + struct sti_rom *rom = scr->scr_rom; + bus_space_tag_t memt = rom->memt; + bus_space_handle_t romh = rom->romh; + bus_addr_t *bases = rom->bases; + struct sti_dd *dd = &rom->rom_dd; + struct sti_cfg *cc = &scr->scr_cfg; + bus_space_handle_t bh; + struct sti_region regions[STI_REGION_MAX], *r; + u_int regno, regcnt; + bus_addr_t addr; - *q = (q == cc->regions ? sc->romh : sc->base) + - (r.offset << PGSHIFT); #ifdef STIDEBUG - printf("%x @ 0x%x%s%s%s%s\n", - r.length << PGSHIFT, *q, r.sys_only ? " sys" : "", - r.cache ? " cache" : "", r.btlb ? " btlb" : "", - r.last ? " last" : ""); + printf("stiregions @ %x:\n", dd->dd_reglst); #endif - /* rom has already been mapped */ - if (q != cc->regions) { - if (bus_space_map(sc->memt, *q, - r.length << PGSHIFT, 0, &fbh)) { + /* + * Read the region information. + */ + + STI_ENABLE_ROM(rom->rom_softc); + + if (rom->rom_devtype == STI_DEVTYPE1) { + for (regno = 0; regno < STI_REGION_MAX; regno++) + *(u_int *)(regions + regno) = + parseword(dd->dd_reglst + regno * 0x10); + } else { + bus_space_read_region_stream_4(memt, romh, dd->dd_reglst, + (uint32_t *)regions, sizeof(regions)); + } + + STI_DISABLE_ROM(rom->rom_softc); + + /* + * Count them. + */ + + for (regcnt = 0, r = regions; regcnt < STI_REGION_MAX; regcnt++, r++) + if (r->last) + break; + regcnt++; + + /* + * Map them. + */ + + for (regno = 0, r = regions; regno < regcnt; regno++, r++) { + if (r->length == 0) + continue; + + /* + * Assume an existing mapping exists. + */ + addr = bases[regno] + (r->offset << PGSHIFT); + #ifdef STIDEBUG - printf("already mapped region\n"); + printf("%08x @ 0x%08x%s%s%s%s", + r->length << PGSHIFT, (int)addr, r->sys_only ? " sys" : "", + r->cache ? " cache" : "", r->btlb ? " btlb" : "", + r->last ? " last" : ""); #endif - } else { - if (q - cc->regions == 1) { - sc->fbaddr = *q; - sc->fblen = r.length << PGSHIFT; - } - *q = fbh; + + /* + * Region #0 is always the rom, and it should have been + * mapped already. + * XXX This expects a 1:1 mapping... + */ + if (regno == 0 && romh == bases[0]) { + cc->regions[0] = addr; + continue; + } + +/* XXXNH BUS_SPACE_MAP_CACHEABLE */ + if (bus_space_map(memt, addr, r->length << PGSHIFT, + r->cache ? BUS_SPACE_MAP_CACHEABLE : 0, &bh)) { +#ifdef STIDEBUG + printf(" - already mapped region\n"); +#endif + } else { +#ifdef STIDEBUG + printf("\n"); +#endif + /* XXX should use bus_space_vaddr */ + addr = (bus_addr_t)bh; + if (regno == 1) { + scr->fbaddr = addr; + scr->fblen = r->length << PGSHIFT; } } + + cc->regions[regno] = addr; } - if ((error = sti_init(sc, 0))) { - printf(": can not initialize (%d)\n", error); - return; +#ifdef STIDEBUG + /* + * Make sure we'll trap accessing unmapped regions + */ + for (regno = 0; regno < STI_REGION_MAX; regno++) + if (cc->regions[regno] == 0) + cc->regions[regno] = 0x81234567; +#endif +} + +int +sti_screen_setup(struct sti_screen *scr, int flags) +{ + struct sti_rom *rom = scr->scr_rom; + bus_space_tag_t memt = rom->memt; + bus_space_handle_t romh = rom->romh; + struct sti_dd *dd = &rom->rom_dd; + struct sti_cfg *cc = &scr->scr_cfg; + struct sti_inqconfout cfg; + struct sti_einqconfout ecfg; + int error, i; + int geometry_kluge = 0; + u_int fontindex = 0; + + cc->ext_cfg = &scr->scr_ecfg; + memset(cc->ext_cfg, 0, sizeof(*cc->ext_cfg)); + + if (dd->dd_stimemreq) { + scr->scr_ecfg.addr = + malloc(dd->dd_stimemreq, M_DEVBUF, M_NOWAIT); + if (!scr->scr_ecfg.addr) { + aprint_error("cannot allocate %d bytes for STI\n", + dd->dd_stimemreq); + return ENOMEM; + } + } + + sti_region_setup(scr); + + if ((error = sti_init(scr, 0))) { + aprint_error(": can not initialize (%d)\n", error); + goto fail; } memset(&cfg, 0, sizeof(cfg)); memset(&ecfg, 0, sizeof(ecfg)); cfg.ext = &ecfg; - if ((error = sti_inqcfg(sc, &cfg))) { + if ((error = sti_inqcfg(scr, &cfg))) { printf(": error %d inquiring config\n", error); - return; + goto fail; } - if ((error = sti_init(sc, STI_TEXTMODE))) { - printf(": can not initialize (%d)\n", error); - return; + /* + * Older (rev 8.02) boards report wrong offset values, + * similar to the displayable area size, at least in m68k mode. + * Attempt to detect this and adjust here. + */ + if (cfg.owidth == cfg.width && + cfg.oheight == cfg.height) + geometry_kluge = 1; + + if (geometry_kluge) { + scr->scr_cfg.oscr_width = cfg.owidth = + cfg.fbwidth - cfg.width; + scr->scr_cfg.oscr_height = cfg.oheight = + cfg.fbheight - cfg.height; } + /* + * Save a few fields for sti_describe_screen() later + */ + scr->fbheight = cfg.fbheight; + scr->fbwidth = cfg.fbwidth; + scr->oheight = cfg.oheight; + scr->owidth = cfg.owidth; + memcpy(scr->name, cfg.name, sizeof(scr->name)); + + if ((error = sti_init(scr, STI_TEXTMODE | flags))) { + aprint_error(": can not initialize (%d)\n", error); + goto fail; + } +#if 0 +XXXNH STI_INQCONF_BITS +#endif #ifdef STIDEBUG - printf("conf: bpp=%d planes=%d attr=%d\n" - "crt=0x%x:0x%x:0x%x hw=0x%x:0x%x:0x%x\n", - cfg.bpp, cfg.planes, cfg.attributes, + printf("conf: bpp=%d planes=%d attr=%x\n" + "crt=0x%x:0x%x:0x%x hw=0x%x:0x%x:0x%x\n", cfg.bpp, + cfg.planes, cfg.attributes, ecfg.crt_config[0], ecfg.crt_config[1], ecfg.crt_config[2], ecfg.crt_hw[0], ecfg.crt_hw[1], ecfg.crt_hw[2]); #endif - sc->sc_wsmode = WSDISPLAYIO_MODE_EMUL; - sc->sc_bpp = cfg.bppu; - printf(": %s rev %d.%02d;%d, ID 0x%016llX\n" - "%s: %dx%d frame buffer, %dx%dx%d display, offset %dx%d\n", - cfg.name, dd->dd_grrev >> 4, dd->dd_grrev & 0xf, dd->dd_lrrev, - *(uint64_t *)dd->dd_grid, device_xname(sc->sc_dev), cfg.fbwidth, - cfg.fbheight, cfg.width, cfg.height, cfg.bppu, cfg.owidth, - cfg.oheight); - - if ((error = sti_fetchfonts(sc, &cfg, dd->dd_fntaddr))) { - aprint_error_dev(sc->sc_dev, "cannot fetch fonts (%d)\n", - error); - return; + scr->scr_bpp = cfg.bppu; + + /* + * Although scr->scr_ecfg.current_monitor is not filled by + * sti_init() as expected, we can nevertheless walk the monitor + * list, if there is any, and if we find a mode matching our + * resolution, pick its font index. + */ + if (dd->dd_montbl != 0) { + STI_ENABLE_ROM(rom->rom_softc); + + for (i = 0; i < dd->dd_nmon; i++) { + u_int offs = dd->dd_montbl + 8 * i; + uint32_t m[2]; + sti_mon_t mon = (void *)m; + if (rom->rom_devtype == STI_DEVTYPE1) { + m[0] = parseword(4 * offs); + m[1] = parseword(4 * (offs + 4)); + } else { + bus_space_read_region_stream_4(memt, romh, offs, + (uint32_t *)mon, sizeof(*mon)); + } + + if (mon->width == scr->scr_cfg.scr_width && + mon->height == scr->scr_cfg.scr_height) { + fontindex = mon->font; + break; + } + } + + STI_DISABLE_ROM(rom->rom_softc); + +#ifdef STIDEBUG + printf("font index: %d\n", fontindex); +#endif + } + + if ((error = sti_fetchfonts(scr, &cfg, dd->dd_fntaddr, fontindex))) { + aprint_error(": cannot fetch fonts (%d)\n", error); + goto fail; } /* - * parse screen descriptions: + * setup screen descriptions: * figure number of fonts supported; * allocate wscons structures; * calculate dimensions. */ - sti_default_screen.ncols = cfg.width / sc->sc_curfont.width; - sti_default_screen.nrows = cfg.height / sc->sc_curfont.height; - sti_default_screen.fontwidth = sc->sc_curfont.width; - sti_default_screen.fontheight = sc->sc_curfont.height; - -#if NWSDISPLAY > 0 - config_interrupts(sc->sc_dev, sti_attach_deferred); +#if 0 + strlcpy(scr->scr_wsd.name, "std", sizeof(scr->scr_wsd.name)); #endif + scr->scr_wsd.ncols = cfg.width / scr->scr_curfont.width; + scr->scr_wsd.nrows = cfg.height / scr->scr_curfont.height; + scr->scr_wsd.textops = &sti_emulops; + scr->scr_wsd.fontwidth = scr->scr_curfont.width; + scr->scr_wsd.fontheight = scr->scr_curfont.height; + scr->scr_wsd.capabilities = 0; + + scr->scr_scrlist[0] = &scr->scr_wsd; + scr->scr_screenlist.nscreens = 1; + scr->scr_screenlist.screens = + (const struct wsscreen_descr **)scr->scr_scrlist; + + return 0; + +fail: + /* XXX free resources */ + if (scr->scr_ecfg.addr != NULL) { + free(scr->scr_ecfg.addr, M_DEVBUF); + scr->scr_ecfg.addr = NULL; + } + + return ENXIO; +} + +void +sti_describe_screen(struct sti_softc *sc, struct sti_screen *scr) +{ + struct sti_font *fp = &scr->scr_curfont; + printf("%s: %s, %dx%d frame buffer, %dx%dx%d display\n", + device_xname(sc->sc_dev), scr->name, scr->fbwidth, scr->fbheight, + scr->scr_cfg.scr_width, scr->scr_cfg.scr_height, scr->scr_bpp); + + printf("%s: %dx%d font type %d, %d bpc, charset %d-%d\n", + device_xname(sc->sc_dev), fp->width, fp->height, + fp->type, fp->bpc, fp->first, fp->last); } void -sti_attach_deferred(device_t dev) +sti_describe(struct sti_softc *sc) { - struct sti_softc *sc = device_private(dev); + struct sti_rom *rom = sc->sc_rom; + struct sti_dd *dd = &rom->rom_dd; + + printf(": rev %d.%02d;%d, ID 0x%08X%08X\n", + dd->dd_grrev >> 4, dd->dd_grrev & 0xf, + dd->dd_lrrev, dd->dd_grid[0], dd->dd_grid[1]); + + if (sc->sc_scr != NULL) + sti_describe_screen(sc, sc->sc_scr); +} + +void +sti_end_attach(struct sti_softc *sc) +{ + struct sti_screen *scr = sc->sc_scr; struct wsemuldisplaydev_attach_args waa; - long defattr; + + if (scr == NULL) + return; + + scr->scr_wsmode = WSDISPLAYIO_MODE_EMUL; waa.console = sc->sc_flags & STI_CONSOLE ? 1 : 0; - waa.scrdata = &sti_default_screenlist; + waa.scrdata = &scr->scr_screenlist; waa.accessops = &sti_accessops; - waa.accesscookie = sc; + waa.accesscookie = scr; /* attach as console if required */ - if (waa.console) { - sti_alloc_attr(sc, 0, 0, 0, &defattr); - wsdisplay_cnattach(&sti_default_screen, sc, - 0, sti_default_screen.nrows - 1, defattr); + if (waa.console && !ISSET(sc->sc_flags, STI_ATTACHED)) { + long defattr; + + sti_alloc_attr(scr, 0, 0, 0, &defattr); + wsdisplay_cnattach(&scr->scr_wsd, scr, + 0, scr->scr_wsd.nrows - 1, defattr); + sc->sc_flags |= STI_ATTACHED; } config_found(sc->sc_dev, &waa, wsemuldisplaydevprint); } +u_int +sti_rom_size(bus_space_tag_t memt, bus_space_handle_t romh) +{ + int devtype; + u_int romend; + + devtype = bus_space_read_1(memt, romh, 3); + if (devtype == STI_DEVTYPE4) { + bus_space_read_region_stream_4(memt, romh, 0x18, + (uint32_t *)&romend, 1); + } else { + romend = parseword(0x50); + } + + return (round_page(romend)); +} + int -sti_fetchfonts(struct sti_softc *sc, struct sti_inqconfout *cfg, uint32_t addr) +sti_fetchfonts(struct sti_screen *scr, struct sti_inqconfout *cfg, + uint32_t baseaddr, u_int fontindex) { - struct sti_font *fp = &sc->sc_curfont; + struct sti_rom *rom = scr->scr_rom; + bus_space_tag_t memt = rom->memt; + bus_space_handle_t romh = rom->romh; + struct sti_font *fp = &scr->scr_curfont; + uint32_t addr; int size; #ifdef notyet int uc; @@ -400,44 +761,69 @@ sti_fetchfonts(struct sti_softc *sc, str /* * Get the first PROM font in memory */ + + STI_ENABLE_ROM(rom->rom_softc); + +rescan: + addr = baseaddr; do { - if (sc->sc_devtype == STI_DEVTYPE1) { + if (rom->rom_devtype == STI_DEVTYPE1) { fp->first = parseshort(addr + 0x00); fp->last = parseshort(addr + 0x08); - fp->width = bus_space_read_1(sc->memt, sc->romh, + fp->width = bus_space_read_1(memt, romh, addr + 0x13); - fp->height = bus_space_read_1(sc->memt, sc->romh, + fp->height = bus_space_read_1(memt, romh, addr + 0x17); - fp->type = bus_space_read_1(sc->memt, sc->romh, + fp->type = bus_space_read_1(memt, romh, addr + 0x1b); - fp->bpc = bus_space_read_1(sc->memt, sc->romh, + fp->bpc = bus_space_read_1(memt, romh, addr + 0x1f); - fp->next = parseword(addr + 0x23); - fp->uheight= bus_space_read_1(sc->memt, sc->romh, + fp->next = parseword(addr + 0x20); + fp->uheight= bus_space_read_1(memt, romh, addr + 0x33); - fp->uoffset= bus_space_read_1(sc->memt, sc->romh, + fp->uoffset= bus_space_read_1(memt, romh, addr + 0x37); - } else /* STI_DEVTYPE4 */ - bus_space_read_region_4(sc->memt, sc->romh, addr, - (uint32_t *)fp, sizeof(struct sti_font) / 4); + } else { /* STI_DEVTYPE4 */ + bus_space_read_region_stream_4(memt, romh, addr, + (uint32_t *)fp, sizeof(struct sti_font)); + } +#ifdef STIDEBUG + STI_DISABLE_ROM(rom->rom_softc); printf("%s: %dx%d font type %d, %d bpc, charset %d-%d\n", - device_xname(sc->sc_dev), fp->width, fp->height, fp->type, + device_xname(scr->scr_rom->rom_softc->sc_dev), fp->width, fp->height, fp->type, fp->bpc, fp->first, fp->last); + STI_ENABLE_ROM(rom->rom_softc); +#endif + + if (fontindex == 0) { + size = sizeof(struct sti_font) + + (fp->last - fp->first + 1) * fp->bpc; + if (rom->rom_devtype == STI_DEVTYPE1) + size *= 4; + scr->scr_romfont = malloc(size, M_DEVBUF, M_NOWAIT); + if (scr->scr_romfont == NULL) + return ENOMEM; - size = sizeof(struct sti_font) + - (fp->last - fp->first + 1) * fp->bpc; - if (sc->sc_devtype == STI_DEVTYPE1) - size *= 4; - sc->sc_romfont = malloc(size, M_DEVBUF, M_NOWAIT); - if (sc->sc_romfont == NULL) - return (ENOMEM); + bus_space_read_region_stream_4(memt, romh, addr, + (uint32_t *)scr->scr_romfont, size); + break; + } - bus_space_read_region_4(sc->memt, sc->romh, addr, - (uint32_t *)sc->sc_romfont, size / 4); + addr = baseaddr + fp->next; + fontindex--; + } while (fp->next != 0); - addr = 0; /* fp->next */ - } while (addr); + /* + * If our font index was bogus, we did not find the expected font. + * In this case, pick the first one and be done with it. + */ + if (fp->next == 0 && scr->scr_romfont == NULL) { + fontindex = 0; + goto rescan; + } + + STI_DISABLE_ROM(rom->rom_softc); #ifdef notyet /* @@ -451,39 +837,44 @@ sti_fetchfonts(struct sti_softc *sc, str a.flags.flags = STI_UNPMVF_WAIT; a.in.fg_colour = STI_COLOUR_WHITE; a.in.bg_colour = STI_COLOUR_BLACK; - a.in.font_addr = sc->sc_romfont; + a.in.font_addr = scr->scr_romfont; - sc->sc_fontmaxcol = cfg->fbheight / fp->height; - sc->sc_fontbase = cfg->width + cfg->owidth; + scr->scr_fontmaxcol = cfg->fbheight / fp->height; + scr->scr_fontbase = cfg->width + cfg->owidth; for (uc = fp->first; uc <= fp->last; uc++) { - a.in.x = ((uc - fp->first) / sc->sc_fontmaxcol) * - fp->width + sc->sc_fontbase; - a.in.y = ((uc - fp->first) % sc->sc_fontmaxcol) * + a.in.x = ((uc - fp->first) / scr->scr_fontmaxcol) * + fp->width + scr->scr_fontbase; + a.in.y = ((uc - fp->first) % scr->scr_fontmaxcol) * fp->height; a.in.index = uc; - (*sc->unpmv)(&a.flags, &a.in, &a.out, &sc->sc_cfg); + (*scr->unpmv)(&a.flags, &a.in, &a.out, &scr->scr_cfg); if (a.out.errno) { aprint_error_dev(sc->sc_dev, "unpmv %d returned %d\n", uc, a.out.errno); - return (0); + return 0; } } - free(sc->sc_romfont, M_DEVBUF); - sc->sc_romfont = NULL; + free(scr->scr_romfont, M_DEVBUF); + scr->scr_romfont = NULL; } #endif - return (0); + return 0; } +/* + * Wrappers around STI code pointers + */ int -sti_init(struct sti_softc *sc, int mode) +sti_init(struct sti_screen *scr, int mode) { + struct sti_rom *rom = scr->scr_rom; struct { struct sti_initflags flags; struct sti_initin in; + struct sti_einitin ein; struct sti_initout out; } a; @@ -491,19 +882,24 @@ sti_init(struct sti_softc *sc, int mode) a.flags.flags = STI_INITF_WAIT | STI_INITF_CMB | STI_INITF_EBET | (mode & STI_TEXTMODE ? STI_INITF_TEXT | STI_INITF_PBET | - STI_INITF_PBETI | STI_INITF_ICMT : 0); + STI_INITF_PBETI | STI_INITF_ICMT : 0) | + (mode & STI_CLEARSCR ? STI_INITF_CLEAR : 0); a.in.text_planes = 1; + a.in.ext_in = &a.ein; #ifdef STIDEBUG - printf("%s: init,%p(%x, %p, %p, %p)\n", device_xname(sc->sc_dev), - sc->init, a.flags.flags, &a.in, &a.out, &sc->sc_cfg); + printf("%s: init,%p(%x, %p, %p, %p)\n", device_xname(rom->rom_softc->sc_dev), + rom->init, a.flags.flags, &a.in, &a.out, &scr->scr_cfg); #endif - (*sc->init)(&a.flags, &a.in, &a.out, &sc->sc_cfg); - return (a.out.text_planes != a.in.text_planes || a.out.errno); + (*rom->init)(&a.flags, &a.in, &a.out, &scr->scr_cfg); + if (a.out.text_planes != a.in.text_planes) + return -1; /* not colliding with sti errno values */ + return a.out.errno; } int -sti_inqcfg(struct sti_softc *sc, struct sti_inqconfout *out) +sti_inqcfg(struct sti_screen *scr, struct sti_inqconfout *out) { + struct sti_rom *rom = scr->scr_rom; struct { struct sti_inqconfflags flags; struct sti_inqconfin in; @@ -512,15 +908,16 @@ sti_inqcfg(struct sti_softc *sc, struct memset(&a, 0, sizeof(a)); a.flags.flags = STI_INQCONFF_WAIT; - (*sc->inqconf)(&a.flags, &a.in, out, &sc->sc_cfg); + (*rom->inqconf)(&a.flags, &a.in, out, &scr->scr_cfg); return out->errno; } void -sti_bmove(struct sti_softc *sc, int x1, int y1, int x2, int y2, int h, int w, +sti_bmove(struct sti_screen *scr, int x1, int y1, int x2, int y2, int h, int w, enum sti_bmove_funcs f) { + struct sti_rom *rom = scr->scr_rom; struct { struct sti_blkmvflags flags; struct sti_blkmvin in; @@ -553,17 +950,18 @@ sti_bmove(struct sti_softc *sc, int x1, a.in.height = h; a.in.width = w; - (*sc->blkmv)(&a.flags, &a.in, &a.out, &sc->sc_cfg); + (*rom->blkmv)(&a.flags, &a.in, &a.out, &scr->scr_cfg); #ifdef STIDEBUG if (a.out.errno) - aprint_error_dev(sc->sc_dev, "blkmv returned %d\n", + aprint_error_dev(rom->rom_softc->sc_dev, "blkmv returned %d\n", a.out.errno); #endif } int -sti_setcment(struct sti_softc *sc, u_int i, u_char r, u_char g, u_char b) +sti_setcment(struct sti_screen *scr, u_int i, u_char r, u_char g, u_char b) { + struct sti_rom *rom = scr->scr_rom; struct { struct sti_scmentflags flags; struct sti_scmentin in; @@ -576,35 +974,39 @@ sti_setcment(struct sti_softc *sc, u_int a.in.entry = i; a.in.value = (r << 16) | (g << 8) | b; - (*sc->scment)(&a.flags, &a.in, &a.out, &sc->sc_cfg); + (*rom->scment)(&a.flags, &a.in, &a.out, &scr->scr_cfg); return a.out.errno; } +/* + * wsdisplay accessops + */ int sti_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l) { - struct sti_softc *sc = v; + struct sti_screen *scr = (struct sti_screen *)v; + struct sti_rom *rom = scr->scr_rom; struct wsdisplay_fbinfo *wdf; struct wsdisplay_cmap *cmapp; u_int mode, idx, count; int i, ret; - +Debugger(); ret = 0; switch (cmd) { case WSDISPLAYIO_GMODE: - *(u_int *)data = sc->sc_wsmode; + *(u_int *)data = scr->scr_wsmode; break; case WSDISPLAYIO_SMODE: mode = *(u_int *)data; - if (sc->sc_wsmode == WSDISPLAYIO_MODE_EMUL && + if (scr->scr_wsmode == WSDISPLAYIO_MODE_EMUL && mode == WSDISPLAYIO_MODE_DUMBFB) - ret = sti_init(sc, 0); - else if (sc->sc_wsmode == WSDISPLAYIO_MODE_DUMBFB && + ret = sti_init(scr, 0); + else if (scr->scr_wsmode == WSDISPLAYIO_MODE_DUMBFB && mode == WSDISPLAYIO_MODE_EMUL) - ret = sti_init(sc, STI_TEXTMODE); - sc->sc_wsmode = mode; + ret = sti_init(scr, STI_TEXTMODE); + scr->scr_wsmode = mode; break; case WSDISPLAYIO_GTYPE: @@ -613,55 +1015,59 @@ sti_ioctl(void *v, void *vs, u_long cmd, case WSDISPLAYIO_GINFO: wdf = (struct wsdisplay_fbinfo *)data; - wdf->height = sc->sc_cfg.scr_height; - wdf->width = sc->sc_cfg.scr_width; - wdf->depth = sc->sc_bpp; + wdf->height = scr->scr_cfg.scr_height; + wdf->width = scr->scr_cfg.scr_width; + wdf->depth = scr->scr_bpp; wdf->cmsize = STI_NCMAP; + if (rom->scment == NULL) + wdf->cmsize = 0; + else + wdf->cmsize = STI_NCMAP; break; case WSDISPLAYIO_LINEBYTES: - *(u_int *)data = sc->sc_cfg.fb_width; + *(u_int *)data = scr->scr_cfg.fb_width; break; case WSDISPLAYIO_GETCMAP: - if (sc->scment == NULL) + if (rom->scment == NULL) return ENOTTY; cmapp = (struct wsdisplay_cmap *)data; idx = cmapp->index; count = cmapp->count; - if (idx > STI_NCMAP || idx + count >= STI_NCMAP) + if (idx >= STI_NCMAP || idx + count > STI_NCMAP) return EINVAL; - if ((ret = copyout(&sc->sc_rcmap[idx], cmapp->red, count))) + if ((ret = copyout(&scr->scr_rcmap[idx], cmapp->red, count))) break; - if ((ret = copyout(&sc->sc_gcmap[idx], cmapp->green, count))) + if ((ret = copyout(&scr->scr_gcmap[idx], cmapp->green, count))) break; - if ((ret = copyout(&sc->sc_bcmap[idx], cmapp->blue, count))) + if ((ret = copyout(&scr->scr_bcmap[idx], cmapp->blue, count))) break; break; case WSDISPLAYIO_PUTCMAP: - if (sc->scment == NULL) + if (rom->scment == NULL) return ENOTTY; cmapp = (struct wsdisplay_cmap *)data; idx = cmapp->index; count = cmapp->count; - if (idx > STI_NCMAP || idx + count >= STI_NCMAP) + if (idx >= STI_NCMAP || idx + count > STI_NCMAP) return EINVAL; - if ((ret = copyin(cmapp->red, &sc->sc_rcmap[idx], count))) + if ((ret = copyin(cmapp->red, &scr->scr_rcmap[idx], count))) break; - if ((ret = copyin(cmapp->green, &sc->sc_gcmap[idx], count))) + if ((ret = copyin(cmapp->green, &scr->scr_gcmap[idx], count))) break; - if ((ret = copyin(cmapp->blue, &sc->sc_bcmap[idx], count))) + if ((ret = copyin(cmapp->blue, &scr->scr_bcmap[idx], count))) break; for (i = idx + count - 1; i >= idx; i--) - if ((ret = sti_setcment(sc, i, sc->sc_rcmap[i], - sc->sc_gcmap[i], sc->sc_bcmap[i]))) { + if ((ret = sti_setcment(scr, i, scr->scr_rcmap[i], + scr->scr_gcmap[i], scr->scr_bcmap[i]))) { #ifdef STIDEBUG printf("sti_ioctl: " "sti_setcment(%d, %u, %u, %u): %%d\n", i, - (u_int)sc->sc_rcmap[i], - (u_int)sc->sc_gcmap[i], - (u_int)sc->sc_bcmap[i]); + (u_int)scr->scr_rcmap[i], + (u_int)scr->scr_gcmap[i], + (u_int)scr->scr_bcmap[i]); #endif ret = EINVAL; break; @@ -676,15 +1082,18 @@ sti_ioctl(void *v, void *vs, u_long cmd, case WSDISPLAYIO_GCURSOR: case WSDISPLAYIO_SCURSOR: default: - return (ENOTTY); /* not supported yet */ + return ENOTTY; /* not supported yet */ } - return (ret); + return ret; } paddr_t sti_mmap(void *v, void *vs, off_t offset, int prot) { +#if 0 + struct sti_screen *scr = (struct sti_screen *)v; +#endif /* XXX not finished */ return -1; } @@ -693,65 +1102,125 @@ int sti_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep, int *cxp, int *cyp, long *defattr) { - struct sti_softc *sc = v; + struct sti_screen *scr = (struct sti_screen *)v; - if (sc->sc_nscreens > 0) + if (scr->scr_nscreens > 0) return ENOMEM; - *cookiep = sc; + *cookiep = scr; *cxp = 0; *cyp = 0; - sti_alloc_attr(sc, 0, 0, 0, defattr); - sc->sc_nscreens++; + sti_alloc_attr(scr, 0, 0, 0, defattr); + scr->scr_nscreens++; + return 0; } void sti_free_screen(void *v, void *cookie) { - struct sti_softc *sc = v; + struct sti_screen *scr = (struct sti_screen *)v; - sc->sc_nscreens--; + scr->scr_nscreens--; } int sti_show_screen(void *v, void *cookie, int waitok, void (*cb)(void *, int, int), void *cbarg) { +#if 0 + struct sti_screen *scr = (struct sti_screen *)v; +#endif + return 0; } int sti_load_font(void *v, void *cookie, struct wsdisplay_font *font) { +#if 0 + struct sti_screen *scr = (struct sti_screen *)v; +#endif + return -1; } +/* + * wsdisplay emulops + */ void sti_cursor(void *v, int on, int row, int col) { - struct sti_softc *sc = v; - struct sti_font *fp = &sc->sc_curfont; + struct sti_screen *scr = (struct sti_screen *)v; + struct sti_font *fp = &scr->scr_curfont; - sti_bmove(sc, col * fp->width, row * fp->height, col * fp->width, + sti_bmove(scr, col * fp->width, row * fp->height, col * fp->width, row * fp->height, fp->height, fp->width, bmf_invert); } +/* + * ISO 8859-1 part of Unicode to HP Roman font index conversion array. + */ +static const uint8_t +sti_unitoroman[0x100 - 0xa0] = { + 0xa0, 0xb8, 0xbf, 0xbb, 0xba, 0xbc, 0, 0xbd, + 0xab, 0, 0xf9, 0xfb, 0, 0xf6, 0, 0xb0, + + 0xb3, 0xfe, 0, 0, 0xa8, 0xf3, 0xf4, 0xf2, + 0, 0, 0xfa, 0xfd, 0xf7, 0xf8, 0, 0xb9, + + 0xa1, 0xe0, 0xa2, 0xe1, 0xd8, 0xd0, 0xd3, 0xb4, + 0xa3, 0xdc, 0xa4, 0xa5, 0xe6, 0xe5, 0xa6, 0xa7, + + 0xe3, 0xb6, 0xe8, 0xe7, 0xdf, 0xe9, 0xda, 0, + 0xd2, 0xad, 0xed, 0xae, 0xdb, 0xb1, 0xf0, 0xde, + + 0xc8, 0xc4, 0xc0, 0xe2, 0xcc, 0xd4, 0xd7, 0xb5, + 0xc9, 0xc5, 0xc1, 0xcd, 0xd9, 0xd5, 0xd1, 0xdd, + + 0xe4, 0xb7, 0xca, 0xc6, 0xc2, 0xea, 0xce, 0, + 0xd6, 0xcb, 0xc7, 0xc3, 0xcf, 0xb2, 0xf1, 0xef +}; + int sti_mapchar(void *v, int uni, u_int *index) { - if (uni < 256) - *index = uni; + struct sti_screen *scr = (struct sti_screen *)v; + struct sti_font *fp = &scr->scr_curfont; + int c; + + switch (fp->type) { + case STI_FONT_HPROMAN8: + if (uni >= 0x80 && uni < 0xa0) + c = -1; + else if (uni >= 0xa0 && uni < 0x100) { + c = (int)sti_unitoroman[uni - 0xa0]; + if (c == 0) + c = -1; + } else + c = uni; + break; + default: + c = uni; + break; + } + + if (c == -1 || c < fp->first || c > fp->last) { + *index = ' '; + return 0; + } - return 1; + *index = c; + return 5; } void sti_putchar(void *v, int row, int col, u_int uc, long attr) { - struct sti_softc *sc = v; - struct sti_font *fp = &sc->sc_curfont; + struct sti_screen *scr = (struct sti_screen *)v; + struct sti_rom *rom = scr->scr_rom; + struct sti_font *fp = &scr->scr_curfont; - if (sc->sc_romfont != NULL) { + if (scr->scr_romfont != NULL) { /* * Font is in memory, use unpmv */ @@ -769,10 +1238,10 @@ sti_putchar(void *v, int row, int col, u a.in.bg_colour = STI_COLOUR_BLACK; a.in.x = col * fp->width; a.in.y = row * fp->height; - a.in.font_addr = sc->sc_romfont; + a.in.font_addr = scr->scr_romfont; a.in.index = uc; - (*sc->unpmv)(&a.flags, &a.in, &a.out, &sc->sc_cfg); + (*rom->unpmv)(&a.flags, &a.in, &a.out, &scr->scr_cfg); } else { /* * Font is in frame buffer, use blkmv @@ -790,36 +1259,36 @@ sti_putchar(void *v, int row, int col, u a.in.fg_colour = STI_COLOUR_WHITE; a.in.bg_colour = STI_COLOUR_BLACK; - a.in.srcx = ((uc - fp->first) / sc->sc_fontmaxcol) * - fp->width + sc->sc_fontbase; - a.in.srcy = ((uc - fp->first) % sc->sc_fontmaxcol) * + a.in.srcx = ((uc - fp->first) / scr->scr_fontmaxcol) * + fp->width + scr->scr_fontbase; + a.in.srcy = ((uc - fp->first) % scr->scr_fontmaxcol) * fp->height; a.in.dstx = col * fp->width; a.in.dsty = row * fp->height; a.in.height = fp->height; a.in.width = fp->width; - (*sc->blkmv)(&a.flags, &a.in, &a.out, &sc->sc_cfg); + (*rom->blkmv)(&a.flags, &a.in, &a.out, &scr->scr_cfg); } } void sti_copycols(void *v, int row, int srccol, int dstcol, int ncols) { - struct sti_softc *sc = v; - struct sti_font *fp = &sc->sc_curfont; + struct sti_screen *scr = (struct sti_screen *)v; + struct sti_font *fp = &scr->scr_curfont; - sti_bmove(sc, srccol * fp->width, row * fp->height, dstcol * fp->width, + sti_bmove(scr, srccol * fp->width, row * fp->height, dstcol * fp->width, row * fp->height, fp->height, ncols * fp->width, bmf_copy); } void sti_erasecols(void *v, int row, int startcol, int ncols, long attr) { - struct sti_softc *sc = v; - struct sti_font *fp = &sc->sc_curfont; + struct sti_screen *scr = (struct sti_screen *)v; + struct sti_font *fp = &scr->scr_curfont; - sti_bmove(sc, startcol * fp->width, row * fp->height, + sti_bmove(scr, startcol * fp->width, row * fp->height, startcol * fp->width, row * fp->height, fp->height, ncols * fp->width, bmf_clear); } @@ -827,32 +1296,31 @@ sti_erasecols(void *v, int row, int star void sti_copyrows(void *v, int srcrow, int dstrow, int nrows) { - struct sti_softc *sc = v; - struct sti_font *fp = &sc->sc_curfont; + struct sti_screen *scr = (struct sti_screen *)v; + struct sti_font *fp = &scr->scr_curfont; - sti_bmove(sc, sc->sc_cfg.oscr_width, srcrow * fp->height, - sc->sc_cfg.oscr_width, dstrow * fp->height, - nrows * fp->height, sc->sc_cfg.scr_width, bmf_copy); + sti_bmove(scr, 0, srcrow * fp->height, 0, dstrow * fp->height, + nrows * fp->height, scr->scr_cfg.scr_width, bmf_copy); } void sti_eraserows(void *v, int srcrow, int nrows, long attr) { - struct sti_softc *sc = v; - struct sti_font *fp = &sc->sc_curfont; + struct sti_screen *scr = (struct sti_screen *)v; + struct sti_font *fp = &scr->scr_curfont; - sti_bmove(sc, sc->sc_cfg.oscr_width, srcrow * fp->height, - sc->sc_cfg.oscr_width, srcrow * fp->height, - nrows * fp->height, sc->sc_cfg.scr_width, bmf_clear); + sti_bmove(scr, 0, srcrow * fp->height, 0, srcrow * fp->height, + nrows * fp->height, scr->scr_cfg.scr_width, bmf_clear); } int sti_alloc_attr(void *v, int fg, int bg, int flags, long *pattr) { - /* struct sti_softc *sc = v; */ +#if 0 + struct sti_screen *scr = (struct sti_screen *)v; +#endif *pattr = 0; return 0; } - Index: sys/dev/ic/stireg.h =================================================================== RCS file: /cvsroot/src/sys/dev/ic/stireg.h,v retrieving revision 1.4 diff -u -p -u -r1.4 stireg.h --- sys/dev/ic/stireg.h 1 Nov 2010 06:41:50 -0000 1.4 +++ sys/dev/ic/stireg.h 7 Nov 2010 14:27:32 -0000 @@ -1,6 +1,6 @@ /* $NetBSD: stireg.h,v 1.4 2010/11/01 06:41:50 skrll Exp $ */ -/* $OpenBSD: stireg.h,v 1.8 2003/08/19 02:52:38 mickey Exp $ */ +/* $OpenBSD: stireg.h,v 1.13 2009/01/28 17:37:40 miod Exp $ */ /* * Copyright (c) 2000 Michael Shalayeff @@ -56,6 +56,13 @@ #define STI_END 13 #define STI_CODECNT 16 +#define STI_CODEBASE_MAIN 0x40 +#define STI_CODEBASE_ALT 0x80 + +#define STI_CODEBASE_PA STI_CODEBASE_MAIN +#define STI_CODEBASE_M68K STI_CODEBASE_ALT +#define STI_CODEBASE_PA64 STI_CODEBASE_ALT + /* sti returns */ #define STI_OK 0 #define STI_FAIL -1 @@ -66,12 +73,12 @@ #define STI_BADREENTLVL 1 /* bad reentry level */ #define STI_NOREGIONSDEF 2 /* region table is not setup */ #define STI_ILLNPLANES 3 /* invalid num of text planes */ -#define STI_ILLINDEX 4 /* invalid fond index */ +#define STI_ILLINDEX 4 /* invalid font index */ #define STI_ILLLOC 5 /* invalid font location */ #define STI_ILLCOLOUR 6 /* invalid colour */ #define STI_ILLBLKMVFROM 7 /* invalid from in blkmv */ #define STI_ILLBLKMVTO 8 /* invalid to in blkmv */ -#define STI_ILLBLKMVSIZE 9 /* invalid siz in blkmv */ +#define STI_ILLBLKMVSIZE 9 /* invalid size in blkmv */ #define STI_BEIUNSUPP 10 /* bus error ints unsupported */ #define STI_UNXPBE 11 /* unexpected bus error */ #define STI_UNXHWF 12 /* unexpected hardware failure */ @@ -106,8 +113,6 @@ #define STI_COLOUR_BLUE 6 #define STI_COLOUR_MAGENTA 7 -#pragma pack(1) - /* LSB high */ struct sti_dd { uint32_t dd_type; /* 0x00 device type */ @@ -117,7 +122,7 @@ struct sti_dd { uint8_t dd_nmon; /* 0x05 number monitor rates */ uint8_t dd_grrev; /* 0x06 global rom revision */ uint8_t dd_lrrev; /* 0x07 local rom revision */ - uint8_t dd_grid[8]; /* 0x08 graphics id */ + uint32_t dd_grid[2]; /* 0x08 graphics id */ #define STI_DEV4_DD_GRID 0x08 /* offset for STI_DEVTYPE4 */ #define STI_DEV1_DD_GRID 0x10 /* offset for STI_DEVTYPE1 */ uint32_t dd_fntaddr; /* 0x10 font start address */ @@ -155,7 +160,9 @@ struct sti_dd { servers w/o accel */ uint32_t dd_pacode[16]; /* 0x40 routines for pa-risc */ uint32_t dd_altcode[16]; /* 0x80 routines for m68k/i386 */ -}; +} __packed; + +#define STI_REVISION(maj, min) (((maj) << 4) | ((min) & 0x0f)) /* after the last region there is one indirect list ptr */ struct sti_region { @@ -165,7 +172,7 @@ struct sti_region { u_int btlb : 1; /* should use BTLB if available */ u_int last : 1; /* last region in the list */ u_int length :14; /* size in pages */ -}; +} __packed; struct sti_font { uint16_t first; @@ -180,7 +187,7 @@ struct sti_font { uint8_t uheight; uint8_t uoffset; uint8_t unused[2]; -}; +} __packed; struct sti_fontcfg { uint16_t first; @@ -191,7 +198,23 @@ struct sti_fontcfg { uint8_t bpc; uint8_t uheight; uint8_t uoffset; -}; +} __packed; + +typedef struct sti_mon { + uint32_t width: 12; + uint32_t height: 12; + uint32_t hz: 7; /* low 7 bits of refresh rate */ + uint32_t flat: 1; /* flatpanel */ + uint32_t vesa: 1; /* vesa mode */ + uint32_t grey: 1; /* greyscale */ + uint32_t dblbuf: 1; /* double buffered */ + uint32_t user: 1; /* user-defined mode */ + uint32_t stereo: 1; /* stereo display */ + uint32_t sam: 1; /* ? */ + uint32_t : 15; + uint32_t hz_upper: 3; /* upper 3 bits of refresh rate */ + uint32_t font: 8; /* rom font index */ +} __packed *sti_mon_t; typedef struct sti_ecfg { uint8_t current_monitor; @@ -200,7 +223,7 @@ typedef struct sti_ecfg { uint32_t freq_ref; uint32_t *addr; /* memory block of size dd_stimemreq */ void *future; -} *sti_ecfg_t; +} __packed *sti_ecfg_t; typedef struct sti_cfg { uint32_t text_planes; @@ -214,7 +237,7 @@ typedef struct sti_cfg { uint32_t reent_level; uint32_t *save_addr; sti_ecfg_t ext_cfg; -} *sti_cfg_t; +} __packed *sti_cfg_t; /* routine types */ @@ -240,25 +263,25 @@ typedef struct sti_initflags { #define STI_INITF_SCMT 0x00040000 /* change current monitor type */ #define STI_INITF_RIE 0x00020000 /* retain int enables */ void *future; -} *sti_initflags_t; +} __packed *sti_initflags_t; typedef struct sti_einitin { uint8_t mon_type; uint8_t pad; uint16_t inflight; /* possible on pci */ void *future; -} *sti_einitin_t; +} __packed *sti_einitin_t; typedef struct sti_initin { uint32_t text_planes; /* number of planes for text */ sti_einitin_t ext_in; -} *sti_initin_t; +} __packed *sti_initin_t; typedef struct sti_initout { int32_t errno; uint32_t text_planes; /* number of planes used for text */ void *future; -} *sti_initout_t; +} __packed *sti_initout_t; STI_DEP(init); @@ -268,17 +291,17 @@ typedef struct sti_mgmtflags { #define STI_MGMTF_SAVE 0x40000000 #define STI_MGMTF_RALL 0x20000000 /* restore all display planes */ void *future; -} *sti_mgmtflags_t; +} __packed *sti_mgmtflags_t; typedef struct sti_mgmtin { void *addr; void *future; -} *sti_mgmtin_t; +} __packed *sti_mgmtin_t; typedef struct sti_mgmtout { int32_t errno; void *future; -} *sti_mgmtout_t; +} __packed *sti_mgmtout_t; STI_DEP(mgmt); @@ -287,7 +310,7 @@ typedef struct sti_unpmvflags { #define STI_UNPMVF_WAIT 0x80000000 #define STI_UNPMVF_NTXT 0x40000000 /* intp non-text planes */ void *future; -} *sti_unpmvflags_t; +} __packed *sti_unpmvflags_t; typedef struct sti_unpmvin { uint32_t *font_addr; /* font */ @@ -296,12 +319,12 @@ typedef struct sti_unpmvin { uint8_t bg_colour; uint16_t x, y; void *future; -} *sti_unpmvin_t; +} __packed *sti_unpmvin_t; typedef struct sti_unpmvout { uint32_t errno; void *future; -} *sti_unpmvout_t; +} __packed *sti_unpmvout_t; STI_DEP(unpmv); @@ -312,7 +335,7 @@ typedef struct sti_blkmvflags { #define STI_BLKMVF_CLR 0x20000000 /* clear on move */ #define STI_BLKMVF_NTXT 0x10000000 /* move in non-text planes */ void *future; -} *sti_blkmvflags_t; +} __packed *sti_blkmvflags_t; typedef struct sti_blkmvin { uint8_t fg_colour; @@ -321,12 +344,12 @@ typedef struct sti_blkmvin { uint16_t width, height; uint16_t pad; void *future; -} *sti_blkmvin_t; +} __packed *sti_blkmvin_t; typedef struct sti_blkmvout { uint32_t errno; void *future; -} *sti_blkmvout_t; +} __packed *sti_blkmvout_t; STI_DEP(blkmv); @@ -335,17 +358,17 @@ typedef struct sti_testflags { #define STI_TESTF_WAIT 0x80000000 #define STI_TESTF_ETST 0x40000000 void *future; -} *sti_testflags_t; +} __packed *sti_testflags_t; typedef struct sti_testin { void *future; -} *sti_testin_t; +} __packed *sti_testin_t; typedef struct sti_testout { uint32_t errno; uint32_t result; void *future; -} *sti_testout_t; +} __packed *sti_testout_t; STI_DEP(test); @@ -366,7 +389,7 @@ typedef struct sti_exhdlflags { #define STI_EXHDLF_EIC 0x00080000 /* end int cycle */ #define STI_EXHDLF_RIE 0x00040000 /* reset do not clear int enables */ void *future; -} *sti_exhdlflags_t; +} __packed *sti_exhdlflags_t; typedef struct sti_eexhdlin { uint32_t eim_addr; @@ -374,7 +397,7 @@ typedef struct sti_eexhdlin { uint32_t iem; /* enable mask */ uint32_t icm; /* clear mask */ void *future; -} *sti_eexhdlin_t; +} __packed *sti_eexhdlin_t; typedef struct sti_exhdlint { uint32_t flags; @@ -387,12 +410,12 @@ typedef struct sti_exhdlint { #define STI_EXHDLINT_BDC 0x02000000 /* buffered dma complete */ #define STI_EXHDLINT_UDPC 0x01000000 /* unbuf priv dma complete */ #define STI_EXHDLINT_BDPC 0x00800000 /* buffered priv dma complete */ -} *sti_exhdlint_t; +} __packed *sti_exhdlint_t; typedef struct sti_exhdlin { sti_exhdlint_t addr; sti_eexhdlin_t ext; -} *sti_exhdlin_t; +} __packed *sti_exhdlin_t; typedef struct sti_eexhdlout { uint32_t eim_addr; @@ -400,7 +423,7 @@ typedef struct sti_eexhdlout { uint32_t iem; /* enable mask */ uint32_t icm; /* clear mask */ void *future; -} *sti_eexhdlout_t; +} __packed *sti_eexhdlout_t; typedef struct sti_exhdlout { uint32_t errno; @@ -409,7 +432,7 @@ typedef struct sti_exhdlout { #define STI_EXHDLO_IP 0x40000000 /* there is int pending */ #define STI_EXHDLO_IE 0x20000000 /* global enable set */ sti_eexhdlout_t ext; -} *sti_exhdlout_t; +} __packed *sti_exhdlout_t; STI_DEP(exhdl); @@ -417,17 +440,17 @@ typedef struct sti_inqconfflags { uint32_t flags; #define STI_INQCONFF_WAIT 0x80000000 void *future; -} *sti_inqconfflags_t; +} __packed *sti_inqconfflags_t; typedef struct sti_inqconfin { void *future; -} *sti_inqconfin_t; +} __packed *sti_inqconfin_t; typedef struct sti_einqconfout { uint32_t crt_config[3]; uint32_t crt_hw[3]; void *future; -} *sti_einqconfout_t; +} __packed *sti_einqconfout_t; typedef struct sti_inqconfout { uint32_t errno; @@ -437,7 +460,7 @@ typedef struct sti_inqconfout { uint32_t planes; uint8_t name[STI_DEVNAME_LEN]; uint32_t attributes; -#define STI_INQCONF_Y2X 0x0001 /* pixel is higher tan wider */ +#define STI_INQCONF_Y2X 0x0001 /* pixel is higher than wider */ #define STI_INQCONF_HWBLKMV 0x0002 /* hw blkmv is present */ #define STI_INQCONF_AHW 0x0004 /* adv hw accel */ #define STI_INQCONF_INT 0x0008 /* can interrupt */ @@ -454,7 +477,7 @@ typedef struct sti_inqconfout { "\020\001y2x\002hwblkmv\003ahw\004int\005gonoff\006aonoff\007vary"\ "\010oddb\011flush\012dma\013vdma\016yuv1\017yuv2" sti_einqconfout_t ext; -} *sti_inqconfout_t; +} __packed *sti_inqconfout_t; STI_DEP(inqconf); @@ -462,18 +485,18 @@ typedef struct sti_scmentflags { uint32_t flags; #define STI_SCMENTF_WAIT 0x80000000 void *future; -} *sti_scmentflags_t; +} __packed *sti_scmentflags_t; typedef struct sti_scmentin { uint32_t entry; uint32_t value; void *future; -} *sti_scmentin_t; +} __packed *sti_scmentin_t; typedef struct sti_scmentout { uint32_t errno; void *future; -} *sti_scmentout_t; +} __packed *sti_scmentout_t; STI_DEP(scment); @@ -486,7 +509,7 @@ typedef struct sti_dmacflags { #define STI_DMACF_MRK 0x08000000 /* write a marker */ #define STI_DMACF_ABRT 0x04000000 /* abort dma xfer */ void *future; -} *sti_dmacflags_t; +} __packed *sti_dmacflags_t; typedef struct sti_dmacin { uint32_t pa_upper; @@ -495,12 +518,12 @@ typedef struct sti_dmacin { uint32_t mrk_data; uint32_t mrk_off; void *future; -} *sti_dmacin_t; +} __packed *sti_dmacin_t; typedef struct sti_dmacout { uint32_t errno; void *future; -} *sti_dmacout_t; +} __packed *sti_dmacout_t; STI_DEP(dmac); @@ -516,7 +539,7 @@ typedef struct sti_flowcflags { #define STI_FLOWCF_CSWC 0x01000000 /* cs write coarse */ #define STI_FLOWCF_CSWQ 0x00800000 /* cs write fifo */ void *future; -} *sti_flowcflags_t; +} __packed *sti_flowcflags_t; typedef struct sti_flowcin { uint32_t retry; @@ -527,14 +550,14 @@ typedef struct sti_flowcin { uint32_t cscv; /* cs coarse value */ uint32_t csqc; /* cs fifo count */ void *future; -} *sti_flowcin_t; +} __packed *sti_flowcin_t; typedef struct sti_flowcout { uint32_t errno; uint32_t retry_result; uint32_t fifo_size; void *future; -} *sti_flowcout_t; +} __packed *sti_flowcout_t; STI_DEP(flowc); @@ -543,19 +566,19 @@ typedef struct sti_utimingflags { #define STI_UTIMF_WAIT 0x80000000 #define STI_UTIMF_HKS 0x40000000 /* has kbuf_size */ void *future; -} *sti_utimingflags_t; +} __packed *sti_utimingflags_t; typedef struct sti_utimingin { void *data; void *kbuf; void *future; -} *sti_utimingin_t; +} __packed *sti_utimingin_t; typedef struct sti_utimingout { uint32_t errno; uint32_t kbuf_size; /* buffer required size */ void *future; -} *sti_utimingout_t; +} __packed *sti_utimingout_t; STI_DEP(utiming); @@ -568,17 +591,17 @@ typedef struct sti_pmgrflags { #define STI_UTIMF_BUFF 0x02000000 #define STI_UTIMF_IBUFF 0x01000000 void *future; -} *sti_pmgrflags_t; +} __packed *sti_pmgrflags_t; typedef struct sti_pmgrin { uint32_t reserved[4]; void *future; -} *sti_pmgrin_t; +} __packed *sti_pmgrin_t; typedef struct sti_pmgrout { int32_t errno; void *future; -} *sti_pmgrout_t; +} __packed *sti_pmgrout_t; STI_DEP(pmgr); @@ -586,21 +609,19 @@ typedef struct sti_utilflags { uint32_t flags; #define STI_UTILF_ROOT 0x80000000 /* was called as root */ void *future; -} *sti_utilflags_t; +} __packed *sti_utilflags_t; typedef struct sti_utilin { uint32_t in_size; uint32_t out_size; uint8_t *buf; -} *sti_utilin_t; +} __packed *sti_utilin_t; typedef struct sti_utilout { int32_t errno; void *future; -} *sti_utilout_t; +} __packed *sti_utilout_t; STI_DEP(util); -#pragma pack() - #endif /* _IC_STIREG_H_ */ Index: sys/dev/ic/stivar.h =================================================================== RCS file: /cvsroot/src/sys/dev/ic/stivar.h,v retrieving revision 1.5 diff -u -p -u -r1.5 stivar.h --- sys/dev/ic/stivar.h 1 Nov 2010 06:41:50 -0000 1.5 +++ sys/dev/ic/stivar.h 7 Nov 2010 14:27:33 -0000 @@ -1,6 +1,6 @@ /* $NetBSD: stivar.h,v 1.5 2010/11/01 06:41:50 skrll Exp $ */ -/* $OpenBSD: stivar.h,v 1.15 2003/12/16 06:07:13 mickey Exp $ */ +/* $OpenBSD: stivar.h,v 1.24 2009/02/06 22:51:04 miod Exp $ */ /* * Copyright (c) 2000-2003 Michael Shalayeff @@ -31,52 +31,102 @@ #ifndef _IC_STIVAR_H_ #define _IC_STIVAR_H_ +struct sti_softc; + +/* + * STI ROM information - one per device + */ +struct sti_rom { + struct sti_softc *rom_softc; /* backpointer to device */ + int rom_devtype; + + bus_space_tag_t iot, memt; /* XXX iot unused */ + bus_space_handle_t romh; + bus_addr_t *bases; + + struct sti_dd rom_dd; /* in word format */ + + vaddr_t rom_code; + sti_init_t init; + sti_mgmt_t mgmt; + sti_unpmv_t unpmv; + sti_blkmv_t blkmv; + sti_test_t test; + sti_exhdl_t exhdl; + sti_inqconf_t inqconf; + sti_scment_t scment; + sti_dmac_t dmac; + sti_flowc_t flowc; + sti_utiming_t utiming; + sti_pmgr_t pmgr; + sti_util_t util; +}; + +/* + * STI screen information - one per head + */ +struct sti_screen { + struct sti_rom *scr_rom; + +#ifdef notyet + u_int scr_flags; +#endif + + int scr_bpp; + + struct sti_font scr_curfont; + struct sti_cfg scr_cfg; + struct sti_ecfg scr_ecfg; + char name[STI_DEVNAME_LEN]; + + void *scr_romfont; /* ROM font copy in memory... */ + u_int scr_fontmaxcol;/* ...or in off-screen area */ + u_int scr_fontbase; + + uint8_t scr_rcmap[STI_NCMAP], + scr_gcmap[STI_NCMAP], + scr_bcmap[STI_NCMAP]; + + uint16_t fbheight, fbwidth; + uint16_t oheight, owidth; /* offscreen size */ + bus_addr_t fbaddr; + bus_size_t fblen; + + /* wsdisplay information */ + int scr_nscreens; + u_int scr_wsmode; + struct wsscreen_descr scr_wsd; + struct wsscreen_descr *scr_scrlist[1]; + struct wsscreen_list scr_screenlist; +}; + +/* + * STI Device state + */ struct sti_softc { device_t sc_dev; void *sc_ih; - u_int sc_wsmode; - u_int sc_flags; -#define STI_TEXTMODE 0x0001 -#define STI_CLEARSCR 0x0002 -#define STI_CONSOLE 0x0004 - int sc_devtype; - int sc_nscreens; - int sc_bpp; - - bus_space_tag_t iot, memt; - bus_space_handle_t romh; - bus_addr_t base, fbaddr; - bus_size_t fblen; - - struct sti_dd sc_dd; /* in word format */ - struct sti_font sc_curfont; - struct sti_cfg sc_cfg; - struct sti_ecfg sc_ecfg; - - void *sc_romfont; /* ROM font copy, either in memory... */ - u_int sc_fontmaxcol; /* ...or in off-screen frame buffer */ - u_int sc_fontbase; - - uint8_t sc_rcmap[STI_NCMAP], sc_gcmap[STI_NCMAP], sc_bcmap[STI_NCMAP]; - vaddr_t sc_code; - - sti_init_t init; - sti_mgmt_t mgmt; - sti_unpmv_t unpmv; - sti_blkmv_t blkmv; - sti_test_t test; - sti_exhdl_t exhdl; - sti_inqconf_t inqconf; - sti_scment_t scment; - sti_dmac_t dmac; - sti_flowc_t flowc; - sti_utiming_t utiming; - sti_pmgr_t pmgr; - sti_util_t util; + u_int sc_flags; +#define STI_CONSOLE 0x0001 /* first head is console... */ +#define STI_ATTACHED 0x0002 /* ... and wsdisplay_cnattach() has been done */ +#define STI_ROM_ENABLED 0x0004 /* PCI ROM is enabled */ + + bus_addr_t bases[STI_REGION_MAX]; + struct sti_rom *sc_rom; + struct sti_screen *sc_scr; + + /* optional, required for PCI */ + void (*sc_enable_rom)(struct sti_softc *); + void (*sc_disable_rom)(struct sti_softc *); }; -void sti_attach_common(struct sti_softc *sc); -int sti_intr(void *v); +int sti_attach_common(struct sti_softc *, bus_space_tag_t, bus_space_tag_t, + bus_space_handle_t, u_int); +int sti_cnattach(struct sti_rom *, struct sti_screen *, bus_space_tag_t, + bus_addr_t *, u_int); +void sti_describe(struct sti_softc *); +void sti_end_attach(struct sti_softc *); +u_int sti_rom_size(bus_space_tag_t, bus_space_handle_t); #endif /* _IC_STIVAR_H_ */ Index: sys/dev/pci/files.pci =================================================================== RCS file: /cvsroot/src/sys/dev/pci/files.pci,v retrieving revision 1.329 diff -u -p -u -r1.329 files.pci --- sys/dev/pci/files.pci 24 May 2010 20:29:41 -0000 1.329 +++ sys/dev/pci/files.pci 7 Nov 2010 14:27:34 -0000 @@ -421,6 +421,10 @@ file dev/ic/bt485.c tga file dev/ic/bt463.c tga file dev/ic/ibm561.c tga +# HP Visualize +attach sti at pci with sti_pci +file dev/pci/sti_pci.c sti_pci needs-flag + # Integraphics Systems IGA168x and CyberPro framebuffers (linear non-VGA mode) # device declaration in sys/conf/files attach igsfb at pci with igsfb_pci Index: sys/dev/pci/sti_pci.c =================================================================== RCS file: sys/dev/pci/sti_pci.c diff -N sys/dev/pci/sti_pci.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sys/dev/pci/sti_pci.c 7 Nov 2010 14:27:35 -0000 @@ -0,0 +1,425 @@ +/* $NetBSD$ */ + +/* $OpenBSD: sti_pci.c,v 1.7 2009/02/06 22:51:04 miod Exp $ */ + +/* + * Copyright (c) 2006, 2007 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include + +int sti_pci_match(device_t, cfdata_t, void *); +void sti_pci_attach(device_t, device_t, void *); + +void sti_pci_end_attach(device_t dev); + +struct sti_pci_softc { + device_t sc_dev; + + struct sti_softc sc_base; + + pci_chipset_tag_t sc_pc; + pcitag_t sc_tag; + + bus_space_handle_t sc_romh; +}; + +CFATTACH_DECL_NEW(sti_pci, sizeof(struct sti_pci_softc), + sti_pci_match, sti_pci_attach, NULL, NULL); + +int sti_readbar(struct sti_softc *, struct pci_attach_args *, u_int, int); +int sti_check_rom(struct sti_pci_softc *, struct pci_attach_args *); +void sti_pci_enable_rom(struct sti_softc *); +void sti_pci_disable_rom(struct sti_softc *); +void sti_pci_enable_rom_internal(struct sti_pci_softc *); +void sti_pci_disable_rom_internal(struct sti_pci_softc *); + +int sti_pci_is_console(struct pci_attach_args *, bus_addr_t *); + +int +sti_pci_match(device_t parent, cfdata_t cf, void *aux) +{ + struct pci_attach_args *paa = aux; + + if (PCI_VENDOR(paa->pa_id) != PCI_VENDOR_HP) + return 0; + + if (PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_EG || + PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_FX2 || + PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_FX4 || + PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_FX6 || + PCI_PRODUCT(paa->pa_id) == PCI_PRODUCT_HP_VISUALIZE_FXE) + return 1; + + return 0; +} + +void +sti_pci_attach(device_t parent, device_t self, void *aux) +{ + struct sti_pci_softc *spc = device_private(self); + struct pci_attach_args *paa = aux; + + spc->sc_dev = self; + + spc->sc_pc = paa->pa_pc; + spc->sc_tag = paa->pa_tag; + spc->sc_base.sc_dev = self; + spc->sc_base.sc_enable_rom = sti_pci_enable_rom; + spc->sc_base.sc_disable_rom = sti_pci_disable_rom; + +/* XXX */ + aprint_normal("\n"); + + if (sti_check_rom(spc, paa) != 0) + return; + +/* XXX */ + aprint_normal("%s", device_xname(self)); + if (sti_pci_is_console(paa, spc->sc_base. bases) != 0) + spc->sc_base.sc_flags |= STI_CONSOLE; + if (sti_attach_common(&spc->sc_base, paa->pa_iot, paa->pa_memt, + spc->sc_romh, STI_CODEBASE_MAIN) == 0) + config_defer(self, sti_pci_end_attach); +} + +void sti_pci_end_attach(device_t dev) +{ + struct sti_pci_softc *spc = device_private(dev); + struct sti_softc *sc = &spc->sc_base; + + sti_end_attach(sc); +} + + +/* + * Grovel the STI ROM image. + */ +int +sti_check_rom(struct sti_pci_softc *spc, struct pci_attach_args *pa) +{ + struct sti_softc *sc = &spc->sc_base; + pcireg_t address, mask; + bus_space_handle_t romh; + bus_size_t romsize, subsize, stiromsize; + bus_addr_t selected, offs, suboffs; + uint32_t tmp; + int i; + int rc; + +#define PCI_ROM_ENABLE 0x00000001 +#define PCI_ROM_ADDR_MASK 0xfffff800 +#define PCI_ROM_ADDR(mr) \ + ((mr) & PCI_ROM_ADDR_MASK) +#define PCI_ROM_SIZE(mr) \ + (PCI_ROM_ADDR(mr) & -PCI_ROM_ADDR(mr)) + + /* sort of inline sti_pci_enable_rom(sc) */ + address = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM); + pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, ~PCI_ROM_ENABLE); + mask = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM); + address |= PCI_ROM_ENABLE; + pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_MAPREG_ROM, address); + sc->sc_flags |= STI_ROM_ENABLED; + /* + * Map the complete ROM for now. + */ + + romsize = PCI_ROM_SIZE(mask); +#ifdef STIDEBUG + printf("mapping rom @ %lx for %lx\n", (long)PCI_ROM_ADDR(address), (long)romsize); +#endif + rc = bus_space_map(pa->pa_memt, PCI_ROM_ADDR(address), romsize, + 0, &romh); + if (rc != 0) { + aprint_error_dev(sc->sc_dev, "can't map PCI ROM (%d)\n", rc); + goto fail2; + } + + sti_pci_disable_rom_internal(spc); + /* + * Iterate over the ROM images, pick the best candidate. + */ + + selected = (bus_addr_t)-1; + for (offs = 0; offs < romsize; offs += subsize) { + sti_pci_enable_rom_internal(spc); + /* + * Check for a valid ROM header. + */ + tmp = bus_space_read_4(pa->pa_memt, romh, offs + 0); + tmp = le32toh(tmp); + if (tmp != 0x55aa0000) { + sti_pci_disable_rom_internal(spc); + if (offs == 0) { + aprint_error_dev(sc->sc_dev, "invalid PCI ROM header signature" + " (%08x)\n",tmp); + rc = EINVAL; + } + break; + } + + /* + * Check ROM type. + */ + tmp = bus_space_read_4(pa->pa_memt, romh, offs + 4); + tmp = le32toh(tmp); + if (tmp != 0x00000001) { /* 1 == STI ROM */ + sti_pci_disable_rom_internal(spc); + if (offs == 0) { + aprint_error_dev(sc->sc_dev, "invalid PCI ROM type (%08x)\n", + tmp); + rc = EINVAL; + } + break; + } + + subsize = (bus_addr_t)bus_space_read_2(pa->pa_memt, romh, + offs + 0x0c); + subsize <<= 9; + +#ifdef STIDEBUG + sti_pci_disable_rom_internal(spc); + printf("ROM offset %08x size %08x type %08x", + (u_int)offs, (u_int)subsize, tmp); + sti_pci_enable_rom_internal(spc); +#endif + + /* + * Check for a valid ROM data structure. + * We do not need it except to know what architecture the ROM + * code is for. + */ + + suboffs = offs +(bus_addr_t)bus_space_read_2(pa->pa_memt, romh, + offs + 0x18); + tmp = bus_space_read_4(pa->pa_memt, romh, suboffs + 0); + tmp = le32toh(tmp); + if (tmp != 0x50434952) { /* PCIR */ + sti_pci_disable_rom_internal(spc); + if (offs == 0) { + aprint_error_dev(sc->sc_dev, "invalid PCI data signature" + " (%08x)\n", tmp); + rc = EINVAL; + } else { +#ifdef STIDEBUG + aprint_normal(" invalid PCI data signature %08x\n", + tmp); +#endif + continue; + } + } + + tmp = bus_space_read_1(pa->pa_memt, romh, suboffs + 0x14); + sti_pci_disable_rom_internal(spc); +#ifdef STIDEBUG + printf(" code %02x", tmp); +#endif + + switch (tmp) { +#ifdef __hppa__ + case 0x10: + if (selected == (bus_addr_t)-1) + selected = offs; + break; +#endif +#ifdef __i386__ + case 0x00: + if (selected == (bus_addr_t)-1) + selected = offs; + break; +#endif + default: +#ifdef STIDEBUG + printf(" (wrong architecture)"); +#endif + break; + } + +#ifdef STIDEBUG + if (selected == offs) + printf(" -> SELECTED"); + printf("\n"); +#endif + } + + if (selected == (bus_addr_t)-1) { + if (rc == 0) { + aprint_error_dev(sc->sc_dev, "found no ROM with correct microcode" + " architecture\n"); + rc = ENOEXEC; + } + goto fail; + } + + /* + * Read the STI region BAR assignments. + */ + + sti_pci_enable_rom_internal(spc); + offs = selected + + (bus_addr_t)bus_space_read_2(pa->pa_memt, romh, selected + 0x0e); + for (i = 0; i < STI_REGION_MAX; i++) { + rc = sti_readbar(sc, pa, i, + bus_space_read_1(pa->pa_memt, romh, offs + i)); + if (rc != 0) + goto fail; + } + + /* + * Find out where the STI ROM itself lies, and its size. + */ + + offs = selected + + (bus_addr_t)bus_space_read_4(pa->pa_memt, romh, selected + 0x08); + stiromsize = (bus_addr_t)bus_space_read_4(pa->pa_memt, romh, + offs + 0x18); + stiromsize = le32toh(stiromsize); + sti_pci_disable_rom_internal(spc); + + /* + * Replace our mapping with a smaller mapping of only the area + * we are interested in. + */ + +#ifdef STIDEBUG + printf("remapping rom @ %lx for %lx\n", (long)(PCI_ROM_ADDR(address) + offs), (long)stiromsize); +#endif + bus_space_unmap(pa->pa_memt, romh, romsize); + rc = bus_space_map(pa->pa_memt, PCI_ROM_ADDR(address) + offs, + stiromsize, 0, &spc->sc_romh); + if (rc != 0) { + aprint_error_dev(sc->sc_dev, "can't map STI ROM (%d)\n", + rc); + goto fail2; + } + sti_pci_disable_rom_internal(spc); + sc->sc_flags &= ~STI_ROM_ENABLED; + + return 0; + +fail: + bus_space_unmap(pa->pa_memt, romh, romsize); +fail2: + sti_pci_disable_rom_internal(spc); + + return rc; +} + +/* + * Decode a BAR register. + */ +int +sti_readbar(struct sti_softc *sc, struct pci_attach_args *pa, u_int region, + int bar) +{ + bus_addr_t addr; + bus_size_t size; + uint32_t cf; + int rc; + + if (bar == 0) { + sc->bases[region] = 0; + return (0); + } + +#ifdef DIAGNOSTIC + if (bar < PCI_MAPREG_START || bar > PCI_MAPREG_PPB_END) { + sti_pci_disable_rom(sc); + printf("%s: unexpected bar %02x for region %d\n", + device_xname(sc->sc_dev), bar, region); + sti_pci_enable_rom(sc); + } +#endif + + cf = pci_conf_read(pa->pa_pc, pa->pa_tag, bar); + + rc = pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, PCI_MAPREG_TYPE(cf), &addr, &size, NULL); + + if (rc != 0) { + sti_pci_disable_rom(sc); + aprint_error_dev(sc->sc_dev, "invalid bar %02x for region %d\n", + bar, region); + sti_pci_enable_rom(sc); + return (rc); + } + + sc->bases[region] = addr; + return (0); +} + +/* + * Enable PCI ROM. + */ +void +sti_pci_enable_rom_internal(struct sti_pci_softc *spc) +{ + pcireg_t address; + + KASSERT(spc != NULL); + + address = pci_conf_read(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM); + address |= PCI_ROM_ENABLE; + pci_conf_write(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM, address); +} + +void +sti_pci_enable_rom(struct sti_softc *sc) +{ + struct sti_pci_softc *spc = device_private(sc->sc_dev); + + if (!ISSET(sc->sc_flags, STI_ROM_ENABLED)) { + sti_pci_enable_rom_internal(spc); + } + SET(sc->sc_flags, STI_ROM_ENABLED); +} + +/* + * Disable PCI ROM. + */ +void +sti_pci_disable_rom_internal(struct sti_pci_softc *spc) +{ + pcireg_t address; + + KASSERT(spc != NULL); + + address = pci_conf_read(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM); + address &= ~PCI_ROM_ENABLE; + pci_conf_write(spc->sc_pc, spc->sc_tag, PCI_MAPREG_ROM, address); +} + +void +sti_pci_disable_rom(struct sti_softc *sc) +{ + struct sti_pci_softc *spc = device_private(sc->sc_dev); + + if (ISSET(sc->sc_flags, STI_ROM_ENABLED)) { + sti_pci_disable_rom_internal(spc); + } + CLR(sc->sc_flags, STI_ROM_ENABLED); +}