2 * Copyright (c) 2013 Roger Pau Monné <roger.pau@citrix.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
32 #include <sys/kernel.h>
33 #include <sys/module.h>
34 #include <sys/sysctl.h>
35 #include <sys/systm.h>
38 #include <contrib/dev/acpica/include/acpi.h>
40 #include <dev/acpica/acpivar.h>
43 #include <machine/nexusvar.h>
44 #include <machine/intr_machdep.h>
46 #include <xen/xen-os.h>
47 #include <xen/xen_intr.h>
48 #include <xen/xen_msi.h>
53 * Xen nexus(4) driver.
56 nexus_xen_probe(device_t dev)
62 return (BUS_PROBE_SPECIFIC);
66 nexus_xen_attach(device_t dev)
69 device_t acpi_dev = NULL;
71 nexus_init_resources();
72 bus_generic_probe(dev);
74 if (xen_initial_domain()) {
75 /* Disable some ACPI devices that are not usable by Dom0 */
76 acpi_cpu_disabled = true;
77 acpi_hpet_disabled = true;
78 acpi_timer_disabled = true;
80 acpi_dev = BUS_ADD_CHILD(dev, 10, "acpi", 0);
82 panic("Unable to add ACPI bus to Xen Dom0");
85 error = bus_generic_attach(dev);
86 if (xen_initial_domain() && (error == 0))
87 acpi_install_wakeup_handler(device_get_softc(acpi_dev));
93 nexus_xen_config_intr(device_t dev, int irq, enum intr_trigger trig,
94 enum intr_polarity pol)
99 * ISA and PCI intline IRQs are not preregistered on Xen, so
100 * intercept calls to configure those and register them on the fly.
102 if ((irq < first_msi_irq) && (intr_lookup_source(irq) == NULL)) {
103 ret = xen_register_pirq(irq, trig, pol);
108 return (intr_config_intr(irq, trig, pol));
112 nexus_xen_alloc_msix(device_t pcib, device_t dev, int *irq)
115 return (xen_msix_alloc(dev, irq));
119 nexus_xen_release_msix(device_t pcib, device_t dev, int irq)
122 return (xen_msix_release(irq));
126 nexus_xen_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs)
129 return (xen_msi_alloc(dev, count, maxcount, irqs));
133 nexus_xen_release_msi(device_t pcib, device_t dev, int count, int *irqs)
136 return (xen_msi_release(irqs, count));
140 nexus_xen_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data)
143 return (xen_msi_map(irq, addr, data));
146 static device_method_t nexus_xen_methods[] = {
147 /* Device interface */
148 DEVMETHOD(device_probe, nexus_xen_probe),
149 DEVMETHOD(device_attach, nexus_xen_attach),
152 DEVMETHOD(bus_config_intr, nexus_xen_config_intr),
155 DEVMETHOD(pcib_alloc_msi, nexus_xen_alloc_msi),
156 DEVMETHOD(pcib_release_msi, nexus_xen_release_msi),
157 DEVMETHOD(pcib_alloc_msix, nexus_xen_alloc_msix),
158 DEVMETHOD(pcib_release_msix, nexus_xen_release_msix),
159 DEVMETHOD(pcib_map_msi, nexus_xen_map_msi),
164 DEFINE_CLASS_1(nexus, nexus_xen_driver, nexus_xen_methods, 1, nexus_driver);
165 static devclass_t nexus_devclass;
167 DRIVER_MODULE(nexus_xen, root, nexus_xen_driver, nexus_devclass, 0, 0);