Skip to content

Commit

Permalink
headers: Refactor kernel and arch headers.
Browse files Browse the repository at this point in the history
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 zephyrproject-rtos#20047, addresses zephyrproject-rtos#19666, and fixes zephyrproject-rtos#3056.

Signed-off-by: Stephanos Ioannidis <[email protected]>
  • Loading branch information
stephanosio authored and andrewboie committed Nov 7, 2019
1 parent 8bb99dc commit 2d74604
Show file tree
Hide file tree
Showing 244 changed files with 1,519 additions and 1,274 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ add_library(zephyr_interface INTERFACE)
zephyr_library_named(zephyr)

zephyr_include_directories(
kernel/include
${ARCH_DIR}/${ARCH}/include
include
include/drivers
${PROJECT_BINARY_DIR}/include/generated
Expand Down Expand Up @@ -632,6 +630,10 @@ set(OFFSETS_C_PATH ${ARCH_DIR}/${ARCH}/core/offsets/offsets.c)
set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h)

add_library( ${OFFSETS_LIB} OBJECT ${OFFSETS_C_PATH})
target_include_directories(${OFFSETS_LIB} PRIVATE
kernel/include
${ARCH_DIR}/${ARCH}/include
)
target_link_libraries(${OFFSETS_LIB} zephyr_interface)
add_dependencies( ${OFFSETS_LIB}
${SYSCALL_LIST_H_TARGET}
Expand Down
41 changes: 24 additions & 17 deletions arch/arc/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@
zephyr_library()

zephyr_library_sources(
thread.c
thread_entry_wrapper.S
cpu_idle.S
fatal.c
fault.c
fault_s.S
irq_manage.c
timestamp.c
isr_wrapper.S
regular_irq.S
switch.S
prep_c.c
reset.S
vector_table.c
)
thread.c
thread_entry_wrapper.S
cpu_idle.S
fatal.c
fault.c
fault_s.S
irq_manage.c
timestamp.c
isr_wrapper.S
regular_irq.S
switch.S
prep_c.c
reset.S
vector_table.c
)

zephyr_library_sources_ifdef(CONFIG_CACHE_FLUSHING cache.c)
zephyr_library_sources_ifdef(CONFIG_ARC_FIRQ fast_irq.S)

zephyr_library_sources_if_kconfig(irq_offload.c)
add_subdirectory_ifdef(CONFIG_ARC_CORE_MPU mpu)
add_subdirectory_ifdef(CONFIG_ARC_SECURE_FIRMWARE secureshield)

zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S)
zephyr_library_sources_ifdef(CONFIG_ARC_CONNECT arc_connect.c)
zephyr_library_sources_ifdef(CONFIG_SMP arc_smp.c)

zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/arc/include
)

add_subdirectory_ifdef(CONFIG_ARC_CORE_MPU mpu)
add_subdirectory_ifdef(CONFIG_ARC_SECURE_FIRMWARE secureshield)
1 change: 1 addition & 0 deletions arch/arc/core/fast_irq.S
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <kernel_structs.h>
#include <offsets_short.h>
#include <toolchain.h>
#include <linker/sections.h>
#include <arch/cpu.h>
#include <swap_macros.h>

Expand Down
3 changes: 1 addition & 2 deletions arch/arc/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
* ARCv2 CPUs.
*/

#include <kernel_structs.h>
#include <kernel.h>
#include <offsets_short.h>
#include <toolchain.h>
#include <arch/cpu.h>
#include <logging/log.h>
LOG_MODULE_DECLARE(os);
Expand Down
1 change: 1 addition & 0 deletions arch/arc/core/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <inttypes.h>

#include <kernel.h>
#include <kernel_internal.h>
#include <kernel_structs.h>
#include <exc_handle.h>
#include <logging/log.h>
Expand Down
5 changes: 5 additions & 0 deletions arch/arc/core/mpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ zephyr_library()

