From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M4Ls2-0008Jp-57 for qemu-devel@nongnu.org; Wed, 13 May 2009 17:20:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M4Lrw-0008JZ-GA for qemu-devel@nongnu.org; Wed, 13 May 2009 17:20:08 -0400 Received: from [199.232.76.173] (port=42010 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M4Lrw-0008JW-8o for qemu-devel@nongnu.org; Wed, 13 May 2009 17:20:04 -0400 Received: from e31.co.us.ibm.com ([32.97.110.149]:52331) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M4Lrv-00040I-SS for qemu-devel@nongnu.org; Wed, 13 May 2009 17:20:04 -0400 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e31.co.us.ibm.com (8.13.1/8.13.1) with ESMTP id n4DLG4aY003795 for ; Wed, 13 May 2009 15:16:04 -0600 Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n4DLJpFU174362 for ; Wed, 13 May 2009 15:19:51 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n4DLJoY2014603 for ; Wed, 13 May 2009 15:19:50 -0600 From: Ryan Harper Date: Wed, 13 May 2009 16:19:49 -0500 Message-Id: <1242249589-1980-1-git-send-email-ryanh@us.ibm.com> Subject: [Qemu-devel] [PATCH]v2 Add monitor command for system_reboot List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Ryan Harper Add a new monitor command (system_reboot) for a soft reboot which uses system_powerdown to trigger ACPI shutdown in the guest and once shutdown is complete, trigger a reset instead of exiting qemu. Depends on commit a6d6552426dcbf726e5549f08b70c9318d6be14b which enabled ACPI power button support. V2: -added reset handler to lower the reboot flag on reset. Tested with Ubuntu 9.04 64-bit guest. Signed-off-by: Ryan Harper diff --git a/hw/acpi.c b/hw/acpi.c index dbaf18a..cf66a86 100644 --- a/hw/acpi.c +++ b/hw/acpi.c @@ -151,7 +151,13 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, uint32_t val) sus_typ = (val >> 10) & 7; switch(sus_typ) { case 0: /* soft power off */ - qemu_system_shutdown_request(); + /* after powerdown, if on system_reboot path, call reset + instead of shutdown */ + if (qemu_reboot_requested()) { + qemu_system_reset_request(); + } else { + qemu_system_shutdown_request(); + } break; case 1: /* RSM_STS should be set on resume. Pretend that resume @@ -497,6 +503,12 @@ static void piix4_reset(void *opaque) } } +static void system_reboot_reset(void *opaque) +{ + /* clear reboot flag */ + qemu_reboot_requested(); +} + i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, qemu_irq sci_irq) { @@ -551,6 +563,7 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, s->smbus = i2c_init_bus(); s->irq = sci_irq; qemu_register_reset(piix4_reset, s); + qemu_register_reset(system_reboot_reset, s); return s->smbus; } diff --git a/monitor.c b/monitor.c index 0f38c71..ca50b31 100644 --- a/monitor.c +++ b/monitor.c @@ -1222,6 +1222,11 @@ static void do_system_powerdown(Monitor *mon) qemu_system_powerdown_request(); } +static void do_system_reboot(Monitor *mon) +{ + qemu_system_reboot_request(); +} + #if defined(TARGET_I386) static void print_pte(Monitor *mon, uint32_t addr, uint32_t pte, uint32_t mask) { @@ -1707,6 +1712,8 @@ static const mon_cmd_t mon_cmds[] = { "", "reset the system" }, { "system_powerdown", "", do_system_powerdown, "", "send system power down event" }, + { "system_reboot", "", do_system_reboot, + "", "send system power down event, and then reset" }, { "sum", "ii", do_sum, "addr size", "compute the checksum of a memory region" }, { "usb_add", "s", do_usb_add, diff --git a/sysemu.h b/sysemu.h index 9bb9fbc..d82042d 100644 --- a/sysemu.h +++ b/sysemu.h @@ -33,10 +33,12 @@ void cpu_enable_ticks(void); void cpu_disable_ticks(void); void qemu_system_reset_request(void); +void qemu_system_reboot_request(void); void qemu_system_shutdown_request(void); void qemu_system_powerdown_request(void); int qemu_shutdown_requested(void); int qemu_reset_requested(void); +int qemu_reboot_requested(void); int qemu_powerdown_requested(void); #if !defined(TARGET_SPARC) && !defined(TARGET_I386) // Please implement a power failure function to signal the OS diff --git a/vl.c b/vl.c index 846d798..750c945 100644 --- a/vl.c +++ b/vl.c @@ -3582,6 +3582,7 @@ static QEMUResetEntry *first_reset_entry; static int reset_requested; static int shutdown_requested; static int powerdown_requested; +static int reboot_requested; static int debug_requested; static int vmstop_requested; @@ -3606,6 +3607,13 @@ int qemu_powerdown_requested(void) return r; } +int qemu_reboot_requested(void) +{ + int r = reboot_requested; + reboot_requested = 0; + return r; +} + static int qemu_debug_requested(void) { int r = debug_requested; @@ -3678,6 +3686,16 @@ void qemu_system_powerdown_request(void) qemu_notify_event(); } +void qemu_system_reboot_request(void) +{ + /* raise the powerdown request to trigger system_powerdown event. Also + raise reboot flag so powerdown handler knows to request a reset + instead of shutdown after the powerdown. */ + powerdown_requested = 1; + reboot_requested = 1; + qemu_notify_event(); +} + #ifdef CONFIG_IOTHREAD static void qemu_system_vmstop_request(int reason) { @@ -4434,6 +4452,8 @@ static int vm_can_run(void) { if (powerdown_requested) return 0; + if (reboot_requested) + return 0; if (reset_requested) return 0; if (shutdown_requested)