git: 04e86ae357b2 - main - busdma_iommu: simplify split logic
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 02 Jun 2022 21:04:18 UTC
The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=04e86ae357b21fce238a90f31198b25975d0f479 commit 04e86ae357b21fce238a90f31198b25975d0f479 Author: Doug Moore <dougm@FreeBSD.org> AuthorDate: 2022-06-02 20:59:57 +0000 Commit: Doug Moore <dougm@FreeBSD.org> CommitDate: 2022-06-02 20:59:57 +0000 busdma_iommu: simplify split logic iommu_bus_dmamap_load_something1 includes code for handling the possibility of splitting a buffer that is needlessly complex. Simplify it. Reviewed by: alc, kib MFC after: 3 weeks Tested by: pho (previous revisions) Differential Revision: https://reviews.freebsd.org/D35232 --- sys/dev/iommu/busdma_iommu.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/sys/dev/iommu/busdma_iommu.c b/sys/dev/iommu/busdma_iommu.c index 99d47f0b6ede..ad638e293324 100644 --- a/sys/dev/iommu/busdma_iommu.c +++ b/sys/dev/iommu/busdma_iommu.c @@ -564,15 +564,16 @@ iommu_bus_dmamap_load_something1(struct bus_dma_tag_iommu *tag, struct iommu_ctx *ctx; struct iommu_domain *domain; struct iommu_map_entry *entry; - iommu_gaddr_t size; bus_size_t buflen1; - int error, idx, gas_flags, seg; + int error, e_flags, idx, gas_flags, seg; KASSERT(offset < IOMMU_PAGE_SIZE, ("offset %d", offset)); if (segs == NULL) segs = tag->segments; ctx = tag->ctx; domain = ctx->domain; + e_flags = IOMMU_MAP_ENTRY_READ | + ((flags & BUS_DMA_NOWRITE) == 0 ? IOMMU_MAP_ENTRY_WRITE : 0); seg = *segp; error = 0; idx = 0; @@ -584,7 +585,6 @@ iommu_bus_dmamap_load_something1(struct bus_dma_tag_iommu *tag, } buflen1 = buflen > tag->common.maxsegsz ? tag->common.maxsegsz : buflen; - size = round_page(offset + buflen1); /* * (Too) optimistically allow split if there are more @@ -594,30 +594,14 @@ iommu_bus_dmamap_load_something1(struct bus_dma_tag_iommu *tag, if (seg + 1 < tag->common.nsegments) gas_flags |= IOMMU_MF_CANSPLIT; - error = iommu_map(domain, &tag->common, size, offset, - IOMMU_MAP_ENTRY_READ | - ((flags & BUS_DMA_NOWRITE) == 0 ? IOMMU_MAP_ENTRY_WRITE : 0), - gas_flags, ma + idx, &entry); + error = iommu_map(domain, &tag->common, + round_page(offset + buflen1), + offset, e_flags, gas_flags, ma + idx, &entry); if (error != 0) break; - if ((gas_flags & IOMMU_MF_CANSPLIT) != 0) { - KASSERT(size >= entry->end - entry->start, - ("split increased entry size %jx %jx %jx", - (uintmax_t)size, (uintmax_t)entry->start, - (uintmax_t)entry->end)); - size = entry->end - entry->start; - if (buflen1 > size) - buflen1 = size; - } else { - KASSERT(entry->end - entry->start == size, - ("no split allowed %jx %jx %jx", - (uintmax_t)size, (uintmax_t)entry->start, - (uintmax_t)entry->end)); - } - if (offset + buflen1 > size) - buflen1 = size - offset; - if (buflen1 > tag->common.maxsegsz) - buflen1 = tag->common.maxsegsz; + /* Update buflen1 in case buffer split. */ + if (buflen1 > entry->end - entry->start - offset) + buflen1 = entry->end - entry->start - offset; KASSERT(vm_addr_align_ok(entry->start + offset, tag->common.alignment),