kernel - Increase KVM default for 32-bit systems from 1GB to 1.5GB
[dragonfly.git] / sys / platform / pc32 / include / pmap.h
1 /*
2  * Copyright (c) 1991 Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * the Systems Programming Group of the University of Utah Computer
7  * Science Department and William Jolitz of UUNET Technologies Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed by the University of
20  *      California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  * Derived from hp300 version by Mike Hibler, this version by William
38  * Jolitz uses a recursive map [a pde points to the page directory] to
39  * map the page tables using the pagetables themselves. This is done to
40  * reduce the impact on kernel virtual memory for lots of sparse address
41  * space, and to reduce the cost of memory to each process.
42  *
43  * from: hp300: @(#)pmap.h      7.2 (Berkeley) 12/16/90
44  * from: @(#)pmap.h     7.4 (Berkeley) 5/12/91
45  * $FreeBSD: src/sys/i386/include/pmap.h,v 1.65.2.3 2001/10/03 07:15:37 peter Exp $
46  */
47
48 #ifndef _MACHINE_PMAP_H_
49 #define _MACHINE_PMAP_H_
50
51 #include <cpu/pmap.h>
52
53 /*
54  * Size of Kernel address space.  This is the number of page table pages
55  * (4MB each) to use for the kernel.  256 pages == 1 Gigabyte.
56  * This **MUST** be a multiple of 4 (eg: 252, 256, 260, etc).
57  *
58  * DEFAULT CHANGED 256->384.  32-bit systems have used 256 (1G KVM, 3G UVM)
59  * for many years, but all recent and continuing kernel development really
60  * assumes that more KVM is available.  In particularly, swapcache can be
61  * very effective on a 32-bit system with 64G or even more swap and 1GB of
62  * KVM just isn't enough to manage it.  Numerous subsystems such as tmpfs
63  * have higher overheads (e.g. when used with pourdriere), vnodes are fatter,
64  * mbufs are bigger and we need more of them, and the list goes on.  Even
65  * PCI space reservations have gone up due to Video subsystems.  On a
66  * freshly booted system well over 512MB of KVM is already reserved before
67  * the machine runs its first user process.
68  *
69  * The new default of 384 gives the kernel 1.5GB of KVM (2.5G UVM) and
70  * relieves the pressure on kernel structures.  This almost doubles the
71  * amount of KVM available to the kernel post-boot.
72  */
73 #ifndef KVA_PAGES
74 #define KVA_PAGES       384
75 #endif
76
77 /*
78  * PTE related macros
79  */
80 #define VADDR(pdi, pti) ((vm_offset_t)(((pdi)<<PDRSHIFT)|((pti)<<PAGE_SHIFT)))
81
82 #ifndef NKPT
83 #define NKPT            30                      /* starting general kptds */
84 #endif
85
86 #ifndef NKPDE
87 #define NKPDE   (KVA_PAGES - 2) /* max general kptds */
88 #endif
89 #if NKPDE > KVA_PAGES - 2
90 #error "Maximum NKPDE is KVA_PAGES - 2"
91 #endif
92
93 /*
94  * The *PTDI values control the layout of virtual memory
95  *
96  * NPEDEPG      - number of pde's in the page directory (1024)
97  * NKPDE        - max general kernel page table pages not including
98  *                special PTDs.  Typically KVA_PAGES minus the number
99  *                of special PTDs.
100  *
101  *      +---------------+ End of kernel memory
102  *      |   APTDPTDI    | alt page table map for cpu 0
103  *      +---------------+
104  *      |    MPPTDI     | globaldata array
105  *      +---------------+
106  *      |               |
107  *      |               |
108  *      |               |
109  *      |               | general kernel page table pages
110  *      |               |
111  *      |  KPTDI[NKPDE] |
112  *      +---------------+ Start of kernel memory
113  *      |    PTDPTDI    | self-mapping of current pmap
114  *      +---------------+
115  *
116  * This typically places PTDPTDI at the index corresponding to VM address
117  * (0xc0000000 - 4M) = bfc00000, and that is where PTmap[] is based for
118  * the self-mapped page table.  PTD points to the self-mapped page
119  * directory itself and any indexes >= KPTDI will correspond to the
120  * common kernel page directory pages since all pmaps map the same ones.
121  *
122  * APTmap / APTDpde are now used by cpu 0 as its alternative page table
123  * mapping via gd_GDMAP1 and GD_GDADDR1.  The remaining cpus allocate
124  * their own dynamically.
125  *
126  * Even though the maps are per-cpu the PTD entries are stored in the
127  * individual pmaps and obviously not replicated so each process pmap
128  * essentially gets its own per-cpu cache (PxN) making for fairly efficient
129  * access.
130  *
131  * UMAXPTDI     - highest inclusive ptd index for user space
132  */
133 #define APTDPTDI        (NPDEPG-1)      /* alt ptd entry that points to APTD */
134 #define MPPTDI          (APTDPTDI-1)    /* globaldata array ptd entry */
135 #define KPTDI           (MPPTDI-NKPDE)  /* start of kernel virtual pde's */
136 #define PTDPTDI         (KPTDI-1)       /* ptd entry that points to ptd! */
137 #define UMAXPTDI        (PTDPTDI-1)     /* ptd entry for user space end */
138
139 /*
140  * XXX doesn't really belong here I guess...
141  */
142 #define ISA_HOLE_START    0xa0000
143 #define ISA_HOLE_LENGTH (0x100000-ISA_HOLE_START)
144
145 #ifndef LOCORE
146
147 #ifndef _SYS_TYPES_H_
148 #include <sys/types.h>
149 #endif
150 #ifndef _SYS_QUEUE_H_
151 #include <sys/queue.h>
152 #endif
153 #ifndef _SYS_SPINLOCK_H_
154 #include <sys/spinlock.h>
155 #endif
156 #ifndef _SYS_THREAD_H_
157 #include <sys/thread.h>
158 #endif
159 #ifndef _MACHINE_TYPES_H_
160 #include <machine/types.h>
161 #endif
162 #ifndef _MACHINE_PARAM_H_
163 #include <machine/param.h>
164 #endif
165
166 /*
167  * Address of current and alternate address space page table maps
168  * and directories.
169  */
170 #ifdef _KERNEL
171 extern pt_entry_t PTmap[], APTmap[], Upte;
172 extern pd_entry_t PTD[], APTD[], PTDpde, APTDpde, Upde;
173
174 extern pd_entry_t IdlePTD;      /* physical address of "Idle" state directory */
175 #endif
176
177 #ifdef _KERNEL
178 /*
179  * virtual address to page table entry and
180  * to physical address. Likewise for alternate address space.
181  * Note: these work recursively, thus vtopte of a pte will give
182  * the corresponding pde that in turn maps it.
183  */
184 #define vtopte(va)      (PTmap + i386_btop(va))
185
186 #define avtopte(va)     (APTmap + i386_btop(va))
187
188 /*
189  *      Routine:        pmap_kextract
190  *      Function:
191  *              Extract the physical page address associated
192  *              kernel virtual address.
193  */
194 static __inline vm_paddr_t
195 pmap_kextract(vm_offset_t va)
196 {
197         vm_paddr_t pa;
198
199         if ((pa = (vm_offset_t) PTD[va >> PDRSHIFT]) & PG_PS) {
200                 pa = (pa & ~(NBPDR - 1)) | (va & (NBPDR - 1));
201         } else {
202                 pa = *(vm_offset_t *)vtopte(va);
203                 pa = (pa & PG_FRAME) | (va & PAGE_MASK);
204         }
205         return pa;
206 }
207
208 /*
209  * XXX
210  */
211 #define vtophys(va)     pmap_kextract(((vm_offset_t)(va)))
212 #define vtophys_pte(va) ((pt_entry_t)pmap_kextract(((vm_offset_t)(va))))
213
214 #endif
215
216 /*
217  * Pmap stuff
218  */
219 struct pv_entry;
220 struct vm_page;
221 struct vm_object;
222 struct vmspace;
223
224 struct md_page {
225         int pv_list_count;
226         TAILQ_HEAD(,pv_entry)   pv_list;
227 };
228
229 struct md_object {
230 };
231
232 /*
233  * Each machine dependent implementation is expected to
234  * keep certain statistics.  They may do this anyway they
235  * so choose, but are expected to return the statistics
236  * in the following structure.
237  *
238  * NOTE: We try to match the size of the pc32 pmap with the vkernel pmap
239  * so the same utilities (like 'ps') can be used on both.
240  */
241 struct pmap_statistics {
242         long resident_count;    /* # of pages mapped (total) */
243         long wired_count;       /* # of pages wired */
244 };
245 typedef struct pmap_statistics *pmap_statistics_t;
246
247 struct pmap {
248         pd_entry_t              *pm_pdir;       /* KVA of page directory */
249         struct vm_page          *pm_pdirm;      /* VM page for pg directory */
250         struct vm_object        *pm_pteobj;     /* Container for pte's */
251         TAILQ_ENTRY(pmap)       pm_pmnode;      /* list of pmaps */
252         TAILQ_HEAD(,pv_entry)   pm_pvlist;      /* list of mappings in pmap */
253         TAILQ_HEAD(,pv_entry)   pm_pvlist_free; /* free mappings */
254         int                     pm_count;       /* reference count */
255         cpumask_t               pm_active;      /* active on cpus */
256         cpumask_t               pm_cached;      /* cached on cpus */
257         int                     pm_filler02;    /* (filler sync w/vkernel) */
258         struct pmap_statistics  pm_stats;       /* pmap statistics */
259         struct  vm_page         *pm_ptphint;    /* pmap ptp hint */
260         int                     pm_generation;  /* detect pvlist deletions */
261         struct spinlock         pm_spin;
262         struct lwkt_token       pm_token;
263 };
264
265 #define pmap_resident_count(pmap) (pmap)->pm_stats.resident_count
266
267 #define CPUMASK_LOCK            CPUMASK(SMP_MAXCPU)
268 #define CPUMASK_BIT             SMP_MAXCPU      /* 1 << SMP_MAXCPU */
269
270 typedef struct pmap     *pmap_t;
271
272 #ifdef _KERNEL
273 extern struct pmap      kernel_pmap;
274 #endif
275
276 /*
277  * For each vm_page_t, there is a list of all currently valid virtual
278  * mappings of that page.  An entry is a pv_entry_t, the list is pv_table.
279  */
280 typedef struct pv_entry {
281         pmap_t          pv_pmap;        /* pmap where mapping lies */
282         vm_offset_t     pv_va;          /* virtual address for mapping */
283         TAILQ_ENTRY(pv_entry)   pv_list;
284         TAILQ_ENTRY(pv_entry)   pv_plist;
285         struct vm_page  *pv_ptem;       /* VM page for pte */
286 #ifdef PMAP_DEBUG
287         struct vm_page  *pv_m;
288 #else
289         void            *pv_dummy;      /* align structure to 32 bytes */
290 #endif
291 } *pv_entry_t;
292
293 #ifdef  _KERNEL
294
295 #define NPPROVMTRR              8
296 #define PPRO_VMTRRphysBase0     0x200
297 #define PPRO_VMTRRphysMask0     0x201
298 struct ppro_vmtrr {
299         u_int64_t base, mask;
300 };
301 extern struct ppro_vmtrr PPro_vmtrr[NPPROVMTRR];
302
303 extern caddr_t  CADDR1;
304 extern pt_entry_t *CMAP1;
305 extern vm_paddr_t dump_avail[];
306 extern vm_paddr_t avail_end;
307 extern vm_paddr_t avail_start;
308 extern vm_offset_t clean_eva;
309 extern vm_offset_t clean_sva;
310 extern char *ptvmmap;           /* poor name! */
311
312 void    pmap_release(struct pmap *pmap);
313 void    pmap_interlock_wait (struct vmspace *);
314 void    pmap_bootstrap (vm_paddr_t, vm_paddr_t);
315 void    *pmap_mapdev (vm_paddr_t, vm_size_t);
316 void    *pmap_mapdev_uncacheable (vm_paddr_t, vm_size_t);
317 void    pmap_unmapdev (vm_offset_t, vm_size_t);
318 unsigned *pmap_kernel_pte (vm_offset_t) __pure2;
319 struct vm_page *pmap_use_pt (pmap_t, vm_offset_t);
320 int     pmap_get_pgeflag(void);
321 void    pmap_set_opt (void);
322
323 #endif /* _KERNEL */
324
325 #endif /* !LOCORE */
326
327 #endif /* !_MACHINE_PMAP_H_ */