Use acpi_compatible_match() / acpi_compatible_lookup().

This commit is contained in:
thorpej 2021-01-29 15:24:00 +00:00
parent 8cccc96e35
commit 8bd8e11fa5
4 changed files with 116 additions and 123 deletions

View File

@ -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 acpibut_softc {
struct sysmon_pswitch sc_smpsw;
};
static const char * const power_button_hid[] = {
"PNP0C0C",
NULL
struct button_type {
const char *desc;
int type;
};
static const char * const sleep_button_hid[] = {
"PNP0C0E",
NULL
static const struct button_type power_button_type = {
.desc = "Power",
.type = PSWITCH_TYPE_POWER
};
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 @@ acpibut_match(device_t parent, cfdata_t match, void *aux)
{
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 @@ acpibut_attach(device_t parent, device_t self, void *aux)
{
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;

View File

@ -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>
@ -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 @@ CFATTACH_DECL_NEW(com_acpi, sizeof(struct com_acpi_softc), com_acpi_match,
* 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 },
/*
* 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
/* 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 },
/* 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 @@ com_acpi_match(device_t parent, cfdata_t match, void *aux)
{
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 @@ com_acpi_attach(device_t parent, device_t self, void *aux)
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 @@ com_acpi_attach(device_t parent, device_t self, void *aux)
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) {

View File

@ -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 @@ static void pckbc_acpi_finish_attach(device_t);
* 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 @@ static int
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 @@ pckbc_acpi_attach(device_t parent, device_t self, void *aux)
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 @@ pckbc_acpi_attach(device_t parent, device_t self, void *aux)
sc->sc_dv = self;
if (acpi_match_hid(aa->aa_node->ad_devinfo, pckbc_acpi_ids_kbd)) {
psc->sc_slot = PCKBC_KBD_SLOT;
} else if (acpi_match_hid(aa->aa_node->ad_devinfo, pckbc_acpi_ids_ms)) {
psc->sc_slot = PCKBC_AUX_SLOT;
} else {
aprint_error(": unknown port!\n");
panic("pckbc_acpi_attach: impossible");
}
dce = acpi_compatible_lookup(aa, compat_data);
KASSERT(dce != NULL);
psc->sc_slot = dce->value;
aprint_normal(" (%s port)", pckbc_slot_names[psc->sc_slot]);

View File

@ -1,4 +1,4 @@
/* $NetBSD: tpm_acpi.c,v 1.12 2021/01/16 01:23:04 thorpej Exp $ */
/* $NetBSD: tpm_acpi.c,v 1.13 2021/01/29 15:24:00 thorpej Exp $ */
/*
* Copyright (c) 2012, 2019 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.12 2021/01/16 01:23:04 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.13 2021/01/29 15:24:00 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -55,44 +55,37 @@ static void tpm_acpi_attach(device_t, device_t, void *);
CFATTACH_DECL_NEW(tpm_acpi, sizeof(struct tpm_softc), tpm_acpi_match,
tpm_acpi_attach, NULL, NULL);
/*
* Supported TPM 1.2 devices.
*/
static const char * const tpm_1_2_acpi_ids[] = {
"PNP0C31",
NULL
};
/*
* Supported TPM 2.0 devices.
*/
static const char * const tpm2_acpi_ids[] = {
"MSFT0101",
NULL
static const struct device_compatible_entry compat_data[] = {
{ .compat = "PNP0C31", .value = TPM_1_2 },
{ .compat = "MSFT0101", .value = TPM_2_0 },
DEVICE_COMPAT_EOL
};
static int
tpm_acpi_match(device_t parent, cfdata_t match, void *aux)
{
struct acpi_attach_args *aa = aux;
const struct device_compatible_entry *dce;
ACPI_TABLE_TPM2 *tpm2;
ACPI_STATUS rv;
if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
return 0;
int ret;
/* We support only one TPM. */
if (tpm_cd.cd_devs && tpm_cd.cd_devs[0])
return 0;
if (acpi_match_hid(aa->aa_node->ad_devinfo, tpm_1_2_acpi_ids)) {
/* XXX assume TPM 1.2 devices are memory-mapped. */
return 1;
}
if (!acpi_match_hid(aa->aa_node->ad_devinfo, tpm2_acpi_ids))
ret = acpi_compatible_match(aa, compat_data);
if (ret == 0)
return 0;
dce = acpi_compatible_lookup(aa, compat_data);
KASSERT(dce != NULL);
if (dce->value == TPM_1_2) {
/* XXX assume TPM 1.2 devices are memory-mapped. */
return ret;
}
/* Make sure it uses TIS, and not CRB. */
rv = AcpiGetTable(ACPI_SIG_TPM2, 1, (ACPI_TABLE_HEADER **)&tpm2);
if (ACPI_FAILURE(rv))
@ -100,7 +93,7 @@ tpm_acpi_match(device_t parent, cfdata_t match, void *aux)
if (tpm2->StartMethod != ACPI_TPM2_MEMORY_MAPPED)
return 0;
return 1;
return ret;
}
static void
@ -108,6 +101,7 @@ tpm_acpi_attach(device_t parent, device_t self, void *aux)
{
struct tpm_softc *sc = device_private(self);
struct acpi_attach_args *aa = aux;
const struct device_compatible_entry *dce;
struct acpi_resources res;
struct acpi_mem *mem;
bus_addr_t base;
@ -134,12 +128,11 @@ tpm_acpi_attach(device_t parent, device_t self, void *aux)
base = mem->ar_base;
size = mem->ar_length;
dce = acpi_compatible_lookup(aa, compat_data);
KASSERT(dce != NULL);
sc->sc_dev = self;
if (acpi_match_hid(aa->aa_node->ad_devinfo, tpm_1_2_acpi_ids)) {
sc->sc_ver = TPM_1_2;
} else {
sc->sc_ver = TPM_2_0;
}
sc->sc_ver = dce->value;
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
sc->sc_busy = false;
sc->sc_intf = &tpm_intf_tis12;