Module Name:    src
Committed By:   thorpej
Date:           Sun Jul 18 05:12:27 UTC 2021

Modified Files:
        src/sys/arch/alpha/common: sgmap_common.c sgmap_typedep.c
        src/sys/arch/alpha/include: bus_defs.h
        src/sys/arch/alpha/tc: tc_dma.c tc_dma_3000_500.c

Log Message:
Allow for the SGMAP implementation to specify a minimum alignment for
SGMAP DMA segments.  If not specified, PAGE_SIZE will be used, as before.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/alpha/common/sgmap_common.c
cvs rdiff -u -r1.42 -r1.43 src/sys/arch/alpha/common/sgmap_typedep.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/alpha/include/bus_defs.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/alpha/tc/tc_dma.c
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/alpha/tc/tc_dma_3000_500.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/common/sgmap_common.c
diff -u src/sys/arch/alpha/common/sgmap_common.c:1.28 src/sys/arch/alpha/common/sgmap_common.c:1.29
--- src/sys/arch/alpha/common/sgmap_common.c:1.28	Sun Jul  4 22:42:35 2021
+++ src/sys/arch/alpha/common/sgmap_common.c	Sun Jul 18 05:12:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_common.c,v 1.28 2021/07/04 22:42:35 thorpej Exp $ */
+/* $NetBSD: sgmap_common.c,v 1.29 2021/07/18 05:12:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: sgmap_common.c,v 1.28 2021/07/04 22:42:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sgmap_common.c,v 1.29 2021/07/18 05:12:27 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -68,6 +68,14 @@ alpha_sgmap_init(bus_dma_tag_t t, struct
 		goto die;
 	}
 
+	/*
+	 * If we don't yet have a minimum SGVA alignment, default
+	 * to the system page size.
+	 */
+	if (t->_sgmap_minalign < PAGE_SIZE) {
+		t->_sgmap_minalign = PAGE_SIZE;
+	}
+
 	sgmap->aps_wbase = wbase;
 	sgmap->aps_sgvabase = sgvabase;
 	sgmap->aps_sgvasize = sgvasize;

Index: src/sys/arch/alpha/common/sgmap_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.42 src/sys/arch/alpha/common/sgmap_typedep.c:1.43
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.42	Thu Jun 24 16:41:16 2021
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Sun Jul 18 05:12:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.42 2021/06/24 16:41:16 thorpej Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.43 2021/07/18 05:12:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.42 2021/06/24 16:41:16 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.43 2021/07/18 05:12:27 thorpej Exp $");
 
 #include "opt_ddb.h"
 
@@ -130,7 +130,8 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	const vm_flag_t vmflags = VM_INSTANTFIT |
 	    ((flags & BUS_DMA_NOWAIT) ? VM_NOSLEEP : VM_SLEEP);
 
-	alignment = PAGE_SIZE;
+	KASSERT(t->_sgmap_minalign != 0);
+	alignment = t->_sgmap_minalign;
 	sgvalen = (endva - va);
 
 	SGMAP_PTE_TYPE spill_pte_v = __C(SGMAP_TYPE,_prefetch_spill_page_pte);
@@ -193,13 +194,16 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 		 * ARGH!  If the addition of the spill page bumped us
 		 * over our boundary, we have to 2x the boundary limit.
 		 * To compensate (and enforce the original boundary
-		 * constraint), we force our alignment to be the previous
-		 * boundary, thus ensuring that the only boundary violation
-		 * is the pre-fetch that the SGMAP controller performs that
-		 * necessitates the spill page in the first place.
+		 * constraint), we force our alignment to be at least the
+		 * previous boundary, thus ensuring that the only boundary
+		 * violation is the pre-fetch that the SGMAP controller
+		 * performs that necessitates the spill page in the first
+		 * place.
 		 */
 		if (boundary && boundary < sgvalen) {
-			alignment = boundary;
+			if (alignment < boundary) {
+				alignment = boundary;
+			}
 			do {
 				boundary <<= 1;
 			} while (boundary < sgvalen);

Index: src/sys/arch/alpha/include/bus_defs.h
diff -u src/sys/arch/alpha/include/bus_defs.h:1.5 src/sys/arch/alpha/include/bus_defs.h:1.6
--- src/sys/arch/alpha/include/bus_defs.h:1.5	Mon Sep 23 16:17:54 2019
+++ src/sys/arch/alpha/include/bus_defs.h	Sun Jul 18 05:12:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_defs.h,v 1.5 2019/09/23 16:17:54 skrll Exp $ */
+/* $NetBSD: bus_defs.h,v 1.6 2021/07/18 05:12:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -364,6 +364,12 @@ struct alpha_bus_dma_tag {
 	struct alpha_sgmap *_sgmap;
 
 	/*
+	 * Some chipsets may want to enforce a minimum alignment
+	 * constraint for SGMAP DMA addresses.
+	 */
+	bus_size_t _sgmap_minalign;
+
+	/*
 	 * The SGMAP MMU implements a prefetch FIFO to keep data
 	 * moving down the pipe, when doing host->bus DMA writes.
 	 * The threshold (distance until the next page) used to

Index: src/sys/arch/alpha/tc/tc_dma.c
diff -u src/sys/arch/alpha/tc/tc_dma.c:1.14 src/sys/arch/alpha/tc/tc_dma.c:1.15
--- src/sys/arch/alpha/tc/tc_dma.c:1.14	Sat Oct 10 21:59:03 2020
+++ src/sys/arch/alpha/tc/tc_dma.c	Sun Jul 18 05:12:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tc_dma.c,v 1.14 2020/10/10 21:59:03 thorpej Exp $ */
+/* $NetBSD: tc_dma.c,v 1.15 2021/07/18 05:12:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: tc_dma.c,v 1.14 2020/10/10 21:59:03 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tc_dma.c,v 1.15 2021/07/18 05:12:27 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -49,6 +49,7 @@ struct alpha_bus_dma_tag tc_dmat_direct 
 	NULL,				/* _next_window */
 	0,				/* _boundary */
 	NULL,				/* _sgmap */
+	0,				/* _sgmap_minalign */
 	0,				/* _pfthresh */
 	NULL,				/* _get_tag */
 	_bus_dmamap_create,

Index: src/sys/arch/alpha/tc/tc_dma_3000_500.c
diff -u src/sys/arch/alpha/tc/tc_dma_3000_500.c:1.23 src/sys/arch/alpha/tc/tc_dma_3000_500.c:1.24
--- src/sys/arch/alpha/tc/tc_dma_3000_500.c:1.23	Wed Nov 18 02:04:30 2020
+++ src/sys/arch/alpha/tc/tc_dma_3000_500.c	Sun Jul 18 05:12:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tc_dma_3000_500.c,v 1.23 2020/11/18 02:04:30 thorpej Exp $ */
+/* $NetBSD: tc_dma_3000_500.c,v 1.24 2021/07/18 05:12:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: tc_dma_3000_500.c,v 1.23 2020/11/18 02:04:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tc_dma_3000_500.c,v 1.24 2021/07/18 05:12:27 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -54,6 +54,7 @@ struct alpha_bus_dma_tag tc_dmat_sgmap =
 	NULL,				/* _next_window */
 	0,				/* _boundary */
 	NULL,				/* _sgmap */
+	PAGE_SIZE,			/* _sgmap_minalign */
 	0,				/* _pfthresh */
 	NULL,				/* _get_tag */
 	tc_bus_dmamap_create_sgmap,

Reply via email to