diff mbox series

[v3,02/18] target/loongarch: Add new object class for loongarch32 cpus

Message ID 20230817093121.1053890-3-gaosong@loongson.cn (mailing list archive)
State New, archived
Headers show
Series Add some checks before translating instructions | expand

Commit Message

Song Gao Aug. 17, 2023, 9:31 a.m. UTC
From: Jiajie Chen <c@jia.je>

Add object class for future loongarch32 cpus. It is derived from the
loongarch64 object class.

Signed-off-by: Jiajie Chen <c@jia.je>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 target/loongarch/cpu.c | 19 +++++++++++++++++++
 target/loongarch/cpu.h |  1 +
 2 files changed, 20 insertions(+)

Comments

Philippe Mathieu-Daudé Aug. 18, 2023, 8:51 a.m. UTC | #1
Hi Jiajie, Song,

(+Huacai)

On 17/8/23 11:31, Song Gao wrote:
> From: Jiajie Chen <c@jia.je>
> 
> Add object class for future loongarch32 cpus. It is derived from the
> loongarch64 object class.

Is it how the architecture design happened? IIUC per [*] it seems
the arch was designed as a whole then adapted per segment (32/R,64).
So from a QOM PoV better would be to have a abstract 'common' parent
objs/classes, then derive 32/64 from it.
IMHO this matters for the maintainability of target/loongarch/, but
if this isn't important then I won't object much to this series.

Regards,

Phil.

[*] 
https://lore.kernel.org/linux-arch/20210706041820.1536502-1-chenhuacai@loongson.cn/

> Signed-off-by: Jiajie Chen <c@jia.je>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> ---
>   target/loongarch/cpu.c | 19 +++++++++++++++++++
>   target/loongarch/cpu.h |  1 +
>   2 files changed, 20 insertions(+)


> @@ -750,6 +760,15 @@ static const TypeInfo loongarch_cpu_type_infos[] = {
>           .class_size = sizeof(LoongArchCPUClass),
>           .class_init = loongarch_cpu_class_init,
>       },
> +    {
> +        .name = TYPE_LOONGARCH32_CPU,
> +        .parent = TYPE_LOONGARCH_CPU,
> +        .instance_size = sizeof(LoongArchCPU),
> +
> +        .abstract = true,
> +        .class_size = sizeof(LoongArchCPUClass),
> +        .class_init = loongarch32_cpu_class_init,
> +    },
>       DEFINE_LOONGARCH_CPU_TYPE("la464", loongarch_la464_initfn),
>   };
>   
> diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
> index 5a71d64a04..2af4c414b0 100644
> --- a/target/loongarch/cpu.h
> +++ b/target/loongarch/cpu.h
> @@ -382,6 +382,7 @@ struct ArchCPU {
>   };
>   
>   #define TYPE_LOONGARCH_CPU "loongarch-cpu"
> +#define TYPE_LOONGARCH32_CPU "loongarch32-cpu"
>   
>   OBJECT_DECLARE_CPU_TYPE(LoongArchCPU, LoongArchCPUClass,
>                           LOONGARCH_CPU)
chen huacai Aug. 18, 2023, 8:56 a.m. UTC | #2
Hi, Philippe,

On Fri, Aug 18, 2023 at 4:52 PM Philippe Mathieu-Daudé
<philmd@linaro.org> wrote:
>
> Hi Jiajie, Song,
>
> (+Huacai)
>
> On 17/8/23 11:31, Song Gao wrote:
> > From: Jiajie Chen <c@jia.je>
> >
> > Add object class for future loongarch32 cpus. It is derived from the
> > loongarch64 object class.
>
> Is it how the architecture design happened? IIUC per [*] it seems
> the arch was designed as a whole then adapted per segment (32/R,64).
> So from a QOM PoV better would be to have a abstract 'common' parent
> objs/classes, then derive 32/64 from it.
> IMHO this matters for the maintainability of target/loongarch/, but
> if this isn't important then I won't object much to this series.
From my point of view, it is more natural to have loongarch32-cpu
together with loongarch64-cpu, not loongarch32-cpu and loongarch-cpu
(only for 64bit).

