Zephyr API Documentation 4.5.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
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/* NOTE: We cannot pull in kernel.h here, need some forward declarations */
40struct arch_esf;
41struct k_thread;
42struct k_mem_domain;
43
44typedef struct z_thread_stack_element k_thread_stack_t;
45
46typedef void (*k_thread_entry_t)(void *p1, void *p2, void *p3);
47
48#ifdef __cplusplus
49}
50#endif
51
52/*
53 * <zephyr/arch/cpu.h> pulls in the architecture headers, which in turn include
54 * <zephyr/kernel/thread.h>. That header uses the declarations above, so these
55 * includes have to come after them: otherwise a translation unit that includes
56 * this header before any kernel header fails to compile.
57 */
58#include <zephyr/arch/cpu.h>
59#include <zephyr/irq_offload.h>
60
61#ifdef __cplusplus
62extern "C" {
63#endif
64
70
85static inline uint32_t arch_k_cycle_get_32(void);
86
99static inline uint64_t arch_k_cycle_get_64(void);
100
102
103
108
122#ifdef __DOXYGEN__
123#define ARCH_THREAD_STACK_RESERVED
124#endif
125
135#ifdef __DOXYGEN__
136#define ARCH_STACK_PTR_ALIGN
137#endif
138
155#ifdef __DOXYGEN__
156#define ARCH_THREAD_STACK_OBJ_ALIGN(size)
157#endif
158
184#ifdef __DOXYGEN__
185#define ARCH_THREAD_STACK_SIZE_ADJUST(size)
186#endif
187
201#ifdef __DOXYGEN__
202#define ARCH_KERNEL_STACK_RESERVED
203#endif
204
212#ifdef __DOXYGEN__
213#define ARCH_KERNEL_STACK_OBJ_ALIGN(size)
214#endif
215
217
222
240void arch_cpu_idle(void);
241
260void arch_cpu_atomic_idle(unsigned int key);
261
277unsigned int arch_pm_state_set_prepare(void);
278
289void arch_pm_state_set_finish(unsigned int key);
290
292
298
304typedef void (*arch_cpustart_t)(void *data);
305
326void arch_cpu_start(int cpu_num, k_thread_stack_t *stack, int sz,
327 arch_cpustart_t fn, void *arg);
328
334bool arch_cpu_active(int cpu_num);
335
337
338
343
349static inline unsigned int arch_irq_lock(void);
350
356static inline void arch_irq_unlock(unsigned int key);
357
365static inline bool arch_irq_unlocked(unsigned int key);
366
376static inline bool arch_cpu_irqs_are_enabled(void);
377
378#ifdef CONFIG_ZERO_LATENCY_IRQS
379
389static inline unsigned int arch_zli_lock(void);
390
396static inline void arch_zli_unlock(unsigned int key);
397
398#endif
399
414void arch_irq_disable(unsigned int irq);
415
421void arch_irq_enable(unsigned int irq);
422
428int arch_irq_is_enabled(unsigned int irq);
429
430#if defined(CONFIG_ARCH_HAS_IRQ_PENDING_OPS) || defined(__DOXYGEN__)
436void arch_irq_clear_pending(unsigned int irq);
437
443void arch_irq_set_pending(unsigned int irq);
444
450bool arch_irq_is_pending(unsigned int irq);
451#endif
452
453#if defined(CONFIG_ARCH_HAS_IRQ_GET_ACTIVE) || defined(__DOXYGEN__)
459unsigned int arch_irq_get_active(void);
460#endif
461
473int arch_irq_connect_dynamic(unsigned int irq, unsigned int priority,
474 void (*routine)(const void *parameter),
475 const void *parameter, uint32_t flags);
476
491int arch_irq_disconnect_dynamic(unsigned int irq, unsigned int priority,
492 void (*routine)(const void *parameter),
493 const void *parameter, uint32_t flags);
494
513#ifdef __DOXYGEN__
514#define ARCH_IRQ_CONNECT(irq, pri, isr, arg, flags)
515#endif
516
534#ifdef __DOXYGEN__
535#define ARCH_PCIE_IRQ_CONNECT(bdf, irq, pri, isr, arg, flags)
536#endif
537
554#ifdef __DOXYGEN__
555#define ARCH_IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p)
556#endif
557
569#ifdef __DOXYGEN__
570#define ARCH_ISR_DIRECT_PM()
571#endif
572
584#ifdef __DOXYGEN__
585#define ARCH_ISR_DIRECT_HEADER()
586#endif
587
601#ifdef __DOXYGEN__
602#define ARCH_ISR_DIRECT_FOOTER(swap)
603#endif
604
620#ifdef __DOXYGEN__
621#define ARCH_ISR_DIRECT_DECLARE(name)
622#endif
623
637unsigned int arch_irq_allocate(void);
638
647void arch_irq_set_used(unsigned int irq);
648
656bool arch_irq_is_used(unsigned int irq);
657
672#ifdef __DOXYGEN__
673#define ARCH_EXCEPT(reason_p)
674#endif
675
676#ifdef CONFIG_IRQ_OFFLOAD
693void arch_irq_offload(irq_offload_routine_t routine, const void *parameter);
694
695
699void arch_irq_offload_init(void);
700
701#endif /* CONFIG_IRQ_OFFLOAD */
702
704
709#ifdef CONFIG_SMP
711static inline struct _cpu *arch_curr_cpu(void);
712
713
733static inline uint32_t arch_proc_id(void);
734
741
750
752
753#endif /* CONFIG_SMP */
754
763static inline unsigned int arch_num_cpus(void);
764
766
767
772
796int arch_page_phys_get(void *virt, uintptr_t *phys);
797
799
805
806#ifdef CONFIG_USERSPACE
807#include <zephyr/arch/syscall.h>
808
831
843 uintptr_t call_id);
844
857 uintptr_t call_id);
858
872 uintptr_t arg3,
873 uintptr_t call_id);
874
889 uintptr_t arg3, uintptr_t arg4,
890 uintptr_t call_id);
891
907 uintptr_t arg3, uintptr_t arg4,
908 uintptr_t arg5,
909 uintptr_t call_id);
910
927 uintptr_t arg3, uintptr_t arg4,
928 uintptr_t arg5, uintptr_t arg6,
929 uintptr_t call_id);
930
936static inline bool arch_is_user_context(void);
937
944
945#ifdef CONFIG_ARCH_MEM_DOMAIN_DATA
967int arch_mem_domain_init(struct k_mem_domain *domain);
968#endif /* CONFIG_ARCH_MEM_DOMAIN_DATA */
969
988
989#ifdef CONFIG_ARCH_MEM_DOMAIN_SYNCHRONOUS_API
1010int arch_mem_domain_thread_add(struct k_thread *thread);
1011
1026int arch_mem_domain_thread_remove(struct k_thread *thread);
1027
1045int arch_mem_domain_partition_remove(struct k_mem_domain *domain,
1046 uint32_t partition_id);
1047
1060int arch_mem_domain_partition_add(struct k_mem_domain *domain,
1061 uint32_t partition_id);
1062#endif /* CONFIG_ARCH_MEM_DOMAIN_SYNCHRONOUS_API */
1063
1092int arch_buffer_validate(const void *addr, size_t size, int write);
1093
1109size_t arch_virt_region_align(uintptr_t phys, size_t size);
1110
1129FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
1130 void *p1, void *p2, void *p3);
1131
1146FUNC_NORETURN void arch_syscall_oops(void *ssf);
1147
1160size_t arch_user_string_nlen(const char *s, size_t maxsize, int *err);
1161#endif /* CONFIG_USERSPACE */
1162
1203#ifndef CONFIG_KERNEL_COHERENCE
1204static inline void arch_cohere_stacks(struct k_thread *old_thread,
1205 void *old_switch_handle,
1206 struct k_thread *new_thread)
1207{
1208 ARG_UNUSED(old_thread);
1209 ARG_UNUSED(old_switch_handle);
1210 ARG_UNUSED(new_thread);
1211}
1212#endif
1213
1215
1221
1222#ifdef CONFIG_GDBSTUB
1223struct gdb_ctx;
1224
1230void arch_gdb_init(void);
1231
1238
1244void arch_gdb_step(void);
1245
1259size_t arch_gdb_reg_readall(struct gdb_ctx *ctx, uint8_t *buf, size_t buflen);
1260
1274size_t arch_gdb_reg_writeall(struct gdb_ctx *ctx, uint8_t *hex, size_t hexlen);
1275
1290size_t arch_gdb_reg_readone(struct gdb_ctx *ctx, uint8_t *buf, size_t buflen,
1291 uint32_t regno);
1292
1307size_t arch_gdb_reg_writeone(struct gdb_ctx *ctx, uint8_t *hex, size_t hexlen,
1308 uint32_t regno);
1309
1322int arch_gdb_add_breakpoint(struct gdb_ctx *ctx, uint8_t type,
1323 uintptr_t addr, uint32_t kind);
1324
1337int arch_gdb_remove_breakpoint(struct gdb_ctx *ctx, uint8_t type,
1338 uintptr_t addr, uint32_t kind);
1339
1347void arch_gdb_post_memory_write(uintptr_t addr, size_t len, uint8_t align);
1348
1349#endif
1351
1352#ifdef CONFIG_TIMING_FUNCTIONS
1353#include <zephyr/timing/types.h>
1354
1365
1374
1388
1402
1430
1446 volatile timing_t *const end);
1447
1456
1466
1477
1486
1488
1489#endif /* CONFIG_TIMING_FUNCTIONS */
1490
1491#ifdef CONFIG_PCIE_MSI_MULTI_VECTOR
1492
1493struct msi_vector;
1494typedef struct msi_vector msi_vector_t;
1495
1505uint8_t arch_pcie_msi_vectors_allocate(unsigned int priority,
1506 msi_vector_t *vectors,
1507 uint8_t n_vector);
1508
1519bool arch_pcie_msi_vector_connect(msi_vector_t *vector,
1520 void (*routine)(const void *parameter),
1521 const void *parameter,
1522 uint32_t flags);
1523
1524#endif /* CONFIG_PCIE_MSI_MULTI_VECTOR */
1525
1535
1547
1555typedef bool (*stack_trace_callback_fn)(void *cookie, unsigned long addr);
1556
1572void arch_stack_walk(stack_trace_callback_fn callback_fn, void *cookie,
1573 const struct k_thread *thread, const struct arch_esf *esf);
1574
1576
1577#ifdef __cplusplus
1578}
1579#endif /* __cplusplus */
1580
1582
1583#endif /* _ASMLANGUAGE */
1584
1585#endif /* ZEPHYR_INCLUDE_ARCH_ARCH_INTERFACE_H_ */
void(* k_thread_entry_t)(void *p1, void *p2, void *p3)
Thread entry point function type.
Definition arch_interface.h:46
void arch_spin_relax(void)
Perform architecture specific processing within spin loops.
struct z_thread_stack_element k_thread_stack_t
Typedef of struct z_thread_stack_element.
Definition arch_interface.h:44
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.
void arch_gdb_post_memory_write(uintptr_t addr, size_t len, uint8_t align)
Post processing after memory write.
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.
void arch_irq_disable(unsigned int irq)
Disable the specified interrupt line.
static unsigned int arch_irq_lock(void)
Lock interrupts on the current CPU.
int arch_irq_is_enabled(unsigned int irq)
Test if an interrupt line is enabled.
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.
void arch_irq_clear_pending(unsigned int irq)
Clear the pending state of the specified interrupt line.
void arch_irq_enable(unsigned int irq)
Enable the specified interrupt line.
static void arch_irq_unlock(unsigned int key)
Unlock interrupts on the current CPU.
bool arch_irq_is_pending(unsigned int irq)
Test if the specified interrupt line is pending.
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_irq_set_pending(unsigned int irq)
Set the pending state of the specified interrupt line.
static bool arch_cpu_irqs_are_enabled(void)
Probe the current CPU overall interrupt controller lock state without modifying it.
unsigned int arch_irq_get_active(void)
Report the interrupt line being serviced on the current CPU.
int arch_page_phys_get(void *virt, uintptr_t *phys)
Get the physical address mapped at a virtual address.
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.
unsigned int arch_pm_state_set_prepare(void)
Prepare interrupt state before entering a system PM state.
void arch_pm_state_set_finish(unsigned int key)
Restore interrupt state after leaving a system PM state.
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:304
bool arch_cpu_active(int cpu_num)
Return CPU power status.
int arch_smp_init(void)
void arch_sched_broadcast_ipi(void)
Broadcast an interrupt to all CPUs.
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_directed_ipi(uint32_t cpu_bitmap)
Direct IPIs to the specified CPUs.
void arch_stack_walk(stack_trace_callback_fn callback_fn, void *cookie, const struct k_thread *thread, const struct arch_esf *esf)
Architecture-specific function to walk the stack.
bool(* stack_trace_callback_fn)(void *cookie, unsigned long addr)
stack_trace_callback_fn - Callback for arch_stack_walk
Definition arch_interface.h:1555
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:1204
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 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.
int arch_mem_domain_deinit(struct k_mem_domain *domain)
Architecture-specific hook for memory domain de-initialization.
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.
struct msi_vector msi_vector_t
Definition msi.h:66
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:86
#define bool
Definition stdbool.h:13
__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
Memory Domain.
Definition mem_domain.h:80
Thread Structure.
Definition thread.h:258
Definition msi.h:57
Macros to abstract toolchain specific capabilities.