1 /*
2  * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3  *
4  * SPDX-License-Identifier: GPL-2.0-only
5  */
6 
7 #pragma once
8 
9 #include <config.h>
10 #include <arch/types.h>
11 #include <arch/model/statedata.h>
12 #include <model/statedata.h>
13 #include <model/smp.h>
14 #include <mode/model/smp.h>
15 
16 #ifdef ENABLE_SMP_SUPPORT
17 
18 typedef struct cpu_id_mapping {
19     cpu_id_t index_to_cpu_id[CONFIG_MAX_NUM_NODES];
20 
21 #ifdef CONFIG_USE_LOGICAL_IDS
22     logical_id_t index_to_logical_id[CONFIG_MAX_NUM_NODES];
23     word_t other_indexes_in_cluster[CONFIG_MAX_NUM_NODES];
24 #endif /* CONFIG_USE_LOGICAL_IDS */
25 } cpu_id_mapping_t;
26 
27 extern cpu_id_mapping_t cpu_mapping;
28 
cpuIndexToID(word_t index)29 static inline cpu_id_t cpuIndexToID(word_t index)
30 {
31     return cpu_mapping.index_to_cpu_id[index];
32 }
33 
getCurrentCPUID(void)34 static inline PURE word_t getCurrentCPUID(void)
35 {
36     return cpu_mapping.index_to_cpu_id[getCurrentCPUIndex()];
37 }
38 
try_arch_atomic_exchange_rlx(void * ptr,void * new_val,void ** prev)39 static inline bool_t try_arch_atomic_exchange_rlx(void *ptr, void *new_val, void **prev)
40 {
41     *prev = __atomic_exchange_n((void **) ptr, new_val, __ATOMIC_RELAXED);
42     return true;
43 }
44 
45 #endif /* ENABLE_SMP_SUPPORT */
46