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