From e3ba7f7856adaa90dc89385d36b59e1d22c08cc7 Mon Sep 17 00:00:00 2001 From: kettenis Date: Fri, 3 Aug 2018 22:18:13 +0000 Subject: [PATCH] Let ahci(4) match on _CLS instead of _HID when attaching at acpi(4). Avoids having to add many more _HID entries to the match table. ok deraadt@, mlarkin@ --- sys/dev/acpi/acpi.c | 32 ++++++++++++++++++++++++++++---- sys/dev/acpi/acpivar.h | 3 ++- sys/dev/acpi/ahci_acpi.c | 12 +++--------- sys/dev/pci/ahci_pci.c | 7 +++---- sys/dev/pci/pcireg.h | 3 ++- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 601bf9717dd..ccc7befe976 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.355 2018/07/10 17:11:42 kettenis Exp $ */ +/* $OpenBSD: acpi.c,v 1.356 2018/08/03 22:18:13 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -123,9 +123,6 @@ void acpi_create_thread(void *); void acpi_indicator(struct acpi_softc *, int); -int acpi_matchhids(struct acpi_attach_args *aa, const char *hids[], - const char *driver); - void acpi_init_pm(struct acpi_softc *); int acpi_founddock(struct aml_node *, void *); @@ -507,6 +504,33 @@ acpi_getminbus(int crsidx, union acpi_resource *crs, void *arg) return 0; } +int +acpi_matchcls(struct acpi_attach_args *aaa, int class, int subclass, + int interface) +{ + struct acpi_softc *sc = acpi_softc; + struct aml_value res; + + if (aaa->aaa_dev == NULL || aaa->aaa_node == NULL) + return (0); + + if (aml_evalname(sc, aaa->aaa_node, "_CLS", 0, NULL, &res)) + return (0); + + if (res.type != AML_OBJTYPE_PACKAGE || res.length != 3 || + res.v_package[0]->type != AML_OBJTYPE_INTEGER || + res.v_package[1]->type != AML_OBJTYPE_INTEGER || + res.v_package[2]->type != AML_OBJTYPE_INTEGER) + return (0); + + if (res.v_package[0]->v_integer == class && + res.v_package[1]->v_integer == subclass && + res.v_package[2]->v_integer == interface) + return (1); + + return (0); +} + int _acpi_matchhids(const char *hid, const char *hids[]) { diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h index 23f9b5e9fcd..f10f8478813 100644 --- a/sys/dev/acpi/acpivar.h +++ b/sys/dev/acpi/acpivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: acpivar.h,v 1.96 2018/07/10 17:11:42 kettenis Exp $ */ +/* $OpenBSD: acpivar.h,v 1.97 2018/08/03 22:18:13 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * @@ -366,6 +366,7 @@ void acpi_write_pmreg(struct acpi_softc *, int, int, int); void acpi_poll(void *); void acpi_sleep(int, char *); +int acpi_matchcls(struct acpi_attach_args *, int, int, int); int acpi_matchhids(struct acpi_attach_args *, const char *[], const char *); int acpi_parsehid(struct aml_node *, void *, char *, char *, size_t); diff --git a/sys/dev/acpi/ahci_acpi.c b/sys/dev/acpi/ahci_acpi.c index 6976e4cb8f7..07438337e10 100644 --- a/sys/dev/acpi/ahci_acpi.c +++ b/sys/dev/acpi/ahci_acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ahci_acpi.c,v 1.1 2018/07/01 15:54:59 kettenis Exp $ */ +/* $OpenBSD: ahci_acpi.c,v 1.2 2018/08/03 22:18:13 kettenis Exp $ */ /* * Copyright (c) 2018 Mark Kettenis * @@ -49,21 +49,15 @@ struct cfattach ahci_acpi_ca = { sizeof(struct ahci_acpi_softc), ahci_acpi_match, ahci_acpi_attach }; -const char *ahci_hids[] = { - "AMDI0600", - "LNRO001E", - NULL -}; - int ahci_acpi_parse_resources(int, union acpi_resource *, void *); int ahci_acpi_match(struct device *parent, void *match, void *aux) { struct acpi_attach_args *aaa = aux; - struct cfdata *cf = match; - return acpi_matchhids(aaa, ahci_hids, cf->cf_driver->cd_name); + return acpi_matchcls(aaa, PCI_CLASS_MASS_STORAGE, + PCI_SUBCLASS_MASS_STORAGE_SATA, PCI_INTERFACE_SATA_AHCI10); } void diff --git a/sys/dev/pci/ahci_pci.c b/sys/dev/pci/ahci_pci.c index 793610d3a83..79044b52dd5 100644 --- a/sys/dev/pci/ahci_pci.c +++ b/sys/dev/pci/ahci_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ahci_pci.c,v 1.14 2018/01/03 20:10:40 kettenis Exp $ */ +/* $OpenBSD: ahci_pci.c,v 1.15 2018/08/03 22:18:13 kettenis Exp $ */ /* * Copyright (c) 2006 David Gwynne @@ -43,7 +43,6 @@ #define AHCI_PCI_BAR 0x24 #define AHCI_PCI_ATI_SB600_MAGIC 0x40 #define AHCI_PCI_ATI_SB600_LOCKED 0x01 -#define AHCI_PCI_INTERFACE 0x01 struct ahci_pci_softc { struct ahci_softc psc_ahci; @@ -232,7 +231,7 @@ ahci_ati_sb_idetoahci(struct ahci_softc *sc, struct pci_attach_args *pa) pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG, PCI_CLASS_MASS_STORAGE << PCI_CLASS_SHIFT | PCI_SUBCLASS_MASS_STORAGE_SATA << PCI_SUBCLASS_SHIFT | - AHCI_PCI_INTERFACE << PCI_INTERFACE_SHIFT | + PCI_INTERFACE_SATA_AHCI10 << PCI_INTERFACE_SHIFT | PCI_REVISION(pa->pa_class) << PCI_REVISION_SHIFT); pci_conf_write(pa->pa_pc, pa->pa_tag, @@ -310,7 +309,7 @@ ahci_pci_match(struct device *parent, void *match, void *aux) if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE && PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_SATA && - PCI_INTERFACE(pa->pa_class) == AHCI_PCI_INTERFACE) + PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_SATA_AHCI10) return (2); return (0); diff --git a/sys/dev/pci/pcireg.h b/sys/dev/pci/pcireg.h index feaa9bc6f47..90ef9275a05 100644 --- a/sys/dev/pci/pcireg.h +++ b/sys/dev/pci/pcireg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pcireg.h,v 1.55 2017/08/09 21:42:44 mlarkin Exp $ */ +/* $OpenBSD: pcireg.h,v 1.56 2018/08/03 22:18:13 kettenis Exp $ */ /* $NetBSD: pcireg.h,v 1.26 2000/05/10 16:58:42 thorpej Exp $ */ /* @@ -168,6 +168,7 @@ typedef u_int8_t pci_revision_t; #define PCI_SUBCLASS_MASS_STORAGE_RAID 0x04 #define PCI_SUBCLASS_MASS_STORAGE_ATA 0x05 #define PCI_SUBCLASS_MASS_STORAGE_SATA 0x06 +#define PCI_INTERFACE_SATA_AHCI10 0x01 #define PCI_SUBCLASS_MASS_STORAGE_SAS 0x07 #define PCI_SUBCLASS_MASS_STORAGE_NVM 0x08 #define PCI_SUBCLASS_MASS_STORAGE_UFS 0x09 -- 2.20.1