1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (c) 2021 Loongson Technology Corporation Limited
4  *
5  * Helpers for IOCSR reads/writes
6  */
7 
8 #include "qemu/osdep.h"
9 #include "cpu.h"
10 #include "qemu/host-utils.h"
11 #include "exec/helper-proto.h"
12 #include "exec/exec-all.h"
13 #include "exec/cpu_ldst.h"
14 
15 #define GET_MEMTXATTRS(cas) \
16         ((MemTxAttrs){.requester_id = env_cpu(cas)->cpu_index})
17 
18 uint64_t helper_iocsrrd_b(CPULoongArchState *env, target_ulong r_addr)
19 {
20     return address_space_ldub(env->address_space_iocsr, r_addr,
21                               GET_MEMTXATTRS(env), NULL);
22 }
23 
24 uint64_t helper_iocsrrd_h(CPULoongArchState *env, target_ulong r_addr)
25 {
26     return address_space_lduw(env->address_space_iocsr, r_addr,
27                               GET_MEMTXATTRS(env), NULL);
28 }
29 
30 uint64_t helper_iocsrrd_w(CPULoongArchState *env, target_ulong r_addr)
31 {
32     return address_space_ldl(env->address_space_iocsr, r_addr,
33                              GET_MEMTXATTRS(env), NULL);
34 }
35 
36 uint64_t helper_iocsrrd_d(CPULoongArchState *env, target_ulong r_addr)
37 {
38     return address_space_ldq(env->address_space_iocsr, r_addr,
39                              GET_MEMTXATTRS(env), NULL);
40 }
41 
42 void helper_iocsrwr_b(CPULoongArchState *env, target_ulong w_addr,
43                       target_ulong val)
44 {
45     address_space_stb(env->address_space_iocsr, w_addr,
46                       val, GET_MEMTXATTRS(env), NULL);
47 }
48 
49 void helper_iocsrwr_h(CPULoongArchState *env, target_ulong w_addr,
50                       target_ulong val)
51 {
52     address_space_stw(env->address_space_iocsr, w_addr,
53                       val, GET_MEMTXATTRS(env), NULL);
54 }
55 
56 void helper_iocsrwr_w(CPULoongArchState *env, target_ulong w_addr,
57                       target_ulong val)
58 {
59     address_space_stl(env->address_space_iocsr, w_addr,
60                       val, GET_MEMTXATTRS(env), NULL);
61 }
62 
63 void helper_iocsrwr_d(CPULoongArchState *env, target_ulong w_addr,
64                       target_ulong val)
65 {
66     address_space_stq(env->address_space_iocsr, w_addr,
67                       val, GET_MEMTXATTRS(env), NULL);
68 }
69