15b81b6b3SRodney W. Grimes /*- 2df57947fSPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause 3df57947fSPedro F. Giffuni * 45b81b6b3SRodney W. Grimes * Copyright (c) 1990 The Regents of the University of California. 55b81b6b3SRodney W. Grimes * All rights reserved. 67f8cb368SDavid Greenman * Copyright (c) 1994 John S. Dyson 77f8cb368SDavid Greenman * All rights reserved. 8fcfe57d6SPeter Wemm * Copyright (c) 2003 Peter Wemm 9fcfe57d6SPeter Wemm * All rights reserved. 105b81b6b3SRodney W. Grimes * 115b81b6b3SRodney W. Grimes * This code is derived from software contributed to Berkeley by 125b81b6b3SRodney W. Grimes * William Jolitz. 135b81b6b3SRodney W. Grimes * 145b81b6b3SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 155b81b6b3SRodney W. Grimes * modification, are permitted provided that the following conditions 165b81b6b3SRodney W. Grimes * are met: 175b81b6b3SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 185b81b6b3SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 195b81b6b3SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 205b81b6b3SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 215b81b6b3SRodney W. Grimes * documentation and/or other materials provided with the distribution. 225b81b6b3SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 235b81b6b3SRodney W. Grimes * must display the following acknowledgement: 245b81b6b3SRodney W. Grimes * This product includes software developed by the University of 255b81b6b3SRodney W. Grimes * California, Berkeley and its contributors. 265b81b6b3SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 275b81b6b3SRodney W. Grimes * may be used to endorse or promote products derived from this software 285b81b6b3SRodney W. Grimes * without specific prior written permission. 295b81b6b3SRodney W. Grimes * 305b81b6b3SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 315b81b6b3SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 325b81b6b3SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 335b81b6b3SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 345b81b6b3SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 355b81b6b3SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 365b81b6b3SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 375b81b6b3SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 385b81b6b3SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 395b81b6b3SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 405b81b6b3SRodney W. Grimes * SUCH DAMAGE. 415b81b6b3SRodney W. Grimes */ 425b81b6b3SRodney W. Grimes 43a69511dbSBrooks Davis #ifdef __i386__ 44a69511dbSBrooks Davis #include <i386/vmparam.h> 45a69511dbSBrooks Davis #else /* !__i386__ */ 46a69511dbSBrooks Davis 476e393973SGarrett Wollman #ifndef _MACHINE_VMPARAM_H_ 486e393973SGarrett Wollman #define _MACHINE_VMPARAM_H_ 1 496e393973SGarrett Wollman 505b81b6b3SRodney W. Grimes /* 51afa88623SPeter Wemm * Machine dependent constants for AMD64. 525b81b6b3SRodney W. Grimes */ 535b81b6b3SRodney W. Grimes 545b81b6b3SRodney W. Grimes /* 555b81b6b3SRodney W. Grimes * Virtual memory related constants, all in bytes 565b81b6b3SRodney W. Grimes */ 5743af5860SEdward Tomasz Napierala #define MAXTSIZ (32768UL*1024*1024) /* max text size */ 585b81b6b3SRodney W. Grimes #ifndef DFLDSIZ 5974269bb4SRobert Millan #define DFLDSIZ (32768UL*1024*1024) /* initial data size limit */ 605b81b6b3SRodney W. Grimes #endif 615b81b6b3SRodney W. Grimes #ifndef MAXDSIZ 623904b13fSPeter Wemm #define MAXDSIZ (32768UL*1024*1024) /* max data size */ 635b81b6b3SRodney W. Grimes #endif 645b81b6b3SRodney W. Grimes #ifndef DFLSSIZ 6529360eb0SDavid Greenman #define DFLSSIZ (8UL*1024*1024) /* initial stack size limit */ 665b81b6b3SRodney W. Grimes #endif 675b81b6b3SRodney W. Grimes #ifndef MAXSSIZ 68cc3112f1SPeter Wemm #define MAXSSIZ (512UL*1024*1024) /* max stack size */ 695b81b6b3SRodney W. Grimes #endif 7029360eb0SDavid Greenman #ifndef SGROWSIZ 7129360eb0SDavid Greenman #define SGROWSIZ (128UL*1024) /* amount to grow stack */ 7229360eb0SDavid Greenman #endif 735b81b6b3SRodney W. Grimes 745b81b6b3SRodney W. Grimes /* 75da76d349SBojan Novković * We provide a single page allocator through the use of the 76da76d349SBojan Novković * direct mapped segment. This uses 2MB pages for reduced 773c9a3c9cSPeter Wemm * TLB pressure. 783c9a3c9cSPeter Wemm */ 7989786088SMark Johnston #if !defined(KASAN) && !defined(KMSAN) 80da76d349SBojan Novković #define UMA_USE_DMAP 816faf45b3SMark Johnston #endif 8268c1eb12SPoul-Henning Kamp 835b81b6b3SRodney W. Grimes /* 8404a18977SAlan Cox * The physical address space is densely populated. 8504a18977SAlan Cox */ 8604a18977SAlan Cox #define VM_PHYSSEG_DENSE 8704a18977SAlan Cox 8804a18977SAlan Cox /* 895b4a3e94SAlan Cox * The number of PHYSSEG entries must be one greater than the number 905b4a3e94SAlan Cox * of phys_avail entries because the phys_avail entry that spans the 915b4a3e94SAlan Cox * largest physical address that is accessible by ISA DMA is split 925b4a3e94SAlan Cox * into two PHYSSEG entries. 935b4a3e94SAlan Cox */ 943165194cSKonstantin Belousov #define VM_PHYSSEG_MAX 63 955b4a3e94SAlan Cox 965b4a3e94SAlan Cox /* 97b16b4c22SMark Johnston * Create three free page pools: VM_FREEPOOL_DEFAULT is the default pool from 98b16b4c22SMark Johnston * which physical pages are allocated and VM_FREEPOOL_DIRECT is the pool from 99b16b4c22SMark Johnston * which physical pages for page tables and small UMA objects are allocated. 100*4441dd40SMark Johnston * VM_FREEPOOL_LAZYINIT is a special-purpose pool that is populated only during 101b16b4c22SMark Johnston * boot and is used to implement deferred initialization of page structures. 1025b4a3e94SAlan Cox */ 103b16b4c22SMark Johnston #define VM_NFREEPOOL 3 104b16b4c22SMark Johnston #define VM_FREEPOOL_LAZYINIT 0 105b16b4c22SMark Johnston #define VM_FREEPOOL_DEFAULT 1 106b16b4c22SMark Johnston #define VM_FREEPOOL_DIRECT 2 1075b4a3e94SAlan Cox 1085b4a3e94SAlan Cox /* 109d866a563SAlan Cox * Create up to three free page lists: VM_FREELIST_DMA32 is for physical pages 110d866a563SAlan Cox * that have physical addresses below 4G but are not accessible by ISA DMA, 111d866a563SAlan Cox * and VM_FREELIST_ISADMA is for physical pages that are accessible by ISA 112d866a563SAlan Cox * DMA. 1135b4a3e94SAlan Cox */ 114d866a563SAlan Cox #define VM_NFREELIST 3 1155b4a3e94SAlan Cox #define VM_FREELIST_DEFAULT 0 116d866a563SAlan Cox #define VM_FREELIST_DMA32 1 11767d33338SWarner Losh #define VM_FREELIST_LOWMEM 2 11867d33338SWarner Losh 11967d33338SWarner Losh #define VM_LOWMEM_BOUNDARY (16 << 20) /* 16MB ISA DMA limit */ 120d866a563SAlan Cox 121d866a563SAlan Cox /* 122d866a563SAlan Cox * Create the DMA32 free list only if the number of physical pages above 123d866a563SAlan Cox * physical address 4G is at least 16M, which amounts to 64GB of physical 124d866a563SAlan Cox * memory. 125d866a563SAlan Cox */ 126d866a563SAlan Cox #define VM_DMA32_NPAGES_THRESHOLD 16777216 1275b4a3e94SAlan Cox 1285b4a3e94SAlan Cox /* 1295b4a3e94SAlan Cox * An allocation size of 16MB is supported in order to optimize the 1305b4a3e94SAlan Cox * use of the direct map by UMA. Specifically, a cache line contains 1315b4a3e94SAlan Cox * at most 8 PDEs, collectively mapping 16MB of physical memory. By 1325b4a3e94SAlan Cox * reducing the number of distinct 16MB "pages" that are used by UMA, 1335b4a3e94SAlan Cox * the physical memory allocator reduces the likelihood of both 2MB 1345b4a3e94SAlan Cox * page TLB misses and cache misses caused by 2MB page TLB misses. 1355b4a3e94SAlan Cox */ 1365b4a3e94SAlan Cox #define VM_NFREEORDER 13 1375b4a3e94SAlan Cox 1385b4a3e94SAlan Cox /* 139b8e7fc24SAlan Cox * Enable superpage reservations: 1 level. 140b8e7fc24SAlan Cox */ 141b8e7fc24SAlan Cox #ifndef VM_NRESERVLEVEL 142b8e7fc24SAlan Cox #define VM_NRESERVLEVEL 1 143b8e7fc24SAlan Cox #endif 144b8e7fc24SAlan Cox 145b8e7fc24SAlan Cox /* 146b8e7fc24SAlan Cox * Level 0 reservations consist of 512 pages. 147b8e7fc24SAlan Cox */ 148b8e7fc24SAlan Cox #ifndef VM_LEVEL_0_ORDER 149b8e7fc24SAlan Cox #define VM_LEVEL_0_ORDER 9 150b8e7fc24SAlan Cox #endif 151b8e7fc24SAlan Cox 1522965a453SKip Macy #ifdef SMP 1532965a453SKip Macy #define PA_LOCK_COUNT 256 1542965a453SKip Macy #endif 1552965a453SKip Macy 156b8e7fc24SAlan Cox /* 157e18380e3SKonstantin Belousov * Kernel physical load address for non-UEFI boot and for legacy UEFI loader. 158e18380e3SKonstantin Belousov * Newer UEFI loader loads kernel anywhere below 4G, with memory allocated 159e18380e3SKonstantin Belousov * by boot services. 160e18380e3SKonstantin Belousov * Needs to be aligned at 2MB superpage boundary. 161fd2ef8efSMaxim Sobolev */ 162fd2ef8efSMaxim Sobolev #ifndef KERNLOAD 163fd2ef8efSMaxim Sobolev #define KERNLOAD 0x200000 164fd2ef8efSMaxim Sobolev #endif 165fd2ef8efSMaxim Sobolev 166fd2ef8efSMaxim Sobolev /* 16768c1eb12SPoul-Henning Kamp * Virtual addresses of things. Derived from the page directory and 16868c1eb12SPoul-Henning Kamp * page table indexes from pmap.h for precision. 16917e21388SAlan Cox * 17017e21388SAlan Cox * 0x0000000000000000 - 0x00007fffffffffff user map 17117e21388SAlan Cox * 0x0000800000000000 - 0xffff7fffffffffff does not exist (hole) 17217e21388SAlan Cox * 0xffff800000000000 - 0xffff804020100fff recursive page table (512GB slot) 1732fd0c8e7SKonstantin Belousov * 0xffff804020100fff - 0xffff807fffffffff unused 1742fd0c8e7SKonstantin Belousov * 0xffff808000000000 - 0xffff847fffffffff large map (can be tuned up) 1756faf45b3SMark Johnston * 0xffff848000000000 - 0xfffff77fffffffff unused (large map extends there) 176f95f780eSMark Johnston * 0xfffff60000000000 - 0xfffff7ffffffffff 2TB KMSAN origin map, optional 177f95f780eSMark Johnston * 0xfffff78000000000 - 0xfffff7bfffffffff 512GB KASAN shadow map, optional 1780ef2ab3aSNeel Natu * 0xfffff80000000000 - 0xfffffbffffffffff 4TB direct map 179f95f780eSMark Johnston * 0xfffffc0000000000 - 0xfffffdffffffffff 2TB KMSAN shadow map, optional 1800ef2ab3aSNeel Natu * 0xfffffe0000000000 - 0xffffffffffffffff 2TB kernel map 18117e21388SAlan Cox * 18217e21388SAlan Cox * Within the kernel map: 18317e21388SAlan Cox * 1849d75f0dcSMark Johnston * 0xfffffe0000000000 vm_page_array 18517e21388SAlan Cox * 0xffffffff80000000 KERNBASE 1865b81b6b3SRodney W. Grimes */ 1875b81b6b3SRodney W. Grimes 1889ce875d9SKonstantin Belousov #define VM_MIN_KERNEL_ADDRESS KV4ADDR(KPML4BASE, 0, 0, 0) 1899ce875d9SKonstantin Belousov #define VM_MAX_KERNEL_ADDRESS KV4ADDR(KPML4BASE + NKPML4E - 1, \ 1900ef2ab3aSNeel Natu NPDPEPG-1, NPDEPG-1, NPTEPG-1) 1917f8cb368SDavid Greenman 1929ce875d9SKonstantin Belousov #define DMAP_MIN_ADDRESS KV4ADDR(DMPML4I, 0, 0, 0) 1939ce875d9SKonstantin Belousov #define DMAP_MAX_ADDRESS KV4ADDR(DMPML4I + NDMPML4E, 0, 0, 0) 19468c1eb12SPoul-Henning Kamp 1956faf45b3SMark Johnston #define KASAN_MIN_ADDRESS KV4ADDR(KASANPML4I, 0, 0, 0) 1966faf45b3SMark Johnston #define KASAN_MAX_ADDRESS KV4ADDR(KASANPML4I + NKASANPML4E, 0, 0, 0) 1976faf45b3SMark Johnston 198f95f780eSMark Johnston #define KMSAN_SHAD_MIN_ADDRESS KV4ADDR(KMSANSHADPML4I, 0, 0, 0) 199f95f780eSMark Johnston #define KMSAN_SHAD_MAX_ADDRESS KV4ADDR(KMSANSHADPML4I + NKMSANSHADPML4E, \ 200f95f780eSMark Johnston 0, 0, 0) 201f95f780eSMark Johnston 202f95f780eSMark Johnston #define KMSAN_ORIG_MIN_ADDRESS KV4ADDR(KMSANORIGPML4I, 0, 0, 0) 203f95f780eSMark Johnston #define KMSAN_ORIG_MAX_ADDRESS KV4ADDR(KMSANORIGPML4I + NKMSANORIGPML4E, \ 204f95f780eSMark Johnston 0, 0, 0) 205f95f780eSMark Johnston 2069ce875d9SKonstantin Belousov #define LARGEMAP_MIN_ADDRESS KV4ADDR(LMSPML4I, 0, 0, 0) 2079ce875d9SKonstantin Belousov #define LARGEMAP_MAX_ADDRESS KV4ADDR(LMEPML4I + 1, 0, 0, 0) 2082fd0c8e7SKonstantin Belousov 209e18380e3SKonstantin Belousov /* 210e18380e3SKonstantin Belousov * Formally kernel mapping starts at KERNBASE, but kernel linker 211e18380e3SKonstantin Belousov * script leaves first PDE reserved. For legacy BIOS boot, kernel is 212e18380e3SKonstantin Belousov * loaded at KERNLOAD = 2M, and initial kernel page table maps 213e18380e3SKonstantin Belousov * physical memory from zero to KERNend starting at KERNBASE. 214e18380e3SKonstantin Belousov * 215e18380e3SKonstantin Belousov * KERNSTART is where the first actual kernel page is mapped, after 216e18380e3SKonstantin Belousov * the compatibility mapping. 217e18380e3SKonstantin Belousov */ 2189ce875d9SKonstantin Belousov #define KERNBASE KV4ADDR(KPML4I, KPDPI, 0, 0) 219e18380e3SKonstantin Belousov #define KERNSTART (KERNBASE + NBPDR) 22068c1eb12SPoul-Henning Kamp 2219ce875d9SKonstantin Belousov #define UPT_MAX_ADDRESS KV4ADDR(PML4PML4I, PML4PML4I, PML4PML4I, PML4PML4I) 2229ce875d9SKonstantin Belousov #define UPT_MIN_ADDRESS KV4ADDR(PML4PML4I, 0, 0, 0) 2233c9a3c9cSPeter Wemm 2249ce875d9SKonstantin Belousov #define VM_MAXUSER_ADDRESS_LA57 UVADDR(NUPML5E, 0, 0, 0, 0) 2259ce875d9SKonstantin Belousov #define VM_MAXUSER_ADDRESS_LA48 UVADDR(0, NUP4ML4E, 0, 0, 0) 2269ce875d9SKonstantin Belousov #define VM_MAXUSER_ADDRESS VM_MAXUSER_ADDRESS_LA57 22768c1eb12SPoul-Henning Kamp 2289ce875d9SKonstantin Belousov #define SHAREDPAGE_LA57 (VM_MAXUSER_ADDRESS_LA57 - PAGE_SIZE) 2299ce875d9SKonstantin Belousov #define SHAREDPAGE_LA48 (VM_MAXUSER_ADDRESS_LA48 - PAGE_SIZE) 2309ce875d9SKonstantin Belousov #define USRSTACK_LA57 SHAREDPAGE_LA57 2319ce875d9SKonstantin Belousov #define USRSTACK_LA48 SHAREDPAGE_LA48 2329ce875d9SKonstantin Belousov #define USRSTACK USRSTACK_LA48 2339ce875d9SKonstantin Belousov #define PS_STRINGS_LA57 (USRSTACK_LA57 - sizeof(struct ps_strings)) 2349ce875d9SKonstantin Belousov #define PS_STRINGS_LA48 (USRSTACK_LA48 - sizeof(struct ps_strings)) 23568c1eb12SPoul-Henning Kamp 236afa88623SPeter Wemm #define VM_MAX_ADDRESS UPT_MAX_ADDRESS 237afa88623SPeter Wemm #define VM_MIN_ADDRESS (0) 2385b81b6b3SRodney W. Grimes 23996699e86SEd Maste /* 24096699e86SEd Maste * XXX Allowing dmaplimit == 0 is a temporary workaround for vt(4) efifb's 24196699e86SEd Maste * early use of PHYS_TO_DMAP before the mapping is actually setup. This works 24296699e86SEd Maste * because the result is not actually accessed until later, but the early 24396699e86SEd Maste * vt fb startup needs to be reworked. 24496699e86SEd Maste */ 24590d4da62SMitchell Horne #define PHYS_IN_DMAP(pa) (dmaplimit == 0 || (pa) < dmaplimit) 24690d4da62SMitchell Horne #define VIRT_IN_DMAP(va) ((va) >= DMAP_MIN_ADDRESS && \ 24790d4da62SMitchell Horne (va) < (DMAP_MIN_ADDRESS + dmaplimit)) 24890d4da62SMitchell Horne 2499a8196ceSNathan Whitehorn #define PMAP_HAS_DMAP 1 250927dc0e0SRoger Pau Monné #define PHYS_TO_DMAP(x) ({ \ 25190d4da62SMitchell Horne KASSERT(PHYS_IN_DMAP(x), \ 252927dc0e0SRoger Pau Monné ("physical address %#jx not covered by the DMAP", \ 253927dc0e0SRoger Pau Monné (uintmax_t)x)); \ 254b5243bd4SKonstantin Belousov (x) | DMAP_MIN_ADDRESS; }) 255927dc0e0SRoger Pau Monné 256927dc0e0SRoger Pau Monné #define DMAP_TO_PHYS(x) ({ \ 25790d4da62SMitchell Horne KASSERT(VIRT_IN_DMAP(x), \ 258927dc0e0SRoger Pau Monné ("virtual address %#jx not covered by the DMAP", \ 259927dc0e0SRoger Pau Monné (uintmax_t)x)); \ 260b5243bd4SKonstantin Belousov (x) & ~DMAP_MIN_ADDRESS; }) 2613c9a3c9cSPeter Wemm 262d9bed5beSJohn Dyson /* 2639d75f0dcSMark Johnston * amd64 maps the page array into KVA so that it can be more easily 2649d75f0dcSMark Johnston * allocated on the correct memory domains. 2653e5e1b51SJeff Roberson */ 2663e5e1b51SJeff Roberson #define PMAP_HAS_PAGE_ARRAY 1 2673e5e1b51SJeff Roberson 2683e5e1b51SJeff Roberson /* 269c70af487SAlan Cox * How many physical pages per kmem arena virtual page. 270d9bed5beSJohn Dyson */ 271d9bed5beSJohn Dyson #ifndef VM_KMEM_SIZE_SCALE 2720b750af1SAndriy Gapon #define VM_KMEM_SIZE_SCALE (1) 273d9bed5beSJohn Dyson #endif 274d9bed5beSJohn Dyson 275d9bed5beSJohn Dyson /* 276c70af487SAlan Cox * Optional ceiling (in bytes) on the size of the kmem arena: 60% of the 277c70af487SAlan Cox * kernel map. 278d9bed5beSJohn Dyson */ 279d9bed5beSJohn Dyson #ifndef VM_KMEM_SIZE_MAX 280db0a9105SAlan Cox #define VM_KMEM_SIZE_MAX ((VM_MAX_KERNEL_ADDRESS - \ 281db0a9105SAlan Cox VM_MIN_KERNEL_ADDRESS + 1) * 3 / 5) 2827bcc0f3dSTor Egge #endif 2835b81b6b3SRodney W. Grimes 28495461b45SJohn Dyson /* initial pagein size of beginning of executable file */ 28595461b45SJohn Dyson #ifndef VM_INITIAL_PAGEIN 28695461b45SJohn Dyson #define VM_INITIAL_PAGEIN 16 28795461b45SJohn Dyson #endif 28895461b45SJohn Dyson 289cfb00e5aSMatthew D Fleming #define ZERO_REGION_SIZE (2 * 1024 * 1024) /* 2MB */ 290cfb00e5aSMatthew D Fleming 2915cd29d0fSMark Johnston /* 29278257765SMark Johnston * The pmap can create non-transparent large page mappings. 29378257765SMark Johnston */ 29478257765SMark Johnston #define PMAP_HAS_LARGEPAGES 1 29578257765SMark Johnston 29678257765SMark Johnston /* 297ab041f71SD Scott Phillips * Need a page dump array for minidump. 298ab041f71SD Scott Phillips */ 299ab041f71SD Scott Phillips #define MINIDUMP_PAGE_TRACKING 1 3000a44b8a5SBojan Novković #define MINIDUMP_STARTUP_PAGE_TRACKING 1 301ab041f71SD Scott Phillips 3026e393973SGarrett Wollman #endif /* _MACHINE_VMPARAM_H_ */ 303a69511dbSBrooks Davis 304a69511dbSBrooks Davis #endif /* __i386__ */ 305