#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: acpi_hed.c,v 1.1 2024/03/21 02:36:01 riastradh Exp $");
#include <sys/device.h>
#include <sys/module.h>
#include <dev/acpi/acpireg.h>
#include <dev/acpi/acpivar.h>
#include <dev/acpi/apei_hed.h>
#define _COMPONENT ACPI_RESOURCE_COMPONENT
ACPI_MODULE_NAME ("acpi_hed")
struct acpihed_softc {
device_t sc_dev;
struct acpi_devnode *sc_node;
};
static const struct device_compatible_entry compat_data[] = {
{ .compat = "PNP0C33" },
DEVICE_COMPAT_EOL
};
static int acpihed_match(device_t, cfdata_t, void *);
static void acpihed_attach(device_t, device_t, void *);
static int acpihed_detach(device_t, int);
static void acpihed_notify(ACPI_HANDLE, uint32_t, void *);
CFATTACH_DECL_NEW(acpihed, sizeof(struct acpihed_softc),
acpihed_match, acpihed_attach, acpihed_detach, NULL);
static int
acpihed_match(device_t parent, cfdata_t match, void *aux)
{
struct acpi_attach_args *aa = aux;
return acpi_compatible_match(aa, compat_data);
}
static void
acpihed_attach(device_t parent, device_t self, void *aux)
{
struct acpihed_softc *sc = device_private(self);
struct acpi_attach_args *aa = aux;
aprint_naive("\n");
aprint_normal(": ACPI Hardware Error Device\n");
pmf_device_register(self, NULL, NULL);
sc->sc_dev = self;
sc->sc_node = aa->aa_node;
acpi_register_notify(sc->sc_node, acpihed_notify);
}
static int
acpihed_detach(device_t self, int flags)
{
struct acpihed_softc *sc = device_private(self);
int error;
error = config_detach_children(self, flags);
if (error)
return error;
acpi_deregister_notify(sc->sc_node);
pmf_device_deregister(self);
return 0;
}
static void
acpihed_notify(ACPI_HANDLE handle, uint32_t event, void *cookie)
{
apei_hed_notify();
}
MODULE(MODULE_CLASS_DRIVER, acpihed, "apei");
#ifdef _MODULE
#include "ioconf.c"
#endif
static int
acpihed_modcmd(modcmd_t cmd, void *opaque)
{
int error = 0;
switch (cmd) {
case MODULE_CMD_INIT:
#ifdef _MODULE
error = config_init_component(cfdriver_ioconf_acpihed,
cfattach_ioconf_acpihed, cfdata_ioconf_acpihed);
#endif
return error;
case MODULE_CMD_FINI:
#ifdef _MODULE
error = config_fini_component(cfdriver_ioconf_acpihed,
cfattach_ioconf_acpihed, cfdata_ioconf_acpihed);
#endif
return error;
default:
return ENOTTY;
}
}