Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 2 | /* |
| 3 | * ACPI device specific properties support. |
| 4 | * |
| 5 | * Copyright (C) 2014, Intel Corporation |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Authors: Mika Westerberg <mika.westerberg@linux.intel.com> |
| 9 | * Darren Hart <dvhart@linux.intel.com> |
| 10 | * Rafael J. Wysocki <rafael.j.wysocki@intel.com> |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/acpi.h> |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/export.h> |
| 16 | |
| 17 | #include "internal.h" |
| 18 | |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 19 | static int acpi_data_get_property_array(const struct acpi_device_data *data, |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 20 | const char *name, |
| 21 | acpi_object_type type, |
| 22 | const union acpi_object **obj); |
| 23 | |
Mika Westerberg | 617654a | 2018-08-16 12:28:48 +0300 | [diff] [blame] | 24 | /* |
| 25 | * The GUIDs here are made equivalent to each other in order to avoid extra |
| 26 | * complexity in the properties handling code, with the caveat that the |
| 27 | * kernel will accept certain combinations of GUID and properties that are |
| 28 | * not defined without a warning. For instance if any of the properties |
| 29 | * from different GUID appear in a property list of another, it will be |
| 30 | * accepted by the kernel. Firmware validation tools should catch these. |
| 31 | */ |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 32 | static const guid_t prp_guids[] = { |
| 33 | /* ACPI _DSD device properties GUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301 */ |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 34 | GUID_INIT(0xdaffd814, 0x6eba, 0x4d8c, |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 35 | 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01), |
Mika Westerberg | 26ad34d | 2018-09-27 16:57:14 -0500 | [diff] [blame] | 36 | /* Hotplug in D3 GUID: 6211e2c0-58a3-4af3-90e1-927a4e0c55a4 */ |
| 37 | GUID_INIT(0x6211e2c0, 0x58a3, 0x4af3, |
| 38 | 0x90, 0xe1, 0x92, 0x7a, 0x4e, 0x0c, 0x55, 0xa4), |
Mika Westerberg | 617654a | 2018-08-16 12:28:48 +0300 | [diff] [blame] | 39 | /* External facing port GUID: efcc06cc-73ac-4bc3-bff0-76143807c389 */ |
| 40 | GUID_INIT(0xefcc06cc, 0x73ac, 0x4bc3, |
| 41 | 0xbf, 0xf0, 0x76, 0x14, 0x38, 0x07, 0xc3, 0x89), |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 42 | }; |
| 43 | |
Shunyong Yang | 5f21f30 | 2019-04-01 16:26:35 +0800 | [diff] [blame] | 44 | /* ACPI _DSD data subnodes GUID: dbb8e3e6-5886-4ba6-8795-1319f52a966b */ |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 45 | static const guid_t ads_guid = |
| 46 | GUID_INIT(0xdbb8e3e6, 0x5886, 0x4ba6, |
| 47 | 0x87, 0x95, 0x13, 0x19, 0xf5, 0x2a, 0x96, 0x6b); |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 48 | |
| 49 | static bool acpi_enumerate_nondev_subnodes(acpi_handle scope, |
| 50 | const union acpi_object *desc, |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 51 | struct acpi_device_data *data, |
| 52 | struct fwnode_handle *parent); |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 53 | static bool acpi_extract_properties(const union acpi_object *desc, |
| 54 | struct acpi_device_data *data); |
| 55 | |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 56 | static bool acpi_nondev_subnode_extract(const union acpi_object *desc, |
| 57 | acpi_handle handle, |
| 58 | const union acpi_object *link, |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 59 | struct list_head *list, |
| 60 | struct fwnode_handle *parent) |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 61 | { |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 62 | struct acpi_data_node *dn; |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 63 | bool result; |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 64 | |
| 65 | dn = kzalloc(sizeof(*dn), GFP_KERNEL); |
| 66 | if (!dn) |
| 67 | return false; |
| 68 | |
| 69 | dn->name = link->package.elements[0].string.pointer; |
Sakari Ailus | db3e50f | 2017-07-21 14:39:31 +0300 | [diff] [blame] | 70 | dn->fwnode.ops = &acpi_data_fwnode_ops; |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 71 | dn->parent = parent; |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 72 | INIT_LIST_HEAD(&dn->data.properties); |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 73 | INIT_LIST_HEAD(&dn->data.subnodes); |
| 74 | |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 75 | result = acpi_extract_properties(desc, &dn->data); |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 76 | |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 77 | if (handle) { |
| 78 | acpi_handle scope; |
| 79 | acpi_status status; |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 80 | |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 81 | /* |
| 82 | * The scope for the subnode object lookup is the one of the |
| 83 | * namespace node (device) containing the object that has |
| 84 | * returned the package. That is, it's the scope of that |
| 85 | * object's parent. |
| 86 | */ |
| 87 | status = acpi_get_parent(handle, &scope); |
| 88 | if (ACPI_SUCCESS(status) |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 89 | && acpi_enumerate_nondev_subnodes(scope, desc, &dn->data, |
| 90 | &dn->fwnode)) |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 91 | result = true; |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 92 | } else if (acpi_enumerate_nondev_subnodes(NULL, desc, &dn->data, |
| 93 | &dn->fwnode)) { |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 94 | result = true; |
| 95 | } |
| 96 | |
| 97 | if (result) { |
Rafael J. Wysocki | 263b4c1 | 2015-08-27 04:37:19 +0200 | [diff] [blame] | 98 | dn->handle = handle; |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 99 | dn->data.pointer = desc; |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 100 | list_add_tail(&dn->sibling, list); |
| 101 | return true; |
| 102 | } |
| 103 | |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 104 | kfree(dn); |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 105 | acpi_handle_debug(handle, "Invalid properties/subnodes data, skipping\n"); |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 106 | return false; |
| 107 | } |
| 108 | |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 109 | static bool acpi_nondev_subnode_data_ok(acpi_handle handle, |
| 110 | const union acpi_object *link, |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 111 | struct list_head *list, |
| 112 | struct fwnode_handle *parent) |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 113 | { |
| 114 | struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER }; |
| 115 | acpi_status status; |
| 116 | |
| 117 | status = acpi_evaluate_object_typed(handle, NULL, NULL, &buf, |
| 118 | ACPI_TYPE_PACKAGE); |
| 119 | if (ACPI_FAILURE(status)) |
| 120 | return false; |
| 121 | |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 122 | if (acpi_nondev_subnode_extract(buf.pointer, handle, link, list, |
| 123 | parent)) |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 124 | return true; |
| 125 | |
| 126 | ACPI_FREE(buf.pointer); |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | static bool acpi_nondev_subnode_ok(acpi_handle scope, |
| 131 | const union acpi_object *link, |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 132 | struct list_head *list, |
| 133 | struct fwnode_handle *parent) |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 134 | { |
| 135 | acpi_handle handle; |
| 136 | acpi_status status; |
| 137 | |
| 138 | if (!scope) |
| 139 | return false; |
| 140 | |
| 141 | status = acpi_get_handle(scope, link->package.elements[1].string.pointer, |
| 142 | &handle); |
| 143 | if (ACPI_FAILURE(status)) |
| 144 | return false; |
| 145 | |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 146 | return acpi_nondev_subnode_data_ok(handle, link, list, parent); |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 149 | static int acpi_add_nondev_subnodes(acpi_handle scope, |
| 150 | const union acpi_object *links, |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 151 | struct list_head *list, |
| 152 | struct fwnode_handle *parent) |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 153 | { |
| 154 | bool ret = false; |
| 155 | int i; |
| 156 | |
| 157 | for (i = 0; i < links->package.count; i++) { |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 158 | const union acpi_object *link, *desc; |
| 159 | acpi_handle handle; |
| 160 | bool result; |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 161 | |
| 162 | link = &links->package.elements[i]; |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 163 | /* Only two elements allowed. */ |
| 164 | if (link->package.count != 2) |
| 165 | continue; |
| 166 | |
| 167 | /* The first one must be a string. */ |
| 168 | if (link->package.elements[0].type != ACPI_TYPE_STRING) |
| 169 | continue; |
| 170 | |
| 171 | /* The second one may be a string, a reference or a package. */ |
| 172 | switch (link->package.elements[1].type) { |
| 173 | case ACPI_TYPE_STRING: |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 174 | result = acpi_nondev_subnode_ok(scope, link, list, |
| 175 | parent); |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 176 | break; |
| 177 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 178 | handle = link->package.elements[1].reference.handle; |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 179 | result = acpi_nondev_subnode_data_ok(handle, link, list, |
| 180 | parent); |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 181 | break; |
| 182 | case ACPI_TYPE_PACKAGE: |
| 183 | desc = &link->package.elements[1]; |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 184 | result = acpi_nondev_subnode_extract(desc, NULL, link, |
| 185 | list, parent); |
Rafael J. Wysocki | 99db5ff | 2016-11-22 00:02:19 +0100 | [diff] [blame] | 186 | break; |
| 187 | default: |
| 188 | result = false; |
| 189 | break; |
| 190 | } |
| 191 | ret = ret || result; |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | return ret; |
| 195 | } |
| 196 | |
| 197 | static bool acpi_enumerate_nondev_subnodes(acpi_handle scope, |
| 198 | const union acpi_object *desc, |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 199 | struct acpi_device_data *data, |
| 200 | struct fwnode_handle *parent) |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 201 | { |
| 202 | int i; |
| 203 | |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 204 | /* Look for the ACPI data subnodes GUID. */ |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 205 | for (i = 0; i < desc->package.count; i += 2) { |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 206 | const union acpi_object *guid, *links; |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 207 | |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 208 | guid = &desc->package.elements[i]; |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 209 | links = &desc->package.elements[i + 1]; |
| 210 | |
| 211 | /* |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 212 | * The first element must be a GUID and the second one must be |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 213 | * a package. |
| 214 | */ |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 215 | if (guid->type != ACPI_TYPE_BUFFER || |
| 216 | guid->buffer.length != 16 || |
| 217 | links->type != ACPI_TYPE_PACKAGE) |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 218 | break; |
| 219 | |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 220 | if (!guid_equal((guid_t *)guid->buffer.pointer, &ads_guid)) |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 221 | continue; |
| 222 | |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 223 | return acpi_add_nondev_subnodes(scope, links, &data->subnodes, |
| 224 | parent); |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | return false; |
| 228 | } |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 229 | |
| 230 | static bool acpi_property_value_ok(const union acpi_object *value) |
| 231 | { |
| 232 | int j; |
| 233 | |
| 234 | /* |
| 235 | * The value must be an integer, a string, a reference, or a package |
| 236 | * whose every element must be an integer, a string, or a reference. |
| 237 | */ |
| 238 | switch (value->type) { |
| 239 | case ACPI_TYPE_INTEGER: |
| 240 | case ACPI_TYPE_STRING: |
| 241 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 242 | return true; |
| 243 | |
| 244 | case ACPI_TYPE_PACKAGE: |
| 245 | for (j = 0; j < value->package.count; j++) |
| 246 | switch (value->package.elements[j].type) { |
| 247 | case ACPI_TYPE_INTEGER: |
| 248 | case ACPI_TYPE_STRING: |
| 249 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 250 | continue; |
| 251 | |
| 252 | default: |
| 253 | return false; |
| 254 | } |
| 255 | |
| 256 | return true; |
| 257 | } |
| 258 | return false; |
| 259 | } |
| 260 | |
| 261 | static bool acpi_properties_format_valid(const union acpi_object *properties) |
| 262 | { |
| 263 | int i; |
| 264 | |
| 265 | for (i = 0; i < properties->package.count; i++) { |
| 266 | const union acpi_object *property; |
| 267 | |
| 268 | property = &properties->package.elements[i]; |
| 269 | /* |
| 270 | * Only two elements allowed, the first one must be a string and |
| 271 | * the second one has to satisfy certain conditions. |
| 272 | */ |
| 273 | if (property->package.count != 2 |
| 274 | || property->package.elements[0].type != ACPI_TYPE_STRING |
| 275 | || !acpi_property_value_ok(&property->package.elements[1])) |
| 276 | return false; |
| 277 | } |
| 278 | return true; |
| 279 | } |
| 280 | |
Mika Westerberg | 733e625 | 2014-10-21 13:33:56 +0200 | [diff] [blame] | 281 | static void acpi_init_of_compatible(struct acpi_device *adev) |
| 282 | { |
| 283 | const union acpi_object *of_compatible; |
Mika Westerberg | 733e625 | 2014-10-21 13:33:56 +0200 | [diff] [blame] | 284 | int ret; |
| 285 | |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 286 | ret = acpi_data_get_property_array(&adev->data, "compatible", |
| 287 | ACPI_TYPE_STRING, &of_compatible); |
Rafael J. Wysocki | 5c53b26 | 2015-05-05 15:43:07 +0200 | [diff] [blame] | 288 | if (ret) { |
| 289 | ret = acpi_dev_get_property(adev, "compatible", |
| 290 | ACPI_TYPE_STRING, &of_compatible); |
| 291 | if (ret) { |
| 292 | if (adev->parent |
| 293 | && adev->parent->flags.of_compatible_ok) |
| 294 | goto out; |
| 295 | |
| 296 | return; |
| 297 | } |
| 298 | } |
| 299 | adev->data.of_compatible = of_compatible; |
| 300 | |
| 301 | out: |
| 302 | adev->flags.of_compatible_ok = 1; |
| 303 | } |
| 304 | |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 305 | static bool acpi_is_property_guid(const guid_t *guid) |
| 306 | { |
| 307 | int i; |
| 308 | |
| 309 | for (i = 0; i < ARRAY_SIZE(prp_guids); i++) { |
| 310 | if (guid_equal(guid, &prp_guids[i])) |
| 311 | return true; |
| 312 | } |
| 313 | |
| 314 | return false; |
| 315 | } |
| 316 | |
| 317 | struct acpi_device_properties * |
| 318 | acpi_data_add_props(struct acpi_device_data *data, const guid_t *guid, |
| 319 | const union acpi_object *properties) |
| 320 | { |
| 321 | struct acpi_device_properties *props; |
| 322 | |
| 323 | props = kzalloc(sizeof(*props), GFP_KERNEL); |
| 324 | if (props) { |
| 325 | INIT_LIST_HEAD(&props->list); |
| 326 | props->guid = guid; |
| 327 | props->properties = properties; |
| 328 | list_add_tail(&props->list, &data->properties); |
| 329 | } |
| 330 | |
| 331 | return props; |
| 332 | } |
| 333 | |
Rafael J. Wysocki | bd8191c | 2015-08-27 04:35:14 +0200 | [diff] [blame] | 334 | static bool acpi_extract_properties(const union acpi_object *desc, |
| 335 | struct acpi_device_data *data) |
Rafael J. Wysocki | 5c53b26 | 2015-05-05 15:43:07 +0200 | [diff] [blame] | 336 | { |
Rafael J. Wysocki | 5c53b26 | 2015-05-05 15:43:07 +0200 | [diff] [blame] | 337 | int i; |
| 338 | |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 339 | if (desc->package.count % 2) |
Rafael J. Wysocki | bd8191c | 2015-08-27 04:35:14 +0200 | [diff] [blame] | 340 | return false; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 341 | |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 342 | /* Look for the device properties GUID. */ |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 343 | for (i = 0; i < desc->package.count; i += 2) { |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 344 | const union acpi_object *guid, *properties; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 345 | |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 346 | guid = &desc->package.elements[i]; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 347 | properties = &desc->package.elements[i + 1]; |
| 348 | |
| 349 | /* |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 350 | * The first element must be a GUID and the second one must be |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 351 | * a package. |
| 352 | */ |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 353 | if (guid->type != ACPI_TYPE_BUFFER || |
| 354 | guid->buffer.length != 16 || |
| 355 | properties->type != ACPI_TYPE_PACKAGE) |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 356 | break; |
| 357 | |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 358 | if (!acpi_is_property_guid((guid_t *)guid->buffer.pointer)) |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 359 | continue; |
| 360 | |
| 361 | /* |
Andy Shevchenko | 3689d3d | 2017-07-19 21:28:57 +0300 | [diff] [blame] | 362 | * We found the matching GUID. Now validate the format of the |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 363 | * package immediately following it. |
| 364 | */ |
| 365 | if (!acpi_properties_format_valid(properties)) |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 366 | continue; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 367 | |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 368 | acpi_data_add_props(data, (const guid_t *)guid->buffer.pointer, |
| 369 | properties); |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 370 | } |
| 371 | |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 372 | return !list_empty(&data->properties); |
Rafael J. Wysocki | bd8191c | 2015-08-27 04:35:14 +0200 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | void acpi_init_properties(struct acpi_device *adev) |
| 376 | { |
| 377 | struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER }; |
| 378 | struct acpi_hardware_id *hwid; |
| 379 | acpi_status status; |
| 380 | bool acpi_of = false; |
| 381 | |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 382 | INIT_LIST_HEAD(&adev->data.properties); |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 383 | INIT_LIST_HEAD(&adev->data.subnodes); |
| 384 | |
Lukas Wunner | 75fc70e | 2017-08-01 14:10:41 +0200 | [diff] [blame] | 385 | if (!adev->handle) |
| 386 | return; |
| 387 | |
Rafael J. Wysocki | bd8191c | 2015-08-27 04:35:14 +0200 | [diff] [blame] | 388 | /* |
| 389 | * Check if ACPI_DT_NAMESPACE_HID is present and inthat case we fill in |
| 390 | * Device Tree compatible properties for this device. |
| 391 | */ |
| 392 | list_for_each_entry(hwid, &adev->pnp.ids, list) { |
| 393 | if (!strcmp(hwid->id, ACPI_DT_NAMESPACE_HID)) { |
| 394 | acpi_of = true; |
| 395 | break; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | status = acpi_evaluate_object_typed(adev->handle, "_DSD", NULL, &buf, |
| 400 | ACPI_TYPE_PACKAGE); |
| 401 | if (ACPI_FAILURE(status)) |
| 402 | goto out; |
| 403 | |
| 404 | if (acpi_extract_properties(buf.pointer, &adev->data)) { |
| 405 | adev->data.pointer = buf.pointer; |
| 406 | if (acpi_of) |
| 407 | acpi_init_of_compatible(adev); |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 408 | } |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 409 | if (acpi_enumerate_nondev_subnodes(adev->handle, buf.pointer, |
| 410 | &adev->data, acpi_fwnode_handle(adev))) |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 411 | adev->data.pointer = buf.pointer; |
| 412 | |
| 413 | if (!adev->data.pointer) { |
Rafael J. Wysocki | bd8191c | 2015-08-27 04:35:14 +0200 | [diff] [blame] | 414 | acpi_handle_debug(adev->handle, "Invalid _DSD data, skipping\n"); |
| 415 | ACPI_FREE(buf.pointer); |
| 416 | } |
Rafael J. Wysocki | 5c53b26 | 2015-05-05 15:43:07 +0200 | [diff] [blame] | 417 | |
| 418 | out: |
| 419 | if (acpi_of && !adev->flags.of_compatible_ok) |
| 420 | acpi_handle_info(adev->handle, |
Rafael J. Wysocki | ee89209 | 2015-05-22 04:24:34 +0200 | [diff] [blame] | 421 | ACPI_DT_NAMESPACE_HID " requires 'compatible' property\n"); |
Lukas Wunner | 899596e | 2017-08-01 14:10:41 +0200 | [diff] [blame] | 422 | |
| 423 | if (!adev->data.pointer) |
| 424 | acpi_extract_apple_properties(adev); |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 425 | } |
| 426 | |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 427 | static void acpi_destroy_nondev_subnodes(struct list_head *list) |
| 428 | { |
| 429 | struct acpi_data_node *dn, *next; |
| 430 | |
| 431 | if (list_empty(list)) |
| 432 | return; |
| 433 | |
| 434 | list_for_each_entry_safe_reverse(dn, next, list, sibling) { |
| 435 | acpi_destroy_nondev_subnodes(&dn->data.subnodes); |
Rafael J. Wysocki | 263b4c1 | 2015-08-27 04:37:19 +0200 | [diff] [blame] | 436 | wait_for_completion(&dn->kobj_done); |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 437 | list_del(&dn->sibling); |
| 438 | ACPI_FREE((void *)dn->data.pointer); |
| 439 | kfree(dn); |
| 440 | } |
| 441 | } |
| 442 | |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 443 | void acpi_free_properties(struct acpi_device *adev) |
| 444 | { |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 445 | struct acpi_device_properties *props, *tmp; |
| 446 | |
Rafael J. Wysocki | 445b0eb | 2015-08-27 04:36:14 +0200 | [diff] [blame] | 447 | acpi_destroy_nondev_subnodes(&adev->data.subnodes); |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 448 | ACPI_FREE((void *)adev->data.pointer); |
Mika Westerberg | 733e625 | 2014-10-21 13:33:56 +0200 | [diff] [blame] | 449 | adev->data.of_compatible = NULL; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 450 | adev->data.pointer = NULL; |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 451 | list_for_each_entry_safe(props, tmp, &adev->data.properties, list) { |
| 452 | list_del(&props->list); |
| 453 | kfree(props); |
| 454 | } |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /** |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 458 | * acpi_data_get_property - return an ACPI property with given name |
| 459 | * @data: ACPI device deta object to get the property from |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 460 | * @name: Name of the property |
| 461 | * @type: Expected property type |
| 462 | * @obj: Location to store the property value (if not %NULL) |
| 463 | * |
| 464 | * Look up a property with @name and store a pointer to the resulting ACPI |
| 465 | * object at the location pointed to by @obj if found. |
| 466 | * |
| 467 | * Callers must not attempt to free the returned objects. These objects will be |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 468 | * freed by the ACPI core automatically during the removal of @data. |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 469 | * |
| 470 | * Return: %0 if property with @name has been found (success), |
| 471 | * %-EINVAL if the arguments are invalid, |
Andy Shevchenko | 3c60f11 | 2015-11-30 17:11:35 +0200 | [diff] [blame] | 472 | * %-EINVAL if the property doesn't exist, |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 473 | * %-EPROTO if the property value type doesn't match @type. |
| 474 | */ |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 475 | static int acpi_data_get_property(const struct acpi_device_data *data, |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 476 | const char *name, acpi_object_type type, |
| 477 | const union acpi_object **obj) |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 478 | { |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 479 | const struct acpi_device_properties *props; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 480 | |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 481 | if (!data || !name) |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 482 | return -EINVAL; |
| 483 | |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 484 | if (!data->pointer || list_empty(&data->properties)) |
Andy Shevchenko | 3c60f11 | 2015-11-30 17:11:35 +0200 | [diff] [blame] | 485 | return -EINVAL; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 486 | |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 487 | list_for_each_entry(props, &data->properties, list) { |
| 488 | const union acpi_object *properties; |
| 489 | unsigned int i; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 490 | |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 491 | properties = props->properties; |
| 492 | for (i = 0; i < properties->package.count; i++) { |
| 493 | const union acpi_object *propname, *propvalue; |
| 494 | const union acpi_object *property; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 495 | |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 496 | property = &properties->package.elements[i]; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 497 | |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 498 | propname = &property->package.elements[0]; |
| 499 | propvalue = &property->package.elements[1]; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 500 | |
Mika Westerberg | 5f5e489 | 2018-09-27 16:57:05 -0500 | [diff] [blame] | 501 | if (!strcmp(name, propname->string.pointer)) { |
| 502 | if (type != ACPI_TYPE_ANY && |
| 503 | propvalue->type != type) |
| 504 | return -EPROTO; |
| 505 | if (obj) |
| 506 | *obj = propvalue; |
| 507 | |
| 508 | return 0; |
| 509 | } |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 510 | } |
| 511 | } |
Andy Shevchenko | 3c60f11 | 2015-11-30 17:11:35 +0200 | [diff] [blame] | 512 | return -EINVAL; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 513 | } |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 514 | |
| 515 | /** |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 516 | * acpi_dev_get_property - return an ACPI property with given name. |
| 517 | * @adev: ACPI device to get the property from. |
| 518 | * @name: Name of the property. |
| 519 | * @type: Expected property type. |
| 520 | * @obj: Location to store the property value (if not %NULL). |
| 521 | */ |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 522 | int acpi_dev_get_property(const struct acpi_device *adev, const char *name, |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 523 | acpi_object_type type, const union acpi_object **obj) |
| 524 | { |
| 525 | return adev ? acpi_data_get_property(&adev->data, name, type, obj) : -EINVAL; |
| 526 | } |
| 527 | EXPORT_SYMBOL_GPL(acpi_dev_get_property); |
| 528 | |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 529 | static const struct acpi_device_data * |
| 530 | acpi_device_data_of_node(const struct fwnode_handle *fwnode) |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 531 | { |
Sakari Ailus | db3e50f | 2017-07-21 14:39:31 +0300 | [diff] [blame] | 532 | if (is_acpi_device_node(fwnode)) { |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 533 | const struct acpi_device *adev = to_acpi_device_node(fwnode); |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 534 | return &adev->data; |
Sakari Ailus | db3e50f | 2017-07-21 14:39:31 +0300 | [diff] [blame] | 535 | } else if (is_acpi_data_node(fwnode)) { |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 536 | const struct acpi_data_node *dn = to_acpi_data_node(fwnode); |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 537 | return &dn->data; |
| 538 | } |
| 539 | return NULL; |
| 540 | } |
| 541 | |
| 542 | /** |
| 543 | * acpi_node_prop_get - return an ACPI property with given name. |
| 544 | * @fwnode: Firmware node to get the property from. |
| 545 | * @propname: Name of the property. |
| 546 | * @valptr: Location to store a pointer to the property value (if not %NULL). |
| 547 | */ |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 548 | int acpi_node_prop_get(const struct fwnode_handle *fwnode, |
| 549 | const char *propname, void **valptr) |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 550 | { |
| 551 | return acpi_data_get_property(acpi_device_data_of_node(fwnode), |
| 552 | propname, ACPI_TYPE_ANY, |
| 553 | (const union acpi_object **)valptr); |
| 554 | } |
| 555 | |
| 556 | /** |
| 557 | * acpi_data_get_property_array - return an ACPI array property with given name |
| 558 | * @adev: ACPI data object to get the property from |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 559 | * @name: Name of the property |
| 560 | * @type: Expected type of array elements |
| 561 | * @obj: Location to store a pointer to the property value (if not NULL) |
| 562 | * |
| 563 | * Look up an array property with @name and store a pointer to the resulting |
| 564 | * ACPI object at the location pointed to by @obj if found. |
| 565 | * |
| 566 | * Callers must not attempt to free the returned objects. Those objects will be |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 567 | * freed by the ACPI core automatically during the removal of @data. |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 568 | * |
| 569 | * Return: %0 if array property (package) with @name has been found (success), |
| 570 | * %-EINVAL if the arguments are invalid, |
Andy Shevchenko | 3c60f11 | 2015-11-30 17:11:35 +0200 | [diff] [blame] | 571 | * %-EINVAL if the property doesn't exist, |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 572 | * %-EPROTO if the property is not a package or the type of its elements |
| 573 | * doesn't match @type. |
| 574 | */ |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 575 | static int acpi_data_get_property_array(const struct acpi_device_data *data, |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 576 | const char *name, |
| 577 | acpi_object_type type, |
| 578 | const union acpi_object **obj) |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 579 | { |
| 580 | const union acpi_object *prop; |
| 581 | int ret, i; |
| 582 | |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 583 | ret = acpi_data_get_property(data, name, ACPI_TYPE_PACKAGE, &prop); |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 584 | if (ret) |
| 585 | return ret; |
| 586 | |
| 587 | if (type != ACPI_TYPE_ANY) { |
| 588 | /* Check that all elements are of correct type. */ |
| 589 | for (i = 0; i < prop->package.count; i++) |
| 590 | if (prop->package.elements[i].type != type) |
| 591 | return -EPROTO; |
| 592 | } |
| 593 | if (obj) |
| 594 | *obj = prop; |
| 595 | |
| 596 | return 0; |
| 597 | } |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 598 | |
Sakari Ailus | 4eb0c3b | 2018-07-17 17:19:12 +0300 | [diff] [blame] | 599 | static struct fwnode_handle * |
| 600 | acpi_fwnode_get_named_child_node(const struct fwnode_handle *fwnode, |
| 601 | const char *childname) |
| 602 | { |
| 603 | struct fwnode_handle *child; |
| 604 | |
| 605 | /* |
| 606 | * Find first matching named child node of this fwnode. |
| 607 | * For ACPI this will be a data only sub-node. |
| 608 | */ |
| 609 | fwnode_for_each_child_node(fwnode, child) |
| 610 | if (acpi_data_node_match(child, childname)) |
| 611 | return child; |
| 612 | |
| 613 | return NULL; |
| 614 | } |
| 615 | |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 616 | /** |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 617 | * __acpi_node_get_property_reference - returns handle to the referenced object |
| 618 | * @fwnode: Firmware node to get the property from |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 619 | * @propname: Name of the property |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 620 | * @index: Index of the reference to return |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 621 | * @num_args: Maximum number of arguments after each reference |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 622 | * @args: Location to store the returned reference with optional arguments |
| 623 | * |
| 624 | * Find property with @name, verifify that it is a package containing at least |
| 625 | * one object reference and if so, store the ACPI device object pointer to the |
Rafael J. Wysocki | 60ba032 | 2014-11-05 00:29:07 +0100 | [diff] [blame] | 626 | * target object in @args->adev. If the reference includes arguments, store |
| 627 | * them in the @args->args[] array. |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 628 | * |
Rafael J. Wysocki | 60ba032 | 2014-11-05 00:29:07 +0100 | [diff] [blame] | 629 | * If there's more than one reference in the property value package, @index is |
| 630 | * used to select the one to return. |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 631 | * |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 632 | * It is possible to leave holes in the property value set like in the |
| 633 | * example below: |
| 634 | * |
| 635 | * Package () { |
| 636 | * "cs-gpios", |
| 637 | * Package () { |
| 638 | * ^GPIO, 19, 0, 0, |
| 639 | * ^GPIO, 20, 0, 0, |
| 640 | * 0, |
| 641 | * ^GPIO, 21, 0, 0, |
| 642 | * } |
| 643 | * } |
| 644 | * |
Sakari Ailus | c343bc2 | 2017-09-26 12:08:27 +0300 | [diff] [blame] | 645 | * Calling this function with index %2 or index %3 return %-ENOENT. If the |
| 646 | * property does not contain any more values %-ENOENT is returned. The NULL |
| 647 | * entry must be single integer and preferably contain value %0. |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 648 | * |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 649 | * Return: %0 on success, negative error code on failure. |
| 650 | */ |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 651 | int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 652 | const char *propname, size_t index, size_t num_args, |
Sakari Ailus | 977d5ad | 2018-07-17 17:19:11 +0300 | [diff] [blame] | 653 | struct fwnode_reference_args *args) |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 654 | { |
| 655 | const union acpi_object *element, *end; |
| 656 | const union acpi_object *obj; |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 657 | const struct acpi_device_data *data; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 658 | struct acpi_device *device; |
| 659 | int ret, idx = 0; |
| 660 | |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 661 | data = acpi_device_data_of_node(fwnode); |
| 662 | if (!data) |
Sakari Ailus | c343bc2 | 2017-09-26 12:08:27 +0300 | [diff] [blame] | 663 | return -ENOENT; |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 664 | |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 665 | ret = acpi_data_get_property(data, propname, ACPI_TYPE_ANY, &obj); |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 666 | if (ret) |
Sakari Ailus | 51858a2 | 2017-10-11 11:06:13 +0300 | [diff] [blame] | 667 | return ret == -EINVAL ? -ENOENT : -EINVAL; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 668 | |
| 669 | /* |
| 670 | * The simplest case is when the value is a single reference. Just |
| 671 | * return that reference then. |
| 672 | */ |
| 673 | if (obj->type == ACPI_TYPE_LOCAL_REFERENCE) { |
Rafael J. Wysocki | 60ba032 | 2014-11-05 00:29:07 +0100 | [diff] [blame] | 674 | if (index) |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 675 | return -EINVAL; |
| 676 | |
| 677 | ret = acpi_bus_get_device(obj->reference.handle, &device); |
| 678 | if (ret) |
Sakari Ailus | 51858a2 | 2017-10-11 11:06:13 +0300 | [diff] [blame] | 679 | return ret == -ENODEV ? -EINVAL : ret; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 680 | |
Sakari Ailus | 977d5ad | 2018-07-17 17:19:11 +0300 | [diff] [blame] | 681 | args->fwnode = acpi_fwnode_handle(device); |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 682 | args->nargs = 0; |
| 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | /* |
| 687 | * If it is not a single reference, then it is a package of |
| 688 | * references followed by number of ints as follows: |
| 689 | * |
| 690 | * Package () { REF, INT, REF, INT, INT } |
| 691 | * |
| 692 | * The index argument is then used to determine which reference |
| 693 | * the caller wants (along with the arguments). |
| 694 | */ |
Sakari Ailus | 51858a2 | 2017-10-11 11:06:13 +0300 | [diff] [blame] | 695 | if (obj->type != ACPI_TYPE_PACKAGE) |
| 696 | return -EINVAL; |
| 697 | if (index >= obj->package.count) |
| 698 | return -ENOENT; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 699 | |
| 700 | element = obj->package.elements; |
| 701 | end = element + obj->package.count; |
| 702 | |
| 703 | while (element < end) { |
| 704 | u32 nargs, i; |
| 705 | |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 706 | if (element->type == ACPI_TYPE_LOCAL_REFERENCE) { |
Sakari Ailus | 4eb0c3b | 2018-07-17 17:19:12 +0300 | [diff] [blame] | 707 | struct fwnode_handle *ref_fwnode; |
| 708 | |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 709 | ret = acpi_bus_get_device(element->reference.handle, |
| 710 | &device); |
| 711 | if (ret) |
Sakari Ailus | c343bc2 | 2017-09-26 12:08:27 +0300 | [diff] [blame] | 712 | return -EINVAL; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 713 | |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 714 | nargs = 0; |
| 715 | element++; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 716 | |
Sakari Ailus | 4eb0c3b | 2018-07-17 17:19:12 +0300 | [diff] [blame] | 717 | /* |
| 718 | * Find the referred data extension node under the |
| 719 | * referred device node. |
| 720 | */ |
| 721 | for (ref_fwnode = acpi_fwnode_handle(device); |
| 722 | element < end && element->type == ACPI_TYPE_STRING; |
| 723 | element++) { |
| 724 | ref_fwnode = acpi_fwnode_get_named_child_node( |
| 725 | ref_fwnode, element->string.pointer); |
| 726 | if (!ref_fwnode) |
| 727 | return -EINVAL; |
| 728 | } |
| 729 | |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 730 | /* assume following integer elements are all args */ |
| 731 | for (i = 0; element + i < end && i < num_args; i++) { |
| 732 | int type = element[i].type; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 733 | |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 734 | if (type == ACPI_TYPE_INTEGER) |
| 735 | nargs++; |
| 736 | else if (type == ACPI_TYPE_LOCAL_REFERENCE) |
| 737 | break; |
| 738 | else |
Sakari Ailus | c343bc2 | 2017-09-26 12:08:27 +0300 | [diff] [blame] | 739 | return -EINVAL; |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 740 | } |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 741 | |
Sakari Ailus | 977d5ad | 2018-07-17 17:19:11 +0300 | [diff] [blame] | 742 | if (nargs > NR_FWNODE_REFERENCE_ARGS) |
Sakari Ailus | c343bc2 | 2017-09-26 12:08:27 +0300 | [diff] [blame] | 743 | return -EINVAL; |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 744 | |
| 745 | if (idx == index) { |
Sakari Ailus | 4eb0c3b | 2018-07-17 17:19:12 +0300 | [diff] [blame] | 746 | args->fwnode = ref_fwnode; |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 747 | args->nargs = nargs; |
| 748 | for (i = 0; i < nargs; i++) |
| 749 | args->args[i] = element[i].integer.value; |
| 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | element += nargs; |
| 755 | } else if (element->type == ACPI_TYPE_INTEGER) { |
| 756 | if (idx == index) |
| 757 | return -ENOENT; |
| 758 | element++; |
| 759 | } else { |
Sakari Ailus | c343bc2 | 2017-09-26 12:08:27 +0300 | [diff] [blame] | 760 | return -EINVAL; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 761 | } |
| 762 | |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 763 | idx++; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 764 | } |
| 765 | |
Sakari Ailus | c343bc2 | 2017-09-26 12:08:27 +0300 | [diff] [blame] | 766 | return -ENOENT; |
Mika Westerberg | ffdcd95 | 2014-10-21 13:33:55 +0200 | [diff] [blame] | 767 | } |
Mika Westerberg | b60e4ea | 2016-09-29 16:39:41 +0300 | [diff] [blame] | 768 | EXPORT_SYMBOL_GPL(__acpi_node_get_property_reference); |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 769 | |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 770 | static int acpi_data_prop_read_single(const struct acpi_device_data *data, |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 771 | const char *propname, |
| 772 | enum dev_prop_type proptype, void *val) |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 773 | { |
| 774 | const union acpi_object *obj; |
| 775 | int ret; |
| 776 | |
| 777 | if (!val) |
| 778 | return -EINVAL; |
| 779 | |
| 780 | if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) { |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 781 | ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj); |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 782 | if (ret) |
| 783 | return ret; |
| 784 | |
| 785 | switch (proptype) { |
| 786 | case DEV_PROP_U8: |
| 787 | if (obj->integer.value > U8_MAX) |
| 788 | return -EOVERFLOW; |
| 789 | *(u8 *)val = obj->integer.value; |
| 790 | break; |
| 791 | case DEV_PROP_U16: |
| 792 | if (obj->integer.value > U16_MAX) |
| 793 | return -EOVERFLOW; |
| 794 | *(u16 *)val = obj->integer.value; |
| 795 | break; |
| 796 | case DEV_PROP_U32: |
| 797 | if (obj->integer.value > U32_MAX) |
| 798 | return -EOVERFLOW; |
| 799 | *(u32 *)val = obj->integer.value; |
| 800 | break; |
| 801 | default: |
| 802 | *(u64 *)val = obj->integer.value; |
| 803 | break; |
| 804 | } |
| 805 | } else if (proptype == DEV_PROP_STRING) { |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 806 | ret = acpi_data_get_property(data, propname, ACPI_TYPE_STRING, &obj); |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 807 | if (ret) |
| 808 | return ret; |
| 809 | |
| 810 | *(char **)val = obj->string.pointer; |
Sakari Ailus | b0b027c | 2017-03-28 15:22:19 +0300 | [diff] [blame] | 811 | |
| 812 | return 1; |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 813 | } else { |
| 814 | ret = -EINVAL; |
| 815 | } |
| 816 | return ret; |
| 817 | } |
| 818 | |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 819 | int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname, |
| 820 | enum dev_prop_type proptype, void *val) |
| 821 | { |
Sakari Ailus | b0b027c | 2017-03-28 15:22:19 +0300 | [diff] [blame] | 822 | int ret; |
| 823 | |
| 824 | if (!adev) |
| 825 | return -EINVAL; |
| 826 | |
| 827 | ret = acpi_data_prop_read_single(&adev->data, propname, proptype, val); |
| 828 | if (ret < 0 || proptype != ACPI_TYPE_STRING) |
| 829 | return ret; |
| 830 | return 0; |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 831 | } |
| 832 | |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 833 | static int acpi_copy_property_array_u8(const union acpi_object *items, u8 *val, |
| 834 | size_t nval) |
| 835 | { |
| 836 | int i; |
| 837 | |
| 838 | for (i = 0; i < nval; i++) { |
| 839 | if (items[i].type != ACPI_TYPE_INTEGER) |
| 840 | return -EPROTO; |
| 841 | if (items[i].integer.value > U8_MAX) |
| 842 | return -EOVERFLOW; |
| 843 | |
| 844 | val[i] = items[i].integer.value; |
| 845 | } |
| 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | static int acpi_copy_property_array_u16(const union acpi_object *items, |
| 850 | u16 *val, size_t nval) |
| 851 | { |
| 852 | int i; |
| 853 | |
| 854 | for (i = 0; i < nval; i++) { |
| 855 | if (items[i].type != ACPI_TYPE_INTEGER) |
| 856 | return -EPROTO; |
| 857 | if (items[i].integer.value > U16_MAX) |
| 858 | return -EOVERFLOW; |
| 859 | |
| 860 | val[i] = items[i].integer.value; |
| 861 | } |
| 862 | return 0; |
| 863 | } |
| 864 | |
| 865 | static int acpi_copy_property_array_u32(const union acpi_object *items, |
| 866 | u32 *val, size_t nval) |
| 867 | { |
| 868 | int i; |
| 869 | |
| 870 | for (i = 0; i < nval; i++) { |
| 871 | if (items[i].type != ACPI_TYPE_INTEGER) |
| 872 | return -EPROTO; |
| 873 | if (items[i].integer.value > U32_MAX) |
| 874 | return -EOVERFLOW; |
| 875 | |
| 876 | val[i] = items[i].integer.value; |
| 877 | } |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | static int acpi_copy_property_array_u64(const union acpi_object *items, |
| 882 | u64 *val, size_t nval) |
| 883 | { |
| 884 | int i; |
| 885 | |
| 886 | for (i = 0; i < nval; i++) { |
| 887 | if (items[i].type != ACPI_TYPE_INTEGER) |
| 888 | return -EPROTO; |
| 889 | |
| 890 | val[i] = items[i].integer.value; |
| 891 | } |
| 892 | return 0; |
| 893 | } |
| 894 | |
| 895 | static int acpi_copy_property_array_string(const union acpi_object *items, |
| 896 | char **val, size_t nval) |
| 897 | { |
| 898 | int i; |
| 899 | |
| 900 | for (i = 0; i < nval; i++) { |
| 901 | if (items[i].type != ACPI_TYPE_STRING) |
| 902 | return -EPROTO; |
| 903 | |
| 904 | val[i] = items[i].string.pointer; |
| 905 | } |
Sakari Ailus | b0b027c | 2017-03-28 15:22:19 +0300 | [diff] [blame] | 906 | return nval; |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 907 | } |
| 908 | |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 909 | static int acpi_data_prop_read(const struct acpi_device_data *data, |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 910 | const char *propname, |
| 911 | enum dev_prop_type proptype, |
| 912 | void *val, size_t nval) |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 913 | { |
| 914 | const union acpi_object *obj; |
| 915 | const union acpi_object *items; |
| 916 | int ret; |
| 917 | |
| 918 | if (val && nval == 1) { |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 919 | ret = acpi_data_prop_read_single(data, propname, proptype, val); |
Sakari Ailus | b0b027c | 2017-03-28 15:22:19 +0300 | [diff] [blame] | 920 | if (ret >= 0) |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 921 | return ret; |
| 922 | } |
| 923 | |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 924 | ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj); |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 925 | if (ret) |
| 926 | return ret; |
| 927 | |
| 928 | if (!val) |
| 929 | return obj->package.count; |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 930 | |
Sakari Ailus | b0b027c | 2017-03-28 15:22:19 +0300 | [diff] [blame] | 931 | if (proptype != DEV_PROP_STRING && nval > obj->package.count) |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 932 | return -EOVERFLOW; |
Andy Shevchenko | 7dc59dc | 2015-08-10 19:56:48 +0300 | [diff] [blame] | 933 | else if (nval <= 0) |
| 934 | return -EINVAL; |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 935 | |
| 936 | items = obj->package.elements; |
Andy Shevchenko | 7dc59dc | 2015-08-10 19:56:48 +0300 | [diff] [blame] | 937 | |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 938 | switch (proptype) { |
| 939 | case DEV_PROP_U8: |
| 940 | ret = acpi_copy_property_array_u8(items, (u8 *)val, nval); |
| 941 | break; |
| 942 | case DEV_PROP_U16: |
| 943 | ret = acpi_copy_property_array_u16(items, (u16 *)val, nval); |
| 944 | break; |
| 945 | case DEV_PROP_U32: |
| 946 | ret = acpi_copy_property_array_u32(items, (u32 *)val, nval); |
| 947 | break; |
| 948 | case DEV_PROP_U64: |
| 949 | ret = acpi_copy_property_array_u64(items, (u64 *)val, nval); |
| 950 | break; |
| 951 | case DEV_PROP_STRING: |
Sakari Ailus | b0b027c | 2017-03-28 15:22:19 +0300 | [diff] [blame] | 952 | ret = acpi_copy_property_array_string( |
| 953 | items, (char **)val, |
| 954 | min_t(u32, nval, obj->package.count)); |
Rafael J. Wysocki | b31384f | 2014-11-04 01:28:56 +0100 | [diff] [blame] | 955 | break; |
| 956 | default: |
| 957 | ret = -EINVAL; |
| 958 | break; |
| 959 | } |
| 960 | return ret; |
| 961 | } |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 962 | |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 963 | int acpi_dev_prop_read(const struct acpi_device *adev, const char *propname, |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 964 | enum dev_prop_type proptype, void *val, size_t nval) |
| 965 | { |
| 966 | return adev ? acpi_data_prop_read(&adev->data, propname, proptype, val, nval) : -EINVAL; |
| 967 | } |
| 968 | |
| 969 | /** |
| 970 | * acpi_node_prop_read - retrieve the value of an ACPI property with given name. |
| 971 | * @fwnode: Firmware node to get the property from. |
| 972 | * @propname: Name of the property. |
| 973 | * @proptype: Expected property type. |
| 974 | * @val: Location to store the property value (if not %NULL). |
| 975 | * @nval: Size of the array pointed to by @val. |
| 976 | * |
| 977 | * If @val is %NULL, return the number of array elements comprising the value |
| 978 | * of the property. Otherwise, read at most @nval values to the array at the |
| 979 | * location pointed to by @val. |
| 980 | */ |
Sakari Ailus | 99a8546 | 2017-07-21 14:39:34 +0300 | [diff] [blame] | 981 | int acpi_node_prop_read(const struct fwnode_handle *fwnode, |
| 982 | const char *propname, enum dev_prop_type proptype, |
| 983 | void *val, size_t nval) |
Rafael J. Wysocki | 3a7a2ab | 2015-08-27 04:40:05 +0200 | [diff] [blame] | 984 | { |
| 985 | return acpi_data_prop_read(acpi_device_data_of_node(fwnode), |
| 986 | propname, proptype, val, nval); |
| 987 | } |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 988 | |
| 989 | /** |
Mika Westerberg | 3405519 | 2017-03-28 10:52:18 +0300 | [diff] [blame] | 990 | * acpi_get_next_subnode - Return the next child node handle for a fwnode |
| 991 | * @fwnode: Firmware node to find the next child node for. |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 992 | * @child: Handle to one of the device's child nodes or a null handle. |
| 993 | */ |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 994 | struct fwnode_handle *acpi_get_next_subnode(const struct fwnode_handle *fwnode, |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 995 | struct fwnode_handle *child) |
| 996 | { |
Sakari Ailus | 01c1da2 | 2017-07-21 14:39:32 +0300 | [diff] [blame] | 997 | const struct acpi_device *adev = to_acpi_device_node(fwnode); |
Sakari Ailus | 01c1da2 | 2017-07-21 14:39:32 +0300 | [diff] [blame] | 998 | const struct list_head *head; |
| 999 | struct list_head *next; |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 1000 | |
Sakari Ailus | db3e50f | 2017-07-21 14:39:31 +0300 | [diff] [blame] | 1001 | if (!child || is_acpi_device_node(child)) { |
Sakari Ailus | 0c0bceb | 2017-09-08 12:24:41 +0300 | [diff] [blame] | 1002 | struct acpi_device *child_adev; |
| 1003 | |
Mika Westerberg | 3405519 | 2017-03-28 10:52:18 +0300 | [diff] [blame] | 1004 | if (adev) |
| 1005 | head = &adev->children; |
| 1006 | else |
| 1007 | goto nondev; |
| 1008 | |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 1009 | if (list_empty(head)) |
| 1010 | goto nondev; |
| 1011 | |
| 1012 | if (child) { |
Sakari Ailus | 0c0bceb | 2017-09-08 12:24:41 +0300 | [diff] [blame] | 1013 | adev = to_acpi_device_node(child); |
| 1014 | next = adev->node.next; |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 1015 | if (next == head) { |
| 1016 | child = NULL; |
| 1017 | goto nondev; |
| 1018 | } |
Sakari Ailus | 01c1da2 | 2017-07-21 14:39:32 +0300 | [diff] [blame] | 1019 | child_adev = list_entry(next, struct acpi_device, node); |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 1020 | } else { |
Sakari Ailus | 01c1da2 | 2017-07-21 14:39:32 +0300 | [diff] [blame] | 1021 | child_adev = list_first_entry(head, struct acpi_device, |
| 1022 | node); |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 1023 | } |
Sakari Ailus | 01c1da2 | 2017-07-21 14:39:32 +0300 | [diff] [blame] | 1024 | return acpi_fwnode_handle(child_adev); |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | nondev: |
Sakari Ailus | db3e50f | 2017-07-21 14:39:31 +0300 | [diff] [blame] | 1028 | if (!child || is_acpi_data_node(child)) { |
Sakari Ailus | 01c1da2 | 2017-07-21 14:39:32 +0300 | [diff] [blame] | 1029 | const struct acpi_data_node *data = to_acpi_data_node(fwnode); |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 1030 | struct acpi_data_node *dn; |
| 1031 | |
Pierre-Louis Bossart | 23583f7 | 2019-04-30 10:52:29 -0500 | [diff] [blame] | 1032 | /* |
| 1033 | * We can have a combination of device and data nodes, e.g. with |
| 1034 | * hierarchical _DSD properties. Make sure the adev pointer is |
| 1035 | * restored before going through data nodes, otherwise we will |
| 1036 | * be looking for data_nodes below the last device found instead |
| 1037 | * of the common fwnode shared by device_nodes and data_nodes. |
| 1038 | */ |
| 1039 | adev = to_acpi_device_node(fwnode); |
Sakari Ailus | 0c0bceb | 2017-09-08 12:24:41 +0300 | [diff] [blame] | 1040 | if (adev) |
| 1041 | head = &adev->data.subnodes; |
Mika Westerberg | 3405519 | 2017-03-28 10:52:18 +0300 | [diff] [blame] | 1042 | else if (data) |
| 1043 | head = &data->data.subnodes; |
| 1044 | else |
| 1045 | return NULL; |
| 1046 | |
Rafael J. Wysocki | 504a337 | 2015-08-27 04:42:33 +0200 | [diff] [blame] | 1047 | if (list_empty(head)) |
| 1048 | return NULL; |
| 1049 | |
| 1050 | if (child) { |
| 1051 | dn = to_acpi_data_node(child); |
| 1052 | next = dn->sibling.next; |
| 1053 | if (next == head) |
| 1054 | return NULL; |
| 1055 | |
| 1056 | dn = list_entry(next, struct acpi_data_node, sibling); |
| 1057 | } else { |
| 1058 | dn = list_first_entry(head, struct acpi_data_node, sibling); |
| 1059 | } |
| 1060 | return &dn->fwnode; |
| 1061 | } |
| 1062 | return NULL; |
| 1063 | } |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 1064 | |
| 1065 | /** |
| 1066 | * acpi_node_get_parent - Return parent fwnode of this fwnode |
| 1067 | * @fwnode: Firmware node whose parent to get |
| 1068 | * |
| 1069 | * Returns parent node of an ACPI device or data firmware node or %NULL if |
| 1070 | * not available. |
| 1071 | */ |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 1072 | struct fwnode_handle *acpi_node_get_parent(const struct fwnode_handle *fwnode) |
Mika Westerberg | dfa672f | 2017-03-28 10:52:16 +0300 | [diff] [blame] | 1073 | { |
| 1074 | if (is_acpi_data_node(fwnode)) { |
| 1075 | /* All data nodes have parent pointer so just return that */ |
| 1076 | return to_acpi_data_node(fwnode)->parent; |
| 1077 | } else if (is_acpi_device_node(fwnode)) { |
| 1078 | acpi_handle handle, parent_handle; |
| 1079 | |
| 1080 | handle = to_acpi_device_node(fwnode)->handle; |
| 1081 | if (ACPI_SUCCESS(acpi_get_parent(handle, &parent_handle))) { |
| 1082 | struct acpi_device *adev; |
| 1083 | |
| 1084 | if (!acpi_bus_get_device(parent_handle, &adev)) |
| 1085 | return acpi_fwnode_handle(adev); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | return NULL; |
| 1090 | } |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1091 | |
Sakari Ailus | 18f1e58d | 2018-07-17 17:19:16 +0300 | [diff] [blame] | 1092 | /* |
| 1093 | * Return true if the node is an ACPI graph node. Called on either ports |
| 1094 | * or endpoints. |
| 1095 | */ |
| 1096 | static bool is_acpi_graph_node(struct fwnode_handle *fwnode, |
| 1097 | const char *str) |
| 1098 | { |
| 1099 | unsigned int len = strlen(str); |
| 1100 | const char *name; |
| 1101 | |
| 1102 | if (!len || !is_acpi_data_node(fwnode)) |
| 1103 | return false; |
| 1104 | |
| 1105 | name = to_acpi_data_node(fwnode)->name; |
| 1106 | |
| 1107 | return (fwnode_property_present(fwnode, "reg") && |
| 1108 | !strncmp(name, str, len) && name[len] == '@') || |
| 1109 | fwnode_property_present(fwnode, str); |
| 1110 | } |
| 1111 | |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1112 | /** |
| 1113 | * acpi_graph_get_next_endpoint - Get next endpoint ACPI firmware node |
| 1114 | * @fwnode: Pointer to the parent firmware node |
| 1115 | * @prev: Previous endpoint node or %NULL to get the first |
| 1116 | * |
| 1117 | * Looks up next endpoint ACPI firmware node below a given @fwnode. Returns |
Sakari Ailus | 0ef7478 | 2018-07-17 17:19:14 +0300 | [diff] [blame] | 1118 | * %NULL if there is no next endpoint or in case of error. In case of success |
| 1119 | * the next endpoint is returned. |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1120 | */ |
Sakari Ailus | 0ef7478 | 2018-07-17 17:19:14 +0300 | [diff] [blame] | 1121 | static struct fwnode_handle *acpi_graph_get_next_endpoint( |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 1122 | const struct fwnode_handle *fwnode, struct fwnode_handle *prev) |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1123 | { |
| 1124 | struct fwnode_handle *port = NULL; |
| 1125 | struct fwnode_handle *endpoint; |
| 1126 | |
| 1127 | if (!prev) { |
| 1128 | do { |
| 1129 | port = fwnode_get_next_child_node(fwnode, port); |
Sakari Ailus | 18f1e58d | 2018-07-17 17:19:16 +0300 | [diff] [blame] | 1130 | /* |
| 1131 | * The names of the port nodes begin with "port@" |
| 1132 | * followed by the number of the port node and they also |
| 1133 | * have a "reg" property that also has the number of the |
| 1134 | * port node. For compatibility reasons a node is also |
| 1135 | * recognised as a port node from the "port" property. |
| 1136 | */ |
| 1137 | if (is_acpi_graph_node(port, "port")) |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1138 | break; |
| 1139 | } while (port); |
| 1140 | } else { |
| 1141 | port = fwnode_get_parent(prev); |
| 1142 | } |
| 1143 | |
| 1144 | if (!port) |
| 1145 | return NULL; |
| 1146 | |
| 1147 | endpoint = fwnode_get_next_child_node(port, prev); |
| 1148 | while (!endpoint) { |
| 1149 | port = fwnode_get_next_child_node(fwnode, port); |
| 1150 | if (!port) |
| 1151 | break; |
Sakari Ailus | 18f1e58d | 2018-07-17 17:19:16 +0300 | [diff] [blame] | 1152 | if (is_acpi_graph_node(port, "port")) |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1153 | endpoint = fwnode_get_next_child_node(port, NULL); |
| 1154 | } |
| 1155 | |
Sakari Ailus | 18f1e58d | 2018-07-17 17:19:16 +0300 | [diff] [blame] | 1156 | /* |
| 1157 | * The names of the endpoint nodes begin with "endpoint@" followed by |
| 1158 | * the number of the endpoint node and they also have a "reg" property |
| 1159 | * that also has the number of the endpoint node. For compatibility |
| 1160 | * reasons a node is also recognised as an endpoint node from the |
| 1161 | * "endpoint" property. |
| 1162 | */ |
| 1163 | if (!is_acpi_graph_node(endpoint, "endpoint")) |
Sakari Ailus | 0ef7478 | 2018-07-17 17:19:14 +0300 | [diff] [blame] | 1164 | return NULL; |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1165 | |
| 1166 | return endpoint; |
| 1167 | } |
| 1168 | |
| 1169 | /** |
| 1170 | * acpi_graph_get_child_prop_value - Return a child with a given property value |
| 1171 | * @fwnode: device fwnode |
| 1172 | * @prop_name: The name of the property to look for |
| 1173 | * @val: the desired property value |
| 1174 | * |
| 1175 | * Return the port node corresponding to a given port number. Returns |
| 1176 | * the child node on success, NULL otherwise. |
| 1177 | */ |
| 1178 | static struct fwnode_handle *acpi_graph_get_child_prop_value( |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 1179 | const struct fwnode_handle *fwnode, const char *prop_name, |
| 1180 | unsigned int val) |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1181 | { |
| 1182 | struct fwnode_handle *child; |
| 1183 | |
| 1184 | fwnode_for_each_child_node(fwnode, child) { |
| 1185 | u32 nr; |
| 1186 | |
Sakari Ailus | b5212f5 | 2017-08-22 23:39:58 +0300 | [diff] [blame] | 1187 | if (fwnode_property_read_u32(child, prop_name, &nr)) |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1188 | continue; |
| 1189 | |
| 1190 | if (val == nr) |
| 1191 | return child; |
| 1192 | } |
| 1193 | |
| 1194 | return NULL; |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | /** |
| 1199 | * acpi_graph_get_remote_enpoint - Parses and returns remote end of an endpoint |
| 1200 | * @fwnode: Endpoint firmware node pointing to a remote device |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1201 | * @endpoint: Firmware node of remote endpoint is filled here if not %NULL |
| 1202 | * |
Sakari Ailus | 0ef7478 | 2018-07-17 17:19:14 +0300 | [diff] [blame] | 1203 | * Returns the remote endpoint corresponding to @__fwnode. NULL on error. |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1204 | */ |
Sakari Ailus | 0ef7478 | 2018-07-17 17:19:14 +0300 | [diff] [blame] | 1205 | static struct fwnode_handle * |
| 1206 | acpi_graph_get_remote_endpoint(const struct fwnode_handle *__fwnode) |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1207 | { |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 1208 | struct fwnode_handle *fwnode; |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1209 | unsigned int port_nr, endpoint_nr; |
Sakari Ailus | 977d5ad | 2018-07-17 17:19:11 +0300 | [diff] [blame] | 1210 | struct fwnode_reference_args args; |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1211 | int ret; |
| 1212 | |
| 1213 | memset(&args, 0, sizeof(args)); |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 1214 | ret = acpi_node_get_property_reference(__fwnode, "remote-endpoint", 0, |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1215 | &args); |
| 1216 | if (ret) |
Sakari Ailus | 0ef7478 | 2018-07-17 17:19:14 +0300 | [diff] [blame] | 1217 | return NULL; |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1218 | |
Sakari Ailus | 6561eb3 | 2018-07-17 17:19:15 +0300 | [diff] [blame] | 1219 | /* Direct endpoint reference? */ |
Sakari Ailus | 977d5ad | 2018-07-17 17:19:11 +0300 | [diff] [blame] | 1220 | if (!is_acpi_device_node(args.fwnode)) |
Sakari Ailus | 6561eb3 | 2018-07-17 17:19:15 +0300 | [diff] [blame] | 1221 | return args.nargs ? NULL : args.fwnode; |
Sakari Ailus | 977d5ad | 2018-07-17 17:19:11 +0300 | [diff] [blame] | 1222 | |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1223 | /* |
| 1224 | * Always require two arguments with the reference: port and |
| 1225 | * endpoint indices. |
| 1226 | */ |
| 1227 | if (args.nargs != 2) |
Sakari Ailus | 0ef7478 | 2018-07-17 17:19:14 +0300 | [diff] [blame] | 1228 | return NULL; |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1229 | |
Sakari Ailus | 977d5ad | 2018-07-17 17:19:11 +0300 | [diff] [blame] | 1230 | fwnode = args.fwnode; |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1231 | port_nr = args.args[0]; |
| 1232 | endpoint_nr = args.args[1]; |
| 1233 | |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1234 | fwnode = acpi_graph_get_child_prop_value(fwnode, "port", port_nr); |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1235 | |
Sakari Ailus | 18f1e58d | 2018-07-17 17:19:16 +0300 | [diff] [blame] | 1236 | return acpi_graph_get_child_prop_value(fwnode, "endpoint", endpoint_nr); |
Mika Westerberg | 79389a8 | 2017-03-28 10:52:20 +0300 | [diff] [blame] | 1237 | } |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 1238 | |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 1239 | static bool acpi_fwnode_device_is_available(const struct fwnode_handle *fwnode) |
Sakari Ailus | 2294b3a | 2017-06-06 12:37:39 +0300 | [diff] [blame] | 1240 | { |
| 1241 | if (!is_acpi_device_node(fwnode)) |
| 1242 | return false; |
| 1243 | |
| 1244 | return acpi_device_is_present(to_acpi_device_node(fwnode)); |
| 1245 | } |
| 1246 | |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 1247 | static bool acpi_fwnode_property_present(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 1248 | const char *propname) |
| 1249 | { |
| 1250 | return !acpi_node_prop_get(fwnode, propname, NULL); |
| 1251 | } |
| 1252 | |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 1253 | static int |
| 1254 | acpi_fwnode_property_read_int_array(const struct fwnode_handle *fwnode, |
| 1255 | const char *propname, |
| 1256 | unsigned int elem_size, void *val, |
| 1257 | size_t nval) |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 1258 | { |
| 1259 | enum dev_prop_type type; |
| 1260 | |
| 1261 | switch (elem_size) { |
| 1262 | case sizeof(u8): |
| 1263 | type = DEV_PROP_U8; |
| 1264 | break; |
| 1265 | case sizeof(u16): |
| 1266 | type = DEV_PROP_U16; |
| 1267 | break; |
| 1268 | case sizeof(u32): |
| 1269 | type = DEV_PROP_U32; |
| 1270 | break; |
| 1271 | case sizeof(u64): |
| 1272 | type = DEV_PROP_U64; |
| 1273 | break; |
| 1274 | default: |
| 1275 | return -ENXIO; |
| 1276 | } |
| 1277 | |
| 1278 | return acpi_node_prop_read(fwnode, propname, type, val, nval); |
| 1279 | } |
| 1280 | |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 1281 | static int |
| 1282 | acpi_fwnode_property_read_string_array(const struct fwnode_handle *fwnode, |
| 1283 | const char *propname, const char **val, |
| 1284 | size_t nval) |
Sakari Ailus | 3708184 | 2017-06-06 12:37:37 +0300 | [diff] [blame] | 1285 | { |
| 1286 | return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING, |
| 1287 | val, nval); |
| 1288 | } |
| 1289 | |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 1290 | static int |
| 1291 | acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode, |
| 1292 | const char *prop, const char *nargs_prop, |
| 1293 | unsigned int args_count, unsigned int index, |
| 1294 | struct fwnode_reference_args *args) |
| 1295 | { |
Sakari Ailus | 977d5ad | 2018-07-17 17:19:11 +0300 | [diff] [blame] | 1296 | return __acpi_node_get_property_reference(fwnode, prop, index, |
| 1297 | args_count, args); |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 1298 | } |
| 1299 | |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 1300 | static struct fwnode_handle * |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 1301 | acpi_fwnode_get_parent(struct fwnode_handle *fwnode) |
| 1302 | { |
| 1303 | return acpi_node_get_parent(fwnode); |
| 1304 | } |
| 1305 | |
| 1306 | static int acpi_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 1307 | struct fwnode_endpoint *endpoint) |
| 1308 | { |
| 1309 | struct fwnode_handle *port_fwnode = fwnode_get_parent(fwnode); |
| 1310 | |
| 1311 | endpoint->local_fwnode = fwnode; |
| 1312 | |
Sakari Ailus | 18f1e58d | 2018-07-17 17:19:16 +0300 | [diff] [blame] | 1313 | if (fwnode_property_read_u32(port_fwnode, "reg", &endpoint->port)) |
| 1314 | fwnode_property_read_u32(port_fwnode, "port", &endpoint->port); |
| 1315 | if (fwnode_property_read_u32(fwnode, "reg", &endpoint->id)) |
| 1316 | fwnode_property_read_u32(fwnode, "endpoint", &endpoint->id); |
Sakari Ailus | 3b27d00 | 2017-06-06 12:37:38 +0300 | [diff] [blame] | 1317 | |
| 1318 | return 0; |
| 1319 | } |
| 1320 | |
Andy Shevchenko | 67dcc26 | 2018-02-09 17:38:36 +0200 | [diff] [blame] | 1321 | static const void * |
Sinan Kaya | 146b4db | 2017-12-13 02:20:51 -0500 | [diff] [blame] | 1322 | acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode, |
| 1323 | const struct device *dev) |
| 1324 | { |
Andy Shevchenko | 29d5325 | 2018-02-09 17:38:35 +0200 | [diff] [blame] | 1325 | return acpi_device_get_match_data(dev); |
Sinan Kaya | 146b4db | 2017-12-13 02:20:51 -0500 | [diff] [blame] | 1326 | } |
| 1327 | |
Sakari Ailus | db3e50f | 2017-07-21 14:39:31 +0300 | [diff] [blame] | 1328 | #define DECLARE_ACPI_FWNODE_OPS(ops) \ |
| 1329 | const struct fwnode_operations ops = { \ |
| 1330 | .device_is_available = acpi_fwnode_device_is_available, \ |
Sinan Kaya | 146b4db | 2017-12-13 02:20:51 -0500 | [diff] [blame] | 1331 | .device_get_match_data = acpi_fwnode_device_get_match_data, \ |
Sakari Ailus | db3e50f | 2017-07-21 14:39:31 +0300 | [diff] [blame] | 1332 | .property_present = acpi_fwnode_property_present, \ |
| 1333 | .property_read_int_array = \ |
| 1334 | acpi_fwnode_property_read_int_array, \ |
| 1335 | .property_read_string_array = \ |
| 1336 | acpi_fwnode_property_read_string_array, \ |
| 1337 | .get_parent = acpi_node_get_parent, \ |
| 1338 | .get_next_child_node = acpi_get_next_subnode, \ |
| 1339 | .get_named_child_node = acpi_fwnode_get_named_child_node, \ |
Sakari Ailus | 3e3119d | 2017-07-21 15:11:49 +0300 | [diff] [blame] | 1340 | .get_reference_args = acpi_fwnode_get_reference_args, \ |
Sakari Ailus | db3e50f | 2017-07-21 14:39:31 +0300 | [diff] [blame] | 1341 | .graph_get_next_endpoint = \ |
Sakari Ailus | 0ef7478 | 2018-07-17 17:19:14 +0300 | [diff] [blame] | 1342 | acpi_graph_get_next_endpoint, \ |
Sakari Ailus | db3e50f | 2017-07-21 14:39:31 +0300 | [diff] [blame] | 1343 | .graph_get_remote_endpoint = \ |
Sakari Ailus | 0ef7478 | 2018-07-17 17:19:14 +0300 | [diff] [blame] | 1344 | acpi_graph_get_remote_endpoint, \ |
Sakari Ailus | 37ba983 | 2017-07-21 14:39:36 +0300 | [diff] [blame] | 1345 | .graph_get_port_parent = acpi_fwnode_get_parent, \ |
Sakari Ailus | db3e50f | 2017-07-21 14:39:31 +0300 | [diff] [blame] | 1346 | .graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint, \ |
| 1347 | }; \ |
| 1348 | EXPORT_SYMBOL_GPL(ops) |
| 1349 | |
| 1350 | DECLARE_ACPI_FWNODE_OPS(acpi_device_fwnode_ops); |
| 1351 | DECLARE_ACPI_FWNODE_OPS(acpi_data_fwnode_ops); |
| 1352 | const struct fwnode_operations acpi_static_fwnode_ops; |
John Hubbard | 9e987b7 | 2017-09-15 17:35:27 -0700 | [diff] [blame] | 1353 | |
| 1354 | bool is_acpi_device_node(const struct fwnode_handle *fwnode) |
| 1355 | { |
| 1356 | return !IS_ERR_OR_NULL(fwnode) && |
| 1357 | fwnode->ops == &acpi_device_fwnode_ops; |
| 1358 | } |
| 1359 | EXPORT_SYMBOL(is_acpi_device_node); |
| 1360 | |
| 1361 | bool is_acpi_data_node(const struct fwnode_handle *fwnode) |
| 1362 | { |
| 1363 | return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &acpi_data_fwnode_ops; |
| 1364 | } |
| 1365 | EXPORT_SYMBOL(is_acpi_data_node); |