Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xtensa: reorganize vectors placement

Allow vectors to be either merged into the kernel .text or put at a
fixed virtual address independently of XIP option. Drop option that
puts vectors at a fixed offset from the kernel text. Add choice to
Kconfig.
Vectors at fixed virtual address may be useful for XIP-aware MTD support
and for noMMU configurations with available IRAM. Configurations without
VECBASE register must put their vectors at specific locations regardless
of the selected option. All other configurations should happily use
merged vectors.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>

+51 -20
+33 -7
arch/xtensa/Kconfig
··· 572 572 573 573 If unsure, leave the default value here. 574 574 575 - config VECTORS_OFFSET 576 - hex "Kernel vectors offset" 577 - default 0x00003000 578 - depends on !XIP_KERNEL 575 + choice 576 + prompt "Relocatable vectors location" 577 + default XTENSA_VECTORS_IN_TEXT 579 578 help 580 - This is the offset of the kernel image from the relocatable vectors 581 - base. 579 + Choose whether relocatable vectors are merged into the kernel .text 580 + or placed separately at runtime. This option does not affect 581 + configurations without VECBASE register where vectors are always 582 + placed at their hardware-defined locations. 582 583 583 - If unsure, leave the default value here. 584 + config XTENSA_VECTORS_IN_TEXT 585 + bool "Merge relocatable vectors into kernel text" 586 + depends on !MTD_XIP 587 + help 588 + This option puts relocatable vectors into the kernel .text section 589 + with proper alignment. 590 + This is a safe choice for most configurations. 591 + 592 + config XTENSA_VECTORS_SEPARATE 593 + bool "Put relocatable vectors at fixed address" 594 + help 595 + This option puts relocatable vectors at specific virtual address. 596 + Vectors are merged with the .init data in the kernel image and 597 + are copied into their designated location during kernel startup. 598 + Use it to put vectors into IRAM or out of FLASH on kernels with 599 + XIP-aware MTD support. 600 + 601 + endchoice 602 + 603 + config VECTORS_ADDR 604 + hex "Kernel vectors virtual address" 605 + default 0x00000000 606 + depends on XTENSA_VECTORS_SEPARATE 607 + help 608 + This is the virtual address of the (relocatable) vectors base. 609 + It must be within KSEG if MMU is used. 584 610 585 611 config XIP_DATA_ADDR 586 612 hex "XIP kernel data virtual address"
-1
arch/xtensa/configs/smp_lx200_defconfig
··· 30 30 CONFIG_HOTPLUG_CPU=y 31 31 # CONFIG_INITIALIZE_XTENSA_MMU_INSIDE_VMLINUX is not set 32 32 # CONFIG_PCI is not set 33 - CONFIG_VECTORS_OFFSET=0x00002000 34 33 CONFIG_XTENSA_PLATFORM_XTFPGA=y 35 34 CONFIG_CMDLINE_BOOL=y 36 35 CONFIG_CMDLINE="earlycon=uart8250,mmio32native,0xfd050020,115200n8 console=ttyS0,115200n8 ip=dhcp root=/dev/nfs rw debug memmap=96M@0"
-1
arch/xtensa/configs/virt_defconfig
··· 19 19 CONFIG_PERF_EVENTS=y 20 20 CONFIG_XTENSA_VARIANT_DC233C=y 21 21 CONFIG_XTENSA_UNALIGNED_USER=y 22 - CONFIG_VECTORS_OFFSET=0x00002000 23 22 CONFIG_XTENSA_KSEG_512M=y 24 23 CONFIG_HIGHMEM=y 25 24 CONFIG_CMDLINE_BOOL=y
+2 -2
arch/xtensa/include/asm/vectors.h
··· 34 34 #endif 35 35 36 36 #define RESET_VECTOR1_VADDR (XCHAL_RESET_VECTOR1_VADDR) 37 - #ifdef CONFIG_VECTORS_OFFSET 38 - #define VECBASE_VADDR (KERNELOFFSET - CONFIG_VECTORS_OFFSET) 37 + #ifdef CONFIG_VECTORS_ADDR 38 + #define VECBASE_VADDR (CONFIG_VECTORS_ADDR) 39 39 #else 40 40 #define VECBASE_VADDR _vecbase 41 41 #endif
+2 -2
arch/xtensa/kernel/setup.c
··· 349 349 mem_reserve(__pa(_xip_start), __pa(_xip_end)); 350 350 #endif 351 351 352 - #ifdef CONFIG_VECTORS_OFFSET 352 + #ifdef CONFIG_VECTORS_ADDR 353 353 mem_reserve(__pa(&_WindowVectors_text_start), 354 354 __pa(&_WindowVectors_text_end)); 355 355 ··· 388 388 __pa(&_Level6InterruptVector_text_end)); 389 389 #endif 390 390 391 - #endif /* CONFIG_VECTORS_OFFSET */ 391 + #endif /* CONFIG_VECTORS_ADDR */ 392 392 393 393 #ifdef CONFIG_SMP 394 394 mem_reserve(__pa(&_SecondaryResetVector_text_start),
+14 -7
arch/xtensa/kernel/vmlinux.lds.S
··· 47 47 LONG(sym ## _end); \ 48 48 LONG(LOADADDR(section)) 49 49 50 + #if !defined(CONFIG_VECTORS_ADDR) && XCHAL_HAVE_VECBASE 51 + #define MERGED_VECTORS 1 52 + #else 53 + #define MERGED_VECTORS 0 54 + #endif 55 + 50 56 /* 51 - * Macro to define a section for a vector. When CONFIG_VECTORS_OFFSET is 52 - * defined code for every vector is located with other init data. At startup 57 + * Macro to define a section for a vector. When MERGED_VECTORS is 0 58 + * code for every vector is located with other init data. At startup 53 59 * time head.S copies code for every vector to its final position according 54 60 * to description recorded in the corresponding RELOCATE_ENTRY. 55 61 */ ··· 90 84 /* The HEAD_TEXT section must be the first section! */ 91 85 HEAD_TEXT 92 86 93 - #ifndef CONFIG_VECTORS_OFFSET 87 + #if MERGED_VECTORS 94 88 . = ALIGN(PAGE_SIZE); 95 89 _vecbase = .; 96 90 ··· 165 159 . = ALIGN(16); 166 160 __boot_reloc_table_start = ABSOLUTE(.); 167 161 168 - #ifdef CONFIG_VECTORS_OFFSET 162 + #if !MERGED_VECTORS 169 163 RELOCATE_ENTRY(_WindowVectors_text, 170 164 .WindowVectors.text); 171 165 #if XCHAL_EXCM_LEVEL >= 2 ··· 226 220 #undef LAST 227 221 #define LAST .dummy 228 222 229 - #ifdef CONFIG_VECTORS_OFFSET 223 + #if !MERGED_VECTORS 230 224 /* The vectors are relocated to the real position at startup time */ 231 225 232 226 SECTION_VECTOR4 (_WindowVectors_text, ··· 305 299 #define LAST .SecondaryResetVector.text 306 300 307 301 #endif 308 - #ifdef CONFIG_VECTORS_OFFSET 302 + #if !MERGED_VECTORS 309 303 SECTION_VECTOR4 (_exception_text, 310 304 .exception.text, 311 305 , ··· 316 310 #endif 317 311 . = (LOADADDR(LAST) + SIZEOF(LAST) + 3) & ~ 3; 318 312 313 + .dummy1 : AT(ADDR(.dummy1)) { LONG(0) } 319 314 . = ALIGN(PAGE_SIZE); 320 315 321 316 #ifndef CONFIG_XIP_KERNEL ··· 334 327 335 328 #undef LOAD_OFFSET 336 329 #define LOAD_OFFSET \ 337 - (CONFIG_XIP_DATA_ADDR - (LOADADDR(.dummy) + SIZEOF(.dummy) + 3) & ~ 3) 330 + (CONFIG_XIP_DATA_ADDR - (LOADADDR(.dummy1) + SIZEOF(.dummy1) + 3) & ~ 3) 338 331 339 332 _xip_data_start = .; 340 333 _sdata = .;