Skip to content

Commit 2d74604

Browse files
stephanosioandrewboie
authored andcommitted
headers: Refactor kernel and arch headers.
This commit refactors kernel and arch headers to establish a boundary between private and public interface headers. The refactoring strategy used in this commit is detailed in the issue This commit introduces the following major changes: 1. Establish a clear boundary between private and public headers by removing "kernel/include" and "arch/*/include" from the global include paths. Ideally, only kernel/ and arch/*/ source files should reference the headers in these directories. If these headers must be used by a component, these include paths shall be manually added to the CMakeLists.txt file of the component. This is intended to discourage applications from including private kernel and arch headers either knowingly and unknowingly. - kernel/include/ (PRIVATE) This directory contains the private headers that provide private kernel definitions which should not be visible outside the kernel and arch source code. All public kernel definitions must be added to an appropriate header located under include/. - arch/*/include/ (PRIVATE) This directory contains the private headers that provide private architecture-specific definitions which should not be visible outside the arch and kernel source code. All public architecture- specific definitions must be added to an appropriate header located under include/arch/*/. - include/ AND include/sys/ (PUBLIC) This directory contains the public headers that provide public kernel definitions which can be referenced by both kernel and application code. - include/arch/*/ (PUBLIC) This directory contains the public headers that provide public architecture-specific definitions which can be referenced by both kernel and application code. 2. Split arch_interface.h into "kernel-to-arch interface" and "public arch interface" divisions. - kernel/include/kernel_arch_interface.h * provides private "kernel-to-arch interface" definition. * includes arch/*/include/kernel_arch_func.h to ensure that the interface function implementations are always available. * includes sys/arch_interface.h so that public arch interface definitions are automatically included when including this file. - arch/*/include/kernel_arch_func.h * provides architecture-specific "kernel-to-arch interface" implementation. * only the functions that will be used in kernel and arch source files are defined here. - include/sys/arch_interface.h * provides "public arch interface" definition. * includes include/arch/arch_inlines.h to ensure that the architecture-specific public inline interface function implementations are always available. - include/arch/arch_inlines.h * includes architecture-specific arch_inlines.h in include/arch/*/arch_inline.h. - include/arch/*/arch_inline.h * provides architecture-specific "public arch interface" inline function implementation. * supersedes include/sys/arch_inline.h. 3. Refactor kernel and the existing architecture implementations. - Remove circular dependency of kernel and arch headers. The following general rules should be observed: * Never include any private headers from public headers * Never include kernel_internal.h in kernel_arch_data.h * Always include kernel_arch_data.h from kernel_arch_func.h * Never include kernel.h from kernel_struct.h either directly or indirectly. Only add the kernel structures that must be referenced from public arch headers in this file. - Relocate syscall_handler.h to include/ so it can be used in the public code. This is necessary because many user-mode public codes reference the functions defined in this header. - Relocate kernel_arch_thread.h to include/arch/*/thread.h. This is necessary to provide architecture-specific thread definition for 'struct k_thread' in kernel.h. - Remove any private header dependencies from public headers using the following methods: * If dependency is not required, simply omit * If dependency is required, - Relocate a portion of the required dependencies from the private header to an appropriate public header OR - Relocate the required private header to make it public. This commit supersedes #20047, addresses #19666, and fixes #3056. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 8bb99dc commit 2d74604

File tree

244 files changed

+1519
-1274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+1519
-1274
lines changed

CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ add_library(zephyr_interface INTERFACE)
7373
zephyr_library_named(zephyr)
7474

7575
zephyr_include_directories(
76-
kernel/include
77-
${ARCH_DIR}/${ARCH}/include
7876
include
7977
include/drivers
8078
${PROJECT_BINARY_DIR}/include/generated
@@ -632,6 +630,10 @@ set(OFFSETS_C_PATH ${ARCH_DIR}/${ARCH}/core/offsets/offsets.c)
632630
set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h)
633631

634632
add_library( ${OFFSETS_LIB} OBJECT ${OFFSETS_C_PATH})
633+
target_include_directories(${OFFSETS_LIB} PRIVATE
634+
kernel/include
635+
${ARCH_DIR}/${ARCH}/include
636+
)
635637
target_link_libraries(${OFFSETS_LIB} zephyr_interface)
636638
add_dependencies( ${OFFSETS_LIB}
637639
${SYSCALL_LIST_H_TARGET}

arch/arc/core/CMakeLists.txt

+24-17
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,35 @@
33
zephyr_library()
44

55
zephyr_library_sources(
6-
thread.c
7-
thread_entry_wrapper.S
8-
cpu_idle.S
9-
fatal.c
10-
fault.c
11-
fault_s.S
12-
irq_manage.c
13-
timestamp.c
14-
isr_wrapper.S
15-
regular_irq.S
16-
switch.S
17-
prep_c.c
18-
reset.S
19-
vector_table.c
20-
)
6+
thread.c
7+
thread_entry_wrapper.S
8+
cpu_idle.S
9+
fatal.c
10+
fault.c
11+
fault_s.S
12+
irq_manage.c
13+
timestamp.c
14+
isr_wrapper.S
15+
regular_irq.S
16+
switch.S
17+
prep_c.c
18+
reset.S
19+
vector_table.c
20+
)
2121

2222
zephyr_library_sources_ifdef(CONFIG_CACHE_FLUSHING cache.c)
2323
zephyr_library_sources_ifdef(CONFIG_ARC_FIRQ fast_irq.S)
2424

2525
zephyr_library_sources_if_kconfig(irq_offload.c)
26-
add_subdirectory_ifdef(CONFIG_ARC_CORE_MPU mpu)
27-
add_subdirectory_ifdef(CONFIG_ARC_SECURE_FIRMWARE secureshield)
26+
2827
zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S)
2928
zephyr_library_sources_ifdef(CONFIG_ARC_CONNECT arc_connect.c)
3029
zephyr_library_sources_ifdef(CONFIG_SMP arc_smp.c)
30+
31+
zephyr_library_include_directories(
32+
${ZEPHYR_BASE}/kernel/include
33+
${ZEPHYR_BASE}/arch/arc/include
34+
)
35+
36+
add_subdirectory_ifdef(CONFIG_ARC_CORE_MPU mpu)
37+
add_subdirectory_ifdef(CONFIG_ARC_SECURE_FIRMWARE secureshield)

arch/arc/core/fast_irq.S

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <kernel_structs.h>
1717
#include <offsets_short.h>
1818
#include <toolchain.h>
19+
#include <linker/sections.h>
1920
#include <arch/cpu.h>
2021
#include <swap_macros.h>
2122

arch/arc/core/fatal.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
* ARCv2 CPUs.
1313
*/
1414

