xref: /freebsd/sys/amd64/include/param.h (revision 7660b554bc59a07be0431c17e0e33815818baa69)
1 /*
2  * Copyright (c) 2002 David E. O'Brien.  All rights reserved.
3  * Copyright (c) 1992, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
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 Ralph Campbell.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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.
25  *
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
36  * SUCH DAMAGE.
37  *
38  *	@(#)param.h	8.1 (Berkeley) 6/10/93
39  * $FreeBSD$
40  */
41 
42 /*
43  * Machine dependent constants for AMD64.
44  */
45 
46 /*
47  * Round p (pointer or byte index) up to a correctly-aligned value
48  * for all data types (int, long, ...).   The result is u_long and
49  * must be cast to any desired pointer type.
50  *
51  * ALIGNED_POINTER is a boolean macro that checks whether an address
52  * is valid to fetch data elements of type t from on this architecture.
53  * This does not reflect the optimal alignment, just the possibility
54  * (within reasonable limits).
55  *
56  */
57 #ifndef _ALIGNBYTES
58 #define	_ALIGNBYTES	(sizeof(long) - 1)
59 #endif
60 #ifndef _ALIGN
61 #define	_ALIGN(p)	(((u_long)(p) + _ALIGNBYTES) &~ _ALIGNBYTES)
62 #endif
63 #ifndef _ALIGNED_POINTER
64 #define	_ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)
65 #endif
66 
67 #ifndef _MACHINE
68 #define	_MACHINE	amd64
69 #endif
70 #ifndef _MACHINE_ARCH
71 #define	_MACHINE_ARCH	amd64
72 #endif
73 
74 #ifndef _NO_NAMESPACE_POLLUTION
75 
76 #ifndef _MACHINE_PARAM_H_
77 #define	_MACHINE_PARAM_H_
78 
79 #ifndef MACHINE
80 #define	MACHINE		"amd64"
81 #endif
82 #ifndef MACHINE_ARCH
83 #define	MACHINE_ARCH	"amd64"
84 #endif
85 
86 #define MAXCPU		1
87 
88 #define	ALIGNBYTES		_ALIGNBYTES
89 #define	ALIGN(p)		_ALIGN(p)
90 #define	ALIGNED_POINTER(p,t)	_ALIGNED_POINTER(p,t)
91 
92 
93 /* Size of the level 1 page table units */
94 #define NPTEPG		(PAGE_SIZE/(sizeof (pt_entry_t)))
95 #define	NPTEPGSHIFT	9		/* LOG2(NPTEPG) */
96 #define PAGE_SHIFT	12		/* LOG2(PAGE_SIZE) */
97 #define PAGE_SIZE	(1<<PAGE_SHIFT)	/* bytes/page */
98 #define PAGE_MASK	(PAGE_SIZE-1)
99 /* Size of the level 2 page directory units */
100 #define	NPDEPG		(PAGE_SIZE/(sizeof (pd_entry_t)))
101 #define	NPDEPGSHIFT	9		/* LOG2(NPDEPG) */
102 #define	PDRSHIFT	21              /* LOG2(NBPDR) */
103 #define	NBPDR		(1<<PDRSHIFT)   /* bytes/page dir */
104 #define	PDRMASK		(NBPDR-1)
105 /* Size of the level 3 page directory pointer table units */
106 #define	NPDPEPG		(PAGE_SIZE/(sizeof (pdp_entry_t)))
107 #define	NPDPEPGSHIFT	9		/* LOG2(NPDPEPG) */
108 #define	PDPSHIFT	30		/* LOG2(NBPDP) */
109 #define	NBPDP		(1<<PDPSHIFT)	/* bytes/page dir ptr table */
110 #define	PDPMASK		(NBPDP-1)
111 /* Size of the level 4 page-map level-4 table units */
112 #define	NPML4EPG	(PAGE_SIZE/(sizeof (pml4_entry_t)))
113 #define	NPML4EPGSHIFT	9		/* LOG2(NPML4EPG) */
114 #define	PML4SHIFT	39		/* LOG2(NBPML4T) */
115 #define	NBPML4T		(1ul<<PML4SHIFT)/* bytes/page map lev4 table */
116 #define	PML4MASK	(NBPML4T-1)
117 
118 #define IOPAGES	2		/* pages of i/o permission bitmap */
119 
120 #ifndef	KSTACK_PAGES
121 #define	KSTACK_PAGES	4	/* pages of kstack (with pcb) */
122 #endif
123 #define	KSTACK_GUARD_PAGES 1	/* pages of kstack guard; 0 disables */
124 #define UAREA_PAGES	1	/* holds struct user WITHOUT PCB (see def.) */
125 
126 
127 /*
128  * Ceiling on amount of swblock kva space, can be changed via
129  * the kern.maxswzone /boot/loader.conf variable.
130  */
131 #ifndef VM_SWZONE_SIZE_MAX
132 #define	VM_SWZONE_SIZE_MAX	(32 * 1024 * 1024)
133 #endif
134 
135 /*
136  * Ceiling on size of buffer cache (really only effects write queueing,
137  * the VM page cache is not effected), can be changed via
138  * the kern.maxbcache /boot/loader.conf variable.
139  */
140 #ifndef VM_BCACHE_SIZE_MAX
141 #define	VM_BCACHE_SIZE_MAX	(200 * 1024 * 1024)
142 #endif
143 
144 /*
145  * Mach derived conversion macros
146  */
147 #define	round_page(x)	((((unsigned long)(x)) + PAGE_MASK) & ~(PAGE_MASK))
148 #define	trunc_page(x)	((unsigned long)(x) & ~(PAGE_MASK))
149 #define trunc_2mpage(x)	((unsigned long)(x) & ~PDRMASK)
150 #define round_2mpage(x)	((((unsigned long)(x)) + PDRMASK) & ~PDRMASK)
151 
152 #define	atop(x)		((unsigned long)(x) >> PAGE_SHIFT)
153 #define	ptoa(x)		((unsigned long)(x) << PAGE_SHIFT)
154 
155 #define	amd64_btop(x)	((unsigned long)(x) >> PAGE_SHIFT)
156 #define	amd64_ptob(x)	((unsigned long)(x) << PAGE_SHIFT)
157 
158 #define	pgtok(x)	((unsigned long)(x) * (PAGE_SIZE / 1024))
159 
160 #endif /* !_MACHINE_PARAM_H_ */
161 #endif /* !_NO_NAMESPACE_POLLUTION */
162