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