From nobody Sun Feb 8 22:34:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511514840531156.5173119042014; Fri, 24 Nov 2017 01:14:00 -0800 (PST) Received: from localhost ([::1]:48118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eIA3V-0007fY-7g for importer@patchew.org; Fri, 24 Nov 2017 04:13:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eI9zK-00043T-Tf for qemu-devel@nongnu.org; Fri, 24 Nov 2017 04:09:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eI9zG-0000Ge-DD for qemu-devel@nongnu.org; Fri, 24 Nov 2017 04:09:34 -0500 Received: from mga14.intel.com ([192.55.52.115]:26004) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eI9zG-00006q-4p for qemu-devel@nongnu.org; Fri, 24 Nov 2017 04:09:30 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Nov 2017 01:09:29 -0800 Received: from sky-dev.bj.intel.com ([10.238.144.127]) by orsmga005.jf.intel.com with ESMTP; 24 Nov 2017 01:09:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,446,1505804400"; d="scan'208";a="177227734" From: "Liu, Yi L" To: qemu-devel@nongnu.org, mst@redhat.com, david@gibson.dropbear.id.au Date: Fri, 24 Nov 2017 16:52:37 +0800 Message-Id: <1511513560-28611-5-git-send-email-yi.l.liu@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1511513560-28611-1-git-send-email-yi.l.liu@linux.intel.com> References: <1511513560-28611-1-git-send-email-yi.l.liu@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.115 Subject: [Qemu-devel] [PATCH v2 4/7] memory: introduce AddressSpaceOps X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tianyu.lan@intel.com, "Liu, Yi L" , kevin.tian@intel.com, yi.l.liu@intel.com, jasowang@redhat.com, peterx@redhat.com, alex.williamson@redhat.com, pbonzini@redhat.com, eric.auger.pro@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu This patch is going to introduce AddressSpaceOps which is to link an AddressSpace to the IOMMU abstraction behind it. The basic idea here is to associate an IOMMUObject with an AddressSpace. This is still an open so far. Needs to have more inputs on it. Here is my thoughts, and any other idea is welcomed. For systems with IOMMU, the DMA isolation is introduced, the isolation may be multiple DMA AddressSpaces or multiple DMA windows. Without IOMMU, the DMA AddressSpace would be a single and shared address space across the system. So if IOMMU exists, a DMA AddressSpace should always has an IOMMU abstract behind it. This IOMMU abstract may mean the AddressSpace is an individual isolation space or the AddressSpace is divided into multiple DMA windows. So my thought is getting the IOMMU abstract by AddressSpaceOps. And the IOMMU abstract is the new IOMMUObject introduced in this patchset. The first AddressSpaceOps added here is iommu_get(). Return an IOMMUObject behind the AddressSpace. Signed-off-by: Peter Xu Signed-off-by: Liu, Yi L --- include/exec/memory.h | 22 ++++++++++++++++++++++ memory.c | 10 ++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 03595e3..8350973 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -26,6 +26,7 @@ #include "qom/object.h" #include "qemu/rcu.h" #include "hw/qdev-core.h" +#include "hw/core/iommu.h" =20 #define RAM_ADDR_INVALID (~(ram_addr_t)0) =20 @@ -301,6 +302,19 @@ struct MemoryListener { }; =20 /** + * AddressSpaceOps: callbacks structure for address space specific operati= ons + * + * @iommu_get: returns an IOMMU object that backs the address space. + * Normally this should be NULL for generic address + * spaces, and it's only used when there is one + * translation unit behind this address space. + */ +struct AddressSpaceOps { + IOMMUObject *(*iommu_get)(AddressSpace *as); +}; +typedef struct AddressSpaceOps AddressSpaceOps; + +/** * AddressSpace: describes a mapping of addresses to #MemoryRegion objects */ struct AddressSpace { @@ -316,6 +330,7 @@ struct AddressSpace { struct MemoryRegionIoeventfd *ioeventfds; QTAILQ_HEAD(memory_listeners_as, MemoryListener) listeners; QTAILQ_ENTRY(AddressSpace) address_spaces_link; + AddressSpaceOps as_ops; }; =20 FlatView *address_space_to_flatview(AddressSpace *as); @@ -1988,6 +2003,13 @@ address_space_write_cached(MemoryRegionCache *cache,= hwaddr addr, address_space_write(cache->as, cache->xlat + addr, MEMTXATTRS_UNSPECIF= IED, buf, len); } =20 +/** + * address_space_iommu_get: Get the backend IOMMU for the address space + * + * @as: the address space to fetch IOMMU from + */ +IOMMUObject *address_space_iommu_get(AddressSpace *as); + #endif =20 #endif diff --git a/memory.c b/memory.c index 77fb3ef..307f665 100644 --- a/memory.c +++ b/memory.c @@ -235,8 +235,6 @@ struct FlatView { MemoryRegion *root; }; =20 -typedef struct AddressSpaceOps AddressSpaceOps; - #define FOR_EACH_FLAT_RANGE(var, view) \ for (var =3D (view)->ranges; var < (view)->ranges + (view)->nr; ++var) =20 @@ -2793,6 +2791,14 @@ static void do_address_space_destroy(AddressSpace *a= s) memory_region_unref(as->root); } =20 +IOMMUObject *address_space_iommu_get(AddressSpace *as) +{ + if (!as->as_ops.iommu_get) { + return NULL; + } + return as->as_ops.iommu_get(as); +} + void address_space_destroy(AddressSpace *as) { MemoryRegion *root =3D as->root; --=20 1.9.1