From patchwork Mon Aug 25 13:27:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 4774871 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5D3DC9F3B4 for ; Mon, 25 Aug 2014 13:32:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B2F9620109 for ; Mon, 25 Aug 2014 13:32:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A5B062011E for ; Mon, 25 Aug 2014 13:32:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XLuL1-0007om-Eb; Mon, 25 Aug 2014 13:29:35 +0000 Received: from mail-we0-f169.google.com ([74.125.82.169]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XLuKb-0007Q3-6Q for linux-arm-kernel@lists.infradead.org; Mon, 25 Aug 2014 13:29:10 +0000 Received: by mail-we0-f169.google.com with SMTP id u56so13246940wes.14 for ; Mon, 25 Aug 2014 06:28:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4l/q6ksuE0M5rdNAkUmMoXSztNlXacHreHZW4H7Z0FY=; b=UMxXMrAwRV0YijWojJB2WhPSDXpvbktK0s8488rW7lQW/q0SWUXu4VSBjS6r94C0S9 Or+/yOXu3m5VhxvnhEqTLjrCHnn6lFwhJJKc5uoHRNgqVJsNLJ1kQptUBw6RWdmItoEh dJh6D+6jJAb1DwxRTst8a4tQGvuLpgentw4ui4HfJd9DhbPAOQGFmdqEEn/7U6iq7Rm0 XNmRP/dZGWrP724AyjZElvrefhlycDL4BgJhcUVIuI/T3mZp37tHU+mPM9h1CoydaxX+ Z4i9WqxesYa7XxIEP6VY+I286yuCIJVR9uxdB/y3kTQLF9R9e6aErkSLCFzF4FARdL/7 60sw== X-Gm-Message-State: ALoCoQnToJPBQDPsqCfivtbjuUoeH6kzoGduH3ga2DziV6HinoCO5DP7z3mJvt4+9fXdUVj8qINI X-Received: by 10.194.94.165 with SMTP id dd5mr9318813wjb.75.1408973326895; Mon, 25 Aug 2014 06:28:46 -0700 (PDT) Received: from gnx2579.gnb.st.com (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by mx.google.com with ESMTPSA id co6sm100101595wjb.31.2014.08.25.06.28.45 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Aug 2014 06:28:46 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, alex.williamson@redhat.com, joel.schopp@amd.com, kim.phillips@freescale.com Subject: [RFC 5/9] VFIO: Extend external user API Date: Mon, 25 Aug 2014 15:27:40 +0200 Message-Id: <1408973264-30384-6-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1408973264-30384-1-git-send-email-eric.auger@linaro.org> References: <1408973264-30384-1-git-send-email-eric.auger@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140825_062909_436602_232ACB4E X-CRM114-Status: GOOD ( 11.26 ) X-Spam-Score: -0.7 (/) Cc: patches@linaro.org, john.liuli@huawei.com, will.deacon@arm.com, a.rigo@virtualopensystems.com, linux-kernel@vger.kernel.org, a.motakis@virtualopensystems.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP New functions are added to be called from ARM KVM-VFIO device. - vfio_device_get_external_user enables to get a vfio device from its fd - vfio_device_put_external_user puts the vfio device - vfio_external_get_type enables to retrieve the type of the device (PCI or platform) - vfio_external_get_base_device enables to get the struct device*, useful to access the platform_device Signed-off-by: Eric Auger --- drivers/vfio/vfio.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/vfio.h | 4 ++++ 2 files changed, 39 insertions(+) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index 8e84471..c93b9e4 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c @@ -1401,6 +1401,41 @@ void vfio_group_put_external_user(struct vfio_group *group) } EXPORT_SYMBOL_GPL(vfio_group_put_external_user); +struct vfio_device *vfio_device_get_external_user(struct file *filep) +{ + struct vfio_device *vdev = filep->private_data; + + if (filep->f_op != &vfio_device_fops) + return ERR_PTR(-EINVAL); + + vfio_device_get(vdev); + return vdev; +} +EXPORT_SYMBOL_GPL(vfio_device_get_external_user); + +void vfio_device_put_external_user(struct vfio_device *vdev) +{ + vfio_device_put(vdev); +} +EXPORT_SYMBOL_GPL(vfio_device_put_external_user); + +int vfio_external_get_type(struct vfio_device *vdev) +{ + if (!strcmp(vdev->ops->name, "vfio-platform")) + return VFIO_DEVICE_FLAGS_PLATFORM; + else if (!strcmp(vdev->ops->name, "vfio-pci")) + return VFIO_DEVICE_FLAGS_PCI; + else + return -EINVAL; +} +EXPORT_SYMBOL_GPL(vfio_external_get_type); + +struct device *vfio_external_get_base_device(struct vfio_device *vdev) +{ + return vdev->dev; +} +EXPORT_SYMBOL_GPL(vfio_external_get_base_device); + int vfio_external_user_iommu_id(struct vfio_group *group) { return iommu_group_id(group->iommu_group); diff --git a/include/linux/vfio.h b/include/linux/vfio.h index ffe04ed..19e98eb 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -99,6 +99,10 @@ extern void vfio_group_put_external_user(struct vfio_group *group); extern int vfio_external_user_iommu_id(struct vfio_group *group); extern long vfio_external_check_extension(struct vfio_group *group, unsigned long arg); +extern struct vfio_device *vfio_device_get_external_user(struct file *filep); +extern void vfio_device_put_external_user(struct vfio_device *vdev); +extern int vfio_external_get_type(struct vfio_device *vdev); +extern struct device *vfio_external_get_base_device(struct vfio_device *vdev); struct pci_dev; #ifdef CONFIG_EEH