Home | History | Annotate | Line # | Download | only in pmap
vmpagemd.h revision 1.7.4.2
      1  1.7.4.2  jdolecek /*	$NetBSD: vmpagemd.h,v 1.7.4.2 2017/12/03 11:39:23 jdolecek Exp $	*/
      2  1.7.4.2  jdolecek 
      3  1.7.4.2  jdolecek /*-
      4  1.7.4.2  jdolecek  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      5  1.7.4.2  jdolecek  * All rights reserved.
      6  1.7.4.2  jdolecek  *
      7  1.7.4.2  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8  1.7.4.2  jdolecek  * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
      9  1.7.4.2  jdolecek  * Agency and which was developed by Matt Thomas of 3am Software Foundry.
     10  1.7.4.2  jdolecek  *
     11  1.7.4.2  jdolecek  * This material is based upon work supported by the Defense Advanced Research
     12  1.7.4.2  jdolecek  * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
     13  1.7.4.2  jdolecek  * Contract No. N66001-09-C-2073.
     14  1.7.4.2  jdolecek  * Approved for Public Release, Distribution Unlimited
     15  1.7.4.2  jdolecek  *
     16  1.7.4.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     17  1.7.4.2  jdolecek  * modification, are permitted provided that the following conditions
     18  1.7.4.2  jdolecek  * are met:
     19  1.7.4.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     20  1.7.4.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     21  1.7.4.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     22  1.7.4.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     23  1.7.4.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     24  1.7.4.2  jdolecek  *
     25  1.7.4.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  1.7.4.2  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.7.4.2  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.7.4.2  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  1.7.4.2  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.7.4.2  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.7.4.2  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.7.4.2  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.7.4.2  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.7.4.2  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.7.4.2  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     36  1.7.4.2  jdolecek  */
     37  1.7.4.2  jdolecek 
     38  1.7.4.2  jdolecek #ifndef _UVM_PMAP_VMPAGEMD_H_
     39  1.7.4.2  jdolecek #define _UVM_PMAP_VMPAGEMD_H_
     40  1.7.4.2  jdolecek 
     41  1.7.4.2  jdolecek #ifdef _LOCORE
     42  1.7.4.2  jdolecek #error use assym.h instead
     43  1.7.4.2  jdolecek #endif
     44  1.7.4.2  jdolecek 
     45  1.7.4.2  jdolecek //#ifdef _MODULE
     46  1.7.4.2  jdolecek //#error this file should not be included by loadable kernel modules
     47  1.7.4.2  jdolecek //#endif
     48  1.7.4.2  jdolecek 
     49  1.7.4.2  jdolecek #ifdef _KERNEL_OPT
     50  1.7.4.2  jdolecek #include "opt_modular.h"
     51  1.7.4.2  jdolecek #include "opt_multiprocessor.h"
     52  1.7.4.2  jdolecek #endif
     53  1.7.4.2  jdolecek 
     54  1.7.4.2  jdolecek #include <sys/atomic.h>
     55  1.7.4.2  jdolecek #include <sys/mutex.h>
     56  1.7.4.2  jdolecek 
     57  1.7.4.2  jdolecek #define	__HAVE_VM_PAGE_MD
     58  1.7.4.2  jdolecek 
     59  1.7.4.2  jdolecek typedef struct pv_entry {
     60  1.7.4.2  jdolecek 	struct pv_entry *pv_next;
     61  1.7.4.2  jdolecek 	struct pmap *pv_pmap;
     62  1.7.4.2  jdolecek 	vaddr_t pv_va;
     63  1.7.4.2  jdolecek #define	PV_KENTER		__BIT(0)
     64  1.7.4.2  jdolecek } *pv_entry_t;
     65  1.7.4.2  jdolecek 
     66  1.7.4.2  jdolecek #ifndef _MODULE
     67  1.7.4.2  jdolecek 
     68  1.7.4.2  jdolecek #define	VM_PAGEMD_REFERENCED	__BIT(0)	/* page has been referenced */
     69  1.7.4.2  jdolecek #define	VM_PAGEMD_MODIFIED	__BIT(1)	/* page has been modified */
     70  1.7.4.2  jdolecek #define	VM_PAGEMD_POOLPAGE	__BIT(2)	/* page is used as a poolpage */
     71  1.7.4.2  jdolecek #define	VM_PAGEMD_EXECPAGE	__BIT(3)	/* page is exec mapped */
     72  1.7.4.2  jdolecek #ifdef PMAP_VIRTUAL_CACHE_ALIASES
     73  1.7.4.2  jdolecek #define	VM_PAGEMD_UNCACHED	__BIT(4)	/* page is mapped uncached */
     74  1.7.4.2  jdolecek #endif
     75  1.7.4.2  jdolecek 
     76  1.7.4.2  jdolecek #ifdef PMAP_VIRTUAL_CACHE_ALIASES
     77  1.7.4.2  jdolecek #define	VM_PAGEMD_CACHED_P(mdpg)	(((mdpg)->mdpg_attrs & VM_PAGEMD_UNCACHED) == 0)
     78  1.7.4.2  jdolecek #define	VM_PAGEMD_UNCACHED_P(mdpg)	(((mdpg)->mdpg_attrs & VM_PAGEMD_UNCACHED) != 0)
     79  1.7.4.2  jdolecek #endif
     80  1.7.4.2  jdolecek #define	VM_PAGEMD_MODIFIED_P(mdpg)	(((mdpg)->mdpg_attrs & VM_PAGEMD_MODIFIED) != 0)
     81  1.7.4.2  jdolecek #define	VM_PAGEMD_REFERENCED_P(mdpg)	(((mdpg)->mdpg_attrs & VM_PAGEMD_REFERENCED) != 0)
     82  1.7.4.2  jdolecek #define	VM_PAGEMD_POOLPAGE_P(mdpg)	(((mdpg)->mdpg_attrs & VM_PAGEMD_POOLPAGE) != 0)
     83  1.7.4.2  jdolecek #define	VM_PAGEMD_EXECPAGE_P(mdpg)	(((mdpg)->mdpg_attrs & VM_PAGEMD_EXECPAGE) != 0)
     84  1.7.4.2  jdolecek 
     85  1.7.4.2  jdolecek #endif /* !_MODULE */
     86  1.7.4.2  jdolecek 
     87  1.7.4.2  jdolecek struct vm_page_md {
     88  1.7.4.2  jdolecek 	volatile unsigned long mdpg_attrs;	/* page attributes */
     89  1.7.4.2  jdolecek 	struct pv_entry mdpg_first;		/* pv_entry first */
     90  1.7.4.2  jdolecek #if defined(MULTIPROCESSOR) || defined(MODULAR) || defined(_MODULE)
     91  1.7.4.2  jdolecek 	kmutex_t *mdpg_lock;			/* pv list lock */
     92  1.7.4.2  jdolecek #endif
     93  1.7.4.2  jdolecek };
     94  1.7.4.2  jdolecek 
     95  1.7.4.2  jdolecek #ifndef _MODULE
     96  1.7.4.2  jdolecek #if defined(MULTIPROCESSOR) || defined(MODULAR)
     97  1.7.4.2  jdolecek #define	VM_PAGEMD_PVLIST_LOCK_INIT(mdpg) 	\
     98  1.7.4.2  jdolecek 	(mdpg)->mdpg_lock = NULL
     99  1.7.4.2  jdolecek #else
    100  1.7.4.2  jdolecek #define	VM_PAGEMD_PVLIST_LOCK_INIT(mdpg)	do { } while (/*CONSTCOND*/ 0)
    101  1.7.4.2  jdolecek #endif /* MULTIPROCESSOR || MODULAR */
    102  1.7.4.2  jdolecek 
    103  1.7.4.2  jdolecek #define	VM_PAGEMD_PVLIST_LOCK(mdpg)		\
    104  1.7.4.2  jdolecek 	pmap_pvlist_lock(mdpg, 1)
    105  1.7.4.2  jdolecek #define	VM_PAGEMD_PVLIST_READLOCK(mdpg)		\
    106  1.7.4.2  jdolecek 	pmap_pvlist_lock(mdpg, 0)
    107  1.7.4.2  jdolecek #define	VM_PAGEMD_PVLIST_UNLOCK(mdpg)		\
    108  1.7.4.2  jdolecek 	pmap_pvlist_unlock(mdpg)
    109  1.7.4.2  jdolecek #define	VM_PAGEMD_PVLIST_LOCKED_P(mdpg)		\
    110  1.7.4.2  jdolecek 	pmap_pvlist_locked_p(mdpg)
    111  1.7.4.2  jdolecek #define	VM_PAGEMD_PVLIST_GEN(mdpg)		\
    112  1.7.4.2  jdolecek 	((mdpg)->mdpg_attrs >> 16)
    113  1.7.4.2  jdolecek 
    114  1.7.4.2  jdolecek #ifdef _KERNEL
    115  1.7.4.2  jdolecek #if defined(MULTIPROCESSOR) || defined(MODULAR)
    116  1.7.4.2  jdolecek kmutex_t *pmap_pvlist_lock_addr(struct vm_page_md *);
    117  1.7.4.2  jdolecek #else
    118  1.7.4.2  jdolecek extern kmutex_t pmap_pvlist_mutex;
    119  1.7.4.2  jdolecek static inline kmutex_t *
    120  1.7.4.2  jdolecek pmap_pvlist_lock_addr(struct vm_page_md *mdpg)
    121  1.7.4.2  jdolecek {
    122  1.7.4.2  jdolecek 	return &pmap_pvlist_mutex;
    123  1.7.4.2  jdolecek }
    124  1.7.4.2  jdolecek #endif
    125  1.7.4.2  jdolecek 
    126  1.7.4.2  jdolecek static inline uintptr_t
    127  1.7.4.2  jdolecek pmap_pvlist_lock(struct vm_page_md *mdpg, uintptr_t increment)
    128  1.7.4.2  jdolecek {
    129  1.7.4.2  jdolecek 	mutex_spin_enter(pmap_pvlist_lock_addr(mdpg));
    130  1.7.4.2  jdolecek 	const uintptr_t gen = VM_PAGEMD_PVLIST_GEN(mdpg);
    131  1.7.4.2  jdolecek 	mdpg->mdpg_attrs += increment << 16;
    132  1.7.4.2  jdolecek 	return gen;
    133  1.7.4.2  jdolecek }
    134  1.7.4.2  jdolecek 
    135  1.7.4.2  jdolecek static inline uintptr_t
    136  1.7.4.2  jdolecek pmap_pvlist_unlock(struct vm_page_md *mdpg)
    137  1.7.4.2  jdolecek {
    138  1.7.4.2  jdolecek 	const uintptr_t gen = VM_PAGEMD_PVLIST_GEN(mdpg);
    139  1.7.4.2  jdolecek 	mutex_spin_exit(pmap_pvlist_lock_addr(mdpg));
    140  1.7.4.2  jdolecek 	return gen;
    141  1.7.4.2  jdolecek }
    142  1.7.4.2  jdolecek 
    143  1.7.4.2  jdolecek static inline bool
    144  1.7.4.2  jdolecek pmap_pvlist_locked_p(struct vm_page_md *mdpg)
    145  1.7.4.2  jdolecek {
    146  1.7.4.2  jdolecek 	return mutex_owned(pmap_pvlist_lock_addr(mdpg));
    147  1.7.4.2  jdolecek }
    148  1.7.4.2  jdolecek #endif /* _KERNEL */
    149  1.7.4.2  jdolecek 
    150  1.7.4.2  jdolecek #define VM_MDPAGE_INIT(pg)						\
    151  1.7.4.2  jdolecek do {									\
    152  1.7.4.2  jdolecek 	(pg)->mdpage.mdpg_first.pv_next = NULL;				\
    153  1.7.4.2  jdolecek 	(pg)->mdpage.mdpg_first.pv_pmap = NULL;				\
    154  1.7.4.2  jdolecek 	(pg)->mdpage.mdpg_first.pv_va = (pg)->phys_addr;		\
    155  1.7.4.2  jdolecek 	(pg)->mdpage.mdpg_attrs = 0;					\
    156  1.7.4.2  jdolecek 	VM_PAGEMD_PVLIST_LOCK_INIT(&(pg)->mdpage);			\
    157  1.7.4.2  jdolecek } while (/* CONSTCOND */ 0)
    158  1.7.4.2  jdolecek 
    159  1.7.4.2  jdolecek #endif /* _MODULE */
    160  1.7.4.2  jdolecek 
    161  1.7.4.2  jdolecek #endif /* _UVM_PMAP_VMPAGEMD_H_ */
    162