Module Name: src
Committed By: chs
Date: Sat Jan 21 16:48:57 UTC 2012
Modified Files:
src/sys/arch/amd64/include: cpu.h types.h
src/sys/arch/x86/x86: vm_machdep.c
Log Message:
allocate uareas contiguously and access them via the direct map.
To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/amd64/include/cpu.h
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/amd64/include/types.h
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/x86/x86/vm_machdep.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/amd64/include/cpu.h
diff -u src/sys/arch/amd64/include/cpu.h:1.59 src/sys/arch/amd64/include/cpu.h:1.60
--- src/sys/arch/amd64/include/cpu.h:1.59 Tue Dec 30 12:35:23 2008
+++ src/sys/arch/amd64/include/cpu.h Sat Jan 21 16:48:56 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.59 2008/12/30 12:35:23 pooka Exp $ */
+/* $NetBSD: cpu.h,v 1.60 2012/01/21 16:48:56 chs Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -89,6 +89,9 @@ cpu_set_curpri(int pri)
#define CLKF_INTR(frame) (curcpu()->ci_idepth > 0)
#define LWP_PC(l) ((l)->l_md.md_regs->tf_rip)
+void *cpu_uarea_alloc(bool);
+bool cpu_uarea_free(void *);
+
#endif /* _KERNEL */
#else /* __x86_64__ */
Index: src/sys/arch/amd64/include/types.h
diff -u src/sys/arch/amd64/include/types.h:1.40 src/sys/arch/amd64/include/types.h:1.41
--- src/sys/arch/amd64/include/types.h:1.40 Sun Dec 4 16:24:13 2011
+++ src/sys/arch/amd64/include/types.h Sat Jan 21 16:48:56 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.40 2011/12/04 16:24:13 chs Exp $ */
+/* $NetBSD: types.h,v 1.41 2012/01/21 16:48:56 chs Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -99,6 +99,7 @@ typedef volatile unsigned char __cpu_si
#define __HAVE_DIRECT_MAP 1
#define __HAVE_MM_MD_DIRECT_MAPPED_IO
#define __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+#define __HAVE_CPU_UAREA_ROUTINES
#endif
#endif
Index: src/sys/arch/x86/x86/vm_machdep.c
diff -u src/sys/arch/x86/x86/vm_machdep.c:1.13 src/sys/arch/x86/x86/vm_machdep.c:1.14
--- src/sys/arch/x86/x86/vm_machdep.c:1.13 Thu Feb 10 14:46:48 2011
+++ src/sys/arch/x86/x86/vm_machdep.c Sat Jan 21 16:48:57 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.13 2011/02/10 14:46:48 pooka Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.14 2012/01/21 16:48:57 chs Exp $ */
/*-
* Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.13 2011/02/10 14:46:48 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.14 2012/01/21 16:48:57 chs Exp $");
#include "opt_mtrr.h"
@@ -93,7 +93,7 @@ __KERNEL_RCSID(0, "$NetBSD: vm_machdep.c
#include <sys/exec.h>
#include <sys/ptrace.h>
-#include <uvm/uvm_extern.h>
+#include <uvm/uvm.h>
#include <machine/cpu.h>
#include <machine/gdt.h>
@@ -356,3 +356,58 @@ vunmapbuf(struct buf *bp, vsize_t len)
bp->b_data = bp->b_saveaddr;
bp->b_saveaddr = 0;
}
+
+#ifdef __HAVE_CPU_UAREA_ROUTINES
+void *
+cpu_uarea_alloc(bool system)
+{
+ struct pglist pglist;
+ int error;
+
+ /*
+ * Allocate a new physically contiguous uarea which can be
+ * direct-mapped.
+ */
+ error = uvm_pglistalloc(USPACE, 0, ptoa(physmem), 0, 0, &pglist, 1, 1);
+ if (error) {
+ return NULL;
+ }
+
+ /*
+ * Get the physical address from the first page.
+ */
+ const struct vm_page * const pg = TAILQ_FIRST(&pglist);
+ KASSERT(pg != NULL);
+ const paddr_t pa = VM_PAGE_TO_PHYS(pg);
+
+ /*
+ * We need to return a direct-mapped VA for the pa.
+ */
+
+ return (void *)PMAP_MAP_POOLPAGE(pa);
+}
+
+/*
+ * Return true if we freed it, false if we didn't.
+ */
+bool
+cpu_uarea_free(void *vva)
+{
+ vaddr_t va = (vaddr_t) vva;
+
+ if (va >= VM_MIN_KERNEL_ADDRESS && va < VM_MAX_KERNEL_ADDRESS) {
+ return false;
+ }
+
+ /*
+ * Since the pages are physically contiguous, the vm_page structures
+ * will be as well.
+ */
+ struct vm_page *pg = PHYS_TO_VM_PAGE(PMAP_UNMAP_POOLPAGE(va));
+ KASSERT(pg != NULL);
+ for (size_t i = 0; i < UPAGES; i++, pg++) {
+ uvm_pagefree(pg);
+ }
+ return true;
+}
+#endif /* __HAVE_CPU_UAREA_ROUTINES */