From patchwork Mon May 24 20:13:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 53459 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 78A0CB7D7F for ; Tue, 25 May 2010 06:23:44 +1000 (EST) Received: from localhost ([127.0.0.1]:56355 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGeBY-0006hs-5b for incoming@patchwork.ozlabs.org; Mon, 24 May 2010 16:23:40 -0400 Received: from [140.186.70.92] (port=40895 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGe2Q-000190-Sk for qemu-devel@nongnu.org; Mon, 24 May 2010 16:14:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OGe29-0000D4-9x for qemu-devel@nongnu.org; Mon, 24 May 2010 16:14:14 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:46561) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGe28-0000CW-OT for qemu-devel@nongnu.org; Mon, 24 May 2010 16:13:57 -0400 Received: from smtp05.web.de ( [172.20.4.166]) by fmmailgate02.web.de (Postfix) with ESMTP id 312C916272221; Mon, 24 May 2010 22:13:56 +0200 (CEST) Received: from [88.65.39.229] (helo=localhost.localdomain) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #4) id 1OGe28-0004UY-00; Mon, 24 May 2010 22:13:56 +0200 From: Jan Kiszka To: qemu-devel@nongnu.org Date: Mon, 24 May 2010 22:13:38 +0200 Message-Id: <3d07ca44a4c2332d3f6247033031e891d3678804.1274732025.git.jan.kiszka@web.de> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: References: In-Reply-To: References: X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX1/4puVUOlI//GY5w81WMfgA0+e08ZMvv/WIRFQ5 hbdRK4NuvJrrrLV1kVTc5rxiigjsk54pBbU8SEzbza4CrW0CVw MMmo3BDmA= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: blue Swirl , Jan Kiszka , Juan Quintela Subject: [Qemu-devel] [RFT][PATCH 05/15] hpet: Convert to qdev 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: Jan Kiszka Register the HPET as a sysbus device and create it that way. As it can route its IRQs to any ISA IRQ, we need to connect it to all 24 of them. Once converted to qdev, we can move reset handler and vmstate registration into its hands as well. Signed-off-by: Jan Kiszka --- hw/hpet.c | 43 ++++++++++++++++++++++++++++++------------- hw/hpet_emul.h | 3 ++- hw/pc.c | 7 ++++++- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/hw/hpet.c b/hw/hpet.c index fd7a1fd..6974935 100644 --- a/hw/hpet.c +++ b/hw/hpet.c @@ -29,6 +29,7 @@ #include "console.h" #include "qemu-timer.h" #include "hpet_emul.h" +#include "sysbus.h" //#define HPET_DEBUG #ifdef HPET_DEBUG @@ -54,8 +55,9 @@ typedef struct HPETTimer { /* timers */ } HPETTimer; typedef struct HPETState { + SysBusDevice busdev; uint64_t hpet_offset; - qemu_irq *irqs; + qemu_irq irqs[HPET_NUM_IRQ_ROUTES]; HPETTimer timer[HPET_NUM_TIMERS]; /* Memory-mapped, software visible registers */ @@ -565,9 +567,9 @@ static CPUWriteMemoryFunc * const hpet_ram_write[] = { hpet_ram_writel, }; -static void hpet_reset(void *opaque) +static void hpet_reset(DeviceState *d) { - HPETState *s = opaque; + HPETState *s = FROM_SYSBUS(HPETState, sysbus_from_qdev(d)); int i; static int count = 0; @@ -600,28 +602,43 @@ static void hpet_reset(void *opaque) count = 1; } - -void hpet_init(qemu_irq *irq) +static int hpet_init(SysBusDevice *dev) { + HPETState *s = FROM_SYSBUS(HPETState, dev); int i, iomemtype; HPETTimer *timer; - HPETState *s; - - DPRINTF ("hpet_init\n"); - s = qemu_mallocz(sizeof(HPETState)); + assert(!hpet_statep); hpet_statep = s; - s->irqs = irq; + for (i = 0; i < HPET_NUM_IRQ_ROUTES; i++) { + sysbus_init_irq(dev, &s->irqs[i]); + } for (i = 0; i < HPET_NUM_TIMERS; i++) { timer = &s->timer[i]; timer->qemu_timer = qemu_new_timer(vm_clock, hpet_timer, timer); timer->tn = i; timer->state = s; } - vmstate_register(-1, &vmstate_hpet, s); - qemu_register_reset(hpet_reset, s); + /* HPET Area */ iomemtype = cpu_register_io_memory(hpet_ram_read, hpet_ram_write, s); - cpu_register_physical_memory(HPET_BASE, 0x400, iomemtype); + sysbus_init_mmio(dev, 0x400, iomemtype); + return 0; } + +static SysBusDeviceInfo hpet_device_info = { + .qdev.name = "hpet", + .qdev.size = sizeof(HPETState), + .qdev.no_user = 1, + .qdev.vmsd = &vmstate_hpet, + .qdev.reset = hpet_reset, + .init = hpet_init, +}; + +static void hpet_register_device(void) +{ + sysbus_register_withprop(&hpet_device_info); +} + +device_init(hpet_register_device) diff --git a/hw/hpet_emul.h b/hw/hpet_emul.h index 2f5f8ba..785f850 100644 --- a/hw/hpet_emul.h +++ b/hw/hpet_emul.h @@ -19,6 +19,8 @@ #define FS_PER_NS 1000000 #define HPET_NUM_TIMERS 3 +#define HPET_NUM_IRQ_ROUTES 32 + #define HPET_CFG_ENABLE 0x001 #define HPET_CFG_LEGACY 0x002 @@ -47,7 +49,6 @@ #if defined TARGET_I386 extern uint32_t hpet_in_legacy_mode(void); -extern void hpet_init(qemu_irq *irq); #endif #endif diff --git a/hw/pc.c b/hw/pc.c index e7f31d3..631b0ae 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -35,6 +35,7 @@ #include "elf.h" #include "multiboot.h" #include "mc146818rtc.h" +#include "sysbus.h" /* output Bochs bios info messages */ //#define DEBUG_BIOS @@ -945,7 +946,11 @@ void pc_basic_device_init(qemu_irq *isa_irq, pit = pit_init(0x40, isa_reserve_irq(0)); pcspk_init(pit); if (!no_hpet) { - hpet_init(isa_irq); + DeviceState *hpet = sysbus_create_simple("hpet", HPET_BASE, NULL); + + for (i = 0; i < 24; i++) { + sysbus_connect_irq(sysbus_from_qdev(hpet), i, isa_irq[i]); + } } for(i = 0; i < MAX_SERIAL_PORTS; i++) {