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