vmbus_acpi.c revision 1.1
1/* $NetBSD: vmbus_acpi.c,v 1.1 2019/02/15 08:54:01 nonaka 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.1 2019/02/15 08:54:01 nonaka 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 42ACPI_MODULE_NAME ("vmbus_acpi") 43 44static int vmbus_acpi_match(device_t, cfdata_t, void *); 45static void vmbus_acpi_attach(device_t, device_t, void *); 46static int vmbus_acpi_detach(device_t, int); 47 48struct vmbus_acpi_softc { 49 struct vmbus_softc sc; 50}; 51 52CFATTACH_DECL_NEW(vmbus_acpi, sizeof(struct vmbus_acpi_softc), 53 vmbus_acpi_match, vmbus_acpi_attach, vmbus_acpi_detach, NULL); 54 55static const char * const vmbus_acpi_ids[] = { 56 "VMBUS", 57 "VMBus", 58 NULL 59}; 60 61static int 62vmbus_acpi_match(device_t parent, cfdata_t match, void *opaque) 63{ 64 struct acpi_attach_args *aa = opaque; 65 66 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 67 return 0; 68 69 if (!acpi_match_hid(aa->aa_node->ad_devinfo, vmbus_acpi_ids)) 70 return 0; 71 72 if (!vmbus_match(parent, match, opaque)) 73 return 0; 74 75 return 1; 76} 77 78static void 79vmbus_acpi_attach(device_t parent, device_t self, void *opaque) 80{ 81 struct vmbus_acpi_softc *sc = device_private(self); 82 struct acpi_attach_args *aa = opaque; 83 84 sc->sc.sc_dev = self; 85 sc->sc.sc_dmat = aa->aa_dmat64 ? 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 93static int 94vmbus_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