xref: /netbsd/sys/arch/powerpc/include/booke/vmparam.h (revision 6550d01e)
1 /*	$NetBSD: vmparam.h,v 1.3 2011/01/18 01:02:54 matt Exp $	*/
2 /*-
3  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to The NetBSD Foundation
7  * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
8  * Agency and which was developed by Matt Thomas of 3am Software Foundry.
9  *
10  * This material is based upon work supported by the Defense Advanced Research
11  * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
12  * Contract No. N66001-09-C-2073.
13  * Approved for Public Release, Distribution Unlimited
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the distribution.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #ifndef _POWERPC_BOOKE_VMPARAM_H_
38 #define _POWERPC_BOOKE_VMPARAM_H_
39 
40 /*
41  * Most of the definitions in this can be overriden by a machine-specific
42  * vmparam.h if required.  Otherwise a port can just include this file
43  * get the right thing to happen.
44  */
45 
46 /*
47  * BookE processors have 4K pages.  Override the PAGE_* definitions to be
48  * compile-time constants.
49  */
50 #define	PAGE_SHIFT	12
51 #define	PAGE_SIZE	(1 << PAGE_SHIFT)
52 #define	PAGE_MASK	(PAGE_SIZE - 1)
53 
54 #ifndef	USRSTACK
55 #define	USRSTACK	VM_MAXUSER_ADDRESS
56 #endif
57 
58 #ifndef	MAXTSIZ
59 #define	MAXTSIZ		(2*256*1024*1024)	/* maximum text size */
60 #endif
61 
62 #ifndef	MAXDSIZ
63 #define	MAXDSIZ		(13*256*1024*1024U)	/* maximum data size */
64 #endif
65 
66 #ifndef	MAXSSIZ
67 #define	MAXSSIZ		(1*256*1024*1024-PAGE_SIZE) /* maximum stack size */
68 #endif
69 
70 #ifndef	DFLDSIZ
71 #define	DFLDSIZ		(256*1024*1024)		/* default data size */
72 #endif
73 
74 #ifndef	DFLSSIZ
75 #define	DFLSSIZ		(2*1024*1024)		/* default stack size */
76 #endif
77 
78 /*
79  * Default number of pages in the user raw I/O map.
80  */
81 #ifndef USRIOSIZE
82 #define	USRIOSIZE	1024
83 #endif
84 
85 /*
86  * The number of seconds for a process to be blocked before being
87  * considered very swappable.
88  */
89 #ifndef MAXSLP
90 #define	MAXSLP		20
91 #endif
92 
93 /*
94  * Some system constants
95  */
96 
97 #define	VM_MIN_ADDRESS		((vaddr_t) 0)
98 #define	VM_MAXUSER_ADDRESS	((vaddr_t) /* -32768 */ 0x7fff8000)
99 #define	VM_MAX_ADDRESS		VM_MAXUSER_ADDRESS
100 #define	VM_MIN_KERNEL_ADDRESS	((vaddr_t) 0xe4000000)
101 #define	VM_MAX_KERNEL_ADDRESS	((vaddr_t) 0xfefff000)
102 
103 /*
104  * The address to which unspecified mapping requests default
105  * Put the stack in it's own segment and start mmaping at the
106  * top of the next lower segment.
107  */
108 #ifdef _KERNEL_OPT
109 #include "opt_uvm.h"
110 #endif
111 #define	__USE_TOPDOWN_VM
112 #define	VM_DEFAULT_ADDRESS(da, sz) \
113 	((VM_MAXUSER_ADDRESS - MAXSSIZ) - round_page(sz))
114 
115 #ifndef VM_PHYSSEG_MAX
116 #define	VM_PHYSSEG_MAX		16
117 #endif
118 #define	VM_PHYSSEG_STRAT	VM_PSTRAT_BIGFIRST
119 
120 #ifndef VM_PHYS_SIZE
121 #define	VM_PHYS_SIZE		(USRIOSIZE * PAGE_SIZE)
122 #endif
123 
124 #define	VM_NFREELIST		2	/* 16 distinct memory segments */
125 #define	VM_FREELIST_DEFAULT	0
126 #define	VM_FREELIST_FIRST16	1
127 #define	VM_FREELIST_MAX		2
128 
129 #ifndef VM_NFREELIST
130 #define	VM_NFREELIST		16	/* 16 distinct memory segments */
131 #define VM_FREELIST_DEFAULT	0
132 #define VM_FREELIST_MAX		1
133 #endif
134 
135 #define	__HAVE_VM_PAGE_MD
136 #ifndef _LOCORE
137 
138 typedef struct pv_entry {
139 	struct pv_entry *pv_next;
140 	struct pmap *pv_pmap;
141 	vaddr_t pv_va;
142 } *pv_entry_t;
143 
144 #define	VM_PAGE_MD_REFERENCED	0x0001	/* page has been recently referenced */
145 #define	VM_PAGE_MD_MODIFIED	0x0002	/* page has been modified */
146 #define	VM_PAGE_MD_POOLPAGE	0x0004	/* page is used as a poolpage */
147 #define	VM_PAGE_MD_EXECPAGE	0x0008	/* page is exec mapped */
148 #if 0
149 #define	VM_PAGE_MD_UNCACHED	0x0010	/* page is mapped uncached */
150 #endif
151 
152 #ifdef VM_PAGE_MD_UNCACHED
153 #define	VM_PAGE_MD_CACHED_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_UNCACHED) == 0)
154 #define	VM_PAGE_MD_UNCACHED_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_UNCACHED) != 0)
155 #endif
156 #define	VM_PAGE_MD_MODIFIED_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_MODIFIED) != 0)
157 #define	VM_PAGE_MD_REFERENCED_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_REFERENCED) != 0)
158 #define	VM_PAGE_MD_POOLPAGE_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_POOLPAGE) != 0)
159 #define	VM_PAGE_MD_EXECPAGE_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_EXECPAGE) != 0)
160 
161 struct vm_page_md {
162 	struct pv_entry mdpg_first;	/* pv_entry first */
163 #ifdef MULTIPROCESSOR
164 	volatile u_int mdpg_attrs;	/* page attributes */
165 	kmutex_t *mdpg_lock;		/* pv list lock */
166 #define	VM_PAGE_PVLIST_LOCK_INIT(pg) 		\
167 	(pg)->mdpage.mdpg_lock = NULL
168 #define	VM_PAGE_PVLIST_LOCKED_P(pg)		\
169 	(mutex_owner((pg)->mdpage.mdpg_lock) != 0)
170 #define	VM_PAGE_PVLIST_LOCK(pg, list_change)	\
171 	pmap_pvlist_lock(pg, list_change)
172 #define	VM_PAGE_PVLIST_UNLOCK(pg)		\
173 	mutex_spin_exit((pg)->mdpage.mdpg_lock);
174 #define	VM_PAGE_PVLIST_GEN(pg)		((uint16_t)(pg->mdpage.mdpg_attrs >> 16))
175 #else
176 	u_int mdpg_attrs;		/* page attributes */
177 #define	VM_PAGE_PVLIST_LOCK_INIT(pg)	do { } while (/*CONSTCOND*/ 0)
178 #define	VM_PAGE_PVLIST_LOCKED_P(pg)	true
179 #define	VM_PAGE_PVLIST_LOCK(pg, lc)	(mutex_spin_enter(&pmap_pvlist_mutex), 0)
180 #define	VM_PAGE_PVLIST_UNLOCK(pg)	mutex_spin_exit(&pmap_pvlist_mutex)
181 #define	VM_PAGE_PVLIST_GEN(pg)		(0)
182 #endif
183 };
184 
185 #define VM_MDPAGE_INIT(pg)						\
186 do {									\
187 	(pg)->mdpage.mdpg_first.pv_next = NULL;				\
188 	(pg)->mdpage.mdpg_first.pv_pmap = NULL;				\
189 	(pg)->mdpage.mdpg_first.pv_va = (pg)->phys_addr;			\
190 	VM_PAGE_PVLIST_LOCK_INIT(pg);					\
191 	(pg)->mdpage.mdpg_attrs = 0;					\
192 } while (/* CONSTCOND */ 0)
193 
194 #endif /* _LOCORE */
195 
196 #endif /* _POWERPC_BOOKE_VMPARAM_H_ */
197