From patchwork Sat Feb 22 08:07:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi Liu X-Patchwork-Id: 11397893 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B692C138D for ; Sat, 22 Feb 2020 08:05:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 973E8208C3 for ; Sat, 22 Feb 2020 08:05:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 973E8208C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:39928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5Pms-0007MM-Mu for patchwork-qemu-devel@patchwork.kernel.org; Sat, 22 Feb 2020 03:05:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57457) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5Pjk-0002BC-HO for qemu-devel@nongnu.org; Sat, 22 Feb 2020 03:02:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j5Pji-00081e-Re for qemu-devel@nongnu.org; Sat, 22 Feb 2020 03:02:08 -0500 Received: from mga12.intel.com ([192.55.52.136]:36223) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j5Pji-0007tv-Hy for qemu-devel@nongnu.org; Sat, 22 Feb 2020 03:02:06 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Feb 2020 00:01:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,471,1574150400"; d="scan'208";a="240547665" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga006.jf.intel.com with ESMTP; 22 Feb 2020 00:01:56 -0800 From: Liu Yi L To: qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com Subject: [RFC v3.1 05/22] hw/pci: add pci_device_setup_iommu Date: Sat, 22 Feb 2020 00:07:06 -0800 Message-Id: <1582358843-51931-6-git-send-email-yi.l.liu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1582358843-51931-1-git-send-email-yi.l.liu@intel.com> References: <1582358843-51931-1-git-send-email-yi.l.liu@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.136 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevin.tian@intel.com, yi.l.liu@intel.com, Yi Sun , kvm@vger.kernel.org, mst@redhat.com, jun.j.tian@intel.com, eric.auger@redhat.com, yi.y.sun@intel.com, Jacob Pan , pbonzini@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" HostIOMMUContext was introduced to provide an explicit way for vIOMMU emulators call into pass-through components (e.g. VFIO). vIOMMU needs to get the HostIOMMUContext before using it. This patch adds a new callback in PCIDevice, which would be set by pass-through components, and be used by vIOMMU emulators to get HostIOMMUContext. Cc: Kevin Tian Cc: Jacob Pan Cc: Peter Xu Cc: Eric Auger Cc: Yi Sun Cc: David Gibson Cc: Michael S. Tsirkin Signed-off-by: Liu, Yi L --- hw/pci/pci.c | 10 ++++++++++ include/hw/pci/pci.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index e1ed667..3166cc3 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2695,6 +2695,16 @@ void pci_setup_iommu(PCIBus *bus, PCIIOMMUFunc fn, void *opaque) bus->iommu_opaque = opaque; } +void pci_device_setup_iommu(PCIDevice *dev, PCIHostIOMMUFunc fn) +{ + dev->host_iommu_fn = fn; +} + +void pci_device_unset_iommu(PCIDevice *dev) +{ + dev->host_iommu_fn = NULL; +} + static void pci_dev_get_w64(PCIBus *b, PCIDevice *dev, void *opaque) { Range *range = opaque; diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 2acd832..e44eefb 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -8,6 +8,7 @@ #include "hw/isa/isa.h" #include "hw/pci/pcie.h" +#include "hw/iommu/host_iommu_context.h" extern bool pci_available; @@ -248,6 +249,7 @@ typedef void (*MSIVectorReleaseNotifier)(PCIDevice *dev, unsigned int vector); typedef void (*MSIVectorPollNotifier)(PCIDevice *dev, unsigned int vector_start, unsigned int vector_end); +typedef HostIOMMUContext *(*PCIHostIOMMUFunc)(PCIDevice *); enum PCIReqIDType { PCI_REQ_ID_INVALID = 0, @@ -356,6 +358,8 @@ struct PCIDevice { /* ID of standby device in net_failover pair */ char *failover_pair_id; + /* Callback to get host iommu context */ + PCIHostIOMMUFunc host_iommu_fn; }; void pci_register_bar(PCIDevice *pci_dev, int region_num, @@ -488,6 +492,8 @@ typedef AddressSpace *(*PCIIOMMUFunc)(PCIBus *, void *, int); AddressSpace *pci_device_iommu_address_space(PCIDevice *dev); void pci_setup_iommu(PCIBus *bus, PCIIOMMUFunc fn, void *opaque); +void pci_device_setup_iommu(PCIDevice *dev, PCIHostIOMMUFunc fn); +void pci_device_unset_iommu(PCIDevice *dev); static inline void pci_set_byte(uint8_t *config, uint8_t val)