From: Antonios Motakis <a.motakis@virtualopensystems.com>
To: alex.williamson@redhat.com, kvmarm@lists.cs.columbia.edu,
iommu@lists.linux-foundation.org
Cc: tech@virtualopensystems.com, a.rigo@virtualopensystems.com,
kvm@vger.kernel.org, christoffer.dall@linaro.org,
will.deacon@arm.com, kim.phillips@freescale.com,
stuart.yoder@freescale.com, eric.auger@linaro.org,
marc.zyngier@arm.com,
Antonios Motakis <a.motakis@virtualopensystems.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH 3/4] VFIO: PLATFORM: DEVTREE: Access property as a list of strings
Date: Wed, 13 Aug 2014 13:02:18 +0200 [thread overview]
Message-ID: <1407927740-14993-4-git-send-email-a.motakis@virtualopensystems.com> (raw)
In-Reply-To: <1407927740-14993-1-git-send-email-a.motakis@virtualopensystems.com>
Certain device tree properties (e.g. the device node name, the compatible
string), are available as a list of strings (separated by the null
terminating character). Let the VFIO user query this type of properties.
Signed-off-by: Antonios Motakis <a.motakis@virtualopensystems.com>
---
drivers/vfio/platform/devtree.c | 60 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/drivers/vfio/platform/devtree.c b/drivers/vfio/platform/devtree.c
index b8fd4138..80c60d4 100644
--- a/drivers/vfio/platform/devtree.c
+++ b/drivers/vfio/platform/devtree.c
@@ -61,6 +61,43 @@ static int devtree_get_prop_names(struct device_node *np, void __user *datap,
return ret;
}
+static int devtree_get_strings(struct device_node *np, char *name,
+ void __user *datap, unsigned long datasz)
+{
+ struct property *prop;
+ int len;
+
+ prop = of_find_property(np, name, &len);
+
+ if (!prop)
+ return -EINVAL;
+
+ if (len > datasz)
+ return -EAGAIN;
+
+ if (copy_to_user(datap, prop->value, len))
+ return -EFAULT;
+ else
+ return 0;
+}
+
+static int devtree_get_full_name(struct device_node *np, void __user *datap,
+ unsigned long datasz, int *lenp)
+{
+ int len = strlen(np->full_name) + 1;
+
+ if (lenp)
+ *lenp = len;
+
+ if (len > datasz)
+ return -EAGAIN;
+
+ if (copy_to_user(datap, np->full_name, len))
+ return -EFAULT;
+
+ return 0;
+}
+
long vfio_platform_devtree_ioctl(struct vfio_platform_device *vdev,
unsigned long arg)
{
@@ -68,6 +105,7 @@ long vfio_platform_devtree_ioctl(struct vfio_platform_device *vdev,
unsigned long minsz = offsetofend(struct vfio_devtree_info, length);
void __user *datap = (void __user *) arg + minsz;
unsigned long int datasz;
+ char *name;
int ret = -EINVAL;
if (!vfio_platform_has_devtree(vdev))
@@ -84,8 +122,30 @@ long vfio_platform_devtree_ioctl(struct vfio_platform_device *vdev,
if (info.type == VFIO_DEVTREE_PROP_NAMES) {
ret = devtree_get_prop_names(vdev->of_node, datap, datasz,
&info.length);
+ goto out;
}
+ name = kzalloc(datasz, GFP_KERNEL);
+ if (!name)
+ return -ENOMEM;
+ if (copy_from_user(name, datap, datasz))
+ return -EFAULT;
+
+ if (!of_find_property(vdev->of_node, name, &info.length)) {
+ /* special case full_name as a property that is not on the fdt,
+ * but we wish to return to the user as it includes the full
+ * path of the device */
+ if (!strcmp(name, "full_name") &&
+ (info.type == VFIO_DEVTREE_ARR_TYPE_STRING))
+ ret = devtree_get_full_name(vdev->of_node, datap,
+ datasz, &info.length);
+
+ } else if (info.type == VFIO_DEVTREE_ARR_TYPE_STRING)
+ ret = devtree_get_strings(vdev->of_node, name, datap, datasz);
+
+ kfree(name);
+
+out:
if (copy_to_user((void __user *)arg, &info, minsz))
ret = -EFAULT;
--
1.8.3.2
next prev parent reply other threads:[~2014-08-13 11:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1407927740-14993-1-git-send-email-a.motakis@virtualopensystems.com>
2014-08-13 11:02 ` [PATCH 1/4] VFIO: PLATFORM: Add device tree info API and skeleton Antonios Motakis
2014-08-13 11:02 ` [PATCH 2/4] VFIO: PLATFORM: DEVTREE: Return available property names Antonios Motakis
2014-08-13 11:02 ` Antonios Motakis [this message]
2014-08-13 11:02 ` [PATCH 4/4] VFIO: PLATFORM: DEVTREE: Return arrays of u32, u16, or u8 Antonios Motakis
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=1407927740-14993-4-git-send-email-a.motakis@virtualopensystems.com \
--to=a.motakis@virtualopensystems.com \
--cc=a.rigo@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=marc.zyngier@arm.com \
--cc=stuart.yoder@freescale.com \
--cc=tech@virtualopensystems.com \
--cc=will.deacon@arm.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
Powered by JetHome