xref: /freebsd/sys/dev/hyperv/vmbus/vmbus_res.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
1554e6778SSepherosa Ziehau /*-
2554e6778SSepherosa Ziehau  * Copyright (c) 2017 Microsoft Corp.
3554e6778SSepherosa Ziehau  * All rights reserved.
4554e6778SSepherosa Ziehau  *
5554e6778SSepherosa Ziehau  * Redistribution and use in source and binary forms, with or without
6554e6778SSepherosa Ziehau  * modification, are permitted provided that the following conditions
7554e6778SSepherosa Ziehau  * are met:
8554e6778SSepherosa Ziehau  * 1. Redistributions of source code must retain the above copyright
9554e6778SSepherosa Ziehau  *    notice unmodified, this list of conditions, and the following
10554e6778SSepherosa Ziehau  *    disclaimer.
11554e6778SSepherosa Ziehau  * 2. Redistributions in binary form must reproduce the above copyright
12554e6778SSepherosa Ziehau  *    notice, this list of conditions and the following disclaimer in the
13554e6778SSepherosa Ziehau  *    documentation and/or other materials provided with the distribution.
14554e6778SSepherosa Ziehau  *
15554e6778SSepherosa Ziehau  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16554e6778SSepherosa Ziehau  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17554e6778SSepherosa Ziehau  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18554e6778SSepherosa Ziehau  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19554e6778SSepherosa Ziehau  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20554e6778SSepherosa Ziehau  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21554e6778SSepherosa Ziehau  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22554e6778SSepherosa Ziehau  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23554e6778SSepherosa Ziehau  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24554e6778SSepherosa Ziehau  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25554e6778SSepherosa Ziehau  */
26554e6778SSepherosa Ziehau 
27554e6778SSepherosa Ziehau #include <sys/param.h>
28554e6778SSepherosa Ziehau #include <sys/kernel.h>
29554e6778SSepherosa Ziehau #include <sys/bus.h>
30554e6778SSepherosa Ziehau #include <sys/module.h>
31554e6778SSepherosa Ziehau 
32554e6778SSepherosa Ziehau #include <contrib/dev/acpica/include/acpi.h>
33554e6778SSepherosa Ziehau #include <dev/acpica/acpivar.h>
34554e6778SSepherosa Ziehau 
35554e6778SSepherosa Ziehau #include <dev/hyperv/include/hyperv.h>
36554e6778SSepherosa Ziehau 
37554e6778SSepherosa Ziehau #include "acpi_if.h"
38554e6778SSepherosa Ziehau #include "bus_if.h"
39554e6778SSepherosa Ziehau 
40554e6778SSepherosa Ziehau static int		vmbus_res_probe(device_t);
41554e6778SSepherosa Ziehau static int		vmbus_res_attach(device_t);
42554e6778SSepherosa Ziehau static int		vmbus_res_detach(device_t);
43554e6778SSepherosa Ziehau 
44554e6778SSepherosa Ziehau static device_method_t vmbus_res_methods[] = {
45554e6778SSepherosa Ziehau 	/* Device interface */
46554e6778SSepherosa Ziehau 	DEVMETHOD(device_probe,			vmbus_res_probe),
47554e6778SSepherosa Ziehau 	DEVMETHOD(device_attach,		vmbus_res_attach),
48554e6778SSepherosa Ziehau 	DEVMETHOD(device_detach,		vmbus_res_detach),
49554e6778SSepherosa Ziehau 	DEVMETHOD(device_shutdown,		bus_generic_shutdown),
50554e6778SSepherosa Ziehau 	DEVMETHOD(device_suspend,		bus_generic_suspend),
51554e6778SSepherosa Ziehau 	DEVMETHOD(device_resume,		bus_generic_resume),
52554e6778SSepherosa Ziehau 
53554e6778SSepherosa Ziehau 	DEVMETHOD_END
54554e6778SSepherosa Ziehau };
55554e6778SSepherosa Ziehau 
56554e6778SSepherosa Ziehau static driver_t vmbus_res_driver = {
57554e6778SSepherosa Ziehau 	"vmbus_res",
58554e6778SSepherosa Ziehau 	vmbus_res_methods,
59554e6778SSepherosa Ziehau 	1
60554e6778SSepherosa Ziehau };
61554e6778SSepherosa Ziehau 
62*c1cef544SJohn Baldwin DRIVER_MODULE(vmbus_res, acpi, vmbus_res_driver, NULL, NULL);
63554e6778SSepherosa Ziehau MODULE_DEPEND(vmbus_res, acpi, 1, 1, 1);
64554e6778SSepherosa Ziehau MODULE_VERSION(vmbus_res, 1);
65554e6778SSepherosa Ziehau 
66554e6778SSepherosa Ziehau static int
vmbus_res_probe(device_t dev)67554e6778SSepherosa Ziehau vmbus_res_probe(device_t dev)
68554e6778SSepherosa Ziehau {
69554e6778SSepherosa Ziehau 	char *id[] = { "VMBUS", NULL };
705efca36fSTakanori Watanabe 	int rv;
71554e6778SSepherosa Ziehau 
725efca36fSTakanori Watanabe 	if (device_get_unit(dev) != 0 || vm_guest != VM_GUEST_HV ||
73554e6778SSepherosa Ziehau 	    (hyperv_features & CPUID_HV_MSR_SYNIC) == 0)
74554e6778SSepherosa Ziehau 		return (ENXIO);
755efca36fSTakanori Watanabe 	rv = ACPI_ID_PROBE(device_get_parent(dev), dev, id, NULL);
765efca36fSTakanori Watanabe 	if (rv <= 0)
77554e6778SSepherosa Ziehau 		device_set_desc(dev, "Hyper-V Vmbus Resource");
785efca36fSTakanori Watanabe 	return (rv);
79554e6778SSepherosa Ziehau }
80554e6778SSepherosa Ziehau 
81554e6778SSepherosa Ziehau static int
vmbus_res_attach(device_t dev __unused)82554e6778SSepherosa Ziehau vmbus_res_attach(device_t dev __unused)
83554e6778SSepherosa Ziehau {
84554e6778SSepherosa Ziehau 
85554e6778SSepherosa Ziehau 	return (0);
86554e6778SSepherosa Ziehau }
87554e6778SSepherosa Ziehau 
88554e6778SSepherosa Ziehau static int
vmbus_res_detach(device_t dev __unused)89554e6778SSepherosa Ziehau vmbus_res_detach(device_t dev __unused)
90554e6778SSepherosa Ziehau {
91554e6778SSepherosa Ziehau 
92554e6778SSepherosa Ziehau 	return (0);
93554e6778SSepherosa Ziehau }
94