/*-1* SPDX-License-Identifier: BSD-4-Clause2*3* Copyright (c) 2002 David E. O'Brien. All rights reserved.4* Copyright (c) 1992, 19935* The Regents of the University of California. All rights reserved.6*7* This code is derived from software contributed to Berkeley by8* the Systems Programming Group of the University of Utah Computer9* Science Department and Ralph Campbell.10*11* Redistribution and use in source and binary forms, with or without12* modification, are permitted provided that the following conditions13* are met:14* 1. Redistributions of source code must retain the above copyright15* notice, this list of conditions and the following disclaimer.16* 2. Redistributions in binary form must reproduce the above copyright17* notice, this list of conditions and the following disclaimer in the18* documentation and/or other materials provided with the distribution.19* 3. All advertising materials mentioning features or use of this software20* must display the following acknowledgement:21* This product includes software developed by the University of22* California, Berkeley and its contributors.23* 4. Neither the name of the University nor the names of its contributors24* may be used to endorse or promote products derived from this software25* without specific prior written permission.26*27* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND28* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE29* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE30* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE31* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL32* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS33* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)34* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT35* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY36* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF37* SUCH DAMAGE.38*/3940#ifndef _AMD64_INCLUDE_PARAM_H_41#define _AMD64_INCLUDE_PARAM_H_4243#include <machine/_align.h>4445/*46* Machine dependent constants for AMD64.47*/4849#ifndef MACHINE50#define MACHINE "amd64"51#endif52#ifndef MACHINE_ARCH53#define MACHINE_ARCH "amd64"54#endif55#ifndef MACHINE_ARCH3256#define MACHINE_ARCH32 "i386"57#endif5859#ifdef SMP60#ifndef MAXCPU61#define MAXCPU 102462#endif63#else64#define MAXCPU 165#endif6667#ifndef MAXMEMDOM68#define MAXMEMDOM 869#endif7071#define ALIGNBYTES _ALIGNBYTES72#define ALIGN(p) _ALIGN(p)73/*74* ALIGNED_POINTER is a boolean macro that checks whether an address75* is valid to fetch data elements of type t from on this architecture.76* This does not reflect the optimal alignment, just the possibility77* (within reasonable limits).78*/79#define ALIGNED_POINTER(p, t) 18081/*82* CACHE_LINE_SIZE is the compile-time maximum cache line size for an83* architecture. It should be used with appropriate caution.84*/85#define CACHE_LINE_SHIFT 686#define CACHE_LINE_SIZE (1 << CACHE_LINE_SHIFT)8788/* Size of the level 1 page table units */89#define NPTEPG (PAGE_SIZE/(sizeof (pt_entry_t)))90#define NPTEPGSHIFT 9 /* LOG2(NPTEPG) */91#define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */92#define PAGE_SIZE (1<<PAGE_SHIFT) /* bytes/page */93#define PAGE_MASK (PAGE_SIZE-1)94/* Size of the level 2 page directory units */95#define NPDEPG (PAGE_SIZE/(sizeof (pd_entry_t)))96#define NPDEPGSHIFT 9 /* LOG2(NPDEPG) */97#define PDRSHIFT 21 /* LOG2(NBPDR) */98#define NBPDR (1<<PDRSHIFT) /* bytes/page dir */99#define PDRMASK (NBPDR-1)100/* Size of the level 3 page directory pointer table units */101#define NPDPEPG (PAGE_SIZE/(sizeof (pdp_entry_t)))102#define NPDPEPGSHIFT 9 /* LOG2(NPDPEPG) */103#define PDPSHIFT 30 /* LOG2(NBPDP) */104#define NBPDP (1<<PDPSHIFT) /* bytes/page dir ptr table */105#define PDPMASK (NBPDP-1)106/* Size of the level 4 page-map level-4 table units */107#define NPML4EPG (PAGE_SIZE/(sizeof (pml4_entry_t)))108#define NPML4EPGSHIFT 9 /* LOG2(NPML4EPG) */109#define PML4SHIFT 39 /* LOG2(NBPML4) */110#define NBPML4 (1UL<<PML4SHIFT)/* bytes/page map lev4 table */111#define PML4MASK (NBPML4-1)112/* Size of the level 5 page-map level-5 table units */113#define NPML5EPG (PAGE_SIZE/(sizeof (pml5_entry_t)))114#define NPML5EPGSHIFT 9 /* LOG2(NPML5EPG) */115#define PML5SHIFT 48 /* LOG2(NBPML5) */116#define NBPML5 (1UL<<PML5SHIFT)/* bytes/page map lev5 table */117#define PML5MASK (NBPML5-1)118119#define MAXPAGESIZES 3 /* maximum number of supported page sizes */120121#define IOPAGES 2 /* pages of i/o permission bitmap */122/*123* I/O permission bitmap has a bit for each I/O port plus an additional124* byte at the end with all bits set. See section "I/O Permission Bit Map"125* in the Intel SDM for more details.126*/127#define IOPERM_BITMAP_SIZE (IOPAGES * PAGE_SIZE + 1)128129#ifndef KSTACK_PAGES130#if defined(KASAN) || defined(KMSAN)131#define KSTACK_PAGES 6132#else133#define KSTACK_PAGES 4 /* pages of kstack (with pcb) */134#endif135#endif136#define KSTACK_GUARD_PAGES 1 /* pages of kstack guard; 0 disables */137138/*139* Mach derived conversion macros140*/141#define trunc_2mpage(x) ((unsigned long)(x) & ~PDRMASK)142#define round_2mpage(x) ((((unsigned long)(x)) + PDRMASK) & ~PDRMASK)143#define trunc_1gpage(x) ((unsigned long)(x) & ~PDPMASK)144145#define amd64_btop(x) ((unsigned long)(x) >> PAGE_SHIFT)146#define amd64_ptob(x) ((unsigned long)(x) << PAGE_SHIFT)147148#define INKERNEL(va) \149(((va) >= kva_layout.dmap_low && (va) < kva_layout.dmap_high) || \150((va) >= kva_layout.km_low && (va) < kva_layout.km_high))151152/*153* Must be power of 2.154*155* Perhaps should be autosized on boot based on found ncpus.156*/157#if MAXCPU > 256158#define SC_TABLESIZE 2048159#else160#define SC_TABLESIZE 1024161#endif162163#endif /* !_AMD64_INCLUDE_PARAM_H_ */164165166