/*-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 <sys/_align.h>4445#define STACKALIGNBYTES (16 - 1)46#define REDZONE_SZ 1284748/*49* Machine dependent constants for AMD64.50*/5152#ifndef MACHINE53#define MACHINE "amd64"54#endif55#ifndef MACHINE_ARCH56#define MACHINE_ARCH "amd64"57#endif58#ifndef MACHINE_ARCH3259#define MACHINE_ARCH32 "i386"60#endif6162#ifdef SMP63#ifndef MAXCPU64#define MAXCPU 102465#endif66#else67#define MAXCPU 168#endif6970#ifndef MAXMEMDOM71#define MAXMEMDOM 872#endif7374#define ALIGNBYTES _ALIGNBYTES75#define ALIGN(p) _ALIGN(p)76/*77* ALIGNED_POINTER is a boolean macro that checks whether an address78* is valid to fetch data elements of type t from on this architecture.79* This does not reflect the optimal alignment, just the possibility80* (within reasonable limits).81*/82#define ALIGNED_POINTER(p, t) 18384/*85* CACHE_LINE_SIZE is the compile-time maximum cache line size for an86* architecture. It should be used with appropriate caution.87*/88#define CACHE_LINE_SHIFT 689#define CACHE_LINE_SIZE (1 << CACHE_LINE_SHIFT)9091/* Size of the level 1 page table units */92#define NPTEPG (PAGE_SIZE/(sizeof (pt_entry_t)))93#define NPTEPGSHIFT 9 /* LOG2(NPTEPG) */94#define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */95#define PAGE_SIZE (1<<PAGE_SHIFT) /* bytes/page */96#define PAGE_MASK (PAGE_SIZE-1)97/* Size of the level 2 page directory units */98#define NPDEPG (PAGE_SIZE/(sizeof (pd_entry_t)))99#define NPDEPGSHIFT 9 /* LOG2(NPDEPG) */100#define PDRSHIFT 21 /* LOG2(NBPDR) */101#define NBPDR (1<<PDRSHIFT) /* bytes/page dir */102#define PDRMASK (NBPDR-1)103/* Size of the level 3 page directory pointer table units */104#define NPDPEPG (PAGE_SIZE/(sizeof (pdp_entry_t)))105#define NPDPEPGSHIFT 9 /* LOG2(NPDPEPG) */106#define PDPSHIFT 30 /* LOG2(NBPDP) */107#define NBPDP (1<<PDPSHIFT) /* bytes/page dir ptr table */108#define PDPMASK (NBPDP-1)109/* Size of the level 4 page-map level-4 table units */110#define NPML4EPG (PAGE_SIZE/(sizeof (pml4_entry_t)))111#define NPML4EPGSHIFT 9 /* LOG2(NPML4EPG) */112#define PML4SHIFT 39 /* LOG2(NBPML4) */113#define NBPML4 (1UL<<PML4SHIFT)/* bytes/page map lev4 table */114#define PML4MASK (NBPML4-1)115/* Size of the level 5 page-map level-5 table units */116#define NPML5EPG (PAGE_SIZE/(sizeof (pml5_entry_t)))117#define NPML5EPGSHIFT 9 /* LOG2(NPML5EPG) */118#define PML5SHIFT 48 /* LOG2(NBPML5) */119#define NBPML5 (1UL<<PML5SHIFT)/* bytes/page map lev5 table */120#define PML5MASK (NBPML5-1)121122#define MAXPAGESIZES 3 /* maximum number of supported page sizes */123124#define IOPAGES 2 /* pages of i/o permission bitmap */125/*126* I/O permission bitmap has a bit for each I/O port plus an additional127* byte at the end with all bits set. See section "I/O Permission Bit Map"128* in the Intel SDM for more details.129*/130#define IOPERM_BITMAP_SIZE (IOPAGES * PAGE_SIZE + 1)131132#ifndef KSTACK_PAGES133#if defined(KASAN) || defined(KMSAN)134#define KSTACK_PAGES 6135#else136#define KSTACK_PAGES 4 /* pages of kstack (with pcb) */137#endif138#endif139#define KSTACK_GUARD_PAGES 1 /* pages of kstack guard; 0 disables */140141/*142* Mach derived conversion macros143*/144#define trunc_2mpage(x) ((unsigned long)(x) & ~PDRMASK)145#define round_2mpage(x) ((((unsigned long)(x)) + PDRMASK) & ~PDRMASK)146#define trunc_1gpage(x) ((unsigned long)(x) & ~PDPMASK)147148#define amd64_btop(x) ((unsigned long)(x) >> PAGE_SHIFT)149#define amd64_ptob(x) ((unsigned long)(x) << PAGE_SHIFT)150151#define INKERNEL(va) \152(((va) >= kva_layout.dmap_low && (va) < kva_layout.dmap_high) || \153((va) >= kva_layout.km_low && (va) < kva_layout.km_high))154155/*156* Must be power of 2.157*158* Perhaps should be autosized on boot based on found ncpus.159*/160#if MAXCPU > 256161#define SC_TABLESIZE 2048162#else163#define SC_TABLESIZE 1024164#endif165166#endif /* !_AMD64_INCLUDE_PARAM_H_ */167168169