Skip to content

Commit 159c86f

Browse files
vlsunilPaul Walmsley
authored andcommitted
ACPI: Add support for nargs_prop in acpi_fwnode_get_reference_args()
Currently, ACPI does not support the use of a nargs_prop (e.g., associated with a reference in fwnode_property_get_reference_args(). Instead, ACPI expects the number of arguments (nargs) to be explicitly passed or known. This behavior diverges from Open Firmware (OF), which allows the use of a #*-cells property in the referenced node to determine the number of arguments. Since fwnode_property_get_reference_args() is a common interface used across both OF and ACPI firmware paradigms, it is desirable to have a unified calling convention that works seamlessly for both. Add the support for ACPI to parse a nargs_prop from the referenced fwnode, aligning its behavior with the OF backend. This allows drivers and subsystems using fwnode_property_get_reference_args() to work in a firmware-agnostic way without having to hardcode or special-case argument counts for ACPI. Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com> Acked-by: Jassi Brar <jassisinghbrar@gmail.com> Link: https://lore.kernel.org/r/20250818040920.272664-16-apatel@ventanamicro.com Signed-off-by: Paul Walmsley <pjw@kernel.org>
1 parent e121be7 commit 159c86f

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

drivers/acpi/property.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,13 +804,35 @@ acpi_fwnode_get_named_child_node(const struct fwnode_handle *fwnode,
804804
return NULL;
805805
}
806806

807+
static unsigned int acpi_fwnode_get_args_count(struct fwnode_handle *fwnode,
808+
const char *nargs_prop)
809+
{
810+
const struct acpi_device_data *data;
811+
const union acpi_object *obj;
812+
int ret;
813+
814+
data = acpi_device_data_of_node(fwnode);
815+
if (!data)
816+
return 0;
817+
818+
ret = acpi_data_get_property(data, nargs_prop, ACPI_TYPE_INTEGER, &obj);
819+
if (ret)
820+
return 0;
821+
822+
return obj->integer.value;
823+
}
824+
807825
static int acpi_get_ref_args(struct fwnode_reference_args *args,
808826
struct fwnode_handle *ref_fwnode,
827+
const char *nargs_prop,
809828
const union acpi_object **element,
810829
const union acpi_object *end, size_t num_args)
811830
{
812831
u32 nargs = 0, i;
813832

833+
if (nargs_prop)
834+
num_args = acpi_fwnode_get_args_count(ref_fwnode, nargs_prop);
835+
814836
/*
815837
* Assume the following integer elements are all args. Stop counting on
816838
* the first reference (possibly represented as a string) or end of the
@@ -961,10 +983,10 @@ static int acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
961983
return -EINVAL;
962984

963985
element++;
964-
965986
ret = acpi_get_ref_args(idx == index ? args : NULL,
966987
acpi_fwnode_handle(device),
967-
&element, end, args_count);
988+
nargs_prop, &element, end,
989+
args_count);
968990
if (ret < 0)
969991
return ret;
970992

@@ -979,9 +1001,8 @@ static int acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
9791001
return -EINVAL;
9801002

9811003
element++;
982-
9831004
ret = acpi_get_ref_args(idx == index ? args : NULL,
984-
ref_fwnode, &element, end,
1005+
ref_fwnode, nargs_prop, &element, end,
9851006
args_count);
9861007
if (ret < 0)
9871008
return ret;

drivers/base/property.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ EXPORT_SYMBOL_GPL(fwnode_property_match_property_string);
578578
* @prop: The name of the property
579579
* @nargs_prop: The name of the property telling the number of
580580
* arguments in the referred node. NULL if @nargs is known,
581-
* otherwise @nargs is ignored. Only relevant on OF.
581+
* otherwise @nargs is ignored.
582582
* @nargs: Number of arguments. Ignored if @nargs_prop is non-NULL.
583583
* @index: Index of the reference, from zero onwards.
584584
* @args: Result structure with reference and integer arguments.

0 commit comments

Comments
 (0)