Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1266739pxb; Fri, 22 Jan 2021 11:00:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwhCEUjiqp7ge0/NV616Zk9CB05MzY1qcxQFg0shGjWUKy5ZlD4P6C20j5Tqgkuf3/nQ7I X-Received: by 2002:a05:6402:79a:: with SMTP id d26mr4224959edy.266.1611342047639; Fri, 22 Jan 2021 11:00:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611342047; cv=none; d=google.com; s=arc-20160816; b=T7gJ6N38CUSkgD4/LMVFVEAxhJDJaPstP6+QERjpES/UfFnXDu0CHExa2EIH52NyK7 /Ar+qhIzhGkNemyTBXb3tFb68EJgs306FMnJrvuUOEUZlac9+H5Z0Z1MvTn5/XFuhs7U cHQC4N8AxaY612Tf3gdiNYv5Ul1JVrQvN0kgXvz9hqa8B3I6n3KntQ9RdXQImBpuLYvO JPGrul6gRpeOwU6x3IMhh0dBfrEU4tRZSuTbgHpRTAZTHJiqiiPBNyxgHd+mrLqlUhP4 N/+OHXQfhR0/TxY+n4YHSEVH6kOc3qHfEvjiezO0wW94XCkaxkdc4uAjyNpkGPPgPDMu cZdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=g8SVGJP7WiJQmZYbq/niFUHB4GuvGT5AtK/6Ph5PLj0=; b=UReUBzYAU4TiKKPHgA87Zetw1jIU4TlrvmufrUB+Z3ZKMwaiz2p0yk9XefQUw+o0cg HPjkFbdSk1rE3gU4NuxeWegvUp/NXD7XXydGwBIFE2tZe5Rvz7197mz0lY1JODkAojZt VECf0xYXCHwZDDXm0k48XN2mWHomP7hFHC30fujsL5oPsh/7bPO7R0Vzm10rj59x7NQG bQqACS0kKgnKuUpztNLeinbbY9pJs7JOXMhH3OVjdv4BkDgDGFPQLb9E2tt5DvbtlNsQ 0duRT2HtaULa/vDe/XJyz39bxw2oq4HdpJUsD92uec0wcRTpAPxf0nBvpjBbZZHsjGCA 1hOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx8si3265698ejb.664.2021.01.22.11.00.22; Fri, 22 Jan 2021 11:00:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730419AbhAVSyd (ORCPT + 99 others); Fri, 22 Jan 2021 13:54:33 -0500 Received: from mail-oi1-f174.google.com ([209.85.167.174]:42333 "EHLO mail-oi1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730067AbhAVSgZ (ORCPT ); Fri, 22 Jan 2021 13:36:25 -0500 Received: by mail-oi1-f174.google.com with SMTP id x71so7012357oia.9; Fri, 22 Jan 2021 10:36:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=g8SVGJP7WiJQmZYbq/niFUHB4GuvGT5AtK/6Ph5PLj0=; b=tChtH8J+HJnYJRHGL7uYSVy36di01ZFJ1MROlR3Q/eQs+fOBldjlgS7vT5Wn0fk+VT 0NR7Qx2/xTghvznrwRHGJo5uICwufeoajo/DywzooWi/TTMssVpPpwlWis7qEOfulkMA yhuVTr9PUTp2ymolkmrGqHcskyaBwyF+IBFWhvGC3g9VapAdSAUyCsxOYwwmf8Bl8ZJq 0+eC5KWjIh13MlT454IluNHetd6QoVyZqAg0Ep3pIwK7IfjiLBWirbsi1qUzUtNa7sa9 qN7mzKijyjiHnxTydGnfGdTM30Q9ZTlZ7j6dJeD+oEWuzi8zQgMWDFkMBMd3g/aVyyHt 7McQ== X-Gm-Message-State: AOAM533kvUJVq2s0K4TtzUFyRFg5U5wHfXEI3urdJSpXjrPT113VNCqa w4JGTIoKL1MvFZaQdGq+G0aSiYSwLw0zhfUPq/M= X-Received: by 2002:a05:6808:9a8:: with SMTP id e8mr4342802oig.157.1611340543679; Fri, 22 Jan 2021 10:35:43 -0800 (PST) MIME-Version: 1.0 References: <20210122154300.7628-1-calvin.johnson@oss.nxp.com> <20210122154300.7628-10-calvin.johnson@oss.nxp.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Fri, 22 Jan 2021 19:35:32 +0100 Message-ID: Subject: Re: [net-next PATCH v4 09/15] device property: Introduce fwnode_get_id() To: Calvin Johnson Cc: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Cristi Sovaiala , Florin Laurentiu Chiculita , Ioana Ciornei , Madalin Bucur , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , "linux.cj" , Diana Madalina Craciun , ACPI Devel Maling List , Linux ARM , Linux Kernel Mailing List , netdev , Laurentiu Tudor , Andy Shevchenko , Bartosz Golaszewski , Greg Kroah-Hartman , Kieran Bingham , Laurent Pinchart Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 22, 2021 at 7:13 PM Rafael J. Wysocki wrote: > > On Fri, Jan 22, 2021 at 4:46 PM Calvin Johnson > wrote: > > > > Using fwnode_get_id(), get the reg property value for DT node > > or get the _ADR object value for ACPI node. This is not accurate AFAICS, because if the "reg" property is present in the ACPI case, it will be returned then too. > > > > Signed-off-by: Calvin Johnson > > --- > > > > Changes in v4: > > - Improve code structure to handle all cases > > > > Changes in v3: > > - Modified to retrieve reg property value for ACPI as well > > - Resolved compilation issue with CONFIG_ACPI = n > > - Added more info into documentation > > > > Changes in v2: None > > > > drivers/base/property.c | 34 ++++++++++++++++++++++++++++++++++ > > include/linux/property.h | 1 + > > 2 files changed, 35 insertions(+) > > > > diff --git a/drivers/base/property.c b/drivers/base/property.c > > index 35b95c6ac0c6..f0581bbf7a4b 100644 > > --- a/drivers/base/property.c > > +++ b/drivers/base/property.c > > @@ -580,6 +580,40 @@ const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode) > > return fwnode_call_ptr_op(fwnode, get_name_prefix); > > } > > > > +/** > > + * fwnode_get_id - Get the id of a fwnode. > > + * @fwnode: firmware node > > + * @id: id of the fwnode > > + * > > + * This function provides the id of a fwnode which can be either > > + * DT or ACPI node. For ACPI, "reg" property value, if present will > > + * be provided or else _ADR value will be provided. > > + * Returns 0 on success or a negative errno. What about using the following description instead of the above: "Retrieve the value of the "reg" property for @fwnode which can be either DT or ACPI node. In the ACPI case, if the "reg" property is missing, evaluate the _ADR object located under the given node, if present, and provide its return value to the caller. Return 0 on success or a negative error code. This function can be used only if it is known valid to treat the _ADR return value as a fallback replacement for the value of the "reg" property that is missing in the given use case." > > + */ > > +int fwnode_get_id(struct fwnode_handle *fwnode, u32 *id) > > +{ > > +#ifdef CONFIG_ACPI > > + unsigned long long adr; > > + acpi_status status; > > +#endif > > + int ret; > > + > > + ret = fwnode_property_read_u32(fwnode, "reg", id); > > + if (ret) { > > +#ifdef CONFIG_ACPI > > + status = acpi_evaluate_integer(ACPI_HANDLE_FWNODE(fwnode), > > + METHOD_NAME__ADR, NULL, &adr); > > + if (ACPI_FAILURE(status)) > > + return -EINVAL; > > Please don't return -EINVAL from here, because this means "invalid > argument" to the caller, but there may be nothing wrong with the > fwnode and id pointers. > > I would return -ENODATA instead. > > > + *id = (u32)adr; > > +#else > > + return ret; > > +#endif > > + } > > + return 0; > > +} > > +EXPORT_SYMBOL_GPL(fwnode_get_id); > > + > > /** > > * fwnode_get_parent - Return parent firwmare node > > * @fwnode: Firmware whose parent is retrieved > > diff --git a/include/linux/property.h b/include/linux/property.h > > index 0a9001fe7aea..3f41475f010b 100644 > > --- a/include/linux/property.h > > +++ b/include/linux/property.h > > @@ -82,6 +82,7 @@ struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode, > > > > const char *fwnode_get_name(const struct fwnode_handle *fwnode); > > const char *fwnode_get_name_prefix(const struct fwnode_handle *fwnode); > > +int fwnode_get_id(struct fwnode_handle *fwnode, u32 *id); > > struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode); > > struct fwnode_handle *fwnode_get_next_parent( > > struct fwnode_handle *fwnode); > > -- > > 2.17.1 > >