1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the GNU General Public License version 2. Note that NO WARRANTY is provided.
8 * See "LICENSE_GPLv2.txt" for details.
9 *
10 * @TAG(DATA61_GPL)
11 */
12
13#ifndef __ARCH_MODEL_SMP_H_
14#define __ARCH_MODEL_SMP_H_
15
16#include <config.h>
17#include <arch/types.h>
18#include <arch/model/statedata.h>
19#include <model/statedata.h>
20#include <model/smp.h>
21#include <mode/model/smp.h>
22
23#ifdef ENABLE_SMP_SUPPORT
24
25typedef struct cpu_id_mapping {
26    cpu_id_t index_to_cpu_id[CONFIG_MAX_NUM_NODES];
27
28#ifdef CONFIG_USE_LOGICAL_IDS
29    logical_id_t index_to_logical_id[CONFIG_MAX_NUM_NODES];
30    word_t other_indexes_in_cluster[CONFIG_MAX_NUM_NODES];
31#endif /* CONFIG_USE_LOGICAL_IDS */
32} cpu_id_mapping_t;
33
34extern cpu_id_mapping_t cpu_mapping;
35
36static inline cpu_id_t cpuIndexToID(word_t index)
37{
38    return cpu_mapping.index_to_cpu_id[index];
39}
40
41static inline PURE word_t getCurrentCPUID(void)
42{
43    return cpu_mapping.index_to_cpu_id[getCurrentCPUIndex()];
44}
45
46static inline bool_t
47try_arch_atomic_exchange(void *ptr, void *new_val, void **prev, int success_memorder, int failure_memorder)
48{
49    *prev = __atomic_exchange_n((void **) ptr, new_val, success_memorder);
50    return true;
51}
52
53#endif /* ENABLE_SMP_SUPPORT */
54#endif /* __ARCH_MODEL_SMP_H_ */
55