Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc64 sun4v: add cbus driver - from OpenBSD



details:   https://anonhg.NetBSD.org/src/rev/7f6d15abdbe8
branches:  trunk
changeset: 346074:7f6d15abdbe8
user:      palle <palle%NetBSD.org@localhost>
date:      Wed Jun 22 20:12:59 2016 +0000

description:
sun4v: add cbus driver - from OpenBSD

diffstat:

 sys/arch/sparc64/conf/GENERIC       |    5 +-
 sys/arch/sparc64/conf/files.sparc64 |    6 +-
 sys/arch/sparc64/dev/cbus.c         |  314 ++++++++++++++++++++++++++++++++++++
 sys/arch/sparc64/dev/cbusvar.h      |   42 ++++
 sys/arch/sparc64/include/cpu.h      |    4 +-
 sys/arch/sparc64/include/mdesc.h    |    9 +-
 6 files changed, 375 insertions(+), 5 deletions(-)

diffs (truncated from 469 to 300 lines):

diff -r 6d6659137483 -r 7f6d15abdbe8 sys/arch/sparc64/conf/GENERIC
--- a/sys/arch/sparc64/conf/GENERIC     Wed Jun 22 15:01:38 2016 +0000
+++ b/sys/arch/sparc64/conf/GENERIC     Wed Jun 22 20:12:59 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.190 2016/06/17 21:38:09 palle Exp $
+# $NetBSD: GENERIC,v 1.191 2016/06/22 20:12:59 palle Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident         "GENERIC-$Revision: 1.190 $"
+#ident         "GENERIC-$Revision: 1.191 $"
 
 maxusers       64
 
@@ -248,6 +248,7 @@
 # XXX 'puc's aren't really bridges, but there's no better place for them here
 puc*   at pci? dev ? function ?                # PCI "universal" comm. cards
 vbus0  at mainbus0
+cbus*  at vbus?
 
 #### Standard system devices -- all required for a given architecture
 
diff -r 6d6659137483 -r 7f6d15abdbe8 sys/arch/sparc64/conf/files.sparc64
--- a/sys/arch/sparc64/conf/files.sparc64       Wed Jun 22 15:01:38 2016 +0000
+++ b/sys/arch/sparc64/conf/files.sparc64       Wed Jun 22 20:12:59 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.sparc64,v 1.150 2016/06/17 21:38:09 palle Exp $
+#      $NetBSD: files.sparc64,v 1.151 2016/06/22 20:12:59 palle Exp $
 
 # @(#)files.sparc64    8.1 (Berkeley) 7/19/93
 # sparc64-specific configuration info
@@ -73,6 +73,10 @@
 attach vbus at mainbus
 file   arch/sparc64/dev/vbus.c                 vbus
 
+device cbus {}
+attach cbus at vbus
+file   arch/sparc64/dev/cbus.c                 cbus
+
 device clock: mk48txx
 attach clock at sbus with mkclock_sbus
 attach clock at ebus with mkclock_ebus
