]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/x86/xen/xenpv.c
Update serf-1.3.6 -> 1.3.7
[FreeBSD/FreeBSD.git] / sys / x86 / xen / xenpv.c
1 /*
2  * Copyright (c) 2014 Roger Pau MonnĂ© <roger.pau@citrix.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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
24  * SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/bus.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/pcpu.h>
36 #include <sys/smp.h>
37
38 #include <xen/xen-os.h>
39 #include <xen/gnttab.h>
40
41 static devclass_t xenpv_devclass;
42
43 static void
44 xenpv_identify(driver_t *driver, device_t parent)
45 {
46         if (!xen_domain())
47                 return;
48
49         /* Make sure there's only one xenpv device. */
50         if (devclass_get_device(xenpv_devclass, 0))
51                 return;
52
53         if (BUS_ADD_CHILD(parent, 0, "xenpv", 0) == NULL)
54                 panic("Unable to attach xenpv bus.");
55 }
56
57 static int
58 xenpv_probe(device_t dev)
59 {
60
61         device_set_desc(dev, "Xen PV bus");
62         return (BUS_PROBE_NOWILDCARD);
63 }
64
65 static int
66 xenpv_attach(device_t dev)
67 {
68         device_t child;
69         int error;
70
71         /* Initialize grant table before any Xen specific device is attached */
72         error = gnttab_init(dev);
73         if (error != 0) {
74                 device_printf(dev, "error initializing grant table: %d\n",
75                     error);
76                 return (error);
77         }
78
79         /*
80          * Let our child drivers identify any child devices that they
81          * can find.  Once that is done attach any devices that we
82          * found.
83          */
84         bus_generic_probe(dev);
85         bus_generic_attach(dev);
86
87         if (!devclass_get_device(devclass_find("isa"), 0)) {
88                 child = BUS_ADD_CHILD(dev, 0, "isa", 0);
89                 if (child == NULL)
90                         panic("Failed to attach ISA bus.");
91                 device_probe_and_attach(child);
92         }
93
94         return (0);
95 }
96
97 static device_method_t xenpv_methods[] = {
98         /* Device interface */
99         DEVMETHOD(device_identify,              xenpv_identify),
100         DEVMETHOD(device_probe,                 xenpv_probe),
101         DEVMETHOD(device_attach,                xenpv_attach),
102         DEVMETHOD(device_suspend,               bus_generic_suspend),
103         DEVMETHOD(device_resume,                bus_generic_resume),
104
105         /* Bus interface */
106         DEVMETHOD(bus_add_child,                bus_generic_add_child),
107         DEVMETHOD(bus_alloc_resource,           bus_generic_alloc_resource),
108         DEVMETHOD(bus_release_resource,         bus_generic_release_resource),
109         DEVMETHOD(bus_activate_resource,        bus_generic_activate_resource),
110         DEVMETHOD(bus_deactivate_resource,      bus_generic_deactivate_resource),
111
112         DEVMETHOD_END
113 };
114
115 static driver_t xenpv_driver = {
116         "xenpv",
117         xenpv_methods,
118         0,
119 };
120
121 DRIVER_MODULE(xenpv, nexus, xenpv_driver, xenpv_devclass, 0, 0);