xref: /qemu/include/accel/tcg/cpu-mmu-index.h (revision cc944932ecef3b7a56ae62d89dd92fb9e56c5cc8)
1 /*
2  * cpu_mmu_index()
3  *
4  *  Copyright (c) 2003 Fabrice Bellard
5  *
6  * SPDX-License-Identifier: LGPL-2.1-or-later
7  */
8 
9 #ifndef ACCEL_TCG_CPU_MMU_INDEX_H
10 #define ACCEL_TCG_CPU_MMU_INDEX_H
11 
12 #include "hw/core/cpu.h"
13 #include "accel/tcg/cpu-ops.h"
14 #include "tcg/debug-assert.h"
15 #ifdef COMPILING_PER_TARGET
16 # ifdef CONFIG_USER_ONLY
17 #  include "cpu.h"
18 # endif
19 #endif
20 
21 /**
22  * cpu_mmu_index:
23  * @env: The cpu environment
24  * @ifetch: True for code access, false for data access.
25  *
26  * Return the core mmu index for the current translation regime.
27  * This function is used by generic TCG code paths.
28  */
29 static inline int cpu_mmu_index(CPUState *cs, bool ifetch)
30 {
31 #ifdef COMPILING_PER_TARGET
32 # ifdef CONFIG_USER_ONLY
33     return MMU_USER_IDX;
34 # endif
35 #endif
36 
37     const TCGCPUOps *tcg_ops = cs->cc->tcg_ops;
38     int ret = tcg_ops->mmu_index ? tcg_ops->mmu_index(cs, ifetch)
39                                  : cs->cc->mmu_index(cs, ifetch);
40     tcg_debug_assert(ret >= 0 && ret < NB_MMU_MODES);
41     return ret;
42 }
43 
44 #endif /* ACCEL_TCG_CPU_MMU_INDEX_H */
45