From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54425) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuXbB-0006jg-2b for qemu-devel@nongnu.org; Mon, 06 Feb 2012 18:03:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RuXb9-0007WT-LB for qemu-devel@nongnu.org; Mon, 06 Feb 2012 18:03:48 -0500 Received: from mail-gy0-f173.google.com ([209.85.160.173]:62740) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RuXb9-0007WI-Hr for qemu-devel@nongnu.org; Mon, 06 Feb 2012 18:03:47 -0500 Received: by ghrr20 with SMTP id r20so3585995ghr.4 for ; Mon, 06 Feb 2012 15:03:47 -0800 (PST) Message-ID: <4F305C50.9020107@codemonkey.ws> Date: Mon, 06 Feb 2012 17:03:44 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1328237992-14953-1-git-send-email-afaerber@suse.de> <1328237992-14953-7-git-send-email-afaerber@suse.de> In-Reply-To: <1328237992-14953-7-git-send-email-afaerber@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH RFC v3 06/21] target-arm: Prepare model-specific class_init function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?QW5kcmVhcyBGw6RyYmVy?= Cc: qemu-devel@nongnu.org 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 > --- > 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)