diff options
author | Kornel Duleba <mindal@semihalf.com> | 2022-01-28 09:28:37 +0000 |
---|---|---|
committer | Marcin Wojtas <mw@FreeBSD.org> | 2022-03-10 11:11:32 +0000 |
commit | b344de4d0d163cbd8bf88cb5d226c18fe96f488f (patch) | |
tree | c1637f71d5b8566b9d3e9451d4eb0694958bac96 /sys/dev/fdt | |
parent | 206dc82bc3fc5e1d90200e189ce5f2240dfec874 (diff) | |
download | src-b344de4d0d163cbd8bf88cb5d226c18fe96f488f.tar.gz src-b344de4d0d163cbd8bf88cb5d226c18fe96f488f.zip |
Extend device_get_property API
In order to support various types of data stored in device
tree properties or ACPI _DSD packages, create a new enum so
the caller can specify the expected type of a property they
want to read, according to the binding. The bus logic will use
that information to process the underlying data.
For example in DT all integer properties are stored in BE format.
In order to get constant results across different platforms we
need to convert its endianness to match the host.
Another example are ACPI_TYPE_INTEGER properties stored
as uint64_t. Before this patch the ACPI logic would refuse
to read them if the provided buffer was smaller than 8 bytes.
Now this can be handled by using DEVICE_PROP_UINT32 type.
Modify the existing consumers of this API to reflect the changes
and update the man pages accordingly.
Reviewed by: mw
Obtained from: Semihalf
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D33457
Diffstat (limited to 'sys/dev/fdt')
-rw-r--r-- | sys/dev/fdt/simplebus.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/sys/dev/fdt/simplebus.c b/sys/dev/fdt/simplebus.c index 4d58f9b3ea69..b5a10f83055c 100644 --- a/sys/dev/fdt/simplebus.c +++ b/sys/dev/fdt/simplebus.c @@ -56,7 +56,8 @@ static struct resource_list *simplebus_get_resource_list(device_t bus, device_t child); static ssize_t simplebus_get_property(device_t bus, device_t child, - const char *propname, void *propvalue, size_t size); + const char *propname, void *propvalue, size_t size, + device_property_type_t type); /* * ofw_bus interface */ @@ -356,14 +357,56 @@ simplebus_get_resource_list(device_t bus __unused, device_t child) static ssize_t simplebus_get_property(device_t bus, device_t child, const char *propname, - void *propvalue, size_t size) + void *propvalue, size_t size, device_property_type_t type) { phandle_t node = ofw_bus_get_node(child); + ssize_t ret, i; + uint32_t *buffer; + uint64_t val; + + switch (type) { + case DEVICE_PROP_ANY: + case DEVICE_PROP_BUFFER: + case DEVICE_PROP_UINT32: + case DEVICE_PROP_UINT64: + break; + default: + return (-1); + } if (propvalue == NULL || size == 0) return (OF_getproplen(node, propname)); - return (OF_getencprop(node, propname, propvalue, size)); + /* + * Integer values are stored in BE format. + * If caller declared that the underlying property type is uint32_t + * we need to do the conversion to match host endianness. + */ + if (type == DEVICE_PROP_UINT32) + return (OF_getencprop(node, propname, propvalue, size)); + + /* + * uint64_t also requires endianness handling. + * In FDT every 8 byte value is stored using two uint32_t variables + * in BE format. Now, since the upper bits are stored as the first + * of the pair, both halves require swapping. + */ + if (type == DEVICE_PROP_UINT64) { + ret = OF_getencprop(node, propname, propvalue, size); + if (ret <= 0) { + return (ret); + } + + buffer = (uint32_t *)propvalue; + + for (i = 0; i < size / 4; i += 2) { + val = (uint64_t)buffer[i] << 32 | buffer[i + 1]; + ((uint64_t *)buffer)[i / 2] = val; + } + return (ret); + } + + return (OF_getprop(node, propname, propvalue, size)); } static struct resource * |