Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc64 port the openbsd central and fhc drivers, a...



details:   https://anonhg.NetBSD.org/src/rev/74cf02248495
branches:  trunk
changeset: 767749:74cf02248495
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Jul 29 08:37:36 2011 +0000

description:
port the openbsd central and fhc drivers, and the clock/zs attachments.
doesn't quite work yet, crashes when central_attach() calls
config_attach() (faulting address is 0xf8000000.)

diffstat:

 sys/arch/sparc64/conf/GENERIC       |   13 +-
 sys/arch/sparc64/conf/files.sparc64 |   18 ++-
 sys/arch/sparc64/dev/central.c      |  201 +++++++++++++++++++++++++
 sys/arch/sparc64/dev/centralvar.h   |   53 ++++++
 sys/arch/sparc64/dev/fhc.c          |  283 ++++++++++++++++++++++++++++++++++++
 sys/arch/sparc64/dev/fhc_central.c  |  120 +++++++++++++++
 sys/arch/sparc64/dev/fhc_mainbus.c  |  111 ++++++++++++++
 sys/arch/sparc64/dev/fhcreg.h       |   79 ++++++++++
 sys/arch/sparc64/dev/fhcvar.h       |   78 +++++++++
 sys/arch/sparc64/dev/mkclock.c      |   42 +++++-
 sys/arch/sparc64/dev/sbus.c         |    6 +-
 sys/arch/sparc64/dev/zs.c           |   81 ++++++++++-
 12 files changed, 1072 insertions(+), 13 deletions(-)

diffs (truncated from 1298 to 300 lines):

diff -r b7a1187427ff -r 74cf02248495 sys/arch/sparc64/conf/GENERIC
--- a/sys/arch/sparc64/conf/GENERIC     Thu Jul 28 22:54:02 2011 +0000
+++ b/sys/arch/sparc64/conf/GENERIC     Fri Jul 29 08:37:36 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.141 2011/07/23 21:12:58 jakllsch Exp $
+# $NetBSD: GENERIC,v 1.142 2011/07/29 08:37:37 mrg Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "GENERIC-$Revision: 1.141 $"
+#ident                 "GENERIC-$Revision: 1.142 $"
 
 maxusers       64
 
@@ -240,11 +240,14 @@
 psycho*        at mainbus0                             # PCI-based systems
 schizo*        at mainbus?
 pyro*  at mainbus?
+central* at mainbus?
+fhc*   at mainbus?
 pci*   at psycho?
 pci*   at schizo?
 pci*   at pyro?
 pci*   at ppb?
-ppb*   at pci?                                 # `APB' support.
+ppb*   at pci?
+fhc*   at central?
 ebus*  at mainbus0                             # ebus devices
 ebus*  at pci?                                 # ebus devices
 # XXX 'puc's aren't really bridges, but there's no better place for them here
@@ -266,6 +269,7 @@
 ## Mostek clock found on sbus on Ultra-1,2 systems
 ## and found on ebus on Ultra-5 and other systems.
 clock* at sbus? slot ? offset ?
+clock* at fhc?
 clock* at ebus?
 
 ## DS1287 compatible clock found on ebus on Netra X1 and other systems.
@@ -279,7 +283,8 @@
 ## Zilog 8530 serial chips.  Each has two-channels.
 ## zs0 is ttya and ttyb.  zs1 is the keyboard and mouse.
 zs*    at sbus? slot ? offset ?
-zstty* at zs? channel ?                        # ttya
+zs*    at fhc?
+zstty* at zs? channel ?                        # ttys
 kbd0   at zstty?
 ms0    at zstty?
 
diff -r b7a1187427ff -r 74cf02248495 sys/arch/sparc64/conf/files.sparc64
--- a/sys/arch/sparc64/conf/files.sparc64       Thu Jul 28 22:54:02 2011 +0000
+++ b/sys/arch/sparc64/conf/files.sparc64       Fri Jul 29 08:37:36 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.sparc64,v 1.133 2011/06/12 03:35:47 rmind Exp $
+#      $NetBSD: files.sparc64,v 1.134 2011/07/29 08:37:37 mrg Exp $
 
 # @(#)files.sparc64    8.1 (Berkeley) 7/19/93
 # sparc64-specific configuration info
@@ -42,6 +42,19 @@
 file   arch/sparc64/dev/pyro.c                 pyro
 file   arch/sparc64/dev/pci_machdep.c          psycho | schizo | pyro
 
+define  central {}
+device central: central
+attach central at mainbus
+file   arch/sparc64/dev/central.c              central
+
+define  fhc {}
+device fhc: fhc
+attach fhc at mainbus with fhc_mainbus
+attach fhc at central with fhc_central
+file   arch/sparc64/dev/fhc.c                  fhc
+file   arch/sparc64/dev/fhc_central.c          fhc_central
+file   arch/sparc64/dev/fhc_mainbus.c          fhc_mainbus
+
 # IOMMU is for both
 file   arch/sparc64/dev/iommu.c                sbus | psycho | schizo | pyro
 
@@ -56,6 +69,7 @@
 device clock: mk48txx
 attach clock at sbus with mkclock_sbus
 attach clock at ebus with mkclock_ebus
+attach clock at fhc with mkclock_fhc
 file   arch/sparc64/dev/mkclock.c              clock
 
 device rtc: mc146818
@@ -125,7 +139,7 @@
 #
 
 device zs {channel = -1}
-attach zs at sbus
+attach zs at sbus, fhc
 file   arch/sparc64/dev/zs.c                   zs needs-flag
 file   dev/ic/z8530sc.c                        zs
 
