xref: /netbsd/sys/dev/acpi/vmbus_acpi.c (revision e9607ed6)
1 /*	$NetBSD: vmbus_acpi.c,v 1.4 2021/01/29 15:49:55 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 2018 Kimihiro Nonaka <nonaka@NetBSD.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. The name of the author may not be used to endorse or promote products
13  *    derived from this software without specific prior written permission.
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,
20  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: vmbus_acpi.c,v 1.4 2021/01/29 15:49:55 thorpej Exp $");
30 
31 #include <sys/param.h>
32 #include <sys/device.h>
33 #include <sys/systm.h>
34 #include <sys/kmem.h>
35 
36 #include <dev/acpi/acpireg.h>
37 #include <dev/acpi/acpivar.h>
38 
39 #include <dev/hyperv/vmbusvar.h>
40 
41 #define _COMPONENT	ACPI_RESOURCE_COMPONENT
42 ACPI_MODULE_NAME	("vmbus_acpi")
43 
44 static int	vmbus_acpi_match(device_t, cfdata_t, void *);
45 static void	vmbus_acpi_attach(device_t, device_t, void *);
46 static int	vmbus_acpi_detach(device_t, int);
47 
48 struct vmbus_acpi_softc {
49 	struct vmbus_softc sc;
50 };
51 
52 CFATTACH_DECL_NEW(vmbus_acpi, sizeof(struct vmbus_acpi_softc),
53     vmbus_acpi_match, vmbus_acpi_attach, vmbus_acpi_detach, NULL);
54 
55 static const struct device_compatible_entry compat_data[] = {
56 	{ .compat = "VMBUS" },
57 	{ .compat = "VMBus" },
58 	DEVICE_COMPAT_EOL
59 };
60 
61 static int
vmbus_acpi_match(device_t parent,cfdata_t match,void * opaque)62 vmbus_acpi_match(device_t parent, cfdata_t match, void *opaque)
63 {
64 	struct acpi_attach_args *aa = opaque;
65 	int ret;
66 
67 	ret = acpi_compatible_match(aa, compat_data);
68 
69 	if (!vmbus_match(parent, match, opaque))
70 		return 0;
71 
72 	return ret;
73 }
74 
75 static void
vmbus_acpi_attach(device_t parent,device_t self,void * opaque)76 vmbus_acpi_attach(device_t parent, device_t self, void *opaque)
77 {
78 	struct vmbus_acpi_softc *sc = device_private(self);
79 	struct acpi_attach_args *aa = opaque;
80 
81 	sc->sc.sc_dev = self;
82 	sc->sc.sc_iot = aa->aa_iot;
83 	sc->sc.sc_memt = aa->aa_memt;
84 	sc->sc.sc_dmat = BUS_DMA_TAG_VALID(aa->aa_dmat64) ?
85 	    aa->aa_dmat64 : aa->aa_dmat;
86 
87 	if (vmbus_attach(&sc->sc))
88 		return;
89 
90 	(void)pmf_device_register(self, NULL, NULL);
91 }
92 
93 static int
vmbus_acpi_detach(device_t self,int flags)94 vmbus_acpi_detach(device_t self, int flags)
95 {
96 	struct vmbus_acpi_softc *sc = device_private(self);
97 	int rv;
98 
99 	rv = vmbus_detach(&sc->sc, flags);
100 	if (rv)
101 		return rv;
102 
103 	pmf_device_deregister(self);
104 
105 	return 0;
106 }
107