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: Auger Eric X-Patchwork-Id: 35914 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f198.google.com (mail-ie0-f198.google.com [209.85.223.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 21B2920565 for ; Mon, 25 Aug 2014 13:28:49 +0000 (UTC) Received: by mail-ie0-f198.google.com with SMTP id rl12sf41152387iec.1 for ; Mon, 25 Aug 2014 06:28:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=4l/q6ksuE0M5rdNAkUmMoXSztNlXacHreHZW4H7Z0FY=; b=HB1VXYEEpb0qmDsc1RetKqwVKArn90zN3bWKTk2GA79vz+EiSw58Fp3HoVDycRuBc1 Nv/dUoNRtWgZY47qole6gRWsC87t7qGdwMcdyqqcaFIlH6BOxmwEq4LnwBzYL9Fz473s e1ssXHAFtVq3nhPPf2eucfnFssJMzR30VA4RtpqwsQgrc5icmAoX9+MlINH8DR3wDO5U 1cWXgP6r9VeHcI7QO43Bccnka4qrYrCgGXbn8iT4HVPYj8e0/IFAy/tlI9UKRHPNlLfb 9gnhJ1kva5U7QjiL3+qPFkrqJRm0XpCnhOe0xk/9HwXm9aIeOgl5T4Pi/ruaxiRkw+6W LHXg== X-Gm-Message-State: ALoCoQnUos/WzKz7j7e36qDEvYYY/QsPaAtOQCTqHn39w/Vd8e6LTlp3BT+spNReBaS3IzQY1tx1 X-Received: by 10.182.129.37 with SMTP id nt5mr14116388obb.8.1408973328648; Mon, 25 Aug 2014 06:28:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.246 with SMTP id l109ls2213442qgf.1.gmail; Mon, 25 Aug 2014 06:28:48 -0700 (PDT) X-Received: by 10.220.74.10 with SMTP id s10mr1886264vcj.61.1408973328509; Mon, 25 Aug 2014 06:28:48 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id sf7si17293849vdb.19.2014.08.25.06.28.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Aug 2014 06:28:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ij19so14733692vcb.25 for ; Mon, 25 Aug 2014 06:28:48 -0700 (PDT) X-Received: by 10.52.129.200 with SMTP id ny8mr1715526vdb.27.1408973328443; Mon, 25 Aug 2014 06:28:48 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp117325vcb; Mon, 25 Aug 2014 06:28:47 -0700 (PDT) X-Received: by 10.180.12.239 with SMTP id b15mr15043236wic.75.1408973327291; Mon, 25 Aug 2014 06:28:47 -0700 (PDT) Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by mx.google.com with ESMTPS id hb5si3473910wjc.81.2014.08.25.06.28.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Aug 2014 06:28:47 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.172 as permitted sender) client-ip=209.85.212.172; Received: by mail-wi0-f172.google.com with SMTP id n3so2534585wiv.11 for ; Mon, 25 Aug 2014 06:28:46 -0700 (PDT) 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 Cc: linux-kernel@vger.kernel.org, patches@linaro.org, will.deacon@arm.com, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, john.liuli@huawei.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-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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