From patchwork Tue Dec 18 20:04:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 207206 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7B9332C0089 for ; Wed, 19 Dec 2012 08:01:23 +1100 (EST) Received: from localhost ([::1]:33286 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tl3OS-0007jn-On for incoming@patchwork.ozlabs.org; Tue, 18 Dec 2012 15:04:00 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tl3NL-0005HK-Kl for qemu-devel@nongnu.org; Tue, 18 Dec 2012 15:02:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tl3NH-0000d5-94 for qemu-devel@nongnu.org; Tue, 18 Dec 2012 15:02:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13260) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tl3NH-0000c9-0o for qemu-devel@nongnu.org; Tue, 18 Dec 2012 15:02:47 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBIK2kJr020294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 18 Dec 2012 15:02:46 -0500 Received: from blackpad.lan.raisama.net (vpn1-6-125.gru2.redhat.com [10.97.6.125]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBIK2jMJ024306 for ; Tue, 18 Dec 2012 15:02:46 -0500 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id D453E2036FA; Tue, 18 Dec 2012 18:04:18 -0200 (BRST) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Tue, 18 Dec 2012 18:04:03 -0200 Message-Id: <1355861053-11460-11-git-send-email-ehabkost@redhat.com> In-Reply-To: <1355861053-11460-1-git-send-email-ehabkost@redhat.com> References: <1355861053-11460-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 10/20] cpu: introduce generic_cpu_init() & generic_cpu_create() functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Useful for architectures where cpu_init() is just creation of a CPU object and a call to cpu_realize(). All the functions should need is the base CPU class name and cpu_model string. Any target-specific behavior/information can later be provided by the target-specific CPU class, if necessary. Signed-off-by: Eduardo Habkost --- include/qemu/cpu.h | 24 ++++++++++++++++++++++++ qom/cpu.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h index 90bb27d..7461319 100644 --- a/include/qemu/cpu.h +++ b/include/qemu/cpu.h @@ -151,4 +151,28 @@ bool cpu_is_stopped(CPUState *cpu); void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); +/* generic_cpu_create: + * @base_class_name: The name of the base CPU class + * @cpu_model: full CPU model string to be parsed + * @errp: pointer to Error pointer, where error information can be returned + * + * Generic target-independent function to create a CPU object. Caller + * should call cpu_realize() later. + * + * Any target-specific behavior can be set as CPUClass fields in the base class. + */ +CPUState *generic_cpu_create(const char *base_class_name, + const char *cpu_model, + Error **errp); + +/* generic_cpu_init: + * @base_class_name: The name of the base CPU class + * @cpu_model: full CPU model string to be parsed + * + * Generic target-independent cpu_init implementation. Any target-specific + * behavior can be set as CPUClass fields in the base class. + */ +CPUState *generic_cpu_init(const char *base_class_name, const char *cpu_model); + + #endif diff --git a/qom/cpu.c b/qom/cpu.c index a96f6ee..42cbe42 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -19,6 +19,7 @@ */ #include "qemu/cpu.h" +#include "qemu-error.h" #include "qemu-common.h" void cpu_reset(CPUState *cpu) @@ -65,4 +66,41 @@ static void cpu_register_types(void) type_register_static(&cpu_type_info); } +CPUState *generic_cpu_create(const char *base_class_name, + const char *cpu_model, + Error **errp) +{ + CPUState *cpu; + + if (!object_class_by_name(cpu_model)) { + error_setg(errp, "Can't find CPU class for model: %s", cpu_model); + return NULL; + } + + cpu = CPU(object_new(cpu_model)); + cpu->cpu_model_str = cpu_model; + return cpu; +} + +CPUState *generic_cpu_init(const char *base_class_name, const char *cpu_model) +{ + CPUState *cpu; + Error *err = NULL; + + cpu = generic_cpu_create(base_class_name, cpu_model, &err); + if (err) { + goto error; + } + + cpu_realize(cpu, &err); + if (err) { + goto error; + } + + return cpu; +error: + error_report("cpu_init: %s", error_get_pretty(err)); + return NULL; +} + type_init(cpu_register_types)