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: make device interrupts work. Introdu...



details:   https://anonhg.NetBSD.org/src/rev/9c90904d938a
branches:  trunk
changeset: 345154:9c90904d938a
user:      palle <palle%NetBSD.org@localhost>
date:      Tue May 10 19:23:59 2016 +0000

description:
sun4v: make device interrupts work. Introduce a new intrhand_alloc() function for allocation of interrupt handlers and adapt to this. Parts from OpenBSD. ok martin@

diffstat:

 sys/arch/sparc64/dev/fhc.c           |   9 ++----
 sys/arch/sparc64/dev/psycho.c        |  11 ++----
 sys/arch/sparc64/dev/pyro.c          |   8 ++---
 sys/arch/sparc64/dev/sbus.c          |  12 ++-----
 sys/arch/sparc64/dev/schizo.c        |  14 +++------
 sys/arch/sparc64/dev/vpci.c          |  44 +++++++++++++++++++++++++----
 sys/arch/sparc64/include/cpu.h       |   4 ++-
 sys/arch/sparc64/sparc64/genassym.cf |   4 ++-
 sys/arch/sparc64/sparc64/intr.c      |  29 +++++++++++++------
 sys/arch/sparc64/sparc64/locore.s    |  53 +++++++++++++++++++++++++++++++++--
 10 files changed, 132 insertions(+), 56 deletions(-)

diffs (truncated from 473 to 300 lines):

diff -r f3374bf1b0cf -r 9c90904d938a sys/arch/sparc64/dev/fhc.c
--- a/sys/arch/sparc64/dev/fhc.c        Tue May 10 15:23:39 2016 +0000
+++ b/sys/arch/sparc64/dev/fhc.c        Tue May 10 19:23:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fhc.c,v 1.3 2012/03/18 05:26:58 mrg Exp $      */
+/*     $NetBSD: fhc.c,v 1.4 2016/05/10 19:23:59 palle Exp $    */
 /*     $OpenBSD: fhc.c,v 1.17 2010/11/11 17:58:23 miod Exp $   */
 
 /*
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fhc.c,v 1.3 2012/03/18 05:26:58 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fhc.c,v 1.4 2016/05/10 19:23:59 palle Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -251,10 +251,7 @@
        vec = ((sc->sc_ign << INTMAP_IGN_SHIFT) & INTMAP_IGN) |
            INTINO(ihandle);
 
-       ih = (struct intrhand *)
-               malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT);
-       if (ih == NULL)
-               return (NULL);
+       ih = intrhand_alloc();
 
        ih->ih_ivec = ihandle;
 
diff -r f3374bf1b0cf -r 9c90904d938a sys/arch/sparc64/dev/psycho.c
--- a/sys/arch/sparc64/dev/psycho.c     Tue May 10 15:23:39 2016 +0000
+++ b/sys/arch/sparc64/dev/psycho.c     Tue May 10 19:23:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: psycho.c,v 1.123 2015/11/27 00:36:58 mrg Exp $ */
+/*     $NetBSD: psycho.c,v 1.124 2016/05/10 19:23:59 palle Exp $       */
 
 /*
  * Copyright (c) 1999, 2000 Matthew R. Green
@@ -55,7 +55,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: psycho.c,v 1.123 2015/11/27 00:36:58 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: psycho.c,v 1.124 2016/05/10 19:23:59 palle Exp $");
 
 #include "opt_ddb.h"
 
@@ -707,8 +707,7 @@
 {
        struct intrhand *ih;
 
-       ih = (struct intrhand *)malloc(sizeof(struct intrhand),
-               M_DEVBUF, M_NOWAIT);
+       ih = intrhand_alloc();
        ih->ih_arg = sc;
        ih->ih_map = mapper;
        ih->ih_clr = clearer;
@@ -1273,9 +1272,7 @@
        int ino;
        long vec = INTVEC(ihandle);
 
-       ih = malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT);
-       if (ih == NULL)
-               return (NULL);
+       ih = intrhand_alloc();
 
        ih->ih_ivec = ihandle;
 
diff -r f3374bf1b0cf -r 9c90904d938a sys/arch/sparc64/dev/pyro.c
--- a/sys/arch/sparc64/dev/pyro.c       Tue May 10 15:23:39 2016 +0000
+++ b/sys/arch/sparc64/dev/pyro.c       Tue May 10 19:23:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pyro.c,v 1.16 2015/10/02 05:22:52 msaitoh Exp $        */
+/*     $NetBSD: pyro.c,v 1.17 2016/05/10 19:23:59 palle Exp $  */
 /*     from: $OpenBSD: pyro.c,v 1.20 2010/12/05 15:15:14 kettenis Exp $        */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pyro.c,v 1.16 2015/10/02 05:22:52 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pyro.c,v 1.17 2016/05/10 19:23:59 palle Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -580,9 +580,7 @@
 
        ino |= INTVEC(ihandle);
 
