This adds a simple PCI device driver that has only one purpose
to allocate the interrupt vector and communicate that to the HV
in case the IDT callback method was not available.
OK?
---
sys/arch/amd64/conf/GENERIC | 2 +
sys/dev/pci/files.pci | 5 ++
sys/dev/pci/xspd.c | 119 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 126 insertions(+)
create mode 100644 sys/dev/pci/xspd.c
diff --git sys/arch/amd64/conf/GENERIC sys/arch/amd64/conf/GENERIC
index b20b62b..a4a87b0 100644
--- sys/arch/amd64/conf/GENERIC
+++ sys/arch/amd64/conf/GENERIC
@@ -599,10 +599,12 @@ radio* at bktr?
# crypto support
hifn* at pci? # Hi/fn 7751 crypto card
ubsec* at pci? # Bluesteel Networks 5xxx crypto card
safe* at pci? # SafeNet SafeXcel 1141/1741
+xspd0 at pci? # XenSource Platform Device
+
# 1-Wire devices
option ONEWIREVERBOSE
owid* at onewire? # ID
owsbm* at onewire? # Smart Battery Monitor
owtemp* at onewire? # Temperature
diff --git sys/dev/pci/files.pci sys/dev/pci/files.pci
index 1cef934..37e43a6 100644
--- sys/dev/pci/files.pci
+++ sys/dev/pci/files.pci
@@ -800,10 +800,15 @@ file dev/pci/glxpcib.c glxpcib
# Realtek RTS5209 Card Reader
attach rtsx at pci with rtsx_pci
file dev/pci/rtsx_pci.c rtsx
+# XenSource Platform Device
+device xspd
+attach xspd at pci
+file dev/pci/xspd.c xspd
+
# VirtIO
device virtio {}
file dev/pci/virtio.c virtio
attach virtio at pci with virtio_pci
diff --git sys/dev/pci/xspd.c sys/dev/pci/xspd.c
new file mode 100644
index 0000000..cdb6543
--- /dev/null
+++ sys/dev/pci/xspd.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2015 Mike Belopuhov
+ *
+ * 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/systm.h>
+#include <sys/atomic.h>
+#include <sys/device.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+#include <machine/i82093var.h>
+
+#include <dev/pv/xenreg.h>
+#include <dev/pv/xenvar.h>
+
+struct xspd_softc {
+ struct device sc_dev;
+ void * sc_ih;
+};
+
+int xspd_match(struct device *, void *, void *);
+void xspd_attach(struct device *, struct device *, void *);
+int xspd_intr(void *);
+
+struct cfdriver xspd_cd = {
+ NULL, "xspd", DV_DULL
+};
+
+struct cfattach xspd_ca = {
+ sizeof(struct xspd_softc), xspd_match, xspd_attach, NULL, NULL
+};
+
+const struct pci_matchid xspd_devices[] = {
+ { PCI_VENDOR_XENSOURCE, PCI_PRODUCT_XENSOURCE_PLATFORMDEV }
+};
+
+int
+xspd_match(struct device *parent, void *match, void *aux)
+{
+ return (pci_matchbyid(aux, xspd_devices, nitems(xspd_devices)));
+}
+
+void
+xspd_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct pci_attach_args *pa = (struct pci_attach_args *)aux;
+ struct xspd_softc *sc = (struct xspd_softc *)self;
+ const char *intrstr = NULL;
+ pci_intr_handle_t ih;
+ extern struct cfdriver xen_cd;
+ struct xen_hvm_param xhp;
+ struct xen_softc *xsc;
+
+ xsc = (struct xen_softc *)device_lookup(&xen_cd, 0);
+ if (xsc == NULL || xsc->sc_cbvec != 0) {
+ if (xsc == NULL)
+ printf(": device xen0 wasn't found");
+ printf("\n");
+ return;
+ }
+
+ if (pci_intr_map(pa, &ih) != 0) {
+ printf(": couldn't map interrupt\n");
+ return;
+ }
+
+ intrstr = pci_intr_string(pa->pa_pc, ih);
+ sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET | IPL_MPSAFE,
+ xspd_intr, sc, sc->sc_dev.dv_xname);
+ if (sc->sc_ih == NULL) {
+ printf(": couldn't establish interrupt\n");
+ if (intrstr != NULL)
+ printf(" at %s", intrstr);
+ printf("\n");
+ return;
+ }
+ printf(": %s\n", intrstr);
+
+ xhp.domid = DOMID_SELF;
+ xhp.index = HVM_PARAM_CALLBACK_IRQ;
+
+ if (ih.line & APIC_INT_VIA_APIC)
+ xhp.value = HVM_CALLBACK_PCI_INTX(pa->pa_device,
+ pa->pa_intrpin - 1);
+ else
+ xhp.value = HVM_CALLBACK_GSI(pci_intr_line(pa->pa_pc, ih));
+
+ if (xen_hypercall(xsc, hvm_op, 2, HVMOP_set_param, &xhp)) {
+ printf("%s: failed to register callback PCI vector\n",
+ sc->sc_dev.dv_xname);
+ pci_intr_disestablish(pa->pa_pc, sc->sc_ih);
+ return;
+ }
+
+ xsc->sc_cbvec = 1;
+}
+
+int
+xspd_intr(void *arg)
+{
+ xen_intr();
+
+ return (1);
+}
--
2.6.3