Source-Changes-HG archive

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

[src/perseant-stdc-iso10646]: src/sys/arch/xen 2302677



details:   https://anonhg.NetBSD.org/src/rev/6b9292daa4ee
branches:  perseant-stdc-iso10646
changeset: 850653:6b9292daa4ee
user:      cherry <cherry%NetBSD.org@localhost>
date:      Sun Jul 16 14:02:49 2017 +0000

description:
2302677

diffstat:

 sys/arch/xen/include/intr.h         |   85 +++
 sys/arch/xen/xen/evtchn.c           |  887 ++++++++++++++++++++++++++++++++++++
 sys/arch/xen/xen/pci_intr_machdep.c |  228 +++++++++
 sys/arch/xen/xen/xenevt.c           |  647 ++++++++++++++++++++++++++
 4 files changed, 1847 insertions(+), 0 deletions(-)

diffs (truncated from 1863 to 300 lines):

diff -r b0bdd987b6b8 -r 6b9292daa4ee sys/arch/xen/include/intr.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/xen/include/intr.h       Sun Jul 16 14:02:49 2017 +0000
@@ -0,0 +1,85 @@
+/*     $NetBSD: intr.h,v 1.42.2.2 2017/07/16 14:02:49 cherry Exp $     */
+/*     NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp       */
+
+/*-
+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum, and by Jason R. Thorpe.
+ *
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+#ifndef _XEN_INTR_H_
+#define        _XEN_INTR_H_
+
+#include <machine/intrdefs.h>
+
+#ifndef _LOCORE
+#include <xen/xen-public/xen.h>
+#include <x86/intr.h>
+#include <xen/xen.h>
+#include <xen/hypervisor.h>
+#include <machine/pic.h>
+#include <sys/evcnt.h>
+
+#include "opt_xen.h"
+
+
+struct cpu_info;
+/*
+ * Struct describing an event channel. 
+ */
+
+struct evtsource {
+       int ev_maxlevel;                /* max. IPL for this source */
+       uint32_t ev_imask;              /* interrupt mask */
+       struct intrhand *ev_handlers;   /* handler chain */
+       struct evcnt ev_evcnt;          /* interrupt counter */
+       struct cpu_info *ev_cpu;        /* cpu on which this event is bound */
+       char ev_evname[32];             /* event counter name */
+};
+
+extern struct intrstub xenev_stubs[];
+
+
+#ifdef MULTIPROCESSOR
+int xen_intr_biglock_wrapper(void *);
+#endif
+
+int xen_intr_map(int *, int);
+struct pic *intr_findpic(int);
+void intr_add_pcibus(struct pcibus_attach_args *);
+
+#ifdef MULTIPROCESSOR
+void xen_ipi_init(void);
+int xen_send_ipi(struct cpu_info *, uint32_t);
+void xen_broadcast_ipi(uint32_t);
+#else
+#define xen_ipi_init(_1) ((void) 0) /* nothing */
+#define xen_send_ipi(_i1, _i2) (0) /* nothing */
+#define xen_broadcast_ipi(_i1) ((void) 0) /* nothing */
+#endif /* MULTIPROCESSOR */
+#endif /* !_LOCORE */
+
+#endif /* _XEN_INTR_H_ */
diff -r b0bdd987b6b8 -r 6b9292daa4ee sys/arch/xen/xen/evtchn.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/xen/xen/evtchn.c Sun Jul 16 14:02:49 2017 +0000
@@ -0,0 +1,887 @@
+/*     $NetBSD: evtchn.c,v 1.73.2.2 2017/07/16 14:02:49 cherry Exp $   */
+
+/*
+ * Copyright (c) 2006 Manuel Bouyer.
+ *
+ * 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.
+ *
+ */
+
+/*
+ *
+ * Copyright (c) 2004 Christian Limpach.
+ * Copyright (c) 2004, K A Fraser.
+ * 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/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.73.2.2 2017/07/16 14:02:49 cherry Exp $");
+
+#include "opt_xen.h"
+#include "isa.h"
+#include "pci.h"
+
+#include <sys/param.h>
+#include <sys/cpu.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/proc.h>
+#include <sys/kmem.h>
+#include <sys/reboot.h>
+#include <sys/mutex.h>
+
+#include <uvm/uvm.h>
+
+#include <machine/intrdefs.h>
+
+#include <xen/xen.h>
+#include <xen/hypervisor.h>
+#include <xen/evtchn.h>
+#include <xen/xenfunc.h>
+
+/*
+ * This lock protects updates to the following mapping and reference-count
+ * arrays. The lock does not need to be acquired to read the mapping tables.
+ */
+static kmutex_t evtchn_lock;
+
+/* event handlers */
+struct evtsource *evtsource[NR_EVENT_CHANNELS];
+
+/* channel locks */
+static kmutex_t evtlock[NR_EVENT_CHANNELS];
+
+/* Reference counts for bindings to event channels XXX: redo for SMP */
+static uint8_t evtch_bindcount[NR_EVENT_CHANNELS];
+
+/* event-channel <-> VCPU mapping for IPIs. XXX: redo for SMP. */
+static evtchn_port_t vcpu_ipi_to_evtch[XEN_LEGACY_MAX_VCPUS];
+
+/* event-channel <-> VCPU mapping for VIRQ_TIMER.  XXX: redo for SMP. */
+static int virq_timer_to_evtch[XEN_LEGACY_MAX_VCPUS];
+
+/* event-channel <-> VIRQ mapping. */
+static int virq_to_evtch[NR_VIRQS];
+
+
+#if NPCI > 0 || NISA > 0
+/* event-channel <-> PIRQ mapping */
+static int pirq_to_evtch[NR_PIRQS];
+/* PIRQ needing notify */
+static uint32_t pirq_needs_unmask_notify[NR_EVENT_CHANNELS / 32];
+int pirq_interrupt(void *);
+physdev_op_t physdev_op_notify = {
+       .cmd = PHYSDEVOP_IRQ_UNMASK_NOTIFY,
+};
+#endif
+
+int debug_port = -1;
+
+// #define IRQ_DEBUG 4
+
+/* http://mail-index.netbsd.org/port-amd64/2004/02/22/0000.html */
+#ifdef MULTIPROCESSOR
+
+/*
+ * intr_biglock_wrapper: grab biglock and call a real interrupt handler.
+ */
+
+int
+xen_intr_biglock_wrapper(void *vp)
+{
+       struct intrhand *ih = vp;
+       int ret;
+
+       KERNEL_LOCK(1, NULL);
+
+       ret = (*ih->ih_realfun)(ih->ih_realarg);
+
+       KERNEL_UNLOCK_ONE(NULL);
+
+       return ret;
+}
+#endif /* MULTIPROCESSOR */
+
+void
+events_default_setup(void)
+{
+       int i;
+
+       /* No VCPU -> event mappings. */
+       for (i = 0; i < XEN_LEGACY_MAX_VCPUS; i++)
+               vcpu_ipi_to_evtch[i] = -1;
+
+       /* No VIRQ_TIMER -> event mappings. */
+       for (i = 0; i < XEN_LEGACY_MAX_VCPUS; i++)
+               virq_timer_to_evtch[i] = -1;
+
+       /* No VIRQ -> event mappings. */
+       for (i = 0; i < NR_VIRQS; i++)
+               virq_to_evtch[i] = -1;
+
+#if NPCI > 0 || NISA > 0
+       /* No PIRQ -> event mappings. */
+       for (i = 0; i < NR_PIRQS; i++)
+               pirq_to_evtch[i] = -1;
+       for (i = 0; i < NR_EVENT_CHANNELS / 32; i++)
+               pirq_needs_unmask_notify[i] = 0;
+#endif
+
+       /* No event-channel are 'live' right now. */
+       for (i = 0; i < NR_EVENT_CHANNELS; i++) {
+               evtsource[i] = NULL;
+               evtch_bindcount[i] = 0;
+               hypervisor_mask_event(i);
+       }
+
+}
+
+void
+events_init(void)
+{
+       mutex_init(&evtchn_lock, MUTEX_DEFAULT, IPL_NONE);
+       debug_port = bind_virq_to_evtch(VIRQ_DEBUG);
+
+       KASSERT(debug_port != -1);
+
+       aprint_verbose("VIRQ_DEBUG interrupt using event channel %d\n",
+           debug_port);
+       /*
+        * Don't call event_set_handler(), we'll use a shortcut. Just set
+        * evtsource[] to a non-NULL value so that evtchn_do_event will
+        * be called.
+        */
+       evtsource[debug_port] = (void *)-1;
+       xen_atomic_set_bit(&curcpu()->ci_evtmask[0], debug_port);
+       hypervisor_enable_event(debug_port);
+
+       x86_enable_intr();              /* at long last... */
+}
+
+bool
+events_suspend(void)
+{
+       int evtch;
+
+       x86_disable_intr();
+



Home | Main Index | Thread Index | Old Index