vmparam.h revision 1.4
1/*	$NetBSD: vmparam.h,v 1.4 2011/06/05 16:52:25 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#include <sys/mutex.h>
41
42/*
43 * Most of the definitions in this can be overriden by a machine-specific
44 * vmparam.h if required.  Otherwise a port can just include this file
45 * get the right thing to happen.
46 */
47
48/*
49 * BookE processors have 4K pages.  Override the PAGE_* definitions to be
50 * compile-time constants.
51 */
52#define	PAGE_SHIFT	12
53#define	PAGE_SIZE	(1 << PAGE_SHIFT)
54#define	PAGE_MASK	(PAGE_SIZE - 1)
55
56#ifndef	USRSTACK
57#define	USRSTACK	VM_MAXUSER_ADDRESS
58#endif
59
60#ifndef	MAXTSIZ
61#define	MAXTSIZ		(2*256*1024*1024)	/* maximum text size */
62#endif
63
64#ifndef	MAXDSIZ
65#define	MAXDSIZ		(13*256*1024*1024U)	/* maximum data size */
66#endif
67
68#ifndef	MAXSSIZ
69#define	MAXSSIZ		(1*256*1024*1024-PAGE_SIZE) /* maximum stack size */
70#endif
71
72#ifndef	DFLDSIZ
73#define	DFLDSIZ		(256*1024*1024)		/* default data size */
74#endif
75
76#ifndef	DFLSSIZ
77#define	DFLSSIZ		(2*1024*1024)		/* default stack size */
78#endif
79
80/*
81 * Default number of pages in the user raw I/O map.
82 */
83#ifndef USRIOSIZE
84#define	USRIOSIZE	1024
85#endif
86
87/*
88 * The number of seconds for a process to be blocked before being
89 * considered very swappable.
90 */
91#ifndef MAXSLP
92#define	MAXSLP		20
93#endif
94
95/*
96 * Some system constants
97 */
98
99#define	VM_MIN_ADDRESS		((vaddr_t) 0)
100#define	VM_MAXUSER_ADDRESS	((vaddr_t) /* -32768 */ 0x7fff8000)
101#define	VM_MAX_ADDRESS		VM_MAXUSER_ADDRESS
102#define	VM_MIN_KERNEL_ADDRESS	((vaddr_t) 0xe4000000)
103#define	VM_MAX_KERNEL_ADDRESS	((vaddr_t) 0xfefff000)
104
105/*
106 * The address to which unspecified mapping requests default
107 * Put the stack in it's own segment and start mmaping at the
108 * top of the next lower segment.
109 */
110#ifdef _KERNEL_OPT
111#include "opt_uvm.h"
112#endif
113#define	__USE_TOPDOWN_VM
114#define	VM_DEFAULT_ADDRESS(da, sz) \
115	((VM_MAXUSER_ADDRESS - MAXSSIZ) - round_page(sz))
116
117#ifndef VM_PHYSSEG_MAX
118#define	VM_PHYSSEG_MAX		16
119#endif
120#define	VM_PHYSSEG_STRAT	VM_PSTRAT_BIGFIRST
121
122#ifndef VM_PHYS_SIZE
123#define	VM_PHYS_SIZE		(USRIOSIZE * PAGE_SIZE)
124#endif
125
126#define	VM_NFREELIST		2	/* 16 distinct memory segments */
127#define	VM_FREELIST_DEFAULT	0
128#define	VM_FREELIST_FIRST16	1
129#define	VM_FREELIST_MAX		2
130
131#ifndef VM_NFREELIST
132#define	VM_NFREELIST		16	/* 16 distinct memory segments */
133#define VM_FREELIST_DEFAULT	0
134#define VM_FREELIST_MAX		1
135#endif
136
137#define	__HAVE_VM_PAGE_MD
138#ifndef _LOCORE
139
140typedef struct pv_entry {
141	struct pv_entry *pv_next;
142	struct pmap *pv_pmap;
143	vaddr_t pv_va;
144} *pv_entry_t;
145
146#define	VM_PAGE_MD_REFERENCED	0x0001	/* page has been recently referenced */
147#define	VM_PAGE_MD_MODIFIED	0x0002	/* page has been modified */
148#define	VM_PAGE_MD_POOLPAGE	0x0004	/* page is used as a poolpage */
149#define	VM_PAGE_MD_EXECPAGE	0x0008	/* page is exec mapped */
150#if 0
151#define	VM_PAGE_MD_UNCACHED	0x0010	/* page is mapped uncached */
152#endif
153
154#ifdef VM_PAGE_MD_UNCACHED
155#define	VM_PAGE_MD_CACHED_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_UNCACHED) == 0)
156#define	VM_PAGE_MD_UNCACHED_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_UNCACHED) != 0)
157#endif
158#define	VM_PAGE_MD_MODIFIED_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_MODIFIED) != 0)
159#define	VM_PAGE_MD_REFERENCED_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_REFERENCED) != 0)
160#define	VM_PAGE_MD_POOLPAGE_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_POOLPAGE) != 0)
161#define	VM_PAGE_MD_EXECPAGE_P(pg)	(((pg)->mdpage.mdpg_attrs & VM_PAGE_MD_EXECPAGE) != 0)
162
163struct vm_page_md {
164	struct pv_entry mdpg_first;	/* pv_entry first */
165#ifdef MULTIPROCESSOR
166	volatile u_int mdpg_attrs;	/* page attributes */
167	kmutex_t *mdpg_lock;		/* pv list lock */
168#define	VM_PAGE_PVLIST_LOCK_INIT(pg) 		\
169	(pg)->mdpage.mdpg_lock = NULL
170#define	VM_PAGE_PVLIST_LOCKED_P(pg)		\
171	(mutex_owner((pg)->mdpage.mdpg_lock) != 0)
172#define	VM_PAGE_PVLIST_LOCK(pg, list_change)	\
173	pmap_pvlist_lock(pg, list_change)
174#define	VM_PAGE_PVLIST_UNLOCK(pg)		\
175	mutex_spin_exit((pg)->mdpage.mdpg_lock);
176#define	VM_PAGE_PVLIST_GEN(pg)		((uint16_t)(pg->mdpage.mdpg_attrs >> 16))
177#else
178	u_int mdpg_attrs;		/* page attributes */
179#define	VM_PAGE_PVLIST_LOCK_INIT(pg)	do { } while (/*CONSTCOND*/ 0)
180#define	VM_PAGE_PVLIST_LOCKED_P(pg)	true
181#define	VM_PAGE_PVLIST_LOCK(pg, lc)	(mutex_spin_enter(&pmap_pvlist_mutex), 0)
182#define	VM_PAGE_PVLIST_UNLOCK(pg)	mutex_spin_exit(&pmap_pvlist_mutex)
183#define	VM_PAGE_PVLIST_GEN(pg)		(0)
184#endif
185};
186
187#define VM_MDPAGE_INIT(pg)						\
188do {									\
189	(pg)->mdpage.mdpg_first.pv_next = NULL;				\
190	(pg)->mdpage.mdpg_first.pv_pmap = NULL;				\
191	(pg)->mdpage.mdpg_first.pv_va = (pg)->phys_addr;			\
192	VM_PAGE_PVLIST_LOCK_INIT(pg);					\
193	(pg)->mdpage.mdpg_attrs = 0;					\
194} while (/* CONSTCOND */ 0)
195
196#endif /* _LOCORE */
197
198#endif /* _POWERPC_BOOKE_VMPARAM_H_ */
199