CVS commit: src/sys/arch/alpha/common

2021-07-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jul 19 16:25:54 UTC 2021

Modified Files:
src/sys/arch/alpha/common: bus_dma.c sgmap_typedep.c

Log Message:
There is already a fast-path in pmap_extract() for the kernel pmap, so
don't bother doing a conditional for kernel vs. user-space here.

KASSERT() that pmap_extract() succeeds; it is a programming error if
it does not, and it's not a great idea to insert a garbage address
into the SGMAP page table.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/arch/alpha/common/bus_dma.c
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/alpha/common/sgmap_typedep.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/bus_dma.c
diff -u src/sys/arch/alpha/common/bus_dma.c:1.72 src/sys/arch/alpha/common/bus_dma.c:1.73
--- src/sys/arch/alpha/common/bus_dma.c:1.72	Fri May  7 16:58:33 2021
+++ src/sys/arch/alpha/common/bus_dma.c	Mon Jul 19 16:25:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_dma.c,v 1.72 2021/05/07 16:58:33 thorpej Exp $ */
+/* $NetBSD: bus_dma.c,v 1.73 2021/07/19 16:25:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.72 2021/05/07 16:58:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.73 2021/07/19 16:25:54 thorpej Exp $");
 
 #include 
 #include 
@@ -138,6 +138,7 @@ _bus_dmamap_load_buffer_direct(bus_dma_t
 	bus_addr_t curaddr, lastaddr, baddr, bmask;
 	vaddr_t vaddr = (vaddr_t)buf;
 	int seg;
+	bool address_is_valid __diagused;
 
 	lastaddr = *lastaddrp;
 	bmask = ~(map->_dm_boundary - 1);
@@ -146,10 +147,9 @@ _bus_dmamap_load_buffer_direct(bus_dma_t
 		/*
 		 * Get the physical address for this segment.
 		 */
-		if (!VMSPACE_IS_KERNEL_P(vm))
-			(void) pmap_extract(vm->vm_map.pmap, vaddr, &curaddr);
-		else
-			curaddr = vtophys(vaddr);
+		address_is_valid =
+		pmap_extract(vm->vm_map.pmap, vaddr, &curaddr);
+		KASSERT(address_is_valid);
 
 		/*
 		 * If we're beyond the current DMA window, indicate

Index: src/sys/arch/alpha/common/sgmap_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.43 src/sys/arch/alpha/common/sgmap_typedep.c:1.44
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.43	Sun Jul 18 05:12:27 2021
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Mon Jul 19 16:25:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.43 2021/07/18 05:12:27 thorpej Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.44 2021/07/19 16:25:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.43 2021/07/18 05:12:27 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.44 2021/07/19 16:25:54 thorpej Exp $");
 
 #include "opt_ddb.h"
 
@@ -74,6 +74,7 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	bus_size_t sgvalen, extra_sgvalen, boundary, alignment;
 	SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt;
 	int pteidx, error, spill, seg = *segp;
+	bool address_is_valid __diagused;
 
 	/* Initialize the spill page PTE if it hasn't been already. */
 	if (__C(SGMAP_TYPE,_prefetch_spill_page_pte) == 0)
