From: Bibo Mao <maobibo@loongson.cn>
To: Song Gao <gaosong@loongson.cn>
Cc: qemu-devel@nongnu.org, philmd@linaro.org, jiaxun.yang@flygoat.com
Subject: Re: [PATCH v6 05/11] target/loongarch: add msg interrupt CSR registers
Date: Fri, 5 Sep 2025 16:55:36 +0800	[thread overview]
Message-ID: <2495fcdb-2f8c-bc80-028f-8977d804eba3@loongson.cn> (raw)
In-Reply-To: <20250904121840.2023683-6-gaosong@loongson.cn>
On 2025/9/4 下午8:18, Song Gao wrote:
> include CSR_MSGIS0-3, CSR_MSGIR and CSR_MSGIE.
> 
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> ---
>   target/loongarch/cpu-csr.h |  3 +++
>   target/loongarch/cpu.h     | 11 +++++++++++
>   target/loongarch/machine.c | 27 +++++++++++++++++++++++++--
>   3 files changed, 39 insertions(+), 2 deletions(-)
> 
> diff --git a/target/loongarch/cpu-csr.h b/target/loongarch/cpu-csr.h
> index 0834e91f30..4792677086 100644
> --- a/target/loongarch/cpu-csr.h
> +++ b/target/loongarch/cpu-csr.h
> @@ -186,6 +186,9 @@ FIELD(CSR_MERRCTL, ISMERR, 0, 1)
>   
>   #define LOONGARCH_CSR_CTAG           0x98 /* TagLo + TagHi */
>   
> +#define LOONGARCH_CSR_MSGIS(N)       (0xa0 + N)
> +#define LOONGARCH_CSR_MSGIR               0xa4
> +
>   /* Direct map windows CSRs*/
>   #define LOONGARCH_CSR_DMW(N)         (0x180 + N)
>   FIELD(CSR_DMW, PLV0, 0, 1)
> diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
> index 56fc4a1459..f083c31bb4 100644
> --- a/target/loongarch/cpu.h
> +++ b/target/loongarch/cpu.h
> @@ -233,6 +233,13 @@ FIELD(TLB_MISC, ASID, 1, 10)
>   FIELD(TLB_MISC, VPPN, 13, 35)
>   FIELD(TLB_MISC, PS, 48, 6)
>   
> +/*Msg interrupt registers */
> +#define N_MSGIS                4
> +FIELD(CSR_MSGIS, IS, 0, 63)
> +FIELD(CSR_MSGIR, INTNUM, 0, 8)
> +FIELD(CSR_MSGIR, ACTIVE, 31, 1)
> +FIELD(CSR_MSGIE, PT, 0, 8)
> +
>   #define LSX_LEN    (128)
>   #define LASX_LEN   (256)
>   
> @@ -350,6 +357,10 @@ typedef struct CPUArchState {
>       uint64_t CSR_DBG;
>       uint64_t CSR_DERA;
>       uint64_t CSR_DSAVE;
> +    /* Msg interrupt registers */
> +    uint64_t CSR_MSGIS[N_MSGIS];
> +    uint64_t CSR_MSGIR;
> +    uint64_t CSR_MSGIE;
>       struct {
>           uint64_t guest_addr;
>       } stealtime;
> diff --git a/target/loongarch/machine.c b/target/loongarch/machine.c
> index 4e70f5c879..996fbeb501 100644
> --- a/target/loongarch/machine.c
> +++ b/target/loongarch/machine.c
> @@ -10,6 +10,7 @@
>   #include "migration/cpu.h"
>   #include "system/tcg.h"
>   #include "vec.h"
> +#include "hw/loongarch/virt.h"
>   
>   static const VMStateDescription vmstate_fpu_reg = {
>       .name = "fpu_reg",
> @@ -45,6 +46,27 @@ static const VMStateDescription vmstate_fpu = {
>       },
>   };
>   
> +static bool msg_needed(void *opaque)
> +{
> +    MachineState *ms = MACHINE(qdev_get_machine());
The avec CSR registers CSR_MSGIR etc is part of CPU, I just think
it will be better to check avec CPU feature rather than board feature.
> +    LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(ms);
> +
> +    return virt_has_avecintc(lvms);
It supposes that LoongArch CPU must be together with virt machine :)
> +}
> +
> +static const VMStateDescription vmstate_msg = {
how about rename it as vmstate_avec?  the same with msg_needed.
Regards
Bibo Mao
> +    .name = "cpu/msg",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .needed = msg_needed,
> +    .fields = (const VMStateField[]) {
> +        VMSTATE_UINT64_ARRAY(env.CSR_MSGIS, LoongArchCPU, N_MSGIS),
> +        VMSTATE_UINT64(env.CSR_MSGIR, LoongArchCPU),
> +        VMSTATE_UINT64(env.CSR_MSGIE, LoongArchCPU),
> +        VMSTATE_END_OF_LIST()
> +    },
> +};
> +
>   static const VMStateDescription vmstate_lsxh_reg = {
>       .name = "lsxh_reg",
>       .version_id = 1,
> @@ -168,8 +190,8 @@ static const VMStateDescription vmstate_tlb = {
>   /* LoongArch CPU state */
>   const VMStateDescription vmstate_loongarch_cpu = {
>       .name = "cpu",
> -    .version_id = 3,
> -    .minimum_version_id = 3,
> +    .version_id = 4,
> +    .minimum_version_id = 4,
>       .fields = (const VMStateField[]) {
>           VMSTATE_UINTTL_ARRAY(env.gpr, LoongArchCPU, 32),
>           VMSTATE_UINTTL(env.pc, LoongArchCPU),
> @@ -245,6 +267,7 @@ const VMStateDescription vmstate_loongarch_cpu = {
>           &vmstate_tlb,
>   #endif
>           &vmstate_lbt,
> +        &vmstate_msg,
>           NULL
>       }
>   };
> 
next prev parent reply	other threads:[~2025-09-05  8:59 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-04 12:18 [PATCH v6 00/11] hw/loongarch: add the advanced extended interrupt controllers (AVECINTC) support Song Gao
2025-09-04 12:18 ` [PATCH v6 01/11] target/loongarch: move some machine define to virt.h Song Gao
2025-09-04 12:18 ` [PATCH v6 02/11] hw/loongarch: add virt feature avecintc support Song Gao
2025-09-05  8:35   ` Bibo Mao
2025-09-04 12:18 ` [PATCH v6 03/11] hw/loongarch: add misc register supoort avecintc Song Gao
2025-09-05  8:40   ` Bibo Mao
2025-09-06  1:42     ` gaosong
2025-09-04 12:18 ` [PATCH v6 04/11] loongarch: add a advance interrupt controller device Song Gao
2025-09-05  8:44   ` Bibo Mao
2025-09-04 12:18 ` [PATCH v6 05/11] target/loongarch: add msg interrupt CSR registers Song Gao
2025-09-05  8:55   ` Bibo Mao [this message]
2025-09-06  2:22     ` gaosong
2025-09-04 12:18 ` [PATCH v6 06/11] hw/loongarch: AVEC controller add a MemoryRegion Song Gao
2025-09-05  8:58   ` Bibo Mao
2025-09-04 12:18 ` [PATCH v6 07/11] hw/loongarch: Implement avec controller imput and output pins Song Gao
2025-09-05  9:15   ` Bibo Mao
2025-09-04 12:18 ` [PATCH v6 08/11] hw/loongarch: Implement avec set irq Song Gao
2025-09-05  9:52   ` Bibo Mao
2025-09-06  8:26     ` gaosong
2025-09-05 10:05   ` Bibo Mao
2025-09-06  7:13     ` Bibo Mao
2025-09-06  8:33       ` gaosong
2025-09-04 12:18 ` [PATCH v6 09/11] target/loongarch: Add CSR_ESTAT.bit15 and CSR_ECFG.bit15 for msg interrupts Song Gao
2025-09-06  7:18   ` Bibo Mao
2025-09-04 12:18 ` [PATCH v6 10/11] target/loongarch:Implement csrrd CSR_MSGIR register Song Gao
2025-09-06  7:20   ` Bibo Mao
2025-09-04 12:18 ` [PATCH v6 11/11] hw/loongarch: Implement AVEC plug/unplug interfaces Song Gao
2025-09-06  7:22   ` Bibo Mao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox
  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):
  git send-email \
    --in-reply-to=2495fcdb-2f8c-bc80-028f-8977d804eba3@loongson.cn \
    --to=maobibo@loongson.cn \
    --cc=gaosong@loongson.cn \
    --cc=jiaxun.yang@flygoat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY
  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
  Be sure your reply has a Subject: header at the top and a blank line
  before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).