From 9108e412bd3927bbb0cb663c132f152da551254b Mon Sep 17 00:00:00 2001 From: patrick Date: Wed, 10 Aug 2022 16:58:16 +0000 Subject: [PATCH] Provide the AML root in ACPI's softc so that drivers that need access don't have to declare it using extern. Suggested by and with feedback from kettenis@ Tested by deraadt@ on arm64, amd64 and i386 Tested by bluhm@ on amd64 and i386 --- sys/dev/acpi/acpi.c | 46 +++++++++++++++++++-------------------- sys/dev/acpi/acpidebug.c | 10 ++++----- sys/dev/acpi/acpidock.c | 8 +++---- sys/dev/acpi/acpiec.c | 6 ++--- sys/dev/acpi/acpipwrres.c | 18 ++++++--------- sys/dev/acpi/acpitz.c | 4 +--- sys/dev/acpi/acpivar.h | 3 ++- 7 files changed, 43 insertions(+), 52 deletions(-) diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index d73a0a823fe..15373d47cb9 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.413 2022/02/17 00:21:40 jsg Exp $ */ +/* $OpenBSD: acpi.c,v 1.414 2022/08/10 16:58:16 patrick Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -183,7 +183,6 @@ int mouse_has_softbtn; struct acpi_softc *acpi_softc; -/* XXX move this into dsdt softc at some point */ extern struct aml_node aml_root; struct cfdriver acpi_cd = { @@ -986,6 +985,7 @@ acpi_attach_common(struct acpi_softc *sc, paddr_t base) rw_init(&sc->sc_lck, "acpilk"); acpi_softc = sc; + sc->sc_root = &aml_root; if (acpi_map(base, sizeof(struct acpi_rsdp), &handle)) { printf(": can't map memory\n"); @@ -1188,42 +1188,42 @@ acpi_attach_common(struct acpi_softc *sc, paddr_t base) } /* initialize runtime environment */ - aml_find_node(&aml_root, "_INI", acpi_inidev, sc); + aml_find_node(sc->sc_root, "_INI", acpi_inidev, sc); /* Get PCI mapping */ - aml_walknodes(&aml_root, AML_WALK_PRE, acpi_getpci, sc); + aml_walknodes(sc->sc_root, AML_WALK_PRE, acpi_getpci, sc); #if defined (__amd64__) || defined(__i386__) /* attach pci interrupt routing tables */ - aml_find_node(&aml_root, "_PRT", acpi_foundprt, sc); + aml_find_node(sc->sc_root, "_PRT", acpi_foundprt, sc); #endif - aml_find_node(&aml_root, "_HID", acpi_foundec, sc); + aml_find_node(sc->sc_root, "_HID", acpi_foundec, sc); /* check if we're running on a sony */ - aml_find_node(&aml_root, "GBRT", acpi_foundsony, sc); + aml_find_node(sc->sc_root, "GBRT", acpi_foundsony, sc); #ifndef SMALL_KERNEL /* try to find smart battery first */ - aml_find_node(&aml_root, "_HID", acpi_foundsbs, sc); + aml_find_node(sc->sc_root, "_HID", acpi_foundsbs, sc); #endif /* SMALL_KERNEL */ /* attach battery, power supply and button devices */ - aml_find_node(&aml_root, "_HID", acpi_foundhid, sc); + aml_find_node(sc->sc_root, "_HID", acpi_foundhid, sc); - aml_walknodes(&aml_root, AML_WALK_PRE, acpi_add_device, sc); + aml_walknodes(sc->sc_root, AML_WALK_PRE, acpi_add_device, sc); #ifndef SMALL_KERNEL #if NWD > 0 /* Attach IDE bay */ - aml_walknodes(&aml_root, AML_WALK_PRE, acpi_foundide, sc); + aml_walknodes(sc->sc_root, AML_WALK_PRE, acpi_foundide, sc); #endif /* attach docks */ - aml_find_node(&aml_root, "_DCK", acpi_founddock, sc); + aml_find_node(sc->sc_root, "_DCK", acpi_founddock, sc); /* attach video */ - aml_find_node(&aml_root, "_DOS", acpi_foundvideo, sc); + aml_find_node(sc->sc_root, "_DOS", acpi_foundvideo, sc); /* create list of devices we want to query when APM comes in */ SLIST_INIT(&sc->sc_ac); @@ -2356,30 +2356,30 @@ acpi_init_gpes(struct acpi_softc *sc) for (idx = 0; idx < sc->sc_lastgpe; idx++) { /* Search Level-sensitive GPES */ snprintf(name, sizeof(name), "\\_GPE._L%.2X", idx); - gpe = aml_searchname(&aml_root, name); + gpe = aml_searchname(sc->sc_root, name); if (gpe != NULL) acpi_set_gpehandler(sc, idx, acpi_gpe, gpe, GPE_LEVEL); if (gpe == NULL) { /* Search Edge-sensitive GPES */ snprintf(name, sizeof(name), "\\_GPE._E%.2X", idx); - gpe = aml_searchname(&aml_root, name); + gpe = aml_searchname(sc->sc_root, name); if (gpe != NULL) acpi_set_gpehandler(sc, idx, acpi_gpe, gpe, GPE_EDGE); } } - aml_find_node(&aml_root, "_PRW", acpi_foundprw, sc); + aml_find_node(sc->sc_root, "_PRW", acpi_foundprw, sc); } void acpi_init_pm(struct acpi_softc *sc) { - sc->sc_tts = aml_searchname(&aml_root, "_TTS"); - sc->sc_pts = aml_searchname(&aml_root, "_PTS"); - sc->sc_wak = aml_searchname(&aml_root, "_WAK"); - sc->sc_bfs = aml_searchname(&aml_root, "_BFS"); - sc->sc_gts = aml_searchname(&aml_root, "_GTS"); - sc->sc_sst = aml_searchname(&aml_root, "_SI_._SST"); + sc->sc_tts = aml_searchname(sc->sc_root, "_TTS"); + sc->sc_pts = aml_searchname(sc->sc_root, "_PTS"); + sc->sc_wak = aml_searchname(sc->sc_root, "_WAK"); + sc->sc_bfs = aml_searchname(sc->sc_root, "_BFS"); + sc->sc_gts = aml_searchname(sc->sc_root, "_GTS"); + sc->sc_sst = aml_searchname(sc->sc_root, "_SI_._SST"); } #ifndef SMALL_KERNEL @@ -2396,7 +2396,7 @@ acpi_init_states(struct acpi_softc *sc) snprintf(name, sizeof(name), "_S%d_", i); sc->sc_sleeptype[i].slp_typa = -1; sc->sc_sleeptype[i].slp_typb = -1; - if (aml_evalname(sc, &aml_root, name, 0, NULL, &res) == 0) { + if (aml_evalname(sc, sc->sc_root, name, 0, NULL, &res) == 0) { if (res.type == AML_OBJTYPE_PACKAGE) { sc->sc_sleeptype[i].slp_typa = aml_val2int(res.v_package[0]); diff --git a/sys/dev/acpi/acpidebug.c b/sys/dev/acpi/acpidebug.c index 17bcf1ec8a4..e9dfeec950c 100644 --- a/sys/dev/acpi/acpidebug.c +++ b/sys/dev/acpi/acpidebug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpidebug.c,v 1.32 2020/09/11 09:27:10 mpi Exp $ */ +/* $OpenBSD: acpidebug.c,v 1.33 2022/08/10 16:58:16 patrick Exp $ */ /* * Copyright (c) 2006 Marco Peereboom * @@ -52,8 +52,6 @@ const char *db_aml_fieldacc(int); const char *db_aml_fieldlock(int); const char *db_aml_fieldupdate(int); -extern struct aml_node aml_root; - /* name of scope for lexer */ char scope[80]; @@ -288,7 +286,7 @@ db_acpi_showval(db_expr_t addr, int haddr, db_expr_t count, char *modif) if (db_parse_name()) return; - node = aml_searchname(&aml_root, scope); + node = aml_searchname(acpi_softc->sc_root, scope); if (node) db_aml_showvalue(node->value); else @@ -312,7 +310,7 @@ db_acpi_disasm(db_expr_t addr, int haddr, db_expr_t count, char *modif) if (db_parse_name()) return; - node = aml_searchname(&aml_root, scope); + node = aml_searchname(acpi_softc->sc_root, scope); if (node && node->value && node->value->type == AML_OBJTYPE_METHOD) { struct aml_scope ns; @@ -330,7 +328,7 @@ db_acpi_disasm(db_expr_t addr, int haddr, db_expr_t count, char *modif) void db_acpi_tree(db_expr_t addr, int haddr, db_expr_t count, char *modif) { - db_aml_walktree(&aml_root); + db_aml_walktree(acpi_softc->sc_root); } void diff --git a/sys/dev/acpi/acpidock.c b/sys/dev/acpi/acpidock.c index ff0f5c74745..7a5d59a864e 100644 --- a/sys/dev/acpi/acpidock.c +++ b/sys/dev/acpi/acpidock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpidock.c,v 1.45 2022/04/06 18:59:27 naddy Exp $ */ +/* $OpenBSD: acpidock.c,v 1.46 2022/08/10 16:58:16 patrick Exp $ */ /* * Copyright (c) 2006,2007 Michael Knudsen * @@ -73,7 +73,6 @@ acpidock_attach(struct device *parent, struct device *self, void *aux) { struct acpidock_softc *sc = (struct acpidock_softc *)self; struct acpi_attach_args *aa = aux; - extern struct aml_node aml_root; sc->sc_acpi = (struct acpi_softc *)parent; sc->sc_devnode = aa->aaa_node; @@ -107,7 +106,7 @@ acpidock_attach(struct device *parent, struct device *self, void *aux) sensordev_install(&sc->sc_sensdev); TAILQ_INIT(&sc->sc_deps_h); - aml_find_node(&aml_root, "_EJD", acpidock_foundejd, sc); + aml_find_node(sc->sc_acpi->sc_root, "_EJD", acpidock_foundejd, sc); aml_register_notify(sc->sc_devnode, aa->aaa_dev, acpidock_notify, sc, ACPIDEV_NOPOLL); @@ -279,14 +278,13 @@ acpidock_foundejd(struct aml_node *node, void *arg) struct acpidock_softc *sc = (struct acpidock_softc *)arg; struct aml_value res; struct aml_node *dock; - extern struct aml_node aml_root; dnprintf(15, "%s: %s", DEVNAME(sc), node->name); if (aml_evalnode(sc->sc_acpi, node, 0, NULL, &res) == -1) printf(": error\n"); else { - dock = aml_searchname(&aml_root, res.v_string); + dock = aml_searchname(sc->sc_acpi->sc_root, res.v_string); if (dock == sc->sc_devnode) /* Add all children devices of Device containing _EJD */ diff --git a/sys/dev/acpi/acpiec.c b/sys/dev/acpi/acpiec.c index 9923f950ade..5ef24d5179d 100644 --- a/sys/dev/acpi/acpiec.c +++ b/sys/dev/acpi/acpiec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpiec.c,v 1.64 2022/04/06 18:59:27 naddy Exp $ */ +/* $OpenBSD: acpiec.c,v 1.65 2022/08/10 16:58:16 patrick Exp $ */ /* * Copyright (c) 2006 Can Erkin Acar * @@ -425,7 +425,6 @@ acpiec_getcrs(struct acpiec_softc *sc, struct acpi_attach_args *aa) struct aml_value res; int64_t gpe; struct acpi_ecdt *ecdt = aa->aaa_table; - extern struct aml_node aml_root; int rc; /* Check if this is ECDT initialization */ @@ -446,7 +445,8 @@ acpiec_getcrs(struct acpiec_softc *sc, struct acpi_attach_args *aa) sc->sc_ec_data = ecdt->ec_data.address; /* Get devnode from header */ - sc->sc_devnode = aml_searchname(&aml_root, ecdt->ec_id); + sc->sc_devnode = aml_searchname(sc->sc_acpi->sc_root, + ecdt->ec_id); goto ecdtdone; } diff --git a/sys/dev/acpi/acpipwrres.c b/sys/dev/acpi/acpipwrres.c index 57aea81fb76..65d5555dd0c 100644 --- a/sys/dev/acpi/acpipwrres.c +++ b/sys/dev/acpi/acpipwrres.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpipwrres.c,v 1.11 2022/04/06 18:59:27 naddy Exp $ */ +/* $OpenBSD: acpipwrres.c,v 1.12 2022/08/10 16:58:16 patrick Exp $ */ /* * Copyright (c) 2013 Martin Pieuchot @@ -98,8 +98,6 @@ acpipwrres_attach(struct device *parent, struct device *self, void *aux) struct aml_value res; struct acpipwrres_consumer *cons; - extern struct aml_node aml_root; - sc->sc_acpi = (struct acpi_softc *)parent; sc->sc_devnode = aaa->aaa_node; memset(&res, 0, sizeof res); @@ -125,12 +123,12 @@ acpipwrres_attach(struct device *parent, struct device *self, void *aux) /* Get the list of consumers */ SIMPLEQ_INIT(&sc->sc_cons); #if notyet - aml_find_node(&aml_root, "_PRW", acpipwrres_foundcons, sc); + aml_find_node(sc->sc_acpi->sc_root, "_PRW", acpipwrres_foundcons, sc); #endif - aml_find_node(&aml_root, "_PR0", acpipwrres_foundcons, sc); - aml_find_node(&aml_root, "_PR1", acpipwrres_foundcons, sc); - aml_find_node(&aml_root, "_PR2", acpipwrres_foundcons, sc); - aml_find_node(&aml_root, "_PR3", acpipwrres_foundcons, sc); + aml_find_node(sc->sc_acpi->sc_root, "_PR0", acpipwrres_foundcons, sc); + aml_find_node(sc->sc_acpi->sc_root, "_PR1", acpipwrres_foundcons, sc); + aml_find_node(sc->sc_acpi->sc_root, "_PR2", acpipwrres_foundcons, sc); + aml_find_node(sc->sc_acpi->sc_root, "_PR3", acpipwrres_foundcons, sc); DPRINTF(("%s", DEVNAME(sc))); if (!SIMPLEQ_EMPTY(&sc->sc_cons)) { @@ -268,8 +266,6 @@ acpipwrres_foundcons(struct aml_node *node, void *arg) struct aml_value res, *ref; int i = 0; - extern struct aml_node aml_root; - memset(&res, 0, sizeof(res)); if (aml_evalnode(sc->sc_acpi, node, 0, NULL, &res) == -1) { @@ -294,7 +290,7 @@ acpipwrres_foundcons(struct aml_node *node, void *arg) if (ref->type == AML_OBJTYPE_NAMEREF) { struct aml_node *pnode; - pnode = aml_searchrel(&aml_root, + pnode = aml_searchrel(sc->sc_acpi->sc_root, aml_getname(ref->v_nameref)); if (pnode == NULL) { DPRINTF(("%s: device %s not found\n", diff --git a/sys/dev/acpi/acpitz.c b/sys/dev/acpi/acpitz.c index aa184976dbe..39230579346 100644 --- a/sys/dev/acpi/acpitz.c +++ b/sys/dev/acpi/acpitz.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpitz.c,v 1.58 2022/04/06 18:59:27 naddy Exp $ */ +/* $OpenBSD: acpitz.c,v 1.59 2022/08/10 16:58:16 patrick Exp $ */ /* * Copyright (c) 2006 Can Erkin Acar * Copyright (c) 2005 Marco Peereboom @@ -96,8 +96,6 @@ extern int perflevel; #define ACPITZ_DEVLIST (1L << 1) #define ACPITZ_INIT (ACPITZ_TRIPS|ACPITZ_DEVLIST) -extern struct aml_node aml_root; - void acpitz_init_perf(void *arg) { diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h index 339eb9baeb3..75f74d8a0cf 100644 --- a/sys/dev/acpi/acpivar.h +++ b/sys/dev/acpi/acpivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: acpivar.h,v 1.120 2022/07/05 09:33:39 tb Exp $ */ +/* $OpenBSD: acpivar.h,v 1.121 2022/08/10 16:58:16 patrick Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * @@ -260,6 +260,7 @@ struct acpi_softc { uint32_t sc_gpe_en; struct acpi_thread *sc_thread; + struct aml_node *sc_root; struct aml_node *sc_tts; struct aml_node *sc_pts; struct aml_node *sc_bfs; -- 2.20.1