Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
arch_inlines.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_INLINES_H_
8#define ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_INLINES_H_
9
10#ifndef _ASMLANGUAGE
11
13#include "csr.h"
14
16{
17#ifdef CONFIG_RISCV_S_MODE
18 /* mhartid is M-mode only; S-mode cannot read it.
19 * For single-hart systems the hart ID is always 0.
20 * SMP S-mode would need to retrieve this from per-CPU data.
21 */
22 return 0;
23#else
24 return csr_read(mhartid) & ((uintptr_t)CONFIG_RISCV_HART_MASK);
25#endif
26}
27
28static ALWAYS_INLINE _cpu_t *arch_curr_cpu(void)
29{
30#if defined(CONFIG_SMP) || defined(CONFIG_USERSPACE)
31#ifdef CONFIG_RISCV_S_MODE
32 return (_cpu_t *)csr_read(sscratch);
33#else
34 return (_cpu_t *)csr_read(mscratch);
35#endif
36#else
37 return &_kernel.cpus[0];
38#endif
39}
40
41#ifdef CONFIG_RISCV_CURRENT_VIA_GP
42
43register struct k_thread *__arch_current_thread __asm__("gp");
44
45#define arch_current_thread() __arch_current_thread
46#define arch_current_thread_set(thread) ({ __arch_current_thread = (thread); })
47
48#endif /* CONFIG_RISCV_CURRENT_VIA_GP */
49
50static ALWAYS_INLINE unsigned int arch_num_cpus(void)
51{
52 return CONFIG_MP_MAX_NUM_CPUS;
53}
54
55#endif /* !_ASMLANGUAGE */
56#endif /* ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_INLINES_H_ */
static ALWAYS_INLINE _cpu_t * arch_curr_cpu(void)
Definition arch_inlines.h:18
#define csr_read(csr)
Definition csr.h:210
#define ALWAYS_INLINE
Definition common.h:161
static ALWAYS_INLINE unsigned int arch_num_cpus(void)
Definition arch_inlines.h:12
static ALWAYS_INLINE uint32_t arch_proc_id(void)
Definition arch_inlines.h:15
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
Thread Structure.
Definition thread.h:259