acpi_ged.c revision 1.2
1/* $NetBSD: acpi_ged.c,v 1.2 2020/10/23 11:00:09 jmcneill Exp $ */ 2 3/*- 4 * Copyright (c) 2018 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jared McNeill <jmcneill@invisible.ca>. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33__KERNEL_RCSID(0, "$NetBSD: acpi_ged.c,v 1.2 2020/10/23 11:00:09 jmcneill Exp $"); 34 35#include <sys/param.h> 36#include <sys/bus.h> 37#include <sys/cpu.h> 38#include <sys/device.h> 39#include <sys/intr.h> 40#include <sys/kmem.h> 41 42#include <dev/acpi/acpireg.h> 43#include <dev/acpi/acpivar.h> 44#include <dev/acpi/acpi_event.h> 45#include <dev/acpi/acpi_intr.h> 46 47static int acpi_ged_match(device_t, cfdata_t, void *); 48static void acpi_ged_attach(device_t, device_t, void *); 49 50static void acpi_ged_register_event(void *, struct acpi_event *, struct acpi_irq *); 51static int acpi_ged_intr(void *); 52 53CFATTACH_DECL_NEW(acpiged, 0, acpi_ged_match, acpi_ged_attach, NULL, NULL); 54 55static const char * const compatible[] = { 56 "ACPI0013", 57 NULL 58}; 59 60static int 61acpi_ged_match(device_t parent, cfdata_t cf, void *aux) 62{ 63 struct acpi_attach_args *aa = aux; 64 65 if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 66 return 0; 67 68 return acpi_match_hid(aa->aa_node->ad_devinfo, compatible); 69} 70 71static void 72acpi_ged_attach(device_t parent, device_t self, void *aux) 73{ 74 struct acpi_attach_args * const aa = aux; 75 ACPI_HANDLE handle = aa->aa_node->ad_handle; 76 77 if (ACPI_FAILURE(acpi_event_create_int(self, handle, acpi_ged_register_event, self))) 78 aprint_error_dev(self, "failed to create events\n"); 79} 80 81static void 82acpi_ged_register_event(void *priv, struct acpi_event *ev, struct acpi_irq *irq) 83{ 84 device_t dev = priv; 85 void *ih; 86 87 ih = acpi_intr_establish_irq(dev, irq, IPL_VM, true, 88 acpi_ged_intr, ev, device_xname(dev)); 89 if (ih == NULL) { 90 aprint_error_dev(dev, "couldn't establish interrupt (irq %d)\n", irq->ar_irq); 91 return; 92 } 93} 94 95static int 96acpi_ged_intr(void *priv) 97{ 98 struct acpi_event * const ev = priv; 99 100 acpi_event_notify(ev); 101 102 return 1; 103} 104