-       ih = malloc(sizeof *ih, M_DEVBUF, M_NOWAIT);
-       if (ih == NULL)
-               return (NULL);
+       ih = intrhand_alloc();
 
        /* Register the map and clear intr registers */
        ih->ih_map = intrmapptr;
diff -r f3374bf1b0cf -r 9c90904d938a sys/arch/sparc64/dev/sbus.c
--- a/sys/arch/sparc64/dev/sbus.c       Tue May 10 15:23:39 2016 +0000
+++ b/sys/arch/sparc64/dev/sbus.c       Tue May 10 19:23:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sbus.c,v 1.93 2012/01/30 04:25:15 mrg Exp $ */
+/*     $NetBSD: sbus.c,v 1.94 2016/05/10 19:23:59 palle Exp $ */
 
 /*
  * Copyright (c) 1999-2002 Eduardo Horvath
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sbus.c,v 1.93 2012/01/30 04:25:15 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sbus.c,v 1.94 2016/05/10 19:23:59 palle Exp $");
 
 #include "opt_ddb.h"
 
@@ -254,8 +254,7 @@
        iommu_init(name, &sc->sc_is, 0, -1);
 
        /* Enable the over temp intr */
-       ih = (struct intrhand *)
-               malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT);
+       ih = intrhand_alloc();
        ih->ih_map = &sc->sc_sysio->therm_int_map;
        ih->ih_clr = NULL; /* &sc->sc_sysio->therm_clr_int; */
        ih->ih_fun = sbus_overtemp;
@@ -508,10 +507,7 @@
        int ipl;
        long vec = pri; 
 
-       ih = (struct intrhand *)
-               malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT);
-       if (ih == NULL)
-               return (NULL);
+       ih = intrhand_alloc();
 
        if ((vec & SBUS_INTR_COMPAT) != 0)
                ipl = vec & ~SBUS_INTR_COMPAT;
diff -r f3374bf1b0cf -r 9c90904d938a sys/arch/sparc64/dev/schizo.c
--- a/sys/arch/sparc64/dev/schizo.c     Tue May 10 15:23:39 2016 +0000
+++ b/sys/arch/sparc64/dev/schizo.c     Tue May 10 19:23:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: schizo.c,v 1.35 2015/11/27 09:34:36 martin Exp $       */
+/*     $NetBSD: schizo.c,v 1.36 2016/05/10 19:23:59 palle Exp $        */
 /*     $OpenBSD: schizo.c,v 1.55 2008/08/18 20:29:37 brad Exp $        */
 
 /*
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: schizo.c,v 1.35 2015/11/27 09:34:36 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: schizo.c,v 1.36 2016/05/10 19:23:59 palle Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -588,10 +588,8 @@
        DPRINTF(SDB_INTR, (" mapoff %" PRIx64 " clroff %" PRIx64 "\n",
            mapoff, clroff));
 
-       ih = (struct intrhand *)
-               kmem_alloc(sizeof(struct intrhand), KM_NOSLEEP);
-       if (ih == NULL)
-               return;
+       ih = intrhand_alloc();
+       
        ih->ih_arg = arg;
        intrregs = (uintptr_t)bus_space_vaddr(pbm->sp_regt, pbm->sp_intrh);
        ih->ih_map = (uint64_t *)(uintptr_t)(intrregs + mapoff);
@@ -815,9 +813,7 @@
        vec = INTVEC(ihandle);
        ino = INTINO(vec);
 
-       ih = kmem_alloc(sizeof *ih, KM_NOSLEEP);
-       if (ih == NULL)
-               return (NULL);
+       ih = intrhand_alloc();
 
        DPRINTF(SDB_INTR, ("\n%s: ihandle %x level %d fn %p arg %p\n", __func__,
            ihandle, level, handler, arg));
diff -r f3374bf1b0cf -r 9c90904d938a sys/arch/sparc64/dev/vpci.c
--- a/sys/arch/sparc64/dev/vpci.c       Tue May 10 15:23:39 2016 +0000
+++ b/sys/arch/sparc64/dev/vpci.c       Tue May 10 19:23:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vpci.c,v 1.6 2015/11/27 13:51:57 joerg Exp $   */
+/*     $NetBSD: vpci.c,v 1.7 2016/05/10 19:23:59 palle Exp $   */
 /*
  * Copyright (c) 2015 Palle Lyckegaard
  * All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vpci.c,v 1.6 2015/11/27 13:51:57 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vpci.c,v 1.7 2016/05/10 19:23:59 palle Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -114,7 +114,7 @@
 static void * vpci_pci_intr_establish(pci_chipset_tag_t pc,
                                      pci_intr_handle_t ih, int level,
                                      int (*func)(void *), void *arg);
-
+void vpci_intr_ack(struct intrhand *);
 int vpci_intr_map(const struct pci_attach_args *, pci_intr_handle_t *);
 int vpci_bus_map(bus_space_tag_t, bus_addr_t,
     bus_size_t, int, vaddr_t, bus_space_handle_t *);
@@ -596,9 +596,7 @@
        ino |= INTVEC(ihandle);
        DPRINTF(VDB_INTR, ("%s: ih %lx; level %d ino %#x\n", __func__, (u_long)ihandle, level, ino));
 
-       ih = malloc(sizeof *ih, M_DEVBUF, M_NOWAIT);
-       if (ih == NULL)
-               return (NULL);
+       ih = intrhand_alloc();
 
        ih->ih_ivec = ihandle;
        ih->ih_fun = handler;
@@ -606,12 +604,44 @@
        ih->ih_pil = level;
        ih->ih_number = ino;
        ih->ih_pending = 0;
-       
+       ih->ih_ack = vpci_intr_ack;
        intr_establish(ih->ih_pil, level != IPL_VM, ih);
 
+       uint64_t sysino = INTVEC(ihandle);
+       DPRINTF(VDB_INTR, ("vpci_intr_establish(): sysino 0x%lx\n", sysino));
+
+       int err;
+
+       err = hv_intr_settarget(sysino, cpus->ci_cpuid);
+       if (err != H_EOK)
+               printf("hv_intr_settarget(%lu, %u) failed - err = %d\n", 
+                      (long unsigned int)sysino, cpus->ci_cpuid, err);
+
+       /* Clear pending interrupts. */
+       err = hv_intr_setstate(sysino, INTR_IDLE);
+       if (err != H_EOK)
+         printf("hv_intr_setstate(%lu, INTR_IDLE) failed - err = %d\n", 
+               (long unsigned int)sysino, err);
+
+       err = hv_intr_setenabled(sysino, INTR_ENABLED);
+       if (err != H_EOK)
+         printf("hv_intr_setenabled(%lu) failed - err = %d\n", 
+               (long unsigned int)sysino, err);
+
+       DPRINTF(VDB_INTR, ("%s() returning %p\n", __func__, ih));
        return (ih);
 }
 
