diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-05 12:50:00 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-05 12:50:00 -0700 |
commit | e7d0c41ecc2e372a81741a30894f556afec24315 (patch) | |
tree | 744c7fa370ef15677303818640a3db5c9083f89f /drivers/acpi | |
parent | 53ac64aac9af8cd0e5456c8a9bb68c47b571b0a9 (diff) | |
parent | 3689d3d6907271b5737de5bff584cb50cb29ebc2 (diff) |
Merge tag 'devprop-4.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull device properties framework updates from Rafael Wysocki:
"These introduce fwnode operations for all of the separate types of
'firmware nodes' that can be handled by the device properties
framework, make the framework use const fwnode arguments all over, add
a helper for the consolidated handling of node references and switch
over the framework to the new UUID API.
Specifics:
- Introduce fwnode operations for all of the separate types of
'firmware nodes' that can be handled by the device properties
framework and drop the type field from struct fwnode_handle (Sakari
Ailus, Arnd Bergmann).
- Make the device properties framework use const fwnode arguments
where possible (Sakari Ailus).
- Add a helper for the consolidated handling of node references to
the device properties framework (Sakari Ailus).
- Switch over the ACPI part of the device properties framework to the
new UUID API (Andy Shevchenko)"
* tag 'devprop-4.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm:
ACPI: device property: Switch to use new generic UUID API
device property: export irqchip_fwnode_ops
device property: Introduce fwnode_property_get_reference_args
device property: Constify fwnode property API
device property: Constify argument to pset fwnode backend
ACPI: Constify internal fwnode arguments
ACPI: Constify acpi_bus helper functions, switch to macros
ACPI: Prepare for constifying acpi_get_next_subnode() fwnode argument
device property: Get rid of struct fwnode_handle type field
ACPI: Use IS_ERR_OR_NULL() instead of non-NULL check in is_acpi_data_node()
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/property.c | 231 | ||||
-rw-r--r-- | drivers/acpi/scan.c | 3 |
2 files changed, 142 insertions, 92 deletions
diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c index 09b7974b6c62..c1c216163de3 100644 --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -19,21 +19,19 @@ #include "internal.h" -static int acpi_data_get_property_array(struct acpi_device_data *data, +static int acpi_data_get_property_array(const struct acpi_device_data *data, const char *name, acpi_object_type type, const union acpi_object **obj); -/* ACPI _DSD device properties UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301 */ -static const u8 prp_uuid[16] = { - 0x14, 0xd8, 0xff, 0xda, 0xba, 0x6e, 0x8c, 0x4d, - 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01 -}; -/* ACPI _DSD data subnodes UUID: dbb8e3e6-5886-4ba6-8795-1319f52a966b */ -static const u8 ads_uuid[16] = { - 0xe6, 0xe3, 0xb8, 0xdb, 0x86, 0x58, 0xa6, 0x4b, - 0x87, 0x95, 0x13, 0x19, 0xf5, 0x2a, 0x96, 0x6b -}; +/* ACPI _DSD device properties GUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301 */ +static const guid_t prp_guid = + GUID_INIT(0xdaffd814, 0x6eba, 0x4d8c, + 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01); +/* ACPI _DSD data subnodes GUID: dbb8e3e6-5886-4ba6-8795-1319f52a966b */ +static const guid_t ads_guid = + GUID_INIT(0xdbb8e3e6, 0x5886, 0x4ba6, + 0x87, 0x95, 0x13, 0x19, 0xf5, 0x2a, 0x96, 0x6b); static bool acpi_enumerate_nondev_subnodes(acpi_handle scope, const union acpi_object *desc, @@ -56,8 +54,7 @@ static bool acpi_nondev_subnode_extract(const union acpi_object *desc, return false; dn->name = link->package.elements[0].string.pointer; - dn->fwnode.type = FWNODE_ACPI_DATA; - dn->fwnode.ops = &acpi_fwnode_ops; + dn->fwnode.ops = &acpi_data_fwnode_ops; dn->parent = parent; INIT_LIST_HEAD(&dn->data.subnodes); @@ -190,22 +187,23 @@ static bool acpi_enumerate_nondev_subnodes(acpi_handle scope, { int i; - /* Look for the ACPI data subnodes UUID. */ + /* Look for the ACPI data subnodes GUID. */ for (i = 0; i < desc->package.count; i += 2) { - const union acpi_object *uuid, *links; + const union acpi_object *guid, *links; - uuid = &desc->package.elements[i]; + guid = &desc->package.elements[i]; links = &desc->package.elements[i + 1]; /* - * The first element must be a UUID and the second one must be + * The first element must be a GUID and the second one must be * a package. */ - if (uuid->type != ACPI_TYPE_BUFFER || uuid->buffer.length != 16 - || links->type != ACPI_TYPE_PACKAGE) + if (guid->type != ACPI_TYPE_BUFFER || + guid->buffer.length != 16 || + links->type != ACPI_TYPE_PACKAGE) break; - if (memcmp(uuid->buffer.pointer, ads_uuid, sizeof(ads_uuid))) + if (!guid_equal((guid_t *)guid->buffer.pointer, &ads_guid)) continue; return acpi_add_nondev_subnodes(scope, links, &data->subnodes, @@ -298,26 +296,27 @@ static bool acpi_extract_properties(const union acpi_object *desc, if (desc->package.count % 2) return false; - /* Look for the device properties UUID. */ + /* Look for the device properties GUID. */ for (i = 0; i < desc->package.count; i += 2) { - const union acpi_object *uuid, *properties; + const union acpi_object *guid, *properties; - uuid = &desc->package.elements[i]; + guid = &desc->package.elements[i]; properties = &desc->package.elements[i + 1]; /* - * The first element must be a UUID and the second one must be + * The first element must be a GUID and the second one must be * a package. */ - if (uuid->type != ACPI_TYPE_BUFFER || uuid->buffer.length != 16 - || properties->type != ACPI_TYPE_PACKAGE) + if (guid->type != ACPI_TYPE_BUFFER || + guid->buffer.length != 16 || + properties->type != ACPI_TYPE_PACKAGE) break; - if (memcmp(uuid->buffer.pointer, prp_uuid, sizeof(prp_uuid))) + if (!guid_equal((guid_t *)guid->buffer.pointer, &prp_guid)) continue; /* - * We found the matching UUID. Now validate the format of the + * We found the matching GUID. Now validate the format of the * package immediately following it. */ if (!acpi_properties_format_valid(properties)) @@ -424,7 +423,7 @@ void acpi_free_properties(struct acpi_device *adev) * %-EINVAL if the property doesn't exist, * %-EPROTO if the property value type doesn't match @type. */ -static int acpi_data_get_property(struct acpi_device_data *data, +static int acpi_data_get_property(const struct acpi_device_data *data, const char *name, acpi_object_type type, const union acpi_object **obj) { @@ -466,20 +465,21 @@ static int acpi_data_get_property(struct acpi_device_data *data, * @type: Expected property type. * @obj: Location to store the property value (if not %NULL). */ -int acpi_dev_get_property(struct acpi_device *adev, const char *name, +int acpi_dev_get_property(const struct acpi_device *adev, const char *name, acpi_object_type type, const union acpi_object **obj) { return adev ? acpi_data_get_property(&adev->data, name, type, obj) : -EINVAL; } EXPORT_SYMBOL_GPL(acpi_dev_get_property); -static struct acpi_device_data *acpi_device_data_of_node(struct fwnode_handle *fwnode) +static const struct acpi_device_data * +acpi_device_data_of_node(const struct fwnode_handle *fwnode) { - if (fwnode->type == FWNODE_ACPI) { - struct acpi_device *adev = to_acpi_device_node(fwnode); + if (is_acpi_device_node(fwnode)) { + const struct acpi_device *adev = to_acpi_device_node(fwnode); return &adev->data; - } else if (fwnode->type == FWNODE_ACPI_DATA) { - struct acpi_data_node *dn = to_acpi_data_node(fwnode); + } else if (is_acpi_data_node(fwnode)) { + const struct acpi_data_node *dn = to_acpi_data_node(fwnode); return &dn->data; } return NULL; @@ -491,8 +491,8 @@ static struct acpi_device_data *acpi_device_data_of_node(struct fwnode_handle *f * @propname: Name of the property. * @valptr: Location to store a pointer to the property value (if not %NULL). */ -int acpi_node_prop_get(struct fwnode_handle *fwnode, const char *propname, - void **valptr) +int acpi_node_prop_get(const struct fwnode_handle *fwnode, + const char *propname, void **valptr) { return acpi_data_get_property(acpi_device_data_of_node(fwnode), propname, ACPI_TYPE_ANY, @@ -518,7 +518,7 @@ int acpi_node_prop_get(struct fwnode_handle *fwnode, const char *propname, * %-EPROTO if the property is not a package or the type of its elements * doesn't match @type. */ -static int acpi_data_get_property_array(struct acpi_device_data *data, +static int acpi_data_get_property_array(const struct acpi_device_data *data, const char *name, acpi_object_type type, const union acpi_object **obj) @@ -578,13 +578,13 @@ static int acpi_data_get_property_array(struct acpi_device_data *data, * * Return: %0 on success, negative error code on failure. */ -int __acpi_node_get_property_reference(struct fwnode_handle *fwnode, +int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, const char *propname, size_t index, size_t num_args, struct acpi_reference_args *args) { const union acpi_object *element, *end; const union acpi_object *obj; - struct acpi_device_data *data; + const struct acpi_device_data *data; struct acpi_device *device; int ret, idx = 0; @@ -680,7 +680,7 @@ int __acpi_node_get_property_reference(struct fwnode_handle *fwnode, } EXPORT_SYMBOL_GPL(__acpi_node_get_property_reference); -static int acpi_data_prop_read_single(struct acpi_device_data *data, +static int acpi_data_prop_read_single(const struct acpi_device_data *data, const char *propname, enum dev_prop_type proptype, void *val) { @@ -819,7 +819,7 @@ static int acpi_copy_property_array_string(const union acpi_object *items, return nval; } -static int acpi_data_prop_read(struct acpi_device_data *data, +static int acpi_data_prop_read(const struct acpi_device_data *data, const char *propname, enum dev_prop_type proptype, void *val, size_t nval) @@ -873,7 +873,7 @@ static int acpi_data_prop_read(struct acpi_device_data *data, return ret; } -int acpi_dev_prop_read(struct acpi_device *adev, const char *propname, +int acpi_dev_prop_read(const struct acpi_device *adev, const char *propname, enum dev_prop_type proptype, void *val, size_t nval) { return adev ? acpi_data_prop_read(&adev->data, propname, proptype, val, nval) : -EINVAL; @@ -891,8 +891,9 @@ int acpi_dev_prop_read(struct acpi_device *adev, const char *propname, * of the property. Otherwise, read at most @nval values to the array at the * location pointed to by @val. */ -int acpi_node_prop_read(struct fwnode_handle *fwnode, const char *propname, - enum dev_prop_type proptype, void *val, size_t nval) +int acpi_node_prop_read(const struct fwnode_handle *fwnode, + const char *propname, enum dev_prop_type proptype, + void *val, size_t nval) { return acpi_data_prop_read(acpi_device_data_of_node(fwnode), propname, proptype, val, nval); @@ -903,13 +904,15 @@ int acpi_node_prop_read(struct fwnode_handle *fwnode, const char *propname, * @fwnode: Firmware node to find the next child node for. * @child: Handle to one of the device's child nodes or a null handle. */ -struct fwnode_handle *acpi_get_next_subnode(struct fwnode_handle *fwnode, +struct fwnode_handle *acpi_get_next_subnode(const struct fwnode_handle *fwnode, struct fwnode_handle *child) { - struct acpi_device *adev = to_acpi_device_node(fwnode); - struct list_head *head, *next; + const struct acpi_device *adev = to_acpi_device_node(fwnode); + struct acpi_device *child_adev = NULL; + const struct list_head *head; + struct list_head *next; - if (!child || child->type == FWNODE_ACPI) { + if (!child || is_acpi_device_node(child)) { if (adev) head = &adev->children; else @@ -919,26 +922,27 @@ struct fwnode_handle *acpi_get_next_subnode(struct fwnode_handle *fwnode, goto nondev; if (child) { - adev = to_acpi_device_node(child); - next = adev->node.next; + child_adev = to_acpi_device_node(child); + next = child_adev->node.next; if (next == head) { child = NULL; goto nondev; } - adev = list_entry(next, struct acpi_device, node); + child_adev = list_entry(next, struct acpi_device, node); } else { - adev = list_first_entry(head, struct acpi_device, node); + child_adev = list_first_entry(head, struct acpi_device, + node); } - return acpi_fwnode_handle(adev); + return acpi_fwnode_handle(child_adev); } nondev: - if (!child || child->type == FWNODE_ACPI_DATA) { - struct acpi_data_node *data = to_acpi_data_node(fwnode); + if (!child || is_acpi_data_node(child)) { + const struct acpi_data_node *data = to_acpi_data_node(fwnode); struct acpi_data_node *dn; - if (adev) - head = &adev->data.subnodes; + if (child_adev) + head = &child_adev->data.subnodes; else if (data) head = &data->data.subnodes; else @@ -969,7 +973,7 @@ struct fwnode_handle *acpi_get_next_subnode(struct fwnode_handle *fwnode, * Returns parent node of an ACPI device or data firmware node or %NULL if * not available. */ -struct fwnode_handle *acpi_node_get_parent(struct fwnode_handle *fwnode) +struct fwnode_handle *acpi_node_get_parent(const struct fwnode_handle *fwnode) { if (is_acpi_data_node(fwnode)) { /* All data nodes have parent pointer so just return that */ @@ -998,8 +1002,8 @@ struct fwnode_handle *acpi_node_get_parent(struct fwnode_handle *fwnode) * %NULL if there is no next endpoint, ERR_PTR() in case of error. In case * of success the next endpoint is returned. */ -struct fwnode_handle *acpi_graph_get_next_endpoint(struct fwnode_handle *fwnode, - struct fwnode_handle *prev) +struct fwnode_handle *acpi_graph_get_next_endpoint( + const struct fwnode_handle *fwnode, struct fwnode_handle *prev) { struct fwnode_handle *port = NULL; struct fwnode_handle *endpoint; @@ -1046,7 +1050,8 @@ struct fwnode_handle *acpi_graph_get_next_endpoint(struct fwnode_handle *fwnode, * the child node on success, NULL otherwise. */ static struct fwnode_handle *acpi_graph_get_child_prop_value( - struct fwnode_handle *fwnode, const char *prop_name, unsigned int val) + const struct fwnode_handle *fwnode, const char *prop_name, + unsigned int val) { struct fwnode_handle *child; @@ -1075,17 +1080,18 @@ static struct fwnode_handle *acpi_graph_get_child_prop_value( * fields requested by the caller. Returns %0 in case of success and * negative errno otherwise. */ -int acpi_graph_get_remote_endpoint(struct fwnode_handle *fwnode, +int acpi_graph_get_remote_endpoint(const struct fwnode_handle *__fwnode, struct fwnode_handle **parent, struct fwnode_handle **port, struct fwnode_handle **endpoint) { + struct fwnode_handle *fwnode; unsigned int port_nr, endpoint_nr; struct acpi_reference_args args; int ret; memset(&args, 0, sizeof(args)); - ret = acpi_node_get_property_reference(fwnode, "remote-endpoint", 0, + ret = acpi_node_get_property_reference(__fwnode, "remote-endpoint", 0, &args); if (ret) return ret; @@ -1127,7 +1133,7 @@ int acpi_graph_get_remote_endpoint(struct fwnode_handle *fwnode, return 0; } -static bool acpi_fwnode_device_is_available(struct fwnode_handle *fwnode) +static bool acpi_fwnode_device_is_available(const struct fwnode_handle *fwnode) { if (!is_acpi_device_node(fwnode)) return false; @@ -1135,16 +1141,17 @@ static bool acpi_fwnode_device_is_available(struct fwnode_handle *fwnode) return acpi_device_is_present(to_acpi_device_node(fwnode)); } -static bool acpi_fwnode_property_present(struct fwnode_handle *fwnode, +static bool acpi_fwnode_property_present(const struct fwnode_handle *fwnode, const char *propname) { return !acpi_node_prop_get(fwnode, propname, NULL); } -static int acpi_fwnode_property_read_int_array(struct fwnode_handle *fwnode, - const char *propname, - unsigned int elem_size, - void *val, size_t nval) +static int +acpi_fwnode_property_read_int_array(const struct fwnode_handle *fwnode, + const char *propname, + unsigned int elem_size, void *val, + size_t nval) { enum dev_prop_type type; @@ -1168,16 +1175,17 @@ static int acpi_fwnode_property_read_int_array(struct fwnode_handle *fwnode, return acpi_node_prop_read(fwnode, propname, type, val, nval); } -static int acpi_fwnode_property_read_string_array(struct fwnode_handle *fwnode, - const char *propname, - const char **val, size_t nval) +static int +acpi_fwnode_property_read_string_array(const struct fwnode_handle *fwnode, + const char *propname, const char **val, + size_t nval) { return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING, val, nval); } static struct fwnode_handle * -acpi_fwnode_get_named_child_node(struct fwnode_handle *fwnode, +acpi_fwnode_get_named_child_node(const struct fwnode_handle *fwnode, const char *childname) { struct fwnode_handle *child; @@ -1193,8 +1201,34 @@ acpi_fwnode_get_named_child_node(struct fwnode_handle *fwnode, return NULL; } +static int +acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode, + const char *prop, const char *nargs_prop, + unsigned int args_count, unsigned int index, + struct fwnode_reference_args *args) +{ + struct acpi_reference_args acpi_args; + unsigned int i; + int ret; + + ret = __acpi_node_get_property_reference(fwnode, prop, index, + args_count, &acpi_args); + if (ret < 0) + return ret; + if (!args) + return 0; + + args->nargs = acpi_args.nargs; + args->fwnode = acpi_fwnode_handle(acpi_args.adev); + + for (i = 0; i < NR_FWNODE_REFERENCE_ARGS; i++) + args->args[i] = i < acpi_args.nargs ? acpi_args.args[i] : 0; + + return 0; +} + static struct fwnode_handle * -acpi_fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode, +acpi_fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode, struct fwnode_handle *prev) { struct fwnode_handle *endpoint; @@ -1207,7 +1241,7 @@ acpi_fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode, } static struct fwnode_handle * -acpi_fwnode_graph_get_remote_endpoint(struct fwnode_handle *fwnode) +acpi_fwnode_graph_get_remote_endpoint(const struct fwnode_handle *fwnode) { struct fwnode_handle *endpoint = NULL; @@ -1216,7 +1250,13 @@ acpi_fwnode_graph_get_remote_endpoint(struct fwnode_handle *fwnode) return endpoint; } -static int acpi_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode, +static struct fwnode_handle * +acpi_fwnode_get_parent(struct fwnode_handle *fwnode) +{ + return acpi_node_get_parent(fwnode); +} + +static int acpi_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, struct fwnode_endpoint *endpoint) { struct fwnode_handle *port_fwnode = fwnode_get_parent(fwnode); @@ -1229,16 +1269,27 @@ static int acpi_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode, return 0; } -const struct fwnode_operations acpi_fwnode_ops = { - .device_is_available = acpi_fwnode_device_is_available, - .property_present = acpi_fwnode_property_present, - .property_read_int_array = acpi_fwnode_property_read_int_array, - .property_read_string_array = acpi_fwnode_property_read_string_array, - .get_parent = acpi_node_get_parent, - .get_next_child_node = acpi_get_next_subnode, - .get_named_child_node = acpi_fwnode_get_named_child_node, - .graph_get_next_endpoint = acpi_fwnode_graph_get_next_endpoint, - .graph_get_remote_endpoint = acpi_fwnode_graph_get_remote_endpoint, - .graph_get_port_parent = acpi_node_get_parent, - .graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint, -}; +#define DECLARE_ACPI_FWNODE_OPS(ops) \ + const struct fwnode_operations ops = { \ + .device_is_available = acpi_fwnode_device_is_available, \ + .property_present = acpi_fwnode_property_present, \ + .property_read_int_array = \ + acpi_fwnode_property_read_int_array, \ + .property_read_string_array = \ + acpi_fwnode_property_read_string_array, \ + .get_parent = acpi_node_get_parent, \ + .get_next_child_node = acpi_get_next_subnode, \ + .get_named_child_node = acpi_fwnode_get_named_child_node, \ + .get_reference_args = acpi_fwnode_get_reference_args, \ + .graph_get_next_endpoint = \ + acpi_fwnode_graph_get_next_endpoint, \ + .graph_get_remote_endpoint = \ + acpi_fwnode_graph_get_remote_endpoint, \ + .graph_get_port_parent = acpi_fwnode_get_parent, \ + .graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint, \ + }; \ + EXPORT_SYMBOL_GPL(ops) + +DECLARE_ACPI_FWNODE_OPS(acpi_device_fwnode_ops); +DECLARE_ACPI_FWNODE_OPS(acpi_data_fwnode_ops); +const struct fwnode_operations acpi_static_fwnode_ops; diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index ac8a8a52ee4a..602f8ff212f2 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1549,8 +1549,7 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, device->device_type = type; device->handle = handle; device->parent = acpi_bus_get_parent(handle); - device->fwnode.type = FWNODE_ACPI; - device->fwnode.ops = &acpi_fwnode_ops; + device->fwnode.ops = &acpi_device_fwnode_ops; acpi_set_device_status(device, sta); acpi_device_get_busid(device); acpi_set_pnp_ids(handle, &device->pnp, type); |