xref: /freebsd/sys/dev/hyperv/vmbus/vmbus_res.c (revision 10ff414c14eef433d8157f0c17904d740693933b)
1 /*-
2  * Copyright (c) 2017 Microsoft Corp.
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 unmodified, this list of conditions, and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 #include <sys/param.h>
31 #include <sys/kernel.h>
32 #include <sys/bus.h>
33 #include <sys/module.h>
34 
35 #include <contrib/dev/acpica/include/acpi.h>
36 #include <dev/acpica/acpivar.h>
37 
38 #include <dev/hyperv/include/hyperv.h>
39 
40 #include "acpi_if.h"
41 #include "bus_if.h"
42 
43 static int		vmbus_res_probe(device_t);
44 static int		vmbus_res_attach(device_t);
45 static int		vmbus_res_detach(device_t);
46 
47 static device_method_t vmbus_res_methods[] = {
48 	/* Device interface */
49 	DEVMETHOD(device_probe,			vmbus_res_probe),
50 	DEVMETHOD(device_attach,		vmbus_res_attach),
51 	DEVMETHOD(device_detach,		vmbus_res_detach),
52 	DEVMETHOD(device_shutdown,		bus_generic_shutdown),
53 	DEVMETHOD(device_suspend,		bus_generic_suspend),
54 	DEVMETHOD(device_resume,		bus_generic_resume),
55 
56 	DEVMETHOD_END
57 };
58 
59 static driver_t vmbus_res_driver = {
60 	"vmbus_res",
61 	vmbus_res_methods,
62 	1
63 };
64 
65 static devclass_t vmbus_res_devclass;
66 
67 DRIVER_MODULE(vmbus_res, acpi, vmbus_res_driver, vmbus_res_devclass,
68     NULL, NULL);
69 MODULE_DEPEND(vmbus_res, acpi, 1, 1, 1);
70 MODULE_VERSION(vmbus_res, 1);
71 
72 static int
73 vmbus_res_probe(device_t dev)
74 {
75 	char *id[] = { "VMBUS", NULL };
76 	int rv;
77 
78 	if (device_get_unit(dev) != 0 || vm_guest != VM_GUEST_HV ||
79 	    (hyperv_features & CPUID_HV_MSR_SYNIC) == 0)
80 		return (ENXIO);
81 	rv = ACPI_ID_PROBE(device_get_parent(dev), dev, id, NULL);
82 	if (rv <= 0)
83 		device_set_desc(dev, "Hyper-V Vmbus Resource");
84 	return (rv);
85 }
86 
87 static int
88 vmbus_res_attach(device_t dev __unused)
89 {
90 
91 	return (0);
92 }
93 
94 static int
95 vmbus_res_detach(device_t dev __unused)
96 {
97 
98 	return (0);
99 }
100