2 * ACPI device specific properties support.
4 * Copyright (C) 2014, Intel Corporation
7 * Authors: Mika Westerberg <mika.westerberg@linux.intel.com>
8 * Darren Hart <dvhart@linux.intel.com>
9 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/acpi.h>
17 #include <linux/device.h>
18 #include <linux/export.h>
22 static int acpi_data_get_property_array(struct acpi_device_data *data,
24 acpi_object_type type,
25 const union acpi_object **obj);
27 /* ACPI _DSD device properties UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301 */
28 static const u8 prp_uuid[16] = {
29 0x14, 0xd8, 0xff, 0xda, 0xba, 0x6e, 0x8c, 0x4d,
30 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01
32 /* ACPI _DSD data subnodes UUID: dbb8e3e6-5886-4ba6-8795-1319f52a966b */
33 static const u8 ads_uuid[16] = {
34 0xe6, 0xe3, 0xb8, 0xdb, 0x86, 0x58, 0xa6, 0x4b,
35 0x87, 0x95, 0x13, 0x19, 0xf5, 0x2a, 0x96, 0x6b
38 static bool acpi_enumerate_nondev_subnodes(acpi_handle scope,
39 const union acpi_object *desc,
40 struct acpi_device_data *data,
41 struct fwnode_handle *parent);
42 static bool acpi_extract_properties(const union acpi_object *desc,
43 struct acpi_device_data *data);
45 static bool acpi_nondev_subnode_extract(const union acpi_object *desc,
47 const union acpi_object *link,
48 struct list_head *list,
49 struct fwnode_handle *parent)
51 struct acpi_data_node *dn;
54 dn = kzalloc(sizeof(*dn), GFP_KERNEL);
58 dn->name = link->package.elements[0].string.pointer;
59 dn->fwnode.type = FWNODE_ACPI_DATA;
61 INIT_LIST_HEAD(&dn->data.subnodes);
63 result = acpi_extract_properties(desc, &dn->data);
70 * The scope for the subnode object lookup is the one of the
71 * namespace node (device) containing the object that has
72 * returned the package. That is, it's the scope of that
75 status = acpi_get_parent(handle, &scope);
76 if (ACPI_SUCCESS(status)
77 && acpi_enumerate_nondev_subnodes(scope, desc, &dn->data,
80 } else if (acpi_enumerate_nondev_subnodes(NULL, desc, &dn->data,
87 dn->data.pointer = desc;
88 list_add_tail(&dn->sibling, list);
93 acpi_handle_debug(handle, "Invalid properties/subnodes data, skipping\n");
97 static bool acpi_nondev_subnode_data_ok(acpi_handle handle,
98 const union acpi_object *link,
99 struct list_head *list,
100 struct fwnode_handle *parent)
102 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER };
105 status = acpi_evaluate_object_typed(handle, NULL, NULL, &buf,
107 if (ACPI_FAILURE(status))
110 if (acpi_nondev_subnode_extract(buf.pointer, handle, link, list,
114 ACPI_FREE(buf.pointer);
118 static bool acpi_nondev_subnode_ok(acpi_handle scope,
119 const union acpi_object *link,
120 struct list_head *list,
121 struct fwnode_handle *parent)
129 status = acpi_get_handle(scope, link->package.elements[1].string.pointer,
131 if (ACPI_FAILURE(status))
134 return acpi_nondev_subnode_data_ok(handle, link, list, parent);
137 static int acpi_add_nondev_subnodes(acpi_handle scope,
138 const union acpi_object *links,
139 struct list_head *list,
140 struct fwnode_handle *parent)
145 for (i = 0; i < links->package.count; i++) {
146 const union acpi_object *link, *desc;
150 link = &links->package.elements[i];
151 /* Only two elements allowed. */
152 if (link->package.count != 2)
155 /* The first one must be a string. */
156 if (link->package.elements[0].type != ACPI_TYPE_STRING)
159 /* The second one may be a string, a reference or a package. */
160 switch (link->package.elements[1].type) {
161 case ACPI_TYPE_STRING:
162 result = acpi_nondev_subnode_ok(scope, link, list,
165 case ACPI_TYPE_LOCAL_REFERENCE:
166 handle = link->package.elements[1].reference.handle;
167 result = acpi_nondev_subnode_data_ok(handle, link, list,
170 case ACPI_TYPE_PACKAGE:
171 desc = &link->package.elements[1];
172 result = acpi_nondev_subnode_extract(desc, NULL, link,
185 static bool acpi_enumerate_nondev_subnodes(acpi_handle scope,
186 const union acpi_object *desc,
187 struct acpi_device_data *data,
188 struct fwnode_handle *parent)
192 /* Look for the ACPI data subnodes UUID. */
193 for (i = 0; i < desc->package.count; i += 2) {
194 const union acpi_object *uuid, *links;
196 uuid = &desc->package.elements[i];
197 links = &desc->package.elements[i + 1];
200 * The first element must be a UUID and the second one must be
203 if (uuid->type != ACPI_TYPE_BUFFER || uuid->buffer.length != 16
204 || links->type != ACPI_TYPE_PACKAGE)
207 if (memcmp(uuid->buffer.pointer, ads_uuid, sizeof(ads_uuid)))
210 return acpi_add_nondev_subnodes(scope, links, &data->subnodes,
217 static bool acpi_property_value_ok(const union acpi_object *value)
222 * The value must be an integer, a string, a reference, or a package
223 * whose every element must be an integer, a string, or a reference.
225 switch (value->type) {
226 case ACPI_TYPE_INTEGER:
227 case ACPI_TYPE_STRING:
228 case ACPI_TYPE_LOCAL_REFERENCE:
231 case ACPI_TYPE_PACKAGE:
232 for (j = 0; j < value->package.count; j++)
233 switch (value->package.elements[j].type) {
234 case ACPI_TYPE_INTEGER:
235 case ACPI_TYPE_STRING:
236 case ACPI_TYPE_LOCAL_REFERENCE:
248 static bool acpi_properties_format_valid(const union acpi_object *properties)
252 for (i = 0; i < properties->package.count; i++) {
253 const union acpi_object *property;
255 property = &properties->package.elements[i];
257 * Only two elements allowed, the first one must be a string and
258 * the second one has to satisfy certain conditions.
260 if (property->package.count != 2
261 || property->package.elements[0].type != ACPI_TYPE_STRING
262 || !acpi_property_value_ok(&property->package.elements[1]))
268 static void acpi_init_of_compatible(struct acpi_device *adev)
270 const union acpi_object *of_compatible;
273 ret = acpi_data_get_property_array(&adev->data, "compatible",
274 ACPI_TYPE_STRING, &of_compatible);
276 ret = acpi_dev_get_property(adev, "compatible",
277 ACPI_TYPE_STRING, &of_compatible);
280 && adev->parent->flags.of_compatible_ok)
286 adev->data.of_compatible = of_compatible;
289 adev->flags.of_compatible_ok = 1;
292 static bool acpi_extract_properties(const union acpi_object *desc,
293 struct acpi_device_data *data)
297 if (desc->package.count % 2)
300 /* Look for the device properties UUID. */
301 for (i = 0; i < desc->package.count; i += 2) {
302 const union acpi_object *uuid, *properties;
304 uuid = &desc->package.elements[i];
305 properties = &desc->package.elements[i + 1];
308 * The first element must be a UUID and the second one must be
311 if (uuid->type != ACPI_TYPE_BUFFER || uuid->buffer.length != 16
312 || properties->type != ACPI_TYPE_PACKAGE)
315 if (memcmp(uuid->buffer.pointer, prp_uuid, sizeof(prp_uuid)))
319 * We found the matching UUID. Now validate the format of the
320 * package immediately following it.
322 if (!acpi_properties_format_valid(properties))
325 data->properties = properties;
332 void acpi_init_properties(struct acpi_device *adev)
334 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER };
335 struct acpi_hardware_id *hwid;
337 bool acpi_of = false;
339 INIT_LIST_HEAD(&adev->data.subnodes);
342 * Check if ACPI_DT_NAMESPACE_HID is present and inthat case we fill in
343 * Device Tree compatible properties for this device.
345 list_for_each_entry(hwid, &adev->pnp.ids, list) {
346 if (!strcmp(hwid->id, ACPI_DT_NAMESPACE_HID)) {
352 status = acpi_evaluate_object_typed(adev->handle, "_DSD", NULL, &buf,
354 if (ACPI_FAILURE(status))
357 if (acpi_extract_properties(buf.pointer, &adev->data)) {
358 adev->data.pointer = buf.pointer;
360 acpi_init_of_compatible(adev);
362 if (acpi_enumerate_nondev_subnodes(adev->handle, buf.pointer,
363 &adev->data, acpi_fwnode_handle(adev)))
364 adev->data.pointer = buf.pointer;
366 if (!adev->data.pointer) {
367 acpi_handle_debug(adev->handle, "Invalid _DSD data, skipping\n");
368 ACPI_FREE(buf.pointer);
372 if (acpi_of && !adev->flags.of_compatible_ok)
373 acpi_handle_info(adev->handle,
374 ACPI_DT_NAMESPACE_HID " requires 'compatible' property\n");
377 static void acpi_destroy_nondev_subnodes(struct list_head *list)
379 struct acpi_data_node *dn, *next;
381 if (list_empty(list))
384 list_for_each_entry_safe_reverse(dn, next, list, sibling) {
385 acpi_destroy_nondev_subnodes(&dn->data.subnodes);
386 wait_for_completion(&dn->kobj_done);
387 list_del(&dn->sibling);
388 ACPI_FREE((void *)dn->data.pointer);
393 void acpi_free_properties(struct acpi_device *adev)
395 acpi_destroy_nondev_subnodes(&adev->data.subnodes);
396 ACPI_FREE((void *)adev->data.pointer);
397 adev->data.of_compatible = NULL;
398 adev->data.pointer = NULL;
399 adev->data.properties = NULL;
403 * acpi_data_get_property - return an ACPI property with given name
404 * @data: ACPI device deta object to get the property from
405 * @name: Name of the property
406 * @type: Expected property type
407 * @obj: Location to store the property value (if not %NULL)
409 * Look up a property with @name and store a pointer to the resulting ACPI
410 * object at the location pointed to by @obj if found.
412 * Callers must not attempt to free the returned objects. These objects will be
413 * freed by the ACPI core automatically during the removal of @data.
415 * Return: %0 if property with @name has been found (success),
416 * %-EINVAL if the arguments are invalid,
417 * %-EINVAL if the property doesn't exist,
418 * %-EPROTO if the property value type doesn't match @type.
420 static int acpi_data_get_property(struct acpi_device_data *data,
421 const char *name, acpi_object_type type,
422 const union acpi_object **obj)
424 const union acpi_object *properties;
430 if (!data->pointer || !data->properties)
433 properties = data->properties;
434 for (i = 0; i < properties->package.count; i++) {
435 const union acpi_object *propname, *propvalue;
436 const union acpi_object *property;
438 property = &properties->package.elements[i];
440 propname = &property->package.elements[0];
441 propvalue = &property->package.elements[1];
443 if (!strcmp(name, propname->string.pointer)) {
444 if (type != ACPI_TYPE_ANY && propvalue->type != type)
456 * acpi_dev_get_property - return an ACPI property with given name.
457 * @adev: ACPI device to get the property from.
458 * @name: Name of the property.
459 * @type: Expected property type.
460 * @obj: Location to store the property value (if not %NULL).
462 int acpi_dev_get_property(struct acpi_device *adev, const char *name,
463 acpi_object_type type, const union acpi_object **obj)
465 return adev ? acpi_data_get_property(&adev->data, name, type, obj) : -EINVAL;
467 EXPORT_SYMBOL_GPL(acpi_dev_get_property);
469 static struct acpi_device_data *acpi_device_data_of_node(struct fwnode_handle *fwnode)
471 if (fwnode->type == FWNODE_ACPI) {
472 struct acpi_device *adev = to_acpi_device_node(fwnode);
474 } else if (fwnode->type == FWNODE_ACPI_DATA) {
475 struct acpi_data_node *dn = to_acpi_data_node(fwnode);
482 * acpi_node_prop_get - return an ACPI property with given name.
483 * @fwnode: Firmware node to get the property from.
484 * @propname: Name of the property.
485 * @valptr: Location to store a pointer to the property value (if not %NULL).
487 int acpi_node_prop_get(struct fwnode_handle *fwnode, const char *propname,
490 return acpi_data_get_property(acpi_device_data_of_node(fwnode),
491 propname, ACPI_TYPE_ANY,
492 (const union acpi_object **)valptr);
496 * acpi_data_get_property_array - return an ACPI array property with given name
497 * @adev: ACPI data object to get the property from
498 * @name: Name of the property
499 * @type: Expected type of array elements
500 * @obj: Location to store a pointer to the property value (if not NULL)
502 * Look up an array property with @name and store a pointer to the resulting
503 * ACPI object at the location pointed to by @obj if found.
505 * Callers must not attempt to free the returned objects. Those objects will be
506 * freed by the ACPI core automatically during the removal of @data.
508 * Return: %0 if array property (package) with @name has been found (success),
509 * %-EINVAL if the arguments are invalid,
510 * %-EINVAL if the property doesn't exist,
511 * %-EPROTO if the property is not a package or the type of its elements
512 * doesn't match @type.
514 static int acpi_data_get_property_array(struct acpi_device_data *data,
516 acpi_object_type type,
517 const union acpi_object **obj)
519 const union acpi_object *prop;
522 ret = acpi_data_get_property(data, name, ACPI_TYPE_PACKAGE, &prop);
526 if (type != ACPI_TYPE_ANY) {
527 /* Check that all elements are of correct type. */
528 for (i = 0; i < prop->package.count; i++)
529 if (prop->package.elements[i].type != type)
539 * __acpi_node_get_property_reference - returns handle to the referenced object
540 * @fwnode: Firmware node to get the property from
541 * @propname: Name of the property
542 * @index: Index of the reference to return
543 * @num_args: Maximum number of arguments after each reference
544 * @args: Location to store the returned reference with optional arguments
546 * Find property with @name, verifify that it is a package containing at least
547 * one object reference and if so, store the ACPI device object pointer to the
548 * target object in @args->adev. If the reference includes arguments, store
549 * them in the @args->args[] array.
551 * If there's more than one reference in the property value package, @index is
552 * used to select the one to return.
554 * It is possible to leave holes in the property value set like in the
567 * Calling this function with index %2 return %-ENOENT and with index %3
568 * returns the last entry. If the property does not contain any more values
569 * %-ENODATA is returned. The NULL entry must be single integer and
570 * preferably contain value %0.
572 * Return: %0 on success, negative error code on failure.
574 int __acpi_node_get_property_reference(struct fwnode_handle *fwnode,
575 const char *propname, size_t index, size_t num_args,
576 struct acpi_reference_args *args)
578 const union acpi_object *element, *end;
579 const union acpi_object *obj;
580 struct acpi_device_data *data;
581 struct acpi_device *device;
584 data = acpi_device_data_of_node(fwnode);
588 ret = acpi_data_get_property(data, propname, ACPI_TYPE_ANY, &obj);
593 * The simplest case is when the value is a single reference. Just
594 * return that reference then.
596 if (obj->type == ACPI_TYPE_LOCAL_REFERENCE) {
600 ret = acpi_bus_get_device(obj->reference.handle, &device);
610 * If it is not a single reference, then it is a package of
611 * references followed by number of ints as follows:
613 * Package () { REF, INT, REF, INT, INT }
615 * The index argument is then used to determine which reference
616 * the caller wants (along with the arguments).
618 if (obj->type != ACPI_TYPE_PACKAGE || index >= obj->package.count)
621 element = obj->package.elements;
622 end = element + obj->package.count;
624 while (element < end) {
627 if (element->type == ACPI_TYPE_LOCAL_REFERENCE) {
628 ret = acpi_bus_get_device(element->reference.handle,
636 /* assume following integer elements are all args */
637 for (i = 0; element + i < end && i < num_args; i++) {
638 int type = element[i].type;
640 if (type == ACPI_TYPE_INTEGER)
642 else if (type == ACPI_TYPE_LOCAL_REFERENCE)
648 if (nargs > MAX_ACPI_REFERENCE_ARGS)
654 for (i = 0; i < nargs; i++)
655 args->args[i] = element[i].integer.value;
661 } else if (element->type == ACPI_TYPE_INTEGER) {
674 EXPORT_SYMBOL_GPL(__acpi_node_get_property_reference);
676 static int acpi_data_prop_read_single(struct acpi_device_data *data,
677 const char *propname,
678 enum dev_prop_type proptype, void *val)
680 const union acpi_object *obj;
686 if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) {
687 ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj);
693 if (obj->integer.value > U8_MAX)
695 *(u8 *)val = obj->integer.value;
698 if (obj->integer.value > U16_MAX)
700 *(u16 *)val = obj->integer.value;
703 if (obj->integer.value > U32_MAX)
705 *(u32 *)val = obj->integer.value;
708 *(u64 *)val = obj->integer.value;
711 } else if (proptype == DEV_PROP_STRING) {
712 ret = acpi_data_get_property(data, propname, ACPI_TYPE_STRING, &obj);
716 *(char **)val = obj->string.pointer;
725 int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname,
726 enum dev_prop_type proptype, void *val)
733 ret = acpi_data_prop_read_single(&adev->data, propname, proptype, val);
734 if (ret < 0 || proptype != ACPI_TYPE_STRING)
739 static int acpi_copy_property_array_u8(const union acpi_object *items, u8 *val,
744 for (i = 0; i < nval; i++) {
745 if (items[i].type != ACPI_TYPE_INTEGER)
747 if (items[i].integer.value > U8_MAX)
750 val[i] = items[i].integer.value;
755 static int acpi_copy_property_array_u16(const union acpi_object *items,
756 u16 *val, size_t nval)
760 for (i = 0; i < nval; i++) {
761 if (items[i].type != ACPI_TYPE_INTEGER)
763 if (items[i].integer.value > U16_MAX)
766 val[i] = items[i].integer.value;
771 static int acpi_copy_property_array_u32(const union acpi_object *items,
772 u32 *val, size_t nval)
776 for (i = 0; i < nval; i++) {
777 if (items[i].type != ACPI_TYPE_INTEGER)
779 if (items[i].integer.value > U32_MAX)
782 val[i] = items[i].integer.value;
787 static int acpi_copy_property_array_u64(const union acpi_object *items,
788 u64 *val, size_t nval)
792 for (i = 0; i < nval; i++) {
793 if (items[i].type != ACPI_TYPE_INTEGER)
796 val[i] = items[i].integer.value;
801 static int acpi_copy_property_array_string(const union acpi_object *items,
802 char **val, size_t nval)
806 for (i = 0; i < nval; i++) {
807 if (items[i].type != ACPI_TYPE_STRING)
810 val[i] = items[i].string.pointer;
815 static int acpi_data_prop_read(struct acpi_device_data *data,
816 const char *propname,
817 enum dev_prop_type proptype,
818 void *val, size_t nval)
820 const union acpi_object *obj;
821 const union acpi_object *items;
824 if (val && nval == 1) {
825 ret = acpi_data_prop_read_single(data, propname, proptype, val);
830 ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj);
835 return obj->package.count;
837 if (proptype != DEV_PROP_STRING && nval > obj->package.count)
842 items = obj->package.elements;
846 ret = acpi_copy_property_array_u8(items, (u8 *)val, nval);
849 ret = acpi_copy_property_array_u16(items, (u16 *)val, nval);
852 ret = acpi_copy_property_array_u32(items, (u32 *)val, nval);
855 ret = acpi_copy_property_array_u64(items, (u64 *)val, nval);
857 case DEV_PROP_STRING:
858 ret = acpi_copy_property_array_string(
860 min_t(u32, nval, obj->package.count));
869 int acpi_dev_prop_read(struct acpi_device *adev, const char *propname,
870 enum dev_prop_type proptype, void *val, size_t nval)
872 return adev ? acpi_data_prop_read(&adev->data, propname, proptype, val, nval) : -EINVAL;
876 * acpi_node_prop_read - retrieve the value of an ACPI property with given name.
877 * @fwnode: Firmware node to get the property from.
878 * @propname: Name of the property.
879 * @proptype: Expected property type.
880 * @val: Location to store the property value (if not %NULL).
881 * @nval: Size of the array pointed to by @val.
883 * If @val is %NULL, return the number of array elements comprising the value
884 * of the property. Otherwise, read at most @nval values to the array at the
885 * location pointed to by @val.
887 int acpi_node_prop_read(struct fwnode_handle *fwnode, const char *propname,
888 enum dev_prop_type proptype, void *val, size_t nval)
890 return acpi_data_prop_read(acpi_device_data_of_node(fwnode),
891 propname, proptype, val, nval);
895 * acpi_get_next_subnode - Return the next child node handle for a fwnode
896 * @fwnode: Firmware node to find the next child node for.
897 * @child: Handle to one of the device's child nodes or a null handle.
899 struct fwnode_handle *acpi_get_next_subnode(struct fwnode_handle *fwnode,
900 struct fwnode_handle *child)
902 struct acpi_device *adev = to_acpi_device_node(fwnode);
903 struct list_head *head, *next;
905 if (!child || child->type == FWNODE_ACPI) {
907 head = &adev->children;
911 if (list_empty(head))
915 adev = to_acpi_device_node(child);
916 next = adev->node.next;
921 adev = list_entry(next, struct acpi_device, node);
923 adev = list_first_entry(head, struct acpi_device, node);
925 return acpi_fwnode_handle(adev);
929 if (!child || child->type == FWNODE_ACPI_DATA) {
930 struct acpi_data_node *data = to_acpi_data_node(fwnode);
931 struct acpi_data_node *dn;
934 head = &adev->data.subnodes;
936 head = &data->data.subnodes;
940 if (list_empty(head))
944 dn = to_acpi_data_node(child);
945 next = dn->sibling.next;
949 dn = list_entry(next, struct acpi_data_node, sibling);
951 dn = list_first_entry(head, struct acpi_data_node, sibling);
959 * acpi_node_get_parent - Return parent fwnode of this fwnode
960 * @fwnode: Firmware node whose parent to get
962 * Returns parent node of an ACPI device or data firmware node or %NULL if
965 struct fwnode_handle *acpi_node_get_parent(struct fwnode_handle *fwnode)
967 if (is_acpi_data_node(fwnode)) {
968 /* All data nodes have parent pointer so just return that */
969 return to_acpi_data_node(fwnode)->parent;
970 } else if (is_acpi_device_node(fwnode)) {
971 acpi_handle handle, parent_handle;
973 handle = to_acpi_device_node(fwnode)->handle;
974 if (ACPI_SUCCESS(acpi_get_parent(handle, &parent_handle))) {
975 struct acpi_device *adev;
977 if (!acpi_bus_get_device(parent_handle, &adev))
978 return acpi_fwnode_handle(adev);
986 * acpi_graph_get_next_endpoint - Get next endpoint ACPI firmware node
987 * @fwnode: Pointer to the parent firmware node
988 * @prev: Previous endpoint node or %NULL to get the first
990 * Looks up next endpoint ACPI firmware node below a given @fwnode. Returns
991 * %NULL if there is no next endpoint, ERR_PTR() in case of error. In case
992 * of success the next endpoint is returned.
994 struct fwnode_handle *acpi_graph_get_next_endpoint(struct fwnode_handle *fwnode,
995 struct fwnode_handle *prev)
997 struct fwnode_handle *port = NULL;
998 struct fwnode_handle *endpoint;
1002 port = fwnode_get_next_child_node(fwnode, port);
1003 /* Ports must have port property */
1004 if (fwnode_property_present(port, "port"))
1008 port = fwnode_get_parent(prev);
1014 endpoint = fwnode_get_next_child_node(port, prev);
1016 port = fwnode_get_next_child_node(fwnode, port);
1019 if (fwnode_property_present(port, "port"))
1020 endpoint = fwnode_get_next_child_node(port, NULL);
1024 /* Endpoints must have "endpoint" property */
1025 if (!fwnode_property_present(endpoint, "endpoint"))
1026 return ERR_PTR(-EPROTO);
1033 * acpi_graph_get_child_prop_value - Return a child with a given property value
1034 * @fwnode: device fwnode
1035 * @prop_name: The name of the property to look for
1036 * @val: the desired property value
1038 * Return the port node corresponding to a given port number. Returns
1039 * the child node on success, NULL otherwise.
1041 static struct fwnode_handle *acpi_graph_get_child_prop_value(
1042 struct fwnode_handle *fwnode, const char *prop_name, unsigned int val)
1044 struct fwnode_handle *child;
1046 fwnode_for_each_child_node(fwnode, child) {
1049 if (!fwnode_property_read_u32(fwnode, prop_name, &nr))
1061 * acpi_graph_get_remote_enpoint - Parses and returns remote end of an endpoint
1062 * @fwnode: Endpoint firmware node pointing to a remote device
1063 * @parent: Firmware node of remote port parent is filled here if not %NULL
1064 * @port: Firmware node of remote port is filled here if not %NULL
1065 * @endpoint: Firmware node of remote endpoint is filled here if not %NULL
1067 * Function parses remote end of ACPI firmware remote endpoint and fills in
1068 * fields requested by the caller. Returns %0 in case of success and
1069 * negative errno otherwise.
1071 int acpi_graph_get_remote_endpoint(struct fwnode_handle *fwnode,
1072 struct fwnode_handle **parent,
1073 struct fwnode_handle **port,
1074 struct fwnode_handle **endpoint)
1076 unsigned int port_nr, endpoint_nr;
1077 struct acpi_reference_args args;
1080 memset(&args, 0, sizeof(args));
1081 ret = acpi_node_get_property_reference(fwnode, "remote-endpoint", 0,
1087 * Always require two arguments with the reference: port and
1090 if (args.nargs != 2)
1093 fwnode = acpi_fwnode_handle(args.adev);
1094 port_nr = args.args[0];
1095 endpoint_nr = args.args[1];
1100 if (!port && !endpoint)
1103 fwnode = acpi_graph_get_child_prop_value(fwnode, "port", port_nr);
1113 fwnode = acpi_graph_get_child_prop_value(fwnode, "endpoint",