[PATCH v6 14/23] ACPI: property: Add support for cells property

Anup Patel posted 23 patches 3 months, 3 weeks ago
There is a newer version of this series
[PATCH v6 14/23] ACPI: property: Add support for cells property
Posted by Anup Patel 3 months, 3 weeks ago
From: Sunil V L <sunilvl@ventanamicro.com>

Currently, ACPI doesn't support cells property when
fwnode_property_get_reference_args() is called. ACPI always expects
the number of arguments to be passed. However, the above mentioned
call being a common interface for OF and ACPI, it is better to have
single calling convention which works for both. Hence, add support
for cells property on the reference device to get the number of
arguments dynamically.

Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
 drivers/acpi/property.c | 22 ++++++++++++++++++++++
 drivers/base/property.c |  2 +-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index d4863746fb11..c9c3d6920326 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -882,6 +882,20 @@ static struct fwnode_handle *acpi_parse_string_ref(const struct fwnode_handle *f
 	return &dn->fwnode;
 }
 
+static unsigned int acpi_fwnode_get_args_count(const struct acpi_device *device,
+					       const char *nargs_prop)
+{
+	const union acpi_object *obj;
+
+	if (!nargs_prop)
+		return 0;
+
+	if (acpi_dev_get_property(device, nargs_prop, ACPI_TYPE_INTEGER, &obj))
+		return 0;
+
+	return obj->integer.value;
+}
+
 static int acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
 					  const char *propname, const char *nargs_prop,
 					  unsigned int args_count, unsigned int index,
@@ -960,6 +974,9 @@ static int acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
 			if (!device)
 				return -EINVAL;
 
+			if (nargs_prop)
+				args_count = acpi_fwnode_get_args_count(device, nargs_prop);
+
 			element++;
 
 			ret = acpi_get_ref_args(idx == index ? args : NULL,
@@ -978,6 +995,11 @@ static int acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
 			if (!ref_fwnode)
 				return -EINVAL;
 
+			if (nargs_prop) {
+				device = to_acpi_device_node(ref_fwnode);
+				args_count = acpi_fwnode_get_args_count(device, nargs_prop);
+			}
+
 			element++;
 
 			ret = acpi_get_ref_args(idx == index ? args : NULL,
diff --git a/drivers/base/property.c b/drivers/base/property.c
index f626d5bbe806..6a63860579dd 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -578,7 +578,7 @@ EXPORT_SYMBOL_GPL(fwnode_property_match_property_string);
  * @prop:	The name of the property
  * @nargs_prop:	The name of the property telling the number of
  *		arguments in the referred node. NULL if @nargs is known,
- *		otherwise @nargs is ignored. Only relevant on OF.
+ *		otherwise @nargs is ignored.
  * @nargs:	Number of arguments. Ignored if @nargs_prop is non-NULL.
  * @index:	Index of the reference, from zero onwards.
  * @args:	Result structure with reference and integer arguments.
-- 
2.43.0
Re: [PATCH v6 14/23] ACPI: property: Add support for cells property
Posted by Andy Shevchenko 3 months, 2 weeks ago
On Wed, Jun 18, 2025 at 05:43:49PM +0530, Anup Patel wrote:
> From: Sunil V L <sunilvl@ventanamicro.com>
> 
> Currently, ACPI doesn't support cells property when
> fwnode_property_get_reference_args() is called. ACPI always expects
> the number of arguments to be passed. However, the above mentioned
> call being a common interface for OF and ACPI, it is better to have
> single calling convention which works for both. Hence, add support
> for cells property on the reference device to get the number of
> arguments dynamically.

...

> +static unsigned int acpi_fwnode_get_args_count(const struct acpi_device *device,
> +					       const char *nargs_prop)
> +{
> +	const union acpi_object *obj;

> +	if (!nargs_prop)
> +		return 0;

This check is implied by the call. No need to duplicate.

> +	if (acpi_dev_get_property(device, nargs_prop, ACPI_TYPE_INTEGER, &obj))
> +		return 0;
> +
> +	return obj->integer.value;
> +}

...

> +			if (nargs_prop)

Again, if you don't won't to reassign the existing value, it's better to have
this data be collected in the temporary variable of the same semantics. Then
you will choose one when it's needed, no need to have this dup check (again!).

> +				args_count = acpi_fwnode_get_args_count(device, nargs_prop);
> +
>  			element++;
>  
>  			ret = acpi_get_ref_args(idx == index ? args : NULL,

...

> +			if (nargs_prop) {

Ditto.

> +				device = to_acpi_device_node(ref_fwnode);
> +				args_count = acpi_fwnode_get_args_count(device, nargs_prop);
> +			}

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v6 14/23] ACPI: property: Add support for cells property
Posted by Sunil V L 3 months, 1 week ago
On Mon, Jun 23, 2025 at 12:14:07PM +0300, Andy Shevchenko wrote:
> On Wed, Jun 18, 2025 at 05:43:49PM +0530, Anup Patel wrote:
> > From: Sunil V L <sunilvl@ventanamicro.com>
> > 
> > Currently, ACPI doesn't support cells property when
> > fwnode_property_get_reference_args() is called. ACPI always expects
> > the number of arguments to be passed. However, the above mentioned
> > call being a common interface for OF and ACPI, it is better to have
> > single calling convention which works for both. Hence, add support
> > for cells property on the reference device to get the number of
> > arguments dynamically.
> 
> ...
> 
> > +static unsigned int acpi_fwnode_get_args_count(const struct acpi_device *device,
> > +					       const char *nargs_prop)
> > +{
> > +	const union acpi_object *obj;
> 
> > +	if (!nargs_prop)
> > +		return 0;
> 
> This check is implied by the call. No need to duplicate.
> 
> > +	if (acpi_dev_get_property(device, nargs_prop, ACPI_TYPE_INTEGER, &obj))
> > +		return 0;
> > +
> > +	return obj->integer.value;
> > +}
> 
> ...
> 
> > +			if (nargs_prop)
> 
> Again, if you don't won't to reassign the existing value, it's better to have
> this data be collected in the temporary variable of the same semantics. Then
> you will choose one when it's needed, no need to have this dup check (again!).
> 
Okay. Let me update in the next version.

Thanks!
Sunil