[RFC PATCH v2 4/4] vfio: platform: devtree: return arrays of u32, u16, or u8 data

From: Antonios Motakis
Date: Thu Oct 16 2014 - 11:55:56 EST


Certain properties of a device tree node are accessible as an array
of unsigned integers, either u32, u16, or u8. Let the VFIO user query
this type of device node properties. Accessing u64 arrays is not yet
implemented in this RFC.

Signed-off-by: Antonios Motakis <a.motakis@xxxxxxxxxxxxxxxxxxxxxx>
---
drivers/vfio/platform/devtree.c | 55 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/drivers/vfio/platform/devtree.c b/drivers/vfio/platform/devtree.c
index 6d25f97..17f55d4 100644
--- a/drivers/vfio/platform/devtree.c
+++ b/drivers/vfio/platform/devtree.c
@@ -97,7 +97,60 @@ static int devtree_get_uint(struct device_node *np, char *name,
uint32_t type, unsigned *lenp,
void __user *datap, unsigned long datasz)
{
- return -EINVAL;
+ int ret, n;
+ size_t sz;
+ u8 *out;
+ int (*func)(const struct device_node *, const char *, void *, size_t)
+ = NULL;
+
+ switch (type) {
+ case VFIO_DEVTREE_TYPE_U32:
+ sz = sizeof(u32);
+ func = (int (*)(const struct device_node *,
+ const char *, void *, size_t))
+ of_property_read_u32_array;
+ break;
+ case VFIO_DEVTREE_TYPE_U16:
+ sz = sizeof(u16);
+ func = (int (*)(const struct device_node *,
+ const char *, void *, size_t))
+ of_property_read_u16_array;
+ break;
+ case VFIO_DEVTREE_TYPE_U8:
+ sz = sizeof(u8);
+ func = (int (*)(const struct device_node *,
+ const char *, void *, size_t))
+ of_property_read_u8_array;
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ n = of_property_count_elems_of_size(np, name, sz);
+ if (n < 0)
+ return n;
+
+ if (lenp)
+ *lenp = n * sz;
+
+ if (n * sz > datasz)
+ return -EAGAIN;
+
+ out = kcalloc(n, sz, GFP_KERNEL);
+ if (!out)
+ return -EFAULT;
+
+ ret = func(np, name, out, n);
+ if (ret)
+ goto out;
+
+ if (copy_to_user(datap, out, n * sz))
+ ret = -EFAULT;
+
+out:
+ kfree(out);
+ return ret;
}

int vfio_platform_devtree_info(struct device_node *np,
--
2.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/