param.h revision 114349
1110545Sphk/*
2110545Sphk * Copyright (c) 2002 David E. O'Brien.  All rights reserved.
3110545Sphk * Copyright (c) 1992, 1993
4110545Sphk *	The Regents of the University of California.  All rights reserved.
5110545Sphk *
6110545Sphk * This code is derived from software contributed to Berkeley by
7110545Sphk * the Systems Programming Group of the University of Utah Computer
8110545Sphk * Science Department and Ralph Campbell.
9110545Sphk *
10110545Sphk * Redistribution and use in source and binary forms, with or without
11110545Sphk * modification, are permitted provided that the following conditions
12110545Sphk * are met:
13110545Sphk * 1. Redistributions of source code must retain the above copyright
14110545Sphk *    notice, this list of conditions and the following disclaimer.
15110545Sphk * 2. Redistributions in binary form must reproduce the above copyright
16110545Sphk *    notice, this list of conditions and the following disclaimer in the
17110545Sphk *    documentation and/or other materials provided with the distribution.
18110545Sphk * 3. All advertising materials mentioning features or use of this software
19110545Sphk *    must display the following acknowledgement:
20110545Sphk *	This product includes software developed by the University of
21110545Sphk *	California, Berkeley and its contributors.
22110545Sphk * 4. Neither the name of the University nor the names of its contributors
23110545Sphk *    may be used to endorse or promote products derived from this software
24110545Sphk *    without specific prior written permission.
25110545Sphk *
26110545Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27110545Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28110545Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29110545Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30110545Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31110545Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32110545Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33110545Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34126786Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35126786Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36110603Sphk * SUCH DAMAGE.
37110547Sphk *
38110545Sphk *	@(#)param.h	8.1 (Berkeley) 6/10/93
39112510Sphk * $FreeBSD: head/sys/amd64/include/param.h 114349 2003-05-01 01:05:25Z peter $
40112510Sphk */
41126786Sjhb
42126786Sjhb/*
43110545Sphk * Machine dependent constants for AMD64.
44110545Sphk */
45110545Sphk
46110545Sphk/*
47110545Sphk * Round p (pointer or byte index) up to a correctly-aligned value
48110545Sphk * for all data types (int, long, ...).   The result is u_long and
49110545Sphk * must be cast to any desired pointer type.
50112372Sphk *
51110545Sphk * ALIGNED_POINTER is a boolean macro that checks whether an address
52110603Sphk * is valid to fetch data elements of type t from on this architecture.
53110603Sphk * This does not reflect the optimal alignment, just the possibility
54110603Sphk * (within reasonable limits).
55110603Sphk *
56110603Sphk */
57110603Sphk#ifndef _ALIGNBYTES
58110603Sphk#define	_ALIGNBYTES	(sizeof(long) - 1)
59110603Sphk#endif
60110603Sphk#ifndef _ALIGN
61110603Sphk#define	_ALIGN(p)	(((u_long)(p) + _ALIGNBYTES) &~ _ALIGNBYTES)
62110603Sphk#endif
63110603Sphk#ifndef _ALIGNED_POINTER
64110603Sphk#define	_ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)
65110603Sphk#endif
66110603Sphk
67110603Sphk#ifndef _MACHINE
68110603Sphk#define	_MACHINE	amd64
69126786Sjhb#endif
70126786Sjhb#ifndef _MACHINE_ARCH
71110603Sphk#define	_MACHINE_ARCH	amd64
72110603Sphk#endif
73110603Sphk
74126786Sjhb#ifndef _NO_NAMESPACE_POLLUTION
75110603Sphk
76110603Sphk#ifndef _MACHINE_PARAM_H_
77110603Sphk#define	_MACHINE_PARAM_H_
78126786Sjhb
79126786Sjhb#ifndef MACHINE
80110603Sphk#define	MACHINE		"amd64"
81110603Sphk#endif
82110603Sphk#ifndef MACHINE_ARCH
83126786Sjhb#define	MACHINE_ARCH	"amd64"
84126786Sjhb#endif
85126786Sjhb
86110603Sphk#define MAXCPU		1
87110603Sphk
88110603Sphk#define	ALIGNBYTES		_ALIGNBYTES
89126786Sjhb#define	ALIGN(p)		_ALIGN(p)
90126786Sjhb#define	ALIGNED_POINTER(p,t)	_ALIGNED_POINTER((p),(t))
91126786Sjhb
92126786Sjhb/* Size of the level 1 page table units */
93126786Sjhb#define NPTEPG		(PAGE_SIZE/(sizeof (pt_entry_t)))
94110603Sphk#define PAGE_SHIFT	12		/* LOG2(PAGE_SIZE) */
95110603Sphk#define PAGE_SIZE	(1<<PAGE_SHIFT)	/* bytes/page */
96110603Sphk#define PAGE_MASK	(PAGE_SIZE-1)
97126786Sjhb/* Size of the level 2 page directory units */
98126786Sjhb#define	NPDEPG		(PAGE_SIZE/(sizeof (pd_entry_t)))
99126786Sjhb#define	PDRSHIFT	21              /* LOG2(NBPDR) */
100126786Sjhb#define	NBPDR		(1<<PDRSHIFT)   /* bytes/page dir */
101126786Sjhb#define	PDRMASK		(NBPDR-1)
102126786Sjhb/* Size of the level 3 page directory pointer table units */
103126786Sjhb#define	NPDPEPG		(PAGE_SIZE/(sizeof (pdp_entry_t)))
104126786Sjhb#define	PDPSHIFT	30		/* LOG2(NBPDP) */
105110603Sphk#define	NBPDP		(1<<PDPSHIFT)	/* bytes/page dir ptr table */
106110603Sphk#define	PDPMASK		(NBPDP-1)
107110603Sphk/* Size of the level 4 page-map level-4 table units */
108126786Sjhb#define	NPML4EPG	(PAGE_SIZE/(sizeof (pml4_entry_t)))
109126786Sjhb#define	PML4SHIFT	39		/* LOG2(NBPML4T) */
110126786Sjhb#define	NBPML4T		(1ul<<PML4SHIFT)/* bytes/page map lev4 table */
111126786Sjhb#define	PML4MASK	(NBPML4T-1)
112126786Sjhb
113126786Sjhb#define NKPML4E		1		/* addressable number of page tables/pde's */
114126786Sjhb#define NKPDPE		1		/* addressable number of page tables/pde's */
115110603Sphk#define NPGPTD		4
116110603Sphk
117110603Sphk#define NBPTD           (NPGPTD<<PAGE_SHIFT)
118126786Sjhb#define NPDEPTD         (NBPTD/(sizeof (pd_entry_t)))
119126786Sjhb
120126786Sjhb#define IOPAGES	2		/* pages of i/o permission bitmap */
121126786Sjhb
122126786Sjhb#define	KSTACK_PAGES	4	/* pages of kstack (with pcb) */
123126786Sjhb#define UAREA_PAGES	1	/* holds struct user WITHOUT PCB (see def.) */
124126786Sjhb
125126786Sjhb#define KSTACK_GUARD	1	/* compile in the kstack guard page */
126126786Sjhb
127110603Sphk/*
128110603Sphk * Ceiling on amount of swblock kva space, can be changed via
129112340Sphk * the kern.maxswzone /boot/loader.conf variable.
130110603Sphk */
131110603Sphk#ifndef VM_SWZONE_SIZE_MAX
132110603Sphk#define	VM_SWZONE_SIZE_MAX	(32 * 1024 * 1024)
133110603Sphk#endif
134112510Sphk
135112510Sphk/*
136112709Sphk * Ceiling on size of buffer cache (really only effects write queueing,
137112510Sphk * the VM page cache is not effected), can be changed via
138112510Sphk * the kern.maxbcache /boot/loader.conf variable.
139112709Sphk */
140112510Sphk#ifndef VM_BCACHE_SIZE_MAX
141112709Sphk#define	VM_BCACHE_SIZE_MAX	(200 * 1024 * 1024)
142115625Sphk#endif
143112709Sphk
144112709Sphk/*
145112709Sphk * Mach derived conversion macros
146112510Sphk */
147169299Spjd#define	round_page(x)	((((unsigned long)(x)) + PAGE_MASK) & ~(PAGE_MASK))
148169299Spjd#define	trunc_page(x)	((unsigned long)(x) & ~(PAGE_MASK))
149169299Spjd#define trunc_2mpage(x)	((unsigned long)(x) & ~PDRMASK)
150169299Spjd#define round_2mpage(x)	((((unsigned long)(x)) + PDRMASK) & ~PDRMASK)
151169299Spjd
152169299Spjd#define	atop(x)		((unsigned long)(x) >> PAGE_SHIFT)
153169299Spjd#define	ptoa(x)		((unsigned long)(x) << PAGE_SHIFT)
154169299Spjd
155169299Spjd#define	amd64_btop(x)	((unsigned long)(x) >> PAGE_SHIFT)
156169299Spjd#define	amd64_ptob(x)	((unsigned long)(x) << PAGE_SHIFT)
157169299Spjd
158126786Sjhb#define	pgtok(x)	((unsigned long)(x) * (PAGE_SIZE / 1024))
159126786Sjhb
160110545Sphk#endif /* !_MACHINE_PARAM_H_ */
161#endif /* !_NO_NAMESPACE_POLLUTION */
162