76daa3
From 3ab1c8abe9f08c363752b8aa6204038895a72a51 Mon Sep 17 00:00:00 2001
76daa3
From: Eric Blake <eblake@redhat.com>
76daa3
Date: Thu, 1 Jun 2017 16:58:20 +0200
76daa3
Subject: [PATCH 04/17] shutdown: Add source information to SHUTDOWN and RESET
76daa3
76daa3
RH-Author: Eric Blake <eblake@redhat.com>
76daa3
Message-id: <20170601165821.26810-5-eblake@redhat.com>
76daa3
Patchwork-id: 75467
76daa3
O-Subject: [RHEL-7.4 qemu-kvm-rhev PATCH v2 4/5] shutdown: Add source information to SHUTDOWN and RESET
76daa3
Bugzilla: 1418927
76daa3
RH-Acked-by: John Snow <jsnow@redhat.com>
76daa3
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
76daa3
RH-Acked-by: Thomas Huth <thuth@redhat.com>
76daa3
76daa3
Time to wire up all the call sites that request a shutdown or
76daa3
reset to use the enum added in the previous patch.
76daa3
76daa3
It would have been less churn to keep the common case with no
76daa3
arguments as meaning guest-triggered, and only modified the
76daa3
host-triggered code paths, via a wrapper function, but then we'd
76daa3
still have to audit that I didn't miss any host-triggered spots;
76daa3
changing the signature forces us to double-check that I correctly
76daa3
categorized all callers.
76daa3
76daa3
Since command line options can change whether a guest reset request
76daa3
causes an actual reset vs. a shutdown, it's easy to also add the
76daa3
information to reset requests.
76daa3
76daa3
Signed-off-by: Eric Blake <eblake@redhat.com>
76daa3
Acked-by: David Gibson <david@gibson.dropbear.id.au> [ppc parts]
76daa3
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> [SPARC part]
76daa3
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com> [s390x parts]
76daa3
Message-Id: <20170515214114.15442-5-eblake@redhat.com>
76daa3
Reviewed-by: Markus Armbruster <armbru@redhat.com>
76daa3
Signed-off-by: Markus Armbruster <armbru@redhat.com>
76daa3
(cherry picked from commit cf83f140059f21d4629ae4b61d468c3baef2bb4c)
76daa3
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
---
76daa3
 hw/acpi/core.c              |  4 ++--
76daa3
 hw/arm/highbank.c           |  4 ++--
76daa3
 hw/arm/integratorcp.c       |  2 +-
76daa3
 hw/arm/musicpal.c           |  2 +-
76daa3
 hw/arm/omap1.c              | 10 ++++++----
76daa3
 hw/arm/omap2.c              |  2 +-
76daa3
 hw/arm/spitz.c              |  2 +-
76daa3
 hw/arm/stellaris.c          |  2 +-
76daa3
 hw/arm/tosa.c               |  2 +-
76daa3
 hw/i386/pc.c                |  2 +-
76daa3
 hw/input/pckbd.c            |  4 ++--
76daa3
 hw/ipmi/ipmi.c              |  4 ++--
76daa3
 hw/isa/lpc_ich9.c           |  2 +-
76daa3
 hw/mips/boston.c            |  2 +-
76daa3
 hw/mips/mips_malta.c        |  2 +-
76daa3
 hw/mips/mips_r4k.c          |  4 ++--
76daa3
 hw/misc/arm_sysctl.c        |  8 ++++----
76daa3
 hw/misc/cbus.c              |  2 +-
76daa3
 hw/misc/macio/cuda.c        |  4 ++--
76daa3
 hw/misc/slavio_misc.c       |  4 ++--
76daa3
 hw/misc/zynq_slcr.c         |  2 +-
76daa3
 hw/pci-host/apb.c           |  4 ++--
76daa3
 hw/pci-host/bonito.c        |  2 +-
76daa3
 hw/pci-host/piix.c          |  2 +-
76daa3
 hw/ppc/e500.c               |  2 +-
76daa3
 hw/ppc/mpc8544_guts.c       |  2 +-
76daa3
 hw/ppc/ppc.c                |  2 +-
76daa3
 hw/ppc/ppc405_uc.c          |  2 +-
76daa3
 hw/ppc/spapr_hcall.c        |  2 +-
76daa3
 hw/ppc/spapr_rtas.c         |  4 ++--
76daa3
 hw/s390x/ipl.c              |  2 +-
76daa3
 hw/sh4/r2d.c                |  2 +-
76daa3
 hw/timer/etraxfs_timer.c    |  2 +-
76daa3
 hw/timer/m48t59.c           |  4 ++--
76daa3
 hw/timer/milkymist-sysctl.c |  4 ++--
76daa3
 hw/timer/pxa2xx_timer.c     |  2 +-
76daa3
 hw/watchdog/watchdog.c      |  2 +-
76daa3
 hw/xenpv/xen_domainbuild.c  |  2 +-
76daa3
 hw/xtensa/xtfpga.c          |  2 +-
76daa3
 include/sysemu/sysemu.h     |  4 ++--
76daa3
 kvm-all.c                   |  6 +++---
76daa3
 os-win32.c                  |  2 +-
76daa3
 qmp.c                       |  4 ++--
76daa3
 replay/replay.c             |  4 ++--
76daa3
 target/alpha/sys_helper.c   |  4 ++--
76daa3
 target/arm/psci.c           |  4 ++--
76daa3
 target/i386/excp_helper.c   |  2 +-
76daa3
 target/i386/hax-all.c       |  6 +++---
76daa3
 target/i386/helper.c        |  2 +-
76daa3
 target/i386/kvm.c           |  2 +-
76daa3
 target/s390x/helper.c       |  2 +-
76daa3
 target/s390x/kvm.c          |  4 ++--
76daa3
 target/s390x/misc_helper.c  |  4 ++--
76daa3
 target/sparc/int32_helper.c |  2 +-
76daa3
 trace-events                |  2 +-
76daa3
 ui/cocoa.m                  |  2 +-
76daa3
 ui/sdl.c                    |  2 +-
76daa3
 ui/sdl2.c                   |  4 ++--
76daa3
 vl.c                        | 18 ++++++++----------
76daa3
 xen-hvm.c                   |  2 +-
76daa3
 60 files changed, 98 insertions(+), 98 deletions(-)
76daa3
76daa3
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
76daa3
index e890a5d..95fcac9 100644
76daa3
--- a/hw/acpi/core.c
76daa3
+++ b/hw/acpi/core.c
76daa3
@@ -561,7 +561,7 @@ static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
76daa3
         uint16_t sus_typ = (val >> 10) & 7;
76daa3
         switch(sus_typ) {
76daa3
         case 0: /* soft power off */
76daa3
-            qemu_system_shutdown_request();
76daa3
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
             break;
76daa3
         case 1:
76daa3
             qemu_system_suspend_request();
76daa3
@@ -569,7 +569,7 @@ static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
76daa3
         default:
76daa3
             if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
76daa3
                 qapi_event_send_suspend_disk(&error_abort);
76daa3
-                qemu_system_shutdown_request();
76daa3
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
             }
