From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upg7A-0006y1-SN for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:45:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Upg76-0007DU-1Y for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:45:32 -0400 Received: from mail-ee0-x22d.google.com ([2a00:1450:4013:c00::22d]:40173) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upg75-0007DM-QK for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:45:27 -0400 Received: by mail-ee0-f45.google.com with SMTP id c1so3995116eek.4 for ; Thu, 20 Jun 2013 07:45:27 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 20 Jun 2013 16:44:41 +0200 Message-Id: <1371739493-10187-14-git-send-email-pbonzini@redhat.com> In-Reply-To: <1371739493-10187-1-git-send-email-pbonzini@redhat.com> References: <1371739493-10187-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 13/25] memory: Add iommu map/unmap notifiers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: 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 Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 32 ++++++++++++++++++++++++++++++++ memory.c | 18 ++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index a5e7721..75fa2b6 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) @@ -173,6 +174,7 @@ struct MemoryRegion { uint8_t dirty_log_mask; unsigned ioeventfd_nb; MemoryRegionIoeventfd *ioeventfds; + NotifierList iommu_notify; }; struct MemoryRegionPortio { @@ -424,6 +426,36 @@ static inline bool memory_region_is_romd(MemoryRegion *mr) bool memory_region_is_iommu(MemoryRegion *mr); /** + * memory_region_notify_iommu: notify a change in an IOMMU translation entry. + * + * @mr: the memory region that was changed + * @entry: the new entry in the IOMMU translation table. The entry + * replaces all old entries for the same virtual I/O address range. + * Deleted entries have .@perm == 0. + */ +void memory_region_notify_iommu(MemoryRegion *mr, + IOMMUTLBEntry entry); + +/** + * memory_region_register_iommu_notifier: register a notifier for changes to + * IOMMU translation entries. + * + * @mr: the memory region to observe + * @n: the notifier to be added; the notifier receives a pointer to an + * #IOMMUTLBEntry as the opaque value; the pointer ceases to be + * valid on exit from the notifier. + */ +void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n); + +/** + * memory_region_unregister_iommu_notifier: unregister a notifier for + * changes to IOMMU translation entries. + * + * @n: the notifier to be removed. + */ +void memory_region_unregister_iommu_notifier(Notifier *n); + +/** * memory_region_name: get a memory region's name * * Returns the string that was used to initialize the memory region. diff --git a/memory.c b/memory.c index 7eb8d46..2a94d7d 100644 --- a/memory.c +++ b/memory.c @@ -1072,6 +1072,7 @@ void memory_region_init_iommu(MemoryRegion *mr, memory_region_init(mr, name, size); mr->iommu_ops = ops, mr->terminates = true; /* then re-forwards */ + notifier_list_init(&mr->iommu_notify); } void memory_region_init_reservation(MemoryRegion *mr, @@ -1124,6 +1125,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