From 979b17f2431d03d5f83335c9d5d572e895862f44 Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Thu, 3 Oct 2019 15:20:41 -0700 Subject: [PATCH] kernel: activate arch interface headers Duplicate definitions elsewhere have been removed. A couple functions which are defined by the arch interface to be non-inline, but were implemented inline by native_posix and intel64, have been moved to non-inline. Some missing conditional compilation for z_arch_irq_offload() has been fixed, as this is an optional feature. Some massaging of native_posix headers to get everything in the right scope. Signed-off-by: Andrew Boie --- arch/arm/include/kernel_arch_func.h | 7 --- arch/posix/core/irq.c | 17 +++++++ arch/posix/include/posix_soc_if.h | 13 +++++ arch/x86/core/intel64/irq.c | 9 ++++ arch/x86/include/intel64/kernel_arch_func.h | 18 ------- boards/posix/native_posix/irq_handler.c | 2 + boards/posix/nrf52_bsim/irq_handler.c | 2 + include/arch/cpu.h | 2 + include/arch/posix/arch.h | 29 ----------- include/arch/x86/ia32/arch.h | 1 + include/irq.h | 4 -- include/irq_offload.h | 6 +-- include/kernel.h | 13 ++--- include/syscall.h | 39 -------------- kernel/include/kernel_internal.h | 56 --------------------- kernel/include/kernel_structs.h | 1 + 16 files changed, 54 insertions(+), 165 deletions(-) diff --git a/arch/arm/include/kernel_arch_func.h b/arch/arm/include/kernel_arch_func.h index 0a35f4e5186..f11204baf53 100644 --- a/arch/arm/include/kernel_arch_func.h +++ b/arch/arm/include/kernel_arch_func.h @@ -49,8 +49,6 @@ z_arch_thread_return_value_set(struct k_thread *thread, unsigned int value) thread->arch.swap_return_value = value; } -extern void z_arch_cpu_atomic_idle(unsigned int key); - extern FUNC_NORETURN void z_arm_userspace_enter(k_thread_entry_t user_entry, void *p1, void *p2, void *p3, u32_t stack_end, @@ -58,11 +56,6 @@ extern FUNC_NORETURN void z_arm_userspace_enter(k_thread_entry_t user_entry, extern void z_arm_fatal_error(unsigned int reason, const z_arch_esf_t *esf); -extern void z_arch_switch_to_main_thread(struct k_thread *main_thread, - k_thread_stack_t *main_stack, - size_t main_stack_size, - k_thread_entry_t _main); - #endif /* _ASMLANGUAGE */ #ifdef __cplusplus diff --git a/arch/posix/core/irq.c b/arch/posix/core/irq.c index 07349338f7b..3207b139000 100644 --- a/arch/posix/core/irq.c +++ b/arch/posix/core/irq.c @@ -7,10 +7,27 @@ #include "posix_soc_if.h" #include "board_irq.h" +#ifdef CONFIG_IRQ_OFFLOAD void z_arch_irq_offload(irq_offload_routine_t routine, void *parameter) { posix_irq_offload(routine, parameter); } +#endif + +void z_arch_irq_enable(unsigned int irq) +{ + posix_irq_enable(irq); +} + +void z_arch_irq_disable(unsigned int irq) +{ + posix_irq_disable(irq); +} + +int z_arch_irq_is_enabled(unsigned int irq) +{ + return posix_irq_is_enabled(irq); +} #ifdef CONFIG_DYNAMIC_INTERRUPTS /** diff --git a/arch/posix/include/posix_soc_if.h b/arch/posix/include/posix_soc_if.h index 20bb671221c..e3c98833d05 100644 --- a/arch/posix/include/posix_soc_if.h +++ b/arch/posix/include/posix_soc_if.h @@ -32,7 +32,20 @@ unsigned int posix_irq_lock(void); void posix_irq_unlock(unsigned int key); void posix_irq_full_unlock(void); int posix_get_current_irq(void); +#ifdef CONFIG_IRQ_OFFLOAD void posix_irq_offload(irq_offload_routine_t routine, void *parameter); +#endif + +static ALWAYS_INLINE unsigned int z_arch_irq_lock(void) +{ + return posix_irq_lock(); +} + + +static ALWAYS_INLINE void z_arch_irq_unlock(unsigned int key) +{ + posix_irq_unlock(key); +} #ifdef __cplusplus } diff --git a/arch/x86/core/intel64/irq.c b/arch/x86/core/intel64/irq.c index f4293512663..e3051b9958c 100644 --- a/arch/x86/core/intel64/irq.c +++ b/arch/x86/core/intel64/irq.c @@ -8,6 +8,7 @@ #include #include #include +#include #include unsigned char _irq_to_interrupt_vector[CONFIG_MAX_IRQ_LINES]; @@ -114,4 +115,12 @@ void z_x86_ipi_setup(void) (void *) z_sched_ipi; } +/* + * it is not clear exactly how/where/why to abstract this, as it + * assumes the use of a local APIC (but there's no other mechanism). + */ +void z_arch_sched_ipi(void) +{ + z_loapic_ipi(0, LOAPIC_ICR_IPI_OTHERS, CONFIG_SCHED_IPI_VECTOR); +} #endif diff --git a/arch/x86/include/intel64/kernel_arch_func.h b/arch/x86/include/intel64/kernel_arch_func.h index 29f9a5f5d69..5b58cdd64fb 100644 --- a/arch/x86/include/intel64/kernel_arch_func.h +++ b/arch/x86/include/intel64/kernel_arch_func.h @@ -40,24 +40,6 @@ static inline struct _cpu *z_arch_curr_cpu(void) return cpu; } - -#if defined(CONFIG_SMP) - -#include - -/* - * it is not clear exactly how/where/why to abstract this, as it - * assumes the use of a local APIC (but there's no other mechanism). - */ - -static inline void z_arch_sched_ipi(void) -{ - z_loapic_ipi(0, LOAPIC_ICR_IPI_OTHERS, CONFIG_SCHED_IPI_VECTOR); -} - -#endif - - #endif /* _ASMLANGUAGE */ #endif /* ZEPHYR_ARCH_X86_INCLUDE_INTEL64_KERNEL_ARCH_FUNC_H_ */ diff --git a/boards/posix/native_posix/irq_handler.c b/boards/posix/native_posix/irq_handler.c index 372a70dd0d7..4ad5fc2ad6a 100644 --- a/boards/posix/native_posix/irq_handler.c +++ b/boards/posix/native_posix/irq_handler.c @@ -274,6 +274,7 @@ void posix_sw_clear_pending_IRQ(unsigned int IRQn) hw_irq_ctrl_clear_irq(IRQn); } +#ifdef CONFIG_IRQ_OFFLOAD /** * Storage for functions offloaded to IRQ */ @@ -303,3 +304,4 @@ void posix_irq_offload(irq_offload_routine_t routine, void *parameter) posix_sw_set_pending_IRQ(OFFLOAD_SW_IRQ); posix_irq_disable(OFFLOAD_SW_IRQ); } +#endif /* CONFIG_IRQ_OFFLOAD */ diff --git a/boards/posix/nrf52_bsim/irq_handler.c b/boards/posix/nrf52_bsim/irq_handler.c index ad11893ffe0..f7d4045f70f 100644 --- a/boards/posix/nrf52_bsim/irq_handler.c +++ b/boards/posix/nrf52_bsim/irq_handler.c @@ -333,6 +333,7 @@ void posix_sw_clear_pending_IRQ(unsigned int IRQn) hw_irq_ctrl_clear_irq(IRQn); } +#ifdef CONFIG_IRQ_OFFLOAD /** * Storage for functions offloaded to IRQ */ @@ -362,6 +363,7 @@ void posix_irq_offload(irq_offload_routine_t routine, void *parameter) posix_sw_set_pending_IRQ(OFFLOAD_SW_IRQ); posix_irq_disable(OFFLOAD_SW_IRQ); } +#endif /** * Replacement for ARMs NVIC_SetPendingIRQ() diff --git a/include/arch/cpu.h b/include/arch/cpu.h index 53519e2d9ca..d21b8c6f44a 100644 --- a/include/arch/cpu.h +++ b/include/arch/cpu.h @@ -9,6 +9,8 @@ #ifndef ZEPHYR_INCLUDE_ARCH_CPU_H_ #define ZEPHYR_INCLUDE_ARCH_CPU_H_ +#include + #if defined(CONFIG_X86) #include #elif defined(CONFIG_X86_64) diff --git a/include/arch/posix/arch.h b/include/arch/posix/arch.h index 3e4182f844a..522002d8c36 100644 --- a/include/arch/posix/arch.h +++ b/include/arch/posix/arch.h @@ -56,35 +56,6 @@ static ALWAYS_INLINE void z_arch_nop(void) __asm__ volatile("nop"); } -static ALWAYS_INLINE unsigned int z_arch_irq_lock(void) -{ - return posix_irq_lock(); -} - -static ALWAYS_INLINE void z_arch_irq_unlock(unsigned int key) -{ - posix_irq_unlock(key); -} - -static ALWAYS_INLINE void z_arch_irq_enable(unsigned int irq) -{ - posix_irq_enable(irq); -} - -static ALWAYS_INLINE void z_arch_irq_disable(unsigned int irq) -{ - posix_irq_disable(irq); -} - -static ALWAYS_INLINE int z_arch_irq_is_enabled(unsigned int irq) -{ - return posix_irq_is_enabled(irq); -} - -/** - * Returns true if interrupts were unlocked prior to the - * z_arch_irq_lock() call that produced the key argument. - */ static ALWAYS_INLINE bool z_arch_irq_unlocked(unsigned int key) { return key == false; diff --git a/include/arch/x86/ia32/arch.h b/include/arch/x86/ia32/arch.h index f864122b01e..994b5bbdd79 100644 --- a/include/arch/x86/ia32/arch.h +++ b/include/arch/x86/ia32/arch.h @@ -21,6 +21,7 @@ #include #include #include +#include #ifndef _ASMLANGUAGE #include /* for size_t */ diff --git a/include/irq.h b/include/irq.h index b4e4b0ffebd..0c899a0de5e 100644 --- a/include/irq.h +++ b/include/irq.h @@ -50,10 +50,6 @@ extern "C" { #define IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \ Z_ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) -extern int z_arch_irq_connect_dynamic(unsigned int irq, unsigned int priority, - void (*routine)(void *parameter), void *parameter, - u32_t flags); - /** * Configure a dynamic interrupt. * diff --git a/include/irq_offload.h b/include/irq_offload.h index 430fde2521c..30d9bf6a2ae 100644 --- a/include/irq_offload.h +++ b/include/irq_offload.h @@ -15,10 +15,9 @@ extern "C" { #endif -typedef void (*irq_offload_routine_t)(void *parameter); - -void z_arch_irq_offload(irq_offload_routine_t routine, void *parameter); +#include +#ifdef CONFIG_IRQ_OFFLOAD /** * @brief Run a function in interrupt context * @@ -35,6 +34,7 @@ static inline void irq_offload(irq_offload_routine_t routine, void *parameter) { z_arch_irq_offload(routine, parameter); } +#endif #ifdef __cplusplus } diff --git a/include/kernel.h b/include/kernel.h index 53707516c07..407729b8c22 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -1814,7 +1814,10 @@ static inline u32_t k_uptime_delta_32(s64_t *reftime) * * @return Current hardware clock up-counter (in cycles). */ -#define k_cycle_get_32() z_arch_k_cycle_get_32() +static inline u32_t k_cycle_get_32(void) +{ + return z_arch_k_cycle_get_32(); +} /** * @} @@ -4747,10 +4750,6 @@ extern void z_handle_obj_poll_events(sys_dlist_t *events, u32_t state); * @ingroup kernel_apis * @{ */ - -extern void z_arch_cpu_idle(void); -extern void z_arch_cpu_atomic_idle(unsigned int key); - /** * @brief Make the CPU idle. * @@ -5162,10 +5161,6 @@ extern void k_mem_domain_remove_thread(k_tid_t thread); */ __syscall void k_str_out(char *c, size_t n); -extern void z_arch_start_cpu(int cpu_num, k_thread_stack_t *stack, int sz, - void (*fn)(int key, void *data), void *arg); - - /** * @brief Disable preservation of floating point context information. * diff --git a/include/syscall.h b/include/syscall.h index cf1279529d5..a9dea2ced19 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -86,45 +86,6 @@ extern "C" { typedef u32_t (*_k_syscall_handler_t)(u32_t arg1, u32_t arg2, u32_t arg3, u32_t arg4, u32_t arg5, u32_t arg6, void *ssf); -#ifdef CONFIG_USERSPACE - -/* - * Interfaces for invoking system calls - */ - -static inline u32_t z_arch_syscall_invoke0(u32_t call_id); - -static inline u32_t z_arch_syscall_invoke1(u32_t arg1, u32_t call_id); - -static inline u32_t z_arch_syscall_invoke2(u32_t arg1, u32_t arg2, - u32_t call_id); - -static inline u32_t z_arch_syscall_invoke3(u32_t arg1, u32_t arg2, u32_t arg3, - u32_t call_id); - -static inline u32_t z_arch_syscall_invoke4(u32_t arg1, u32_t arg2, u32_t arg3, - u32_t arg4, u32_t call_id); - -static inline u32_t z_arch_syscall_invoke5(u32_t arg1, u32_t arg2, u32_t arg3, - u32_t arg4, u32_t arg5, - u32_t call_id); - -static inline u32_t z_arch_syscall_invoke6(u32_t arg1, u32_t arg2, u32_t arg3, - u32_t arg4, u32_t arg5, u32_t arg6, - u32_t call_id); - -#endif /* CONFIG_USERSPACE */ - -/** - * Indicate whether we are currently running in user mode - * - * @return true if the CPU is currently running with user permissions - */ -#ifdef CONFIG_USERSPACE -static inline bool z_arch_is_user_context(void); -#else -#define z_arch_is_user_context() (true) -#endif /* True if a syscall function must trap to the kernel, usually a * compile-time decision. diff --git a/kernel/include/kernel_internal.h b/kernel/include/kernel_internal.h index 47d44ae88b2..1c03bec5f32 100644 --- a/kernel/include/kernel_internal.h +++ b/kernel/include/kernel_internal.h @@ -39,48 +39,13 @@ FUNC_NORETURN void z_cstart(void); extern FUNC_NORETURN void z_thread_entry(k_thread_entry_t entry, void *p1, void *p2, void *p3); -/* Implemented by architectures. Only called from z_setup_new_thread. */ -extern void z_arch_new_thread(struct k_thread *thread, k_thread_stack_t *pStack, - size_t stackSize, k_thread_entry_t entry, - void *p1, void *p2, void *p3, - int prio, unsigned int options); - extern void z_setup_new_thread(struct k_thread *new_thread, k_thread_stack_t *stack, size_t stack_size, k_thread_entry_t entry, void *p1, void *p2, void *p3, int prio, u32_t options, const char *name); -#if defined(CONFIG_FLOAT) && defined(CONFIG_FP_SHARING) -extern int z_arch_float_disable(struct k_thread *thread); -#endif /* CONFIG_FLOAT && CONFIG_FP_SHARING */ - #ifdef CONFIG_USERSPACE -extern int z_arch_mem_domain_max_partitions_get(void); - -extern void z_arch_mem_domain_thread_add(struct k_thread *thread); - -extern void z_arch_mem_domain_thread_remove(struct k_thread *thread); - -extern void z_arch_mem_domain_partition_remove(struct k_mem_domain *domain, - u32_t partition_id); - -extern void z_arch_mem_domain_partition_add(struct k_mem_domain *domain, - u32_t partition_id); - -extern void z_arch_mem_domain_destroy(struct k_mem_domain *domain); - -extern int z_arch_buffer_validate(void *addr, size_t size, int write); - -extern FUNC_NORETURN -void z_arch_user_mode_enter(k_thread_entry_t user_entry, void *p1, void *p2, - void *p3); - - -extern FUNC_NORETURN void z_arch_syscall_oops(void *ssf); - -extern size_t z_arch_user_string_nlen(const char *s, size_t maxsize, int *err); - /** * @brief Zero out BSS sections for application shared memory * @@ -128,27 +93,6 @@ extern u32_t z_early_boot_rand32_get(void); extern int z_stack_adjust_initialized; #endif -#if defined(CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT) -extern void z_arch_busy_wait(u32_t usec_to_wait); -#endif - -int z_arch_swap(unsigned int key); - -extern FUNC_NORETURN void z_arch_system_halt(unsigned int reason); - -#ifdef CONFIG_EXECUTION_BENCHMARKING -extern u64_t z_arch_timing_swap_start; -extern u64_t z_arch_timing_swap_end; -extern u64_t z_arch_timing_irq_start; -extern u64_t z_arch_timing_irq_end; -extern u64_t z_arch_timing_tick_start; -extern u64_t z_arch_timing_tick_end; -extern u64_t z_arch_timing_user_mode_end; -extern u32_t z_arch_timing_value_swap_end; -extern u64_t z_arch_timing_value_swap_common; -extern u64_t z_arch_timing_value_swap_temp; -#endif /* CONFIG_EXECUTION_BENCHMARKING */ - #ifdef CONFIG_BOOT_TIME_MEASUREMENT extern u32_t z_timestamp_main; /* timestamp when main task starts */ extern u32_t z_timestamp_idle; /* timestamp when CPU goes idle */ diff --git a/kernel/include/kernel_structs.h b/kernel/include/kernel_structs.h index df461c79343..49b8f3d910e 100644 --- a/kernel/include/kernel_structs.h +++ b/kernel/include/kernel_structs.h @@ -15,6 +15,7 @@ #include #include #include +#include #endif #define K_NUM_PRIORITIES \