15c23704eSSong Gao /* SPDX-License-Identifier: GPL-2.0-or-later */
25c23704eSSong Gao /*
35c23704eSSong Gao  * Copyright (c) 2021 Loongson Technology Corporation Limited
45c23704eSSong Gao  *
55c23704eSSong Gao  * Helpers for IOCSR reads/writes
65c23704eSSong Gao  */
75c23704eSSong Gao 
85c23704eSSong Gao #include "qemu/osdep.h"
95c23704eSSong Gao #include "cpu.h"
105c23704eSSong Gao #include "qemu/host-utils.h"
115c23704eSSong Gao #include "exec/helper-proto.h"
125c23704eSSong Gao #include "exec/exec-all.h"
135c23704eSSong Gao #include "exec/cpu_ldst.h"
145c23704eSSong Gao 
155c23704eSSong Gao #define GET_MEMTXATTRS(cas) \
165c23704eSSong Gao         ((MemTxAttrs){.requester_id = env_cpu(cas)->cpu_index})
175c23704eSSong Gao 
helper_iocsrrd_b(CPULoongArchState * env,target_ulong r_addr)185c23704eSSong Gao uint64_t helper_iocsrrd_b(CPULoongArchState *env, target_ulong r_addr)
195c23704eSSong Gao {
20*5e90b8dbSBibo Mao     return address_space_ldub(env->address_space_iocsr, r_addr,
215c23704eSSong Gao                               GET_MEMTXATTRS(env), NULL);
225c23704eSSong Gao }
235c23704eSSong Gao 
helper_iocsrrd_h(CPULoongArchState * env,target_ulong r_addr)245c23704eSSong Gao uint64_t helper_iocsrrd_h(CPULoongArchState *env, target_ulong r_addr)
255c23704eSSong Gao {
26*5e90b8dbSBibo Mao     return address_space_lduw(env->address_space_iocsr, r_addr,
275c23704eSSong Gao                               GET_MEMTXATTRS(env), NULL);
285c23704eSSong Gao }
295c23704eSSong Gao 
helper_iocsrrd_w(CPULoongArchState * env,target_ulong r_addr)305c23704eSSong Gao uint64_t helper_iocsrrd_w(CPULoongArchState *env, target_ulong r_addr)
315c23704eSSong Gao {
32*5e90b8dbSBibo Mao     return address_space_ldl(env->address_space_iocsr, r_addr,
335c23704eSSong Gao                              GET_MEMTXATTRS(env), NULL);
345c23704eSSong Gao }
355c23704eSSong Gao 
helper_iocsrrd_d(CPULoongArchState * env,target_ulong r_addr)365c23704eSSong Gao uint64_t helper_iocsrrd_d(CPULoongArchState *env, target_ulong r_addr)
375c23704eSSong Gao {
38*5e90b8dbSBibo Mao     return address_space_ldq(env->address_space_iocsr, r_addr,
395c23704eSSong Gao                              GET_MEMTXATTRS(env), NULL);
405c23704eSSong Gao }
415c23704eSSong Gao 
helper_iocsrwr_b(CPULoongArchState * env,target_ulong w_addr,target_ulong val)425c23704eSSong Gao void helper_iocsrwr_b(CPULoongArchState *env, target_ulong w_addr,
435c23704eSSong Gao                       target_ulong val)
445c23704eSSong Gao {
45*5e90b8dbSBibo Mao     address_space_stb(env->address_space_iocsr, w_addr,
465c23704eSSong Gao                       val, GET_MEMTXATTRS(env), NULL);
475c23704eSSong Gao }
485c23704eSSong Gao 
helper_iocsrwr_h(CPULoongArchState * env,target_ulong w_addr,target_ulong val)495c23704eSSong Gao void helper_iocsrwr_h(CPULoongArchState *env, target_ulong w_addr,
505c23704eSSong Gao                       target_ulong val)
515c23704eSSong Gao {
52*5e90b8dbSBibo Mao     address_space_stw(env->address_space_iocsr, w_addr,
535c23704eSSong Gao                       val, GET_MEMTXATTRS(env), NULL);
545c23704eSSong Gao }
555c23704eSSong Gao 
helper_iocsrwr_w(CPULoongArchState * env,target_ulong w_addr,target_ulong val)565c23704eSSong Gao void helper_iocsrwr_w(CPULoongArchState *env, target_ulong w_addr,
575c23704eSSong Gao                       target_ulong val)
585c23704eSSong Gao {
59*5e90b8dbSBibo Mao     address_space_stl(env->address_space_iocsr, w_addr,
605c23704eSSong Gao                       val, GET_MEMTXATTRS(env), NULL);
615c23704eSSong Gao }
625c23704eSSong Gao 
helper_iocsrwr_d(CPULoongArchState * env,target_ulong w_addr,target_ulong val)635c23704eSSong Gao void helper_iocsrwr_d(CPULoongArchState *env, target_ulong w_addr,
645c23704eSSong Gao                       target_ulong val)
655c23704eSSong Gao {
66*5e90b8dbSBibo Mao     address_space_stq(env->address_space_iocsr, w_addr,
675c23704eSSong Gao                       val, GET_MEMTXATTRS(env), NULL);
685c23704eSSong Gao }
69