xref: /f-stack/freebsd/amd64/include/param.h (revision 22ce4aff)
1a9643ea8Slogwang /*-
2*22ce4affSfengbojiang  * SPDX-License-Identifier: BSD-4-Clause
3*22ce4affSfengbojiang  *
4a9643ea8Slogwang  * Copyright (c) 2002 David E. O'Brien.  All rights reserved.
5a9643ea8Slogwang  * Copyright (c) 1992, 1993
6a9643ea8Slogwang  *	The Regents of the University of California.  All rights reserved.
7a9643ea8Slogwang  *
8a9643ea8Slogwang  * This code is derived from software contributed to Berkeley by
9a9643ea8Slogwang  * the Systems Programming Group of the University of Utah Computer
10a9643ea8Slogwang  * Science Department and Ralph Campbell.
11a9643ea8Slogwang  *
12a9643ea8Slogwang  * Redistribution and use in source and binary forms, with or without
13a9643ea8Slogwang  * modification, are permitted provided that the following conditions
14a9643ea8Slogwang  * are met:
15a9643ea8Slogwang  * 1. Redistributions of source code must retain the above copyright
16a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer.
17a9643ea8Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
18a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer in the
19a9643ea8Slogwang  *    documentation and/or other materials provided with the distribution.
20a9643ea8Slogwang  * 3. All advertising materials mentioning features or use of this software
21a9643ea8Slogwang  *    must display the following acknowledgement:
22a9643ea8Slogwang  *	This product includes software developed by the University of
23a9643ea8Slogwang  *	California, Berkeley and its contributors.
24a9643ea8Slogwang  * 4. Neither the name of the University nor the names of its contributors
25a9643ea8Slogwang  *    may be used to endorse or promote products derived from this software
26a9643ea8Slogwang  *    without specific prior written permission.
27a9643ea8Slogwang  *
28a9643ea8Slogwang  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29a9643ea8Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30a9643ea8Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31a9643ea8Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32a9643ea8Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33a9643ea8Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34a9643ea8Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35a9643ea8Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36a9643ea8Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37a9643ea8Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38a9643ea8Slogwang  * SUCH DAMAGE.
39a9643ea8Slogwang  *
40a9643ea8Slogwang  *	@(#)param.h	8.1 (Berkeley) 6/10/93
41a9643ea8Slogwang  * $FreeBSD$
42a9643ea8Slogwang  */
43a9643ea8Slogwang 
44a9643ea8Slogwang #ifndef _AMD64_INCLUDE_PARAM_H_
45a9643ea8Slogwang #define	_AMD64_INCLUDE_PARAM_H_
46a9643ea8Slogwang 
47a9643ea8Slogwang #include <machine/_align.h>
48a9643ea8Slogwang 
49a9643ea8Slogwang /*
50a9643ea8Slogwang  * Machine dependent constants for AMD64.
51a9643ea8Slogwang  */
52a9643ea8Slogwang 
53a9643ea8Slogwang #define __HAVE_ACPI
54a9643ea8Slogwang #define __PCI_REROUTE_INTERRUPT
55a9643ea8Slogwang 
56a9643ea8Slogwang #ifndef MACHINE
57a9643ea8Slogwang #define	MACHINE		"amd64"
58a9643ea8Slogwang #endif
59a9643ea8Slogwang #ifndef MACHINE_ARCH
60a9643ea8Slogwang #define	MACHINE_ARCH	"amd64"
61a9643ea8Slogwang #endif
62a9643ea8Slogwang #ifndef MACHINE_ARCH32
63a9643ea8Slogwang #define	MACHINE_ARCH32	"i386"
64a9643ea8Slogwang #endif
65a9643ea8Slogwang 
66*22ce4affSfengbojiang #ifdef SMP
67a9643ea8Slogwang #ifndef MAXCPU
68a9643ea8Slogwang #define MAXCPU		256
69a9643ea8Slogwang #endif
70a9643ea8Slogwang #else
71a9643ea8Slogwang #define MAXCPU		1
72a9643ea8Slogwang #endif
73a9643ea8Slogwang 
74a9643ea8Slogwang #ifndef MAXMEMDOM
75a9643ea8Slogwang #define	MAXMEMDOM	8
76a9643ea8Slogwang #endif
77a9643ea8Slogwang 
78a9643ea8Slogwang #define	ALIGNBYTES		_ALIGNBYTES
79a9643ea8Slogwang #define	ALIGN(p)		_ALIGN(p)
80a9643ea8Slogwang /*
81a9643ea8Slogwang  * ALIGNED_POINTER is a boolean macro that checks whether an address
82a9643ea8Slogwang  * is valid to fetch data elements of type t from on this architecture.
83a9643ea8Slogwang  * This does not reflect the optimal alignment, just the possibility
84a9643ea8Slogwang  * (within reasonable limits).
85a9643ea8Slogwang  */
86a9643ea8Slogwang #define	ALIGNED_POINTER(p, t)	1
87a9643ea8Slogwang 
88a9643ea8Slogwang /*
89a9643ea8Slogwang  * CACHE_LINE_SIZE is the compile-time maximum cache line size for an
90a9643ea8Slogwang  * architecture.  It should be used with appropriate caution.
91a9643ea8Slogwang  */
92*22ce4affSfengbojiang #define	CACHE_LINE_SHIFT	6
93a9643ea8Slogwang #define	CACHE_LINE_SIZE		(1 << CACHE_LINE_SHIFT)
94a9643ea8Slogwang 
95a9643ea8Slogwang /* Size of the level 1 page table units */
96a9643ea8Slogwang #define NPTEPG		(PAGE_SIZE/(sizeof (pt_entry_t)))
97a9643ea8Slogwang #define	NPTEPGSHIFT	9		/* LOG2(NPTEPG) */
98a9643ea8Slogwang #define PAGE_SHIFT	12		/* LOG2(PAGE_SIZE) */
99a9643ea8Slogwang #define PAGE_SIZE	(1<<PAGE_SHIFT)	/* bytes/page */
100a9643ea8Slogwang #define PAGE_MASK	(PAGE_SIZE-1)
101a9643ea8Slogwang /* Size of the level 2 page directory units */
102a9643ea8Slogwang #define	NPDEPG		(PAGE_SIZE/(sizeof (pd_entry_t)))
103a9643ea8Slogwang #define	NPDEPGSHIFT	9		/* LOG2(NPDEPG) */
104a9643ea8Slogwang #define	PDRSHIFT	21              /* LOG2(NBPDR) */
105a9643ea8Slogwang #define	NBPDR		(1<<PDRSHIFT)   /* bytes/page dir */
106a9643ea8Slogwang #define	PDRMASK		(NBPDR-1)
107a9643ea8Slogwang /* Size of the level 3 page directory pointer table units */
108a9643ea8Slogwang #define	NPDPEPG		(PAGE_SIZE/(sizeof (pdp_entry_t)))
109a9643ea8Slogwang #define	NPDPEPGSHIFT	9		/* LOG2(NPDPEPG) */
110a9643ea8Slogwang #define	PDPSHIFT	30		/* LOG2(NBPDP) */
111a9643ea8Slogwang #define	NBPDP		(1<<PDPSHIFT)	/* bytes/page dir ptr table */
112a9643ea8Slogwang #define	PDPMASK		(NBPDP-1)
113a9643ea8Slogwang /* Size of the level 4 page-map level-4 table units */
114a9643ea8Slogwang #define	NPML4EPG	(PAGE_SIZE/(sizeof (pml4_entry_t)))
115a9643ea8Slogwang #define	NPML4EPGSHIFT	9		/* LOG2(NPML4EPG) */
116a9643ea8Slogwang #define	PML4SHIFT	39		/* LOG2(NBPML4) */
117a9643ea8Slogwang #define	NBPML4		(1UL<<PML4SHIFT)/* bytes/page map lev4 table */
118a9643ea8Slogwang #define	PML4MASK	(NBPML4-1)
119*22ce4affSfengbojiang /* Size of the level 5 page-map level-5 table units */
120*22ce4affSfengbojiang #define	NPML5EPG	(PAGE_SIZE/(sizeof (pml5_entry_t)))
121*22ce4affSfengbojiang #define	NPML5EPGSHIFT	9		/* LOG2(NPML5EPG) */
122*22ce4affSfengbojiang #define	PML5SHIFT	48		/* LOG2(NBPML5) */
123*22ce4affSfengbojiang #define	NBPML5		(1UL<<PML5SHIFT)/* bytes/page map lev5 table */
124*22ce4affSfengbojiang #define	PML5MASK	(NBPML5-1)
125a9643ea8Slogwang 
126a9643ea8Slogwang #define	MAXPAGESIZES	3	/* maximum number of supported page sizes */
127a9643ea8Slogwang 
128a9643ea8Slogwang #define IOPAGES	2		/* pages of i/o permission bitmap */
129a9643ea8Slogwang /*
130a9643ea8Slogwang  * I/O permission bitmap has a bit for each I/O port plus an additional
131a9643ea8Slogwang  * byte at the end with all bits set. See section "I/O Permission Bit Map"
132a9643ea8Slogwang  * in the Intel SDM for more details.
133a9643ea8Slogwang  */
134a9643ea8Slogwang #define	IOPERM_BITMAP_SIZE	(IOPAGES * PAGE_SIZE + 1)
135a9643ea8Slogwang 
136a9643ea8Slogwang #ifndef	KSTACK_PAGES
137a9643ea8Slogwang #define	KSTACK_PAGES	4	/* pages of kstack (with pcb) */
138a9643ea8Slogwang #endif
139a9643ea8Slogwang #define	KSTACK_GUARD_PAGES 1	/* pages of kstack guard; 0 disables */
140a9643ea8Slogwang 
141a9643ea8Slogwang /*
142a9643ea8Slogwang  * Mach derived conversion macros
143a9643ea8Slogwang  */
144a9643ea8Slogwang #define	round_page(x)	((((unsigned long)(x)) + PAGE_MASK) & ~(PAGE_MASK))
145a9643ea8Slogwang #define	trunc_page(x)	((unsigned long)(x) & ~(PAGE_MASK))
146a9643ea8Slogwang #define trunc_2mpage(x)	((unsigned long)(x) & ~PDRMASK)
147a9643ea8Slogwang #define round_2mpage(x)	((((unsigned long)(x)) + PDRMASK) & ~PDRMASK)
148a9643ea8Slogwang #define trunc_1gpage(x)	((unsigned long)(x) & ~PDPMASK)
149a9643ea8Slogwang 
150a9643ea8Slogwang #define	atop(x)		((unsigned long)(x) >> PAGE_SHIFT)
151a9643ea8Slogwang #define	ptoa(x)		((unsigned long)(x) << PAGE_SHIFT)
152a9643ea8Slogwang 
153a9643ea8Slogwang #define	amd64_btop(x)	((unsigned long)(x) >> PAGE_SHIFT)
154a9643ea8Slogwang #define	amd64_ptob(x)	((unsigned long)(x) << PAGE_SHIFT)
155a9643ea8Slogwang 
156a9643ea8Slogwang #define	pgtok(x)	((unsigned long)(x) * (PAGE_SIZE / 1024))
157a9643ea8Slogwang 
158a9643ea8Slogwang #define	INKERNEL(va) (((va) >= DMAP_MIN_ADDRESS && (va) < DMAP_MAX_ADDRESS) \
159a9643ea8Slogwang     || ((va) >= VM_MIN_KERNEL_ADDRESS && (va) < VM_MAX_KERNEL_ADDRESS))
160a9643ea8Slogwang 
161*22ce4affSfengbojiang #ifdef SMP
162*22ce4affSfengbojiang #define SC_TABLESIZE    1024                     /* Must be power of 2. */
163*22ce4affSfengbojiang #endif
164*22ce4affSfengbojiang 
165a9643ea8Slogwang #endif /* !_AMD64_INCLUDE_PARAM_H_ */
166