Commit b60e4ea4 authored by Mika Westerberg's avatar Mika Westerberg Committed by Rafael J. Wysocki

ACPI / property: Allow holes in reference properties

DT allows holes or empty phandles for references. This is used for example
in SPI subsystem where some chip selects are native and others are regular
GPIOs. In ACPI _DSD we currently do not support this but instead the
preceding reference consumes all following integer arguments.

For example we would like to support something like the below ASL fragment
for SPI:

  Package () {
      "cs-gpios",
      Package () {
          ^GPIO, 19, 0, 0, // GPIO CS0
          0,               // Native CS
          ^GPIO, 20, 0, 0, // GPIO CS1
      }
  }

The zero in the middle means "no entry" or NULL reference. To support this
we change acpi_data_get_property_reference() to take firmware node and
num_args as argument and rename it to __acpi_node_get_property_reference().
The function returns -ENOENT if the given index resolves to "no entry"
reference and -ENODATA when there are no more entries in the property.

We then add static inline wrapper acpi_node_get_property_reference() that
passes MAX_ACPI_REFERENCE_ARGS as num_args to support the existing
behaviour which some drivers have been relying on.
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 20a875e2
...@@ -468,10 +468,11 @@ static int acpi_data_get_property_array(struct acpi_device_data *data, ...@@ -468,10 +468,11 @@ static int acpi_data_get_property_array(struct acpi_device_data *data,
} }
/** /**
* acpi_data_get_property_reference - returns handle to the referenced object * __acpi_node_get_property_reference - returns handle to the referenced object
* @data: ACPI device data object containing the property * @fwnode: Firmware node to get the property from
* @propname: Name of the property * @propname: Name of the property
* @index: Index of the reference to return * @index: Index of the reference to return
* @num_args: Maximum number of arguments after each reference
* @args: Location to store the returned reference with optional arguments * @args: Location to store the returned reference with optional arguments
* *
* Find property with @name, verifify that it is a package containing at least * Find property with @name, verifify that it is a package containing at least
...@@ -482,17 +483,40 @@ static int acpi_data_get_property_array(struct acpi_device_data *data, ...@@ -482,17 +483,40 @@ static int acpi_data_get_property_array(struct acpi_device_data *data,
* If there's more than one reference in the property value package, @index is * If there's more than one reference in the property value package, @index is
* used to select the one to return. * used to select the one to return.
* *
* It is possible to leave holes in the property value set like in the
* example below:
*
* Package () {
* "cs-gpios",
* Package () {
* ^GPIO, 19, 0, 0,
* ^GPIO, 20, 0, 0,
* 0,
* ^GPIO, 21, 0, 0,
* }
* }
*
* Calling this function with index %2 return %-ENOENT and with index %3
* returns the last entry. If the property does not contain any more values
* %-ENODATA is returned. The NULL entry must be single integer and
* preferably contain value %0.
*
* Return: %0 on success, negative error code on failure. * Return: %0 on success, negative error code on failure.
*/ */
static int acpi_data_get_property_reference(struct acpi_device_data *data, int __acpi_node_get_property_reference(struct fwnode_handle *fwnode,
const char *propname, size_t index, const char *propname, size_t index, size_t num_args,
struct acpi_reference_args *args) struct acpi_reference_args *args)
{ {
const union acpi_object *element, *end; const union acpi_object *element, *end;
const union acpi_object *obj; const union acpi_object *obj;
struct acpi_device_data *data;
struct acpi_device *device; struct acpi_device *device;
int ret, idx = 0; int ret, idx = 0;
data = acpi_device_data_of_node(fwnode);
if (!data)
return -EINVAL;
ret = acpi_data_get_property(data, propname, ACPI_TYPE_ANY, &obj); ret = acpi_data_get_property(data, propname, ACPI_TYPE_ANY, &obj);
if (ret) if (ret)
return ret; return ret;
...@@ -532,18 +556,17 @@ static int acpi_data_get_property_reference(struct acpi_device_data *data, ...@@ -532,18 +556,17 @@ static int acpi_data_get_property_reference(struct acpi_device_data *data,
while (element < end) { while (element < end) {
u32 nargs, i; u32 nargs, i;
if (element->type != ACPI_TYPE_LOCAL_REFERENCE) if (element->type == ACPI_TYPE_LOCAL_REFERENCE) {
return -EPROTO; ret = acpi_bus_get_device(element->reference.handle,
&device);
ret = acpi_bus_get_device(element->reference.handle, &device);
if (ret) if (ret)
return -ENODEV; return -ENODEV;
element++;
nargs = 0; nargs = 0;
element++;
/* assume following integer elements are all args */ /* assume following integer elements are all args */
for (i = 0; element + i < end; i++) { for (i = 0; element + i < end && i < num_args; i++) {
int type = element[i].type; int type = element[i].type;
if (type == ACPI_TYPE_INTEGER) if (type == ACPI_TYPE_INTEGER)
...@@ -554,7 +577,10 @@ static int acpi_data_get_property_reference(struct acpi_device_data *data, ...@@ -554,7 +577,10 @@ static int acpi_data_get_property_reference(struct acpi_device_data *data,
return -EPROTO; return -EPROTO;
} }
if (idx++ == index) { if (nargs > MAX_ACPI_REFERENCE_ARGS)
return -EPROTO;
if (idx == index) {
args->adev = device; args->adev = device;
args->nargs = nargs; args->nargs = nargs;
for (i = 0; i < nargs; i++) for (i = 0; i < nargs; i++)
...@@ -564,27 +590,20 @@ static int acpi_data_get_property_reference(struct acpi_device_data *data, ...@@ -564,27 +590,20 @@ static int acpi_data_get_property_reference(struct acpi_device_data *data,
} }
element += nargs; element += nargs;
} } else if (element->type == ACPI_TYPE_INTEGER) {
if (idx == index)
return -ENOENT;
element++;
} else {
return -EPROTO; return -EPROTO;
} }
/** idx++;
* acpi_node_get_property_reference - get a handle to the referenced object. }
* @fwnode: Firmware node to get the property from.
* @propname: Name of the property.
* @index: Index of the reference to return.
* @args: Location to store the returned reference with optional arguments.
*/
int acpi_node_get_property_reference(struct fwnode_handle *fwnode,
const char *name, size_t index,
struct acpi_reference_args *args)
{
struct acpi_device_data *data = acpi_device_data_of_node(fwnode);
return data ? acpi_data_get_property_reference(data, name, index, args) : -EINVAL; return -ENODATA;
} }
EXPORT_SYMBOL_GPL(acpi_node_get_property_reference); 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(struct acpi_device_data *data,
const char *propname, const char *propname,
......
...@@ -927,10 +927,18 @@ struct acpi_reference_args { ...@@ -927,10 +927,18 @@ struct acpi_reference_args {
#ifdef CONFIG_ACPI #ifdef CONFIG_ACPI
int acpi_dev_get_property(struct acpi_device *adev, const char *name, int acpi_dev_get_property(struct acpi_device *adev, const char *name,
acpi_object_type type, const union acpi_object **obj); acpi_object_type type, const union acpi_object **obj);
int acpi_node_get_property_reference(struct fwnode_handle *fwnode, int __acpi_node_get_property_reference(struct fwnode_handle *fwnode,
const char *name, size_t index, const char *name, size_t index, size_t num_args,
struct acpi_reference_args *args); struct acpi_reference_args *args);
static inline int acpi_node_get_property_reference(struct fwnode_handle *fwnode,
const char *name, size_t index,
struct acpi_reference_args *args)
{
return __acpi_node_get_property_reference(fwnode, name, index,
MAX_ACPI_REFERENCE_ARGS, args);
}
int acpi_node_prop_get(struct fwnode_handle *fwnode, const char *propname, int acpi_node_prop_get(struct fwnode_handle *fwnode, const char *propname,
void **valptr); void **valptr);
int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname, int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname,
...@@ -1005,6 +1013,14 @@ static inline int acpi_dev_get_property(struct acpi_device *adev, ...@@ -1005,6 +1013,14 @@ static inline int acpi_dev_get_property(struct acpi_device *adev,
return -ENXIO; return -ENXIO;
} }
static inline int
__acpi_node_get_property_reference(struct fwnode_handle *fwnode,
const char *name, size_t index, size_t num_args,
struct acpi_reference_args *args)
{
return -ENXIO;
}
static inline int acpi_node_get_property_reference(struct fwnode_handle *fwnode, static inline int acpi_node_get_property_reference(struct fwnode_handle *fwnode,
const char *name, size_t index, const char *name, size_t index,
struct acpi_reference_args *args) struct acpi_reference_args *args)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment