Line data Source code
1 : /* $OpenBSD: xspd.c,v 1.6 2017/07/18 11:42:51 mikeb Exp $ */
2 :
3 : /*
4 : * Copyright (c) 2015 Mike Belopuhov
5 : *
6 : * Permission to use, copy, modify, and distribute this software for any
7 : * purpose with or without fee is hereby granted, provided that the above
8 : * copyright notice and this permission notice appear in all copies.
9 : *
10 : * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 : * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 : * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 : * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 : * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 : * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 : * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 : */
18 :
19 : #include "xen.h"
20 :
21 : #include <sys/param.h>
22 : #include <sys/systm.h>
23 : #include <sys/atomic.h>
24 : #include <sys/device.h>
25 : #include <sys/task.h>
26 :
27 : #include <dev/pci/pcireg.h>
28 : #include <dev/pci/pcivar.h>
29 : #include <dev/pci/pcidevs.h>
30 :
31 : #include <machine/i82093var.h>
32 :
33 : #include <dev/pv/xenreg.h>
34 : #include <dev/pv/xenvar.h>
35 :
36 : struct xspd_softc {
37 : struct device sc_dev;
38 : void * sc_ih;
39 : };
40 :
41 : int xspd_match(struct device *, void *, void *);
42 : void xspd_attach(struct device *, struct device *, void *);
43 : int xspd_intr(void *);
44 :
45 : struct cfdriver xspd_cd = {
46 : NULL, "xspd", DV_DULL
47 : };
48 :
49 : struct cfattach xspd_ca = {
50 : sizeof(struct xspd_softc), xspd_match, xspd_attach, NULL, NULL
51 : };
52 :
53 : const struct pci_matchid xspd_devices[] = {
54 : { PCI_VENDOR_XENSOURCE, PCI_PRODUCT_XENSOURCE_PLATFORMDEV }
55 : };
56 :
57 : int
58 0 : xspd_match(struct device *parent, void *match, void *aux)
59 : {
60 0 : return (pci_matchbyid(aux, xspd_devices, nitems(xspd_devices)));
61 : }
62 :
63 : #if NXEN > 0
64 : void
65 0 : xspd_attach(struct device *parent, struct device *self, void *aux)
66 : {
67 0 : struct pci_attach_args *pa = (struct pci_attach_args *)aux;
68 0 : struct xspd_softc *sc = (struct xspd_softc *)self;
69 : const char *intrstr = NULL;
70 0 : pci_intr_handle_t ih;
71 0 : struct xen_hvm_param xhp;
72 : extern struct xen_softc *xen_sc;
73 :
74 0 : if (xen_sc == NULL || (xen_sc->sc_flags & XSF_CBVEC)) {
75 0 : printf("\n");
76 0 : return;
77 : }
78 :
79 0 : if (pci_intr_map(pa, &ih) != 0) {
80 0 : printf(": couldn't map interrupt\n");
81 0 : return;
82 : }
83 :
84 0 : intrstr = pci_intr_string(pa->pa_pc, ih);
85 0 : sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET | IPL_MPSAFE,
86 0 : xspd_intr, sc, sc->sc_dev.dv_xname);
87 0 : if (sc->sc_ih == NULL) {
88 0 : printf(": couldn't establish interrupt");
89 0 : if (intrstr != NULL)
90 0 : printf(" at %s", intrstr);
91 0 : printf("\n");
92 0 : return;
93 : }
94 0 : printf(": %s\n", intrstr);
95 :
96 0 : xhp.domid = DOMID_SELF;
97 0 : xhp.index = HVM_PARAM_CALLBACK_IRQ;
98 :
99 0 : if (ih.line & APIC_INT_VIA_APIC)
100 0 : xhp.value = HVM_CALLBACK_PCI_INTX(pa->pa_device,
101 : pa->pa_intrpin - 1);
102 : else
103 0 : xhp.value = HVM_CALLBACK_GSI(pci_intr_line(pa->pa_pc, ih));
104 :
105 0 : if (xen_hypercall(xen_sc, XC_HVM, 2, HVMOP_set_param, &xhp)) {
106 0 : printf("%s: failed to register callback PCI vector\n",
107 : sc->sc_dev.dv_xname);
108 0 : pci_intr_disestablish(pa->pa_pc, sc->sc_ih);
109 0 : return;
110 : }
111 :
112 0 : xen_sc->sc_flags |= XSF_CBVEC;
113 0 : }
114 :
115 : int
116 0 : xspd_intr(void *arg)
117 : {
118 0 : xen_intr();
119 :
120 0 : return (1);
121 : }
122 : #else
123 : void
124 : xspd_attach(struct device *parent, struct device *self, void *aux)
125 : {
126 : printf("\n");
127 : }
128 : #endif /* NXEN > 0 */
|