xref: /freebsd/sys/i386/include/pmap_pae.h (revision 29363fb446372cb3f10bc98664e9767c53fbb457)
19a527560SKonstantin Belousov /*-
29a527560SKonstantin Belousov  * SPDX-License-Identifier: BSD-3-Clause
39a527560SKonstantin Belousov  *
49a527560SKonstantin Belousov  * Copyright (c) 1991 Regents of the University of California.
59a527560SKonstantin Belousov  * All rights reserved.
69a527560SKonstantin Belousov  *
79a527560SKonstantin Belousov  * Copyright (c) 2018 The FreeBSD Foundation
89a527560SKonstantin Belousov  * All rights reserved.
99a527560SKonstantin Belousov  *
109a527560SKonstantin Belousov  * This code is derived from software contributed to Berkeley by
119a527560SKonstantin Belousov  * the Systems Programming Group of the University of Utah Computer
129a527560SKonstantin Belousov  * Science Department and William Jolitz of UUNET Technologies Inc.
139a527560SKonstantin Belousov  *
149a527560SKonstantin Belousov  * Portions of this software were developed by
159a527560SKonstantin Belousov  * Konstantin Belousov <kib@FreeBSD.org> under sponsorship from
169a527560SKonstantin Belousov  * the FreeBSD Foundation.
179a527560SKonstantin Belousov  *
189a527560SKonstantin Belousov  * Redistribution and use in source and binary forms, with or without
199a527560SKonstantin Belousov  * modification, are permitted provided that the following conditions
209a527560SKonstantin Belousov  * are met:
219a527560SKonstantin Belousov  * 1. Redistributions of source code must retain the above copyright
229a527560SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer.
239a527560SKonstantin Belousov  * 2. Redistributions in binary form must reproduce the above copyright
249a527560SKonstantin Belousov  *    notice, this list of conditions and the following disclaimer in the
259a527560SKonstantin Belousov  *    documentation and/or other materials provided with the distribution.
269a527560SKonstantin Belousov  * 3. Neither the name of the University nor the names of its contributors
279a527560SKonstantin Belousov  *    may be used to endorse or promote products derived from this software
289a527560SKonstantin Belousov  *    without specific prior written permission.
299a527560SKonstantin Belousov  *
309a527560SKonstantin Belousov  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
319a527560SKonstantin Belousov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
329a527560SKonstantin Belousov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
339a527560SKonstantin Belousov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
349a527560SKonstantin Belousov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
359a527560SKonstantin Belousov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
369a527560SKonstantin Belousov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
379a527560SKonstantin Belousov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
389a527560SKonstantin Belousov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
399a527560SKonstantin Belousov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
409a527560SKonstantin Belousov  * SUCH DAMAGE.
419a527560SKonstantin Belousov  *
429a527560SKonstantin Belousov  * Derived from hp300 version by Mike Hibler, this version by William
439a527560SKonstantin Belousov  * Jolitz uses a recursive map [a pde points to the page directory] to
449a527560SKonstantin Belousov  * map the page tables using the pagetables themselves. This is done to
459a527560SKonstantin Belousov  * reduce the impact on kernel virtual memory for lots of sparse address
469a527560SKonstantin Belousov  * space, and to reduce the cost of memory to each process.
479a527560SKonstantin Belousov  */
489a527560SKonstantin Belousov 
499a527560SKonstantin Belousov #ifndef _MACHINE_PMAP_PAE_H
509a527560SKonstantin Belousov #define	_MACHINE_PMAP_PAE_H
519a527560SKonstantin Belousov 
529a527560SKonstantin Belousov #define	NTRPPTD		2		/* Number of PTDs for trampoline
539a527560SKonstantin Belousov 					   mapping */
549a527560SKonstantin Belousov #define	LOWPTDI		2		/* low memory map pde */
559a527560SKonstantin Belousov #define	KERNPTDI	4		/* start of kernel text pde */
569a527560SKonstantin Belousov 
579a527560SKonstantin Belousov #define NPGPTD		4		/* Num of pages for page directory */
589a527560SKonstantin Belousov #define NPGPTD_SHIFT	9
599a527560SKonstantin Belousov #undef	PDRSHIFT
609a527560SKonstantin Belousov #define	PDRSHIFT	PDRSHIFT_PAE
619a527560SKonstantin Belousov #undef	NBPDR
629a527560SKonstantin Belousov #define NBPDR		(1 << PDRSHIFT_PAE)	/* bytes/page dir */
639a527560SKonstantin Belousov 
649a527560SKonstantin Belousov #define	PG_FRAME	PG_FRAME_PAE
659a527560SKonstantin Belousov #define	PG_PS_FRAME	PG_PS_FRAME_PAE
669a527560SKonstantin Belousov 
679a527560SKonstantin Belousov /*
689a527560SKonstantin Belousov  * Size of Kernel address space.  This is the number of page table pages
699a527560SKonstantin Belousov  * (4MB each) to use for the kernel.  256 pages == 1 Gigabyte.
709a527560SKonstantin Belousov  * This **MUST** be a multiple of 4 (eg: 252, 256, 260, etc).
719a527560SKonstantin Belousov  * For PAE, the page table page unit size is 2MB.  This means that 512 pages
729a527560SKonstantin Belousov  * is 1 Gigabyte.  Double everything.  It must be a multiple of 8 for PAE.
739a527560SKonstantin Belousov  */
749a527560SKonstantin Belousov #define KVA_PAGES	(512*4)
759a527560SKonstantin Belousov 
769a527560SKonstantin Belousov /*
779a527560SKonstantin Belousov  * The initial number of kernel page table pages that are constructed
789a527560SKonstantin Belousov  * by pmap_cold() must be sufficient to map vm_page_array.  That number can
799a527560SKonstantin Belousov  * be calculated as follows:
809a527560SKonstantin Belousov  *     max_phys / PAGE_SIZE * sizeof(struct vm_page) / NBPDR
819a527560SKonstantin Belousov  * PAE:      max_phys 16G, sizeof(vm_page) 76, NBPDR 2M, 152 page table pages.
829a527560SKonstantin Belousov  * PAE_TABLES: max_phys 4G,  sizeof(vm_page) 68, NBPDR 2M, 36 page table pages.
839a527560SKonstantin Belousov  * Non-PAE:  max_phys 4G,  sizeof(vm_page) 68, NBPDR 4M, 18 page table pages.
849a527560SKonstantin Belousov  */
859a527560SKonstantin Belousov #ifndef NKPT
869a527560SKonstantin Belousov #define	NKPT		240
879a527560SKonstantin Belousov #endif
889a527560SKonstantin Belousov 
899a527560SKonstantin Belousov typedef uint64_t pdpt_entry_t;
909a527560SKonstantin Belousov typedef uint64_t pd_entry_t;
919a527560SKonstantin Belousov typedef uint64_t pt_entry_t;
929a527560SKonstantin Belousov 
939a527560SKonstantin Belousov #define	PTESHIFT	(3)
949a527560SKonstantin Belousov #define	PDESHIFT	(3)
959a527560SKonstantin Belousov 
969a527560SKonstantin Belousov #define	pde_cmpset(pdep, old, new)	atomic_cmpset_64_i586(pdep, old, new)
979a527560SKonstantin Belousov #define	pte_load_store(ptep, pte)	atomic_swap_64_i586(ptep, pte)
989a527560SKonstantin Belousov #define	pte_load_clear(ptep)		atomic_swap_64_i586(ptep, 0)
999a527560SKonstantin Belousov #define	pte_store(ptep, pte)		atomic_store_rel_64_i586(ptep, pte)
100*d5f2c1e4SKonstantin Belousov #define	pte_store_zero(ptep, pte)		\
101*d5f2c1e4SKonstantin Belousov do {						\
102*d5f2c1e4SKonstantin Belousov 	uint32_t *p;				\
103*d5f2c1e4SKonstantin Belousov 						\
104*d5f2c1e4SKonstantin Belousov 	MPASS((*ptep & PG_V) == 0);		\
105*d5f2c1e4SKonstantin Belousov 	p = (void *)ptep;			\
106*d5f2c1e4SKonstantin Belousov 	*(p + 1) = (uint32_t)(pte >> 32);	\
107*d5f2c1e4SKonstantin Belousov 	__compiler_membar();			\
108*d5f2c1e4SKonstantin Belousov 	*p = (uint32_t)pte;			\
109*d5f2c1e4SKonstantin Belousov } while (0)
1109a527560SKonstantin Belousov #define	pte_load(ptep)			atomic_load_acq_64_i586(ptep)
1119a527560SKonstantin Belousov 
1129a527560SKonstantin Belousov extern pdpt_entry_t *IdlePDPT;
1139a527560SKonstantin Belousov extern pt_entry_t pg_nx;
1149a527560SKonstantin Belousov extern pd_entry_t *IdlePTD_pae;	/* physical address of "Idle" state directory */
1159a527560SKonstantin Belousov 
1169a527560SKonstantin Belousov /*
1179a527560SKonstantin Belousov  * KPTmap is a linear mapping of the kernel page table.  It differs from the
1189a527560SKonstantin Belousov  * recursive mapping in two ways: (1) it only provides access to kernel page
1199a527560SKonstantin Belousov  * table pages, and not user page table pages, and (2) it provides access to
1209a527560SKonstantin Belousov  * a kernel page table page after the corresponding virtual addresses have
1219a527560SKonstantin Belousov  * been promoted to a 2/4MB page mapping.
1229a527560SKonstantin Belousov  *
1239a527560SKonstantin Belousov  * KPTmap is first initialized by pmap_cold() to support just NPKT page table
1249a527560SKonstantin Belousov  * pages.  Later, it is reinitialized by pmap_bootstrap() to allow for
1259a527560SKonstantin Belousov  * expansion of the kernel page table.
1269a527560SKonstantin Belousov  */
1279a527560SKonstantin Belousov extern pt_entry_t *KPTmap_pae;
1289a527560SKonstantin Belousov 
1299a527560SKonstantin Belousov #endif
130