vmpagemd.h revision 1.2 1 1.2 matt /* $NetBSD: vmpagemd.h,v 1.2 2014/03/04 06:14:53 matt Exp $ */
2 1.1 christos
3 1.1 christos /*-
4 1.1 christos * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.1 christos * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
9 1.1 christos * Agency and which was developed by Matt Thomas of 3am Software Foundry.
10 1.1 christos *
11 1.1 christos * This material is based upon work supported by the Defense Advanced Research
12 1.1 christos * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
13 1.1 christos * Contract No. N66001-09-C-2073.
14 1.1 christos * Approved for Public Release, Distribution Unlimited
15 1.1 christos *
16 1.1 christos * Redistribution and use in source and binary forms, with or without
17 1.1 christos * modification, are permitted provided that the following conditions
18 1.1 christos * are met:
19 1.1 christos * 1. Redistributions of source code must retain the above copyright
20 1.1 christos * notice, this list of conditions and the following disclaimer.
21 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 christos * notice, this list of conditions and the following disclaimer in the
23 1.1 christos * documentation and/or other materials provided with the distribution.
24 1.1 christos *
25 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
36 1.1 christos */
37 1.1 christos
38 1.1 christos #ifndef _COMMON_PMAP_TLB_VMPAGEMD_H_
39 1.1 christos #define _COMMON_PMAP_TLB_VMPAGEMD_H_
40 1.1 christos
41 1.1 christos #ifdef _LOCORE
42 1.1 christos #error use assym.h instead
43 1.1 christos #endif
44 1.1 christos
45 1.1 christos #ifdef _MODULE
46 1.1 christos #error this file should not be included by loadable kernel modules
47 1.1 christos #endif
48 1.1 christos
49 1.2 matt #ifdef _KERNEL_OPT
50 1.1 christos #include "opt_modular.h"
51 1.1 christos #include "opt_multiprocessor.h"
52 1.2 matt #endif
53 1.1 christos
54 1.1 christos #include <sys/mutex.h>
55 1.1 christos
56 1.1 christos #define __HAVE_VM_PAGE_MD
57 1.1 christos
58 1.1 christos typedef struct pv_entry {
59 1.1 christos struct pv_entry *pv_next;
60 1.1 christos struct pmap *pv_pmap;
61 1.1 christos vaddr_t pv_va;
62 1.1 christos } *pv_entry_t;
63 1.1 christos
64 1.1 christos #define VM_PAGEMD_REFERENCED 0x0001 /* page has been recently referenced */
65 1.1 christos #define VM_PAGEMD_MODIFIED 0x0002 /* page has been modified */
66 1.1 christos #define VM_PAGEMD_POOLPAGE 0x0004 /* page is used as a poolpage */
67 1.1 christos #define VM_PAGEMD_EXECPAGE 0x0008 /* page is exec mapped */
68 1.1 christos #ifdef __PMAP_VIRTUAL_CACHE_ALIASES
69 1.1 christos #define VM_PAGEMD_UNCACHED 0x0010 /* page is mapped uncached */
70 1.1 christos #endif
71 1.1 christos
72 1.1 christos #ifdef __PMAP_VIRTUAL_CACHE_ALIASES
73 1.1 christos #define VM_PAGEMD_CACHED_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_UNCACHED) == 0)
74 1.1 christos #define VM_PAGEMD_UNCACHED_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_UNCACHED) != 0)
75 1.1 christos #endif
76 1.1 christos #define VM_PAGEMD_MODIFIED_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_MODIFIED) != 0)
77 1.1 christos #define VM_PAGEMD_REFERENCED_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_REFERENCED) != 0)
78 1.1 christos #define VM_PAGEMD_POOLPAGE_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_POOLPAGE) != 0)
79 1.1 christos #define VM_PAGEMD_EXECPAGE_P(mdpg) (((mdpg)->mdpg_attrs & VM_PAGEMD_EXECPAGE) != 0)
80 1.1 christos
81 1.1 christos struct vm_page_md {
82 1.1 christos volatile u_int mdpg_attrs; /* page attributes */
83 1.1 christos struct pv_entry mdpg_first; /* pv_entry first */
84 1.1 christos #if defined(MULTIPROCESSOR) || defined(MODULAR)
85 1.1 christos kmutex_t *mdpg_lock; /* pv list lock */
86 1.1 christos #define VM_PAGEMD_PVLIST_LOCK_INIT(mdpg) \
87 1.1 christos (mdpg)->mdpg_lock = NULL
88 1.1 christos #define VM_PAGEMD_PVLIST_LOCK(pg, list_change) \
89 1.1 christos pmap_pvlist_lock(mdpg, list_change)
90 1.1 christos #define VM_PAGEMD_PVLIST_UNLOCK(mdpg) \
91 1.1 christos mutex_spin_exit((mdpg)->mdpg_lock)
92 1.1 christos #define VM_PAGEMD_PVLIST_LOCKED_P(mdpg) \
93 1.1 christos mutex_owner((mdpg)->mdpg_lock)
94 1.1 christos #define VM_PAGEMD_PVLIST_GEN(mdpg) \
95 1.1 christos ((uint16_t)((mdpg)->mdpg_attrs >> 16))
96 1.1 christos #else
97 1.1 christos #define VM_PAGEMD_PVLIST_LOCK_INIT(mdpg) do { } while (/*CONSTCOND*/ 0)
98 1.1 christos #define VM_PAGEMD_PVLIST_LOCK(mdpg, lc) (mutex_spin_enter(&pmap_pvlist_mutex), 0)
99 1.1 christos #define VM_PAGEMD_PVLIST_UNLOCK(mdpg) mutex_spin_exit(&pmap_pvlist_mutex)
100 1.1 christos #define VM_PAGEMD_PVLIST_LOCKED_P(mdpg) true
101 1.1 christos #define VM_PAGEMD_PVLIST_GEN(mdpg) (0)
102 1.1 christos #endif /* MULTIPROCESSOR || MODULAR */
103 1.1 christos };
104 1.1 christos
105 1.1 christos #define VM_MDPAGE_INIT(pg) \
106 1.1 christos do { \
107 1.1 christos (pg)->mdpage.mdpg_first.pv_next = NULL; \
108 1.1 christos (pg)->mdpage.mdpg_first.pv_pmap = NULL; \
109 1.1 christos (pg)->mdpage.mdpg_first.pv_va = (pg)->phys_addr; \
110 1.1 christos (pg)->mdpage.mdpg_attrs = 0; \
111 1.1 christos VM_PAGEMD_PVLIST_LOCK_INIT(&(pg)->mdpage); \
112 1.1 christos } while (/* CONSTCOND */ 0)
113 1.1 christos
114 1.1 christos #endif /* __COMMON_PMAP_TLB_VMPAGEMD_H_ */
115