| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* |
| 3 | * Copyright (c) 2025 Loongson Technology Corporation Limited |
| 4 | */ |
| 5 | |
| 6 | #ifndef TARGET_LOONGARCH_CSR_H |
| 7 | #define TARGET_LOONGARCH_CSR_H |
| 8 | |
| 9 | #include "cpu-csr.h" |
| 10 | |
| 11 | #define CSR_OFFSET(id) offsetof(CPUSysState, id) |
| 12 | #define CPU_CSR_OFFSET(id, vm_level) \ |
| 13 | (offsetof(CPULoongArchState, sys_states[vm_level]) \ |
| 14 | + CSR_OFFSET(id)) |
| 15 | |
| 16 | typedef void (*GenCSRFunc)(void); |
| 17 | enum { |
| 18 | CSRFL_READONLY = (1 << 0), |
| 19 | CSRFL_EXITTB = (1 << 1), |
| 20 | CSRFL_IO = (1 << 2), |
| 21 | CSRFL_UNUSED = (1 << 3), |
| 22 | CSRFL_BASIC = (1 << 4), |
| 23 | }; |
| 24 | |
| 25 | typedef struct { |
| 26 | const char *name; |
| 27 | int offset; |
| 28 | int flags; |
| 29 | GenCSRFunc readfn; |
| 30 | GenCSRFunc writefn; |
| 31 | } CSRInfo; |
| 32 | |
| 33 | CSRInfo *get_csr(unsigned int csr_num); |
| 34 | bool set_csr_flag(unsigned int csr_num, int flag); |
| 35 | static inline unsigned int get_csr_offset(const CSRInfo *csr, int vm_level) |
| 36 | { |
| 37 | return csr->offset + offsetof(CPULoongArchState, sys_states[vm_level]); |
| 38 | } |
| 39 | #endif /* TARGET_LOONGARCH_CSR_H */ |