From patchwork Sun Jun 6 08:10:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 54803 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 B5280B7D47 for ; Sun, 6 Jun 2010 18:19:27 +1000 (EST) Received: from localhost ([127.0.0.1]:35520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLB4h-0005NO-0O for incoming@patchwork.ozlabs.org; Sun, 06 Jun 2010 04:19:19 -0400 Received: from [140.186.70.92] (port=54768 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLAwt-0002MR-U2 for qemu-devel@nongnu.org; Sun, 06 Jun 2010 04:11:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLAwr-0004lx-O3 for qemu-devel@nongnu.org; Sun, 06 Jun 2010 04:11:15 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:54410) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLAwq-0004lR-Uu for qemu-devel@nongnu.org; Sun, 06 Jun 2010 04:11:13 -0400 Received: from smtp04.web.de ( [172.20.0.225]) by fmmailgate02.web.de (Postfix) with ESMTP id 5F5DA164DD828; Sun, 6 Jun 2010 10:11:12 +0200 (CEST) Received: from [88.66.126.39] (helo=localhost.localdomain) by smtp04.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #4) id 1OLAwq-000200-01; Sun, 06 Jun 2010 10:11:12 +0200 From: Jan Kiszka To: qemu-devel@nongnu.org Date: Sun, 6 Jun 2010 10:10:54 +0200 Message-Id: <9980820e7ae71c0f1314b18b3fb412591f96ae3c.1275811861.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: V01U2FsdGVkX18k/wgWFeIGmOpHkaoSZ8HDWGyMOXJs/7zEdd6Z gfGYoF5sM8OvvfAm83MxfAtlU4he+Gz3hlRFhXC5/1nbqx5lWL 9IS+55awk= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: blue Swirl , Jan Kiszka , Paul Brook , Gleb Natapov , Juan Quintela Subject: [Qemu-devel] [PATCH 05/16] 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 9b85c42..ae31e2e 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 @@ -957,7 +958,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++) {