diff -r 6d6659137483 -r 7f6d15abdbe8 sys/arch/sparc64/dev/cbus.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sparc64/dev/cbus.c       Wed Jun 22 20:12:59 2016 +0000
@@ -0,0 +1,314 @@
+/*     $NetBSD: cbus.c,v 1.1 2016/06/22 20:13:51 palle Exp $   */
+/*     $OpenBSD: cbus.c,v 1.15 2015/09/27 11:29:20 kettenis Exp $      */
+/*
+ * Copyright (c) 2008 Mark Kettenis
+ *
+ * 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 and this permission notice 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 <sys/param.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+#include <sys/systm.h>
+
+#include <machine/autoconf.h>
+#include <machine/hypervisor.h>
+#include <machine/openfirm.h>
+#include <machine/mdesc.h>
+
+#include <sparc64/dev/cbusvar.h>
+#include <sparc64/dev/vbusvar.h>
+
+#include <sparc64/dev/iommureg.h>
+
+#ifdef DEBUG
+#define CBUSDB_AC               0x01
+#define CBUSDB_INTR             0x02
+int cbus_debug = 0x00|CBUSDB_INTR;
+#define DPRINTF(l, s)   do { if (cbus_debug & l) printf s; } while (0)
+#else
+#define DPRINTF(l, s)
+#endif
+
+struct cbus_softc {
+       device_t                sc_dv;
+       bus_space_tag_t         sc_bustag;
+       bus_dma_tag_t           sc_dmatag;
+
+       uint64_t                sc_devhandle;
+
+       /* Machine description. */
+       int                     sc_idx;
+};
+
+int    cbus_match(device_t, cfdata_t, void *);
+void   cbus_attach(device_t, device_t, void *);
+int    cbus_print(void *, const char *);
+
+CFATTACH_DECL_NEW(cbus, sizeof(struct cbus_softc),
+    cbus_match, cbus_attach, NULL, NULL);
+
+
+void *cbus_intr_establish(bus_space_tag_t, int, int,
+    int (*)(void *), void *, void (*)(void));
+void cbus_intr_ack(struct intrhand *);
+bus_space_tag_t cbus_alloc_bus_tag(struct cbus_softc *, bus_space_tag_t);
+
+int cbus_get_channel_endpoint(struct cbus_softc *,
+                             struct cbus_attach_args *);
+
+int
+cbus_match(device_t parent, cfdata_t match, void *aux)
+{
+       struct vbus_attach_args *va = aux;
+
+       if (strcmp(va->va_name, "channel-devices") == 0)
+               return (1);
+
+       return (0);
+}
+
+void
+cbus_attach(device_t parent, device_t self, void *aux)
+{
+        struct cbus_softc *sc = device_private(self);
+       struct vbus_attach_args *va = aux;
+       int node;
+       int reg;
+
+       sc->sc_bustag = cbus_alloc_bus_tag(sc, va->va_bustag);
+       sc->sc_dmatag = va->va_dmatag;
+
+       if (OF_getprop(va->va_node, "reg", &reg, sizeof(reg)) != sizeof(reg))
+               return;
+       sc->sc_devhandle = reg;
+
+       printf("\n");
+
+       sc->sc_idx = mdesc_find(va->va_name, va->va_reg[0]);
+       if (sc->sc_idx == -1) {
+         DPRINTF(CBUSDB_AC, ("cbus_attach() - no idx\n"));
+         return;
+       }
+
+       for (node = OF_child(va->va_node); node; node = OF_peer(node)) {
+               struct cbus_attach_args ca;
+               char buf[32];
+
+               bzero(&ca, sizeof(ca));
+               ca.ca_node = node;
+               if (OF_getprop(node, "name", buf, sizeof(buf)) <= 0)
+                       continue;
+               DPRINTF(CBUSDB_AC, ("cbus_attach() - buf %s\n", buf));
+               ca.ca_name = buf;
+               ca.ca_bustag = sc->sc_bustag;
+               ca.ca_dmatag = sc->sc_dmatag;
+               prom_getprop(node, "reg", sizeof(*ca.ca_reg),
+                            &ca.ca_nreg, (void **)&ca.ca_reg);
+               int rc = cbus_get_channel_endpoint(sc, &ca);
+               DPRINTF(CBUSDB_AC, ("cbus_attach() - cbus_get_channel_endpoint() %d\n", rc));
+               if ( rc != 0) {
+                 continue;
+               }
+
+               config_found(self, &ca, cbus_print);
+
+       }
+}
+
+int
+cbus_print(void *aux, const char *name)
+{
+       struct cbus_attach_args *ca = aux;
+       DPRINTF(CBUSDB_AC, ("cbus_print() name %s\n", name));
+
+       if (name)
+               printf("\"%s\" at %s", ca->ca_name, name);
+       if (ca->ca_id != -1)
+         printf(" chan 0x%llx", (long long unsigned int)ca->ca_id);
+       return (UNCONF);
+}
+
+int
+cbus_intr_setstate(bus_space_tag_t t, uint64_t devino, uint64_t state)
+{
+       struct cbus_softc *sc = t->cookie;
+       uint64_t devhandle = sc->sc_devhandle;
+       int err;
+
+       err = hv_vintr_setstate(devhandle, devino, state);
+       if (err != H_EOK)
+               return (-1);
+
+       return (0);
+}
+
+int
+cbus_intr_setenabled(bus_space_tag_t t, uint64_t devino, uint64_t enabled)
+{
+       struct cbus_softc *sc = t->cookie;
+       uint64_t devhandle = sc->sc_devhandle;
+       int err;
+
+       err = hv_vintr_setenabled(devhandle, devino, enabled);
+       if (err != H_EOK)
+               return (-1);
+
+       return (0);
+}
+
+void *
+cbus_intr_establish(bus_space_tag_t t, int ihandle, int level,
+       int (*handler)(void *), void *arg, void (*fastvec)(void) /* ignored */)
+{
+       struct cbus_softc *sc = t->cookie;
+       uint64_t devhandle = sc->sc_devhandle;
+       uint64_t devino = ihandle;
+       struct intrhand *ih;
+       int ino;
+       int err;
+
+       ino = INTINO(ihandle);
+
+       DPRINTF(CBUSDB_INTR, ("cbus_intr_establish(): ino 0x%x\n", ino));
+
+       ih = intrhand_alloc();
+
+       ih->ih_ivec = ihandle;
+       ih->ih_fun = handler;
+       ih->ih_arg = arg;
+       ih->ih_pil = level;
+       ih->ih_number = ino;
+       ih->ih_bus = t;
+
+       err = hv_vintr_setenabled(devhandle, devino, INTR_DISABLED);
+       if (err != H_EOK) {
+               printf("hv_vintr_setenabled: %d\n", err);
+               return (NULL);
+       }
+
+       err = hv_vintr_setcookie(devhandle, devino, (vaddr_t)ih);
+       if (err != H_EOK) {
+               printf("hv_vintr_setcookie: %d\n", err);
+               return (NULL);
+       }
+
+       ih->ih_ack = cbus_intr_ack;
+
+       err = hv_vintr_settarget(devhandle, devino, cpus->ci_cpuid);
+       if (err != H_EOK) {
+               printf("hv_vintr_settarget: %d\n", err);
+               return (NULL);
+       }
+
+       /* Clear pending interrupts. */
+       err = hv_vintr_setstate(devhandle, devino, INTR_IDLE);
+       if (err != H_EOK) {
+               printf("hv_vintr_setstate: %d\n", err);
+               return (NULL);
+       }
+
+       return (ih);
+}
+
+void
+cbus_intr_ack(struct intrhand *ih)
+{
+       DPRINTF(CBUSDB_INTR, ("cbus_intr_ack()\n"));
+       bus_space_tag_t t = ih->ih_bus;
+       struct cbus_softc *sc = t->cookie;
+       uint64_t devhandle = sc->sc_devhandle;
+       uint64_t devino = ih->ih_number;
+
+       hv_vintr_setstate(devhandle, devino, INTR_IDLE);
+}
+
+bus_space_tag_t
+cbus_alloc_bus_tag(struct cbus_softc *sc, bus_space_tag_t parent)
+{
+       struct sparc_bus_space_tag *bt;
+
+       bt = malloc(sizeof(*bt), M_DEVBUF, M_NOWAIT | M_ZERO);
+       if (bt == NULL)
+               panic("could not allocate cbus bus tag");
+
+       bt->cookie = sc;
+       bt->parent = parent;
+       bt->sparc_bus_map = parent->sparc_bus_map;
+       bt->sparc_intr_establish = cbus_intr_establish;
+
+       return (bt);



Home | Main Index | Thread Index | Old Index