From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAexn-0000Ui-DT for qemu-devel@nongnu.org; Mon, 12 Jan 2015 08:23:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YAexj-0003R6-8c for qemu-devel@nongnu.org; Mon, 12 Jan 2015 08:23:23 -0500 Received: from mail-wg0-f47.google.com ([74.125.82.47]:32993) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAexj-0003PX-32 for qemu-devel@nongnu.org; Mon, 12 Jan 2015 08:23:19 -0500 Received: by mail-wg0-f47.google.com with SMTP id n12so19254586wgh.6 for ; Mon, 12 Jan 2015 05:23:18 -0800 (PST) From: Baptiste Reynal Date: Mon, 12 Jan 2015 14:21:41 +0100 Message-Id: <1421068903-8981-3-git-send-email-b.reynal@virtualopensystems.com> In-Reply-To: <1421068903-8981-1-git-send-email-b.reynal@virtualopensystems.com> References: <1421068903-8981-1-git-send-email-b.reynal@virtualopensystems.com> Subject: [Qemu-devel] [RFC PATCH 2/4] hw/vfio/common.c : vfio_get_dev_property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, kvmarm@lists.cs.columbia.edu Cc: Alex Williamson , tech@virtualopensystems.com, Baptiste Reynal , eric.auger@linaro.org Add a function to handle ioctl VFIO_DEVICE_GET_DEV_PROPERTY to retrieve properties from a VFIO device. Signed-off-by: Baptiste Reynal --- hw/vfio/common.c | 33 +++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-common.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index ba00ec9..698d2c4 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -958,3 +958,36 @@ int vfio_container_ioctl(AddressSpace *as, int32_t groupid, return vfio_container_do_ioctl(as, groupid, req, param); } + +struct vfio_dev_property *vfio_get_dev_property(int device, const char *name, + unsigned int type) +{ + unsigned int length = 0; + struct vfio_dev_property *property = NULL; + int ret; + + length = strlen(name) + 1; + + while (1) { + unsigned int argsz = sizeof(struct vfio_dev_property) + length; + property = realloc(property, argsz); + property->argsz = argsz; + property->type = type; + strcpy((char *) property->data, name); + + ret = ioctl(device, VFIO_DEVICE_GET_DEV_PROPERTY, property); + + if (length < property->length) { + length = property->length; + } else { + break; + } + } + + if (ret) { + g_free(property); + property = NULL; + } + + return property; +} diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 2f1b09c..9c649cd 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -149,6 +149,8 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as); void vfio_put_group(VFIOGroup *group); int vfio_get_device(VFIOGroup *group, const char *name, VFIODevice *vbasedev); +struct vfio_dev_property *vfio_get_dev_property(int device, const char *name, + unsigned int type); extern const MemoryRegionOps vfio_region_ops; extern const MemoryListener vfio_memory_listener; -- 2.2.1