mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Antonios Motakis <a.motakis@virtualopensystems.com>
To: kvmarm@lists.cs.columbia.edu, iommu@lists.linux-foundation.org,
	alex.williamson@redhat.com
Cc: tech@virtualopensystems.com, christoffer.dall@linaro.org,
	eric.auger@linaro.org, kim.phillips@freescale.com,
	Antonios Motakis <a.motakis@virtualopensystems.com>,
	kvm@vger.kernel.org (open list:VFIO DRIVER),
	linux-kernel@vger.kernel.org (open list)
Subject: [RFC PATCH v2 4/4] vfio: platform: devtree: return arrays of u32, u16, or u8 data
Date: Thu, 16 Oct 2014 17:54:36 +0200	[thread overview]
Message-ID: <1413474876-28544-5-git-send-email-a.motakis@virtualopensystems.com> (raw)
In-Reply-To: <1413474876-28544-1-git-send-email-a.motakis@virtualopensystems.com>

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


      parent reply	other threads:[~2014-10-16 15:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1413474876-28544-1-git-send-email-a.motakis@virtualopensystems.com>
2014-10-16 15:54 ` [RFC PATCH v2 1/4] vfio: platform: add device tree info API and skeleton Antonios Motakis
2014-10-16 15:54 ` [RFC PATCH v2 2/4] vfio: platform: devtree: return available property names Antonios Motakis
2014-10-16 15:54 ` [RFC PATCH v2 3/4] vfio: platform: devtree: access property as a list of strings Antonios Motakis
2014-10-16 15:54 ` Antonios Motakis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1413474876-28544-5-git-send-email-a.motakis@virtualopensystems.com \
    --to=a.motakis@virtualopensystems.com \
    --cc=alex.williamson@redhat.com \
    --cc=christoffer.dall@linaro.org \
    --cc=eric.auger@linaro.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=kim.phillips@freescale.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tech@virtualopensystems.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®