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 
12 #include <zephyr/kernel_structs.h>
13 #include "csr.h"
14 
arch_proc_id(void)15 static ALWAYS_INLINE uint32_t arch_proc_id(void)
16 {
17 	return csr_read(mhartid);
18 }
19 
arch_curr_cpu(void)20 static ALWAYS_INLINE _cpu_t *arch_curr_cpu(void)
21 {
22 #if defined(CONFIG_SMP) || defined(CONFIG_USERSPACE)
23 	return (_cpu_t *)csr_read(mscratch);
24 #else
25 	return &_kernel.cpus[0];
26 #endif
27 }
28 
arch_num_cpus(void)29 static ALWAYS_INLINE unsigned int arch_num_cpus(void)
30 {
31 	return CONFIG_MP_MAX_NUM_CPUS;
32 }
33 
34 #endif /* !_ASMLANGUAGE */
35 #endif /* ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_INLINES_H_ */
36