param.h revision 192331
1139749Simp/*-
254134Swpaul * Copyright (c) 2002 David E. O'Brien.  All rights reserved.
354134Swpaul * Copyright (c) 1992, 1993
454134Swpaul *	The Regents of the University of California.  All rights reserved.
554134Swpaul *
654134Swpaul * This code is derived from software contributed to Berkeley by
754134Swpaul * the Systems Programming Group of the University of Utah Computer
854134Swpaul * Science Department and Ralph Campbell.
954134Swpaul *
1054134Swpaul * Redistribution and use in source and binary forms, with or without
1154134Swpaul * modification, are permitted provided that the following conditions
1254134Swpaul * are met:
1354134Swpaul * 1. Redistributions of source code must retain the above copyright
1454134Swpaul *    notice, this list of conditions and the following disclaimer.
1554134Swpaul * 2. Redistributions in binary form must reproduce the above copyright
1654134Swpaul *    notice, this list of conditions and the following disclaimer in the
1754134Swpaul *    documentation and/or other materials provided with the distribution.
1854134Swpaul * 3. All advertising materials mentioning features or use of this software
1954134Swpaul *    must display the following acknowledgement:
2054134Swpaul *	This product includes software developed by the University of
2154134Swpaul *	California, Berkeley and its contributors.
2254134Swpaul * 4. Neither the name of the University nor the names of its contributors
2354134Swpaul *    may be used to endorse or promote products derived from this software
2454134Swpaul *    without specific prior written permission.
2554134Swpaul *
2654134Swpaul * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2754134Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2854134Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2954134Swpaul * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3054134Swpaul * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3154134Swpaul * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3254134Swpaul * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33119418Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34119418Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35119418Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3654134Swpaul * SUCH DAMAGE.
3754134Swpaul *
38183505Smarius *	@(#)param.h	8.1 (Berkeley) 6/10/93
3954134Swpaul * $FreeBSD: head/sys/amd64/include/param.h 192331 2009-05-18 19:33:59Z jhb $
40183505Smarius */
4154134Swpaul
4254134Swpaul/*
4354134Swpaul * Machine dependent constants for AMD64.
4454134Swpaul */
4554134Swpaul
4654134Swpaul/*
4754134Swpaul * Round p (pointer or byte index) up to a correctly-aligned value
4854134Swpaul * for all data types (int, long, ...).   The result is u_long and
4954134Swpaul * must be cast to any desired pointer type.
5074914Sjhb *
5154134Swpaul * ALIGNED_POINTER is a boolean macro that checks whether an address
5267365Sjhb * is valid to fetch data elements of type t from on this architecture.
5354134Swpaul * This does not reflect the optimal alignment, just the possibility
5454134Swpaul * (within reasonable limits).
5554134Swpaul *
5654134Swpaul */
5754134Swpaul#ifndef _ALIGNBYTES
5854134Swpaul#define	_ALIGNBYTES	(sizeof(long) - 1)
5954134Swpaul#endif
6054134Swpaul#ifndef _ALIGN
61109514Sobrien#define	_ALIGN(p)	(((u_long)(p) + _ALIGNBYTES) &~ _ALIGNBYTES)
6254134Swpaul#endif
6354134Swpaul#ifndef _ALIGNED_POINTER
6454134Swpaul#define	_ALIGNED_POINTER(p,t)	((((u_long)(p)) & (sizeof(t)-1)) == 0)
6554134Swpaul#endif
66119285Simp
6754134Swpaul#ifndef _NO_NAMESPACE_POLLUTION
68151435Simp
6954134Swpaul#define __HAVE_ACPI
7054134Swpaul#define __PCI_REROUTE_INTERRUPT
7154134Swpaul
7254134Swpaul#ifndef _MACHINE_PARAM_H_
7354134Swpaul#define	_MACHINE_PARAM_H_
7454134Swpaul
7554134Swpaul#ifndef MACHINE
7654134Swpaul#define	MACHINE		"amd64"
7754134Swpaul#endif
7854134Swpaul#ifndef MACHINE_ARCH
7954134Swpaul#define	MACHINE_ARCH	"amd64"
8054134Swpaul#endif
8154134Swpaul
8254577Swpaul#if defined(SMP) || defined(KLD_MODULE)
8354577Swpaul#define MAXCPU		32
84183505Smarius#else
8554577Swpaul#define MAXCPU		1
8654577Swpaul#endif
8754577Swpaul
8854577Swpaul#define	ALIGNBYTES		_ALIGNBYTES
89105135Salfred#define	ALIGN(p)		_ALIGN(p)
90105135Salfred#define	ALIGNED_POINTER(p,t)	_ALIGNED_POINTER(p,t)
9154134Swpaul
9254134Swpaul/*
9354134Swpaul * CACHE_LINE_SIZE is the compile-time maximum cache line size for an
9454134Swpaul * architecture.  It should be used with appropriate caution.
9554134Swpaul */
9695722Sphk#define	CACHE_LINE_SHIFT	7
9754134Swpaul#define	CACHE_LINE_SIZE		(1 << CACHE_LINE_SHIFT)
98227908Smarius
9954134Swpaul/* Size of the level 1 page table units */
10054134Swpaul#define NPTEPG		(PAGE_SIZE/(sizeof (pt_entry_t)))
10154134Swpaul#define	NPTEPGSHIFT	9		/* LOG2(NPTEPG) */
10254134Swpaul#define PAGE_SHIFT	12		/* LOG2(PAGE_SIZE) */
10354134Swpaul#define PAGE_SIZE	(1<<PAGE_SHIFT)	/* bytes/page */
10454134Swpaul#define PAGE_MASK	(PAGE_SIZE-1)
10554134Swpaul/* Size of the level 2 page directory units */
10654134Swpaul#define	NPDEPG		(PAGE_SIZE/(sizeof (pd_entry_t)))
10754134Swpaul#define	NPDEPGSHIFT	9		/* LOG2(NPDEPG) */
10854134Swpaul#define	PDRSHIFT	21              /* LOG2(NBPDR) */
10954134Swpaul#define	NBPDR		(1<<PDRSHIFT)   /* bytes/page dir */
11054134Swpaul#define	PDRMASK		(NBPDR-1)
11192739Salfred/* Size of the level 3 page directory pointer table units */
11292739Salfred#define	NPDPEPG		(PAGE_SIZE/(sizeof (pdp_entry_t)))
11392739Salfred#define	NPDPEPGSHIFT	9		/* LOG2(NPDPEPG) */
11496026Sphk#define	PDPSHIFT	30		/* LOG2(NBPDP) */
11554134Swpaul#define	NBPDP		(1<<PDPSHIFT)	/* bytes/page dir ptr table */
116221407Smarius#define	PDPMASK		(NBPDP-1)
117221407Smarius/* Size of the level 4 page-map level-4 table units */
118221407Smarius#define	NPML4EPG	(PAGE_SIZE/(sizeof (pml4_entry_t)))
119221407Smarius#define	NPML4EPGSHIFT	9		/* LOG2(NPML4EPG) */
120221407Smarius#define	PML4SHIFT	39		/* LOG2(NBPML4) */
121221407Smarius#define	NBPML4		(1ul<<PML4SHIFT)/* bytes/page map lev4 table */
122105135Salfred#define	PML4MASK	(NBPML4-1)
123150763Simp
12454134Swpaul#define IOPAGES	2		/* pages of i/o permission bitmap */
12554134Swpaul
12654134Swpaul#ifndef	KSTACK_PAGES
12754134Swpaul#define	KSTACK_PAGES	4	/* pages of kstack (with pcb) */
12854134Swpaul#endif
12954134Swpaul#define	KSTACK_GUARD_PAGES 1	/* pages of kstack guard; 0 disables */
13054134Swpaul
13154134Swpaul/*
13254134Swpaul * Ceiling on amount of swblock kva space, can be changed via
13354134Swpaul * the kern.maxswzone /boot/loader.conf variable.
13454134Swpaul */
135183505Smarius#ifndef VM_SWZONE_SIZE_MAX
13654134Swpaul#define	VM_SWZONE_SIZE_MAX	(32 * 1024 * 1024)
13754134Swpaul#endif
13854134Swpaul
139160907Syongari/*
14054134Swpaul * Ceiling on size of buffer cache (really only effects write queueing,
14154134Swpaul * the VM page cache is not effected), can be changed via
142105135Salfred * the kern.maxbcache /boot/loader.conf variable.
143150763Simp */
14454134Swpaul#ifndef VM_BCACHE_SIZE_MAX
14554134Swpaul#define	VM_BCACHE_SIZE_MAX	(1024 * 1024 * 1024)
14654134Swpaul#endif
147159201Sjhb
14854134Swpaul/*
14954134Swpaul * Mach derived conversion macros
15054134Swpaul */
151221407Smarius#define	round_page(x)	((((unsigned long)(x)) + PAGE_MASK) & ~(PAGE_MASK))
152221407Smarius#define	trunc_page(x)	((unsigned long)(x) & ~(PAGE_MASK))
15354134Swpaul#define trunc_2mpage(x)	((unsigned long)(x) & ~PDRMASK)
154221407Smarius#define round_2mpage(x)	((((unsigned long)(x)) + PDRMASK) & ~PDRMASK)
155221407Smarius#define trunc_1gpage(x)	((unsigned long)(x) & ~PDPMASK)
15654134Swpaul
15754134Swpaul#define	atop(x)		((unsigned long)(x) >> PAGE_SHIFT)
15854134Swpaul#define	ptoa(x)		((unsigned long)(x) << PAGE_SHIFT)
159159201Sjhb
160159201Sjhb#define	amd64_btop(x)	((unsigned long)(x) >> PAGE_SHIFT)
16154577Swpaul#define	amd64_ptob(x)	((unsigned long)(x) << PAGE_SHIFT)
16254134Swpaul
163183505Smarius#define	pgtok(x)	((unsigned long)(x) * (PAGE_SIZE / 1024))
16454134Swpaul
16554134Swpaul#endif /* !_MACHINE_PARAM_H_ */
166183505Smarius#endif /* !_NO_NAMESPACE_POLLUTION */
16766681Swpaul