15-
#include <kernel_structs.h>
15+
#include <kernel.h>
1616
#include <offsets_short.h>
17-
#include <toolchain.h>
1817
#include <arch/cpu.h>
1918
#include <logging/log.h>
2019
LOG_MODULE_DECLARE(os);

arch/arc/core/fault.c

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <inttypes.h>
1717

1818
#include <kernel.h>
19+
#include <kernel_internal.h>
1920
#include <kernel_structs.h>
2021
#include <exc_handle.h>
2122
#include <logging/log.h>

arch/arc/core/mpu/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ zephyr_library()
44

55
zephyr_library_sources_if_kconfig(arc_core_mpu.c)
66
zephyr_library_sources_if_kconfig(arc_mpu.c)
7+
8+
zephyr_library_include_directories(
9+
${ZEPHYR_BASE}/kernel/include
10+
${ZEPHYR_BASE}/arch/arc/include
11+
)

arch/arc/core/offsets/offsets.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
* completeness.
2323
*/
2424

25+
#include <kernel.h>
26+
#include <kernel_arch_data.h>
2527
#include <gen_offset.h>
26-
#include <kernel_structs.h>
2728
#include <kernel_offsets.h>
2829

2930
GEN_OFFSET_SYM(_thread_arch_t, relinquish_cause);

arch/arc/core/regular_irq.S

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <kernel_structs.h>
1818
#include <offsets_short.h>
1919
#include <toolchain.h>
20+
#include <linker/sections.h>
2021
#include <arch/cpu.h>
2122
#include <swap_macros.h>
2223

