iommu: change iommu_domain_map_ops to take iommu_map_entry
instead of base/size. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
This commit is contained in:
+11
-14
@@ -80,22 +80,21 @@ struct iommu_entry {
|
||||
static LIST_HEAD(, iommu_entry) iommu_list = LIST_HEAD_INITIALIZER(iommu_list);
|
||||
|
||||
static int
|
||||
iommu_domain_unmap_buf(struct iommu_domain *iodom, iommu_gaddr_t base,
|
||||
iommu_gaddr_t size, int flags)
|
||||
iommu_domain_unmap_buf(struct iommu_domain *iodom,
|
||||
struct iommu_map_entry *entry, int flags)
|
||||
{
|
||||
struct iommu_unit *iommu;
|
||||
int error;
|
||||
|
||||
iommu = iodom->iommu;
|
||||
|
||||
error = IOMMU_UNMAP(iommu->dev, iodom, base, size);
|
||||
|
||||
error = IOMMU_UNMAP(iommu->dev, iodom, entry->start, entry->end -
|
||||
entry->start);
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
iommu_domain_map_buf(struct iommu_domain *iodom, iommu_gaddr_t base,
|
||||
iommu_gaddr_t size, vm_page_t *ma, uint64_t eflags, int flags)
|
||||
iommu_domain_map_buf(struct iommu_domain *iodom, struct iommu_map_entry *entry,
|
||||
vm_page_t *ma, uint64_t eflags, int flags)
|
||||
{
|
||||
struct iommu_unit *iommu;
|
||||
vm_prot_t prot;
|
||||
@@ -110,12 +109,10 @@ iommu_domain_map_buf(struct iommu_domain *iodom, iommu_gaddr_t base,
|
||||
if (eflags & IOMMU_MAP_ENTRY_WRITE)
|
||||
prot |= VM_PROT_WRITE;
|
||||
|
||||
va = base;
|
||||
|
||||
va = entry->start;
|
||||
iommu = iodom->iommu;
|
||||
|
||||
error = IOMMU_MAP(iommu->dev, iodom, va, ma, size, prot);
|
||||
|
||||
error = IOMMU_MAP(iommu->dev, iodom, va, ma, entry->end -
|
||||
entry->start, prot);
|
||||
return (error);
|
||||
}
|
||||
|
||||
@@ -427,8 +424,8 @@ iommu_domain_unload(struct iommu_domain *iodom,
|
||||
TAILQ_FOREACH_SAFE(entry, entries, dmamap_link, entry1) {
|
||||
KASSERT((entry->flags & IOMMU_MAP_ENTRY_MAP) != 0,
|
||||
("not mapped entry %p %p", iodom, entry));
|
||||
error = iodom->ops->unmap(iodom, entry->start, entry->end -
|
||||
entry->start, cansleep ? IOMMU_PGF_WAITOK : 0);
|
||||
error = iodom->ops->unmap(iodom, entry,
|
||||
cansleep ? IOMMU_PGF_WAITOK : 0);
|
||||
KASSERT(error == 0, ("unmap %p error %d", iodom, error));
|
||||
TAILQ_REMOVE(entries, entry, dmamap_link);
|
||||
iommu_domain_free_entry(entry, true);
|
||||
|
||||
@@ -86,10 +86,10 @@ struct iommu_unit {
|
||||
};
|
||||
|
||||
struct iommu_domain_map_ops {
|
||||
int (*map)(struct iommu_domain *domain, iommu_gaddr_t base,
|
||||
iommu_gaddr_t size, vm_page_t *ma, uint64_t pflags, int flags);
|
||||
int (*unmap)(struct iommu_domain *domain, iommu_gaddr_t base,
|
||||
iommu_gaddr_t size, int flags);
|
||||
int (*map)(struct iommu_domain *domain, struct iommu_map_entry *entry,
|
||||
vm_page_t *ma, uint64_t pflags, int flags);
|
||||
int (*unmap)(struct iommu_domain *domain, struct iommu_map_entry *entry,
|
||||
int flags);
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -826,8 +826,7 @@ iommu_gas_map(struct iommu_domain *domain,
|
||||
entry->flags |= eflags;
|
||||
IOMMU_DOMAIN_UNLOCK(domain);
|
||||
|
||||
error = domain->ops->map(domain, entry->start,
|
||||
entry->end - entry->start, ma, eflags,
|
||||
error = domain->ops->map(domain, entry, ma, eflags,
|
||||
((flags & IOMMU_MF_CANWAIT) != 0 ? IOMMU_PGF_WAITOK : 0));
|
||||
if (error == ENOMEM) {
|
||||
iommu_domain_unload_entry(entry, true,
|
||||
@@ -868,9 +867,9 @@ iommu_gas_map_region(struct iommu_domain *domain, struct iommu_map_entry *entry,
|
||||
if (entry->end == entry->start)
|
||||
return (0);
|
||||
|
||||
error = domain->ops->map(domain, entry->start,
|
||||
entry->end - entry->start, ma + OFF_TO_IDX(start - entry->start),
|
||||
eflags, ((flags & IOMMU_MF_CANWAIT) != 0 ? IOMMU_PGF_WAITOK : 0));
|
||||
error = domain->ops->map(domain, entry,
|
||||
ma + OFF_TO_IDX(start - entry->start), eflags,
|
||||
((flags & IOMMU_MF_CANWAIT) != 0 ? IOMMU_PGF_WAITOK : 0));
|
||||
if (error == ENOMEM) {
|
||||
iommu_domain_unload_entry(entry, false,
|
||||
(flags & IOMMU_MF_CANWAIT) != 0);
|
||||
@@ -979,8 +978,7 @@ iommu_unmap_msi(struct iommu_ctx *ctx)
|
||||
if (entry == NULL)
|
||||
return;
|
||||
|
||||
domain->ops->unmap(domain, entry->start, entry->end -
|
||||
entry->start, IOMMU_PGF_WAITOK);
|
||||
domain->ops->unmap(domain, entry, IOMMU_PGF_WAITOK);
|
||||
|
||||
iommu_gas_free_space(entry);
|
||||
|
||||
|
||||
@@ -895,8 +895,8 @@ dmar_domain_unload(struct iommu_domain *iodom,
|
||||
TAILQ_FOREACH_SAFE(entry, entries, dmamap_link, entry1) {
|
||||
KASSERT((entry->flags & IOMMU_MAP_ENTRY_MAP) != 0,
|
||||
("not mapped entry %p %p", domain, entry));
|
||||
error = iodom->ops->unmap(iodom, entry->start, entry->end -
|
||||
entry->start, cansleep ? IOMMU_PGF_WAITOK : 0);
|
||||
error = iodom->ops->unmap(iodom, entry,
|
||||
cansleep ? IOMMU_PGF_WAITOK : 0);
|
||||
KASSERT(error == 0, ("unmap %p error %d", domain, error));
|
||||
if (!unit->qi_enabled) {
|
||||
dmar_flush_iotlb_sync(domain, entry->start,
|
||||
|
||||
@@ -462,14 +462,18 @@ dmar_map_buf_locked(struct dmar_domain *domain, iommu_gaddr_t base,
|
||||
}
|
||||
|
||||
static int
|
||||
dmar_map_buf(struct iommu_domain *iodom, iommu_gaddr_t base,
|
||||
iommu_gaddr_t size, vm_page_t *ma, uint64_t eflags, int flags)
|
||||
dmar_map_buf(struct iommu_domain *iodom, struct iommu_map_entry *entry,
|
||||
vm_page_t *ma, uint64_t eflags, int flags)
|
||||
{
|
||||
struct dmar_domain *domain;
|
||||
struct dmar_unit *unit;
|
||||
iommu_gaddr_t base, size;
|
||||
uint64_t pflags;
|
||||
int error;
|
||||
|
||||
base = entry->start;
|
||||
size = entry->end - entry->start;
|
||||
|
||||
pflags = ((eflags & IOMMU_MAP_ENTRY_READ) != 0 ? DMAR_PTE_R : 0) |
|
||||
((eflags & IOMMU_MAP_ENTRY_WRITE) != 0 ? DMAR_PTE_W : 0) |
|
||||
((eflags & IOMMU_MAP_ENTRY_SNOOP) != 0 ? DMAR_PTE_SNP : 0) |
|
||||
@@ -647,8 +651,8 @@ dmar_unmap_buf_locked(struct dmar_domain *domain, iommu_gaddr_t base,
|
||||
}
|
||||
|
||||
static int
|
||||
dmar_unmap_buf(struct iommu_domain *iodom, iommu_gaddr_t base,
|
||||
iommu_gaddr_t size, int flags)
|
||||
dmar_unmap_buf(struct iommu_domain *iodom, struct iommu_map_entry *entry,
|
||||
int flags)
|
||||
{
|
||||
struct dmar_domain *domain;
|
||||
int error;
|
||||
@@ -656,7 +660,8 @@ dmar_unmap_buf(struct iommu_domain *iodom, iommu_gaddr_t base,
|
||||
domain = IODOM2DOM(iodom);
|
||||
|
||||
DMAR_DOMAIN_PGLOCK(domain);
|
||||
error = dmar_unmap_buf_locked(domain, base, size, flags);
|
||||
error = dmar_unmap_buf_locked(domain, entry->start, entry->end -
|
||||
entry->start, flags);
|
||||
DMAR_DOMAIN_PGUNLOCK(domain);
|
||||
return (error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user