Received: from eggs.gnu.org ([2001:4830:134:3::10]:60453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLa9d-0006sF-4I for qemu-devel@nongnu.org; Wed, 11 Feb 2015 11:28:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLa9Y-0004nX-UA for qemu-devel@nongnu.org; Wed, 11 Feb 2015 11:28:44 -0500 Received: from mail-wg0-f54.google.com ([74.125.82.54]:60481) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLa9Y-0004nS-P5 for qemu-devel@nongnu.org; Wed, 11 Feb 2015 11:28:40 -0500 Received: by mail-wg0-f54.google.com with SMTP id y19so4512122wgg.13 for ; Wed, 11 Feb 2015 08:28:40 -0800 (PST) From: Baptiste Reynal Date: Wed, 11 Feb 2015 17:28:07 +0100 Message-Id: <1423672089-13464-3-git-send-email-b.reynal@virtualopensystems.com> In-Reply-To: <1423672089-13464-1-git-send-email-b.reynal@virtualopensystems.com> References: <1423672089-13464-1-git-send-email-b.reynal@virtualopensystems.com> Subject: [Qemu-devel] [RFC PATCH v2 2/4] hw/vfio/common.c : vfio_get_dev_property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kvmarm@lists.cs.columbia.edu, qemu-devel@nongnu.org Cc: Alex Williamson , tech@virtualopensystems.com, Baptiste Reynal Add a function to handle ioctl VFIO_DEVICE_GET_DEV_PROPERTY to retrieve properties from a VFIO device. Signed-off-by: Baptiste Reynal --- v1 -> v2: fix property->length initialization --- hw/vfio/common.c | 32 ++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-common.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index cf483ff..728afee 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -957,3 +957,35 @@ 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, argsz; + struct vfio_dev_property *property = NULL; + int ret; + + length = strlen(name) + 1; + argsz = sizeof(struct vfio_dev_property) + length; + property = malloc(argsz); + property->argsz = argsz; + property->type = type; + property->length = length; + + do { + length = property->length; + argsz = sizeof(struct vfio_dev_property) + length; + property = realloc(property, argsz); + property->argsz = argsz; + strcpy((char *) property->data, name); + + ret = ioctl(device, VFIO_DEVICE_GET_DEV_PROPERTY, property); + } while (length < property->length); + + 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 8ab880a..66e9c5a 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -144,6 +144,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.3.0