From nobody Mon Oct 13 23:19:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1582358747; cv=none; d=zohomail.com; s=zohoarc; b=jWaNxXoqDMNLjo3FCmR17hDsdr49fFJ79E9Jrb/5weie2y6nUwaClOzlPEzo7eUmsVuqA8JYFgzmTVlh445r6BoQV612T5Fav/llccDqiilfPecI/ijivO5yCpIIHrE0Q5BO3hukJUrqPXMxONCNcP0at8UMFaGAjWCMnXgIqbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582358747; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=uTrQCCIOc4B5KPVfvsMG0ztdNmvxX1V95Oy/73R9piU=; b=IZAr15n2/nhtb48lnqQWzyt93KbcwQcCZfuRY0geCmuHO1MacY6JwQpUCn+Xi5UgoDhu2LvdLtv9J7APaxFQ7q/mb8F/W2MoKO7lSNE1q8b3KoBwgad9mJGpzKZzUEayZtTeepZi8AA3wwBYocHUNT9yZwBZnVsPGIvWqf0lUUU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582358747825538.6965257407528; Sat, 22 Feb 2020 00:05:47 -0800 (PST) Received: from localhost ([::1]:39928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5PnG-0007MM-Pe for importer@patchew.org; Sat, 22 Feb 2020 03:05:46 -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 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 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 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,471,1574150400"; d="scan'208";a="240547665" 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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, v= oid *opaque) bus->iommu_opaque =3D opaque; } =20 +void pci_device_setup_iommu(PCIDevice *dev, PCIHostIOMMUFunc fn) +{ + dev->host_iommu_fn =3D fn; +} + +void pci_device_unset_iommu(PCIDevice *dev) +{ + dev->host_iommu_fn =3D NULL; +} + static void pci_dev_get_w64(PCIBus *b, PCIDevice *dev, void *opaque) { Range *range =3D 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" =20 #include "hw/pci/pcie.h" +#include "hw/iommu/host_iommu_context.h" =20 extern bool pci_available; =20 @@ -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 *); =20 enum PCIReqIDType { PCI_REQ_ID_INVALID =3D 0, @@ -356,6 +358,8 @@ struct PCIDevice { =20 /* ID of standby device in net_failover pair */ char *failover_pair_id; + /* Callback to get host iommu context */ + PCIHostIOMMUFunc host_iommu_fn; }; =20 void pci_register_bar(PCIDevice *pci_dev, int region_num, @@ -488,6 +492,8 @@ typedef AddressSpace *(*PCIIOMMUFunc)(PCIBus *, void *,= int); =20 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); =20 static inline void pci_set_byte(uint8_t *config, uint8_t val) --=20 2.7.4