+void
+vpci_intr_ack(struct intrhand *ih)
+{
+       int err;
+       err = hv_intr_setstate(ih->ih_number, INTR_IDLE);
+       if (err != H_EOK)
+         panic("%s(%u, INTR_IDLE) failed - err = %d\n", 
+               __func__, ih->ih_number, err);
+}
+
 static void *
 vpci_pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
        int (*func)(void *), void *arg)
diff -r f3374bf1b0cf -r 9c90904d938a sys/arch/sparc64/include/cpu.h
--- a/sys/arch/sparc64/include/cpu.h    Tue May 10 15:23:39 2016 +0000
+++ b/sys/arch/sparc64/include/cpu.h    Tue May 10 19:23:59 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.118 2015/09/07 20:00:49 palle Exp $ */
+/*     $NetBSD: cpu.h,v 1.119 2016/05/10 19:24:00 palle Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -361,6 +361,7 @@
        struct intrhand         *ih_pending;    /* interrupt queued */
        volatile uint64_t       *ih_map;        /* Interrupt map reg */
        volatile uint64_t       *ih_clr;        /* clear interrupt reg */
+       void                    (*ih_ack)(struct intrhand *); /* ack interrupt function */
        struct evcnt            ih_cnt;         /* counter for vmstat */
        uint32_t                ih_ivec;
        char                    ih_name[32];    /* name for the above */
@@ -372,6 +373,7 @@
 void   *sparc_softintr_establish(int, int (*)(void *), void *);
 void   sparc_softintr_schedule(void *);
 void   sparc_softintr_disestablish(void *);
+struct intrhand *intrhand_alloc(void);
 
 /* cpu.c */
 int    cpu_myid(void);
diff -r f3374bf1b0cf -r 9c90904d938a sys/arch/sparc64/sparc64/genassym.cf
--- a/sys/arch/sparc64/sparc64/genassym.cf      Tue May 10 15:23:39 2016 +0000
+++ b/sys/arch/sparc64/sparc64/genassym.cf      Tue May 10 19:23:59 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.76 2015/04/01 18:38:30 palle Exp $
+#      $NetBSD: genassym.cf,v 1.77 2016/05/10 19:24:00 palle Exp $
 
 #
 # Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -170,6 +170,7 @@
 define CI_MMFSA        offsetof(struct cpu_info, ci_mmfsa)



Home | Main Index | Thread Index | Old Index