1# Copyright (c) 2021 Intel Corporation 2# 3# SPDX-License-Identifier: Apache-2.0 4 5menu "Virtual Memory Support" 6 7config KERNEL_VM_SUPPORT 8 bool 9 help 10 Hidden option to enable virtual memory Kconfigs. 11 12if KERNEL_VM_SUPPORT 13 14DT_CHOSEN_Z_SRAM := zephyr,sram 15 16config KERNEL_VM_BASE 17 hex "Virtual address space base address" 18 default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_SRAM)) 19 help 20 Define the base of the kernel's address space. 21 22 By default, this is the same as the DT_CHOSEN_Z_SRAM physical base SRAM 23 address from DTS, in which case RAM will be identity-mapped. Some 24 architectures may require RAM to be mapped in this way; they may have 25 just one RAM region and doing this makes linking much simpler, as 26 at least when the kernel boots all virtual RAM addresses are the same 27 as their physical address (demand paging at runtime may later modify 28 this for non-pinned page frames). 29 30 Otherwise, if RAM isn't identity-mapped: 31 1. It is the architecture's responsibility to transition the 32 instruction pointer to virtual addresses at early boot before 33 entering the kernel at z_cstart(). 34 2. The underlying architecture may impose constraints on the bounds of 35 the kernel's address space, such as not overlapping physical RAM 36 regions if RAM is not identity-mapped, or the virtual and physical 37 base addresses being aligned to some common value (which allows 38 double-linking of paging structures to make the instruction pointer 39 transition simpler). 40 41 Zephyr does not implement a split address space and if multiple 42 page tables are in use, they all have the same virtual-to-physical 43 mappings (with potentially different permissions). 44 45config KERNEL_VM_OFFSET 46 hex "Kernel offset within address space" 47 default 0 48 help 49 Offset that the kernel image begins within its address space, 50 if this is not the same offset from the beginning of RAM. 51 52 Some care may need to be taken in selecting this value. In certain 53 build-time cases, or when a physical address cannot be looked up 54 in page tables, the equation: 55 56 virt = phys + ((KERNEL_VM_BASE + KERNEL_VM_OFFSET) - 57 (SRAM_BASE_ADDRESS + SRAM_OFFSET)) 58 59 Will be used to convert between physical and virtual addresses for 60 memory that is mapped at boot. 61 62 This uncommon and is only necessary if the beginning of VM and 63 physical memory have dissimilar alignment. 64 65config KERNEL_VM_SIZE 66 hex "Size of kernel address space in bytes" 67 default 0x800000 68 help 69 Size of the kernel's address space. Constraining this helps control 70 how much total memory can be used for page tables. 71 72 The difference between KERNEL_VM_BASE and KERNEL_VM_SIZE indicates the 73 size of the virtual region for runtime memory mappings. This is needed 74 for mapping driver MMIO regions, as well as special RAM mapping use-cases 75 such as VSDO pages, memory mapped thread stacks, and anonymous memory 76 mappings. The kernel itself will be mapped in here as well at boot. 77 78 Systems with very large amounts of memory (such as 512M or more) 79 will want to use a 64-bit build of Zephyr, there are no plans to 80 implement a notion of "high" memory in Zephyr to work around physical 81 RAM size larger than the defined bounds of the virtual address space. 82 83config KERNEL_DIRECT_MAP 84 bool "Memory region direct-map support" 85 depends on MMU 86 help 87 This enables the direct-map support, namely the region can be 1:1 88 mapping between virtual address and physical address. 89 90 If the specific memory region is in the virtual memory space and 91 there isn't overlap with the existed mappings, it will reserve the 92 region from the virtual memory space and do the mapping, otherwise 93 it will fail. And any attempt across the boundary of the virtual 94 memory space will fail. 95 96 Note that this is for compatibility and portable apps shouldn't 97 be using it. 98 99endif # KERNEL_VM_SUPPORT 100 101menuconfig MMU 102 bool "MMU features" 103 depends on CPU_HAS_MMU 104 select KERNEL_VM_SUPPORT 105 help 106 This option is enabled when the CPU's memory management unit is active 107 and the arch_mem_map() API is available. 108 109if MMU 110config MMU_PAGE_SIZE 111 hex "Size of smallest granularity MMU page" 112 default 0x1000 113 help 114 Size of memory pages. Varies per MMU but 4K is common. For MMUs that 115 support multiple page sizes, put the smallest one here. 116 117menuconfig DEMAND_PAGING 118 bool "Demand paging [EXPERIMENTAL]" 119 depends on ARCH_HAS_DEMAND_PAGING 120 help 121 Enable demand paging. Requires architecture support in how the kernel 122 is linked and the implementation of an eviction algorithm and a 123 backing store for evicted pages. 124 125if DEMAND_PAGING 126config DEMAND_MAPPING 127 bool "Allow on-demand memory mappings" 128 depends on ARCH_HAS_DEMAND_MAPPING 129 default y 130 help 131 When this is enabled, RAM-based memory mappings don't actually 132 allocate memory at mem_map time. They are made to be populated 133 at access time using the demand paging mechanism instead. 134 135config DEMAND_PAGING_ALLOW_IRQ 136 bool "Allow interrupts during page-ins/outs" 137 help 138 Allow interrupts to be serviced while pages are being evicted or 139 retrieved from the backing store. This is much better for system 140 latency, but any code running in interrupt context that page faults 141 will cause a kernel panic. Such code must work with exclusively pinned 142 code and data pages. 143 144 The scheduler is still disabled during this operation. 145 146 If this option is disabled, the page fault servicing logic 147 runs with interrupts disabled for the entire operation. However, 148 ISRs may also page fault. 149 150config DEMAND_PAGING_PAGE_FRAMES_RESERVE 151 int "Number of page frames reserved for paging" 152 default 32 if !LINKER_GENERIC_SECTIONS_PRESENT_AT_BOOT 153 default 0 154 help 155 This sets the number of page frames that will be reserved for 156 paging that do not count towards free memory. This is to 157 ensure that there are some page frames available for paging 158 code and data. Otherwise, it would be possible to exhaust 159 all page frames via anonymous memory mappings. 160 161config DEMAND_PAGING_STATS 162 bool "Gather Demand Paging Statistics" 163 help 164 This enables gathering various statistics related to demand paging, 165 e.g. number of pagefaults. This is useful for tuning eviction 166 algorithms and optimizing backing store. 167 168 Should say N in production system as this is not without cost. 169 170config DEMAND_PAGING_STATS_USING_TIMING_FUNCTIONS 171 bool "Use Timing Functions to Gather Demand Paging Statistics" 172 select TIMING_FUNCTIONS_NEED_AT_BOOT 173 help 174 Use timing functions to gather various demand paging statistics. 175 176config DEMAND_PAGING_THREAD_STATS 177 bool "Gather per Thread Demand Paging Statistics" 178 depends on DEMAND_PAGING_STATS 179 help 180 This enables gathering per thread statistics related to demand 181 paging. 182 183 Should say N in production system as this is not without cost. 184 185config DEMAND_PAGING_TIMING_HISTOGRAM 186 bool "Gather Demand Paging Execution Timing Histogram" 187 depends on DEMAND_PAGING_STATS 188 help 189 This gathers the histogram of execution time on page eviction 190 selection, and backing store page in and page out. 191 192 Should say N in production system as this is not without cost. 193 194config DEMAND_PAGING_TIMING_HISTOGRAM_NUM_BINS 195 int "Number of bins (buckets) in Demand Paging Timing Histogram" 196 depends on DEMAND_PAGING_TIMING_HISTOGRAM 197 default 10 198 help 199 Defines the number of bins (buckets) in the histogram used for 200 gathering execution timing information for demand paging. 201 202 This requires k_mem_paging_eviction_histogram_bounds[] and 203 k_mem_paging_backing_store_histogram_bounds[] to define 204 the upper bounds for each bin. See kernel/statistics.c for 205 information. 206 207endif # DEMAND_PAGING 208endif # MMU 209 210config KERNEL_VM_USE_CUSTOM_MEM_RANGE_CHECK 211 bool 212 help 213 Use custom memory range check functions instead of the generic 214 checks in k_mem_phys_addr() and k_mem_virt_addr(). 215 216 sys_mm_is_phys_addr_in_range() and 217 sys_mm_is_virt_addr_in_range() must be implemented. 218 219endmenu # Virtual Memory Support 220