Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/acpi Use acpi_compatible_match() / acpi_compatible_l...



details:   https://anonhg.NetBSD.org/src/rev/dec0d7ce0a7a
branches:  trunk
changeset: 959024:dec0d7ce0a7a
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Jan 29 15:24:00 2021 +0000

description:
Use acpi_compatible_match() / acpi_compatible_lookup().

diffstat:

 sys/dev/acpi/acpi_button.c |  58 +++++++++++++++++++-------------------
 sys/dev/acpi/com_acpi.c    |  69 +++++++++++++++++++++++++++------------------
 sys/dev/acpi/pckbc_acpi.c  |  57 ++++++++++++++-----------------------
 sys/dev/acpi/tpm_acpi.c    |  53 +++++++++++++++--------------------
 4 files changed, 115 insertions(+), 122 deletions(-)

diffs (truncated from 425 to 300 lines):

diff -r bfc532740400 -r dec0d7ce0a7a sys/dev/acpi/acpi_button.c
--- a/sys/dev/acpi/acpi_button.c        Fri Jan 29 15:20:13 2021 +0000
+++ b/sys/dev/acpi/acpi_button.c        Fri Jan 29 15:24:00 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_button.c,v 1.42 2015/04/23 23:23:00 pgoyette Exp $        */
+/*     $NetBSD: acpi_button.c,v 1.43 2021/01/29 15:24:00 thorpej Exp $ */
 
 /*
  * Copyright 2001, 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.42 2015/04/23 23:23:00 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.43 2021/01/29 15:24:00 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -61,14 +61,25 @@
        struct sysmon_pswitch    sc_smpsw;
 };
 
-static const char * const power_button_hid[] = {
-       "PNP0C0C",
-       NULL
+struct button_type {
+       const char *desc;
+       int type;
+};
+
+static const struct button_type power_button_type = {
+       .desc = "Power",
+       .type = PSWITCH_TYPE_POWER
 };
 
-static const char * const sleep_button_hid[] = {
-       "PNP0C0E",
-       NULL
+static const struct button_type sleep_button_type = {
+       .desc = "Sleep",
+       .type = PSWITCH_TYPE_SLEEP
+};
+
+static const struct device_compatible_entry compat_data[] = {
+       { .compat = "PNP0C0C",  .data = &power_button_type },
+       { .compat = "PNP0C0E",  .data = &sleep_button_type },
+       DEVICE_COMPAT_EOL
 };
 
 static int     acpibut_match(device_t, cfdata_t, void *);
@@ -90,16 +101,7 @@
 {
        struct acpi_attach_args *aa = aux;
 
-       if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
-               return 0;
-
-       if (acpi_match_hid(aa->aa_node->ad_devinfo, power_button_hid))
-               return 1;
-
-       if (acpi_match_hid(aa->aa_node->ad_devinfo, sleep_button_hid))
-               return 1;
-
-       return 0;
+       return acpi_compatible_match(aa, compat_data);
 }
 
 /*
@@ -112,22 +114,20 @@
 {
        struct acpibut_softc *sc = device_private(self);
        struct acpi_attach_args *aa = aux;
+       const struct device_compatible_entry *dce;
+       const struct button_type *type;
        struct acpi_wakedev *aw;
-       const char *desc;
 
        sc->sc_smpsw.smpsw_name = device_xname(self);
 
-       if (acpi_match_hid(aa->aa_node->ad_devinfo, power_button_hid)) {
-               sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_POWER;
-               desc = "Power";
-       } else if (acpi_match_hid(aa->aa_node->ad_devinfo, sleep_button_hid)) {
-               sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_SLEEP;
-               desc = "Sleep";
-       } else
-               panic("%s: impossible", __func__);
+       dce = acpi_compatible_lookup(aa, compat_data);
+       KASSERT(dce != NULL);
+       type = dce->data;
 
-       aprint_naive(": ACPI %s Button\n", desc);
-       aprint_normal(": ACPI %s Button\n", desc);
+       sc->sc_smpsw.smpsw_type = type->type;
+
+       aprint_naive(": ACPI %s Button\n", type->desc);
+       aprint_normal(": ACPI %s Button\n", type->desc);
 
        sc->sc_node = aa->aa_node;
        aw = sc->sc_node->ad_wakedev;
diff -r bfc532740400 -r dec0d7ce0a7a sys/dev/acpi/com_acpi.c
--- a/sys/dev/acpi/com_acpi.c   Fri Jan 29 15:20:13 2021 +0000
+++ b/sys/dev/acpi/com_acpi.c   Fri Jan 29 15:24:00 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: com_acpi.c,v 1.40 2019/03/01 09:21:06 mlelstv Exp $ */
+/* $NetBSD: com_acpi.c,v 1.41 2021/01/29 15:24:00 thorpej Exp $ */
 
 /*
  * Copyright (c) 2002 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.40 2019/03/01 09:21:06 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.41 2021/01/29 15:24:00 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -53,27 +53,38 @@
  * Supported device IDs
  */
 
