From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:39559) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBgh6-0000gs-Hk for qemu-devel@nongnu.org; Sat, 02 Mar 2013 02:17:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBgh4-0001Bs-E7 for qemu-devel@nongnu.org; Sat, 02 Mar 2013 02:17:20 -0500 Received: from g6t0184.atlanta.hp.com ([15.193.32.61]:12788) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBgh4-00019T-93 for qemu-devel@nongnu.org; Sat, 02 Mar 2013 02:17:18 -0500 From: Vijay Mohan Pandarathil Date: Sat, 2 Mar 2013 01:16:57 -0600 Message-Id: <1362208619-5028-2-git-send-email-vijaymohan.pandarathil@hp.com> In-Reply-To: <1362208619-5028-1-git-send-email-vijaymohan.pandarathil@hp.com> References: <1362208619-5028-1-git-send-email-vijaymohan.pandarathil@hp.com> Subject: [Qemu-devel] [PATCH v6 1/3] VFIO: Wrapper for getting reference to vfio_device from device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: alex.williamson@redhat.com, gleb@redhat.com, bhelgaas@google.com, blauwirbel@gmail.com, lance.oritz@hp.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Vijay Mohan Pandarathil - Added vfio_device_get_from_dev() as wrapper to get reference to vfio_device from struct device. - Added vfio_device_data() as a wrapper to get device_data from vfio_device. Signed-off-by: Vijay Mohan Pandarathil --- drivers/vfio/vfio.c | 27 ++++++++++++++++++++++++++- include/linux/vfio.h | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 28e2d5b..eec6674 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -407,12 +407,13 @@ static void vfio_device_release(struct kref *kref) } /* Device reference always implies a group reference */ -static void vfio_device_put(struct vfio_device *device) +void vfio_device_put(struct vfio_device *device) { struct vfio_group *group = device->group; kref_put_mutex(&device->kref, vfio_device_release, &group->device_lock); vfio_group_put(group); } +EXPORT_SYMBOL_GPL(vfio_device_put); static void vfio_device_get(struct vfio_device *device) { @@ -642,6 +643,30 @@ int vfio_add_group_dev(struct device *dev, } EXPORT_SYMBOL_GPL(vfio_add_group_dev); +/** + * This does a get on the vfio_device from device. + * Callers of this function will have to call vfio_put_device() to + * remove the reference. + */ +struct vfio_device *vfio_device_get_from_dev(struct device *dev) +{ + struct vfio_device *device = dev_get_drvdata(dev); + + vfio_device_get(device); + + return device; +} +EXPORT_SYMBOL_GPL(vfio_device_get_from_dev); + +/* + * Caller must hold a reference to the vfio_device + */ +void *vfio_device_data(struct vfio_device *device) +{ + return device->device_data; +} +EXPORT_SYMBOL_GPL(vfio_device_data); + /* Given a referenced group, check if it contains the device */ static bool vfio_dev_present(struct vfio_group *group, struct device *dev) { diff --git a/include/linux/vfio.h b/include/linux/vfio.h index ab9e862..ac8d488 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -45,6 +45,9 @@ extern int vfio_add_group_dev(struct device *dev, void *device_data); extern void *vfio_del_group_dev(struct device *dev); +extern struct vfio_device *vfio_device_get_from_dev(struct device *dev); +extern void vfio_device_put(struct vfio_device *device); +extern void *vfio_device_data(struct vfio_device *device); /** * struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks -- 1.7.11.3