git: 3532bcd282b3 - main - Fix a coherent bus check in the arm64 busdma

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Wed, 06 Apr 2022 13:24:01 UTC
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=3532bcd282b3ba508f0b39560626983463512813

commit 3532bcd282b3ba508f0b39560626983463512813
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-04-04 09:28:59 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-04-06 13:11:12 +0000

    Fix a coherent bus check in the arm64 busdma
    
    In the arm64 busdma we have an internal flag to signal when a tag is
    for a cache-coherent device. In this case we don't need to adjust the
    size and alignment of allocated buffers to be within a cache line.
    
    The cache line adjustment was incorrectly using the coherent flag
    passed in to bus_dma_tag_create and not the internal flag. Fix it to
    use the latter to reduce the memory usage slightly.
    
    Reviewed by:    bz
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D34763
---
 sys/arm64/arm64/busdma_bounce.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/sys/arm64/arm64/busdma_bounce.c b/sys/arm64/arm64/busdma_bounce.c
index 0f17fdb9bffc..afaa1ef8510d 100644
--- a/sys/arm64/arm64/busdma_bounce.c
+++ b/sys/arm64/arm64/busdma_bounce.c
@@ -228,6 +228,18 @@ bounce_bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
 
 	if ((flags & BUS_DMA_COHERENT) != 0) {
 		newtag->bounce_flags |= BF_COHERENT;
+	}
+
+	if (parent != NULL) {
+		if ((newtag->common.filter != NULL ||
+		    (parent->bounce_flags & BF_COULD_BOUNCE) != 0))
+			newtag->bounce_flags |= BF_COULD_BOUNCE;
+
+		/* Copy some flags from the parent */
+		newtag->bounce_flags |= parent->bounce_flags & BF_COHERENT;
+	}
+
+	if ((newtag->bounce_flags & BF_COHERENT) != 0) {
 		newtag->alloc_alignment = newtag->common.alignment;
 		newtag->alloc_size = newtag->common.maxsize;
 	} else {
@@ -243,15 +255,6 @@ bounce_bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
 		    dcache_line_size);
 	}
 
-	if (parent != NULL) {
-		if ((newtag->common.filter != NULL ||
-		    (parent->bounce_flags & BF_COULD_BOUNCE) != 0))
-			newtag->bounce_flags |= BF_COULD_BOUNCE;
-
-		/* Copy some flags from the parent */
-		newtag->bounce_flags |= parent->bounce_flags & BF_COHERENT;
-	}
-
 	if (newtag->common.lowaddr < ptoa((vm_paddr_t)Maxmem) ||
 	    newtag->common.alignment > 1)
 		newtag->bounce_flags |= BF_COULD_BOUNCE;