-static const char * const com_acpi_ids[] = {
-       "PNP0500",      /* Standard PC COM port */
-       "PNP0501",      /* 16550A-compatible COM port */
-       "PNP0510",      /* Generic IRDA-compatible device */
-       "PNP0511",      /* Generic IRDA-compatible device */
-       "IBM0071",      /* IBM ThinkPad IRDA device */
-       "SMCF010",      /* SMC SuperIO IRDA device */
-       "NSC6001",      /* NSC IRDA device */
-       "FUJ02E6",      /* Fujitsu Serial Pen Tablet */
-       "HISI0031",     /* Hisilicon UART */
-       "8250dw",       /* Designware APB UART */
-       NULL
-};
+static const struct device_compatible_entry compat_data[] = {
+       /* Standard PC COM port */
+       { .compat = "PNP0500",          .value = COM_TYPE_NORMAL },
+
+       /* 16550A-compatible COM port */
+       { .compat = "PNP0501",          .value = COM_TYPE_NORMAL },
+
+       /* Generic IRDA-compatible device */
+       { .compat = "PNP0510",          .value = COM_TYPE_NORMAL },
+
+       /* Generic IRDA-compatible device */
+       { .compat = "PNP0511",          .value = COM_TYPE_NORMAL },
+
+       /* IBM ThinkPad IRDA device */
+       { .compat = "IBM0071",          .value = COM_TYPE_NORMAL },
 
-/*
- * Subset of supported device IDs of type COM_TYPE_DW_APB
- */
-static const char * const com_acpi_dw_ids[] = {
-       "HISI0031",     /* Hisilicon UART */
-       "8250dw",       /* Designware APB UART */
-       NULL
+       /* SMC SuperIO IRDA device */
+       { .compat = "SMCF010",          .value = COM_TYPE_NORMAL },
+
+       /* NSC IRDA device */
+       { .compat = "NSC6001",          .value = COM_TYPE_NORMAL },
+
+       /* Fujitsu Serial Pen Tablet */
+       { .compat = "FUJ02E6",          .value = COM_TYPE_NORMAL },
+
+       /* Hisilicon UART */
+       { .compat = "HISI0031",         .value = COM_TYPE_DW_APB },
+
+       /* Designware APB UART */
+       { .compat = "8250dw",           .value = COM_TYPE_DW_APB },
+
+       DEVICE_COMPAT_EOL
 };
 
 /*
@@ -84,10 +95,7 @@
 {
        struct acpi_attach_args *aa = aux;
 
-       if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
-               return 0;
-
-       return acpi_match_hid(aa->aa_node->ad_devinfo, com_acpi_ids);
+       return acpi_compatible_match(aa, compat_data);
 }
 
 /*
@@ -99,6 +107,7 @@
        struct com_acpi_softc *asc = device_private(self);
        struct com_softc *sc = &asc->sc_com;
        struct acpi_attach_args *aa = aux;
+       const struct device_compatible_entry *dce;
        struct acpi_resources res;
        struct acpi_io *io;
        struct acpi_mem *mem;
@@ -153,8 +162,12 @@
 
        aprint_normal("%s", device_xname(self));
 
-       if (acpi_match_hid(aa->aa_node->ad_devinfo, com_acpi_dw_ids) != 0) {
-               sc->sc_type = COM_TYPE_DW_APB;
+       dce = acpi_compatible_lookup(aa, compat_data);
+       KASSERT(dce != NULL);
+
+       sc->sc_type = dce->value;
+
+       if (sc->sc_type == COM_TYPE_DW_APB) {
                SET(sc->sc_hwflags, COM_HW_POLL);       /* XXX */
        } else {
                if (com_probe_subr(&sc->sc_regs) == 0) {
diff -r bfc532740400 -r dec0d7ce0a7a sys/dev/acpi/pckbc_acpi.c
--- a/sys/dev/acpi/pckbc_acpi.c Fri Jan 29 15:20:13 2021 +0000
+++ b/sys/dev/acpi/pckbc_acpi.c Fri Jan 29 15:24:00 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pckbc_acpi.c,v 1.38 2020/12/06 12:23:13 jmcneill Exp $ */
+/*     $NetBSD: pckbc_acpi.c,v 1.39 2021/01/29 15:24:00 thorpej Exp $  */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pckbc_acpi.c,v 1.38 2020/12/06 12:23:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pckbc_acpi.c,v 1.39 2021/01/29 15:24:00 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/callout.h>
@@ -83,21 +83,21 @@
  * Supported Device IDs
  */
 
-static const char * const pckbc_acpi_ids_kbd[] = {
-       "PNP03??",      /* Standard PC KBD port */
-       NULL
-};
+static const struct device_compatible_entry compat_data[] = {
+       /* Standard PC KBD port */
+       { .compat = "PNP03??",          .value = PCKBC_KBD_SLOT },
 
-static const char * const pckbc_acpi_ids_ms[] = {
-       "PNP0F03",
-       "PNP0F0E",
-       "PNP0F12",
-       "PNP0F13",
-       "PNP0F19",
-       "PNP0F1B",
-       "PNP0F1C",
-       "SYN0302",
-       NULL
+       /* (Nobody else here but us mouses...) */
+       { .compat = "PNP0F03",          .value = PCKBC_AUX_SLOT },
+       { .compat = "PNP0F0E",          .value = PCKBC_AUX_SLOT },
+       { .compat = "PNP0F12",          .value = PCKBC_AUX_SLOT },
+       { .compat = "PNP0F13",          .value = PCKBC_AUX_SLOT },
+       { .compat = "PNP0F19",          .value = PCKBC_AUX_SLOT },
+       { .compat = "PNP0F1B",          .value = PCKBC_AUX_SLOT },
+       { .compat = "PNP0F1C",          .value = PCKBC_AUX_SLOT },
+       { .compat = "SYN0302",          .value = PCKBC_AUX_SLOT },
+
+       DEVICE_COMPAT_EOL
 };
 
 /*
@@ -107,18 +107,8 @@
 pckbc_acpi_match(device_t parent, cfdata_t match, void *aux)
 {
        struct acpi_attach_args *aa = aux;
-       int rv;
 
-       if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
-               return 0;
-
-       rv = acpi_match_hid(aa->aa_node->ad_devinfo, pckbc_acpi_ids_kbd);
-       if (rv)
-               return rv;
-       rv = acpi_match_hid(aa->aa_node->ad_devinfo, pckbc_acpi_ids_ms);
-       if (rv)
-               return rv;
-       return 0;
+       return acpi_compatible_match(aa, compat_data);
 }
 
 static void
@@ -128,6 +118,7 @@
        struct pckbc_softc *sc = &psc->sc_pckbc;
        struct pckbc_internal *t;
        struct acpi_attach_args *aa = aux;
+       const struct device_compatible_entry *dce;
        bus_space_handle_t ioh_d, ioh_c;
        struct acpi_resources res;
        struct acpi_io *io0, *io1, *ioswap;
@@ -136,14 +127,10 @@
 
        sc->sc_dv = self;
 
-       if (acpi_match_hid(aa->aa_node->ad_devinfo, pckbc_acpi_ids_kbd)) {
-               psc->sc_slot = PCKBC_KBD_SLOT;



Home | Main Index | Thread Index | Old Index