diff mbox

[RFC,v3,06/21] target-arm: Prepare model-specific class_init function

Message ID 1328237992-14953-7-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber Feb. 3, 2012, 2:59 a.m. UTC
This allows to share initialization between CPU models.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 target-arm/cpu.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

Comments

Anthony Liguori Feb. 6, 2012, 11:03 p.m. UTC | #1
On 02/02/2012 08:59 PM, Andreas Färber wrote:
> This allows to share initialization between CPU models.
>
> Signed-off-by: Andreas Färber<afaerber@suse.de>
> ---
>   target-arm/cpu.c |    5 +++++
>   1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/target-arm/cpu.c b/target-arm/cpu.c
> index 43231c9..b794ec1 100644
> --- a/target-arm/cpu.c
> +++ b/target-arm/cpu.c
> @@ -96,6 +96,7 @@ static void arm_cpu_reset(CPU *c)
>   typedef struct ARMCPUInfo {
>       const char *name;
>       uint32_t id;
> +    void (*class_init)(ARMCPUClass *klass, const struct ARMCPUInfo *info);
>   } ARMCPUInfo;

So could you do:

TypeInfo arm_cpus[] = {
    {
	.name = "arm-cpu-model",
         .parent = TYPE_ARM_CPU,
         .class_data = (void *)(intptr_t)0x2342342,
         .class_init = arm_generic_init,
    }

It's roughly the same code but then there isn't redirection.  You can do this in 
general by having something like:

.class_data = (SpecialInfo[]){ .id = 0x23423423 },

Regards,

Anthony Liguori

>
>   static const ARMCPUInfo arm_cpus[] = {
> @@ -230,6 +231,10 @@ static void arm_cpu_class_init(ObjectClass *klass, void *data)
>       cpu_class->reset = arm_cpu_reset;
>
>       k->cp15.c0_cpuid = info->id;
> +
> +    if (info->class_init != NULL) {
> +        (*info->class_init)(k, info);
> +    }
>   }
>
>   static void cpu_register(const ARMCPUInfo *info)
Andreas Färber Feb. 6, 2012, 11:08 p.m. UTC | #2
Am 07.02.2012 00:03, schrieb Anthony Liguori:
> On 02/02/2012 08:59 PM, Andreas Färber wrote:
>> This allows to share initialization between CPU models.
>>
>> Signed-off-by: Andreas Färber<afaerber@suse.de>
>> ---
>>   target-arm/cpu.c |    5 +++++
>>   1 files changed, 5 insertions(+), 0 deletions(-)
>>
>> diff --git a/target-arm/cpu.c b/target-arm/cpu.c
>> index 43231c9..b794ec1 100644
>> --- a/target-arm/cpu.c
>> +++ b/target-arm/cpu.c
>> @@ -96,6 +96,7 @@ static void arm_cpu_reset(CPU *c)
>>   typedef struct ARMCPUInfo {
>>       const char *name;
>>       uint32_t id;
>> +    void (*class_init)(ARMCPUClass *klass, const struct ARMCPUInfo
>> *info);
>>   } ARMCPUInfo;
> 
> So could you do:
> 
> TypeInfo arm_cpus[] = {
>    {
>     .name = "arm-cpu-model",
>         .parent = TYPE_ARM_CPU,
>         .class_data = (void *)(intptr_t)0x2342342,
>         .class_init = arm_generic_init,
>    }
> 
> It's roughly the same code but then there isn't redirection.  You can do
> this in general by having something like:
> 
> .class_data = (SpecialInfo[]){ .id = 0x23423423 },

Have you reviewed the users of this? More fields are being added, and
the specific users of this facility initialize fields not shared by many
CPUs so I wanted to keep ARMCPUInfo small. The shared fields are already
being initialized by arm_cpu_class_init() via .class_data.

Andreas
diff mbox

Patch

diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 43231c9..b794ec1 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -96,6 +96,7 @@  static void arm_cpu_reset(CPU *c)
 typedef struct ARMCPUInfo {
     const char *name;
     uint32_t id;
+    void (*class_init)(ARMCPUClass *klass, const struct ARMCPUInfo *info);
 } ARMCPUInfo;
 
 static const ARMCPUInfo arm_cpus[] = {
@@ -230,6 +231,10 @@  static void arm_cpu_class_init(ObjectClass *klass, void *data)
     cpu_class->reset = arm_cpu_reset;
 
     k->cp15.c0_cpuid = info->id;
+
+    if (info->class_init != NULL) {
+        (*info->class_init)(k, info);
+    }
 }
 
 static void cpu_register(const ARMCPUInfo *info)