xref: /linux/arch/riscv/Kconfig (revision daa121128a2d2ac6006159e2c47676e4fcd21eab)
1# SPDX-License-Identifier: GPL-2.0-only
2#
3# For a description of the syntax of this configuration file,
4# see Documentation/kbuild/kconfig-language.rst.
5#
6
7config 64BIT
8	bool
9
10config 32BIT
11	bool
12
13config RISCV
14	def_bool y
15	select ACPI_GENERIC_GSI if ACPI
16	select ACPI_REDUCED_HARDWARE_ONLY if ACPI
17	select ARCH_DMA_DEFAULT_COHERENT
18	select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION
19	select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
20	select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
21	select ARCH_HAS_BINFMT_FLAT
22	select ARCH_HAS_CURRENT_STACK_POINTER
23	select ARCH_HAS_DEBUG_VIRTUAL if MMU
24	select ARCH_HAS_DEBUG_VM_PGTABLE
25	select ARCH_HAS_DEBUG_WX
26	select ARCH_HAS_FORTIFY_SOURCE
27	select ARCH_HAS_GCOV_PROFILE_ALL
28	select ARCH_HAS_GIGANTIC_PAGE
29	select ARCH_HAS_KCOV
30	select ARCH_HAS_MEMBARRIER_CALLBACKS
31	select ARCH_HAS_MEMBARRIER_SYNC_CORE
32	select ARCH_HAS_MMIOWB
33	select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
34	select ARCH_HAS_PMEM_API
35	select ARCH_HAS_PREPARE_SYNC_CORE_CMD
36	select ARCH_HAS_PTE_SPECIAL
37	select ARCH_HAS_SET_DIRECT_MAP if MMU
38	select ARCH_HAS_SET_MEMORY if MMU
39	select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
40	select ARCH_HAS_STRICT_MODULE_RWX if MMU && !XIP_KERNEL
41	select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
42	select ARCH_HAS_SYSCALL_WRAPPER
43	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
44	select ARCH_HAS_UBSAN
45	select ARCH_HAS_VDSO_DATA
46	select ARCH_KEEP_MEMBLOCK if ACPI
47	select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
48	select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
49	select ARCH_STACKWALK
50	select ARCH_SUPPORTS_ATOMIC_RMW
51	select ARCH_SUPPORTS_CFI_CLANG
52	select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
53	select ARCH_SUPPORTS_HUGETLBFS if MMU
54	# LLD >= 14: https://github.com/llvm/llvm-project/issues/50505
55	select ARCH_SUPPORTS_LTO_CLANG if LLD_VERSION >= 140000
56	select ARCH_SUPPORTS_LTO_CLANG_THIN if LLD_VERSION >= 140000
57	select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
58	select ARCH_SUPPORTS_PER_VMA_LOCK if MMU
59	select ARCH_SUPPORTS_SHADOW_CALL_STACK if HAVE_SHADOW_CALL_STACK
60	select ARCH_USE_MEMTEST
61	select ARCH_USE_QUEUED_RWLOCKS
62	select ARCH_USES_CFI_TRAPS if CFI_CLANG
63	select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH if SMP && MMU
64	select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
65	select ARCH_WANT_FRAME_POINTERS
66	select ARCH_WANT_GENERAL_HUGETLB if !RISCV_ISA_SVNAPOT
67	select ARCH_WANT_HUGE_PMD_SHARE if 64BIT
68	select ARCH_WANT_LD_ORPHAN_WARN if !XIP_KERNEL
69	select ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP
70	select ARCH_WANTS_NO_INSTR
71	select ARCH_WANTS_THP_SWAP if HAVE_ARCH_TRANSPARENT_HUGEPAGE
72	select BINFMT_FLAT_NO_DATA_START_OFFSET if !MMU
73	select BUILDTIME_TABLE_SORT if MMU
74	select CLINT_TIMER if !MMU
75	select CLONE_BACKWARDS
76	select COMMON_CLK
77	select CPU_PM if CPU_IDLE || HIBERNATION || SUSPEND
78	select EDAC_SUPPORT
79	select FRAME_POINTER if PERF_EVENTS || (FUNCTION_TRACER && !DYNAMIC_FTRACE)
80	select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY if DYNAMIC_FTRACE
81	select GENERIC_ARCH_TOPOLOGY
82	select GENERIC_ATOMIC64 if !64BIT
83	select GENERIC_CLOCKEVENTS_BROADCAST if SMP
84	select GENERIC_CPU_DEVICES
85	select GENERIC_EARLY_IOREMAP
86	select GENERIC_ENTRY
87	select GENERIC_GETTIMEOFDAY if HAVE_GENERIC_VDSO
88	select GENERIC_IDLE_POLL_SETUP
89	select GENERIC_IOREMAP if MMU
90	select GENERIC_IRQ_IPI if SMP
91	select GENERIC_IRQ_IPI_MUX if SMP
92	select GENERIC_IRQ_MULTI_HANDLER
93	select GENERIC_IRQ_SHOW
94	select GENERIC_IRQ_SHOW_LEVEL
95	select GENERIC_LIB_DEVMEM_IS_ALLOWED
96	select GENERIC_PCI_IOMAP
97	select GENERIC_PTDUMP if MMU
98	select GENERIC_SCHED_CLOCK
99	select GENERIC_SMP_IDLE_THREAD
100	select GENERIC_TIME_VSYSCALL if MMU && 64BIT
101	select GENERIC_VDSO_TIME_NS if HAVE_GENERIC_VDSO
102	select HARDIRQS_SW_RESEND
103	select HAS_IOPORT if MMU
104	select HAVE_ARCH_AUDITSYSCALL
105	select HAVE_ARCH_HUGE_VMALLOC if HAVE_ARCH_HUGE_VMAP
106	select HAVE_ARCH_HUGE_VMAP if MMU && 64BIT && !XIP_KERNEL
107	select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL
108	select HAVE_ARCH_JUMP_LABEL_RELATIVE if !XIP_KERNEL
109	select HAVE_ARCH_KASAN if MMU && 64BIT
110	select HAVE_ARCH_KASAN_VMALLOC if MMU && 64BIT
111	select HAVE_ARCH_KFENCE if MMU && 64BIT
112	select HAVE_ARCH_KGDB if !XIP_KERNEL
113	select HAVE_ARCH_KGDB_QXFER_PKT
114	select HAVE_ARCH_MMAP_RND_BITS if MMU
115	select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT
116	select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
117	select HAVE_ARCH_SECCOMP_FILTER
118	select HAVE_ARCH_THREAD_STRUCT_WHITELIST
119	select HAVE_ARCH_TRACEHOOK
120	select HAVE_ARCH_TRANSPARENT_HUGEPAGE if 64BIT && MMU
121	select HAVE_ARCH_USERFAULTFD_MINOR if 64BIT && USERFAULTFD
122	select HAVE_ARCH_VMAP_STACK if MMU && 64BIT
123	select HAVE_ASM_MODVERSIONS
124	select HAVE_CONTEXT_TRACKING_USER
125	select HAVE_DEBUG_KMEMLEAK
126	select HAVE_DMA_CONTIGUOUS if MMU
127	select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)
128	select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
129	select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
130	select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
131	select HAVE_FUNCTION_GRAPH_TRACER
132	select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER
133	select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION
134	select HAVE_EBPF_JIT if MMU
135	select HAVE_GUP_FAST if MMU
136	select HAVE_FUNCTION_ARG_ACCESS_API
137	select HAVE_FUNCTION_ERROR_INJECTION
138	select HAVE_GCC_PLUGINS
139	select HAVE_GENERIC_VDSO if MMU && 64BIT
140	select HAVE_IRQ_TIME_ACCOUNTING
141	select HAVE_KPROBES if !XIP_KERNEL
142	select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
143	select HAVE_KRETPROBES if !XIP_KERNEL
144	# https://github.com/ClangBuiltLinux/linux/issues/1881
145	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION if !LD_IS_LLD
146	select HAVE_MOVE_PMD
147	select HAVE_MOVE_PUD
148	select HAVE_PAGE_SIZE_4KB
149	select HAVE_PCI
150	select HAVE_PERF_EVENTS
151	select HAVE_PERF_REGS
152	select HAVE_PERF_USER_STACK_DUMP
153	select HAVE_POSIX_CPU_TIMERS_TASK_WORK
154	select HAVE_PREEMPT_DYNAMIC_KEY if !XIP_KERNEL
155	select HAVE_REGS_AND_STACK_ACCESS_API
156	select HAVE_RETHOOK if !XIP_KERNEL
157	select HAVE_RSEQ
158	select HAVE_SAMPLE_FTRACE_DIRECT
159	select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
160	select HAVE_STACKPROTECTOR
161	select HAVE_SYSCALL_TRACEPOINTS
162	select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU
163	select IRQ_DOMAIN
164	select IRQ_FORCED_THREADING
165	select KASAN_VMALLOC if KASAN
166	select LOCK_MM_AND_FIND_VMA
167	select MMU_GATHER_RCU_TABLE_FREE if SMP && MMU
168	select MODULES_USE_ELF_RELA if MODULES
169	select MODULE_SECTIONS if MODULES
170	select OF
171	select OF_EARLY_FLATTREE
172	select OF_IRQ
173	select PCI_DOMAINS_GENERIC if PCI
174	select PCI_MSI if PCI
175	select RISCV_ALTERNATIVE if !XIP_KERNEL
176	select RISCV_APLIC
177	select RISCV_IMSIC
178	select RISCV_INTC
179	select RISCV_TIMER if RISCV_SBI
180	select SIFIVE_PLIC
181	select SPARSE_IRQ
182	select SYSCTL_EXCEPTION_TRACE
183	select THREAD_INFO_IN_TASK
184	select TRACE_IRQFLAGS_SUPPORT
185	select UACCESS_MEMCPY if !MMU
186	select ZONE_DMA32 if 64BIT
187
188config CLANG_SUPPORTS_DYNAMIC_FTRACE
189	def_bool CC_IS_CLANG
190	# https://github.com/ClangBuiltLinux/linux/issues/1817
191	depends on AS_IS_GNU || (AS_IS_LLVM && (LD_IS_LLD || LD_VERSION >= 23600))
192
193config GCC_SUPPORTS_DYNAMIC_FTRACE
194	def_bool CC_IS_GCC
195	depends on $(cc-option,-fpatchable-function-entry=8)
196
197config HAVE_SHADOW_CALL_STACK
198	def_bool $(cc-option,-fsanitize=shadow-call-stack)
199	# https://github.com/riscv-non-isa/riscv-elf-psabi-doc/commit/a484e843e6eeb51f0cb7b8819e50da6d2444d769
200	depends on $(ld-option,--no-relax-gp)
201
202config RISCV_USE_LINKER_RELAXATION
203	def_bool y
204	# https://github.com/llvm/llvm-project/commit/6611d58f5bbcbec77262d392e2923e1d680f6985
205	depends on !LD_IS_LLD || LLD_VERSION >= 150000
206
207# https://github.com/llvm/llvm-project/commit/bbc0f99f3bc96f1db16f649fc21dd18e5b0918f6
208config ARCH_HAS_BROKEN_DWARF5
209	def_bool y
210	depends on RISCV_USE_LINKER_RELAXATION
211	# https://github.com/llvm/llvm-project/commit/1df5ea29b43690b6622db2cad7b745607ca4de6a
212	depends on AS_IS_LLVM && AS_VERSION < 180000
213	# https://github.com/llvm/llvm-project/commit/7ffabb61a5569444b5ac9322e22e5471cc5e4a77
214	depends on LD_IS_LLD && LLD_VERSION < 180000
215
216config ARCH_MMAP_RND_BITS_MIN
217	default 18 if 64BIT
218	default 8
219
220config ARCH_MMAP_RND_COMPAT_BITS_MIN
221	default 8
222
223# max bits determined by the following formula:
224#  VA_BITS - PAGE_SHIFT - 3
225config ARCH_MMAP_RND_BITS_MAX
226	default 24 if 64BIT # SV39 based
227	default 17
228
229config ARCH_MMAP_RND_COMPAT_BITS_MAX
230	default 17
231
232# set if we run in machine mode, cleared if we run in supervisor mode
233config RISCV_M_MODE
234	bool
235	default !MMU
236
237# set if we are running in S-mode and can use SBI calls
238config RISCV_SBI
239	bool
240	depends on !RISCV_M_MODE
241	default y
242
243config MMU
244	bool "MMU-based Paged Memory Management Support"
245	default y
246	help
247	  Select if you want MMU-based virtualised addressing space
248	  support by paged memory management. If unsure, say 'Y'.
249
250config PAGE_OFFSET
251	hex
252	default 0xC0000000 if 32BIT && MMU
253	default 0x80000000 if !MMU
254	default 0xff60000000000000 if 64BIT
255
256config KASAN_SHADOW_OFFSET
257	hex
258	depends on KASAN_GENERIC
259	default 0xdfffffff00000000 if 64BIT
260	default 0xffffffff if 32BIT
261
262config ARCH_FLATMEM_ENABLE
263	def_bool !NUMA
264
265config ARCH_SPARSEMEM_ENABLE
266	def_bool y
267	depends on MMU
268	select SPARSEMEM_STATIC if 32BIT && SPARSEMEM
269	select SPARSEMEM_VMEMMAP_ENABLE if 64BIT
270
271config ARCH_SELECT_MEMORY_MODEL
272	def_bool ARCH_SPARSEMEM_ENABLE
273
274config ARCH_SUPPORTS_UPROBES
275	def_bool y
276
277config STACKTRACE_SUPPORT
278	def_bool y
279
280config GENERIC_BUG
281	def_bool y
282	depends on BUG
283	select GENERIC_BUG_RELATIVE_POINTERS if 64BIT
284
285config GENERIC_BUG_RELATIVE_POINTERS
286	bool
287
288config GENERIC_CALIBRATE_DELAY
289	def_bool y
290
291config GENERIC_CSUM
292	def_bool y
293
294config GENERIC_HWEIGHT
295	def_bool y
296
297config FIX_EARLYCON_MEM
298	def_bool MMU
299
300config PGTABLE_LEVELS
301	int
302	default 5 if 64BIT
303	default 2
304
305config LOCKDEP_SUPPORT
306	def_bool y
307
308config RISCV_DMA_NONCOHERENT
309	bool
310	select ARCH_HAS_DMA_PREP_COHERENT
311	select ARCH_HAS_SETUP_DMA_OPS
312	select ARCH_HAS_SYNC_DMA_FOR_CPU
313	select ARCH_HAS_SYNC_DMA_FOR_DEVICE
314	select DMA_BOUNCE_UNALIGNED_KMALLOC if SWIOTLB
315
316config RISCV_NONSTANDARD_CACHE_OPS
317	bool
318	help
319	  This enables function pointer support for non-standard noncoherent
320	  systems to handle cache management.
321
322config AS_HAS_INSN
323	def_bool $(as-instr,.insn r 51$(comma) 0$(comma) 0$(comma) t0$(comma) t0$(comma) zero)
324
325config AS_HAS_OPTION_ARCH
326	# https://github.com/llvm/llvm-project/commit/9e8ed3403c191ab9c4903e8eeb8f732ff8a43cb4
327	def_bool y
328	depends on $(as-instr, .option arch$(comma) +m)
329
330source "arch/riscv/Kconfig.socs"
331source "arch/riscv/Kconfig.errata"
332
333menu "Platform type"
334
335config NONPORTABLE
336	bool "Allow configurations that result in non-portable kernels"
337	help
338	  RISC-V kernel binaries are compatible between all known systems
339	  whenever possible, but there are some use cases that can only be
340	  satisfied by configurations that result in kernel binaries that are
341	  not portable between systems.
342
343	  Selecting N does not guarantee kernels will be portable to all known
344	  systems.  Selecting any of the options guarded by NONPORTABLE will
345	  result in kernel binaries that are unlikely to be portable between
346	  systems.
347
348	  If unsure, say N.
349
350choice
351	prompt "Base ISA"
352	default ARCH_RV64I
353	help
354	  This selects the base ISA that this kernel will target and must match
355	  the target platform.
356
357config ARCH_RV32I
358	bool "RV32I"
359	depends on NONPORTABLE
360	select 32BIT
361	select GENERIC_LIB_ASHLDI3
362	select GENERIC_LIB_ASHRDI3
363	select GENERIC_LIB_LSHRDI3
364	select GENERIC_LIB_UCMPDI2
365
366config ARCH_RV64I
367	bool "RV64I"
368	select 64BIT
369	select ARCH_SUPPORTS_INT128 if CC_HAS_INT128
370	select SWIOTLB if MMU
371
372endchoice
373
374# We must be able to map all physical memory into the kernel, but the compiler
375# is still a bit more efficient when generating code if it's setup in a manner
376# such that it can only map 2GiB of memory.
377choice
378	prompt "Kernel Code Model"
379	default CMODEL_MEDLOW if 32BIT
380	default CMODEL_MEDANY if 64BIT
381
382	config CMODEL_MEDLOW
383		bool "medium low code model"
384	config CMODEL_MEDANY
385		bool "medium any code model"
386endchoice
387
388config MODULE_SECTIONS
389	bool
390	select HAVE_MOD_ARCH_SPECIFIC
391
392config SMP
393	bool "Symmetric Multi-Processing"
394	help
395	  This enables support for systems with more than one CPU.  If
396	  you say N here, the kernel will run on single and
397	  multiprocessor machines, but will use only one CPU of a
398	  multiprocessor machine. If you say Y here, the kernel will run
399	  on many, but not all, single processor machines. On a single
400	  processor machine, the kernel will run faster if you say N
401	  here.
402
403	  If you don't know what to do here, say N.
404
405config SCHED_MC
406	bool "Multi-core scheduler support"
407	depends on SMP
408	help
409	  Multi-core scheduler support improves the CPU scheduler's decision
410	  making when dealing with multi-core CPU chips at a cost of slightly
411	  increased overhead in some places. If unsure say N here.
412
413config NR_CPUS
414	int "Maximum number of CPUs (2-512)"
415	depends on SMP
416	range 2 512 if !RISCV_SBI_V01
417	range 2 32 if RISCV_SBI_V01 && 32BIT
418	range 2 64 if RISCV_SBI_V01 && 64BIT
419	default "32" if 32BIT
420	default "64" if 64BIT
421
422config HOTPLUG_CPU
423	bool "Support for hot-pluggable CPUs"
424	depends on SMP
425	select GENERIC_IRQ_MIGRATION
426	help
427
428	  Say Y here to experiment with turning CPUs off and on.  CPUs
429	  can be controlled through /sys/devices/system/cpu.
430
431	  Say N if you want to disable CPU hotplug.
432
433choice
434	prompt "CPU Tuning"
435	default TUNE_GENERIC
436
437config TUNE_GENERIC
438	bool "generic"
439
440endchoice
441
442# Common NUMA Features
443config NUMA
444	bool "NUMA Memory Allocation and Scheduler Support"
445	depends on SMP && MMU
446	select ARCH_SUPPORTS_NUMA_BALANCING
447	select GENERIC_ARCH_NUMA
448	select HAVE_SETUP_PER_CPU_AREA
449	select NEED_PER_CPU_EMBED_FIRST_CHUNK
450	select NEED_PER_CPU_PAGE_FIRST_CHUNK
451	select OF_NUMA
452	select USE_PERCPU_NUMA_NODE_ID
453	help
454	  Enable NUMA (Non-Uniform Memory Access) support.
455
456	  The kernel will try to allocate memory used by a CPU on the
457	  local memory of the CPU and add some more NUMA awareness to the kernel.
458
459config NODES_SHIFT
460	int "Maximum NUMA Nodes (as a power of 2)"
461	range 1 10
462	default "2"
463	depends on NUMA
464	help
465	  Specify the maximum number of NUMA Nodes available on the target
466	  system.  Increases memory reserved to accommodate various tables.
467
468config RISCV_ALTERNATIVE
469	bool
470	depends on !XIP_KERNEL
471	help
472	  This Kconfig allows the kernel to automatically patch the
473	  erratum or cpufeature required by the execution platform at run
474	  time. The code patching overhead is minimal, as it's only done
475	  once at boot and once on each module load.
476
477config RISCV_ALTERNATIVE_EARLY
478	bool
479	depends on RISCV_ALTERNATIVE
480	help
481	  Allows early patching of the kernel for special errata
482
483config RISCV_ISA_C
484	bool "Emit compressed instructions when building Linux"
485	default y
486	help
487	  Adds "C" to the ISA subsets that the toolchain is allowed to emit
488	  when building Linux, which results in compressed instructions in the
489	  Linux binary.
490
491	  If you don't know what to do here, say Y.
492
493config RISCV_ISA_SVNAPOT
494	bool "Svnapot extension support for supervisor mode NAPOT pages"
495	depends on 64BIT && MMU
496	depends on RISCV_ALTERNATIVE
497	default y
498	help
499	  Allow kernel to detect the Svnapot ISA-extension dynamically at boot
500	  time and enable its usage.
501
502	  The Svnapot extension is used to mark contiguous PTEs as a range
503	  of contiguous virtual-to-physical translations for a naturally
504	  aligned power-of-2 (NAPOT) granularity larger than the base 4KB page
505	  size. When HUGETLBFS is also selected this option unconditionally
506	  allocates some memory for each NAPOT page size supported by the kernel.
507	  When optimizing for low memory consumption and for platforms without
508	  the Svnapot extension, it may be better to say N here.
509
510	  If you don't know what to do here, say Y.
511
512config RISCV_ISA_SVPBMT
513	bool "Svpbmt extension support for supervisor mode page-based memory types"
514	depends on 64BIT && MMU
515	depends on RISCV_ALTERNATIVE
516	default y
517	help
518	   Adds support to dynamically detect the presence of the Svpbmt
519	   ISA-extension (Supervisor-mode: page-based memory types) and
520	   enable its usage.
521
522	   The memory type for a page contains a combination of attributes
523	   that indicate the cacheability, idempotency, and ordering
524	   properties for access to that page.
525
526	   The Svpbmt extension is only available on 64-bit cpus.
527
528	   If you don't know what to do here, say Y.
529
530config TOOLCHAIN_HAS_V
531	bool
532	default y
533	depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64iv)
534	depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32iv)
535	depends on LLD_VERSION >= 140000 || LD_VERSION >= 23800
536	depends on AS_HAS_OPTION_ARCH
537
538config RISCV_ISA_V
539	bool "VECTOR extension support"
540	depends on TOOLCHAIN_HAS_V
541	depends on FPU
542	select DYNAMIC_SIGFRAME
543	default y
544	help
545	  Say N here if you want to disable all vector related procedure
546	  in the kernel.
547
548	  If you don't know what to do here, say Y.
549
550config RISCV_ISA_V_DEFAULT_ENABLE
551	bool "Enable userspace Vector by default"
552	depends on RISCV_ISA_V
553	default y
554	help
555	  Say Y here if you want to enable Vector in userspace by default.
556	  Otherwise, userspace has to make explicit prctl() call to enable
557	  Vector, or enable it via the sysctl interface.
558
559	  If you don't know what to do here, say Y.
560
561config RISCV_ISA_V_UCOPY_THRESHOLD
562	int "Threshold size for vectorized user copies"
563	depends on RISCV_ISA_V
564	default 768
565	help
566	  Prefer using vectorized copy_to_user()/copy_from_user() when the
567	  workload size exceeds this value.
568
569config RISCV_ISA_V_PREEMPTIVE
570	bool "Run kernel-mode Vector with kernel preemption"
571	depends on PREEMPTION
572	depends on RISCV_ISA_V
573	default y
574	help
575	  Usually, in-kernel SIMD routines are run with preemption disabled.
576	  Functions which envoke long running SIMD thus must yield core's
577	  vector unit to prevent blocking other tasks for too long.
578
579	  This config allows kernel to run SIMD without explicitly disable
580	  preemption. Enabling this config will result in higher memory
581	  consumption due to the allocation of per-task's kernel Vector context.
582
583config TOOLCHAIN_HAS_ZBB
584	bool
585	default y
586	depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbb)
587	depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbb)
588	depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900
589	depends on AS_HAS_OPTION_ARCH
590
591# This symbol indicates that the toolchain supports all v1.0 vector crypto
592# extensions, including Zvk*, Zvbb, and Zvbc.  LLVM added all of these at once.
593# binutils added all except Zvkb, then added Zvkb.  So we just check for Zvkb.
594config TOOLCHAIN_HAS_VECTOR_CRYPTO
595	def_bool $(as-instr, .option arch$(comma) +v$(comma) +zvkb)
596	depends on AS_HAS_OPTION_ARCH
597
598config RISCV_ISA_ZBB
599	bool "Zbb extension support for bit manipulation instructions"
600	depends on TOOLCHAIN_HAS_ZBB
601	depends on MMU
602	depends on RISCV_ALTERNATIVE
603	default y
604	help
605	   Adds support to dynamically detect the presence of the ZBB
606	   extension (basic bit manipulation) and enable its usage.
607
608	   The Zbb extension provides instructions to accelerate a number
609	   of bit-specific operations (count bit population, sign extending,
610	   bitrotation, etc).
611
612	   If you don't know what to do here, say Y.
613
614config RISCV_ISA_ZICBOM
615	bool "Zicbom extension support for non-coherent DMA operation"
616	depends on MMU
617	depends on RISCV_ALTERNATIVE
618	default y
619	select RISCV_DMA_NONCOHERENT
620	select DMA_DIRECT_REMAP
621	help
622	   Adds support to dynamically detect the presence of the ZICBOM
623	   extension (Cache Block Management Operations) and enable its
624	   usage.
625
626	   The Zicbom extension can be used to handle for example
627	   non-coherent DMA support on devices that need it.
628
629	   If you don't know what to do here, say Y.
630
631config RISCV_ISA_ZICBOZ
632	bool "Zicboz extension support for faster zeroing of memory"
633	depends on MMU
634	depends on RISCV_ALTERNATIVE
635	default y
636	help
637	   Enable the use of the Zicboz extension (cbo.zero instruction)
638	   when available.
639
640	   The Zicboz extension is used for faster zeroing of memory.
641
642	   If you don't know what to do here, say Y.
643
644config TOOLCHAIN_HAS_ZIHINTPAUSE
645	bool
646	default y
647	depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zihintpause)
648	depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zihintpause)
649	depends on LLD_VERSION >= 150000 || LD_VERSION >= 23600
650
651config TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI
652	def_bool y
653	# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=aed44286efa8ae8717a77d94b51ac3614e2ca6dc
654	# https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=98416dbb0a62579d4a7a4a76bab51b5b52fec2cd
655	depends on AS_IS_GNU && AS_VERSION >= 23600
656	help
657	  Binutils-2.38 and GCC-12.1.0 bumped the default ISA spec to the newer
658	  20191213 version, which moves some instructions from the I extension to
659	  the Zicsr and Zifencei extensions. This requires explicitly specifying
660	  Zicsr and Zifencei when binutils >= 2.38 or GCC >= 12.1.0. Zicsr
661	  and Zifencei are supported in binutils from version 2.36 onwards.
662	  To make life easier, and avoid forcing toolchains that default to a
663	  newer ISA spec to version 2.2, relax the check to binutils >= 2.36.
664	  For clang < 17 or GCC < 11.3.0, for which this is not possible or need
665	  special treatment, this is dealt with in TOOLCHAIN_NEEDS_OLD_ISA_SPEC.
666
667config TOOLCHAIN_NEEDS_OLD_ISA_SPEC
668	def_bool y
669	depends on TOOLCHAIN_NEEDS_EXPLICIT_ZICSR_ZIFENCEI
670	# https://github.com/llvm/llvm-project/commit/22e199e6afb1263c943c0c0d4498694e15bf8a16
671	# https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=d29f5d6ab513c52fd872f532c492e35ae9fd6671
672	depends on (CC_IS_CLANG && CLANG_VERSION < 170000) || (CC_IS_GCC && GCC_VERSION < 110300)
673	help
674	  Certain versions of clang and GCC do not support zicsr and zifencei via
675	  -march. This option causes an older ISA spec compatible with these older
676	  versions of clang and GCC to be passed to GAS, which has the same result
677	  as passing zicsr and zifencei to -march.
678
679config FPU
680	bool "FPU support"
681	default y
682	help
683	  Say N here if you want to disable all floating-point related procedure
684	  in the kernel.
685
686	  If you don't know what to do here, say Y.
687
688config IRQ_STACKS
689	bool "Independent irq & softirq stacks" if EXPERT
690	default y
691	select HAVE_IRQ_EXIT_ON_IRQ_STACK
692	select HAVE_SOFTIRQ_ON_OWN_STACK
693	help
694	  Add independent irq & softirq stacks for percpu to prevent kernel stack
695	  overflows. We may save some memory footprint by disabling IRQ_STACKS.
696
697config THREAD_SIZE_ORDER
698	int "Kernel stack size (in power-of-two numbers of page size)" if VMAP_STACK && EXPERT
699	range 0 4
700	default 1 if 32BIT && !KASAN
701	default 3 if 64BIT && KASAN
702	default 2
703	help
704	  Specify the Pages of thread stack size (from 4KB to 64KB), which also
705	  affects irq stack size, which is equal to thread stack size.
706
707config RISCV_MISALIGNED
708	bool
709	select SYSCTL_ARCH_UNALIGN_ALLOW
710	help
711	  Embed support for emulating misaligned loads and stores.
712
713choice
714	prompt "Unaligned Accesses Support"
715	default RISCV_PROBE_UNALIGNED_ACCESS
716	help
717	  This determines the level of support for unaligned accesses. This
718	  information is used by the kernel to perform optimizations. It is also
719	  exposed to user space via the hwprobe syscall. The hardware will be
720	  probed at boot by default.
721
722config RISCV_PROBE_UNALIGNED_ACCESS
723	bool "Probe for hardware unaligned access support"
724	select RISCV_MISALIGNED
725	help
726	  During boot, the kernel will run a series of tests to determine the
727	  speed of unaligned accesses. This probing will dynamically determine
728	  the speed of unaligned accesses on the underlying system. If unaligned
729	  memory accesses trap into the kernel as they are not supported by the
730	  system, the kernel will emulate the unaligned accesses to preserve the
731	  UABI.
732
733config RISCV_EMULATED_UNALIGNED_ACCESS
734	bool "Emulate unaligned access where system support is missing"
735	select RISCV_MISALIGNED
736	help
737	  If unaligned memory accesses trap into the kernel as they are not
738	  supported by the system, the kernel will emulate the unaligned
739	  accesses to preserve the UABI. When the underlying system does support
740	  unaligned accesses, the unaligned accesses are assumed to be slow.
741
742config RISCV_SLOW_UNALIGNED_ACCESS
743	bool "Assume the system supports slow unaligned memory accesses"
744	depends on NONPORTABLE
745	help
746	  Assume that the system supports slow unaligned memory accesses. The
747	  kernel and userspace programs may not be able to run at all on systems
748	  that do not support unaligned memory accesses.
749
750config RISCV_EFFICIENT_UNALIGNED_ACCESS
751	bool "Assume the system supports fast unaligned memory accesses"
752	depends on NONPORTABLE
753	select DCACHE_WORD_ACCESS if MMU
754	select HAVE_EFFICIENT_UNALIGNED_ACCESS
755	help
756	  Assume that the system supports fast unaligned memory accesses. When
757	  enabled, this option improves the performance of the kernel on such
758	  systems. However, the kernel and userspace programs will run much more
759	  slowly, or will not be able to run at all, on systems that do not
760	  support efficient unaligned memory accesses.
761
762endchoice
763
764endmenu # "Platform type"
765
766menu "Kernel features"
767
768source "kernel/Kconfig.hz"
769
770config RISCV_SBI_V01
771	bool "SBI v0.1 support"
772	depends on RISCV_SBI
773	help
774	  This config allows kernel to use SBI v0.1 APIs. This will be
775	  deprecated in future once legacy M-mode software are no longer in use.
776
777config RISCV_BOOT_SPINWAIT
778	bool "Spinwait booting method"
779	depends on SMP
780	default y if RISCV_SBI_V01 || RISCV_M_MODE
781	help
782	  This enables support for booting Linux via spinwait method. In the
783	  spinwait method, all cores randomly jump to Linux. One of the cores
784	  gets chosen via lottery and all other keep spinning on a percpu
785	  variable. This method cannot support CPU hotplug and sparse hartid
786	  scheme. It should be only enabled for M-mode Linux or platforms relying
787	  on older firmware without SBI HSM extension. All other platforms should
788	  rely on ordered booting via SBI HSM extension which gets chosen
789	  dynamically at runtime if the firmware supports it.
790
791	  Since spinwait is incompatible with sparse hart IDs, it requires
792	  NR_CPUS be large enough to contain the physical hart ID of the first
793	  hart to enter Linux.
794
795	  If unsure what to do here, say N.
796
797config ARCH_SUPPORTS_KEXEC
798	def_bool y
799
800config ARCH_SELECTS_KEXEC
801	def_bool y
802	depends on KEXEC
803	select HOTPLUG_CPU if SMP
804
805config ARCH_SUPPORTS_KEXEC_FILE
806	def_bool 64BIT
807
808config ARCH_SELECTS_KEXEC_FILE
809	def_bool y
810	depends on KEXEC_FILE
811	select HAVE_IMA_KEXEC if IMA
812	select KEXEC_ELF
813
814config ARCH_SUPPORTS_KEXEC_PURGATORY
815	def_bool ARCH_SUPPORTS_KEXEC_FILE
816
817config ARCH_SUPPORTS_CRASH_DUMP
818	def_bool y
819
820config ARCH_HAS_GENERIC_CRASHKERNEL_RESERVATION
821	def_bool CRASH_RESERVE
822
823config COMPAT
824	bool "Kernel support for 32-bit U-mode"
825	default 64BIT
826	depends on 64BIT && MMU
827	help
828	  This option enables support for a 32-bit U-mode running under a 64-bit
829	  kernel at S-mode. riscv32-specific components such as system calls,
830	  the user helper functions (vdso), signal rt_frame functions and the
831	  ptrace interface are handled appropriately by the kernel.
832
833	  If you want to execute 32-bit userspace applications, say Y.
834
835config PARAVIRT
836	bool "Enable paravirtualization code"
837	depends on RISCV_SBI
838	help
839	  This changes the kernel so it can modify itself when it is run
840	  under a hypervisor, potentially improving performance significantly
841	  over full virtualization.
842
843config PARAVIRT_TIME_ACCOUNTING
844	bool "Paravirtual steal time accounting"
845	depends on PARAVIRT
846	help
847	  Select this option to enable fine granularity task steal time
848	  accounting. Time spent executing other tasks in parallel with
849	  the current vCPU is discounted from the vCPU power. To account for
850	  that, there can be a small performance impact.
851
852	  If in doubt, say N here.
853
854config RELOCATABLE
855	bool "Build a relocatable kernel"
856	depends on MMU && 64BIT && !XIP_KERNEL
857	help
858          This builds a kernel as a Position Independent Executable (PIE),
859          which retains all relocation metadata required to relocate the
860          kernel binary at runtime to a different virtual address than the
861          address it was linked at.
862          Since RISCV uses the RELA relocation format, this requires a
863          relocation pass at runtime even if the kernel is loaded at the
864          same address it was linked at.
865
866          If unsure, say N.
867
868config RANDOMIZE_BASE
869        bool "Randomize the address of the kernel image"
870        select RELOCATABLE
871        depends on MMU && 64BIT && !XIP_KERNEL
872        help
873          Randomizes the virtual address at which the kernel image is
874          loaded, as a security feature that deters exploit attempts
875          relying on knowledge of the location of kernel internals.
876
877          It is the bootloader's job to provide entropy, by passing a
878          random u64 value in /chosen/kaslr-seed at kernel entry.
879
880          When booting via the UEFI stub, it will invoke the firmware's
881          EFI_RNG_PROTOCOL implementation (if available) to supply entropy
882          to the kernel proper. In addition, it will randomise the physical
883          location of the kernel Image as well.
884
885          If unsure, say N.
886
887endmenu # "Kernel features"
888
889menu "Boot options"
890
891config CMDLINE
892	string "Built-in kernel command line"
893	help
894	  For most platforms, the arguments for the kernel's command line
895	  are provided at run-time, during boot. However, there are cases
896	  where either no arguments are being provided or the provided
897	  arguments are insufficient or even invalid.
898
899	  When that occurs, it is possible to define a built-in command
900	  line here and choose how the kernel should use it later on.
901
902choice
903	prompt "Built-in command line usage" if CMDLINE != ""
904	default CMDLINE_FALLBACK
905	help
906	  Choose how the kernel will handle the provided built-in command
907	  line.
908
909config CMDLINE_FALLBACK
910	bool "Use bootloader kernel arguments if available"
911	help
912	  Use the built-in command line as fallback in case we get nothing
913	  during boot. This is the default behaviour.
914
915config CMDLINE_EXTEND
916	bool "Extend bootloader kernel arguments"
917	help
918	  The command-line arguments provided during boot will be
919	  appended to the built-in command line. This is useful in
920	  cases where the provided arguments are insufficient and
921	  you don't want to or cannot modify them.
922
923config CMDLINE_FORCE
924	bool "Always use the default kernel command string"
925	help
926	  Always use the built-in command line, even if we get one during
927	  boot. This is useful in case you need to override the provided
928	  command line on systems where you don't have or want control
929	  over it.
930
931endchoice
932
933config EFI_STUB
934	bool
935
936config EFI
937	bool "UEFI runtime support"
938	depends on OF && !XIP_KERNEL
939	depends on MMU
940	default y
941	select ARCH_SUPPORTS_ACPI if 64BIT
942	select EFI_GENERIC_STUB
943	select EFI_PARAMS_FROM_FDT
944	select EFI_RUNTIME_WRAPPERS
945	select EFI_STUB
946	select LIBFDT
947	select RISCV_ISA_C
948	select UCS2_STRING
949	help
950	  This option provides support for runtime services provided
951	  by UEFI firmware (such as non-volatile variables, realtime
952	  clock, and platform reset). A UEFI stub is also provided to
953	  allow the kernel to be booted as an EFI application. This
954	  is only useful on systems that have UEFI firmware.
955
956config CC_HAVE_STACKPROTECTOR_TLS
957	def_bool $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=tp -mstack-protector-guard-offset=0)
958
959config STACKPROTECTOR_PER_TASK
960	def_bool y
961	depends on !RANDSTRUCT
962	depends on STACKPROTECTOR && CC_HAVE_STACKPROTECTOR_TLS
963
964config PHYS_RAM_BASE_FIXED
965	bool "Explicitly specified physical RAM address"
966	depends on NONPORTABLE
967	default n
968
969config PHYS_RAM_BASE
970	hex "Platform Physical RAM address"
971	depends on PHYS_RAM_BASE_FIXED
972	default "0x80000000"
973	help
974	  This is the physical address of RAM in the system. It has to be
975	  explicitly specified to run early relocations of read-write data
976	  from flash to RAM.
977
978config XIP_KERNEL
979	bool "Kernel Execute-In-Place from ROM"
980	depends on MMU && SPARSEMEM && NONPORTABLE
981	# This prevents XIP from being enabled by all{yes,mod}config, which
982	# fail to build since XIP doesn't support large kernels.
983	depends on !COMPILE_TEST
984	select PHYS_RAM_BASE_FIXED
985	help
986	  Execute-In-Place allows the kernel to run from non-volatile storage
987	  directly addressable by the CPU, such as NOR flash. This saves RAM
988	  space since the text section of the kernel is not loaded from flash
989	  to RAM.  Read-write sections, such as the data section and stack,
990	  are still copied to RAM.  The XIP kernel is not compressed since
991	  it has to run directly from flash, so it will take more space to
992	  store it.  The flash address used to link the kernel object files,
993	  and for storing it, is configuration dependent. Therefore, if you
994	  say Y here, you must know the proper physical address where to
995	  store the kernel image depending on your own flash memory usage.
996
997	  Also note that the make target becomes "make xipImage" rather than
998	  "make zImage" or "make Image".  The final kernel binary to put in
999	  ROM memory will be arch/riscv/boot/xipImage.
1000
1001	  SPARSEMEM is required because the kernel text and rodata that are
1002	  flash resident are not backed by memmap, then any attempt to get
1003	  a struct page on those regions will trigger a fault.
1004
1005	  If unsure, say N.
1006
1007config XIP_PHYS_ADDR
1008	hex "XIP Kernel Physical Location"
1009	depends on XIP_KERNEL
1010	default "0x21000000"
1011	help
1012	  This is the physical address in your flash memory the kernel will
1013	  be linked for and stored to.  This address is dependent on your
1014	  own flash usage.
1015
1016config RISCV_ISA_FALLBACK
1017	bool "Permit falling back to parsing riscv,isa for extension support by default"
1018	default y
1019	help
1020	  Parsing the "riscv,isa" devicetree property has been deprecated and
1021	  replaced by a list of explicitly defined strings. For compatibility
1022	  with existing platforms, the kernel will fall back to parsing the
1023	  "riscv,isa" property if the replacements are not found.
1024
1025	  Selecting N here will result in a kernel that does not use the
1026	  fallback, unless the commandline "riscv_isa_fallback" parameter is
1027	  present.
1028
1029	  Please see the dt-binding, located at
1030	  Documentation/devicetree/bindings/riscv/extensions.yaml for details
1031	  on the replacement properties, "riscv,isa-base" and
1032	  "riscv,isa-extensions".
1033
1034config BUILTIN_DTB
1035	bool "Built-in device tree"
1036	depends on OF && NONPORTABLE
1037	help
1038	  Build a device tree into the Linux image.
1039	  This option should be selected if no bootloader is being used.
1040	  If unsure, say N.
1041
1042
1043config BUILTIN_DTB_SOURCE
1044	string "Built-in device tree source"
1045	depends on BUILTIN_DTB
1046	help
1047	  DTS file path (without suffix, relative to arch/riscv/boot/dts)
1048	  for the DTS file that will be used to produce the DTB linked into the
1049	  kernel.
1050
1051endmenu # "Boot options"
1052
1053config PORTABLE
1054	bool
1055	default !NONPORTABLE
1056	select EFI
1057	select MMU
1058	select OF
1059
1060config ARCH_PROC_KCORE_TEXT
1061	def_bool y
1062
1063menu "Power management options"
1064
1065source "kernel/power/Kconfig"
1066
1067config ARCH_HIBERNATION_POSSIBLE
1068	def_bool y
1069
1070config ARCH_HIBERNATION_HEADER
1071	def_bool HIBERNATION
1072
1073config ARCH_SUSPEND_POSSIBLE
1074	def_bool y
1075
1076endmenu # "Power management options"
1077
1078menu "CPU Power Management"
1079
1080source "drivers/cpuidle/Kconfig"
1081
1082source "drivers/cpufreq/Kconfig"
1083
1084endmenu # "CPU Power Management"
1085
1086source "arch/riscv/kvm/Kconfig"
1087
1088source "drivers/acpi/Kconfig"
1089