lkml.org 
[lkml]   [2014]   [Oct]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH v2 4/4] vfio: platform: devtree: return arrays of u32, u16, or u8 data
Date
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@virtualopensystems.com>
---
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


\
 
 \ /
  Last update: 2014-10-16 18:22    [W:0.038 / U:1.176 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site