arch/arc/core/secureshield/CMakeLists.txt

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
zephyr_library()
77

88
zephyr_library_sources(
9-
arc_sjli.c
10-
arc_secure.S
11-
secure_sys_services.c
12-
)
9+
arc_sjli.c
10+
arc_secure.S
11+
secure_sys_services.c
12+
)
13+
14+
zephyr_library_include_directories(
15+
${ZEPHYR_BASE}/kernel/include
16+
${ZEPHYR_BASE}/arch/arc/include
17+
)

arch/arc/core/switch.S

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <kernel_structs.h>
1818
#include <offsets_short.h>
1919
#include <toolchain.h>
20+
#include <linker/sections.h>
2021
#include <arch/cpu.h>
2122
#include <v2/irq.h>
2223
#include <swap_macros.h>

arch/arc/core/thread.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
*/
1313

1414
#include <kernel.h>
15-
#include <toolchain.h>
16-
#include <kernel_structs.h>
15+
#include <ksched.h>
1716
#include <offsets_short.h>
1817
#include <wait_q.h>
1918

arch/arc/include/kernel_arch_data.h

-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
#include <linker/sections.h>
2525
#include <arch/cpu.h>
2626
#include <vector_table.h>
27-
#include <kernel_arch_thread.h>
2827

2928
#ifndef _ASMLANGUAGE
3029
#include <kernel.h>
31-
#include <kernel_internal.h>
3230
#include <zephyr/types.h>
3331
#include <sys/util.h>
3432
#include <sys/dlist.h>

arch/arc/include/kernel_arch_func.h

+2-13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#if !defined(_ASMLANGUAGE)
2424

