2 * Copyright (c) 1991 Regents of the University of California.
3 * Copyright (c) 2008 The DragonFly Project.
6 * This code is derived from software contributed to Berkeley by
7 * the Systems Programming Group of the University of Utah Computer
8 * Science Department and William Jolitz of UUNET Technologies Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * Derived from hp300 version by Mike Hibler, this version by William
39 * Jolitz uses a recursive map [a pde points to the page directory] to
40 * map the page tables using the pagetables themselves. This is done to
41 * reduce the impact on kernel virtual memory for lots of sparse address
42 * space, and to reduce the cost of memory to each process.
44 * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90
45 * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91
46 * $FreeBSD: src/sys/i386/include/pmap.h,v 1.65.2.3 2001/10/03 07:15:37 peter Exp $
47 * $DragonFly: src/sys/platform/pc64/include/pmap.h,v 1.1 2008/08/29 17:07:17 dillon Exp $
50 #ifndef _MACHINE_PMAP_H_
51 #define _MACHINE_PMAP_H_
56 * Size of Kernel address space. This is the number of page table pages
57 * (2MB each) to use for the kernel. 256 pages == 512 Megabyte.
58 * This **MUST** be a multiple of 4 (eg: 252, 256, 260, etc).
67 #define VADDR(pdi, pti) ((vm_offset_t)(((pdi)<<PDRSHIFT)|((pti)<<PAGE_SHIFT)))
70 #define NKPT 30 /* actual number of kernel page tables */
73 #define NKPDE (KVA_PAGES - 2) /* addressable number of page tables/pde's */
75 #if NKPDE > KVA_PAGES - 2
76 #error "Maximum NKPDE is KVA_PAGES - 2"
80 * The *PTDI values control the layout of virtual memory
82 * XXX This works for now, but I am not real happy with it, I'll fix it
83 * right after I fix locore.s and the magic 28K hole
85 * SMP_PRIVPAGES: The per-cpu address space is 0xff80000 -> 0xffbfffff
87 #define APTDPTDI (NPDEPG-1) /* alt ptd entry that points to APTD */
88 #define MPPTDI (APTDPTDI-1) /* per cpu ptd entry */
89 #define KPTDI (MPPTDI-NKPDE) /* start of kernel virtual pde's */
90 #define PTDPTDI (KPTDI-1) /* ptd entry that points to ptd! */
91 #define UMAXPTDI (PTDPTDI-1) /* ptd entry for user space end */
92 #define UMAXPTEOFF (NPTEPG) /* pte entry for user space end */
98 * XXX doesn't really belong here I guess...
100 #define ISA_HOLE_START 0xa0000
101 #define ISA_HOLE_LENGTH (0x100000-ISA_HOLE_START)
105 #ifndef _SYS_TYPES_H_
106 #include <sys/types.h>
108 #ifndef _SYS_QUEUE_H_
109 #include <sys/queue.h>
111 #ifndef _MACHINE_TYPES_H_
112 #include <machine/types.h>
114 #ifndef _MACHINE_PARAM_H_
115 #include <machine/param.h>
119 * Address of current and alternate address space page table maps
123 extern pt_entry_t PTmap[], APTmap[], Upte;
124 extern pd_entry_t PTD[], APTD[], PTDpde, APTDpde, Upde;
126 extern uint64_t IdlePTD; /* physical address of "Idle" state directory */
128 extern uint64_t common_lvl4_phys;
129 extern uint64_t common_lvl3_phys;
130 extern pdp_entry_t *link_pdpe;
135 * virtual address to page table entry and
136 * to physical address. Likewise for alternate address space.
137 * Note: these work recursively, thus vtopte of a pte will give
138 * the corresponding pde that in turn maps it.
140 #define vtopte(va) (PTmap + amd64_btop(va))
142 #define avtopte(va) (APTmap + amd64_btop(va))
145 * Routine: pmap_kextract
147 * Extract the physical page address associated
148 * kernel virtual address.
150 static __inline vm_paddr_t
151 pmap_kextract(vm_offset_t va)
155 if ((pa = (vm_offset_t) PTD[va >> PDRSHIFT]) & PG_PS) {
156 pa = (pa & ~(NBPDR - 1)) | (va & (NBPDR - 1));
158 pa = *(vm_offset_t *)vtopte(va);
159 pa = (pa & PG_FRAME) | (va & PAGE_MASK);
167 #define vtophys(va) pmap_kextract(((vm_offset_t)(va)))
168 #define vtophys_pte(va) ((pt_entry_t)pmap_kextract(((vm_offset_t)(va))))
172 #define pte_load_clear(pte) atomic_readandclear_long(pte)
183 TAILQ_HEAD(,pv_entry) pv_list;
187 * Each machine dependent implementation is expected to
188 * keep certain statistics. They may do this anyway they
189 * so choose, but are expected to return the statistics
190 * in the following structure.
192 * NOTE: We try to match the size of the pc32 pmap with the vkernel pmap
193 * so the same utilities (like 'ps') can be used on both.
195 struct pmap_statistics {
196 long resident_count; /* # of pages mapped (total) */
197 long wired_count; /* # of pages wired */
199 typedef struct pmap_statistics *pmap_statistics_t;
202 pd_entry_t *pm_pdir; /* KVA of page directory */
203 struct vm_page *pm_pdirm; /* VM page for pg directory */
204 struct vm_object *pm_pteobj; /* Container for pte's */
205 TAILQ_ENTRY(pmap) pm_pmnode; /* list of pmaps */
206 TAILQ_HEAD(,pv_entry) pm_pvlist; /* list of mappings in pmap */
207 int pm_count; /* reference count */
208 cpumask_t pm_active; /* active on cpus */
209 int pm_filler02; /* (filler sync w/vkernel) */
210 struct pmap_statistics pm_stats; /* pmap statistics */
211 struct vm_page *pm_ptphint; /* pmap ptp hint */
212 int pm_generation; /* detect pvlist deletions */
215 #define pmap_resident_count(pmap) (pmap)->pm_stats.resident_count
217 typedef struct pmap *pmap_t;
220 extern struct pmap kernel_pmap;
224 * For each vm_page_t, there is a list of all currently valid virtual
225 * mappings of that page. An entry is a pv_entry_t, the list is pv_table.
227 typedef struct pv_entry {
228 pmap_t pv_pmap; /* pmap where mapping lies */
229 vm_offset_t pv_va; /* virtual address for mapping */
230 TAILQ_ENTRY(pv_entry) pv_list;
231 TAILQ_ENTRY(pv_entry) pv_plist;
232 struct vm_page *pv_ptem; /* VM page for pte */
238 #define PPRO_VMTRRphysBase0 0x200
239 #define PPRO_VMTRRphysMask0 0x201
241 u_int64_t base, mask;
243 extern struct ppro_vmtrr PPro_vmtrr[NPPROVMTRR];
245 extern caddr_t CADDR1;
246 extern pt_entry_t *CMAP1;
247 extern vm_paddr_t avail_end;
248 extern vm_paddr_t avail_start;
249 extern vm_offset_t clean_eva;
250 extern vm_offset_t clean_sva;
251 extern char *ptvmmap; /* poor name! */
253 void pmap_bootstrap ( vm_paddr_t *, vm_paddr_t);
254 void *pmap_mapdev (vm_paddr_t, vm_size_t);
255 void pmap_unmapdev (vm_offset_t, vm_size_t);
256 pt_entry_t *pmap_pte (pmap_t, vm_offset_t) __pure2;
257 struct vm_page *pmap_use_pt (pmap_t, vm_offset_t);
259 void pmap_set_opt (void);
266 #endif /* !_MACHINE_PMAP_H_ */