Zephyr Project API 4.5.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
arch_inlines.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_ARCH_ARM64_ARCH_INLINES_H
8#define ZEPHYR_INCLUDE_ARCH_ARM64_ARCH_INLINES_H
9
10#ifndef _ASMLANGUAGE
11
15#include <zephyr/sys/__assert.h>
16
17#ifdef CONFIG_ARCH_HAS_CUSTOM_CURRENT_IMPL
18/* A register read cannot race with migration between a CPU lookup and load. */
19static ALWAYS_INLINE struct k_thread *arch_current_thread(void)
20{
21 uintptr_t thread;
22
23 /* The _current contract permits reusing this read. Code that needs an
24 * updated value before the context switch uses _raw_current instead.
25 */
26 __asm__("mrs %0, tpidr_el1" : "=r"(thread));
27 return (struct k_thread *)thread;
28}
29
30static ALWAYS_INLINE void arch_current_thread_set(struct k_thread *thread)
31{
32 /* The scheduler updates this CPU-local register with preemption disabled. */
33 write_tpidr_el1((uintptr_t)thread);
34}
35#endif
36
37/* Note: keep in sync with `get_cpu` in arch/arm64/core/macro_priv.inc */
38static ALWAYS_INLINE _cpu_t *arch_curr_cpu(void)
39{
40 return (_cpu_t *)(read_tpidrro_el0() & TPIDRROEL0_CURR_CPU);
41}
42
44{
45 return (read_tpidrro_el0() & TPIDRROEL0_EXC_DEPTH) / TPIDRROEL0_EXC_UNIT;
46}
47
49{
50 uint64_t cpu_mpid = read_mpidr_el1();
51
52 __ASSERT(cpu_mpid == (uint32_t)cpu_mpid, "mpid extends past 32 bits");
53
54 return (uint32_t)cpu_mpid;
55}
56
57static ALWAYS_INLINE unsigned int arch_num_cpus(void)
58{
59 return CONFIG_MP_MAX_NUM_CPUS;
60}
61
62#endif /* !_ASMLANGUAGE */
63#endif /* ZEPHYR_INCLUDE_ARCH_ARM64_ARCH_INLINES_H */
static ALWAYS_INLINE _cpu_t * arch_curr_cpu(void)
Definition arch_inlines.h:17
static ALWAYS_INLINE uint32_t arch_proc_id(void)
Definition arch_inlines.h:30
static ALWAYS_INLINE unsigned int arch_num_cpus(void)
Definition arch_inlines.h:39
static ALWAYS_INLINE int arch_exception_depth(void)
Definition arch_inlines.h:43
#define ALWAYS_INLINE
Definition common.h:186
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Thread Structure.
Definition thread.h:258
tpidrro_el0 bits allocation
#define TPIDRROEL0_EXC_UNIT
Definition tpidrro_el0.h:25
#define TPIDRROEL0_CURR_CPU
Definition tpidrro_el0.h:22
#define TPIDRROEL0_EXC_DEPTH
Definition tpidrro_el0.h:24