25+
#include <kernel_arch_data.h>
26+
2527
#ifdef CONFIG_CPU_ARCV2
2628
#include <v2/cache.h>
2729
#include <v2/irq.h>
@@ -31,19 +33,6 @@
3133
extern "C" {
3234
#endif
3335

34-
static ALWAYS_INLINE _cpu_t *z_arch_curr_cpu(void)
35-
{
36-
#ifdef CONFIG_SMP
37-
u32_t core;
38-
39-
core = z_arc_v2_core_id();
40-
41-
return &_kernel.cpus[core];
42-
#else
43-
return &_kernel.cpus[0];
44-
#endif
45-
}
46-
4736
static ALWAYS_INLINE void z_arch_kernel_init(void)
4837
{
4938
z_irq_setup();

arch/arm/core/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ zephyr_library_sources(
2020
prep_c.c
2121
)
2222

23+
zephyr_library_include_directories(
24+
${ZEPHYR_BASE}/kernel/include
25+
${ZEPHYR_BASE}/arch/arm/include
26+
)
27+
2328
zephyr_library_sources_ifdef(CONFIG_GEN_SW_ISR_TABLE isr_wrapper.S)
2429
zephyr_library_sources_ifdef(CONFIG_CPLUSPLUS __aeabi_atexit.c)
2530
zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)

arch/arm/core/cortex_m/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ zephyr_linker_sources_ifdef(CONFIG_SW_VECTOR_RELAY
1515
RAM_SECTIONS
1616
vt_pointer_section.ld
1717
)
18+
19+
zephyr_library_include_directories(
20+
${ZEPHYR_BASE}/kernel/include
21+
${ZEPHYR_BASE}/arch/arm/include
22+
)

arch/arm/core/cortex_m/fault.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
* Common fault handler for ARM Cortex-M processors.
1212
*/
1313

14-
#include <toolchain.h>
15-
#include <linker/sections.h>
16-
1714
#include <kernel.h>
18-
#include <kernel_structs.h>
15+
#include <kernel_internal.h>
1916
#include <inttypes.h>
2017
#include <exc_handle.h>
2118
#include <logging/log.h>

arch/arm/core/cortex_m/thread_abort.c

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include <kernel.h>
20-
#include <kernel_structs.h>
2120
#include <toolchain.h>
2221
#include <linker/sections.h>
2322
#include <ksched.h>

arch/arm/core/cortex_r/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ zephyr_library_sources(
99
reboot.c
1010
stacks.c
1111
)
12+
13+
zephyr_library_include_directories(
14+
${ZEPHYR_BASE}/kernel/include
15+
${ZEPHYR_BASE}/arch/arm/include
16+
)

arch/arm/core/cortex_r/fault.c

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <kernel.h>
8+
#include <kernel_internal.h>
89
#include <kernel_structs.h>
910

1011
/**

arch/arm/core/fatal.c

-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
* and Cortex-R CPUs.
1313
*/
1414

15-
#include <toolchain.h>
16-
#include <linker/sections.h>
17-
#include <inttypes.h>
18-
1915
#include <kernel.h>
20-
#include <kernel_structs.h>
2116
#include <logging/log.h>
2217
LOG_MODULE_DECLARE(os);
2318

arch/arm/core/irq_manage.c

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <linker/sections.h>
2828
#include <sw_isr_table.h>
2929
#include <irq.h>
30-
#include <kernel_structs.h>
3130
#include <debug/tracing.h>
3231

3332
extern void z_arm_reserved(void);

arch/arm/core/offsets/offsets.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
* completeness.
2323
*/
2424

25+
#include <kernel.h>
26+
#include <kernel_arch_data.h>
2527
#include <gen_offset.h>
26-
#include <kernel_structs.h>
2728
#include <kernel_offsets.h>
2829

2930
GEN_OFFSET_SYM(_thread_arch_t, basepri);

arch/arm/core/prep_c.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@
1717
*/
1818

1919
#include <kernel.h>
20-
#include <zephyr/types.h>
21-
#include <toolchain.h>
22-
#include <linker/linker-defs.h>
2320
#include <kernel_internal.h>
24-
#include <arch/cpu.h>
25-
#if defined(CONFIG_CPU_CORTEX_M)
26-
#include <arch/arm/cortex_m/cmsis.h>
27-
#elif defined(CONFIG_ARMV7_R)
21+
#include <linker/linker-defs.h>
22+
23+
#if defined(CONFIG_ARMV7_R)
2824
#include <cortex_r/stack.h>
2925
#endif
3026

arch/arm/core/swap.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
*/
66

77
#include <kernel.h>
8-
#include <toolchain.h>
9-
#include <kernel_structs.h>
8+
#include <kernel_internal.h>
109

1110
#ifdef CONFIG_EXECUTION_BENCHMARKING
1211
extern void read_timer_start_of_swap(void);

arch/arm/core/thread.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
*/
1414

1515
#include <kernel.h>
16-
#include <toolchain.h>
17-
#include <kernel_structs.h>
16+
#include <ksched.h>
1817
#include <wait_q.h>
1918

2019
#ifdef CONFIG_USERSPACE

arch/arm/include/kernel_arch_data.h

-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <toolchain.h>
2424
#include <linker/sections.h>
2525
#include <arch/cpu.h>
26-
#include <kernel_arch_thread.h>
2726

2827
/* stacks */
2928

@@ -40,7 +39,6 @@
4039

4140
#ifndef _ASMLANGUAGE
4241
#include <kernel.h>
43-
#include <kernel_internal.h>
4442
#include <zephyr/types.h>
4543
#include <sys/dlist.h>
4644
#include <sys/atomic.h>

arch/arm/include/kernel_arch_func.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
* in the offsets.o module.
1818
*/
1919

20-
/* this file is only meant to be included by kernel_structs.h */
21-
2220
#ifndef ZEPHYR_ARCH_ARM_INCLUDE_KERNEL_ARCH_FUNC_H_
2321
#define ZEPHYR_ARCH_ARM_INCLUDE_KERNEL_ARCH_FUNC_H_
2422

23+
#include <kernel_arch_data.h>
24+
2525
#ifdef __cplusplus
2626
extern "C" {
2727
#endif

arch/common/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ zephyr_linker_sources_ifdef(CONFIG_NOCACHE_MEMORY
2929
RAM_SECTIONS
3030
nocache.ld
3131
)
32+
33+
zephyr_library_include_directories(
34+
${ZEPHYR_BASE}/kernel/include
35+
${ZEPHYR_BASE}/arch/${ARCH}/include
36+
)

0 commit comments

Comments
 (0)