Module Name:    src
Committed By:   thorpej
Date:           Sun Dec  3 00:49:46 UTC 2023

Modified Files:
        src/sys/arch/vax/include: sgmap.h
        src/sys/arch/vax/vax: sgmap.c

Log Message:
Use vmem(9) rather than extent(9) to manage SGMAP space.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/vax/include/sgmap.h
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/vax/vax/sgmap.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/vax/include/sgmap.h
diff -u src/sys/arch/vax/include/sgmap.h:1.7 src/sys/arch/vax/include/sgmap.h:1.8
--- src/sys/arch/vax/include/sgmap.h:1.7	Sun Jul  5 02:03:36 2015
+++ src/sys/arch/vax/include/sgmap.h	Sun Dec  3 00:49:46 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap.h,v 1.7 2015/07/05 02:03:36 matt Exp $ */
+/* $NetBSD: sgmap.h,v 1.8 2023/12/03 00:49:46 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -33,21 +33,21 @@
 #ifndef	_VAX_SGMAP_H
 #define	_VAX_SGMAP_H
 
-#include <sys/extent.h>
+#include <sys/vmem.h>
 #include <machine/bus.h>
 #include <machine/pte.h>
 
 /*
  * A VAX SGMAP's state information.  Nothing in the sgmap requires
- * locking[*], with the exception of the extent map.  Locking of the
- * extent map is handled within the extent manager itself.
+ * locking[*], with the exception of the vmem arena, which takes care
+ * of it on its own.
  *
  * [*] While the page table is a `global' resource, access to it is
- * controlled by the extent map; once a region has been allocated from
- * the map, that region is effectively `locked'.
+ * controlled by the arena; once a region has been allocated from
+ * the arena, that region is effectively `locked'.
  */
 struct vax_sgmap {
-	struct extent *aps_ex;		/* extent map to manage sgva space */
+	vmem_t     *aps_arena;		/* arena to manage sgva space */
 	struct pte *aps_pt;		/* page table */
 	bus_addr_t aps_sgvabase;	/* base of the sgva space */
 	bus_size_t aps_sgvasize;	/* size of the sgva space */

Index: src/sys/arch/vax/vax/sgmap.c
diff -u src/sys/arch/vax/vax/sgmap.c:1.19 src/sys/arch/vax/vax/sgmap.c:1.20
--- src/sys/arch/vax/vax/sgmap.c:1.19	Thu Jul  7 06:55:39 2016
+++ src/sys/arch/vax/vax/sgmap.c	Sun Dec  3 00:49:46 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap.c,v 1.19 2016/07/07 06:55:39 msaitoh Exp $ */
+/* $NetBSD: sgmap.c,v 1.20 2023/12/03 00:49:46 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sgmap.c,v 1.19 2016/07/07 06:55:39 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sgmap.c,v 1.20 2023/12/03 00:49:46 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -89,16 +89,18 @@ vax_sgmap_init(bus_dma_tag_t t, struct v
 	}
 
 	/*
-	 * Create the extent map used to manage the virtual address
+	 * Create the arena used to manage the virtual address
 	 * space.
 	 */
-	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,
+				       VAX_NBPG,	/* quantum */
+				       NULL,		/* importfn */
+				       NULL,		/* releasefn */
+				       NULL,		/* source */
+				       0,		/* qcache_max */
+				       VM_SLEEP,
+				       IPL_VM);
+	KASSERT(sgmap->aps_arena != NULL);
 	return;
  die:
 	panic("vax_sgmap_init");
@@ -131,9 +133,18 @@ vax_sgmap_alloc(bus_dmamap_t map, bus_si
 	    (unsigned int)origlen, (unsigned int)len, (unsigned int)map->_dm_sgvalen, (unsigned int)map->_dm_boundary, 1);
 #endif
 
-	error = extent_alloc(sgmap->aps_ex, map->_dm_sgvalen, VAX_NBPG,
-	    0, (flags & BUS_DMA_NOWAIT) ? EX_NOWAIT : EX_WAITOK,
-	    &map->_dm_sgva);
+	const vm_flag_t vmflags = VM_BESTFIT |
+	    ((flags & BUS_DMA_NOWAIT) ? VM_NOSLEEP : VM_SLEEP);
+
+	error = vmem_xalloc(sgmap->aps_arena, map->_dm_sgvalen,
+			    0,			/* alignment */
+			    0,			/* phase */
+			    map->_dm_boundary,	/* nocross */
+			    VMEM_ADDR_MIN,	/* minaddr */
+			    VMEM_ADDR_MAX,	/* maxaddr */
+			    vmflags,
+			    &map->_dm_sgva);
+
 #if DEBUG_SGMAP
 	printf("error %d _dm_sgva %lx\n", error, map->_dm_sgva);
 #endif
@@ -155,9 +166,7 @@ vax_sgmap_free(bus_dmamap_t map, struct 
 		panic("vax_sgmap_free: no sgva space to free");
 #endif
 
-	if (extent_free(sgmap->aps_ex, map->_dm_sgva, map->_dm_sgvalen,
-	    EX_NOWAIT))
-		panic("vax_sgmap_free");
+	vmem_xfree(sgmap->aps_arena, map->_dm_sgva, map->_dm_sgvalen);
 
 	map->_dm_flags &= ~DMAMAP_HAS_SGMAP;
 }
@@ -165,7 +174,7 @@ vax_sgmap_free(bus_dmamap_t map, struct 
 int
 vax_sgmap_reserve(bus_addr_t ba, bus_size_t len, struct vax_sgmap *sgmap)
 {
-	return extent_alloc_region(sgmap->aps_ex, ba, len, EX_NOWAIT);
+	return vmem_xalloc_addr(sgmap->aps_arena, ba, len, VM_NOSLEEP);
 }
 
 int

Reply via email to