@@ -268,10 +269,8 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	for (; va < endva; va += PAGE_SIZE, pteidx++,
 	 pte = &page_table[pteidx * SGMAP_PTE_SPACING]) {
 		/* Get the physical address for this segment. */
-		if (!VMSPACE_IS_KERNEL_P(vm))
-			(void) pmap_extract(vm->vm_map.pmap, va, &pa);
-		else
-			pa = vtophys(va);
+		address_is_valid = pmap_extract(vm->vm_map.pmap, va, &pa);
+		KASSERT(address_is_valid);
 
 		/* Load the current PTE with this page. */
 		*pte = (pa >> SGPTE_PGADDR_SHIFT) | SGPTE_VALID;
@@ -289,10 +288,8 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 
 		/* va == endva == address of extra page */
 		KASSERT(va == endva);
-		if (!VMSPACE_IS_KERNEL_P(vm))
-			(void) pmap_extract(vm->vm_map.pmap, va, &pa);
-		else
-			pa = vtophys(va);
+		address_is_valid = pmap_extract(vm->vm_map.pmap, va, &pa);
+		KASSERT(address_is_valid);
 
 		/*
 		 * If a spill page is needed, the previous segment will



CVS commit: src/sys/arch/alpha/common

2021-06-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jun 24 16:41:16 UTC 2021

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

Log Message:
Deal with a scenario where:
- DMA map has a boundary constraint.
- Caller asks us to map a buffer that's exactly the same size as the
  boundary constraint, but is not page-aligned.

This results in the size being larger than the boundary constraint after
page-rounding, and and vmem_xalloc() fires a KASSERT for it.  This is
easy to trigger by running fsck.

We handle this by detecting the condition and creating an extra DMA
segment for it the spill-over.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/alpha/common/sgmap_typedep.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_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.41 src/sys/arch/alpha/common/sgmap_typedep.c:1.42
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.41	Thu Apr 15 00:11:09 2021
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Thu Jun 24 16:41:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.41 2021/04/15 00:11:09 rin Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.42 2021/06/24 16:41:16 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.41 2021/04/15 00:11:09 rin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.42 2021/06/24 16:41:16 thorpej Exp $");
 
 #include "opt_ddb.h"
 
@@ -60,23 +60,31 @@ __C(SGMAP_TYPE,_init_spill_page_pte)(voi
 }
 
 DMA_COUNT_DECL(spill_page);
+DMA_COUNT_DECL(extra_segment);
+DMA_COUNT_DECL(extra_segment_and_spill);
 
 static int
 __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
-size_t buflen, struct vmspace *vm, int flags, int seg,
+size_t buflen, struct vmspace *vm, int flags, int * const segp,
 struct alpha_sgmap *sgmap)
 {
 	vaddr_t endva, va = (vaddr_t)buf;
 	paddr_t pa;
-	bus_addr_t dmaoffset, sgva;
-	bus_size_t sgvalen, boundary, alignment;
+	bus_addr_t dmaoffset, sgva, extra_sgva;
+	bus_size_t sgvalen, extra_sgvalen, boundary, alignment;
 	SGMAP_PTE_TYPE *pte, *page_table = sgmap->aps_pt;
-	int pteidx, error, spill;
+	int pteidx, error, spill, seg = *segp;
 
 	/* Initialize the spill page PTE if it hasn't been already. */
 	if (__C(SGMAP_TYPE,_prefetch_spill_page_pte) == 0)
 		__C(SGMAP_TYPE,_init_spill_page_pte)();
 
+	if (seg == map->_dm_segcnt) {
+		/* Ran of segments. */
+		return EFBIG;
+	}
+	KASSERT(seg < map->_dm_segcnt);
+
 	/*
 	 * Remember the offset into the first page and the total
 	 * transfer length.
@@ -106,13 +114,77 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 	else
 		spill = 0;
 
+	boundary = map->_dm_boundary;
+
+	/*
+	 * Caller's mistake if the requested length is larger than
+	 * their own boundary constraint.
+	 */
+	if (__predict_false(boundary != 0 && buflen > boundary)) {
+		return EINVAL;
+	}
+
 	endva = round_page(va + buflen);
 	va = trunc_page(va);
 
-	boundary = map->_dm_boundary;
-	alignment = PAGE_SIZE;
+	const vm_flag_t vmflags = VM_INSTANTFIT |
+	((flags & BUS_DMA_NOWAIT) ? VM_NOSLEEP : VM_SLEEP);
 
+	alignment = PAGE_SIZE;
 	sgvalen = (endva - va);
+
+	SGMAP_PTE_TYPE spill_pte_v = __C(SGMAP_TYPE,_prefetch_spill_page_pte);
+
+	/*
+	 * If we have a boundary constraint, it's possible to end up in
+	 * a situation where sgvalen > boundary if the caller's buffer
+	 * is not page aligned.  In this case, we will have to allocate
+	 * an extra SG segment and split the buffer.
+	 */
+	if (__predict_false(boundary != 0 && boundary < sgvalen)) {
+#ifdef SGMAP_DEBUG
+		if (__C(SGMAP_TYPE,_debug)) {
+			printf("sgmap_load: extra segment needed\n");
+		}
+#endif
+		DMA_COUNT(extra_segment);
+
+		/* This should only ever happen for unaligned buffers. */
+		KASSERT(dmaoffset != 0);
+
+		extra_sgvalen = sgvalen - boundary;
+		KASSERT(extra_sgvalen == PAGE_SIZE);
+
+		/*
+		 * Adjust the lengths of the first segment.  The length
+		 * of the second segment will be dmaoffset.
+		 */
+		sgvalen -= extra_sgvalen;
+		endva -= extra_sgvalen;
+		buflen -= dmaoffset;
+
+		if (spill) {
+			DMA_COUNT(extra_segment_and_spill);
+			extra_sgvalen += PAGE_SIZE;
+		}
+
+		error = vmem_xalloc(sgmap->aps_arena, extra_sgvalen,
+alignment,		/* alignment */
+0,			/* phase */
+boundary,		/* nocross */
+VMEM_ADDR_MIN,	/* minaddr */
+VMEM_ADDR_MAX,	/* maxaddr */
+vmflags,
+&extra_sgva);
+		if (error) {
+			return error;
+		}
+	} else {
+		extra_sgvalen = 0;
+		extra_sgva = 0;
+	}
+
+
 	if (spill) {
 		DMA_COUNT(spill_page);
 		sgvalen += PAGE_SIZE;
@@ -120,6 +192,11 @@ __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 

CVS commit: src/sys/arch/alpha/common

2021-04-14 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Apr 15 00:11:10 UTC 2021

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

Log Message:
Fix inverted logic!!

vmem_xalloc(9) should be used with VM_NOSLEEP for BUS_DMA_NOWAIT.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/alpha/common/sgmap_typedep.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_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.40 src/sys/arch/alpha/common/sgmap_typedep.c:1.41
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.40	Sun Oct 11 00:33:30 2020
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Thu Apr 15 00:11:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.40 2020/10/11 00:33:30 thorpej Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.41 2021/04/15 00:11:09 rin Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.40 2020/10/11 00:33:30 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.41 2021/04/15 00:11:09 rin Exp $");
 
 #include "opt_ddb.h"
 
@@ -138,7 +138,7 @@ __C(SGMAP_TYPE,_load_buffer)(bus_dma_tag
 #endif
 
 	const vm_flag_t vmflags = VM_INSTANTFIT |
-	((flags & BUS_DMA_NOWAIT) ? VM_SLEEP : VM_NOSLEEP);
+	((flags & BUS_DMA_NOWAIT) ? VM_NOSLEEP : VM_SLEEP);
 
 	error = vmem_xalloc(sgmap->aps_arena, sgvalen,
 			alignment,		/* alignment */



CVS commit: src/sys/arch/alpha/common

2020-09-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Sep 26 02:35:31 UTC 2020

Modified Files:
src/sys/arch/alpha/common: shared_intr.c

Log Message:
- Fix some bugs in previous, mainly related to indexing the correct
  interrupt queue.
- Make sure to update cpu_info::ci_nintrhand if an irq moves from
  one CPU to another.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/alpha/common/shared_intr.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/shared_intr.c
diff -u src/sys/arch/alpha/common/shared_intr.c:1.25 src/sys/arch/alpha/common/shared_intr.c:1.26
--- src/sys/arch/alpha/common/shared_intr.c:1.25	Fri Sep 25 03:40:11 2020
+++ src/sys/arch/alpha/common/shared_intr.c	Sat Sep 26 02:35:31 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: shared_intr.c,v 1.25 2020/09/25 03:40:11 thorpej Exp $ */
+/* $NetBSD: shared_intr.c,v 1.26 2020/09/26 02:35:31 thorpej Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.25 2020/09/25 03:40:11 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.26 2020/09/26 02:35:31 thorpej Exp $");
 
 #include 
 #include 
@@ -212,9 +212,11 @@ alpha_shared_intr_link_unlink_xcall(void
 {
 	struct alpha_shared_intrhand *ih = arg1;
 	struct alpha_shared_intr *intr = ih->ih_intrhead;
-	struct cpu_info *ci = intr->intr_cpu;
 	unsigned int num = ih->ih_num;
 
+	struct cpu_info *ci = intr[num].intr_cpu;
+
+	KASSERT(ci != NULL);
 	KASSERT(ci == curcpu() || !mp_online);
 	KASSERT(!cpu_intr_p());
 
@@ -273,17 +275,17 @@ alpha_shared_intr_link(struct alpha_shar
 	 * If a CPU hasn't been assigned yet, just give it to the
 	 * primary.
 	 */
-	if (intr->intr_cpu == NULL) {
-		intr->intr_cpu = &cpu_info_primary;
+	if (intr[num].intr_cpu == NULL) {
+		intr[num].intr_cpu = &cpu_info_primary;
 	}
 
 	kpreempt_disable();
-	if (intr->intr_cpu == curcpu() || !mp_online) {
-		alpha_shared_intr_link_unlink_xcall(ih, intr);
+	if (intr[num].intr_cpu == curcpu() || !mp_online) {
+		alpha_shared_intr_link_unlink_xcall(ih, ih);
 	} else {
 		uint64_t where = xc_unicast(XC_HIGHPRI,
-		alpha_shared_intr_link_unlink_xcall, ih, intr,
-		intr->intr_cpu);
+		alpha_shared_intr_link_unlink_xcall, ih, ih,
+		intr->intr_cpu);
 		xc_wait(where);
 	}
 	kpreempt_enable();
@@ -295,16 +297,17 @@ void
 alpha_shared_intr_unlink(struct alpha_shared_intr *intr,
 struct alpha_shared_intrhand *ih, const char *basename)
 {
+	unsigned int num = ih->ih_num;
 
 	KASSERT(mutex_owned(&cpu_lock));
 
 	kpreempt_disable();
-	if (intr->intr_cpu == curcpu() || !mp_online) {
+	if (intr[num].intr_cpu == curcpu() || !mp_online) {
 		alpha_shared_intr_link_unlink_xcall(ih, NULL);
 	} else {
 		uint64_t where = xc_unicast(XC_HIGHPRI,
 		alpha_shared_intr_link_unlink_xcall, ih, NULL,
-		intr->intr_cpu);
+		intr->intr_cpu);
 		xc_wait(where);
 	}
 	kpreempt_enable();
@@ -401,12 +404,79 @@ alpha_shared_intr_get_private(struct alp
 	return (intr[num].intr_private);
 }
 
+static unsigned int
+alpha_shared_intr_q_count_handlers(struct alpha_shared_intr *intr_q)
+{
+	unsigned int cnt = 0;
+	struct alpha_shared_intrhand *ih;
+
+	TAILQ_FOREACH(ih, &intr_q->intr_q, ih_q) {
+		cnt++;
+	}
+
+	return cnt;
+}
+
+static void
+alpha_shared_intr_set_cpu_xcall(void *arg1, void *arg2)
+{
+	struct alpha_shared_intr *intr_q = arg1;
+	struct cpu_info *ci = arg2;
+	unsigned int cnt = alpha_shared_intr_q_count_handlers(intr_q);
+
+	KASSERT(ci == curcpu() || !mp_online);
+
+	ci->ci_nintrhand += cnt;
+	KASSERT(cnt <= ci->ci_nintrhand);
+}
+
+static void
+alpha_shared_intr_unset_cpu_xcall(void *arg1, void *arg2)
+{
+	struct alpha_shared_intr *intr_q = arg1;
+	struct cpu_info *ci = arg2;
+	unsigned int cnt = alpha_shared_intr_q_count_handlers(intr_q);
+
+	KASSERT(ci == curcpu() || !mp_online);
+
+	KASSERT(cnt <= ci->ci_nintrhand);
+	ci->ci_nintrhand -= cnt;
+}
+
 void
 alpha_shared_intr_set_cpu(struct alpha_shared_intr *intr, unsigned int num,
 struct cpu_info *ci)
 {
+	struct cpu_info *old_ci;
+
+	KASSERT(mutex_owned(&cpu_lock));
 
+	old_ci = intr[num].intr_cpu;
 	intr[num].intr_cpu = ci;
+
+	if (old_ci != NULL && old_ci != ci) {
+		kpreempt_disable();
+
+		if (ci == curcpu() || !mp_online) {
+			alpha_shared_intr_set_cpu_xcall(&intr[num], ci);
+		} else {
+			uint64_t where = xc_unicast(XC_HIGHPRI,
+			alpha_shared_intr_set_cpu_xcall, &intr[num],
+			ci, ci);
+			xc_wait(where);
+		}
+
+		if (old_ci == curcpu() || !mp_online) {
+			alpha_shared_intr_unset_cpu_xcall(&intr[num], old_ci);
+		} else {
+			uint64_t where = xc_unicast(XC_HIGHPRI,
+			alpha_shared_intr_unset_cpu_xcall, &intr[num],
+			old_ci, old_ci);
+			xc_wait(where);
+		}
+
+		kpreempt_enable();
+	}
 }
 
 struct cpu_info *



CVS commit: src/sys/arch/alpha/common

2020-09-23 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Sep 23 18:46:02 UTC 2020

Modified Files:
src/sys/arch/alpha/common: shared_intr.c

Log Message:
Use a wrapper to acquire the kernel lock for non-MPSAFE interrupts,
rather than doing it in alpha_shared_intr_establish() directly.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/alpha/common/shared_intr.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/shared_intr.c
diff -u src/sys/arch/alpha/common/shared_intr.c:1.23 src/sys/arch/alpha/common/shared_intr.c:1.24
--- src/sys/arch/alpha/common/shared_intr.c:1.23	Tue Sep 22 15:24:01 2020
+++ src/sys/arch/alpha/common/shared_intr.c	Wed Sep 23 18:46:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: shared_intr.c,v 1.23 2020/09/22 15:24:01 thorpej Exp $ */
+/* $NetBSD: shared_intr.c,v 1.24 2020/09/23 18:46:02 thorpej Exp $ */
 
 /*
  * Copyright (c) 1996 Carnegie-Mellon University.
@@ -33,7 +33,7 @@
 
 #include 			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.23 2020/09/22 15:24:01 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: shared_intr.c,v 1.24 2020/09/23 18:46:02 thorpej Exp $");
 
 #include 
 #include 
@@ -110,13 +110,7 @@ alpha_shared_intr_dispatch(struct alpha_
 		 *  for sure.
 		 */
 
-		if (!ih->ih_mpsafe) {
-			KERNEL_LOCK(1, NULL);
-			rv = (*ih->ih_fn)(ih->ih_arg);
-			KERNEL_UNLOCK_ONE(NULL);
-		} else {
-			rv = (*ih->ih_fn)(ih->ih_arg);
-		}
+		rv = (*ih->ih_fn)(ih->ih_arg);
 
 		handled = handled || (rv != 0);
 		ih = ih->ih_q.tqe_next;
@@ -125,6 +119,19 @@ alpha_shared_intr_dispatch(struct alpha_
 	return (handled);
 }
 
+static int
+alpha_shared_intr_wrapper(void * const arg)
+{
+	struct alpha_shared_intrhand * const ih = arg;
+	int rv;
+
+	KERNEL_LOCK(1, NULL);
+	rv = (*ih->ih_real_fn)(ih->ih_real_arg);
+	KERNEL_UNLOCK_ONE(NULL);
+
+	return rv;
+}
+
 void *
 alpha_shared_intr_establish(struct alpha_shared_intr *intr, unsigned int num,
 int type, int level, int flags,
@@ -170,11 +177,19 @@ alpha_shared_intr_establish(struct alpha
 	}
 
 	ih->ih_intrhead = intr;
-	ih->ih_fn = fn;
-	ih->ih_arg = arg;
+	ih->ih_fn = ih->ih_real_fn = fn;
+	ih->ih_arg = ih->ih_real_arg = arg;
 	ih->ih_level = level;
 	ih->ih_num = num;
-	ih->ih_mpsafe = (flags & ALPHA_INTR_MPSAFE) != 0;
+
+	/*
+	 * Non-MPSAFE interrupts get a wrapper that takes the
+	 * KERNEL_LOCK.
+	 */
+	if ((flags & ALPHA_INTR_MPSAFE) == 0) {
+		ih->ih_fn = alpha_shared_intr_wrapper;
+		ih->ih_arg = ih;
+	}
 
 	intr[num].intr_sharetype = type;
 	TAILQ_INSERT_TAIL(&intr[num].intr_q, ih, ih_q);



CVS commit: src/sys/arch/alpha/common

2020-09-04 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Sat Sep  5 04:11:10 UTC 2020

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

Log Message:
fix typo


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 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/sgmapvar.h
diff -u src/sys/arch/alpha/common/sgmapvar.h:1.18 src/sys/arch/alpha/common/sgmapvar.h:1.19
--- src/sys/arch/alpha/common/sgmapvar.h:1.18	Sat Sep  5 03:47:16 2020
+++ src/sys/arch/alpha/common/sgmapvar.h	Sat Sep  5 04:11:10 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmapvar.h,v 1.18 2020/09/05 03:47:16 thorpej Exp $ */
+/* $NetBSD: sgmapvar.h,v 1.19 2020/09/05 04:11:10 maya Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  * of it on its own.
  *
  * [*] While the page table is a `global' resource, access to it is
- * controlled by the arenaa; once a region has been allocated from
+ * controlled by the arena; once a region has been allocated from
  * the arena, that region is effectively `locked'.
  */
 struct alpha_sgmap {



CVS commit: src/sys/arch/alpha/common

2020-09-04 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Sep  5 03:47:16 UTC 2020

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

Log Message:
Update a comment.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 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/sgmapvar.h
diff -u src/sys/arch/alpha/common/sgmapvar.h:1.17 src/sys/arch/alpha/common/sgmapvar.h:1.18
--- src/sys/arch/alpha/common/sgmapvar.h:1.17	Wed Jun 17 04:12:39 2020
+++ src/sys/arch/alpha/common/sgmapvar.h	Sat Sep  5 03:47:16 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmapvar.h,v 1.17 2020/06/17 04:12:39 thorpej Exp $ */
+/* $NetBSD: sgmapvar.h,v 1.18 2020/09/05 03:47:16 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -44,12 +44,12 @@
 
 /*
  * An Alpha 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 arenaa; once a region has been allocated from
+ * the arena, that region is effectively `locked'.
  */
 struct alpha_sgmap {
 	vmem_t	*aps_arena;		/* arena to manage sgva space */



CVS commit: src/sys/arch/alpha/common

2020-06-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jun 17 05:52:13 UTC 2020

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

Log Message:
Typo: vmem_free -> vmem_xfree


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/alpha/common/sgmap_typedep.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_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.38 src/sys/arch/alpha/common/sgmap_typedep.c:1.39
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.38	Wed Jun 17 04:12:39 2020
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Wed Jun 17 05:52:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.38 2020/06/17 04:12:39 thorpej Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.39 2020/06/17 05:52:13 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.38 2020/06/17 04:12:39 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.39 2020/06/17 05:52:13 thorpej Exp $");
 
 #include "opt_ddb.h"
 
@@ -438,7 +438,7 @@ __C(SGMAP_TYPE,_unload)(bus_dma_tag_t t,
 		alpha_mb();
 
 		/* Free the virtual address space used by the mapping. */
-		vmem_free(sgmap->aps_arena, osgva, (esgva - osgva));
+		vmem_xfree(sgmap->aps_arena, osgva, (esgva - osgva));
 	}
 
 	map->_dm_flags &= ~(BUS_DMA_READ|BUS_DMA_WRITE);



CVS commit: src/sys/arch/alpha/common

2020-06-16 Thread Jason R Thorpe
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 			/* 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 
 #include 
@@ -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 
-__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/sgm

CVS commit: src/sys/arch/alpha/common

2010-12-14 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Wed Dec 15 01:28:24 UTC 2010

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

Log Message:
include  here instead


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/alpha/common/sgmap_typedep.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_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.36 src/sys/arch/alpha/common/sgmap_typedep.c:1.37
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.36	Thu Oct  7 19:39:30 2010
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Wed Dec 15 01:28:24 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.36 2010/10/07 19:39:30 hans Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.37 2010/12/15 01:28:24 matt Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -31,10 +31,12 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.36 2010/10/07 19:39:30 hans Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.37 2010/12/15 01:28:24 matt Exp $");
 
 #include "opt_ddb.h"
 
+#include 
+
 #ifdef SGMAP_DEBUG
 int			__C(SGMAP_TYPE,_debug) = 0;
 #endif



CVS commit: src/sys/arch/alpha/common

2010-10-07 Thread Hans Rosenfeld
Module Name:src
Committed By:   hans
Date:   Thu Oct  7 19:39:31 UTC 2010

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

Log Message:
fix SGMAP_DEBUG on alpha


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/alpha/common/sgmap_typedep.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_typedep.c
diff -u src/sys/arch/alpha/common/sgmap_typedep.c:1.35 src/sys/arch/alpha/common/sgmap_typedep.c:1.36
--- src/sys/arch/alpha/common/sgmap_typedep.c:1.35	Mon Apr 28 20:23:11 2008
+++ src/sys/arch/alpha/common/sgmap_typedep.c	Thu Oct  7 19:39:30 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sgmap_typedep.c,v 1.35 2008/04/28 20:23:11 martin Exp $ */
+/* $NetBSD: sgmap_typedep.c,v 1.36 2010/10/07 19:39:30 hans Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.35 2008/04/28 20:23:11 martin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: sgmap_typedep.c,v 1.36 2010/10/07 19:39:30 hans Exp $");
 
 #include "opt_ddb.h"
 
@@ -121,9 +121,12 @@
 		}
 	}
 
-#if 0
-	printf("len 0x%lx -> 0x%lx, boundary 0x%lx -> 0x%lx -> ",
-	(endva - va), sgvalen, map->_dm_boundary, boundary);
+#ifdef SGMAP_DEBUG
+	if (__C(SGMAP_TYPE,_debug)) {
+		printf("sgmap_load: va:endva = 0x%lx:0x%lx\n", va, endva);
+		printf("sgmap_load: sgvalen = 0x%lx, boundary = 0x%lx\n",
+		   sgvalen, boundary);
+	}
 #endif
 
 	s = splvm();
@@ -133,10 +136,6 @@
 	if (error)
 		return (error);
 
-#if 0
-	printf("error %d sgva 0x%lx\n", error, sgva);
-#endif
-
 	pteidx = sgva >> SGMAP_ADDR_PTEIDX_SHIFT;
 	pte = &page_table[pteidx * SGMAP_PTE_SPACING];
 
@@ -153,8 +152,8 @@
 
 #ifdef SGMAP_DEBUG
 	if (__C(SGMAP_TYPE,_debug))
-		printf("sgmap_load: wbase = 0x%lx, vpage = 0x%x, "
-		"DMA addr = 0x%lx\n", sgmap->aps_wbase, sgva,
+		printf("sgmap_load: wbase = 0x%lx, vpage = 0x%lx, "
+		"DMA addr = 0x%lx\n", sgmap->aps_wbase, (uint64_t)sgva,
 		map->dm_segs[seg].ds_addr);
 #endif
 
@@ -181,9 +180,7 @@
 #ifdef SGMAP_DEBUG
 		if (__C(SGMAP_TYPE,_debug)) {
 			printf("sgmap_load: spill page, pte = %p, "
-			"*pte = 0x%lx\n", pte, *pte);
-			printf("sgmap_load: pte count = %d\n",
-			map->_dm_ptecnt);
+			"*pte = 0x%lx\n", pte, (uint64_t)*pte);
 		}
 #endif
 	}