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: 2275101 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 76C093FC8F for ; Fri, 15 Mar 2013 07:26:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751985Ab3COH0j (ORCPT ); Fri, 15 Mar 2013 03:26:39 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:37418 "EHLO e8.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750903Ab3COH0i (ORCPT ); Fri, 15 Mar 2013 03:26:38 -0400 Received: from /spool/local by e8.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 15 Mar 2013 03:26:37 -0400 Received: from d01dlp02.pok.ibm.com (9.56.250.167) by e8.ny.us.ibm.com (192.168.1.108) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 15 Mar 2013 03:26:37 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 40B8D6E803F for ; Fri, 15 Mar 2013 03:26:34 -0400 (EDT) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2F7QZOP291038 for ; Fri, 15 Mar 2013 03:26:36 -0400 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 r2F7QYA5014891 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 Cc: alex.williamson@redhat.com, benh@kernel.crashing.org, aik@ozlabs.ru, Gavin Shan 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-9360-0000-0000-000011565810 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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);