76daa3
             break;
76daa3
         }
76daa3
diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c
76daa3
index 0a4508c..d209b97 100644
76daa3
--- a/hw/arm/highbank.c
76daa3
+++ b/hw/arm/highbank.c
76daa3
@@ -108,9 +108,9 @@ static void hb_regs_write(void *opaque, hwaddr offset,
76daa3
 
76daa3
     if (offset == 0xf00) {
76daa3
         if (value == 1 || value == 2) {
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         } else if (value == 3) {
76daa3
-            qemu_system_shutdown_request();
76daa3
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
         }
76daa3
     }
76daa3
 
76daa3
diff --git a/hw/arm/integratorcp.c b/hw/arm/integratorcp.c
76daa3
index 5610ffc..ca3eca1 100644
76daa3
--- a/hw/arm/integratorcp.c
76daa3
+++ b/hw/arm/integratorcp.c
76daa3
@@ -158,7 +158,7 @@ static void integratorcm_do_remap(IntegratorCMState *s)
76daa3
 static void integratorcm_set_ctrl(IntegratorCMState *s, uint32_t value)
76daa3
 {
76daa3
     if (value & 8) {
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     }
76daa3
     if ((s->cm_ctrl ^ value) & 1) {
76daa3
         /* (value & 1) != 0 means the green "MISC LED" is lit.
76daa3
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
76daa3
index cbbca4e..9c710f7 100644
76daa3
--- a/hw/arm/musicpal.c
76daa3
+++ b/hw/arm/musicpal.c
76daa3
@@ -898,7 +898,7 @@ static void mv88w8618_pit_write(void *opaque, hwaddr offset,
76daa3
 
76daa3
     case MP_BOARD_RESET:
76daa3
         if (value == MP_BOARD_RESET_MAGIC) {
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         }
76daa3
         break;
76daa3
     }
76daa3
diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c
76daa3
index b3cf0ec..54582bd 100644
76daa3
--- a/hw/arm/omap1.c
76daa3
+++ b/hw/arm/omap1.c
76daa3
@@ -355,7 +355,7 @@ static void omap_wd_timer_write(void *opaque, hwaddr addr,
76daa3
                 /* XXX: on T|E hardware somehow this has no effect,
76daa3
                  * on Zire 71 it works as specified.  */
76daa3
                 s->reset = 1;
76daa3
-                qemu_system_reset_request();
76daa3
+                qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
             }
76daa3
         }
76daa3
         s->last_wr = value & 0xff;
76daa3
@@ -1545,8 +1545,10 @@ static inline void omap_clkm_idlect1_update(struct omap_mpu_state_s *s,
76daa3
     if (value & (1 << 11)) {                            /* SETARM_IDLE */
76daa3
         cpu_interrupt(CPU(s->cpu), CPU_INTERRUPT_HALT);
76daa3
     }
76daa3
-    if (!(value & (1 << 10)))				/* WKUP_MODE */
76daa3
-        qemu_system_shutdown_request();	/* XXX: disable wakeup from IRQ */
76daa3
+    if (!(value & (1 << 10))) {                         /* WKUP_MODE */
76daa3
+        /* XXX: disable wakeup from IRQ */
76daa3
+        qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
+    }
76daa3
 
76daa3
 #define SET_CANIDLE(clock, bit)				\
76daa3
     if (diff & (1 << bit)) {				\
76daa3
@@ -1693,7 +1695,7 @@ static void omap_clkm_write(void *opaque, hwaddr addr,
76daa3
         diff = s->clkm.arm_rstct1 ^ value;
76daa3
         s->clkm.arm_rstct1 = value & 0x0007;
76daa3
         if (value & 9) {
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
             s->clkm.cold_start = 0xa;
76daa3
         }
76daa3
         if (diff & ~value & 4) {				/* DSP_RST */
76daa3
diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c
76daa3
index cf1b4ba..8afb854 100644
76daa3
--- a/hw/arm/omap2.c
76daa3
+++ b/hw/arm/omap2.c
76daa3
@@ -1610,7 +1610,7 @@ static void omap_prcm_write(void *opaque, hwaddr addr,
76daa3
     case 0x450:	/* RM_RSTCTRL_WKUP */
76daa3
         /* TODO: reset */
76daa3
         if (value & 2)
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         break;
76daa3
     case 0x454:	/* RM_RSTTIME_WKUP */
76daa3
         s->rsttime_wkup = value & 0x1fff;
76daa3
diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
76daa3
index fe2d5a7..7e9f579 100644
76daa3
--- a/hw/arm/spitz.c
76daa3
+++ b/hw/arm/spitz.c
76daa3
@@ -848,7 +848,7 @@ static void spitz_lcd_hsync_handler(void *opaque, int line, int level)
76daa3
 static void spitz_reset(void *opaque, int line, int level)
76daa3
 {
76daa3
     if (level) {
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     }
76daa3
 }
76daa3
 
76daa3
diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
76daa3
index 9edcd49..c35f684 100644
76daa3
--- a/hw/arm/stellaris.c
76daa3
+++ b/hw/arm/stellaris.c
76daa3
@@ -1183,7 +1183,7 @@ static
76daa3
 void do_sys_reset(void *opaque, int n, int level)
76daa3
 {
76daa3
     if (level) {
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     }
76daa3
 }
76daa3
 
76daa3
diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
76daa3
index 9f58a23..2421b81 100644
76daa3
--- a/hw/arm/tosa.c
76daa3
+++ b/hw/arm/tosa.c
76daa3
@@ -90,7 +90,7 @@ static void tosa_out_switch(void *opaque, int line, int level)
76daa3
 static void tosa_reset(void *opaque, int line, int level)
76daa3
 {
76daa3
     if (level) {
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     }
76daa3
 }
76daa3
 
76daa3
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
76daa3
index 3596de0..f0d09d9 100644
76daa3
--- a/hw/i386/pc.c
76daa3
+++ b/hw/i386/pc.c
76daa3
@@ -520,7 +520,7 @@ static void port92_write(void *opaque, hwaddr addr, uint64_t val,
76daa3
     s->outport = val;
76daa3
     qemu_set_irq(s->a20_out, (val >> 1) & 1);
76daa3
     if ((val & 1) && !(oldval & 1)) {
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     }
76daa3
 }
76daa3
 
76daa3
diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c
76daa3
index f475f33..a7676bc 100644
76daa3
--- a/hw/input/pckbd.c
76daa3
+++ b/hw/input/pckbd.c
76daa3
@@ -227,7 +227,7 @@ static void outport_write(KBDState *s, uint32_t val)
76daa3
     s->outport = val;
76daa3
     qemu_set_irq(s->a20_out, (val >> 1) & 1);
76daa3
     if (!(val & 1)) {
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     }
76daa3
 }
76daa3
 
76daa3
@@ -302,7 +302,7 @@ static void kbd_write_command(void *opaque, hwaddr addr,
76daa3
         s->outport &= ~KBD_OUT_A20;
76daa3
         break;
76daa3
     case KBD_CCMD_RESET:
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         break;
76daa3
     case KBD_CCMD_NO_OP:
76daa3
         /* ignore that */
76daa3
diff --git a/hw/ipmi/ipmi.c b/hw/ipmi/ipmi.c
76daa3
index 5cf1caa..afafe14 100644
76daa3
--- a/hw/ipmi/ipmi.c
76daa3
+++ b/hw/ipmi/ipmi.c
76daa3
@@ -44,14 +44,14 @@ static int ipmi_do_hw_op(IPMIInterface *s, enum ipmi_op op, int checkonly)
76daa3
         if (checkonly) {
76daa3
             return 0;
76daa3
         }
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         return 0;
76daa3
 
76daa3
     case IPMI_POWEROFF_CHASSIS:
76daa3
         if (checkonly) {
76daa3
             return 0;
76daa3
         }
76daa3
-        qemu_system_shutdown_request();
76daa3
+        qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
         return 0;
76daa3
 
76daa3
     case IPMI_SEND_NMI:
76daa3
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
76daa3
index a0866c3..2b09354 100644
76daa3
--- a/hw/isa/lpc_ich9.c
76daa3
+++ b/hw/isa/lpc_ich9.c
76daa3
@@ -606,7 +606,7 @@ static void ich9_rst_cnt_write(void *opaque, hwaddr addr, uint64_t val,
76daa3
     ICH9LPCState *lpc = opaque;
76daa3
 
76daa3
     if (val & 4) {
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         return;
76daa3
     }
76daa3
     lpc->rst_cnt = val & 0xA; /* keep FULL_RST (bit 3) and SYS_RST (bit 1) */
76daa3
diff --git a/hw/mips/boston.c b/hw/mips/boston.c
76daa3
index 83f7b82..53d1e0c 100644
76daa3
--- a/hw/mips/boston.c
76daa3
+++ b/hw/mips/boston.c
76daa3
@@ -232,7 +232,7 @@ static void boston_platreg_write(void *opaque, hwaddr addr,
76daa3
         break;
76daa3
     case PLAT_SOFTRST_CTL:
76daa3
         if (val & PLAT_SOFTRST_CTL_SYSRESET) {
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         }
76daa3
         break;
76daa3
     default:
76daa3
diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
76daa3
index 5dd177e..7814c39 100644
76daa3
--- a/hw/mips/mips_malta.c
76daa3
+++ b/hw/mips/mips_malta.c
76daa3
@@ -470,7 +470,7 @@ static void malta_fpga_write(void *opaque, hwaddr addr,
76daa3
     /* SOFTRES Register */
76daa3
     case 0x00500:
76daa3
         if (val == 0x42)
76daa3
-            qemu_system_reset_request ();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         break;
76daa3
 
76daa3
     /* BRKRES Register */
76daa3
diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
76daa3
index 748586e..f4de9fc 100644
76daa3
--- a/hw/mips/mips_r4k.c
76daa3
+++ b/hw/mips/mips_r4k.c
76daa3
@@ -53,9 +53,9 @@ static void mips_qemu_write (void *opaque, hwaddr addr,
76daa3
                              uint64_t val, unsigned size)
76daa3
 {
76daa3
     if ((addr & 0xffff) == 0 && val == 42)
76daa3
-        qemu_system_reset_request ();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     else if ((addr & 0xffff) == 4 && val == 42)
76daa3
-        qemu_system_shutdown_request ();
76daa3
+        qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
 }
76daa3
 
76daa3
 static uint64_t mips_qemu_read (void *opaque, hwaddr addr,
76daa3
diff --git a/hw/misc/arm_sysctl.c b/hw/misc/arm_sysctl.c
76daa3
index 8524008..b20b44e 100644
76daa3
--- a/hw/misc/arm_sysctl.c
76daa3
+++ b/hw/misc/arm_sysctl.c
76daa3
@@ -351,13 +351,13 @@ static bool vexpress_cfgctrl_write(arm_sysctl_state *s, unsigned int dcc,
76daa3
         break;
76daa3
     case SYS_CFG_SHUTDOWN:
76daa3
         if (site == SYS_CFG_SITE_MB && device == 0) {
76daa3
-            qemu_system_shutdown_request();
76daa3
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
             return true;
76daa3
         }
76daa3
         break;
76daa3
     case SYS_CFG_REBOOT:
76daa3
         if (site == SYS_CFG_SITE_MB && device == 0) {
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
             return true;
76daa3
         }
76daa3
         break;
76daa3
@@ -429,7 +429,7 @@ static void arm_sysctl_write(void *opaque, hwaddr offset,
76daa3
             if (s->lockval == LOCK_VALUE) {
76daa3
                 s->resetlevel = val;
76daa3
                 if (val & 0x100) {
76daa3
-                    qemu_system_reset_request();
76daa3
+                    qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
                 }
76daa3
             }
76daa3
             break;
76daa3
@@ -438,7 +438,7 @@ static void arm_sysctl_write(void *opaque, hwaddr offset,
76daa3
             if (s->lockval == LOCK_VALUE) {
76daa3
                 s->resetlevel = val;
76daa3
                 if (val & 0x04) {
76daa3
-                    qemu_system_reset_request();
76daa3
+                    qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
                 }
76daa3
             }
76daa3
             break;
76daa3
diff --git a/hw/misc/cbus.c b/hw/misc/cbus.c
76daa3
index 0c207e3..677274c 100644
76daa3
--- a/hw/misc/cbus.c
76daa3
+++ b/hw/misc/cbus.c
76daa3
@@ -356,7 +356,7 @@ static inline void retu_write(CBusRetu *s, int reg, uint16_t val)
76daa3
 
76daa3
     case RETU_REG_WATCHDOG:
76daa3
         if (val == 0 && (s->cc[0] & 2))
76daa3
-            qemu_system_shutdown_request();
76daa3
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
         break;
76daa3
 
76daa3
     case RETU_REG_TXCR:
76daa3
diff --git a/hw/misc/macio/cuda.c b/hw/misc/macio/cuda.c
76daa3
index 05c02fb..008d8bd 100644
76daa3
--- a/hw/misc/macio/cuda.c
76daa3
+++ b/hw/misc/macio/cuda.c
76daa3
@@ -612,7 +612,7 @@ static bool cuda_cmd_powerdown(CUDAState *s,
76daa3
         return false;
76daa3
     }
76daa3
 
76daa3
-    qemu_system_shutdown_request();
76daa3
+    qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
     return true;
76daa3
 }
76daa3
 
76daa3
@@ -624,7 +624,7 @@ static bool cuda_cmd_reset_system(CUDAState *s,
76daa3
         return false;
76daa3
     }
76daa3
 
76daa3
-    qemu_system_reset_request();
76daa3
+    qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     return true;
76daa3
 }
76daa3
 
76daa3
diff --git a/hw/misc/slavio_misc.c b/hw/misc/slavio_misc.c
76daa3
index edd5de0..18ff677 100644
76daa3
--- a/hw/misc/slavio_misc.c
76daa3
+++ b/hw/misc/slavio_misc.c
76daa3
@@ -258,7 +258,7 @@ static void slavio_aux2_mem_writeb(void *opaque, hwaddr addr,
76daa3
         val &= AUX2_PWROFF;
76daa3
     s->aux2 = val;
76daa3
     if (val & AUX2_PWROFF)
76daa3
-        qemu_system_shutdown_request();
76daa3
+        qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
     slavio_misc_update_irq(s);
76daa3
 }
76daa3
 
76daa3
@@ -338,7 +338,7 @@ static void slavio_sysctrl_mem_writel(void *opaque, hwaddr addr,
76daa3
     case 0:
76daa3
         if (val & SYS_RESET) {
76daa3
             s->sysctrl = SYS_RESETSTAT;
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         }
76daa3
         break;
76daa3
     default:
76daa3
diff --git a/hw/misc/zynq_slcr.c b/hw/misc/zynq_slcr.c
76daa3
index 7891219..44304d4 100644
76daa3
--- a/hw/misc/zynq_slcr.c
76daa3
+++ b/hw/misc/zynq_slcr.c
76daa3
@@ -405,7 +405,7 @@ static void zynq_slcr_write(void *opaque, hwaddr offset,
76daa3
     switch (offset) {
76daa3
     case PSS_RST_CTRL:
76daa3
         if (val & R_PSS_RST_CTRL_SOFT_RST) {
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         }
76daa3
         break;
76daa3
     }
76daa3
diff --git a/hw/pci-host/apb.c b/hw/pci-host/apb.c
76daa3
index 653e711..83fc6a9 100644
76daa3
--- a/hw/pci-host/apb.c
76daa3
+++ b/hw/pci-host/apb.c
76daa3
@@ -482,9 +482,9 @@ static void apb_config_writel (void *opaque, hwaddr addr,
76daa3
             s->reset_control |= val & RESET_WMASK;
76daa3
             if (val & SOFT_POR) {
76daa3
                 s->nr_resets = 0;
76daa3
-                qemu_system_reset_request();
76daa3
+                qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
             } else if (val & SOFT_XIR) {
76daa3
-                qemu_system_reset_request();
76daa3
+                qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
             }
76daa3
         }
76daa3
         break;
76daa3
diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
76daa3
index 1999ece..b1d41d0 100644
76daa3
--- a/hw/pci-host/bonito.c
76daa3
+++ b/hw/pci-host/bonito.c
76daa3
@@ -269,7 +269,7 @@ static void bonito_writel(void *opaque, hwaddr addr,
76daa3
         }
76daa3
         s->regs[saddr] = val;
76daa3
         if (reset) {
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         }
76daa3
         break;
76daa3
     case BONITO_INTENSET:
76daa3
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
76daa3
index 7c3b7c1..f6d1ebc 100644
76daa3
--- a/hw/pci-host/piix.c
76daa3
+++ b/hw/pci-host/piix.c
76daa3
@@ -638,7 +638,7 @@ static void rcr_write(void *opaque, hwaddr addr, uint64_t val, unsigned len)
76daa3
     PIIX3State *d = opaque;
76daa3
 
76daa3
     if (val & 4) {
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         return;
76daa3
     }
76daa3
     d->rcr = val & 2; /* keep System Reset type only */
76daa3
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
76daa3
index f7df238..62f1857 100644
76daa3
--- a/hw/ppc/e500.c
76daa3
+++ b/hw/ppc/e500.c
76daa3
@@ -774,7 +774,7 @@ static qemu_irq *ppce500_init_mpic(MachineState *machine, PPCE500Params *params,
76daa3
 static void ppce500_power_off(void *opaque, int line, int on)
76daa3
 {
76daa3
     if (on) {
76daa3
-        qemu_system_shutdown_request();
76daa3
+        qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
     }
76daa3
 }
76daa3
 
76daa3
diff --git a/hw/ppc/mpc8544_guts.c b/hw/ppc/mpc8544_guts.c
76daa3
index ba69178..ce1254b 100644
76daa3
--- a/hw/ppc/mpc8544_guts.c
76daa3
+++ b/hw/ppc/mpc8544_guts.c
76daa3
@@ -98,7 +98,7 @@ static void mpc8544_guts_write(void *opaque, hwaddr addr,
76daa3
     switch (addr) {
76daa3
     case MPC8544_GUTS_ADDR_RSTCR:
76daa3
         if (value & MPC8544_GUTS_RSTCR_RESET) {
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         }
76daa3
         break;
76daa3
     default:
76daa3
diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
76daa3
index 5f93083..224184d 100644
76daa3
--- a/hw/ppc/ppc.c
76daa3
+++ b/hw/ppc/ppc.c
76daa3
@@ -412,7 +412,7 @@ static void ppce500_set_irq(void *opaque, int pin, int level)
76daa3
             if (level) {
76daa3
                 LOG_IRQ("%s: reset the PowerPC system\n",
76daa3
                             __func__);
76daa3
-                qemu_system_reset_request();
76daa3
+                qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
             }
76daa3
             break;
76daa3
         case PPCE500_INPUT_RESET_CORE:
76daa3
diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c
76daa3
index d5df94a..fc32e96 100644
76daa3
--- a/hw/ppc/ppc405_uc.c
76daa3
+++ b/hw/ppc/ppc405_uc.c
76daa3
@@ -1807,7 +1807,7 @@ void ppc40x_chip_reset(PowerPCCPU *cpu)
76daa3
 void ppc40x_system_reset(PowerPCCPU *cpu)
76daa3
 {
76daa3
     printf("Reset PowerPC system\n");
76daa3
-    qemu_system_reset_request();
76daa3
+    qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
 }
76daa3
 
76daa3
 void store_40x_dbcr0 (CPUPPCState *env, uint32_t val)
76daa3
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
76daa3
index 9f18f75..2735fe9 100644
76daa3
--- a/hw/ppc/spapr_hcall.c
76daa3
+++ b/hw/ppc/spapr_hcall.c
76daa3
@@ -1166,7 +1166,7 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
76daa3
     spapr_ovec_cleanup(ov5_updates);
76daa3
 
76daa3
     if (spapr->cas_reboot) {
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     } else {
76daa3
         /* If ppc_spapr_reset() did not set up a HPT but one is necessary
76daa3
          * (because the guest isn't going to use radix) then set it up here. */
76daa3
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
76daa3
index 619f32c..128d993 100644
76daa3
--- a/hw/ppc/spapr_rtas.c
76daa3
+++ b/hw/ppc/spapr_rtas.c
76daa3
@@ -110,7 +110,7 @@ static void rtas_power_off(PowerPCCPU *cpu, sPAPRMachineState *spapr,
76daa3
         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
76daa3
         return;
76daa3
     }
76daa3
-    qemu_system_shutdown_request();
76daa3
+    qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
     cpu_stop_current();
76daa3
     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
76daa3
 }
76daa3
@@ -124,7 +124,7 @@ static void rtas_system_reboot(PowerPCCPU *cpu, sPAPRMachineState *spapr,
76daa3
         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
76daa3
         return;
76daa3
     }
76daa3
-    qemu_system_reset_request();
76daa3
+    qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     rtas_st(rets, 0, RTAS_OUT_SUCCESS);
76daa3
 }
76daa3
 
76daa3
diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
76daa3
index 7978c7d..e5ab0ad 100644
76daa3
--- a/hw/s390x/ipl.c
76daa3
+++ b/hw/s390x/ipl.c
76daa3
@@ -363,7 +363,7 @@ void s390_reipl_request(void)
76daa3
     S390IPLState *ipl = get_ipl_device();
76daa3
 
76daa3
     ipl->reipl_requested = true;
76daa3
-    qemu_system_reset_request();
76daa3
+    qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
 }
76daa3
 
76daa3
 void s390_ipl_prepare_cpu(S390CPU *cpu)
76daa3
diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
76daa3
index 6d06968..117ba9f 100644
76daa3
--- a/hw/sh4/r2d.c
76daa3
+++ b/hw/sh4/r2d.c
76daa3
@@ -164,7 +164,7 @@ r2d_fpga_write(void *opaque, hwaddr addr, uint64_t value, unsigned int size)
76daa3
 	break;
76daa3
     case PA_POWOFF:
76daa3
         if (value & 1) {
76daa3
-            qemu_system_shutdown_request();
76daa3
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
         }
76daa3
         break;
76daa3
     case PA_VERREG:
76daa3
diff --git a/hw/timer/etraxfs_timer.c b/hw/timer/etraxfs_timer.c
76daa3
index 8e18236..d13bc30 100644
76daa3
--- a/hw/timer/etraxfs_timer.c
76daa3
+++ b/hw/timer/etraxfs_timer.c
76daa3
@@ -207,7 +207,7 @@ static void watchdog_hit(void *opaque)
76daa3
         qemu_irq_raise(t->nmi);
76daa3
     }
76daa3
     else
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
 
76daa3
     t->wd_hits++;
76daa3
 }
76daa3
diff --git a/hw/timer/m48t59.c b/hw/timer/m48t59.c
76daa3
index 474981a..4a064fb 100644
76daa3
--- a/hw/timer/m48t59.c
76daa3
+++ b/hw/timer/m48t59.c
76daa3
@@ -1,7 +1,7 @@
76daa3
 /*
76daa3
  * QEMU M48T59 and M48T08 NVRAM emulation for PPC PREP and Sparc platforms
76daa3
  *
76daa3
- * Copyright (c) 2003-2005, 2007 Jocelyn Mayer
76daa3
+ * Copyright (c) 2003-2005, 2007, 2017 Jocelyn Mayer
76daa3
  * Copyright (c) 2013 Hervé Poussineau
76daa3
  *
76daa3
  * Permission is hereby granted, free of charge, to any person obtaining a copy
76daa3
@@ -159,7 +159,7 @@ static void watchdog_cb (void *opaque)
76daa3
 	NVRAM->buffer[0x1FF7] = 0x00;
76daa3
 	NVRAM->buffer[0x1FFC] &= ~0x40;
76daa3
         /* May it be a hw CPU Reset instead ? */
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     } else {
76daa3
 	qemu_set_irq(NVRAM->IRQ, 1);
76daa3
 	qemu_set_irq(NVRAM->IRQ, 0);
76daa3
diff --git a/hw/timer/milkymist-sysctl.c b/hw/timer/milkymist-sysctl.c
76daa3
index 4488590..93bc6e17 100644
76daa3
--- a/hw/timer/milkymist-sysctl.c
76daa3
+++ b/hw/timer/milkymist-sysctl.c
76daa3
@@ -90,7 +90,7 @@ static void sysctl_icap_write(MilkymistSysctlState *s, uint32_t value)
76daa3
     trace_milkymist_sysctl_icap_write(value);
76daa3
     switch (value & 0xffff) {
76daa3
     case 0x000e:
76daa3
-        qemu_system_shutdown_request();
76daa3
+        qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
         break;
76daa3
     }
76daa3
 }
76daa3
@@ -195,7 +195,7 @@ static void sysctl_write(void *opaque, hwaddr addr, uint64_t value,
76daa3
         s->regs[addr] = 1;
76daa3
         break;
76daa3
     case R_SYSTEM_ID:
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         break;
76daa3
 
76daa3
     case R_GPIO_IN:
76daa3
diff --git a/hw/timer/pxa2xx_timer.c b/hw/timer/pxa2xx_timer.c
76daa3
index 59002b4..68ba5a7 100644
76daa3
--- a/hw/timer/pxa2xx_timer.c
76daa3
+++ b/hw/timer/pxa2xx_timer.c
76daa3
@@ -401,7 +401,7 @@ static void pxa2xx_timer_tick(void *opaque)
76daa3
     if (t->num == 3)
76daa3
         if (i->reset3 & 1) {
76daa3
             i->reset3 = 0;
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         }
76daa3
 }
76daa3
 
76daa3
diff --git a/hw/watchdog/watchdog.c b/hw/watchdog/watchdog.c
76daa3
index 2aeaf1f..0c5c9cd 100644
76daa3
--- a/hw/watchdog/watchdog.c
76daa3
+++ b/hw/watchdog/watchdog.c
76daa3
@@ -110,7 +110,7 @@ void watchdog_perform_action(void)
76daa3
     switch (watchdog_action) {
76daa3
     case WDT_RESET:             /* same as 'system_reset' in monitor */
76daa3
         qapi_event_send_watchdog(WATCHDOG_EXPIRATION_ACTION_RESET, &error_abort);
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         break;
76daa3
 
76daa3
     case WDT_SHUTDOWN:          /* same as 'system_powerdown' in monitor */
76daa3
diff --git a/hw/xenpv/xen_domainbuild.c b/hw/xenpv/xen_domainbuild.c
76daa3
index 457a897..c89ced2 100644
76daa3
--- a/hw/xenpv/xen_domainbuild.c
76daa3
+++ b/hw/xenpv/xen_domainbuild.c
76daa3
@@ -148,7 +148,7 @@ static void xen_domain_poll(void *opaque)
76daa3
     return;
76daa3
 
76daa3
 quit:
76daa3
-    qemu_system_shutdown_request();
76daa3
+    qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
 }
76daa3
 
76daa3
 static int xen_domain_watcher(void)
76daa3
diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
76daa3
index 11176e2..4636f8e 100644
76daa3
--- a/hw/xtensa/xtfpga.c
76daa3
+++ b/hw/xtensa/xtfpga.c
76daa3
@@ -100,7 +100,7 @@ static void lx60_fpga_write(void *opaque, hwaddr addr,
76daa3
 
76daa3
     case 0x10: /*board reset*/
76daa3
         if (val == 0xdead) {
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         }
76daa3
         break;
76daa3
     }
76daa3
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
76daa3
index f942562..01a2c67 100644
76daa3
--- a/include/sysemu/sysemu.h
76daa3
+++ b/include/sysemu/sysemu.h
76daa3
@@ -62,13 +62,13 @@ typedef enum WakeupReason {
76daa3
     QEMU_WAKEUP_REASON_OTHER,
76daa3
 } WakeupReason;
76daa3
 
76daa3
-void qemu_system_reset_request(void);
76daa3
+void qemu_system_reset_request(ShutdownCause reason);
76daa3
 void qemu_system_suspend_request(void);
76daa3
 void qemu_register_suspend_notifier(Notifier *notifier);
76daa3
 void qemu_system_wakeup_request(WakeupReason reason);
76daa3
 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
76daa3
 void qemu_register_wakeup_notifier(Notifier *notifier);
76daa3
-void qemu_system_shutdown_request(void);
76daa3
+void qemu_system_shutdown_request(ShutdownCause reason);
76daa3
 void qemu_system_powerdown_request(void);
76daa3
 void qemu_register_powerdown_notifier(Notifier *notifier);
76daa3
 void qemu_system_debug_request(void);
76daa3
diff --git a/kvm-all.c b/kvm-all.c
76daa3
index cc86415..4322aa3 100644
76daa3
--- a/kvm-all.c
76daa3
+++ b/kvm-all.c
76daa3
@@ -2074,7 +2074,7 @@ int kvm_cpu_exec(CPUState *cpu)
76daa3
             break;
76daa3
         case KVM_EXIT_SHUTDOWN:
76daa3
             DPRINTF("shutdown\n");
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
             ret = EXCP_INTERRUPT;
76daa3
             break;
76daa3
         case KVM_EXIT_UNKNOWN:
76daa3
@@ -2088,11 +2088,11 @@ int kvm_cpu_exec(CPUState *cpu)
76daa3
         case KVM_EXIT_SYSTEM_EVENT:
76daa3
             switch (run->system_event.type) {
76daa3
             case KVM_SYSTEM_EVENT_SHUTDOWN:
76daa3
-                qemu_system_shutdown_request();
76daa3
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
                 ret = EXCP_INTERRUPT;
76daa3
                 break;
76daa3
             case KVM_SYSTEM_EVENT_RESET:
76daa3
-                qemu_system_reset_request();
76daa3
+                qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
                 ret = EXCP_INTERRUPT;
76daa3
                 break;
76daa3
             case KVM_SYSTEM_EVENT_CRASH:
76daa3
diff --git a/os-win32.c b/os-win32.c
76daa3
index ae98574..586a7c7 100644
76daa3
--- a/os-win32.c
76daa3
+++ b/os-win32.c
76daa3
@@ -52,7 +52,7 @@ int setenv(const char *name, const char *value, int overwrite)
76daa3
 
76daa3
 static BOOL WINAPI qemu_ctrl_handler(DWORD type)
76daa3
 {
76daa3
-    qemu_system_shutdown_request();
76daa3
+    qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_SIGNAL);
76daa3
     /* Windows 7 kills application when the function returns.
76daa3
        Sleep here to give QEMU a try for closing.
76daa3
        Sleep period is 10000ms because Windows kills the program
76daa3
diff --git a/qmp.c b/qmp.c
76daa3
index 847b13f..e00359e 100644
76daa3
--- a/qmp.c
76daa3
+++ b/qmp.c
76daa3
@@ -84,7 +84,7 @@ UuidInfo *qmp_query_uuid(Error **errp)
76daa3
 void qmp_quit(Error **errp)
76daa3
 {
76daa3
     no_shutdown = 0;
76daa3
-    qemu_system_shutdown_request();
76daa3
+    qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP);
76daa3
 }
76daa3
 
76daa3
 void qmp_stop(Error **errp)
76daa3
@@ -105,7 +105,7 @@ void qmp_stop(Error **errp)
76daa3
 
76daa3
 void qmp_system_reset(Error **errp)
76daa3
 {
76daa3
-    qemu_system_reset_request();
76daa3
+    qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP);
76daa3
 }
76daa3
 
76daa3
 void qmp_system_powerdown(Error **erp)
76daa3
diff --git a/replay/replay.c b/replay/replay.c
76daa3
index bf94e81..ff58a5a 100644
76daa3
--- a/replay/replay.c
76daa3
+++ b/replay/replay.c
76daa3
@@ -51,8 +51,8 @@ bool replay_next_event_is(int event)
76daa3
         switch (replay_state.data_kind) {
76daa3
         case EVENT_SHUTDOWN ... EVENT_SHUTDOWN_LAST:
76daa3
             replay_finish_event();
76daa3
-            /* TODO - pass replay_state.data_kind - EVENT_SHUTDOWN as cause */
76daa3
-            qemu_system_shutdown_request();
76daa3
+            qemu_system_shutdown_request(replay_state.data_kind -
76daa3
+                                         EVENT_SHUTDOWN);
76daa3
             break;
76daa3
         default:
76daa3
             /* clock, time_t, checkpoint and other events */
76daa3
diff --git a/target/alpha/sys_helper.c b/target/alpha/sys_helper.c
76daa3
index 652195d..ac22323 100644
76daa3
--- a/target/alpha/sys_helper.c
76daa3
+++ b/target/alpha/sys_helper.c
76daa3
@@ -60,9 +60,9 @@ void helper_tb_flush(CPUAlphaState *env)
76daa3
 void helper_halt(uint64_t restart)
76daa3
 {
76daa3
     if (restart) {
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
     } else {
76daa3
-        qemu_system_shutdown_request();
76daa3
+        qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
     }
76daa3
 }
76daa3
 
76daa3
diff --git a/target/arm/psci.c b/target/arm/psci.c
76daa3
index ade9fe2..fc34b26 100644
76daa3
--- a/target/arm/psci.c
76daa3
+++ b/target/arm/psci.c
76daa3
@@ -137,7 +137,7 @@ void arm_handle_psci_call(ARMCPU *cpu)
76daa3
         }
76daa3
         break;
76daa3
     case QEMU_PSCI_0_2_FN_SYSTEM_RESET:
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         /* QEMU reset and shutdown are async requests, but PSCI
76daa3
          * mandates that we never return from the reset/shutdown
76daa3
          * call, so power the CPU off now so it doesn't execute
76daa3
@@ -145,7 +145,7 @@ void arm_handle_psci_call(ARMCPU *cpu)
76daa3
          */
76daa3
         goto cpu_off;
76daa3
     case QEMU_PSCI_0_2_FN_SYSTEM_OFF:
76daa3
-        qemu_system_shutdown_request();
76daa3
+        qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
         goto cpu_off;
76daa3
     case QEMU_PSCI_0_1_FN_CPU_ON:
76daa3
     case QEMU_PSCI_0_2_FN_CPU_ON:
76daa3
diff --git a/target/i386/excp_helper.c b/target/i386/excp_helper.c
76daa3
index ee596c6..b769772 100644
76daa3
--- a/target/i386/excp_helper.c
76daa3
+++ b/target/i386/excp_helper.c
76daa3
@@ -59,7 +59,7 @@ static int check_exception(CPUX86State *env, int intno, int *error_code,
76daa3
 
76daa3
         qemu_log_mask(CPU_LOG_RESET, "Triple fault\n");
76daa3
 
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         return EXCP_HLT;
76daa3
     }
76daa3
 #endif
76daa3
diff --git a/target/i386/hax-all.c b/target/i386/hax-all.c
76daa3
index ef13015..7346931 100644
76daa3
--- a/target/i386/hax-all.c
76daa3
+++ b/target/i386/hax-all.c
76daa3
@@ -540,14 +540,14 @@ static int hax_vcpu_hax_exec(CPUArchState *env)
76daa3
         /* Guest state changed, currently only for shutdown */
76daa3
         case HAX_EXIT_STATECHANGE:
76daa3
             fprintf(stdout, "VCPU shutdown request\n");
76daa3
-            qemu_system_shutdown_request();
76daa3
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
             hax_vcpu_sync_state(env, 0);
76daa3
             ret = 1;
76daa3
             break;
76daa3
         case HAX_EXIT_UNKNOWN_VMEXIT:
76daa3
             fprintf(stderr, "Unknown VMX exit %x from guest\n",
76daa3
                     ht->_exit_reason);
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
             hax_vcpu_sync_state(env, 0);
76daa3
             cpu_dump_state(cpu, stderr, fprintf, 0);
76daa3
             ret = -1;
76daa3
@@ -578,7 +578,7 @@ static int hax_vcpu_hax_exec(CPUArchState *env)
76daa3
             break;
76daa3
         default:
76daa3
             fprintf(stderr, "Unknown exit %x from HAX\n", ht->_exit_status);
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
             hax_vcpu_sync_state(env, 0);
76daa3
             cpu_dump_state(cpu, stderr, fprintf, 0);
76daa3
             ret = 1;
76daa3
diff --git a/target/i386/helper.c b/target/i386/helper.c
76daa3
index f11cac6..ee7eff2 100644
76daa3
--- a/target/i386/helper.c
76daa3
+++ b/target/i386/helper.c
76daa3
@@ -1212,7 +1212,7 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
76daa3
                            " triple fault\n",
76daa3
                            cs->cpu_index);
76daa3
             qemu_log_mask(CPU_LOG_RESET, "Triple fault\n");
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
             return;
76daa3
         }
76daa3
         if (banks[1] & MCI_STATUS_VAL) {
76daa3
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
76daa3
index 55865db..cfd7695 100644
76daa3
--- a/target/i386/kvm.c
76daa3
+++ b/target/i386/kvm.c
76daa3
@@ -2930,7 +2930,7 @@ int kvm_arch_process_async_events(CPUState *cs)
76daa3
 
76daa3
         if (env->exception_injected == EXCP08_DBLE) {
76daa3
             /* this means triple fault */
76daa3
-            qemu_system_reset_request();
76daa3
+            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
             cs->exit_request = 1;
76daa3
             return 0;
76daa3
         }
76daa3
diff --git a/target/s390x/helper.c b/target/s390x/helper.c
76daa3
index 68bd2f9..d2bb9aa 100644
76daa3
--- a/target/s390x/helper.c
76daa3
+++ b/target/s390x/helper.c
76daa3
@@ -266,7 +266,7 @@ void load_psw(CPUS390XState *env, uint64_t mask, uint64_t addr)
76daa3
         S390CPU *cpu = s390_env_get_cpu(env);
76daa3
         if (s390_cpu_halt(cpu) == 0) {
76daa3
 #ifndef CONFIG_USER_ONLY
76daa3
-            qemu_system_shutdown_request();
76daa3
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
 #endif
76daa3
         }
76daa3
     }
76daa3
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
76daa3
index ac47154..c2ffcd6 100644
76daa3
--- a/target/s390x/kvm.c
76daa3
+++ b/target/s390x/kvm.c
76daa3
@@ -1929,7 +1929,7 @@ static int handle_intercept(S390CPU *cpu)
76daa3
             cpu_synchronize_state(cs);
76daa3
             if (s390_cpu_halt(cpu) == 0) {
76daa3
                 if (is_special_wait_psw(cs)) {
76daa3
-                    qemu_system_shutdown_request();
76daa3
+                    qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
                 } else {
76daa3
                     qemu_system_guest_panicked(NULL);
76daa3
                 }
76daa3
@@ -1938,7 +1938,7 @@ static int handle_intercept(S390CPU *cpu)
76daa3
             break;
76daa3
         case ICPT_CPU_STOP:
76daa3
             if (s390_cpu_set_state(CPU_STATE_STOPPED, cpu) == 0) {
76daa3
-                qemu_system_shutdown_request();
76daa3
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
             }
76daa3
             if (cpu->env.sigp_order == SIGP_STOP_STORE_STATUS) {
76daa3
                 kvm_s390_store_status(cpu, KVM_S390_STORE_STATUS_DEF_ADDR,
76daa3
diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c
76daa3
index 93b0e61..0473fab 100644
76daa3
--- a/target/s390x/misc_helper.c
76daa3
+++ b/target/s390x/misc_helper.c
76daa3
@@ -530,11 +530,11 @@ uint32_t HELPER(sigp)(CPUS390XState *env, uint64_t order_code, uint32_t r1,
76daa3
         break;
76daa3
 #if !defined(CONFIG_USER_ONLY)
76daa3
     case SIGP_RESTART:
76daa3
-        qemu_system_reset_request();
76daa3
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
76daa3
         cpu_loop_exit(CPU(s390_env_get_cpu(env)));
76daa3
         break;
76daa3
     case SIGP_STOP:
76daa3
-        qemu_system_shutdown_request();
76daa3
+        qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
         cpu_loop_exit(CPU(s390_env_get_cpu(env)));
76daa3
         break;
76daa3
 #endif
76daa3
diff --git a/target/sparc/int32_helper.c b/target/sparc/int32_helper.c
76daa3
index 09afe13..eec9a4d 100644
76daa3
--- a/target/sparc/int32_helper.c
76daa3
+++ b/target/sparc/int32_helper.c
76daa3
@@ -109,7 +109,7 @@ void sparc_cpu_do_interrupt(CPUState *cs)
76daa3
     if (env->psret == 0) {
76daa3
         if (cs->exception_index == 0x80 &&
76daa3
             env->def->features & CPU_FEATURE_TA0_SHUTDOWN) {
76daa3
-            qemu_system_shutdown_request();
76daa3
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
76daa3
         } else {
76daa3
             cpu_abort(cs, "Trap 0x%02x while interrupts disabled, Error state",
76daa3
                       cs->exception_index);
76daa3
diff --git a/trace-events b/trace-events
76daa3
index b07a09b..4db44d0 100644
76daa3
--- a/trace-events
76daa3
+++ b/trace-events
76daa3
@@ -38,7 +38,7 @@ vm_state_notify(int running, int reason) "running %d reason %d"
76daa3
 load_file(const char *name, const char *path) "name %s location %s"
76daa3
 runstate_set(int new_state) "new state %d"
76daa3
 system_wakeup_request(int reason) "reason=%d"
76daa3
-qemu_system_shutdown_request(void) ""
76daa3
+qemu_system_shutdown_request(int reason) "reason=%d"
76daa3
 qemu_system_powerdown_request(void) ""
76daa3
 
76daa3
 # spice-qemu-char.c
76daa3
diff --git a/ui/cocoa.m b/ui/cocoa.m
76daa3
index c81f7b6..ff29e48 100644
76daa3
--- a/ui/cocoa.m
76daa3
+++ b/ui/cocoa.m
76daa3
@@ -905,7 +905,7 @@ QemuCocoaView *cocoaView;
76daa3
 {
76daa3
     COCOA_DEBUG("QemuCocoaAppController: applicationWillTerminate\n");
76daa3
 
76daa3
-    qemu_system_shutdown_request();
76daa3
+    qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI);
76daa3
     exit(0);
76daa3
 }
76daa3
 
76daa3
diff --git a/ui/sdl.c b/ui/sdl.c
76daa3
index 37c21a0..bd51ffd 100644
76daa3
--- a/ui/sdl.c
76daa3
+++ b/ui/sdl.c
76daa3
@@ -837,7 +837,7 @@ static void sdl_refresh(DisplayChangeListener *dcl)
76daa3
         case SDL_QUIT:
76daa3
             if (!no_quit) {
76daa3
                 no_shutdown = 0;
76daa3
-                qemu_system_shutdown_request();
76daa3
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI);
76daa3
             }
76daa3
             break;
76daa3
         case SDL_MOUSEMOTION:
76daa3
diff --git a/ui/sdl2.c b/ui/sdl2.c
76daa3
index faf9bdf..e092636 100644
76daa3
--- a/ui/sdl2.c
76daa3
+++ b/ui/sdl2.c
76daa3
@@ -568,7 +568,7 @@ static void handle_windowevent(SDL_Event *ev)
76daa3
     case SDL_WINDOWEVENT_CLOSE:
76daa3
         if (!no_quit) {
76daa3
             no_shutdown = 0;
76daa3
-            qemu_system_shutdown_request();
76daa3
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI);
76daa3
         }
76daa3
         break;
76daa3
     case SDL_WINDOWEVENT_SHOWN:
76daa3
@@ -611,7 +611,7 @@ void sdl2_poll_events(struct sdl2_console *scon)
76daa3
         case SDL_QUIT:
76daa3
             if (!no_quit) {
76daa3
                 no_shutdown = 0;
76daa3
-                qemu_system_shutdown_request();
76daa3
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI);
76daa3
             }
76daa3
             break;
76daa3
         case SDL_MOUSEMOTION:
76daa3
diff --git a/vl.c b/vl.c
76daa3
index 18fdef2..76d7708 100644
76daa3
--- a/vl.c
76daa3
+++ b/vl.c
76daa3
@@ -1723,7 +1723,7 @@ void qemu_system_guest_panicked(GuestPanicInformation *info)
76daa3
     if (!no_shutdown) {
76daa3
         qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_POWEROFF,
76daa3
                                        !!info, info, &error_abort);
76daa3
-        qemu_system_shutdown_request();
76daa3
+        qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_PANIC);
76daa3
     }
76daa3
 
76daa3
     if (info) {
76daa3
@@ -1740,13 +1740,12 @@ void qemu_system_guest_panicked(GuestPanicInformation *info)
76daa3
     }
76daa3
 }
76daa3
 
76daa3
-void qemu_system_reset_request(void)
76daa3
+void qemu_system_reset_request(ShutdownCause reason)
76daa3
 {
76daa3
     if (no_reboot) {
76daa3
-        /* TODO - add a parameter to allow callers to specify reason */
76daa3
-        shutdown_requested = SHUTDOWN_CAUSE_HOST_ERROR;
76daa3
+        shutdown_requested = reason;
76daa3
     } else {
76daa3
-        reset_requested = SHUTDOWN_CAUSE_HOST_ERROR;
76daa3
+        reset_requested = reason;
76daa3
     }
76daa3
     cpu_stop_current();
76daa3
     qemu_notify_event();
76daa3
@@ -1817,12 +1816,11 @@ void qemu_system_killed(int signal, pid_t pid)
76daa3
     qemu_notify_event();
76daa3
 }
76daa3
 
76daa3
-void qemu_system_shutdown_request(void)
76daa3
+void qemu_system_shutdown_request(ShutdownCause reason)
76daa3
 {
76daa3
-    trace_qemu_system_shutdown_request();
76daa3
-    /* TODO - add a parameter to allow callers to specify reason */
76daa3
-    replay_shutdown_request(SHUTDOWN_CAUSE_HOST_ERROR);
76daa3
-    shutdown_requested = SHUTDOWN_CAUSE_HOST_ERROR;
76daa3
+    trace_qemu_system_shutdown_request(reason);
76daa3
+    replay_shutdown_request(reason);
76daa3
+    shutdown_requested = reason;
76daa3
     qemu_notify_event();
76daa3
 }
76daa3
 
76daa3
diff --git a/xen-hvm.c b/xen-hvm.c
76daa3
index 858e934..09d3190 100644
76daa3
--- a/xen-hvm.c
76daa3
+++ b/xen-hvm.c
76daa3
@@ -1391,7 +1391,7 @@ void xen_shutdown_fatal_error(const char *fmt, ...)
76daa3
     va_end(ap);
76daa3
     fprintf(stderr, "Will destroy the domain.\n");
76daa3
     /* destroy the domain */
76daa3
-    qemu_system_shutdown_request();
76daa3
+    qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_ERROR);
76daa3
 }
76daa3
 
76daa3
 void xen_modified_memory(ram_addr_t start, ram_addr_t length)
76daa3
-- 
76daa3
1.8.3.1
76daa3