18d7e7a98SRuslan Bukin /*- 28d7e7a98SRuslan Bukin * Copyright (c) 1990 The Regents of the University of California. 38d7e7a98SRuslan Bukin * All rights reserved. 48d7e7a98SRuslan Bukin * Copyright (c) 1994 John S. Dyson 58d7e7a98SRuslan Bukin * All rights reserved. 68d7e7a98SRuslan Bukin * 78d7e7a98SRuslan Bukin * This code is derived from software contributed to Berkeley by 88d7e7a98SRuslan Bukin * William Jolitz. 98d7e7a98SRuslan Bukin * 108d7e7a98SRuslan Bukin * Redistribution and use in source and binary forms, with or without 118d7e7a98SRuslan Bukin * modification, are permitted provided that the following conditions 128d7e7a98SRuslan Bukin * are met: 138d7e7a98SRuslan Bukin * 1. Redistributions of source code must retain the above copyright 148d7e7a98SRuslan Bukin * notice, this list of conditions and the following disclaimer. 158d7e7a98SRuslan Bukin * 2. Redistributions in binary form must reproduce the above copyright 168d7e7a98SRuslan Bukin * notice, this list of conditions and the following disclaimer in the 178d7e7a98SRuslan Bukin * documentation and/or other materials provided with the distribution. 188d7e7a98SRuslan Bukin * 3. Neither the name of the University nor the names of its contributors 198d7e7a98SRuslan Bukin * may be used to endorse or promote products derived from this software 208d7e7a98SRuslan Bukin * without specific prior written permission. 218d7e7a98SRuslan Bukin * 228d7e7a98SRuslan Bukin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 238d7e7a98SRuslan Bukin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 248d7e7a98SRuslan Bukin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 258d7e7a98SRuslan Bukin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 268d7e7a98SRuslan Bukin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 278d7e7a98SRuslan Bukin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 288d7e7a98SRuslan Bukin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 298d7e7a98SRuslan Bukin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 308d7e7a98SRuslan Bukin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 318d7e7a98SRuslan Bukin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 328d7e7a98SRuslan Bukin * SUCH DAMAGE. 338d7e7a98SRuslan Bukin * from: FreeBSD: src/sys/i386/include/vmparam.h,v 1.33 2000/03/30 348d7e7a98SRuslan Bukin */ 358d7e7a98SRuslan Bukin 368d7e7a98SRuslan Bukin #ifndef _MACHINE_VMPARAM_H_ 378d7e7a98SRuslan Bukin #define _MACHINE_VMPARAM_H_ 388d7e7a98SRuslan Bukin 398d7e7a98SRuslan Bukin /* 408d7e7a98SRuslan Bukin * Virtual memory related constants, all in bytes 418d7e7a98SRuslan Bukin */ 428d7e7a98SRuslan Bukin #ifndef MAXTSIZ 43229f3f0dSRuslan Bukin #define MAXTSIZ (1*1024*1024*1024) /* max text size */ 448d7e7a98SRuslan Bukin #endif 458d7e7a98SRuslan Bukin #ifndef DFLDSIZ 468d7e7a98SRuslan Bukin #define DFLDSIZ (128*1024*1024) /* initial data size limit */ 478d7e7a98SRuslan Bukin #endif 488d7e7a98SRuslan Bukin #ifndef MAXDSIZ 49229f3f0dSRuslan Bukin #define MAXDSIZ (1*1024*1024*1024) /* max data size */ 508d7e7a98SRuslan Bukin #endif 518d7e7a98SRuslan Bukin #ifndef DFLSSIZ 52229f3f0dSRuslan Bukin #define DFLSSIZ (128*1024*1024) /* initial stack size limit */ 538d7e7a98SRuslan Bukin #endif 548d7e7a98SRuslan Bukin #ifndef MAXSSIZ 55229f3f0dSRuslan Bukin #define MAXSSIZ (1*1024*1024*1024) /* max stack size */ 568d7e7a98SRuslan Bukin #endif 578d7e7a98SRuslan Bukin #ifndef SGROWSIZ 588d7e7a98SRuslan Bukin #define SGROWSIZ (128*1024) /* amount to grow stack */ 598d7e7a98SRuslan Bukin #endif 608d7e7a98SRuslan Bukin 618d7e7a98SRuslan Bukin /* 628d7e7a98SRuslan Bukin * The physical address space is sparsely populated. 638d7e7a98SRuslan Bukin */ 648d7e7a98SRuslan Bukin #define VM_PHYSSEG_SPARSE 658d7e7a98SRuslan Bukin 668d7e7a98SRuslan Bukin /* 679ecd7fdeSWarner Losh * The number of PHYSSEG entries. 688d7e7a98SRuslan Bukin */ 698d7e7a98SRuslan Bukin #define VM_PHYSSEG_MAX 64 708d7e7a98SRuslan Bukin 718d7e7a98SRuslan Bukin /* 728d7e7a98SRuslan Bukin * Create two free page pools: VM_FREEPOOL_DEFAULT is the default pool 738d7e7a98SRuslan Bukin * from which physical pages are allocated and VM_FREEPOOL_DIRECT is 748d7e7a98SRuslan Bukin * the pool from which physical pages for small UMA objects are 758d7e7a98SRuslan Bukin * allocated. 768d7e7a98SRuslan Bukin */ 778d7e7a98SRuslan Bukin #define VM_NFREEPOOL 2 788d7e7a98SRuslan Bukin #define VM_FREEPOOL_DEFAULT 0 798d7e7a98SRuslan Bukin #define VM_FREEPOOL_DIRECT 1 808d7e7a98SRuslan Bukin 818d7e7a98SRuslan Bukin /* 829ecd7fdeSWarner Losh * Create one free page list: VM_FREELIST_DEFAULT is for all physical 839ecd7fdeSWarner Losh * pages. 848d7e7a98SRuslan Bukin */ 859ecd7fdeSWarner Losh #define VM_NFREELIST 1 868d7e7a98SRuslan Bukin #define VM_FREELIST_DEFAULT 0 878d7e7a98SRuslan Bukin 888d7e7a98SRuslan Bukin /* 898d7e7a98SRuslan Bukin * An allocation size of 16MB is supported in order to optimize the 908d7e7a98SRuslan Bukin * use of the direct map by UMA. Specifically, a cache line contains 918d7e7a98SRuslan Bukin * at most four TTEs, collectively mapping 16MB of physical memory. 928d7e7a98SRuslan Bukin * By reducing the number of distinct 16MB "pages" that are used by UMA, 938d7e7a98SRuslan Bukin * the physical memory allocator reduces the likelihood of both 4MB 948d7e7a98SRuslan Bukin * page TLB misses and cache misses caused by 4MB page TLB misses. 958d7e7a98SRuslan Bukin */ 968d7e7a98SRuslan Bukin #define VM_NFREEORDER 12 978d7e7a98SRuslan Bukin 988d7e7a98SRuslan Bukin /* 99f6893f09SMark Johnston * Enable superpage reservations: 1 level. 1008d7e7a98SRuslan Bukin */ 1018d7e7a98SRuslan Bukin #ifndef VM_NRESERVLEVEL 102f6893f09SMark Johnston #define VM_NRESERVLEVEL 1 1038d7e7a98SRuslan Bukin #endif 1048d7e7a98SRuslan Bukin 1058d7e7a98SRuslan Bukin /* 1068d7e7a98SRuslan Bukin * Level 0 reservations consist of 512 pages. 1078d7e7a98SRuslan Bukin */ 1088d7e7a98SRuslan Bukin #ifndef VM_LEVEL_0_ORDER 1098d7e7a98SRuslan Bukin #define VM_LEVEL_0_ORDER 9 1108d7e7a98SRuslan Bukin #endif 1118d7e7a98SRuslan Bukin 1128d7e7a98SRuslan Bukin /** 1138d7e7a98SRuslan Bukin * Address space layout. 1148d7e7a98SRuslan Bukin * 1151a153f42SMark Johnston * RISC-V implements multiple paging modes with different virtual address space 11635d0f443SMark Johnston * sizes: SV32, SV39, SV48 and SV57. Only SV39 and SV48 are supported by 11735d0f443SMark Johnston * FreeBSD. SV39 provides a 512GB virtual address space and uses three-level 11835d0f443SMark Johnston * page tables, while SV48 provides a 256TB virtual address space and uses 11935d0f443SMark Johnston * four-level page tables. 64-bit RISC-V implementations are required to provide 12035d0f443SMark Johnston * at least SV39 mode; locore initially enables SV39 mode while bootstrapping 12135d0f443SMark Johnston * page tables, and pmap_bootstrap() optionally switches to SV48 mode. 1228d7e7a98SRuslan Bukin * 1231a153f42SMark Johnston * The address space is split into two regions at each end of the 64-bit address 12435d0f443SMark Johnston * space; the lower region is for use by user mode software, while the upper 12535d0f443SMark Johnston * region is used for various kernel maps. The kernel map layout in SV48 mode 12635d0f443SMark Johnston * is currently identical to that used in SV39 mode. 1278d7e7a98SRuslan Bukin * 12835d0f443SMark Johnston * SV39 memory map: 1291a153f42SMark Johnston * 0x0000000000000000 - 0x0000003fffffffff 256GB user map 1301a153f42SMark Johnston * 0x0000004000000000 - 0xffffffbfffffffff unmappable 1311a153f42SMark Johnston * 0xffffffc000000000 - 0xffffffc7ffffffff 32GB kernel map 1321a153f42SMark Johnston * 0xffffffc800000000 - 0xffffffcfffffffff 32GB unused 1331a153f42SMark Johnston * 0xffffffd000000000 - 0xffffffefffffffff 128GB direct map 1341a153f42SMark Johnston * 0xfffffff000000000 - 0xffffffffffffffff 64GB unused 1358d7e7a98SRuslan Bukin * 13635d0f443SMark Johnston * SV48 memory map: 13735d0f443SMark Johnston * 0x0000000000000000 - 0x00007fffffffffff 128TB user map 13835d0f443SMark Johnston * 0x0000800000000000 - 0xffff7fffffffffff unmappable 13935d0f443SMark Johnston * 0xffff800000000000 - 0xffffffc7ffffffff 127.75TB hole 14035d0f443SMark Johnston * 0xffffffc000000000 - 0xffffffc7ffffffff 32GB kernel map 14135d0f443SMark Johnston * 0xffffffc800000000 - 0xffffffcfffffffff 32GB unused 14235d0f443SMark Johnston * 0xffffffd000000000 - 0xffffffefffffffff 128GB direct map 14335d0f443SMark Johnston * 0xfffffff000000000 - 0xffffffffffffffff 64GB unused 14435d0f443SMark Johnston * 1451a153f42SMark Johnston * The kernel is loaded at the beginning of the kernel map. 1468d7e7a98SRuslan Bukin * 1478d7e7a98SRuslan Bukin * We define some interesting address constants: 1488d7e7a98SRuslan Bukin * 1498d7e7a98SRuslan Bukin * VM_MIN_ADDRESS and VM_MAX_ADDRESS define the start and end of the entire 1508d7e7a98SRuslan Bukin * 64 bit address space, mostly just for convenience. 1518d7e7a98SRuslan Bukin * 1528d7e7a98SRuslan Bukin * VM_MIN_KERNEL_ADDRESS and VM_MAX_KERNEL_ADDRESS define the start and end of 1538d7e7a98SRuslan Bukin * mappable kernel virtual address space. 1548d7e7a98SRuslan Bukin * 1558d7e7a98SRuslan Bukin * VM_MIN_USER_ADDRESS and VM_MAX_USER_ADDRESS define the start and end of the 1568d7e7a98SRuslan Bukin * user address space. 1578d7e7a98SRuslan Bukin */ 1588d7e7a98SRuslan Bukin #define VM_MIN_ADDRESS (0x0000000000000000UL) 1598d7e7a98SRuslan Bukin #define VM_MAX_ADDRESS (0xffffffffffffffffUL) 1608d7e7a98SRuslan Bukin 16102a37128SRuslan Bukin #define VM_MIN_KERNEL_ADDRESS (0xffffffc000000000UL) 16202a37128SRuslan Bukin #define VM_MAX_KERNEL_ADDRESS (0xffffffc800000000UL) 1638d7e7a98SRuslan Bukin 16402a37128SRuslan Bukin #define DMAP_MIN_ADDRESS (0xffffffd000000000UL) 1655f8228b2SRuslan Bukin #define DMAP_MAX_ADDRESS (0xfffffff000000000UL) 1668d7e7a98SRuslan Bukin 1675f8228b2SRuslan Bukin #define DMAP_MIN_PHYSADDR (dmap_phys_base) 1685f8228b2SRuslan Bukin #define DMAP_MAX_PHYSADDR (dmap_phys_max) 1698d7e7a98SRuslan Bukin 1708d7e7a98SRuslan Bukin /* True if pa is in the dmap range */ 171229f3f0dSRuslan Bukin #define PHYS_IN_DMAP(pa) ((pa) >= DMAP_MIN_PHYSADDR && \ 1725f8228b2SRuslan Bukin (pa) < DMAP_MAX_PHYSADDR) 1738d7e7a98SRuslan Bukin /* True if va is in the dmap range */ 1748d7e7a98SRuslan Bukin #define VIRT_IN_DMAP(va) ((va) >= DMAP_MIN_ADDRESS && \ 1755f8228b2SRuslan Bukin (va) < (dmap_max_addr)) 1768d7e7a98SRuslan Bukin 1779a8196ceSNathan Whitehorn #define PMAP_HAS_DMAP 1 1788d7e7a98SRuslan Bukin #define PHYS_TO_DMAP(pa) \ 1798d7e7a98SRuslan Bukin ({ \ 1808d7e7a98SRuslan Bukin KASSERT(PHYS_IN_DMAP(pa), \ 1818d7e7a98SRuslan Bukin ("%s: PA out of range, PA: 0x%lx", __func__, \ 1828d7e7a98SRuslan Bukin (vm_paddr_t)(pa))); \ 1835f8228b2SRuslan Bukin ((pa) - dmap_phys_base) + DMAP_MIN_ADDRESS; \ 1848d7e7a98SRuslan Bukin }) 1858d7e7a98SRuslan Bukin 1868d7e7a98SRuslan Bukin #define DMAP_TO_PHYS(va) \ 1878d7e7a98SRuslan Bukin ({ \ 1888d7e7a98SRuslan Bukin KASSERT(VIRT_IN_DMAP(va), \ 1898d7e7a98SRuslan Bukin ("%s: VA out of range, VA: 0x%lx", __func__, \ 1908d7e7a98SRuslan Bukin (vm_offset_t)(va))); \ 1915f8228b2SRuslan Bukin ((va) - DMAP_MIN_ADDRESS) + dmap_phys_base; \ 1928d7e7a98SRuslan Bukin }) 1938d7e7a98SRuslan Bukin 19435d0f443SMark Johnston #define VM_MIN_USER_ADDRESS (0x0000000000000000UL) 19559f192c5SMark Johnston #define VM_MAX_USER_ADDRESS_SV39 (0x0000004000000000UL) 19635d0f443SMark Johnston #define VM_MAX_USER_ADDRESS_SV48 (0x0000800000000000UL) 19731218f32SMark Johnston #define VM_MAX_USER_ADDRESS VM_MAX_USER_ADDRESS_SV48 1988d7e7a98SRuslan Bukin 1998d7e7a98SRuslan Bukin #define VM_MINUSER_ADDRESS (VM_MIN_USER_ADDRESS) 2008d7e7a98SRuslan Bukin #define VM_MAXUSER_ADDRESS (VM_MAX_USER_ADDRESS) 2018d7e7a98SRuslan Bukin 2028d7e7a98SRuslan Bukin #define KERNBASE (VM_MIN_KERNEL_ADDRESS) 20359f192c5SMark Johnston #define SHAREDPAGE_SV39 (VM_MAX_USER_ADDRESS_SV39 - PAGE_SIZE) 20435d0f443SMark Johnston #define SHAREDPAGE_SV48 (VM_MAX_USER_ADDRESS_SV48 - PAGE_SIZE) 20531218f32SMark Johnston #define SHAREDPAGE SHAREDPAGE_SV48 20635d0f443SMark Johnston #define USRSTACK_SV39 SHAREDPAGE_SV39 20735d0f443SMark Johnston #define USRSTACK_SV48 SHAREDPAGE_SV48 20831218f32SMark Johnston #define USRSTACK USRSTACK_SV48 20959f192c5SMark Johnston #define PS_STRINGS_SV39 (USRSTACK_SV39 - sizeof(struct ps_strings)) 21035d0f443SMark Johnston #define PS_STRINGS_SV48 (USRSTACK_SV48 - sizeof(struct ps_strings)) 211229f3f0dSRuslan Bukin 2128d7e7a98SRuslan Bukin /* 2138d7e7a98SRuslan Bukin * How many physical pages per kmem arena virtual page. 2148d7e7a98SRuslan Bukin */ 2158d7e7a98SRuslan Bukin #ifndef VM_KMEM_SIZE_SCALE 2163e3eb5f4SMark Johnston #define VM_KMEM_SIZE_SCALE (1) 2178d7e7a98SRuslan Bukin #endif 2188d7e7a98SRuslan Bukin 2198d7e7a98SRuslan Bukin /* 2208d7e7a98SRuslan Bukin * Optional ceiling (in bytes) on the size of the kmem arena: 60% of the 2218d7e7a98SRuslan Bukin * kernel map. 2228d7e7a98SRuslan Bukin */ 2238d7e7a98SRuslan Bukin #ifndef VM_KMEM_SIZE_MAX 2248d7e7a98SRuslan Bukin #define VM_KMEM_SIZE_MAX ((VM_MAX_KERNEL_ADDRESS - \ 2258d7e7a98SRuslan Bukin VM_MIN_KERNEL_ADDRESS + 1) * 3 / 5) 2268d7e7a98SRuslan Bukin #endif 2278d7e7a98SRuslan Bukin 2288d7e7a98SRuslan Bukin /* 2298d7e7a98SRuslan Bukin * Initial pagein size of beginning of executable file. 2308d7e7a98SRuslan Bukin */ 2318d7e7a98SRuslan Bukin #ifndef VM_INITIAL_PAGEIN 2328d7e7a98SRuslan Bukin #define VM_INITIAL_PAGEIN 16 2338d7e7a98SRuslan Bukin #endif 2348d7e7a98SRuslan Bukin 235da76d349SBojan Novković #define UMA_USE_DMAP 2368d7e7a98SRuslan Bukin 2375f8228b2SRuslan Bukin #ifndef LOCORE 2385f8228b2SRuslan Bukin extern vm_paddr_t dmap_phys_base; 2395f8228b2SRuslan Bukin extern vm_paddr_t dmap_phys_max; 2405f8228b2SRuslan Bukin extern vm_offset_t dmap_max_addr; 2415f8228b2SRuslan Bukin #endif 2428d7e7a98SRuslan Bukin 2438d7e7a98SRuslan Bukin #define ZERO_REGION_SIZE (64 * 1024) /* 64KB */ 2448d7e7a98SRuslan Bukin 245*de09dcebSMitchell Horne /* 246*de09dcebSMitchell Horne * The top of KVA is reserved for early device mappings. 247*de09dcebSMitchell Horne */ 24830b72b68SRuslan Bukin #define DEVMAP_MAX_VADDR VM_MAX_KERNEL_ADDRESS 249*de09dcebSMitchell Horne #define DEVMAP_MIN_VADDR (DEVMAP_MAX_VADDR - PMAP_MAPDEV_EARLY_SIZE) 250*de09dcebSMitchell Horne #define PMAP_MAPDEV_EARLY_SIZE (4 * L2_SIZE) 25130b72b68SRuslan Bukin 252ab041f71SD Scott Phillips /* 25378257765SMark Johnston * No non-transparent large page support in the pmap. 25478257765SMark Johnston */ 25578257765SMark Johnston #define PMAP_HAS_LARGEPAGES 0 25678257765SMark Johnston 25778257765SMark Johnston /* 258ab041f71SD Scott Phillips * Need a page dump array for minidump. 259ab041f71SD Scott Phillips */ 260ab041f71SD Scott Phillips #define MINIDUMP_PAGE_TRACKING 1 2610a44b8a5SBojan Novković #define MINIDUMP_STARTUP_PAGE_TRACKING 1 262ab041f71SD Scott Phillips 2638d7e7a98SRuslan Bukin #endif /* !_MACHINE_VMPARAM_H_ */ 264