git: bdd5eb33cacd - main - iommu: change iommu_domain_map_ops to take iommu_map_entry
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 27 Sep 2024 17:34:46 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=bdd5eb33cacdbf174980b999c77847d0903fc12e
commit bdd5eb33cacdbf174980b999c77847d0903fc12e
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-09-25 01:47:54 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-09-27 17:34:23 +0000
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
---
sys/arm64/iommu/iommu.c | 25 +++++++++++--------------
sys/dev/iommu/iommu.h | 8 ++++----
sys/dev/iommu/iommu_gas.c | 12 +++++-------
sys/x86/iommu/intel_ctx.c | 4 ++--
sys/x86/iommu/intel_idpgtbl.c | 15 ++++++++++-----
5 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/sys/arm64/iommu/iommu.c b/sys/arm64/iommu/iommu.c
index e7b5b2298e26..0fe59c5d10b6 100644
--- a/sys/arm64/iommu/iommu.c
+++ b/sys/arm64/iommu/iommu.c
@@ -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);
diff --git a/sys/dev/iommu/iommu.h b/sys/dev/iommu/iommu.h
index 957d4e14e8e2..84d8c3680b71 100644
--- a/sys/dev/iommu/iommu.h
+++ b/sys/dev/iommu/iommu.h
@@ -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);
};
/*
diff --git a/sys/dev/iommu/iommu_gas.c b/sys/dev/iommu/iommu_gas.c
index 4b6141b981da..26ac38da3c4f 100644
--- a/sys/dev/iommu/iommu_gas.c
+++ b/sys/dev/iommu/iommu_gas.c
@@ -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);
diff --git a/sys/x86/iommu/intel_ctx.c b/sys/x86/iommu/intel_ctx.c
index 659d5c8a35e6..5af5ac7335b8 100644
--- a/sys/x86/iommu/intel_ctx.c
+++ b/sys/x86/iommu/intel_ctx.c
@@ -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,
diff --git a/sys/x86/iommu/intel_idpgtbl.c b/sys/x86/iommu/intel_idpgtbl.c
index 7def178146d1..ffb4c73a6c5a 100644
--- a/sys/x86/iommu/intel_idpgtbl.c
+++ b/sys/x86/iommu/intel_idpgtbl.c
@@ -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);
}