Module Name:    src
Committed By:   thorpej
Date:           Wed Jun 17 04:12:39 UTC 2020

Modified Files:
        src/sys/arch/alpha/common: sgmap_common.c sgmap_typedep.c sgmapvar.h

Log Message:
Switch from an extent mao to a vmem arena to manage SGMAP address space.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/alpha/common/sgmap_common.c
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/alpha/common/sgmap_typedep.c
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/alpha/common/sgmapvar.h

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.26 src/sys/arch/alpha/common/sgmap_common.c:1.27
--- src/sys/arch/alpha/common/sgmap_common.c:1.26	Fri Jan 27 18:52:48 2012
+++ src/sys/arch/alpha/common/sgmap_common.c	Wed Jun 17 04:12:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_common.c,v 1.26 2012/01/27 18:52:48 para Exp $ */
+/* $NetBSD: sgmap_common.c,v 1.27 2020/06/17 04:12:39 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.26 2012/01/27 18:52:48 para Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sgmap_common.c,v 1.27 2020/06/17 04:12:39 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -103,16 +103,22 @@ alpha_sgmap_init(bus_dma_tag_t t, struct
 	}
 
 	/*
-	 * Create the extent map used to manage the virtual address
+	 * Create the arena used to manage the virtual address
 	 * space.
+	 *
+	 * XXX Consider using a quantum cache up to MAXPHYS+PAGE_SIZE
+	 * XXX (extra page to handle the spill page).  For now, we don't,
+	 * XXX because we are using constrained allocations everywhere.
 	 */
-	sgmap->aps_ex = extent_create(name, sgvabase, sgvasize - 1,
-	    NULL, 0, EX_NOWAIT|EX_NOCOALESCE);
-	if (sgmap->aps_ex == NULL) {
-		printf("unable to create extent map for sgmap `%s'\n",
-		    name);
-		goto die;
-	}
+	sgmap->aps_arena = vmem_create(name, sgvabase, sgvasize,
+				       PAGE_SIZE,	/* quantum */
+				       NULL,		/* importfn */
+				       NULL,		/* releasefn */
+				       NULL,		/* source */
+				       0,		/* qcache_max */
+				       VM_SLEEP,
+				       IPL_VM);
+	KASSERT(sgmap->aps_arena != NULL);
 
 	/*
 	 * Allocate a spill page if that hasn't already been done.

Index: src/sys/arch/alpha/common/sgmap_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.37 src/sys/arch/alpha/common/sgmap_typedep.c:1.38
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.37	Wed Dec 15 01:28:24 2010
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Wed Jun 17 04:12:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.37 2010/12/15 01:28:24 matt Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.38 2020/06/17 04:12:39 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.37 2010/12/15 01:28:24 matt Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.38 2020/06/17 04:12:39 thorpej Exp $");
 
 #include "opt_ddb.h"
 
@@ -66,7 +66,7 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	bus_addr_t dmaoffset, sgva;
 	bus_size_t sgvalen, boundary, alignment;
 	SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt;
-	int s, pteidx, error, spill;
+	int pteidx, error, spill;
 
 	/* Initialize the spill page PTE if it hasn't been already. */
 	if (__C(SGMAP_TYPE,_prefetch_spill_page_pte) == 0)
@@ -131,10 +131,17 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	}
 #endif
 
-	s = splvm();
-	error = extent_alloc(sgmap->aps_ex, sgvalen, alignment, boundary,
-	    (flags & BUS_DMA_NOWAIT) ? EX_NOWAIT : EX_WAITOK, &sgva);
-	splx(s);
+	const vm_flag_t vmflags = VM_INSTANTFIT |
+	    ((flags & BUS_DMA_NOWAIT) ? VM_SLEEP : VM_NOSLEEP);
+
+	error = vmem_xalloc(sgmap->aps_arena, sgvalen,
+			    alignment,		/* alignment */
+			    0,			/* phase */
+			    boundary,		/* nocross */
+			    VMEM_ADDR_MIN,	/* minaddr */
+			    VMEM_ADDR_MAX,	/* maxaddr */
+			    vmflags,
+			    &sgva);
 	if (error)
 		return (error);
 
@@ -395,7 +402,7 @@ __C(SGMAP_TYPE,_unload)(bus_dma_tag_t t,
 {
 	SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt;
 	bus_addr_t osgva, sgva, esgva;
-	int s, error, spill, seg, pteidx;
+	int spill, seg, pteidx;
 
 	for (seg = 0; seg < map->dm_nsegs; seg++) {
 		/*
@@ -431,12 +438,7 @@ __C(SGMAP_TYPE,_unload)(bus_dma_tag_t t,
 		alpha_mb();
 
 		/* Free the virtual address space used by the mapping. */
-		s = splvm();
-		error = extent_free(sgmap->aps_ex, osgva, (esgva - osgva),
-		    EX_NOWAIT);
-		splx(s);
-		if (error)
-			panic(__S(__C(SGMAP_TYPE,_unload)));
+		vmem_free(sgmap->aps_arena, osgva, (esgva - osgva));
 	}
 
 	map->_dm_flags &= ~(BUS_DMA_READ|BUS_DMA_WRITE);

Index: src/sys/arch/alpha/common/sgmapvar.h
diff -u src/sys/arch/alpha/common/sgmapvar.h:1.16 src/sys/arch/alpha/common/sgmapvar.h:1.17
--- src/sys/arch/alpha/common/sgmapvar.h:1.16	Fri Jul  1 19:22:35 2011
+++ src/sys/arch/alpha/common/sgmapvar.h	Wed Jun 17 04:12:39 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmapvar.h,v 1.16 2011/07/01 19:22:35 dyoung Exp $ */
+/* $NetBSD: sgmapvar.h,v 1.17 2020/06/17 04:12:39 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -33,8 +33,8 @@
 #ifndef	_ALPHA_COMMON_SGMAPVAR_H
 #define	_ALPHA_COMMON_SGMAPVAR_H
 
-#include <sys/extent.h>
 #include <sys/bus.h>
+#include <sys/vmem.h>
 
 /*
  * Bits n:13 of the DMA address are the index of the PTE into
@@ -52,7 +52,7 @@
  * the map, that region is effectively `locked'.
  */
 struct alpha_sgmap {
-	struct extent *aps_ex;		/* extent map to manage sgva space */
+	vmem_t	*aps_arena;		/* arena to manage sgva space */
 	void	*aps_pt;		/* page table */
 	bus_addr_t aps_ptpa;		/* page table physical address */
 	bus_addr_t aps_sgvabase;	/* base of the sgva space */

Reply via email to