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