xref: /freebsd/sys/i386/include/pmap_pae.h (revision 9a52756044676370f20527b85d450d5fc3ac32e5)
1*9a527560SKonstantin Belousov /*-
2*9a527560SKonstantin Belousov  * SPDX-License-Identifier: BSD-3-Clause
3*9a527560SKonstantin Belousov  *
4*9a527560SKonstantin Belousov  * Copyright (c) 1991 Regents of the University of California.
5*9a527560SKonstantin Belousov  * All rights reserved.
6*9a527560SKonstantin Belousov  *
7*9a527560SKonstantin Belousov  * Copyright (c) 2018 The FreeBSD Foundation
8*9a527560SKonstantin Belousov  * All rights reserved.
9*9a527560SKonstantin Belousov  *
10*9a527560SKonstantin Belousov  * This code is derived from software contributed to Berkeley by
11*9a527560SKonstantin Belousov  * the Systems Programming Group of the University of Utah Computer
12*9a527560SKonstantin Belousov  * Science Department and William Jolitz of UUNET Technologies Inc.
13*9a527560SKonstantin Belousov  *
14*9a527560SKonstantin Belousov  * Portions of this software were developed by
15*9a527560SKonstantin Belousov  * Konstantin Belousov <kib@FreeBSD.org> under sponsorship from
16*9a527560SKonstantin Belousov  * the FreeBSD Foundation.
17*9a527560SKonstantin Belousov  *
18*9a527560SKonstantin Belousov  * Redistribution and use in source and binary forms, with or without
19*9a527560SKonstantin Belousov  * modification, are permitted provided that the following conditions
20*9a527560SKonstantin Belousov  * are met:
21*9a527560SKonstantin Belousov  * 1. Redistributions of source code must retain the above copyright
22*9a527560SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer.
23*9a527560SKonstantin Belousov  * 2. Redistributions in binary form must reproduce the above copyright
24*9a527560SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer in the
25*9a527560SKonstantin Belousov  *    documentation and/or other materials provided with the distribution.
26*9a527560SKonstantin Belousov  * 3. Neither the name of the University nor the names of its contributors
27*9a527560SKonstantin Belousov  *    may be used to endorse or promote products derived from this software
28*9a527560SKonstantin Belousov  *    without specific prior written permission.
29*9a527560SKonstantin Belousov  *
30*9a527560SKonstantin Belousov  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31*9a527560SKonstantin Belousov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32*9a527560SKonstantin Belousov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33*9a527560SKonstantin Belousov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34*9a527560SKonstantin Belousov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35*9a527560SKonstantin Belousov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36*9a527560SKonstantin Belousov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37*9a527560SKonstantin Belousov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38*9a527560SKonstantin Belousov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39*9a527560SKonstantin Belousov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40*9a527560SKonstantin Belousov  * SUCH DAMAGE.
41*9a527560SKonstantin Belousov  *
42*9a527560SKonstantin Belousov  * Derived from hp300 version by Mike Hibler, this version by William
43*9a527560SKonstantin Belousov  * Jolitz uses a recursive map [a pde points to the page directory] to
44*9a527560SKonstantin Belousov  * map the page tables using the pagetables themselves. This is done to
45*9a527560SKonstantin Belousov  * reduce the impact on kernel virtual memory for lots of sparse address
46*9a527560SKonstantin Belousov  * space, and to reduce the cost of memory to each process.
47*9a527560SKonstantin Belousov  *
48*9a527560SKonstantin Belousov  *	from: hp300: @(#)pmap.h	7.2 (Berkeley) 12/16/90
49*9a527560SKonstantin Belousov  *	from: @(#)pmap.h	7.4 (Berkeley) 5/12/91
50*9a527560SKonstantin Belousov  * $FreeBSD$
51*9a527560SKonstantin Belousov  */
52*9a527560SKonstantin Belousov 
53*9a527560SKonstantin Belousov #ifndef _MACHINE_PMAP_PAE_H
54*9a527560SKonstantin Belousov #define	_MACHINE_PMAP_PAE_H
55*9a527560SKonstantin Belousov 
56*9a527560SKonstantin Belousov #define	NTRPPTD		2		/* Number of PTDs for trampoline
57*9a527560SKonstantin Belousov 					   mapping */
58*9a527560SKonstantin Belousov #define	LOWPTDI		2		/* low memory map pde */
59*9a527560SKonstantin Belousov #define	KERNPTDI	4		/* start of kernel text pde */
60*9a527560SKonstantin Belousov 
61*9a527560SKonstantin Belousov #define NPGPTD		4		/* Num of pages for page directory */
62*9a527560SKonstantin Belousov #define NPGPTD_SHIFT	9
63*9a527560SKonstantin Belousov #undef	PDRSHIFT
64*9a527560SKonstantin Belousov #define	PDRSHIFT	PDRSHIFT_PAE
65*9a527560SKonstantin Belousov #undef	NBPDR
66*9a527560SKonstantin Belousov #define NBPDR		(1 << PDRSHIFT_PAE)	/* bytes/page dir */
67*9a527560SKonstantin Belousov 
68*9a527560SKonstantin Belousov #define	PG_FRAME	PG_FRAME_PAE
69*9a527560SKonstantin Belousov #define	PG_PS_FRAME	PG_PS_FRAME_PAE
70*9a527560SKonstantin Belousov 
71*9a527560SKonstantin Belousov /*
72*9a527560SKonstantin Belousov  * Size of Kernel address space.  This is the number of page table pages
73*9a527560SKonstantin Belousov  * (4MB each) to use for the kernel.  256 pages == 1 Gigabyte.
74*9a527560SKonstantin Belousov  * This **MUST** be a multiple of 4 (eg: 252, 256, 260, etc).
75*9a527560SKonstantin Belousov  * For PAE, the page table page unit size is 2MB.  This means that 512 pages
76*9a527560SKonstantin Belousov  * is 1 Gigabyte.  Double everything.  It must be a multiple of 8 for PAE.
77*9a527560SKonstantin Belousov  */
78*9a527560SKonstantin Belousov #define KVA_PAGES	(512*4)
79*9a527560SKonstantin Belousov 
80*9a527560SKonstantin Belousov /*
81*9a527560SKonstantin Belousov  * The initial number of kernel page table pages that are constructed
82*9a527560SKonstantin Belousov  * by pmap_cold() must be sufficient to map vm_page_array.  That number can
83*9a527560SKonstantin Belousov  * be calculated as follows:
84*9a527560SKonstantin Belousov  *     max_phys / PAGE_SIZE * sizeof(struct vm_page) / NBPDR
85*9a527560SKonstantin Belousov  * PAE:      max_phys 16G, sizeof(vm_page) 76, NBPDR 2M, 152 page table pages.
86*9a527560SKonstantin Belousov  * PAE_TABLES: max_phys 4G,  sizeof(vm_page) 68, NBPDR 2M, 36 page table pages.
87*9a527560SKonstantin Belousov  * Non-PAE:  max_phys 4G,  sizeof(vm_page) 68, NBPDR 4M, 18 page table pages.
88*9a527560SKonstantin Belousov  */
89*9a527560SKonstantin Belousov #ifndef NKPT
90*9a527560SKonstantin Belousov #define	NKPT		240
91*9a527560SKonstantin Belousov #endif
92*9a527560SKonstantin Belousov 
93*9a527560SKonstantin Belousov typedef uint64_t pdpt_entry_t;
94*9a527560SKonstantin Belousov typedef uint64_t pd_entry_t;
95*9a527560SKonstantin Belousov typedef uint64_t pt_entry_t;
96*9a527560SKonstantin Belousov 
97*9a527560SKonstantin Belousov #define	PTESHIFT	(3)
98*9a527560SKonstantin Belousov #define	PDESHIFT	(3)
99*9a527560SKonstantin Belousov 
100*9a527560SKonstantin Belousov #define	pde_cmpset(pdep, old, new)	atomic_cmpset_64_i586(pdep, old, new)
101*9a527560SKonstantin Belousov #define	pte_load_store(ptep, pte)	atomic_swap_64_i586(ptep, pte)
102*9a527560SKonstantin Belousov #define	pte_load_clear(ptep)		atomic_swap_64_i586(ptep, 0)
103*9a527560SKonstantin Belousov #define	pte_store(ptep, pte)		atomic_store_rel_64_i586(ptep, pte)
104*9a527560SKonstantin Belousov #define	pte_load(ptep)			atomic_load_acq_64_i586(ptep)
105*9a527560SKonstantin Belousov 
106*9a527560SKonstantin Belousov extern pdpt_entry_t *IdlePDPT;
107*9a527560SKonstantin Belousov extern pt_entry_t pg_nx;
108*9a527560SKonstantin Belousov extern pd_entry_t *IdlePTD_pae;	/* physical address of "Idle" state directory */
109*9a527560SKonstantin Belousov 
110*9a527560SKonstantin Belousov /*
111*9a527560SKonstantin Belousov  * KPTmap is a linear mapping of the kernel page table.  It differs from the
112*9a527560SKonstantin Belousov  * recursive mapping in two ways: (1) it only provides access to kernel page
113*9a527560SKonstantin Belousov  * table pages, and not user page table pages, and (2) it provides access to
114*9a527560SKonstantin Belousov  * a kernel page table page after the corresponding virtual addresses have
115*9a527560SKonstantin Belousov  * been promoted to a 2/4MB page mapping.
116*9a527560SKonstantin Belousov  *
117*9a527560SKonstantin Belousov  * KPTmap is first initialized by pmap_cold() to support just NPKT page table
118*9a527560SKonstantin Belousov  * pages.  Later, it is reinitialized by pmap_bootstrap() to allow for
119*9a527560SKonstantin Belousov  * expansion of the kernel page table.
120*9a527560SKonstantin Belousov  */
121*9a527560SKonstantin Belousov extern pt_entry_t *KPTmap_pae;
122*9a527560SKonstantin Belousov 
123*9a527560SKonstantin Belousov #endif
124