Huacai
>
> Regards,
>
> Phil.
>
> [*]
> https://lore.kernel.org/linux-arch/20210706041820.1536502-1-chenhuacai@loongson.cn/
>
> > Signed-off-by: Jiajie Chen <c@jia.je>
> > Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> > Signed-off-by: Song Gao <gaosong@loongson.cn>
> > ---
> >   target/loongarch/cpu.c | 19 +++++++++++++++++++
> >   target/loongarch/cpu.h |  1 +
> >   2 files changed, 20 insertions(+)
>
>
> > @@ -750,6 +760,15 @@ static const TypeInfo loongarch_cpu_type_infos[] = {
> >           .class_size = sizeof(LoongArchCPUClass),
> >           .class_init = loongarch_cpu_class_init,
> >       },
> > +    {
> > +        .name = TYPE_LOONGARCH32_CPU,
> > +        .parent = TYPE_LOONGARCH_CPU,
> > +        .instance_size = sizeof(LoongArchCPU),
> > +
> > +        .abstract = true,
> > +        .class_size = sizeof(LoongArchCPUClass),
> > +        .class_init = loongarch32_cpu_class_init,
> > +    },
> >       DEFINE_LOONGARCH_CPU_TYPE("la464", loongarch_la464_initfn),
> >   };
> >
> > diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
> > index 5a71d64a04..2af4c414b0 100644
> > --- a/target/loongarch/cpu.h
> > +++ b/target/loongarch/cpu.h
> > @@ -382,6 +382,7 @@ struct ArchCPU {
> >   };
> >
> >   #define TYPE_LOONGARCH_CPU "loongarch-cpu"
> > +#define TYPE_LOONGARCH32_CPU "loongarch32-cpu"
> >
> >   OBJECT_DECLARE_CPU_TYPE(LoongArchCPU, LoongArchCPUClass,
> >                           LOONGARCH_CPU)
>
>
diff mbox series

Patch

diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index ad93ecac92..c6b73444b4 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -732,12 +732,22 @@  static void loongarch_cpu_class_init(ObjectClass *c, void *data)
 #endif
 }
 
+static void loongarch32_cpu_class_init(ObjectClass *c, void *data)
+{
+}
+
 #define DEFINE_LOONGARCH_CPU_TYPE(model, initfn) \
     { \
         .parent = TYPE_LOONGARCH_CPU, \
         .instance_init = initfn, \
         .name = LOONGARCH_CPU_TYPE_NAME(model), \
     }
+#define DEFINE_LOONGARCH32_CPU_TYPE(model, initfn) \
+    { \
+        .parent = TYPE_LOONGARCH32_CPU, \
+        .instance_init = initfn, \
+        .name = LOONGARCH_CPU_TYPE_NAME(model), \
+    }
 
 static const TypeInfo loongarch_cpu_type_infos[] = {
     {
@@ -750,6 +760,15 @@  static const TypeInfo loongarch_cpu_type_infos[] = {
         .class_size = sizeof(LoongArchCPUClass),
         .class_init = loongarch_cpu_class_init,
     },
+    {
+        .name = TYPE_LOONGARCH32_CPU,
+        .parent = TYPE_LOONGARCH_CPU,
+        .instance_size = sizeof(LoongArchCPU),
+
+        .abstract = true,
+        .class_size = sizeof(LoongArchCPUClass),
+        .class_init = loongarch32_cpu_class_init,
+    },
     DEFINE_LOONGARCH_CPU_TYPE("la464", loongarch_la464_initfn),
 };
 
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index 5a71d64a04..2af4c414b0 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -382,6 +382,7 @@  struct ArchCPU {
 };
 
 #define TYPE_LOONGARCH_CPU "loongarch-cpu"
+#define TYPE_LOONGARCH32_CPU "loongarch32-cpu"
 
 OBJECT_DECLARE_CPU_TYPE(LoongArchCPU, LoongArchCPUClass,
                         LOONGARCH_CPU)