From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:45171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UekGx-0004yx-BJ for qemu-devel@nongnu.org; Tue, 21 May 2013 06:58:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UekGv-0005X6-3V for qemu-devel@nongnu.org; Tue, 21 May 2013 06:58:27 -0400 Received: from mail-ea0-x229.google.com ([2a00:1450:4013:c01::229]:43799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UekGu-0005Wm-TL for qemu-devel@nongnu.org; Tue, 21 May 2013 06:58:25 -0400 Received: by mail-ea0-f169.google.com with SMTP id m14so307199eaj.28 for ; Tue, 21 May 2013 03:58:24 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 21 May 2013 12:57:22 +0200 Message-Id: <1369133851-1894-22-git-send-email-pbonzini@redhat.com> In-Reply-To: <1369133851-1894-1-git-send-email-pbonzini@redhat.com> References: <1369133851-1894-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 21/30] memory: Add iommu map/unmap notifiers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, jan.kiszka@gmail.com, David Gibson From: David Gibson This patch adds a NotifierList to MemoryRegions which represent IOMMUs allowing other parts of the code to register interest in mappings or unmappings from the IOMMU. All IOMMU implementations will need to call memory_region_notify_iommu() to inform those waiting on the notifier list, whenever an IOMMU mapping is made or removed. Signed-off-by: David Gibson --- include/exec/memory.h | 7 +++++++ memory.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index e5cad03..05b9bb2 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -25,6 +25,7 @@ #include "exec/iorange.h" #include "exec/ioport.h" #include "qemu/int128.h" +#include "qemu/notify.h" #define MAX_PHYS_ADDR_SPACE_BITS 62 #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1) @@ -172,6 +173,7 @@ struct MemoryRegion { unsigned ioeventfd_nb; MemoryRegionIoeventfd *ioeventfds; struct AddressSpace *iommu_target_as; + NotifierList iommu_notify; }; struct MemoryRegionPortio { @@ -423,6 +425,11 @@ static inline bool memory_region_is_romd(MemoryRegion *mr) */ bool memory_region_is_iommu(MemoryRegion *mr); +void memory_region_notify_iommu(MemoryRegion *mr, + IOMMUTLBEntry entry); +void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n); +void memory_region_unregister_iommu_notifier(Notifier *n); + /** * memory_region_name: get a memory region's name * diff --git a/memory.c b/memory.c index b25d21d..e3970bf 100644 --- a/memory.c +++ b/memory.c @@ -991,6 +991,7 @@ void memory_region_init_iommu(MemoryRegion *mr, mr->terminates = true; /* then re-forwards */ mr->destructor = memory_region_destructor_none; mr->iommu_target_as = target_as; + notifier_list_init(&mr->iommu_notify); } static uint64_t invalid_read(void *opaque, hwaddr addr, @@ -1072,6 +1073,23 @@ bool memory_region_is_iommu(MemoryRegion *mr) return mr->iommu_ops; } +void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n) +{ + notifier_list_add(&mr->iommu_notify, n); +} + +void memory_region_unregister_iommu_notifier(Notifier *n) +{ + notifier_remove(n); +} + +void memory_region_notify_iommu(MemoryRegion *mr, + IOMMUTLBEntry entry) +{ + assert(memory_region_is_iommu(mr)); + notifier_list_notify(&mr->iommu_notify, &entry); +} + void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) { uint8_t mask = 1 << client; -- 1.8.1.4