From patchwork Fri Mar 15 07:26:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 227863 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id C30A22C0773 for ; Fri, 15 Mar 2013 18:28:56 +1100 (EST) Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "e36.co.us.ibm.com", Issuer "GeoTrust SSL CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 5A2FF2C00DD for ; Fri, 15 Mar 2013 18:26:41 +1100 (EST) Received: from /spool/local by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 15 Mar 2013 01:26:38 -0600 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 15 Mar 2013 01:26:36 -0600 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id E0AC01FF0039 for ; Fri, 15 Mar 2013 01:21:40 -0600 (MDT) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2F7QZCY115454 for ; Fri, 15 Mar 2013 01:26:35 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2F7QY9x014891 for ; Fri, 15 Mar 2013 01:26:35 -0600 Received: from shangw ([9.77.179.176]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2F7QXri014843; Fri, 15 Mar 2013 01:26:34 -0600 Received: by shangw (Postfix, from userid 1000) id 1F1D2302217; Fri, 15 Mar 2013 15:26:32 +0800 (CST) From: Gavin Shan To: kvm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH 1/3] VFIO: Architecture dependent VFIO device operations Date: Fri, 15 Mar 2013 15:26:28 +0800 Message-Id: <1363332390-12754-2-git-send-email-shangw@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1363332390-12754-1-git-send-email-shangw@linux.vnet.ibm.com> References: <1363332390-12754-1-git-send-email-shangw@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031507-7606-0000-0000-000009779323 Cc: aik@ozlabs.ru, alex.williamson@redhat.com, Gavin Shan X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Some architectures like PPC, especailly PowerNV platform, need to do additional operations while adding or removing VFIO devices to or from VFIO bus. The patch adds weak functions while to open, release or ioctl for the specific VFIO device. Those functions could be overrided by individual architectures if necessary. Signed-off-by: Gavin Shan --- drivers/vfio/pci/vfio_pci.c | 42 +++++++++++++++++++++++++++++++++++------- include/linux/vfio.h | 7 ++++++- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 8189cb6..1a53e77 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -143,32 +143,51 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev) pci_restore_state(pdev); } +void __weak vfio_pci_arch_release(struct pci_dev *pdev) +{ + return; +} + static void vfio_pci_release(void *device_data) { struct vfio_pci_device *vdev = device_data; - if (atomic_dec_and_test(&vdev->refcnt)) + if (atomic_dec_and_test(&vdev->refcnt)) { + vfio_pci_arch_release(vdev->pdev); + vfio_pci_disable(vdev); + } module_put(THIS_MODULE); } +int __weak vfio_pci_arch_open(struct pci_dev *pdev) +{ + return 0; +} + static int vfio_pci_open(void *device_data) { struct vfio_pci_device *vdev = device_data; + int ret; if (!try_module_get(THIS_MODULE)) return -ENODEV; if (atomic_inc_return(&vdev->refcnt) == 1) { - int ret = vfio_pci_enable(vdev); - if (ret) { - module_put(THIS_MODULE); - return ret; - } + ret = vfio_pci_arch_open(vdev->pdev); + if (ret) + goto fail; + + ret = vfio_pci_enable(vdev); + if (ret) + goto fail; } return 0; +fail: + module_put(THIS_MODULE); + return ret; } static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type) @@ -206,6 +225,12 @@ static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type) return 0; } +long __weak vfio_pci_arch_ioctl(struct pci_dev *pdev, + unsigned int cmd, unsigned long arg) +{ + return -ENOTTY; +} + static long vfio_pci_ioctl(void *device_data, unsigned int cmd, unsigned long arg) { @@ -374,9 +399,12 @@ static long vfio_pci_ioctl(void *device_data, return ret; - } else if (cmd == VFIO_DEVICE_RESET) + } else if (cmd == VFIO_DEVICE_RESET) { return vdev->reset_works ? pci_reset_function(vdev->pdev) : -EINVAL; + } else { + return vfio_pci_arch_ioctl(vdev->pdev, cmd, arg); + } return -ENOTTY; } diff --git a/include/linux/vfio.h b/include/linux/vfio.h index ab9e862..a991c39 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -11,9 +11,9 @@ #ifndef VFIO_H #define VFIO_H - #include #include +#include #include /** @@ -40,6 +40,11 @@ struct vfio_device_ops { int (*mmap)(void *device_data, struct vm_area_struct *vma); }; +extern int vfio_pci_arch_open(struct pci_dev *pdev); +extern long vfio_pci_arch_ioctl(struct pci_dev *pdev, + unsigned int cmd, + unsigned long arg); +extern void vfio_pci_arch_release(struct pci_dev *pdev); extern int vfio_add_group_dev(struct device *dev, const struct vfio_device_ops *ops, void *device_data);