zephyr_library_sources_if_kconfig(arc_core_mpu.c)
zephyr_library_sources_if_kconfig(arc_mpu.c)

zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/arc/include
)
3 changes: 2 additions & 1 deletion arch/arc/core/offsets/offsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
* completeness.
*/

#include <kernel.h>
#include <kernel_arch_data.h>
#include <gen_offset.h>
#include <kernel_structs.h>
#include <kernel_offsets.h>

GEN_OFFSET_SYM(_thread_arch_t, relinquish_cause);
Expand Down
1 change: 1 addition & 0 deletions arch/arc/core/regular_irq.S
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <kernel_structs.h>
#include <offsets_short.h>
#include <toolchain.h>
#include <linker/sections.h>
#include <arch/cpu.h>
#include <swap_macros.h>

Expand Down
13 changes: 9 additions & 4 deletions arch/arc/core/secureshield/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
zephyr_library()

zephyr_library_sources(
arc_sjli.c
arc_secure.S
secure_sys_services.c
)
arc_sjli.c
arc_secure.S
secure_sys_services.c
)

zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/arc/include
)
1 change: 1 addition & 0 deletions arch/arc/core/switch.S
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <kernel_structs.h>
#include <offsets_short.h>
#include <toolchain.h>
#include <linker/sections.h>
#include <arch/cpu.h>
#include <v2/irq.h>
#include <swap_macros.h>
Expand Down
3 changes: 1 addition & 2 deletions arch/arc/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
*/

#include <kernel.h>
#include <toolchain.h>
#include <kernel_structs.h>
#include <ksched.h>
#include <offsets_short.h>
#include <wait_q.h>

Expand Down
2 changes: 0 additions & 2 deletions arch/arc/include/kernel_arch_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
#include <linker/sections.h>
#include <arch/cpu.h>
#include <vector_table.h>
#include <kernel_arch_thread.h>

#ifndef _ASMLANGUAGE
#include <kernel.h>
#include <kernel_internal.h>
#include <zephyr/types.h>
#include <sys/util.h>
#include <sys/dlist.h>
Expand Down
15 changes: 2 additions & 13 deletions arch/arc/include/kernel_arch_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#if !defined(_ASMLANGUAGE)

#include <kernel_arch_data.h>

#ifdef CONFIG_CPU_ARCV2
#include <v2/cache.h>
#include <v2/irq.h>
Expand All @@ -31,19 +33,6 @@
extern "C" {
#endif

static ALWAYS_INLINE _cpu_t *z_arch_curr_cpu(void)
{
#ifdef CONFIG_SMP
u32_t core;

core = z_arc_v2_core_id();

return &_kernel.cpus[core];
#else
return &_kernel.cpus[0];
#endif
}

static ALWAYS_INLINE void z_arch_kernel_init(void)
{
z_irq_setup();
Expand Down
5 changes: 5 additions & 0 deletions arch/arm/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ zephyr_library_sources(
prep_c.c
)

zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/arm/include
)

zephyr_library_sources_ifdef(CONFIG_GEN_SW_ISR_TABLE isr_wrapper.S)
zephyr_library_sources_ifdef(CONFIG_CPLUSPLUS __aeabi_atexit.c)
zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)
Expand Down
5 changes: 5 additions & 0 deletions arch/arm/core/cortex_m/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ zephyr_linker_sources_ifdef(CONFIG_SW_VECTOR_RELAY
RAM_SECTIONS
vt_pointer_section.ld
)

zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/arm/include
)
5 changes: 1 addition & 4 deletions arch/arm/core/cortex_m/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
* Common fault handler for ARM Cortex-M processors.
*/

#include <toolchain.h>
#include <linker/sections.h>

#include <kernel.h>
#include <kernel_structs.h>
#include <kernel_internal.h>
#include <inttypes.h>
#include <exc_handle.h>
#include <logging/log.h>
Expand Down
1 change: 0 additions & 1 deletion arch/arm/core/cortex_m/thread_abort.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

