From patchwork Wed May 22 05:33:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 245520 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 ABA102C00A1 for ; Wed, 22 May 2013 15:40:53 +1000 (EST) Received: from localhost ([::1]:46294 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uf1m4-0001YH-Qq for incoming@patchwork.ozlabs.org; Wed, 22 May 2013 01:39:44 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58514) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uf1gz-0002Rx-7H for qemu-devel@nongnu.org; Wed, 22 May 2013 01:34:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uf1gs-0008Vq-In for qemu-devel@nongnu.org; Wed, 22 May 2013 01:34:29 -0400 Received: from [222.73.24.84] (port=12267 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uf1gr-0008RJ-KI for qemu-devel@nongnu.org; Wed, 22 May 2013 01:34:22 -0400 X-IronPort-AV: E=Sophos;i="4.87,719,1363104000"; d="scan'208";a="7330828" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 22 May 2013 13:31:13 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r4M5Y0bV022011; Wed, 22 May 2013 13:34:02 +0800 Received: from G08FNSTD100614.fnst.cn.fujitsu.com ([10.167.233.156]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013052213324260-1422191 ; Wed, 22 May 2013 13:32:42 +0800 From: Hu Tao To: qemu-devel@nongnu.org Date: Wed, 22 May 2013 13:33:17 +0800 Message-Id: <620c8720b238ce4c75825d8ec9a33f772d1954c4.1369193012.git.hutao@cn.fujitsu.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: References: X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/05/22 13:32:42, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/05/22 13:32:45, Serialize complete at 2013/05/22 13:32:45 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: Vasilis Liaskovitis , Jan Kiszka , Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Wanpeng Li Subject: [Qemu-devel] [RFC PATCH v1 13/20] piix3, ich9: create pit through composition 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 Signed-off-by: Hu Tao --- hw/i386/pc.c | 16 +--------------- hw/isa/lpc_ich9.c | 30 ++++++++++++++++++++++++++++++ hw/pci-host/piix.c | 32 ++++++++++++++++++++++++++++++++ include/hw/i386/ich9.h | 1 + include/hw/timer/i8254.h | 3 +++ 5 files changed, 67 insertions(+), 15 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 97bfad4..8438d0f 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1128,9 +1128,8 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, { int i; DriveInfo *fd[MAX_FD]; - DeviceState *hpet = NULL; qemu_irq *a20_line; - ISADevice *i8042, *port92, *vmmouse, *pit = NULL; + ISADevice *i8042, *port92, *vmmouse; qemu_irq *cpu_exit_irq; MemoryRegion *ioport80_io = g_new(MemoryRegion, 1); MemoryRegion *ioportF0_io = g_new(MemoryRegion, 1); @@ -1141,19 +1140,6 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, memory_region_init_io(ioportF0_io, &ioportF0_io_ops, NULL, "ioportF0", 1); memory_region_add_subregion(isa_bus->address_space_io, 0xf0, ioportF0_io); - if (!xen_enabled()) { - if (kvm_irqchip_in_kernel()) { - pit = kvm_pit_init(isa_bus, 0x40); - } else { - pit = pit_init(isa_bus, 0x40, 0, NULL); - } - if (hpet) { - /* connect PIT to output control line of the HPET */ - qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(&pit->qdev, 0)); - } - pcspk_init(isa_bus, pit); - } - for(i = 0; i < MAX_SERIAL_PORTS; i++) { if (serial_hds[i]) { serial_isa_init(isa_bus, i, serial_hds[i]); diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c index c50795a..42f60b9 100644 --- a/hw/isa/lpc_ich9.c +++ b/hw/isa/lpc_ich9.c @@ -46,6 +46,8 @@ #include "sysemu/sysemu.h" #include "hw/timer/hpet.h" #include "hw/timer/mc146818rtc.h" +#include "hw/audio/pcspk.h" +#include "hw/timer/i8254.h" static int ich9_lpc_sci_irq(ICH9LPCState *lpc); @@ -530,6 +532,7 @@ static int ich9_lpc_realize(PCIDevice *d) { ICH9LPCState *lpc = ICH9_LPC_DEVICE(d); qemu_irq rtc_irq; + qemu_irq pit_irq = NULL; ISABus *isa_bus; isa_bus = isa_bus_new(&d->qdev, get_system_io()); @@ -572,12 +575,31 @@ static int ich9_lpc_realize(PCIDevice *d) sysbus_connect_irq(SYS_BUS_DEVICE(lpc->hpet), i, lpc->pic[i]); } rtc_irq = qdev_get_gpio_in(lpc->hpet, HPET_LEGACY_RTC_INT); + pit_irq = qdev_get_gpio_in(lpc->hpet, HPET_LEGACY_PIT_INT); } else { isa_init_irq(lpc->rtc, &rtc_irq, RTC_ISA_IRQ); } rtc_set_irq(lpc->rtc, rtc_irq); + /* Realize the PIT */ + qdev_set_parent_bus(DEVICE(lpc->pit), BUS(lpc->isa_bus)); + qdev_init_nofail(DEVICE(lpc->pit)); + + if (!pit_irq) { + pit_irq = isa_get_irq(lpc->pit, 0); + } + if (!kvm_irqchip_in_kernel()) { + qdev_connect_gpio_out(DEVICE(lpc->pit), 0, pit_irq); + } + if (lpc->hpet) { + qdev_connect_gpio_out(DEVICE(lpc->hpet), 0, + qdev_get_gpio_in(DEVICE(lpc->pit), 0)); + } + + /* FIXME this should be refactored */ + pcspk_init(lpc->isa_bus, lpc->pit); + return 0; } @@ -639,6 +661,14 @@ static void ich9_lpc_initfn(Object *obj) s->rtc = ISA_DEVICE(object_new(TYPE_MC146818_RTC)); qdev_prop_set_int32(DEVICE(s->rtc), "base_year", 2000); object_property_add_child(obj, "rtc", OBJECT(s->rtc), NULL); + + if (kvm_irqchip_in_kernel()) { + s->pit = ISA_DEVICE(object_new(TYPE_KVM_PIT)); + } else { + s->pit = ISA_DEVICE(object_new(TYPE_PIT)); + } + object_property_add_child(obj, "pit", OBJECT(s->pit), NULL); + qdev_prop_set_uint32(DEVICE(s->pit), "iobase", 0x40); } static void ich9_lpc_class_init(ObjectClass *klass, void *data) diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 60b16d8..f3f3856 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -34,6 +34,8 @@ #include "sysemu/sysemu.h" #include "hw/timer/hpet.h" #include "hw/timer/mc146818rtc.h" +#include "hw/audio/pcspk.h" +#include "hw/timer/i8254.h" /* * I440FX chipset data sheet. @@ -74,6 +76,7 @@ typedef struct PIIX3State { ISABus *bus; DeviceState *hpet; ISADevice *rtc; + ISADevice *pit; qemu_irq *pic; @@ -581,6 +584,7 @@ static const MemoryRegionOps rcr_ops = { static int piix3_realize(PCIDevice *dev) { PIIX3State *s = PIIX3(dev); + qemu_irq pit_irq = NULL; qemu_irq rtc_irq; s->bus = isa_bus_new(DEVICE(s), pci_address_space_io(dev)); @@ -603,12 +607,32 @@ static int piix3_realize(PCIDevice *dev) sysbus_connect_irq(SYS_BUS_DEVICE(s->hpet), i, s->pic[i]); } rtc_irq = qdev_get_gpio_in(s->hpet, HPET_LEGACY_RTC_INT); + pit_irq = qdev_get_gpio_in(s->hpet, HPET_LEGACY_PIT_INT); } else { isa_init_irq(s->rtc, &rtc_irq, RTC_ISA_IRQ); } rtc_set_irq(s->rtc, rtc_irq); + /* Realize the PIT */ + qdev_set_parent_bus(DEVICE(s->pit), BUS(s->bus)); + qdev_init_nofail(DEVICE(s->pit)); + + if (!pit_irq) { + pit_irq = isa_get_irq(s->pit, 0); + } + if (!kvm_irqchip_in_kernel()) { + qdev_connect_gpio_out(DEVICE(s->pit), 0, pit_irq); + } + + if (s->hpet) { + qdev_connect_gpio_out(DEVICE(s->hpet), 0, + qdev_get_gpio_in(DEVICE(s->pit), 0)); + } + + /* FIXME this should be refactored */ + pcspk_init(s->bus, s->pit); + memory_region_init_io(&s->rcr_mem, &rcr_ops, s, "piix3-reset-control", 1); memory_region_add_subregion_overlap(pci_address_space_io(dev), RCR_IOPORT, &s->rcr_mem, 1); @@ -634,6 +658,14 @@ static void piix3_initfn(Object *obj) s->rtc = ISA_DEVICE(object_new(TYPE_MC146818_RTC)); qdev_prop_set_int32(DEVICE(s->rtc), "base_year", 2000); object_property_add_child(obj, "rtc", OBJECT(s->rtc), NULL); + + if (kvm_irqchip_in_kernel()) { + s->pit = ISA_DEVICE(object_new(TYPE_KVM_PIT)); + } else { + s->pit = ISA_DEVICE(object_new(TYPE_PIT)); + } + object_property_add_child(obj, "pit", OBJECT(s->pit), NULL); + qdev_prop_set_uint32(DEVICE(s->pit), "iobase", 0x40); } static void piix3_class_init(ObjectClass *klass, void *data) diff --git a/include/hw/i386/ich9.h b/include/hw/i386/ich9.h index 1d9f26a..14ceafb 100644 --- a/include/hw/i386/ich9.h +++ b/include/hw/i386/ich9.h @@ -64,6 +64,7 @@ typedef struct ICH9LPCState { DeviceState *hpet; ISADevice *rtc; + ISADevice *pit; qemu_irq *pic; qemu_irq *ioapic; diff --git a/include/hw/timer/i8254.h b/include/hw/timer/i8254.h index 75bb530..10da2ea 100644 --- a/include/hw/timer/i8254.h +++ b/include/hw/timer/i8254.h @@ -30,6 +30,9 @@ #define PIT_FREQ 1193182 +#define TYPE_PIT "isa-pit" +#define TYPE_KVM_PIT "kvm-pit" + typedef struct PITChannelInfo { int gate; int mode;