[net-next PATCH v3 09/15] device property: Introduce fwnode_get_id()

Rafael J. Wysocki rafael at kernel.org
Wed Jan 20 13:17:51 EST 2021


On Tue, Jan 12, 2021 at 4:47 PM Andy Shevchenko
<andy.shevchenko at gmail.com> wrote:
>
> On Tue, Jan 12, 2021 at 3:42 PM Calvin Johnson
> <calvin.johnson at oss.nxp.com> wrote:
> >
> > Using fwnode_get_id(), get the reg property value for DT node
> > or get the _ADR object value for ACPI node.
> >
> > Signed-off-by: Calvin Johnson <calvin.johnson at oss.nxp.com>
> > ---
> >
> > 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  | 33 +++++++++++++++++++++++++++++++++
> >  include/linux/property.h |  1 +
> >  2 files changed, 34 insertions(+)
> >
> > diff --git a/drivers/base/property.c b/drivers/base/property.c
> > index 35b95c6ac0c6..2d51108cb936 100644
> > --- a/drivers/base/property.c
> > +++ b/drivers/base/property.c
> > @@ -580,6 +580,39 @@ 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.
> > + */
> > +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 && is_acpi_node(fwnode)))
> > +               return ret;
> > +
> > +#ifdef CONFIG_ACPI
> > +       status = acpi_evaluate_integer(ACPI_HANDLE_FWNODE(fwnode),
> > +                                      METHOD_NAME__ADR, NULL, &adr);
> > +       if (ACPI_FAILURE(status))
> > +               return -EINVAL;
> > +       *id = (u32)adr;
>
> Shouldn't be
>
>        return 0;
> #else
>        return -EINVAL;
> #endif
>
> ?
>
> Yes, it's a theoretical case when is_acpi_node() returns true when
> CONFIG_ACPI=n.

How so?  is_acpi_node() is defined as a static inline returning false then.



More information about the linux-arm-kernel mailing list