Module Name: src Committed By: skrll Date: Wed Nov 11 08:20:22 UTC 2015
Modified Files: src/sys/arch/x86/conf: files.x86 src/sys/arch/x86/include: pmap.h src/sys/arch/x86/x86: pmap.c Added Files: src/sys/uvm/pmap: pmap_pvt.c pmap_pvt.h Log Message: Split out the pmap_pv_track stuff for use by others. Discussed with riastradh@ To generate a diff of this commit: cvs rdiff -u -r1.84 -r1.85 src/sys/arch/x86/conf/files.x86 cvs rdiff -u -r1.56 -r1.57 src/sys/arch/x86/include/pmap.h cvs rdiff -u -r1.188 -r1.189 src/sys/arch/x86/x86/pmap.c cvs rdiff -u -r0 -r1.1 src/sys/uvm/pmap/pmap_pvt.c \ src/sys/uvm/pmap/pmap_pvt.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/x86/conf/files.x86 diff -u src/sys/arch/x86/conf/files.x86:1.84 src/sys/arch/x86/conf/files.x86:1.85 --- src/sys/arch/x86/conf/files.x86:1.84 Mon Apr 27 07:03:58 2015 +++ src/sys/arch/x86/conf/files.x86 Wed Nov 11 08:20:22 2015 @@ -1,4 +1,4 @@ -# $NetBSD: files.x86,v 1.84 2015/04/27 07:03:58 knakahara Exp $ +# $NetBSD: files.x86,v 1.85 2015/11/11 08:20:22 skrll Exp $ # options for MP configuration through the MP spec defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI @@ -95,6 +95,8 @@ file arch/x86/x86/x86_autoconf.c machdep file arch/x86/x86/x86_userconf.c userconf file arch/x86/x86/x86_machdep.c machdep +file uvm/pmap/pmap_pvt.c machdep + file arch/x86/x86/cpu_ucode.c cpu_ucode needs-flag file arch/x86/x86/cpu_ucode_amd.c cpu_ucode needs-flag file arch/x86/x86/cpu_ucode_intel.c cpu_ucode needs-flag Index: src/sys/arch/x86/include/pmap.h diff -u src/sys/arch/x86/include/pmap.h:1.56 src/sys/arch/x86/include/pmap.h:1.57 --- src/sys/arch/x86/include/pmap.h:1.56 Fri Apr 3 01:04:23 2015 +++ src/sys/arch/x86/include/pmap.h Wed Nov 11 08:20:22 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.h,v 1.56 2015/04/03 01:04:23 riastradh Exp $ */ +/* $NetBSD: pmap.h,v 1.57 2015/11/11 08:20:22 skrll Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -109,6 +109,7 @@ #if defined(_KERNEL) #include <sys/kcpuset.h> +#include <uvm/pmap/pmap_pvt.h> /* * pmap data structures: see pmap.c for details of locking. Index: src/sys/arch/x86/x86/pmap.c diff -u src/sys/arch/x86/x86/pmap.c:1.188 src/sys/arch/x86/x86/pmap.c:1.189 --- src/sys/arch/x86/x86/pmap.c:1.188 Fri Apr 3 01:04:24 2015 +++ src/sys/arch/x86/x86/pmap.c Wed Nov 11 08:20:22 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.188 2015/04/03 01:04:24 riastradh Exp $ */ +/* $NetBSD: pmap.c,v 1.189 2015/11/11 08:20:22 skrll Exp $ */ /*- * Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. @@ -171,7 +171,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.188 2015/04/03 01:04:24 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.189 2015/11/11 08:20:22 skrll Exp $"); #include "opt_user_ldt.h" #include "opt_lockdebug.h" @@ -191,10 +191,9 @@ __KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.1 #include <sys/intr.h> #include <sys/xcall.h> #include <sys/kcore.h> -#include <sys/kmem.h> -#include <sys/pserialize.h> #include <uvm/uvm.h> +#include <uvm/pmap/pmap_pvt.h> #include <dev/isa/isareg.h> @@ -463,120 +462,6 @@ pvhash_remove(struct pv_hash_head *hh, s } /* - * unmanaged pv-tracked ranges - * - * This is a linear list for now because the only user are the DRM - * graphics drivers, with a single tracked range per device, for the - * graphics aperture, so there are expected to be few of them. - * - * This is used only after the VM system is initialized well enough - * that we can use kmem_alloc. - */ - -struct pv_track { - paddr_t pvt_start; - psize_t pvt_size; - struct pv_track *pvt_next; - struct pmap_page pvt_pages[]; -}; - -static struct { - kmutex_t lock; - pserialize_t psz; - struct pv_track *list; -} pv_unmanaged __cacheline_aligned; - -void -pmap_pv_init(void) -{ - - mutex_init(&pv_unmanaged.lock, MUTEX_DEFAULT, IPL_VM); - pv_unmanaged.psz = pserialize_create(); - pv_unmanaged.list = NULL; -} - -void -pmap_pv_track(paddr_t start, psize_t size) -{ - struct pv_track *pvt; - size_t npages; - - KASSERT(start == trunc_page(start)); - KASSERT(size == trunc_page(size)); - - npages = size >> PAGE_SHIFT; - pvt = kmem_zalloc(offsetof(struct pv_track, pvt_pages[npages]), - KM_SLEEP); - pvt->pvt_start = start; - pvt->pvt_size = size; - - mutex_enter(&pv_unmanaged.lock); - pvt->pvt_next = pv_unmanaged.list; - membar_producer(); - pv_unmanaged.list = pvt; - mutex_exit(&pv_unmanaged.lock); -} - -void -pmap_pv_untrack(paddr_t start, psize_t size) -{ - struct pv_track **pvtp, *pvt; - size_t npages; - - KASSERT(start == trunc_page(start)); - KASSERT(size == trunc_page(size)); - - mutex_enter(&pv_unmanaged.lock); - for (pvtp = &pv_unmanaged.list; - (pvt = *pvtp) != NULL; - pvtp = &pvt->pvt_next) { - if (pvt->pvt_start != start) - continue; - if (pvt->pvt_size != size) - panic("pmap_pv_untrack: pv-tracking at 0x%"PRIxPADDR - ": 0x%"PRIxPSIZE" bytes, not 0x%"PRIxPSIZE" bytes", - pvt->pvt_start, pvt->pvt_size, size); - *pvtp = pvt->pvt_next; - pserialize_perform(pv_unmanaged.psz); - pvt->pvt_next = NULL; - goto out; - } - panic("pmap_pv_untrack: pages not pv-tracked at 0x%"PRIxPADDR - " (0x%"PRIxPSIZE" bytes)", - start, size); -out: mutex_exit(&pv_unmanaged.lock); - - npages = size >> PAGE_SHIFT; - kmem_free(pvt, offsetof(struct pv_track, pvt_pages[npages])); -} - -static struct pmap_page * -pmap_pv_tracked(paddr_t pa) -{ - struct pv_track *pvt; - size_t pgno; - int s; - - KASSERT(pa == trunc_page(pa)); - - s = pserialize_read_enter(); - for (pvt = pv_unmanaged.list; pvt != NULL; pvt = pvt->pvt_next) { - membar_datadep_consumer(); - if ((pvt->pvt_start <= pa) && - ((pa - pvt->pvt_start) < pvt->pvt_size)) - break; - } - pserialize_read_exit(s); - - if (pvt == NULL) - return NULL; - KASSERT(pvt->pvt_start <= pa); - KASSERT((pa - pvt->pvt_start) < pvt->pvt_size); - pgno = (pa - pvt->pvt_start) >> PAGE_SHIFT; - return &pvt->pvt_pages[pgno]; -} - -/* * other data structures */ Added files: Index: src/sys/uvm/pmap/pmap_pvt.c diff -u /dev/null src/sys/uvm/pmap/pmap_pvt.c:1.1 --- /dev/null Wed Nov 11 08:20:22 2015 +++ src/sys/uvm/pmap/pmap_pvt.c Wed Nov 11 08:20:22 2015 @@ -0,0 +1,160 @@ +/* $NetBSD: pmap_pvt.c,v 1.1 2015/11/11 08:20:22 skrll Exp $ */ + +/*- + * Copyright (c) 2014 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Taylor R. Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: pmap_pvt.c,v 1.1 2015/11/11 08:20:22 skrll Exp $"); + +#if 0 +#include <sys/intr.h> +#include <sys/xcall.h> +#include <sys/kcore.h> +#endif + +#include <sys/kmem.h> +#include <sys/pserialize.h> + +#include <uvm/uvm.h> +#include <uvm/pmap/pmap_pvt.h> + +/* + * unmanaged pv-tracked ranges + * + * This is a linear list for now because the only user are the DRM + * graphics drivers, with a single tracked range per device, for the + * graphics aperture, so there are expected to be few of them. + * + * This is used only after the VM system is initialized well enough + * that we can use kmem_alloc. + */ + +struct pv_track { + paddr_t pvt_start; + psize_t pvt_size; + struct pv_track *pvt_next; + struct pmap_page pvt_pages[]; +}; + +static struct { + kmutex_t lock; + pserialize_t psz; + struct pv_track *list; +} pv_unmanaged __cacheline_aligned; + +void +pmap_pv_init(void) +{ + + mutex_init(&pv_unmanaged.lock, MUTEX_DEFAULT, IPL_VM); + pv_unmanaged.psz = pserialize_create(); + pv_unmanaged.list = NULL; +} + +void +pmap_pv_track(paddr_t start, psize_t size) +{ + struct pv_track *pvt; + size_t npages; + + KASSERT(start == trunc_page(start)); + KASSERT(size == trunc_page(size)); + + npages = size >> PAGE_SHIFT; + pvt = kmem_zalloc(offsetof(struct pv_track, pvt_pages[npages]), + KM_SLEEP); + pvt->pvt_start = start; + pvt->pvt_size = size; + + mutex_enter(&pv_unmanaged.lock); + pvt->pvt_next = pv_unmanaged.list; + membar_producer(); + pv_unmanaged.list = pvt; + mutex_exit(&pv_unmanaged.lock); +} + +void +pmap_pv_untrack(paddr_t start, psize_t size) +{ + struct pv_track **pvtp, *pvt; + size_t npages; + + KASSERT(start == trunc_page(start)); + KASSERT(size == trunc_page(size)); + + mutex_enter(&pv_unmanaged.lock); + for (pvtp = &pv_unmanaged.list; + (pvt = *pvtp) != NULL; + pvtp = &pvt->pvt_next) { + if (pvt->pvt_start != start) + continue; + if (pvt->pvt_size != size) + panic("pmap_pv_untrack: pv-tracking at 0x%"PRIxPADDR + ": 0x%"PRIxPSIZE" bytes, not 0x%"PRIxPSIZE" bytes", + pvt->pvt_start, pvt->pvt_size, size); + *pvtp = pvt->pvt_next; + pserialize_perform(pv_unmanaged.psz); + pvt->pvt_next = NULL; + goto out; + } + panic("pmap_pv_untrack: pages not pv-tracked at 0x%"PRIxPADDR + " (0x%"PRIxPSIZE" bytes)", + start, size); +out: mutex_exit(&pv_unmanaged.lock); + + npages = size >> PAGE_SHIFT; + kmem_free(pvt, offsetof(struct pv_track, pvt_pages[npages])); +} + +struct pmap_page * +pmap_pv_tracked(paddr_t pa) +{ + struct pv_track *pvt; + size_t pgno; + int s; + + KASSERT(pa == trunc_page(pa)); + + s = pserialize_read_enter(); + for (pvt = pv_unmanaged.list; pvt != NULL; pvt = pvt->pvt_next) { + membar_datadep_consumer(); + if ((pvt->pvt_start <= pa) && + ((pa - pvt->pvt_start) < pvt->pvt_size)) + break; + } + pserialize_read_exit(s); + + if (pvt == NULL) + return NULL; + KASSERT(pvt->pvt_start <= pa); + KASSERT((pa - pvt->pvt_start) < pvt->pvt_size); + pgno = (pa - pvt->pvt_start) >> PAGE_SHIFT; + return &pvt->pvt_pages[pgno]; +} + Index: src/sys/uvm/pmap/pmap_pvt.h diff -u /dev/null src/sys/uvm/pmap/pmap_pvt.h:1.1 --- /dev/null Wed Nov 11 08:20:22 2015 +++ src/sys/uvm/pmap/pmap_pvt.h Wed Nov 11 08:20:22 2015 @@ -0,0 +1,47 @@ +/* $NetBSD: pmap_pvt.h,v 1.1 2015/11/11 08:20:22 skrll Exp $ */ + +/*- + * Copyright (c) 2014 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Taylor R. Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef _COMMON_PMAP_PV_H_ +#define _COMMON_PMAP_PV_H_ + +#include <sys/pserialize.h> + +struct pmap_page; + +void pmap_pv_init(void); + +void pmap_pv_track(paddr_t, psize_t); +void pmap_pv_untrack(paddr_t, psize_t); + +struct pmap_page *pmap_pv_tracked(paddr_t); + +#endif /* _COMMON_PMAP_PV_H_ */