mirror of https://github.com/xemu-project/xemu.git
memory: Add iommu map/unmap notifiers
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 <david@gibson.dropbear.id.au> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
3095115744
commit
068665757d
|
@ -25,6 +25,7 @@
|
||||||
#include "exec/iorange.h"
|
#include "exec/iorange.h"
|
||||||
#include "exec/ioport.h"
|
#include "exec/ioport.h"
|
||||||
#include "qemu/int128.h"
|
#include "qemu/int128.h"
|
||||||
|
#include "qemu/notify.h"
|
||||||
|
|
||||||
#define MAX_PHYS_ADDR_SPACE_BITS 62
|
#define MAX_PHYS_ADDR_SPACE_BITS 62
|
||||||
#define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
|
#define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1)
|
||||||
|
@ -173,6 +174,7 @@ struct MemoryRegion {
|
||||||
uint8_t dirty_log_mask;
|
uint8_t dirty_log_mask;
|
||||||
unsigned ioeventfd_nb;
|
unsigned ioeventfd_nb;
|
||||||
MemoryRegionIoeventfd *ioeventfds;
|
MemoryRegionIoeventfd *ioeventfds;
|
||||||
|
NotifierList iommu_notify;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MemoryRegionPortio {
|
struct MemoryRegionPortio {
|
||||||
|
@ -423,6 +425,36 @@ static inline bool memory_region_is_romd(MemoryRegion *mr)
|
||||||
*/
|
*/
|
||||||
bool memory_region_is_iommu(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
|
* memory_region_name: get a memory region's name
|
||||||
*
|
*
|
||||||
|
|
18
memory.c
18
memory.c
|
@ -1072,6 +1072,7 @@ void memory_region_init_iommu(MemoryRegion *mr,
|
||||||
memory_region_init(mr, name, size);
|
memory_region_init(mr, name, size);
|
||||||
mr->iommu_ops = ops,
|
mr->iommu_ops = ops,
|
||||||
mr->terminates = true; /* then re-forwards */
|
mr->terminates = true; /* then re-forwards */
|
||||||
|
notifier_list_init(&mr->iommu_notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
void memory_region_init_reservation(MemoryRegion *mr,
|
void memory_region_init_reservation(MemoryRegion *mr,
|
||||||
|
@ -1124,6 +1125,23 @@ bool memory_region_is_iommu(MemoryRegion *mr)
|
||||||
return mr->iommu_ops;
|
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)
|
void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client)
|
||||||
{
|
{
|
||||||
uint8_t mask = 1 << client;
|
uint8_t mask = 1 << client;
|
||||||
|
|
Loading…
Reference in New Issue