#include <kernel.h>
#include <kernel_structs.h>
#include <toolchain.h>
#include <linker/sections.h>
#include <ksched.h>
Expand Down
5 changes: 5 additions & 0 deletions arch/arm/core/cortex_r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ zephyr_library_sources(
reboot.c
stacks.c
)

zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/arm/include
)
1 change: 1 addition & 0 deletions arch/arm/core/cortex_r/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <kernel.h>
#include <kernel_internal.h>
#include <kernel_structs.h>

/**
Expand Down
5 changes: 0 additions & 5 deletions arch/arm/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
* and Cortex-R CPUs.
*/

#include <toolchain.h>
#include <linker/sections.h>
#include <inttypes.h>

#include <kernel.h>
#include <kernel_structs.h>
#include <logging/log.h>
LOG_MODULE_DECLARE(os);

Expand Down
1 change: 0 additions & 1 deletion arch/arm/core/irq_manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <linker/sections.h>
#include <sw_isr_table.h>
#include <irq.h>
#include <kernel_structs.h>
#include <debug/tracing.h>

extern void z_arm_reserved(void);
Expand Down
3 changes: 2 additions & 1 deletion arch/arm/core/offsets/offsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
* completeness.
*/

#include <kernel.h>
#include <kernel_arch_data.h>
#include <gen_offset.h>
#include <kernel_structs.h>
#include <kernel_offsets.h>

GEN_OFFSET_SYM(_thread_arch_t, basepri);
Expand Down
10 changes: 3 additions & 7 deletions arch/arm/core/prep_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
*/

#include <kernel.h>
#include <zephyr/types.h>
#include <toolchain.h>
#include <linker/linker-defs.h>
#include <kernel_internal.h>
#include <arch/cpu.h>
#if defined(CONFIG_CPU_CORTEX_M)
#include <arch/arm/cortex_m/cmsis.h>
#elif defined(CONFIG_ARMV7_R)
#include <linker/linker-defs.h>

#if defined(CONFIG_ARMV7_R)
#include <cortex_r/stack.h>
#endif

Expand Down
3 changes: 1 addition & 2 deletions arch/arm/core/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*/

#include <kernel.h>
#include <toolchain.h>
#include <kernel_structs.h>
#include <kernel_internal.h>

#ifdef CONFIG_EXECUTION_BENCHMARKING
extern void read_timer_start_of_swap(void);
Expand Down
3 changes: 1 addition & 2 deletions arch/arm/core/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
*/

#include <kernel.h>
#include <toolchain.h>
#include <kernel_structs.h>
#include <ksched.h>
#include <wait_q.h>

#ifdef CONFIG_USERSPACE
Expand Down
2 changes: 0 additions & 2 deletions arch/arm/include/kernel_arch_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <toolchain.h>
#include <linker/sections.h>
#include <arch/cpu.h>
#include <kernel_arch_thread.h>

/* stacks */

Expand All @@ -40,7 +39,6 @@

#ifndef _ASMLANGUAGE
#include <kernel.h>
#include <kernel_internal.h>
#include <zephyr/types.h>
#include <sys/dlist.h>
#include <sys/atomic.h>
Expand Down
4 changes: 2 additions & 2 deletions arch/arm/include/kernel_arch_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* in the offsets.o module.
*/

/* this file is only meant to be included by kernel_structs.h */

#ifndef ZEPHYR_ARCH_ARM_INCLUDE_KERNEL_ARCH_FUNC_H_
#define ZEPHYR_ARCH_ARM_INCLUDE_KERNEL_ARCH_FUNC_H_

#include <kernel_arch_data.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
5 changes: 5 additions & 0 deletions arch/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ zephyr_linker_sources_ifdef(CONFIG_NOCACHE_MEMORY
RAM_SECTIONS
nocache.ld
)

zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/${ARCH}/include
)
Loading

0 comments on commit 2d74604

Please sign in to comment.