195801d700
The Big QEMU Lock (BQL) has many names and they are confusing. The actual QemuMutex variable is called qemu_global_mutex but it's commonly referred to as the BQL in discussions and some code comments. The locking APIs, however, are called qemu_mutex_lock_iothread() and qemu_mutex_unlock_iothread(). The "iothread" name is historic and comes from when the main thread was split into into KVM vcpu threads and the "iothread" (now called the main loop thread). I have contributed to the confusion myself by introducing a separate --object iothread, a separate concept unrelated to the BQL. The "iothread" name is no longer appropriate for the BQL. Rename the locking APIs to: - void bql_lock(void) - void bql_unlock(void) - bool bql_locked(void) There are more APIs with "iothread" in their names. Subsequent patches will rename them. There are also comments and documentation that will be updated in later patches. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Paul Durrant <paul@xen.org> Acked-by: Fabiano Rosas <farosas@suse.de> Acked-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Cédric Le Goater <clg@kaod.org> Acked-by: Peter Xu <peterx@redhat.com> Acked-by: Eric Farman <farman@linux.ibm.com> Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com> Acked-by: Hyman Huang <yong.huang@smartx.com> Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> Message-id: 20240102153529.486531-2-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
98 lines
2.1 KiB
C
98 lines
2.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* LoongArch emulation helpers for CSRs
|
|
*
|
|
* Copyright (c) 2021 Loongson Technology Corporation Limited
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/main-loop.h"
|
|
#include "cpu.h"
|
|
#include "internals.h"
|
|
#include "qemu/host-utils.h"
|
|
#include "exec/helper-proto.h"
|
|
#include "exec/exec-all.h"
|
|
#include "exec/cpu_ldst.h"
|
|
#include "hw/irq.h"
|
|
#include "cpu-csr.h"
|
|
|
|
target_ulong helper_csrrd_pgd(CPULoongArchState *env)
|
|
{
|
|
int64_t v;
|
|
|
|
if (env->CSR_TLBRERA & 0x1) {
|
|
v = env->CSR_TLBRBADV;
|
|
} else {
|
|
v = env->CSR_BADV;
|
|
}
|
|
|
|
if ((v >> 63) & 0x1) {
|
|
v = env->CSR_PGDH;
|
|
} else {
|
|
v = env->CSR_PGDL;
|
|
}
|
|
|
|
return v;
|
|
}
|
|
|
|
target_ulong helper_csrrd_cpuid(CPULoongArchState *env)
|
|
{
|
|
LoongArchCPU *lac = env_archcpu(env);
|
|
|
|
env->CSR_CPUID = CPU(lac)->cpu_index;
|
|
|
|
return env->CSR_CPUID;
|
|
}
|
|
|
|
target_ulong helper_csrrd_tval(CPULoongArchState *env)
|
|
{
|
|
LoongArchCPU *cpu = env_archcpu(env);
|
|
|
|
return cpu_loongarch_get_constant_timer_ticks(cpu);
|
|
}
|
|
|
|
target_ulong helper_csrwr_estat(CPULoongArchState *env, target_ulong val)
|
|
{
|
|
int64_t old_v = env->CSR_ESTAT;
|
|
|
|
/* Only IS[1:0] can be written */
|
|
env->CSR_ESTAT = deposit64(env->CSR_ESTAT, 0, 2, val);
|
|
|
|
return old_v;
|
|
}
|
|
|
|
target_ulong helper_csrwr_asid(CPULoongArchState *env, target_ulong val)
|
|
{
|
|
int64_t old_v = env->CSR_ASID;
|
|
|
|
/* Only ASID filed of CSR_ASID can be written */
|
|
env->CSR_ASID = deposit64(env->CSR_ASID, 0, 10, val);
|
|
if (old_v != env->CSR_ASID) {
|
|
tlb_flush(env_cpu(env));
|
|
}
|
|
return old_v;
|
|
}
|
|
|
|
target_ulong helper_csrwr_tcfg(CPULoongArchState *env, target_ulong val)
|
|
{
|
|
LoongArchCPU *cpu = env_archcpu(env);
|
|
int64_t old_v = env->CSR_TCFG;
|
|
|
|
cpu_loongarch_store_constant_timer_config(cpu, val);
|
|
|
|
return old_v;
|
|
}
|
|
|
|
target_ulong helper_csrwr_ticlr(CPULoongArchState *env, target_ulong val)
|
|
{
|
|
LoongArchCPU *cpu = env_archcpu(env);
|
|
int64_t old_v = 0;
|
|
|
|
if (val & 0x1) {
|
|
bql_lock();
|
|
loongarch_cpu_set_irq(cpu, IRQ_TIMER, 0);
|
|
bql_unlock();
|
|
}
|
|
return old_v;
|
|
}
|