From nobody Wed Jan 18 16:24:35 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Nxrgm1VzPz2yJNP; Wed, 18 Jan 2023 16:24:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Nxrgm0n1Cz3D8K; Wed, 18 Jan 2023 16:24:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674059076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Y8JtkdSUjBVpKIDakFs6+PAejfk+QgW2FhEsxhdzZfg=; b=AXAMBqCE9FU7bs2cPJEF18WnEQNIMA1qi0cncCBJi4Ftr2VvQaO+O1nhLEYdNbwA1C9Oai /Cj0qwHDkBDzsbVflqQ5yP27Grp/uAeZ92+nuatkjiP+j1NBDTuc7bny2tygdEXqkgjUIT 5lH+idMGpxkIhLsIjZqdtYBbTf8a/WN6r1R1LTOmRuXrP3/AWE30rdKGwUgVkdFyXv+Ulo q3ItEMyUwMXt/SokdlLRVqdoDor9EmRoy8oGDSl+p8e6vU0JGYNzguhsHLu+jKM9S5RKXd UvnyMQnuUIUOY3J6L24Ss/U9pXFtVcxV9fuIg1ooxb2/o2A3yty+LjkZruMtDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674059076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Y8JtkdSUjBVpKIDakFs6+PAejfk+QgW2FhEsxhdzZfg=; b=nyT19eoPd8mv/1faYCNBBTK6nEdeP7IWEW08Bg3i0xwlQHx4SRzjXIiYkqHOAhDW8QnjMR sPWXGLTJ+njsuboPkzFRydsPh85DYvmzIIXlTWs5xes6Bh0FAbkMhGfnmKAbLDB5lfcwI/ OKMhQgWrALGjRG9flqZYqy+4wEruWt8BfR8uFJry6GZ0YWC+qn7reoF1NbEsuAm3dKSojY HVAJxwXNIxR0Upm1djH3sHGWVJhTsAb/5i8feKtIeDM/ElLQTNUhnB5Ww/rj9zjPWpHcqN Qm3+izfLZM5p6YfzHcTJ4tlidaAPn/zAn0GpftcnmBoITIKZGQm+OhLRvUQFnQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674059076; a=rsa-sha256; cv=none; b=NNFcI1pWDD5076av31zIy1aV5iNb/QrcH7lt/1mXDw4xj7ZChPzI52D+jkIGQvfLXaj1Zs UBTZO+mRQgj8s4b28kJqph+DDOT2MKIx+k34j6L6zSW38k7u7A3Iz+nVb/VCSD72KhJmZt 2uDreNKSxAdkHhb3qhVaYUY1x+4uFANcKy2Gp+2HPqDxoruTCPubw6A1FPaJnIOH1RChYJ GkeuQxtiDrBLXk+S5LkBmQNuyy2SyQ6L6ehKdBo07hPY9f8VYIo8h+SJHntSBFP0oYpD0X liIHYspI4sbU2qOrKkiu9WtLHLyA3O1ZViLE5Tvdm9zd3UbVXE3mM5HDvTqrSQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Nxrgl6vzvzHp5; Wed, 18 Jan 2023 16:24:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30IGOZdZ037654; Wed, 18 Jan 2023 16:24:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30IGOZAF037653; Wed, 18 Jan 2023 16:24:35 GMT (envelope-from git) Date: Wed, 18 Jan 2023 16:24:35 GMT Message-Id: <202301181624.30IGOZAF037653@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: b3e602d9ac5e - stable/13 - device_get_property: add a HANDLE case List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b3e602d9ac5e3157874dfe3986dc819971d2142c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=b3e602d9ac5e3157874dfe3986dc819971d2142c commit b3e602d9ac5e3157874dfe3986dc819971d2142c Author: Bjoern A. Zeeb AuthorDate: 2022-09-29 12:41:58 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-01-18 13:22:13 +0000 device_get_property: add a HANDLE case This will resolve a reference and return the appropriate handle, a node on the simplebus or an ACPI_HANDLE for ACPI. For now we do not try to further abstract the return type. Reviewed by: mw Differential Revision: https://reviews.freebsd.org/D36793 (cherry picked from commit 99e6980fcf5e12654c3e89b97b774de807d740a4) --- share/man/man9/device_get_property.9 | 5 +++- sys/dev/acpica/acpi.c | 47 ++++++++++++++++++++++++++++++++++++ sys/dev/fdt/simplebus.c | 19 +++++++++++++-- sys/kern/subr_bus.c | 1 + sys/sys/bus.h | 1 + 5 files changed, 70 insertions(+), 3 deletions(-) diff --git a/share/man/man9/device_get_property.9 b/share/man/man9/device_get_property.9 index d925f5f224db..93c01f199477 100644 --- a/share/man/man9/device_get_property.9 +++ b/share/man/man9/device_get_property.9 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 18, 2022 +.Dd September 29, 2022 .Dt DEVICE_GET_PROPERTY 9 .Os .Sh NAME @@ -54,6 +54,9 @@ Currently the following types are supported: The underlying property is a string of bytes. .It Dv DEVICE_PROP_ANY Wildcard property type. +.It Dv DEVICE_PROP_HANDLE +Following a reference the underlying property is a handle of the +respective bus. .It Dv DEVICE_PROP_UINT32 The underlying property is an array of unsigned 32 bit integers. The diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c index 9005448ddee9..8f4419a76c58 100644 --- a/sys/dev/acpica/acpi.c +++ b/sys/dev/acpica/acpi.c @@ -1824,6 +1824,35 @@ acpi_find_dsd(struct acpi_device *ad) return (AE_NOT_FOUND); } +static ssize_t +acpi_bus_get_prop_handle(const ACPI_OBJECT *hobj, void *propvalue, size_t size) +{ + ACPI_OBJECT *pobj; + ACPI_HANDLE h; + + if (hobj->Type != ACPI_TYPE_PACKAGE) + goto err; + if (hobj->Package.Count != 1) + goto err; + + pobj = &hobj->Package.Elements[0]; + if (pobj == NULL) + goto err; + if (pobj->Type != ACPI_TYPE_LOCAL_REFERENCE) + goto err; + + h = acpi_GetReference(NULL, pobj); + if (h == NULL) + goto err; + + if (propvalue != NULL && size >= sizeof(ACPI_HANDLE)) + *(ACPI_HANDLE *)propvalue = h; + return (sizeof(ACPI_HANDLE)); + +err: + return (-1); +} + static ssize_t acpi_bus_get_prop(device_t bus, device_t child, const char *propname, void *propvalue, size_t size, device_property_type_t type) @@ -1842,6 +1871,8 @@ acpi_bus_get_prop(device_t bus, device_t child, const char *propname, case DEVICE_PROP_UINT32: case DEVICE_PROP_UINT64: break; + case DEVICE_PROP_HANDLE: + return (acpi_bus_get_prop_handle(obj, propvalue, size)); default: return (-1); } @@ -1873,6 +1904,22 @@ acpi_bus_get_prop(device_t bus, device_t child, const char *propname, MIN(size, obj->Buffer.Length)); return (obj->Buffer.Length); + case ACPI_TYPE_PACKAGE: + if (propvalue != NULL && size >= sizeof(ACPI_OBJECT *)) { + *((ACPI_OBJECT **) propvalue) = + __DECONST(ACPI_OBJECT *, obj); + } + return (sizeof(ACPI_OBJECT *)); + + case ACPI_TYPE_LOCAL_REFERENCE: + if (propvalue != NULL && size >= sizeof(ACPI_HANDLE)) { + ACPI_HANDLE h; + + h = acpi_GetReference(NULL, + __DECONST(ACPI_OBJECT *, obj)); + memcpy(propvalue, h, sizeof(ACPI_HANDLE)); + } + return (sizeof(ACPI_HANDLE)); default: return (0); } diff --git a/sys/dev/fdt/simplebus.c b/sys/dev/fdt/simplebus.c index ab7868f245bf..a29b28f2a016 100644 --- a/sys/dev/fdt/simplebus.c +++ b/sys/dev/fdt/simplebus.c @@ -359,7 +359,7 @@ static ssize_t simplebus_get_property(device_t bus, device_t child, const char *propname, void *propvalue, size_t size, device_property_type_t type) { - phandle_t node = ofw_bus_get_node(child); + phandle_t node, xref; ssize_t ret, i; uint32_t *buffer; uint64_t val; @@ -369,11 +369,13 @@ simplebus_get_property(device_t bus, device_t child, const char *propname, case DEVICE_PROP_BUFFER: case DEVICE_PROP_UINT32: case DEVICE_PROP_UINT64: + case DEVICE_PROP_HANDLE: break; default: return (-1); } + node = ofw_bus_get_node(child); if (propvalue == NULL || size == 0) return (OF_getproplen(node, propname)); @@ -404,7 +406,20 @@ simplebus_get_property(device_t bus, device_t child, const char *propname, ((uint64_t *)buffer)[i / 2] = val; } return (ret); - } + } + + if (type == DEVICE_PROP_HANDLE) { + if (size < sizeof(node)) + return (-1); + ret = OF_getencprop(node, propname, &xref, sizeof(xref)); + if (ret <= 0) + return (ret); + + node = OF_node_from_xref(xref); + if (propvalue != NULL) + *(uint32_t *)propvalue = node; + return (ret); + } return (OF_getprop(node, propname, propvalue, size)); } diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index c70e0e7b5ec1..c1383add7e47 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -2683,6 +2683,7 @@ device_get_property(device_t dev, const char *prop, void *val, size_t sz, switch (type) { case DEVICE_PROP_ANY: case DEVICE_PROP_BUFFER: + case DEVICE_PROP_HANDLE: /* Size checks done in implementation. */ break; case DEVICE_PROP_UINT32: if (sz % 4 != 0) diff --git a/sys/sys/bus.h b/sys/sys/bus.h index c017f38dcf11..a308810f158f 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -73,6 +73,7 @@ typedef enum device_property_type { DEVICE_PROP_BUFFER = 1, DEVICE_PROP_UINT32 = 2, DEVICE_PROP_UINT64 = 3, + DEVICE_PROP_HANDLE = 4, } device_property_type_t; /**