qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ryan Harper <ryanh@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>, Ryan Harper <ryanh@us.ibm.com>
Subject: [Qemu-devel] [PATCH]v2 Add monitor command for system_reboot
Date: Wed, 13 May 2009 16:19:49 -0500	[thread overview]
Message-ID: <1242249589-1980-1-git-send-email-ryanh@us.ibm.com> (raw)

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 <ryanh@us.ibm.com>

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)

                 reply	other threads:[~2009-05-13 21:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1242249589-1980-1-git-send-email-ryanh@us.ibm.com \
    --to=ryanh@us.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).