From patchwork Mon Jan 28 09:54:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pandarathil, Vijaymohan R" X-Patchwork-Id: 216143 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 01B082C008D for ; Mon, 28 Jan 2013 20:55:16 +1100 (EST) Received: from localhost ([::1]:39710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzlQo-0004FY-6m for incoming@patchwork.ozlabs.org; Mon, 28 Jan 2013 04:55:14 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55705) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzlQa-00046E-VK for qemu-devel@nongnu.org; Mon, 28 Jan 2013 04:55:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TzlQW-0002wO-0s for qemu-devel@nongnu.org; Mon, 28 Jan 2013 04:55:00 -0500 Received: from g4t0014.houston.hp.com ([15.201.24.17]:20353) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzlQV-0002wJ-QU for qemu-devel@nongnu.org; Mon, 28 Jan 2013 04:54:55 -0500 Received: from G9W0364.americas.hpqcorp.net (g9w0364.houston.hp.com [16.216.193.45]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by g4t0014.houston.hp.com (Postfix) with ESMTPS id 2F21D24373; Mon, 28 Jan 2013 09:54:55 +0000 (UTC) Received: from G9W3617.americas.hpqcorp.net (16.216.186.52) by G9W0364.americas.hpqcorp.net (16.216.193.45) with Microsoft SMTP Server (TLS) id 14.2.328.9; Mon, 28 Jan 2013 09:54:34 +0000 Received: from G9W0717.americas.hpqcorp.net ([169.254.4.192]) by G9W3617.americas.hpqcorp.net ([16.216.186.52]) with mapi id 14.02.0328.009; Mon, 28 Jan 2013 09:54:34 +0000 From: "Pandarathil, Vijaymohan R" To: Alex Williamson , Gleb Natapov , Bjorn Helgaas , Blue Swirl , "Ortiz, Lance E" Thread-Topic: [PATCH v2 1/3] VFIO: Wrappers for getting/putting reference to vfio_device Thread-Index: AQHN/T15+xIQxThFMk2st/x5WGLB8g== Date: Mon, 28 Jan 2013 09:54:34 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [16.210.48.23] MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 15.201.24.17 Cc: "linux-pci@vger.kernel.org" , "qemu-devel@nongnu.org" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: [Qemu-devel] [PATCH v2 1/3] VFIO: Wrappers for getting/putting reference to vfio_device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org - Added vfio_device_get_from_vdev(), vfio_device_put_vdev() as wrappers to get/put 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 | 47 +++++++++++++++++++++++++++++++++++++++++------ include/linux/vfio.h | 3 +++ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 12c264d..c2ff1b2 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -642,8 +642,13 @@ int vfio_add_group_dev(struct device *dev, } EXPORT_SYMBOL_GPL(vfio_add_group_dev); -/* Test whether a struct device is present in our tracking */ -static bool vfio_dev_present(struct device *dev) +/** + * This does a get on the corresponding iommu_group, + * vfio_group and the vfio_device. Callers of this + * function will hae to call vfio_put_vdev() to + * remove the reference to all objects. + */ +void *vfio_device_get_from_dev(struct device *dev) { struct iommu_group *iommu_group; struct vfio_group *group; @@ -651,25 +656,55 @@ static bool vfio_dev_present(struct device *dev) iommu_group = iommu_group_get(dev); if (!iommu_group) - return false; + return NULL; group = vfio_group_get_from_iommu(iommu_group); if (!group) { iommu_group_put(iommu_group); - return false; + return NULL; } device = vfio_group_get_device(group, dev); if (!device) { vfio_group_put(group); iommu_group_put(iommu_group); - return false; + return NULL; } + return device; +} +EXPORT_SYMBOL_GPL(vfio_device_get_from_dev); + +void *vfio_device_data(void *data) +{ + struct vfio_device *device = data; + return device->device_data; +} +EXPORT_SYMBOL_GPL(vfio_device_data); + +void vfio_device_put_vdev(void *data) +{ + struct vfio_device *device = data; + struct vfio_group *group = device->group; + struct iommu_group *iommu_group = group->iommu_group; vfio_device_put(device); vfio_group_put(group); iommu_group_put(iommu_group); - return true; + return; +} +EXPORT_SYMBOL_GPL(vfio_device_put_vdev); + +/* Test whether a struct device is present in our tracking */ +static bool vfio_dev_present(struct device *dev) +{ + struct vfio_device *device; + + device = vfio_device_get_from_dev(dev); + if (device) { + vfio_device_put_vdev(device); + return true; + } else + return false; } /* diff --git a/include/linux/vfio.h b/include/linux/vfio.h index ab9e862..e550c09 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 void *vfio_device_get_from_dev(struct device *dev); +extern void vfio_device_put_vdev(void *device); +extern void *vfio_device_data(void *device); /** * struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks