Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
arch_interface.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
27#ifndef ZEPHYR_INCLUDE_ARCH_ARCH_INTERFACE_H_
28#define ZEPHYR_INCLUDE_ARCH_ARCH_INTERFACE_H_
29
30#ifndef _ASMLANGUAGE
31#include <zephyr/toolchain.h>
32#include <stddef.h>
33#include <zephyr/types.h>
34#include <zephyr/arch/cpu.h>
35#include <zephyr/irq_offload.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/* NOTE: We cannot pull in kernel.h here, need some forward declarations */
42struct k_thread;
43struct k_mem_domain;
44
45typedef struct z_thread_stack_element k_thread_stack_t;
46
47typedef void (*k_thread_entry_t)(void *p1, void *p2, void *p3);
48
69static inline uint32_t arch_k_cycle_get_32(void);
70
83static inline uint64_t arch_k_cycle_get_64(void);
84
184void arch_cpu_idle(void);
185
204void arch_cpu_atomic_idle(unsigned int key);
205
219typedef void (*arch_cpustart_t)(void *data);
220
241void arch_cpu_start(int cpu_num, k_thread_stack_t *stack, int sz,
242 arch_cpustart_t fn, void *arg);
243
249bool arch_cpu_active(int cpu_num);
250
264static inline unsigned int arch_irq_lock(void);
265
271static inline void arch_irq_unlock(unsigned int key);
272
280static inline bool arch_irq_unlocked(unsigned int key);
281
296void arch_irq_disable(unsigned int irq);
297
303void arch_irq_enable(unsigned int irq);
304
310int arch_irq_is_enabled(unsigned int irq);
311
323int arch_irq_connect_dynamic(unsigned int irq, unsigned int priority,
324 void (*routine)(const void *parameter),
325 const void *parameter, uint32_t flags);
326
341int arch_irq_disconnect_dynamic(unsigned int irq, unsigned int priority,
342 void (*routine)(const void *parameter),
343 const void *parameter, uint32_t flags);
344
351#ifdef CONFIG_PCIE
357#endif /* CONFIG_PCIE */
358
389#ifndef CONFIG_PCIE_CONTROLLER
399unsigned int arch_irq_allocate(void);
400
409void arch_irq_set_used(unsigned int irq);
410
418bool arch_irq_is_used(unsigned int irq);
419
420#endif /* CONFIG_PCIE_CONTROLLER */
421
437#ifdef CONFIG_IRQ_OFFLOAD
454void arch_irq_offload(irq_offload_routine_t routine, const void *parameter);
455#endif /* CONFIG_IRQ_OFFLOAD */
456
465#ifdef CONFIG_SMP
467static inline struct _cpu *arch_curr_cpu(void);
468
469
489static inline uint32_t arch_proc_id(void);
490
496void arch_sched_ipi(void);
497
498
500
501#endif /* CONFIG_SMP */
502
511static inline unsigned int arch_num_cpus(void);
512
522#ifdef CONFIG_USERSPACE
523#include <zephyr/arch/syscall.h>
524
547
559 uintptr_t call_id);
560
573 uintptr_t call_id);
574
588 uintptr_t arg3,
589 uintptr_t call_id);
590
605 uintptr_t arg3, uintptr_t arg4,
606 uintptr_t call_id);
607
623 uintptr_t arg3, uintptr_t arg4,
624 uintptr_t arg5,
625 uintptr_t call_id);
626
643 uintptr_t arg3, uintptr_t arg4,
644 uintptr_t arg5, uintptr_t arg6,
645 uintptr_t call_id);
646
652static inline bool arch_is_user_context(void);
653
660
661#ifdef CONFIG_ARCH_MEM_DOMAIN_DATA
683int arch_mem_domain_init(struct k_mem_domain *domain);
684#endif /* CONFIG_ARCH_MEM_DOMAIN_DATA */
685
686#ifdef CONFIG_ARCH_MEM_DOMAIN_SYNCHRONOUS_API
704int arch_mem_domain_thread_add(struct k_thread *thread);
705
720int arch_mem_domain_thread_remove(struct k_thread *thread);
721
739int arch_mem_domain_partition_remove(struct k_mem_domain *domain,
740 uint32_t partition_id);
741
754int arch_mem_domain_partition_add(struct k_mem_domain *domain,
755 uint32_t partition_id);
756#endif /* CONFIG_ARCH_MEM_DOMAIN_SYNCHRONOUS_API */
757
786int arch_buffer_validate(const void *addr, size_t size, int write);
787
803size_t arch_virt_region_align(uintptr_t phys, size_t size);
804
823FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
824 void *p1, void *p2, void *p3);
825
840FUNC_NORETURN void arch_syscall_oops(void *ssf);
841
854size_t arch_user_string_nlen(const char *s, size_t maxsize, int *err);
855#endif /* CONFIG_USERSPACE */
856
871#ifndef CONFIG_ARCH_HAS_COHERENCE
872static inline bool arch_mem_coherent(void *ptr)
873{
874 ARG_UNUSED(ptr);
875 return true;
876}
877#endif
878
919#ifndef CONFIG_KERNEL_COHERENCE
920static inline void arch_cohere_stacks(struct k_thread *old_thread,
921 void *old_switch_handle,
922 struct k_thread *new_thread)
923{
924 ARG_UNUSED(old_thread);
925 ARG_UNUSED(old_switch_handle);
926 ARG_UNUSED(new_thread);
927}
928#endif
929
938#ifdef CONFIG_GDBSTUB
939struct gdb_ctx;
940
946void arch_gdb_init(void);
947
954
960void arch_gdb_step(void);
961
975size_t arch_gdb_reg_readall(struct gdb_ctx *ctx, uint8_t *buf, size_t buflen);
976
990size_t arch_gdb_reg_writeall(struct gdb_ctx *ctx, uint8_t *hex, size_t hexlen);
991
1006size_t arch_gdb_reg_readone(struct gdb_ctx *ctx, uint8_t *buf, size_t buflen,
1007 uint32_t regno);
1008
1023size_t arch_gdb_reg_writeone(struct gdb_ctx *ctx, uint8_t *hex, size_t hexlen,
1024 uint32_t regno);
1025
1039 uintptr_t addr, uint32_t kind);
1040
1054 uintptr_t addr, uint32_t kind);
1055
1056#endif
1059#ifdef CONFIG_TIMING_FUNCTIONS
1060#include <zephyr/timing/types.h>
1061
1081
1095
1109
1137
1153 volatile timing_t *const end);
1154
1163
1173
1184
1193
1196#endif /* CONFIG_TIMING_FUNCTIONS */
1197
1198#ifdef CONFIG_PCIE_MSI_MULTI_VECTOR
1199
1200struct msi_vector;
1201typedef struct msi_vector msi_vector_t;
1202
1212uint8_t arch_pcie_msi_vectors_allocate(unsigned int priority,
1213 msi_vector_t *vectors,
1214 uint8_t n_vector);
1215
1226bool arch_pcie_msi_vector_connect(msi_vector_t *vector,
1227 void (*routine)(const void *parameter),
1228 const void *parameter,
1229 uint32_t flags);
1230
1231#endif /* CONFIG_PCIE_MSI_MULTI_VECTOR */
1232
1242
1243#ifdef __cplusplus
1244}
1245#endif /* __cplusplus */
1246
1248
1249#endif /* _ASMLANGUAGE */
1250
1251#endif /* ZEPHYR_INCLUDE_ARCH_ARCH_INTERFACE_H_ */
#define arch_irq_disable(irq)
Definition: irq.h:107
#define arch_irq_enable(irq)
Definition: irq.h:106
#define arch_irq_is_enabled(irq)
Definition: irq.h:109
struct z_thread_stack_element k_thread_stack_t
Typedef of struct z_thread_stack_element.
Definition: arch_interface.h:45
void arch_spin_relax(void)
Perform architecture specific processing within spin loops.
void(* k_thread_entry_t)(void *p1, void *p2, void *p3)
Thread entry point function type.
Definition: arch_interface.h:47
irp nz macro MOVR cc s mov cc s endm endr irp aw macro LDR aa s
Definition: asm-macro-32-bit-gnu.h:17
size_t arch_gdb_reg_writeall(struct gdb_ctx *ctx, uint8_t *hex, size_t hexlen)
Take a hexadecimal string and update all registers.
void arch_gdb_init(void)
Architecture layer debug start.
void arch_gdb_step(void)
Continue with one step.
size_t arch_gdb_reg_readall(struct gdb_ctx *ctx, uint8_t *buf, size_t buflen)
Read all registers, and outputs as hexadecimal string.
int arch_gdb_remove_breakpoint(struct gdb_ctx *ctx, uint8_t type, uintptr_t addr, uint32_t kind)
Remove breakpoint or watchpoint.
void arch_gdb_continue(void)
Continue running program.
size_t arch_gdb_reg_readone(struct gdb_ctx *ctx, uint8_t *buf, size_t buflen, uint32_t regno)
Read one register, and outputs as hexadecimal string.
int arch_gdb_add_breakpoint(struct gdb_ctx *ctx, uint8_t type, uintptr_t addr, uint32_t kind)
Add breakpoint or watchpoint.
size_t arch_gdb_reg_writeone(struct gdb_ctx *ctx, uint8_t *hex, size_t hexlen, uint32_t regno)
Take a hexadecimal string and update one register.
static bool arch_irq_unlocked(unsigned int key)
Test if calling arch_irq_unlock() with this key would unlock irqs.
static unsigned int arch_irq_lock(void)
Lock interrupts on the current CPU.
int arch_irq_disconnect_dynamic(unsigned int irq, unsigned int priority, void(*routine)(const void *parameter), const void *parameter, uint32_t flags)
Arch-specific hook to dynamically uninstall a shared interrupt.
bool arch_irq_is_used(unsigned int irq)
Arch-specific hook for checking if an IRQ is being used already.
void arch_irq_set_used(unsigned int irq)
Arch-specific hook for declaring an IRQ being used.
static void arch_irq_unlock(unsigned int key)
Unlock interrupts on the current CPU.
int arch_irq_connect_dynamic(unsigned int irq, unsigned int priority, void(*routine)(const void *parameter), const void *parameter, uint32_t flags)
Arch-specific hook to install a dynamic interrupt.
unsigned int arch_irq_allocate(void)
Arch-specific hook for allocating IRQs.
void arch_cpu_atomic_idle(unsigned int key)
Atomically re-enable interrupts and enter low power mode.
void arch_cpu_idle(void)
Power save idle routine.
static unsigned int arch_num_cpus(void)
Returns the number of CPUs.
void arch_cpu_start(int cpu_num, k_thread_stack_t *stack, int sz, arch_cpustart_t fn, void *arg)
Start a numbered CPU on a MP-capable system.
void(* arch_cpustart_t)(void *data)
Per-cpu entry function.
Definition: arch_interface.h:219
bool arch_cpu_active(int cpu_num)
Return CPU power status.
int arch_smp_init(void)
static struct _cpu * arch_curr_cpu(void)
Return the CPU struct for the currently executing CPU.
static uint32_t arch_proc_id(void)
Processor hardware ID.
void arch_sched_ipi(void)
Broadcast an interrupt to all CPUs.
static uint32_t arch_k_cycle_get_32(void)
Obtain the current cycle count, in units specified by CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC.
static uint64_t arch_k_cycle_get_64(void)
As for arch_k_cycle_get_32(), but with a 64 bit return value.
static uintptr_t arch_syscall_invoke4(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t call_id)
Invoke a system call with 4 arguments.
int arch_buffer_validate(const void *addr, size_t size, int write)
Check memory region permissions.
size_t arch_user_string_nlen(const char *s, size_t maxsize, int *err)
Safely take the length of a potentially bad string.
static uintptr_t arch_syscall_invoke2(uintptr_t arg1, uintptr_t arg2, uintptr_t call_id)
Invoke a system call with 2 arguments.
static void arch_cohere_stacks(struct k_thread *old_thread, void *old_switch_handle, struct k_thread *new_thread)
Ensure cache coherence prior to context switch.
Definition: arch_interface.h:920
FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry, void *p1, void *p2, void *p3)
Perform a one-way transition from supervisor to user mode.
size_t arch_virt_region_align(uintptr_t phys, size_t size)
Get the optimal virtual region alignment to optimize the MMU table layout.
static uintptr_t arch_syscall_invoke1(uintptr_t arg1, uintptr_t call_id)
Invoke a system call with 1 argument.
static uintptr_t arch_syscall_invoke0(uintptr_t call_id)
Invoke a system call with 0 arguments.
int arch_mem_domain_max_partitions_get(void)
Get the maximum number of partitions for a memory domain.
static bool arch_is_user_context(void)
Indicate whether we are currently running in user mode.
static bool arch_mem_coherent(void *ptr)
Detect memory coherence type.
Definition: arch_interface.h:872
static uintptr_t arch_syscall_invoke5(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, uintptr_t call_id)
Invoke a system call with 5 arguments.
static uintptr_t arch_syscall_invoke3(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t call_id)
Invoke a system call with 3 arguments.
static uintptr_t arch_syscall_invoke6(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, uintptr_t arg6, uintptr_t call_id)
Invoke a system call with 6 arguments.
FUNC_NORETURN void arch_syscall_oops(void *ssf)
Induce a kernel oops that appears to come from a specific location.
uint64_t arch_timing_freq_get(void)
Get frequency of counter used (in Hz).
uint32_t arch_timing_freq_get_mhz(void)
Get frequency of counter used (in MHz).
uint64_t arch_timing_cycles_get(volatile timing_t *const start, volatile timing_t *const end)
Get number of cycles between start and end.
void arch_timing_stop(void)
Signal the end of the timing information gathering.
void arch_timing_init(void)
Initialize the timing subsystem.
uint64_t arch_timing_cycles_to_ns(uint64_t cycles)
Convert number of cycles into nanoseconds.
uint64_t arch_timing_cycles_to_ns_avg(uint64_t cycles, uint32_t count)
Convert number of cycles into nanoseconds with averaging.
timing_t arch_timing_counter_get(void)
Return timing counter.
void arch_timing_start(void)
Signal the start of the timing information gathering.
uint64_t timing_t
Definition: types.h:10
IRQ Offload interface.
void(* irq_offload_routine_t)(const void *parameter)
Definition: irq_offload.h:18
flags
Definition: parser.h:96
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT64_TYPE__ uint64_t
Definition: stdint.h:91
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:105
Architecture specific GDB context.
Definition: gdbstub.h:61
Memory Domain.
Definition: mem_domain.h:80
Thread Structure.
Definition: thread.h:259
Definition: msi.h:51
Macros to abstract toolchain specific capabilities.