From patchwork Thu Apr 27 09:34:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 755921 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wDBk76kQBz9s8V for ; Thu, 27 Apr 2017 19:39:43 +1000 (AEST) Received: from localhost ([::1]:59641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3fth-0006xw-Gx for incoming@patchwork.ozlabs.org; Thu, 27 Apr 2017 05:39:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3fpt-0003x3-CN for qemu-devel@nongnu.org; Thu, 27 Apr 2017 05:35:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3fps-0004Np-44 for qemu-devel@nongnu.org; Thu, 27 Apr 2017 05:35:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42780) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3fpr-0004MV-Rl for qemu-devel@nongnu.org; Thu, 27 Apr 2017 05:35:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BAE6B3DBE8; Thu, 27 Apr 2017 09:35:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BAE6B3DBE8 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=peterx@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BAE6B3DBE8 Received: from pxdev.xzpeter.org.com (ovpn-8-65.pek2.redhat.com [10.72.8.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDF1F17180; Thu, 27 Apr 2017 09:35:32 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 27 Apr 2017 17:34:18 +0800 Message-Id: <1493285660-4470-7-git-send-email-peterx@redhat.com> In-Reply-To: <1493285660-4470-1-git-send-email-peterx@redhat.com> References: <1493285660-4470-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 27 Apr 2017 09:35:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 6/8] 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, kevin.tian@intel.com, yi.l.liu@intel.com, Jason Wang , peterx@redhat.com, Alex Williamson , Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This is something similar to MemoryRegionOps, it's just for address spaces to store arch-specific hooks. The first hook I would like to introduce is iommu_get(). For systems that have IOMMUs, we will create a special address space per device which is different from system default address space for it (please refer to pci_device_iommu_address_space()). Normally when that happens, there will be one specific IOMMU (or say, translation unit) stands right behind that new address space. This iommu_get() fetches that guy behind the address space. Here, the guy is defined as IOMMUObject, which is currently a (void *). In the future, maybe we can make it a better definition, but imho it's good enough for now, considering it's arch-dependent. Signed-off-by: Peter Xu --- include/exec/memory.h | 30 ++++++++++++++++++++++++++++++ memory.c | 8 ++++++++ 2 files changed, 38 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index e5707b3..0b0b58b 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -183,6 +183,15 @@ struct MemoryRegionOps { const MemoryRegionMmio old_mmio; }; +/* + * This stands for an IOMMU unit. Normally it should be exactly the + * IOMMU device, however this can also be actually anything which is + * related to that translation unit. What it is should be totally + * arch-dependent. Maybe one day we can have something better than a + * (void *) here. + */ +typedef void *IOMMUObject; + typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps; struct MemoryRegionIOMMUOps { @@ -282,6 +291,19 @@ struct MemoryListener { }; /** + * AddressSpaceOps: callbacks structure for address space specific operations + * + * @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 { @@ -302,6 +324,7 @@ struct AddressSpace { MemoryListener dispatch_listener; QTAILQ_HEAD(memory_listeners_as, MemoryListener) listeners; QTAILQ_ENTRY(AddressSpace) address_spaces_link; + AddressSpaceOps as_ops; }; /** @@ -1800,6 +1823,13 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr, address_space_write(cache->as, cache->xlat + addr, MEMTXATTRS_UNSPECIFIED, buf, len); } +/** + * 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 #endif diff --git a/memory.c b/memory.c index 6af523e..6aaad45 100644 --- a/memory.c +++ b/memory.c @@ -2500,6 +2500,14 @@ void address_space_destroy(AddressSpace *as) call_rcu(as, do_address_space_destroy, rcu); } +IOMMUObject *address_space_iommu_get(AddressSpace *as) +{ + if (!as->as_ops.iommu_get) { + return NULL; + } + return as->as_ops.iommu_get(as); +} + static const char *memory_region_type(MemoryRegion *mr) { if (memory_region_is_ram_device(mr)) {