Skip to content

Commit 5e4417f

Browse files
committed
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>
1 parent 4f17664 commit 5e4417f

6 files changed

Lines changed: 51 additions & 20 deletions

File tree

‎arch/xtensa/Kconfig‎

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -572,15 +572,41 @@ config KERNEL_LOAD_ADDRESS
572572

573573
If unsure, leave the default value here.
574574

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
579578
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.
582583

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.
584610

585611
config XIP_DATA_ADDR
586612
hex "XIP kernel data virtual address"

‎arch/xtensa/configs/smp_lx200_defconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ CONFIG_SMP=y
3030
CONFIG_HOTPLUG_CPU=y
3131
# CONFIG_INITIALIZE_XTENSA_MMU_INSIDE_VMLINUX is not set
3232
# CONFIG_PCI is not set
33-
CONFIG_VECTORS_OFFSET=0x00002000
3433
CONFIG_XTENSA_PLATFORM_XTFPGA=y
3534
CONFIG_CMDLINE_BOOL=y
3635
CONFIG_CMDLINE="earlycon=uart8250,mmio32native,0xfd050020,115200n8 console=ttyS0,115200n8 ip=dhcp root=/dev/nfs rw debug memmap=96M@0"

‎arch/xtensa/configs/virt_defconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ CONFIG_KALLSYMS_ALL=y
1919
CONFIG_PERF_EVENTS=y
2020
CONFIG_XTENSA_VARIANT_DC233C=y
2121
CONFIG_XTENSA_UNALIGNED_USER=y
22-
CONFIG_VECTORS_OFFSET=0x00002000
2322
CONFIG_XTENSA_KSEG_512M=y
2423
CONFIG_HIGHMEM=y
2524
CONFIG_CMDLINE_BOOL=y

‎arch/xtensa/include/asm/vectors.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
#endif
3535

3636
#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)
3939
#else
4040
#define VECBASE_VADDR _vecbase
4141
#endif

‎arch/xtensa/kernel/setup.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void __init setup_arch(char **cmdline_p)
349349
mem_reserve(__pa(_xip_start), __pa(_xip_end));
350350
#endif
351351

352-
#ifdef CONFIG_VECTORS_OFFSET
352+
#ifdef CONFIG_VECTORS_ADDR
353353
mem_reserve(__pa(&_WindowVectors_text_start),
354354
__pa(&_WindowVectors_text_end));
355355

@@ -388,7 +388,7 @@ void __init setup_arch(char **cmdline_p)
388388
__pa(&_Level6InterruptVector_text_end));
389389
#endif
390390

391-
#endif /* CONFIG_VECTORS_OFFSET */
391+
#endif /* CONFIG_VECTORS_ADDR */
392392

393393
#ifdef CONFIG_SMP
394394
mem_reserve(__pa(&_SecondaryResetVector_text_start),

‎arch/xtensa/kernel/vmlinux.lds.S‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ jiffies = jiffies_64;
4747
LONG(sym ## _end); \
4848
LONG(LOADADDR(section))
4949

50+
#if !defined(CONFIG_VECTORS_ADDR) && XCHAL_HAVE_VECBASE
51+
#define MERGED_VECTORS 1
52+
#else
53+
#define MERGED_VECTORS 0
54+
#endif
55+
5056
/*
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
5359
* time head.S copies code for every vector to its final position according
5460
* to description recorded in the corresponding RELOCATE_ENTRY.
5561
*/
@@ -84,7 +90,7 @@ SECTIONS
8490
/* The HEAD_TEXT section must be the first section! */
8591
HEAD_TEXT
8692

87-
#ifndef CONFIG_VECTORS_OFFSET
93+
#if MERGED_VECTORS
8894
. = ALIGN(PAGE_SIZE);
8995
_vecbase = .;
9096

@@ -159,7 +165,7 @@ SECTIONS
159165
. = ALIGN(16);
160166
__boot_reloc_table_start = ABSOLUTE(.);
161167

162-
#ifdef CONFIG_VECTORS_OFFSET
168+
#if !MERGED_VECTORS
163169
RELOCATE_ENTRY(_WindowVectors_text,
164170
.WindowVectors.text);
165171
#if XCHAL_EXCM_LEVEL >= 2
@@ -220,7 +226,7 @@ SECTIONS
220226
#undef LAST
221227
#define LAST .dummy
222228

223-
#ifdef CONFIG_VECTORS_OFFSET
229+
#if !MERGED_VECTORS
224230
/* The vectors are relocated to the real position at startup time */
225231

226232
SECTION_VECTOR4 (_WindowVectors_text,
@@ -299,7 +305,7 @@ SECTIONS
299305
#define LAST .SecondaryResetVector.text
300306

301307
#endif
302-
#ifdef CONFIG_VECTORS_OFFSET
308+
#if !MERGED_VECTORS
303309
SECTION_VECTOR4 (_exception_text,
304310
.exception.text,
305311
,
@@ -310,6 +316,7 @@ SECTIONS
310316
#endif
311317
. = (LOADADDR(LAST) + SIZEOF(LAST) + 3) & ~ 3;
312318

319+
.dummy1 : AT(ADDR(.dummy1)) { LONG(0) }
313320
. = ALIGN(PAGE_SIZE);
314321

315322
#ifndef CONFIG_XIP_KERNEL
@@ -327,7 +334,7 @@ SECTIONS
327334

328335
#undef LOAD_OFFSET
329336
#define LOAD_OFFSET \
330-
(CONFIG_XIP_DATA_ADDR - (LOADADDR(.dummy) + SIZEOF(.dummy) + 3) & ~ 3)
337+
(CONFIG_XIP_DATA_ADDR - (LOADADDR(.dummy1) + SIZEOF(.dummy1) + 3) & ~ 3)
331338

332339
_xip_data_start = .;
333340
_sdata = .;

0 commit comments

Comments
 (0)