diff -r b7a1187427ff -r 74cf02248495 sys/arch/sparc64/dev/central.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sparc64/dev/central.c    Fri Jul 29 08:37:36 2011 +0000
@@ -0,0 +1,201 @@
+/*     $NetBSD: central.c,v 1.1 2011/07/29 08:37:36 mrg Exp $  */
+/*     $OpenBSD: central.c,v 1.7 2010/11/11 17:58:23 miod Exp $        */
+
+/*
+ * Copyright (c) 2004 Jason L. Wright (jason%thought.net@localhost)
+ * 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.
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/malloc.h>
+#include <sys/bus.h>
+
+#include <machine/autoconf.h>
+#include <machine/openfirm.h>
+
+#include <sparc64/dev/centralvar.h>
+
+struct central_softc {
+       bus_space_tag_t sc_bt;
+       bus_space_tag_t sc_cbt;
+       int sc_node;
+       int sc_nrange;
+       struct central_range *sc_range;
+};
+
+static int central_match(device_t, cfdata_t, void *);
+static void central_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(central, sizeof(struct central_softc),
+    central_match, central_attach, NULL, NULL);
+
+static int central_print(void *, const char *);
+static int central_get_string(int, const char *, char **);
+
+static bus_space_tag_t central_alloc_bus_tag(struct central_softc *);
+static int _central_bus_map(
+               bus_space_tag_t,
+               bus_addr_t,             /*offset*/
+               bus_size_t,             /*size*/
+               int,                    /*flags*/
+               vaddr_t,                /* XXX unused -- compat w/sparc */
+               bus_space_handle_t *);
+
+static int
+central_match(device_t parent, cfdata_t match, void *aux)
+{
+       struct mainbus_attach_args *ma = aux;
+
+       if (strcmp(ma->ma_name, "central") == 0)
+               return (1);
+       return (0);
+}
+
+static void
+central_attach(device_t parent, device_t self, void *aux)
+{
+       struct central_softc *sc = (struct central_softc *)self;
+       struct mainbus_attach_args *ma = aux;
+       int node0, node;
+
+       sc->sc_bt = ma->ma_bustag;
+       sc->sc_node = ma->ma_node;
+       sc->sc_cbt = central_alloc_bus_tag(sc);
+
+       prom_getprop(sc->sc_node, "ranges", sizeof(struct central_range),
+           &sc->sc_nrange, (void **)&sc->sc_range);
+
+       printf("\n");
+
+       node0 = firstchild(sc->sc_node);
+       for (node = node0; node; node = nextsibling(node)) {
+               struct central_attach_args ca;
+
+               bzero(&ca, sizeof(ca));
+               ca.ca_node = node;
+               ca.ca_bustag = sc->sc_cbt;
+               if (central_get_string(ca.ca_node, "name", &ca.ca_name)) {
+                       printf("can't fetch name for node 0x%x\n", node);
+                       continue;
+               }
+
+               prom_getprop(node, "reg", sizeof(struct central_reg),
+                   &ca.ca_nreg, (void **)&ca.ca_reg);
+
+               (void)config_found(self, (void *)&ca, central_print);
+
+               if (ca.ca_name != NULL)
+                       free(ca.ca_name, M_DEVBUF);
+       }
+}
+
+static int
+central_get_string(int node, const char *name, char **buf)
+{
+       int len;
+
+       len = prom_getproplen(node, name);
+       if (len < 0)
+               return (len);
+       *buf = (char *)malloc(len + 1, M_DEVBUF, M_NOWAIT);
+       if (*buf == NULL)
+               return (-1);
+
+       if (len != 0)
+               prom_getpropstringA(node, name, *buf, len + 1);
+       (*buf)[len] = '\0';
+       return (0);
+}
+
+static int
+central_print(void *args, const char *busname)
+{
+       struct central_attach_args *ca = args;
+       char *class;
+
+       if (busname != NULL) {
+               printf("\"%s\" at %s", ca->ca_name, busname);
+               class = prom_getpropstring(ca->ca_node, "device_type");
+               if (*class != '\0')
+                       printf(" class %s", class);
+       }
+       return (UNCONF);
+}
+
+static bus_space_tag_t
+central_alloc_bus_tag(struct central_softc *sc)
+{
+       struct sparc_bus_space_tag *bt;
+
+       bt = malloc(sizeof(*bt), M_DEVBUF, M_NOWAIT | M_ZERO);
+       if (bt == NULL)
+               panic("central: couldn't alloc bus tag");
+
+       bt->cookie = sc;
+       bt->parent = sc->sc_bt;
+#if 0
+       bt->asi = bt->parent->asi;
+       bt->sasi = bt->parent->sasi;
+#endif
+       bt->sparc_bus_map = _central_bus_map;
+       /* XXX bt->sparc_bus_mmap = central_bus_mmap; */
+       /* XXX bt->sparc_intr_establish = upa_intr_establish; */
+       return (bt);
+}
+
+static int
+_central_bus_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size, int flags,
+       vaddr_t v, bus_space_handle_t *hp)
+{
+       struct central_softc *sc = t->cookie;
+       int64_t slot = BUS_ADDR_IOSPACE(addr);
+       int64_t offset = BUS_ADDR_PADDR(addr);
+       int i;
+
+       if (t->parent == NULL || t->parent->sparc_bus_map == NULL) {
+               printf("\ncentral_bus_map: invalid parent");
+               return (EINVAL);
+       }
+
+
+       for (i = 0; i < sc->sc_nrange; i++) {
+               bus_addr_t paddr;
+
+               if (sc->sc_range[i].cspace != slot)
+                       continue;
+
+               paddr = offset - sc->sc_range[i].coffset;
+               paddr += sc->sc_range[i].poffset;
+               paddr |= ((bus_addr_t)sc->sc_range[i].pspace << 32);
+
+               return bus_space_map(t->parent, paddr, size, flags, hp);
+       }



Home | Main Index | Thread Index | Old Index