From nobody Mon Oct 10 23:21:32 2022 X-Original-To: dev-commits-src-all@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 4MmZg469gQz4fG8v for ; Mon, 10 Oct 2022 23:21:36 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MmZg360FWz3bRv for ; Mon, 10 Oct 2022 23:21:35 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: by mail-wm1-f46.google.com with SMTP id bi26-20020a05600c3d9a00b003c1e11f54d2so6131573wmb.2 for ; Mon, 10 Oct 2022 16:21:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jncbclK7X2mgjj8w4Ao0//pWN8dghmTXAvU4/os1/V0=; b=0wml4lBbi2gyfVuLawHdr+cJVAumngwGQtlsU/95u3M3hWLrC3GckhspBoHWyAUZc6 ElF+uuI4ttH1zsbF6aYyJskmKdgW9r+3fI19t1ObY8Ofm3U+KvLfJV7+d0Rt+UL/SGIa ohCk69MB0bvPPUFdRNhVsEDrcp9AW7QrnAVFnFoAbZMx7UpnYRb+uZ3eXebCKgCPou5d cWfcONT71UBNtb30452EQuMDdo4BF9dPBxXZESxeCXs4jXuynvTQTNA49z6gw5tY+1pZ LbayQzFiH65xQitxUwbsCpQtduryeV6yCloIMQg18RrjIDlQEJidge07HSfTqc8FL+5o qtrw== X-Gm-Message-State: ACrzQf0SIe49lz46osOw3Z+EmSll7IaPYIXae4xg4KmlkcsMwLqDh/yB xYOj6uxjqKVRmUvvQy7XAlqg1sWoP7jg84bU X-Google-Smtp-Source: AMsMyM6iJrKnOvk2eJiwrQ+sit1BMpx8E+QavYf1ZqFOSQubWlSpUpMV14Vavz53fP1mrHVmQY+ySw== X-Received: by 2002:a7b:cb56:0:b0:3b3:4ad8:9e31 with SMTP id v22-20020a7bcb56000000b003b34ad89e31mr14309769wmj.87.1665444093770; Mon, 10 Oct 2022 16:21:33 -0700 (PDT) Received: from smtpclient.apple (global-5-142.n-2.net.cam.ac.uk. [131.111.5.142]) by smtp.gmail.com with ESMTPSA id f9-20020a05600c4e8900b003c6c4639ac6sm396793wmq.34.2022.10.10.16.21.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Oct 2022 16:21:33 -0700 (PDT) Content-Type: text/plain; charset=utf-8 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Subject: Re: git: 99e6980fcf5e - main - device_get_property: add a HANDLE case From: Jessica Clarke In-Reply-To: <202210092153.299LriCA024248@gitrepo.freebsd.org> Date: Tue, 11 Oct 2022 00:21:32 +0100 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <9C2F0D00-829F-4EF6-9F27-AC4242C60A3A@freebsd.org> References: <202210092153.299LriCA024248@gitrepo.freebsd.org> To: "Bjoern A. Zeeb" X-Mailer: Apple Mail (2.3696.80.82.1.1) X-Rspamd-Queue-Id: 4MmZg360FWz3bRv X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of jrtc27@jrtc27.com designates 209.85.128.46 as permitted sender) smtp.mailfrom=jrtc27@jrtc27.com X-Spamd-Result: default: False [-2.50 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.995]; MV_CASE(0.50)[]; FORGED_SENDER(0.30)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17:c]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_THREE(0.00)[4]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[dev-commits-src-all@freebsd.org]; TO_DN_EQ_ADDR_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DMARC_NA(0.00)[freebsd.org]; RCVD_IN_DNSWL_NONE(0.00)[209.85.128.46:from]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FREEFALL_USER(0.00)[jrtc27]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; R_DKIM_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.128.46:from] X-ThisMailContainsUnwantedMimeParts: N On 9 Oct 2022, at 22:53, Bjoern A. Zeeb wrote: >=20 > The branch main has been updated by bz: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3D99e6980fcf5e12654c3e89b97b774de8= 07d740a4 >=20 > commit 99e6980fcf5e12654c3e89b97b774de807d740a4 > Author: Bjoern A. Zeeb > AuthorDate: 2022-09-29 12:41:58 +0000 > Commit: Bjoern A. Zeeb > CommitDate: 2022-10-09 21:51:25 +0000 >=20 > device_get_property: add a HANDLE case >=20 > 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. How=E2=80=99s this supposed to be used though? phandle_t is a uint32_t = and ACPI_HANDLE is a void *, which are not the same size (aside from ILP32), let alone the same type. The existing interface lets you not care about the bus because the type corresponds to what you ask for (string or fixed-width integer), but this totally breaks that. This really should be abstracting the type as well, presumably to a uintptr_t. Jess > MFC after: 2 weeks > Reviewed by: mw > Differential Revision: https://reviews.freebsd.org/D36793 > --- > 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(-) >=20 > 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 941e2bd75aeb..a9d49a3c7f74 100644 > --- a/sys/dev/acpica/acpi.c > +++ b/sys/dev/acpica/acpi.c > @@ -1923,6 +1923,35 @@ acpi_find_dsd(struct acpi_device *ad) > return (AE_NOT_FOUND); > } >=20 > +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 !=3D ACPI_TYPE_PACKAGE) > + goto err; > + if (hobj->Package.Count !=3D 1) > + goto err; > + > + pobj =3D &hobj->Package.Elements[0]; > + if (pobj =3D=3D NULL) > + goto err; > + if (pobj->Type !=3D ACPI_TYPE_LOCAL_REFERENCE) > + goto err; > + > + h =3D acpi_GetReference(NULL, pobj); > + if (h =3D=3D NULL) > + goto err; > + > + if (propvalue !=3D NULL && size >=3D sizeof(ACPI_HANDLE)) > + *(ACPI_HANDLE *)propvalue =3D 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) > @@ -1941,6 +1970,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); > } > @@ -1972,6 +2003,22 @@ acpi_bus_get_prop(device_t bus, device_t child, = const char *propname, > MIN(size, obj->Buffer.Length)); > return (obj->Buffer.Length); >=20 > + case ACPI_TYPE_PACKAGE: > + if (propvalue !=3D NULL && size >=3D sizeof(ACPI_OBJECT = *)) { > + *((ACPI_OBJECT **) propvalue) =3D > + __DECONST(ACPI_OBJECT *, obj); > + } > + return (sizeof(ACPI_OBJECT *)); > + > + case ACPI_TYPE_LOCAL_REFERENCE: > + if (propvalue !=3D NULL && size >=3D = sizeof(ACPI_HANDLE)) { > + ACPI_HANDLE h; > + > + h =3D 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 ed472f87b57d..0b1277983da0 100644 > --- a/sys/dev/fdt/simplebus.c > +++ b/sys/dev/fdt/simplebus.c > @@ -357,7 +357,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 =3D ofw_bus_get_node(child); > + phandle_t node, xref; > ssize_t ret, i; > uint32_t *buffer; > uint64_t val; > @@ -367,11 +367,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); > } >=20 > + node =3D ofw_bus_get_node(child); > if (propvalue =3D=3D NULL || size =3D=3D 0) > return (OF_getproplen(node, propname)); >=20 > @@ -402,7 +404,20 @@ simplebus_get_property(device_t bus, device_t = child, const char *propname, > ((uint64_t *)buffer)[i / 2] =3D val; > } > return (ret); > - } > + } > + > + if (type =3D=3D DEVICE_PROP_HANDLE) { > + if (size < sizeof(node)) > + return (-1); > + ret =3D OF_getencprop(node, propname, &xref, = sizeof(xref)); > + if (ret <=3D 0) > + return (ret); > + > + node =3D OF_node_from_xref(xref); > + if (propvalue !=3D NULL) > + *(uint32_t *)propvalue =3D node; > + return (ret); > + } >=20 > return (OF_getprop(node, propname, propvalue, size)); > } > diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c > index 041e77259313..2365d83ef91e 100644 > --- a/sys/kern/subr_bus.c > +++ b/sys/kern/subr_bus.c > @@ -2226,6 +2226,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 !=3D 0) > diff --git a/sys/sys/bus.h b/sys/sys/bus.h > index 26d100aba222..5dead4dd382e 100644 > --- a/sys/sys/bus.h > +++ b/sys/sys/bus.h > @@ -72,6 +72,7 @@ typedef enum device_property_type { > DEVICE_PROP_BUFFER =3D 1, > DEVICE_PROP_UINT32 =3D 2, > DEVICE_PROP_UINT64 =3D 3, > + DEVICE_PROP_HANDLE =3D 4, > } device_property_type_t; >=20 > /**