Message ID | 20210112134054.342-10-calvin.johnson@oss.nxp.com |
---|---|
State | Superseded |
Headers | show |
Series | ACPI support for dpaa2 driver | expand |
Hi, On Tue, Jan 12, 2021 at 09:30:31AM -0800, Saravana Kannan wrote: > On Tue, Jan 12, 2021 at 5:42 AM Calvin Johnson > <calvin.johnson@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@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; > > +#endif > > + return 0; > > +} > > +EXPORT_SYMBOL_GPL(fwnode_get_id); > > Please don't do it this way. The whole point of fwnode_operations is > to avoid conditional stuff at the fwnode level. Also ACPI and DT > aren't mutually exclusive if I'm not mistaken. > > Also, can you CC me on the entire series please? I want to reply to > some of your other patches too. Most of the fwnode changes don't seem > right. fwnode is lower level that the device-driver framework. Making > it aware of busses like mdio, etc doesn't sound right. Also, there's > already get_dev_from_fwnode() which is a much more efficient way to > look up/get a device from a fwnode instead of looping through a bus. Thanks for reviewing the patch. I'll add you in the upcoming v4 series. There is lot of history into patch series. It would be helpful, if you can search for related submissions in the past and get some background. Regards Calvin
On Tue, Jan 12, 2021 at 4:47 PM Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > > On Tue, Jan 12, 2021 at 3:42 PM Calvin Johnson > <calvin.johnson@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@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.
On Wed, Jan 20, 2021 at 8:18 PM Rafael J. Wysocki <rafael@kernel.org> wrote: > On Tue, Jan 12, 2021 at 4:47 PM Andy Shevchenko > <andy.shevchenko@gmail.com> wrote: > > On Tue, Jan 12, 2021 at 3:42 PM Calvin Johnson > > <calvin.johnson@oss.nxp.com> wrote: ... > > > +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. I understand that, that's why it's pure theoretical when, for example, the semantics is changed. But I believe it's unlucky to happen. -- With Best Regards, Andy Shevchenko
On Wed, Jan 20, 2021 at 7:44 PM Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > > On Wed, Jan 20, 2021 at 8:18 PM Rafael J. Wysocki <rafael@kernel.org> wrote: > > On Tue, Jan 12, 2021 at 4:47 PM Andy Shevchenko > > <andy.shevchenko@gmail.com> wrote: > > > On Tue, Jan 12, 2021 at 3:42 PM Calvin Johnson > > > <calvin.johnson@oss.nxp.com> wrote: > > ... > > > > > +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. > > I understand that, that's why it's pure theoretical when, for example, > the semantics is changed. But I believe it's unlucky to happen. Changing the definition of it for CONFIG_ACPI=n would be a regression given the current usage of it.
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; +#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);
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@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(+)