Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add proper consinit(9) support for sti(4) at sgc framebu...



details:   https://anonhg.NetBSD.org/src/rev/a918d1e01c33
branches:  trunk
changeset: 328840:a918d1e01c33
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sun Apr 20 04:12:54 2014 +0000

description:
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...

diffstat:

 sys/arch/hp300/conf/files.hp300   |    4 +-
 sys/arch/hp300/dev/com_frodo.c    |   28 +++++++-
 sys/arch/hp300/dev/sti_sgc.c      |  126 +++++++++++++++++++++++++++----------
 sys/arch/hp300/dev/sti_sgcvar.h   |   27 ++++++++
 sys/arch/hp300/hp300/autoconf.c   |   53 +++++++++++++++-
 sys/arch/hp300/hp300/machdep.c    |    6 +-
 sys/arch/hp300/include/autoconf.h |    3 +-
 sys/dev/ic/sti.c                  |   44 ++++++++++++-
 sys/dev/ic/stivar.h               |    5 +-
 9 files changed, 247 insertions(+), 49 deletions(-)

diffs (truncated from 516 to 300 lines):

diff -r 03bc789f3e0e -r a918d1e01c33 sys/arch/hp300/conf/files.hp300
--- a/sys/arch/hp300/conf/files.hp300   Sun Apr 20 00:20:01 2014 +0000
+++ b/sys/arch/hp300/conf/files.hp300   Sun Apr 20 04:12:54 2014 +0000
@@ -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 @@
 #
 
 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
diff -r 03bc789f3e0e -r a918d1e01c33 sys/arch/hp300/dev/com_frodo.c
--- a/sys/arch/hp300/dev/com_frodo.c    Sun Apr 20 00:20:01 2014 +0000
+++ b/sys/arch/hp300/dev/com_frodo.c    Sun Apr 20 04:12:54 2014 +0000
@@ -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 @@
 {
        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))
diff -r 03bc789f3e0e -r a918d1e01c33 sys/arch/hp300/dev/sti_sgc.c
--- a/sys/arch/hp300/dev/sti_sgc.c      Sun Apr 20 00:20:01 2014 +0000
+++ b/sys/arch/hp300/dev/sti_sgc.c      Sun Apr 20 04:12:54 2014 +0000
@@ -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 @@
 #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 @@
 {
        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;
+
+       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);
 
-       sc->sc_dev = self;
-       sc->sc_enable_rom = NULL;
-       sc->sc_disable_rom = NULL;
+               if (bus_space_map(saa->saa_iot, base, romend, 0, &romh)) {
+                       aprint_error(": can't map frame buffer");
+                       return;
+               }
 
-       if (bus_space_map(iot, pa, romend, 0, &romh)) {
-               aprint_error(": can't map ROM(2)");
-               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 @@
         * 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;
+
+       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;
 
-       sti_end_attach(sc);
+ 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;
+}
diff -r 03bc789f3e0e -r a918d1e01c33 sys/arch/hp300/dev/sti_sgcvar.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hp300/dev/sti_sgcvar.h   Sun Apr 20 04:12:54 2014 +0000
@@ -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);
diff -r 03bc789f3e0e -r a918d1e01c33 sys/arch/hp300/hp300/autoconf.c
--- a/sys/arch/hp300/hp300/autoconf.c   Sun Apr 20 00:20:01 2014 +0000
+++ b/sys/arch/hp300/hp300/autoconf.c   Sun Apr 20 04:12:54 2014 +0000
@@ -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 @@
  */



Home | Main Index | Thread Index | Old Index