xref: /freebsd/sys/dev/hyperv/vmbus/vmbus_res.c (revision 02e9120893770924227138ba49df1edb3896112a)
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/param.h>
28 #include <sys/kernel.h>
29 #include <sys/bus.h>
30 #include <sys/module.h>
31 
32 #include <contrib/dev/acpica/include/acpi.h>
33 #include <dev/acpica/acpivar.h>
34 
35 #include <dev/hyperv/include/hyperv.h>
36 
37 #include "acpi_if.h"
38 #include "bus_if.h"
39 
40 static int		vmbus_res_probe(device_t);
41 static int		vmbus_res_attach(device_t);
42 static int		vmbus_res_detach(device_t);
43 
44 static device_method_t vmbus_res_methods[] = {
45 	/* Device interface */
46 	DEVMETHOD(device_probe,			vmbus_res_probe),
47 	DEVMETHOD(device_attach,		vmbus_res_attach),
48 	DEVMETHOD(device_detach,		vmbus_res_detach),
49 	DEVMETHOD(device_shutdown,		bus_generic_shutdown),
50 	DEVMETHOD(device_suspend,		bus_generic_suspend),
51 	DEVMETHOD(device_resume,		bus_generic_resume),
52 
53 	DEVMETHOD_END
54 };
55 
56 static driver_t vmbus_res_driver = {
57 	"vmbus_res",
58 	vmbus_res_methods,
59 	1
60 };
61 
62 DRIVER_MODULE(vmbus_res, acpi, vmbus_res_driver, NULL, NULL);
63 MODULE_DEPEND(vmbus_res, acpi, 1, 1, 1);
64 MODULE_VERSION(vmbus_res, 1);
65 
66 static int
67 vmbus_res_probe(device_t dev)
68 {
69 	char *id[] = { "VMBUS", NULL };
70 	int rv;
71 
72 	if (device_get_unit(dev) != 0 || vm_guest != VM_GUEST_HV ||
73 	    (hyperv_features & CPUID_HV_MSR_SYNIC) == 0)
74 		return (ENXIO);
75 	rv = ACPI_ID_PROBE(device_get_parent(dev), dev, id, NULL);
76 	if (rv <= 0)
77 		device_set_desc(dev, "Hyper-V Vmbus Resource");
78 	return (rv);
79 }
80 
81 static int
82 vmbus_res_attach(device_t dev __unused)
83 {
84 
85 	return (0);
86 }
87 
88 static int
89 vmbus_res_detach(device_t dev __unused)
90 {
91 
92 	return (0);
93 }
94