Module Name: src Committed By: tsutsui Date: Sun Apr 20 04:12:54 UTC 2014
Modified Files: src/sys/arch/hp300/conf: files.hp300 src/sys/arch/hp300/dev: com_frodo.c sti_sgc.c src/sys/arch/hp300/hp300: autoconf.c machdep.c src/sys/arch/hp300/include: autoconf.h src/sys/dev/ic: sti.c stivar.h Added Files: src/sys/arch/hp300/dev: sti_sgcvar.h Log Message: Add proper consinit(9) support for sti(4) at sgc framebuffer on hp300. The cnattach functions for sti(4) and service switch check method for 425e in com_frodo.c are taken from OpenBSD. The strategy how to choose the console device in hp300_cninit() is quite diverged from 4.4BSD and OpenBSD so it's tweaked by me. Also put several changes in sti_sgc.c to reduce diffs from OpenBSD/hp300. Tested on 425e and 362 (which still uses gendiofb(4), not sti(4)). XXX: sti(4) requires uvm_km_alloc(9) and uvm_map_protect(9) to copy and call ROM functions on the executable memory region, so it can be called before UVM and related initializations are complete. Probably it's time to consider about MI "deferred consinit()" API in init_main.c (or elsewhere) for modern complicated VM system... To generate a diff of this commit: cvs rdiff -u -r1.87 -r1.88 src/sys/arch/hp300/conf/files.hp300 cvs rdiff -u -r1.8 -r1.9 src/sys/arch/hp300/dev/com_frodo.c cvs rdiff -u -r1.1 -r1.2 src/sys/arch/hp300/dev/sti_sgc.c cvs rdiff -u -r0 -r1.1 src/sys/arch/hp300/dev/sti_sgcvar.h cvs rdiff -u -r1.104 -r1.105 src/sys/arch/hp300/hp300/autoconf.c cvs rdiff -u -r1.228 -r1.229 src/sys/arch/hp300/hp300/machdep.c cvs rdiff -u -r1.12 -r1.13 src/sys/arch/hp300/include/autoconf.h cvs rdiff -u -r1.16 -r1.17 src/sys/dev/ic/sti.c cvs rdiff -u -r1.7 -r1.8 src/sys/dev/ic/stivar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/hp300/conf/files.hp300 diff -u src/sys/arch/hp300/conf/files.hp300:1.87 src/sys/arch/hp300/conf/files.hp300:1.88 --- src/sys/arch/hp300/conf/files.hp300:1.87 Sat Apr 19 05:37:54 2014 +++ src/sys/arch/hp300/conf/files.hp300 Sun Apr 20 04:12:54 2014 @@ -1,4 +1,4 @@ -# $NetBSD: files.hp300,v 1.87 2014/04/19 05:37:54 tsutsui Exp $ +# $NetBSD: files.hp300,v 1.88 2014/04/20 04:12:54 tsutsui Exp $ # # hp300-specific configuration info @@ -192,7 +192,7 @@ file arch/hp300/dev/spc.c spc needs-fla # attach sti at sgc with sti_sgc -file arch/hp300/dev/sti_sgc.c sti_sgc +file arch/hp300/dev/sti_sgc.c sti_sgc needs-flag # Memory Disk for ramdisk file dev/md_root.c memory_disk_hooks Index: src/sys/arch/hp300/dev/com_frodo.c diff -u src/sys/arch/hp300/dev/com_frodo.c:1.8 src/sys/arch/hp300/dev/com_frodo.c:1.9 --- src/sys/arch/hp300/dev/com_frodo.c:1.8 Mon Apr 28 20:23:19 2008 +++ src/sys/arch/hp300/dev/com_frodo.c Sun Apr 20 04:12:54 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: com_frodo.c,v 1.8 2008/04/28 20:23:19 martin Exp $ */ +/* $NetBSD: com_frodo.c,v 1.9 2014/04/20 04:12:54 tsutsui Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -61,7 +61,9 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: com_frodo.c,v 1.8 2008/04/28 20:23:19 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: com_frodo.c,v 1.9 2014/04/20 04:12:54 tsutsui Exp $"); + +#include "sti_sgc.h" #include <sys/param.h> #include <sys/systm.h> @@ -155,10 +157,32 @@ com_frodo_cnattach(bus_space_tag_t bst, { bus_space_tag_t iot = &comcntag; bus_space_handle_t ioh; + volatile uint8_t *frodoregs; if (machineid != HP_425 || mmuid != MMUID_425_E) return 1; + /* + * Check the service switch. On the 425e, this is a physical + * switch, unlike other frodo-based machines, so we can use it + * as a serial vs internal video selector, since the PROM can not + * be configured for serial console. + */ + frodoregs = (volatile uint8_t *)IIOV(INTIOBASE + FRODO_BASE); + if (badaddr(__UNVOLATILE(frodoregs)) != 0) { + /* 425e but no frodo chip found? */ + return 1; + } + + /* + * if sti(4) is not configured, we need serial console anyway + * and no need to check the service switch. + */ +#if NSTI_SGC > 0 + if (ISSET(frodoregs[FRODO_IISR], FRODO_IISR_SERVICE)) + return 1; +#endif + frodo_init_bus_space(iot); if (bus_space_map(iot, addr, INTIO_DEVSIZE, BUS_SPACE_MAP_LINEAR, &ioh)) Index: src/sys/arch/hp300/dev/sti_sgc.c diff -u src/sys/arch/hp300/dev/sti_sgc.c:1.1 src/sys/arch/hp300/dev/sti_sgc.c:1.2 --- src/sys/arch/hp300/dev/sti_sgc.c:1.1 Fri Jan 11 12:03:03 2013 +++ src/sys/arch/hp300/dev/sti_sgc.c Sun Apr 20 04:12:54 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: sti_sgc.c,v 1.1 2013/01/11 12:03:03 tsutsui Exp $ */ +/* $NetBSD: sti_sgc.c,v 1.2 2014/04/20 04:12:54 tsutsui Exp $ */ /* $OpenBSD: sti_sgc.c,v 1.14 2007/05/26 00:36:03 krw Exp $ */ /* @@ -27,7 +27,7 @@ * */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.1 2013/01/11 12:03:03 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.2 2014/04/20 04:12:54 tsutsui Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -41,14 +41,18 @@ __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v #include <dev/ic/stivar.h> #include <hp300/dev/sgcvar.h> +#include <hp300/dev/sti_sgcvar.h> +#include <machine/autoconf.h> -static int sticonslot; +static int sticonslot = -1; +static struct sti_rom sticn_rom; +static struct sti_screen sticn_scr; +static bus_addr_t sticn_bases[STI_REGION_MAX]; static int sti_sgc_match(device_t, struct cfdata *, void *); static void sti_sgc_attach(device_t, device_t, void *); static int sti_sgc_probe(bus_space_tag_t, int); -static void sti_sgc_end_attach(device_t); CFATTACH_DECL_NEW(sti_sgc, sizeof(struct sti_softc), sti_sgc_match, sti_sgc_attach, NULL, NULL); @@ -73,48 +77,68 @@ sti_sgc_attach(device_t parent, device_t { struct sti_softc *sc = device_private(self); struct sgc_attach_args *saa = aux; - bus_space_tag_t iot = saa->saa_iot; - bus_space_handle_t ioh, romh; - bus_addr_t pa = (bus_addr_t)sgc_slottopa(saa->saa_slot); + bus_space_handle_t romh; + bus_addr_t base; u_int romend; int i; - /* XXX: temporalily map before obtain romend. */ -#define STI_ROMSIZE_SAFE (sizeof(struct sti_dd) * 4) - if (bus_space_map(iot, pa, STI_ROMSIZE_SAFE, 0, &ioh)) { - aprint_error(": can't map ROM"); - return; - } - romend = sti_rom_size(iot, ioh); - bus_space_unmap(iot, ioh, STI_ROMSIZE_SAFE); - sc->sc_dev = self; - sc->sc_enable_rom = NULL; - sc->sc_disable_rom = NULL; - if (bus_space_map(iot, pa, romend, 0, &romh)) { - aprint_error(": can't map ROM(2)"); - return; + if (saa->saa_slot == sticonslot) { + sc->sc_flags |= STI_CONSOLE | STI_ATTACHED; + sc->sc_rom = &sticn_rom; + sc->sc_scr = &sticn_scr; + memcpy(sc->bases, sticn_bases, sizeof(sc->bases)); + + sti_describe(sc); + } else { + base = (bus_addr_t)sgc_slottopa(saa->saa_slot); + if (bus_space_map(saa->saa_iot, base, PAGE_SIZE, 0, &romh)) { + aprint_error(": can't map ROM"); + return; + } + /* + * Compute real PROM size + */ + romend = sti_rom_size(saa->saa_iot, romh); + + bus_space_unmap(saa->saa_iot, romh, PAGE_SIZE); + + if (bus_space_map(saa->saa_iot, base, romend, 0, &romh)) { + aprint_error(": can't map frame buffer"); + return; + } + + sc->bases[0] = romh; + for (i = 0; i < STI_REGION_MAX; i++) + sc->bases[i] = base; + + if (sti_attach_common(sc, saa->saa_iot, saa->saa_iot, romh, + STI_CODEBASE_ALT) != 0) + return; } - sc->bases[0] = romh; - for (i = 0; i < STI_REGION_MAX; i++) - sc->bases[i] = pa; - if (saa->saa_slot == sticonslot) - sc->sc_flags |= STI_CONSOLE; - if (sti_attach_common(sc, iot, iot, romh, STI_CODEBASE_ALT) == 0) - config_interrupts(self, sti_sgc_end_attach); + + /* + * Note on 425e sti(4) framebuffer bitmap memory can be accessed at + * (sgc_slottopa(saa->saa_slot) + 0x200000) + * but the mmap function to map bitmap display is not provided yet. + */ + + sti_end_attach(sc); } static int sti_sgc_probe(bus_space_tag_t iot, int slot) { bus_space_handle_t ioh; - bus_addr_t pa = (bus_addr_t)sgc_slottopa(slot); int devtype; - if (bus_space_map(iot, pa, PAGE_SIZE, 0, &ioh)) + if (bus_space_map(iot, (bus_addr_t)sgc_slottopa(slot), + PAGE_SIZE, 0, &ioh)) return 0; + devtype = bus_space_read_1(iot, ioh, 3); + bus_space_unmap(iot, ioh, PAGE_SIZE); /* @@ -123,16 +147,46 @@ sti_sgc_probe(bus_space_tag_t iot, int s * point of not even answering bus probes (checked with an * Harmony/FDDI SGC card). */ - if (devtype != STI_DEVTYPE1 && - devtype != STI_DEVTYPE4) + if (devtype != STI_DEVTYPE1 && devtype != STI_DEVTYPE4) return 0; + return 1; } -static void -sti_sgc_end_attach(device_t self) +int +sti_sgc_cnprobe(bus_space_tag_t bst, bus_addr_t addr, int slot) { - struct sti_softc *sc = device_private(self); + void *va; + bus_space_handle_t romh; + int devtype, rv = 0; - sti_end_attach(sc); + if (bus_space_map(bst, addr, PAGE_SIZE, 0, &romh)) + return 0; + + va = bus_space_vaddr(bst, romh); + if (badaddr(va)) + goto out; + + devtype = bus_space_read_1(bst, romh, 3); + if (devtype == STI_DEVTYPE1 || devtype == STI_DEVTYPE4) + rv = 1; + + out: + bus_space_unmap(bst, romh, PAGE_SIZE); + return rv; +} + +void +sti_sgc_cnattach(bus_space_tag_t bst, bus_addr_t addr, int slot) +{ + int i; + + /* sticn_bases[0] will be fixed in sti_cnattach() */ + for (i = 0; i < STI_REGION_MAX; i++) + sticn_bases[i] = addr; + + sti_cnattach(&sticn_rom, &sticn_scr, bst, sticn_bases, + STI_CODEBASE_ALT); + + sticonslot = slot; } Index: src/sys/arch/hp300/hp300/autoconf.c diff -u src/sys/arch/hp300/hp300/autoconf.c:1.104 src/sys/arch/hp300/hp300/autoconf.c:1.105 --- src/sys/arch/hp300/hp300/autoconf.c:1.104 Mon Mar 24 19:42:58 2014 +++ src/sys/arch/hp300/hp300/autoconf.c Sun Apr 20 04:12:54 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.c,v 1.104 2014/03/24 19:42:58 christos Exp $ */ +/* $NetBSD: autoconf.c,v 1.105 2014/04/20 04:12:54 tsutsui Exp $ */ /*- * Copyright (c) 1996, 1997, 2002 The NetBSD Foundation, Inc. @@ -88,7 +88,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.104 2014/03/24 19:42:58 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.105 2014/04/20 04:12:54 tsutsui Exp $"); #include "dvbox.h" #include "gbox.h" @@ -97,6 +97,7 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v #include "topcat.h" #include "tvrx.h" #include "gendiofb.h" +#include "sti_sgc.h" #include "com_dio.h" #include "com_frodo.h" #include "dcm.h" @@ -150,6 +151,11 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v #include <hp300/dev/com_frodovar.h> #endif +#if NSTI_SGC > 0 +#include <hp300/dev/sgcvar.h> +#include <hp300/dev/sti_sgcvar.h> +#endif + #include <hp300/dev/diofbreg.h> #include <hp300/dev/diofbvar.h> @@ -744,6 +750,8 @@ dev_data_insert(struct dev_data *dd, ddl int conscode; void *conaddr; +static bool cninit_deferred; + void hp300_cninit(void) { @@ -824,9 +832,25 @@ hp300_cninit(void) if (!dio_scan(gendiofbcnattach)) goto find_kbd; #endif +#if NSTI_SGC > 0 + if (machineid == HP_400 || + machineid == HP_425 || + machineid == HP_433) { + struct bus_space_tag sgc_tag; + bus_space_tag_t sgc_bst; + + sgc_bst = &sgc_tag; + memset(sgc_bst, 0, sizeof(struct bus_space_tag)); + sgc_bst->bustype = HP300_BUS_SPACE_SGC; + if (sti_sgc_cnprobe(sgc_bst, sgc_slottopa(0), 0)) { + cninit_deferred = true; + goto find_kbd; + } + } +#endif #if (NDVBOX + NGBOX + NRBOX + NTOPCAT + NDVBOX + NGBOX + NHYPER + NRBOX + \ - NTOPCAT + NTVRX + NGENDIOFB) > 0 + NTOPCAT + NTVRX + NGENDIOFB + NSTI_SGC) > 0 find_kbd: #endif @@ -885,6 +909,29 @@ dio_scode_probe(int scode, int (*func)(b return (*func)(bst, (bus_addr_t)pa, scode); } +void +hp300_cninit_deferred(void) +{ + + if (!cninit_deferred) + return; + +#if NSTI_SGC > 0 + if (machineid == HP_400 || + machineid == HP_425 || + machineid == HP_433) { + struct bus_space_tag sgc_tag; + bus_space_tag_t sgc_bst; + + sgc_bst = &sgc_tag; + memset(sgc_bst, 0, sizeof(struct bus_space_tag)); + sgc_bst->bustype = HP300_BUS_SPACE_SGC; + if (sti_sgc_cnprobe(sgc_bst, sgc_slottopa(0), 0)) + sti_sgc_cnattach(sgc_bst, sgc_slottopa(0), 0); + } +#endif +} + /********************************************************************** * Mapping functions Index: src/sys/arch/hp300/hp300/machdep.c diff -u src/sys/arch/hp300/hp300/machdep.c:1.228 src/sys/arch/hp300/hp300/machdep.c:1.229 --- src/sys/arch/hp300/hp300/machdep.c:1.228 Mon Mar 24 19:42:58 2014 +++ src/sys/arch/hp300/hp300/machdep.c Sun Apr 20 04:12:54 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.228 2014/03/24 19:42:58 christos Exp $ */ +/* $NetBSD: machdep.c,v 1.229 2014/04/20 04:12:54 tsutsui Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -39,7 +39,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.228 2014/03/24 19:42:58 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.229 2014/04/20 04:12:54 tsutsui Exp $"); #include "opt_ddb.h" #include "opt_compat_netbsd.h" @@ -295,6 +295,8 @@ cpu_startup(void) pmapdebug = 0; #endif + hp300_cninit_deferred(); + if (fputype != FPU_NONE) m68k_make_fpu_idle_frame(); Index: src/sys/arch/hp300/include/autoconf.h diff -u src/sys/arch/hp300/include/autoconf.h:1.12 src/sys/arch/hp300/include/autoconf.h:1.13 --- src/sys/arch/hp300/include/autoconf.h:1.12 Sun Feb 6 18:26:52 2011 +++ src/sys/arch/hp300/include/autoconf.h Sun Apr 20 04:12:54 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.h,v 1.12 2011/02/06 18:26:52 tsutsui Exp $ */ +/* $NetBSD: autoconf.h,v 1.13 2014/04/20 04:12:54 tsutsui Exp $ */ /*- * Copyright (c) 1996, 2002 The NetBSD Foundation, Inc. @@ -39,6 +39,7 @@ extern int conscode; /* select code o extern void *conaddr; /* KVA of console device */ void hp300_cninit(void); +void hp300_cninit_deferred(void); void iomap_init(void); void * iomap(void *, int); void iounmap(void *, int); Index: src/sys/dev/ic/sti.c diff -u src/sys/dev/ic/sti.c:1.16 src/sys/dev/ic/sti.c:1.17 --- src/sys/dev/ic/sti.c:1.16 Mon Jul 11 02:30:49 2011 +++ src/sys/dev/ic/sti.c Sun Apr 20 04:12:54 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: sti.c,v 1.16 2011/07/11 02:30:49 matt Exp $ */ +/* $NetBSD: sti.c,v 1.17 2014/04/20 04:12:54 tsutsui Exp $ */ /* $OpenBSD: sti.c,v 1.61 2009/09/05 14:09:35 miod Exp $ */ @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.16 2011/07/11 02:30:49 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.17 2014/04/20 04:12:54 tsutsui Exp $"); #include "wsdisplay.h" @@ -1315,3 +1315,43 @@ sti_alloc_attr(void *v, int fg, int bg, return 0; } + +#ifdef hp300 /* XXX */ +/* + * Early console support. Only used on hp300. + */ +int +sti_cnattach(struct sti_rom *rom, struct sti_screen *scr, bus_space_tag_t memt, + bus_addr_t *bases, u_int codebase) +{ + bus_space_handle_t romh; + u_int romend; + int error; + long defattr; + + if ((error = bus_space_map(memt, bases[0], PAGE_SIZE, 0, &romh)) != 0) + return error; + + /* + * Compute real PROM size + */ + romend = sti_rom_size(memt, romh); + + bus_space_unmap(memt, romh, PAGE_SIZE); + + if ((error = bus_space_map(memt, bases[0], romend, 0, &romh)) != 0) + return error; + + bases[0] = romh; + if (sti_rom_setup(rom, memt, memt, romh, bases, codebase) != 0) + return -1; + scr->scr_rom = rom; + if (sti_screen_setup(scr, STI_CLEARSCR) != 0) + return -1; + + sti_alloc_attr(scr, 0, 0, 0, &defattr); + wsdisplay_cnattach(&scr->scr_wsd, scr, 0, 0, defattr); + + return 0; +} +#endif Index: src/sys/dev/ic/stivar.h diff -u src/sys/dev/ic/stivar.h:1.7 src/sys/dev/ic/stivar.h:1.8 --- src/sys/dev/ic/stivar.h:1.7 Mon Jul 11 02:30:49 2011 +++ src/sys/dev/ic/stivar.h Sun Apr 20 04:12:54 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: stivar.h,v 1.7 2011/07/11 02:30:49 matt Exp $ */ +/* $NetBSD: stivar.h,v 1.8 2014/04/20 04:12:54 tsutsui Exp $ */ /* $OpenBSD: stivar.h,v 1.24 2009/02/06 22:51:04 miod Exp $ */ @@ -131,4 +131,7 @@ 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); +int sti_cnattach(struct sti_rom *, struct sti_screen *, bus_space_tag_t, + bus_addr_t *, u_int); + #endif /* _IC_STIVAR_H_ */ Added files: Index: src/sys/arch/hp300/dev/sti_sgcvar.h diff -u /dev/null src/sys/arch/hp300/dev/sti_sgcvar.h:1.1 --- /dev/null Sun Apr 20 04:12:54 2014 +++ src/sys/arch/hp300/dev/sti_sgcvar.h Sun Apr 20 04:12:54 2014 @@ -0,0 +1,27 @@ +/* $NetBSD: sti_sgcvar.h,v 1.1 2014/04/20 04:12:54 tsutsui Exp $ */ +/*- + * Copyright (c) 2014 Izumi Tsutsui. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +int sti_sgc_cnprobe(bus_space_tag_t, bus_addr_t, int); +void sti_sgc_cnattach(bus_space_tag_t, bus_addr_t, int);