From patchwork Tue Dec 21 20:01:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 76326 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AF000B70AA for ; Wed, 22 Dec 2010 07:02:40 +1100 (EST) Received: from localhost ([127.0.0.1]:33101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PV8Pt-0004zL-O3 for incoming@patchwork.ozlabs.org; Tue, 21 Dec 2010 15:02:37 -0500 Received: from [140.186.70.92] (port=55191 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PV8Oj-0004So-Cj for qemu-devel@nongnu.org; Tue, 21 Dec 2010 15:01:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PV8Oh-00049r-48 for qemu-devel@nongnu.org; Tue, 21 Dec 2010 15:01:25 -0500 Received: from fmmailgate01.web.de ([217.72.192.221]:49114) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PV8Og-00049O-Mh for qemu-devel@nongnu.org; Tue, 21 Dec 2010 15:01:23 -0500 Received: from smtp03.web.de ( [172.20.0.65]) by fmmailgate01.web.de (Postfix) with ESMTP id 5D27318341129; Tue, 21 Dec 2010 21:01:20 +0100 (CET) Received: from [87.173.118.159] (helo=af.local) by smtp03.web.de with asmtp (WEB.DE 4.110 #2) id 1PV8Od-0006Hi-00; Tue, 21 Dec 2010 21:01:19 +0100 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Tue, 21 Dec 2010 21:01:18 +0100 Message-Id: <1292961678-1581-1-git-send-email-andreas.faerber@web.de> X-Mailer: git-send-email 1.7.3.4 MIME-Version: 1.0 X-Sender: Andreas.Faerber@web.de X-Provags-ID: V01U2FsdGVkX1+YJINozWwkjISYag5lsPTYh4ciMlMjIM0apR5g wA1Ii1rqhY/cRshIg0VAjjY0FbrPvCGrX4n3pMW8IDHLyWuL3X 6XgwQ0tRPnR8u/zBPxDg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Alexander Graf Subject: [Qemu-devel] [RFC] ppc: qdev-ify CPU creation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Hervé Poussineau v1: * Coding style fixes. Signed-off-by: Hervé Poussineau Cc: Alexander Graf Signed-off-by: Andreas Färber --- Hello Alex, Seeing the discussions about Leon3, is this the way to go for ppc? Is ppc.[hc] right? The unconditional use of 6xx looks suspicious to me, no? Should we rename cpu_device_irq_request() to cpu_device_irq_request_6xx()? Regards, Andreas hw/ppc.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc.h | 2 + target-ppc/cpu.h | 1 + target-ppc/helper.c | 21 +++++++++++--- 4 files changed, 94 insertions(+), 5 deletions(-) diff --git a/hw/ppc.c b/hw/ppc.c index 968aec1..0927326 100644 --- a/hw/ppc.c +++ b/hw/ppc.c @@ -30,6 +30,8 @@ #include "loader.h" #include "kvm.h" #include "kvm_ppc.h" +#include "hw/qdev.h" +#include "hw/sysbus.h" //#define PPC_DEBUG_IRQ //#define PPC_DEBUG_TB @@ -1286,3 +1288,76 @@ int PPC_NVRAM_set_params (nvram_t *nvram, uint16_t NVRAM_size, return 0; } + +DeviceState *cpu_ppc_create_simple(const char *cpu_model) +{ + DeviceState *dev; + + dev = qdev_create(NULL, "cpu-ppc"); + if (!dev) { + return NULL; + } + qdev_prop_set_string(dev, "model", qemu_strdup(cpu_model)); + if (qdev_init(dev) < 0) { + return NULL; + } + return dev; +} + +typedef struct CPUPPC { + SysBusDevice busdev; + char *model; + CPUPPCState state; +} CPUPPC; + +static void cpu_device_irq_request(void *opaque, int pin, int level) +{ + CPUPPC* cpu = opaque; + CPUPPCState* env = &cpu->state; + ppc6xx_set_irq(env, pin, level); +} + +static int cpu_device_init(SysBusDevice *dev) +{ + CPUPPC* cpu = FROM_SYSBUS(CPUPPC, dev); + CPUPPCState* env = &cpu->state; + + if (cpu_ppc_init_inplace(env, cpu->model) < 0) { + return -1; + } + + if (env->flags & POWERPC_FLAG_RTC_CLK) { + /* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */ + cpu_ppc_tb_init(env, 7812500UL); + } else { + /* Set time-base frequency to 100 Mhz */ + cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL); + } + + qdev_init_gpio_in(&dev->qdev, cpu_device_irq_request, PPC6xx_INPUT_NB); + return 0; +} + +static void cpu_device_reset(DeviceState *d) +{ + CPUPPC *s = FROM_SYSBUS(CPUPPC, sysbus_from_qdev(d)); + cpu_reset(&s->state); +} + +static SysBusDeviceInfo cpu_device_info = { + .qdev.name = "cpu-ppc", + .qdev.size = sizeof(CPUPPC), + .qdev.reset = cpu_device_reset, + .init = cpu_device_init, + .qdev.props = (Property[]) { + DEFINE_PROP_STRING("model", CPUPPC, model), + DEFINE_PROP_END_OF_LIST(), + }, +}; + +static void ppc_register_devices(void) +{ + sysbus_register_withprop(&cpu_device_info); +} + +device_init(ppc_register_devices) diff --git a/hw/ppc.h b/hw/ppc.h index 34f54cf..ae8dd97 100644 --- a/hw/ppc.h +++ b/hw/ppc.h @@ -37,6 +37,8 @@ void ppce500_irq_init (CPUState *env); void ppc6xx_irq_init (CPUState *env); void ppc970_irq_init (CPUState *env); +DeviceState *cpu_ppc_create_simple(const char *cpu_model); + /* PPC machines for OpenBIOS */ enum { ARCH_PREP = 0, diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h index deb8d7c..0f56d45 100644 --- a/target-ppc/cpu.h +++ b/target-ppc/cpu.h @@ -721,6 +721,7 @@ struct mmu_ctx_t { /*****************************************************************************/ CPUPPCState *cpu_ppc_init (const char *cpu_model); +int cpu_ppc_init_inplace(CPUPPCState *env, const char *cpu_model); void ppc_translate_init(void); int cpu_ppc_exec (CPUPPCState *s); void cpu_ppc_close (CPUPPCState *s); diff --git a/target-ppc/helper.c b/target-ppc/helper.c index 4b49101..99af1f6 100644 --- a/target-ppc/helper.c +++ b/target-ppc/helper.c @@ -2794,22 +2794,33 @@ void cpu_reset(CPUPPCState *env) tlb_flush(env, 1); } -CPUPPCState *cpu_ppc_init (const char *cpu_model) +int cpu_ppc_init_inplace(CPUPPCState *env, const char *cpu_model) { - CPUPPCState *env; const ppc_def_t *def; def = cpu_ppc_find_by_name(cpu_model); - if (!def) - return NULL; + if (!def) { + return -1; + } - env = qemu_mallocz(sizeof(CPUPPCState)); cpu_exec_init(env); ppc_translate_init(); env->cpu_model_str = cpu_model; cpu_ppc_register_internal(env, def); qemu_init_vcpu(env); + return 0; +} + +CPUPPCState *cpu_ppc_init(const char *cpu_model) +{ + CPUPPCState *env; + + env = qemu_mallocz(sizeof(CPUPPCState)); + if (cpu_ppc_init_inplace(env, cpu_model) < 0) { + qemu_free(env); + return NULL; + } return env; }