From patchwork Fri Sep 24 15:20:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard W.M. Jones" X-Patchwork-Id: 65658 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 78639B70F5 for ; Sat, 25 Sep 2010 01:39:02 +1000 (EST) Received: from localhost ([127.0.0.1]:49444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OzAMT-0005Z0-1h for incoming@patchwork.ozlabs.org; Fri, 24 Sep 2010 11:38:57 -0400 Received: from [140.186.70.92] (port=33220 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OzAJL-00042V-Ja for qemu-devel@nongnu.org; Fri, 24 Sep 2010 11:35:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OzA4o-0007EB-NC for qemu-devel@nongnu.org; Fri, 24 Sep 2010 11:20:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60512) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OzA4o-0007E0-Be for qemu-devel@nongnu.org; Fri, 24 Sep 2010 11:20:42 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o8OFKeou010686 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 24 Sep 2010 11:20:40 -0400 Received: from localhost (vpn2-10-43.ams2.redhat.com [10.36.10.43]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o8OFKdTA024639; Fri, 24 Sep 2010 11:20:39 -0400 Date: Fri, 24 Sep 2010 16:20:38 +0100 From: "Richard W.M. Jones" To: qemu-devel@nongnu.org Message-ID: <20100924152008.GA12004@amd.home.annexia.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Markus Armbruster , Juan Quintela Subject: [Qemu-devel] [PATCH] Watchdog: disable watchdog timer when hard-rebooting a guest. 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 diff --git a/hw/wdt_i6300esb.c b/hw/wdt_i6300esb.c index 46e1df8..dbd05ba 100644 --- a/hw/wdt_i6300esb.c +++ b/hw/wdt_i6300esb.c @@ -102,6 +102,8 @@ struct I6300State { typedef struct I6300State I6300State; +static void i6300esb_reset(DeviceState *dev); + /* This function is called when the watchdog has either been enabled * (hence it starts counting down) or has been keep-alived. */ @@ -140,16 +142,6 @@ static void i6300esb_disable_timer(I6300State *d) qemu_del_timer(d->timer); } -static void i6300esb_reset(I6300State *d) -{ - /* XXX We should probably reset other parts of the state here, - * but we should also reset our state on general machine reset - * too. For now just disable the timer so it doesn't fire - * again after the reboot. - */ - i6300esb_disable_timer(d); -} - /* This function is called when the watchdog expires. Note that * the hardware has two timers, and so expiry happens in two stages. * If d->stage == 1 then we perform the first stage action (usually, @@ -181,7 +173,7 @@ static void i6300esb_timer_expired(void *vp) if (d->reboot_enabled) { d->previous_reboot_flag = 1; watchdog_perform_action(); /* This reboots, exits, etc */ - i6300esb_reset(d); + i6300esb_reset(&d->dev.qdev); } /* In "free running mode" we start stage 1 again. */ @@ -394,17 +386,9 @@ static int i6300esb_init(PCIDevice *dev) I6300State *d = DO_UPCAST(I6300State, dev, dev); uint8_t *pci_conf; - d->reboot_enabled = 1; - d->clock_scale = CLOCK_SCALE_1KHZ; - d->int_type = INT_TYPE_IRQ; - d->free_run = 0; - d->locked = 0; - d->enabled = 0; + i6300esb_debug("watchdog init\n"); + d->timer = qemu_new_timer(vm_clock, i6300esb_timer_expired, d); - d->timer1_preload = 0xfffff; - d->timer2_preload = 0xfffff; - d->stage = 1; - d->unlock_state = 0; d->previous_reboot_flag = 0; pci_conf = d->dev.config; @@ -413,11 +397,33 @@ static int i6300esb_init(PCIDevice *dev) pci_config_set_class(pci_conf, PCI_CLASS_SYSTEM_OTHER); pci_register_bar(&d->dev, 0, 0x10, - PCI_BASE_ADDRESS_SPACE_MEMORY, i6300esb_map); + PCI_BASE_ADDRESS_SPACE_MEMORY, i6300esb_map); return 0; } +static void i6300esb_reset(DeviceState *dev) +{ + I6300State *d = DO_UPCAST(I6300State, dev.qdev, dev); + + i6300esb_debug("watchdog reset\n"); + + /* NB: Don't change d->previous_reboot_flag in this function. */ + + d->reboot_enabled = 1; + d->clock_scale = CLOCK_SCALE_1KHZ; + d->int_type = INT_TYPE_IRQ; + d->free_run = 0; + d->locked = 0; + d->enabled = 0; + d->timer1_preload = 0xfffff; + d->timer2_preload = 0xfffff; + d->stage = 1; + d->unlock_state = 0; + + i6300esb_disable_timer(d); +} + static WatchdogTimerModel model = { .wdt_name = "i6300esb", .wdt_description = "Intel 6300ESB", @@ -427,6 +433,7 @@ static PCIDeviceInfo i6300esb_info = { .qdev.name = "i6300esb", .qdev.size = sizeof(I6300State), .qdev.vmsd = &vmstate_i6300esb, + .qdev.reset = i6300esb_reset, .config_read = i6300esb_config_read, .config_write = i6300esb_config_write, .init = i6300esb_init, diff --git a/hw/wdt_ib700.c b/hw/wdt_ib700.c index c34687b..b6235eb 100644 --- a/hw/wdt_ib700.c +++ b/hw/wdt_ib700.c @@ -97,6 +97,8 @@ static int wdt_ib700_init(ISADevice *dev) { IB700State *s = DO_UPCAST(IB700State, dev, dev); + ib700_debug("watchdog init\n"); + s->timer = qemu_new_timer(vm_clock, ib700_timer_expired, s); register_ioport_write(0x441, 2, 1, ib700_write_disable_reg, s); register_ioport_write(0x443, 2, 1, ib700_write_enable_reg, s); @@ -104,16 +106,26 @@ static int wdt_ib700_init(ISADevice *dev) return 0; } +static void wdt_ib700_reset(DeviceState *dev) +{ + IB700State *s = DO_UPCAST(IB700State, dev.qdev, dev); + + ib700_debug("watchdog reset\n"); + + qemu_del_timer(s->timer); +} + static WatchdogTimerModel model = { .wdt_name = "ib700", .wdt_description = "iBASE 700", }; static ISADeviceInfo wdt_ib700_info = { - .qdev.name = "ib700", - .qdev.size = sizeof(IB700State), - .qdev.vmsd = &vmstate_ib700, - .init = wdt_ib700_init, + .qdev.name = "ib700", + .qdev.size = sizeof(IB700State), + .qdev.vmsd = &vmstate_ib700, + .qdev.reset = wdt_ib700_reset, + .init = wdt_ib700_init, }; static void wdt_ib700_register_devices(void)