1 /* $NetBSD: acpi_hed.c,v 1.1 2024/03/21 02:36:01 riastradh Exp $ */ 2 3 /*- 4 * Copyright (c) 2024 The NetBSD Foundation, Inc. 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. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /* 30 * HED: Hardware Error Device, PNP0C33. 31 * 32 * This device serves only to receive notifications about hardware 33 * errors, which we then dispatch to apei(4). 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: acpi_hed.c,v 1.1 2024/03/21 02:36:01 riastradh Exp $"); 38 39 #include <sys/device.h> 40 #include <sys/module.h> 41 42 #include <dev/acpi/acpireg.h> 43 #include <dev/acpi/acpivar.h> 44 #include <dev/acpi/apei_hed.h> 45 46 #define _COMPONENT ACPI_RESOURCE_COMPONENT 47 ACPI_MODULE_NAME ("acpi_hed") 48 49 struct acpihed_softc { 50 device_t sc_dev; 51 struct acpi_devnode *sc_node; 52 }; 53 54 static const struct device_compatible_entry compat_data[] = { 55 { .compat = "PNP0C33" }, 56 DEVICE_COMPAT_EOL 57 }; 58 59 static int acpihed_match(device_t, cfdata_t, void *); 60 static void acpihed_attach(device_t, device_t, void *); 61 static int acpihed_detach(device_t, int); 62 static void acpihed_notify(ACPI_HANDLE, uint32_t, void *); 63 64 CFATTACH_DECL_NEW(acpihed, sizeof(struct acpihed_softc), 65 acpihed_match, acpihed_attach, acpihed_detach, NULL); 66 67 static int 68 acpihed_match(device_t parent, cfdata_t match, void *aux) 69 { 70 struct acpi_attach_args *aa = aux; 71 72 return acpi_compatible_match(aa, compat_data); 73 } 74 75 static void 76 acpihed_attach(device_t parent, device_t self, void *aux) 77 { 78 struct acpihed_softc *sc = device_private(self); 79 struct acpi_attach_args *aa = aux; 80 81 aprint_naive("\n"); 82 aprint_normal(": ACPI Hardware Error Device\n"); 83 84 pmf_device_register(self, NULL, NULL); 85 86 sc->sc_dev = self; 87 sc->sc_node = aa->aa_node; 88 89 acpi_register_notify(sc->sc_node, acpihed_notify); 90 } 91 92 static int 93 acpihed_detach(device_t self, int flags) 94 { 95 struct acpihed_softc *sc = device_private(self); 96 int error; 97 98 error = config_detach_children(self, flags); 99 if (error) 100 return error; 101 102 acpi_deregister_notify(sc->sc_node); 103 104 pmf_device_deregister(self); 105 106 return 0; 107 } 108 109 static void 110 acpihed_notify(ACPI_HANDLE handle, uint32_t event, void *cookie) 111 { 112 113 apei_hed_notify(); 114 } 115 116 MODULE(MODULE_CLASS_DRIVER, acpihed, "apei"); 117 118 #ifdef _MODULE 119 #include "ioconf.c" 120 #endif 121 122 static int 123 acpihed_modcmd(modcmd_t cmd, void *opaque) 124 { 125 int error = 0; 126 127 switch (cmd) { 128 case MODULE_CMD_INIT: 129 #ifdef _MODULE 130 error = config_init_component(cfdriver_ioconf_acpihed, 131 cfattach_ioconf_acpihed, cfdata_ioconf_acpihed); 132 #endif 133 return error; 134 case MODULE_CMD_FINI: 135 #ifdef _MODULE 136 error = config_fini_component(cfdriver_ioconf_acpihed, 137 cfattach_ioconf_acpihed, cfdata_ioconf_acpihed); 138 #endif 139 return error; 140 default: 141 return ENOTTY; 142 } 143 } 144