[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] hvm: add ACPI power button for HVM



Hi,

This patch adds the ACPI fixed hardware power button for HVM.
It enables a graceful shutdown of a guest OS by direction of Dom0.
(if a proper action for the power button is set inside the guest)

usage:
  xm trigger <Domain> power

It would be nice to get in for xen-3.4...

Thanks,
Kouya

Signed-off-by: Kouya Shimura <kouya@xxxxxxxxxxxxxx>

diff -r b5e7c26835c9 tools/firmware/hvmloader/acpi/static_tables.c
--- a/tools/firmware/hvmloader/acpi/static_tables.c     Wed Apr 01 16:20:30 
2009 +0100
+++ b/tools/firmware/hvmloader/acpi/static_tables.c     Thu Apr 02 15:35:15 
2009 +0900
@@ -69,7 +69,7 @@ struct acpi_20_fadt Fadt = {
     .p_lvl3_lat = 0x0fff, /* >1000, means we do not support C3 state */
     .iapc_boot_arch = ACPI_8042,
     .flags = (ACPI_PROC_C1 | ACPI_SLP_BUTTON |
-              ACPI_WBINVD | ACPI_PWR_BUTTON |
+              ACPI_WBINVD |
               ACPI_FIX_RTC | ACPI_TMR_VAL_EXT),
 
     .reset_reg = {
diff -r b5e7c26835c9 tools/python/xen/xend/XendConstants.py
--- a/tools/python/xen/xend/XendConstants.py    Wed Apr 01 16:20:30 2009 +0100
+++ b/tools/python/xen/xend/XendConstants.py    Thu Apr 02 15:35:15 2009 +0900
@@ -106,12 +106,14 @@ TRIGGER_RESET = 1
 TRIGGER_RESET = 1
 TRIGGER_INIT  = 2
 TRIGGER_S3RESUME = 3
+TRIGGER_POWER = 4
 
 TRIGGER_TYPE = {
     "nmi"   : TRIGGER_NMI,
     "reset" : TRIGGER_RESET,
     "init"  : TRIGGER_INIT,
-    "s3resume": TRIGGER_S3RESUME
+    "s3resume": TRIGGER_S3RESUME,
+    "power": TRIGGER_POWER
 }
 
 #
diff -r b5e7c26835c9 tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py       Wed Apr 01 16:20:30 2009 +0100
+++ b/tools/python/xen/xm/main.py       Thu Apr 02 15:35:15 2009 +0900
@@ -151,7 +151,7 @@ SUBCOMMAND_HELP = {
                      'Get/set credit scheduler parameters.'),
     'sysrq'       : ('<Domain> <letter>', 'Send a sysrq to a domain.'),
     'debug-keys'  : ('<Keys>', 'Send debug keys to Xen.'),
-    'trigger'     : ('<Domain> <nmi|reset|init|s3resume> [<VCPU>]',
+    'trigger'     : ('<Domain> <nmi|reset|init|s3resume|power> [<VCPU>]',
                      'Send a trigger to a domain.'),
     'vcpu-list'   : ('[Domain, ...]',
                      'List the VCPUs for all/some domains.'),
diff -r b5e7c26835c9 xen/arch/x86/domctl.c
--- a/xen/arch/x86/domctl.c     Wed Apr 01 16:20:30 2009 +0100
+++ b/xen/arch/x86/domctl.c     Thu Apr 02 15:35:15 2009 +0900
@@ -584,6 +584,19 @@ long arch_do_domctl(
             ret = 0;
             if ( !test_and_set_bool(v->nmi_pending) )
                 vcpu_kick(v);
+        }
+        break;
+
+        case XEN_DOMCTL_SENDTRIGGER_POWER:
+        {
+            extern void hvm_acpi_power_button(struct domain *d);
+
+            ret = -EINVAL;
+            if ( is_hvm_domain(d) ) 
+            {
+                ret = 0;
+                hvm_acpi_power_button(d);
+            }
         }
         break;
 
diff -r b5e7c26835c9 xen/arch/x86/hvm/pmtimer.c
--- a/xen/arch/x86/hvm/pmtimer.c        Wed Apr 01 16:20:30 2009 +0100
+++ b/xen/arch/x86/hvm/pmtimer.c        Thu Apr 02 15:35:15 2009 +0900
@@ -29,13 +29,13 @@
 
 /* The interesting bits of the PM1a_STS register */
 #define TMR_STS    (1 << 0)
-#define PWRBTN_STS (1 << 5)
-#define GBL_STS    (1 << 8)
+#define GBL_STS    (1 << 5)
+#define PWRBTN_STS (1 << 8)
 
 /* The same in PM1a_EN */
 #define TMR_EN     (1 << 0)
-#define PWRBTN_EN  (1 << 5)
-#define GBL_EN     (1 << 8)
+#define GBL_EN     (1 << 5)
+#define PWRBTN_EN  (1 << 8)
 
 /* Mask of bits in PM1a_STS that can generate an SCI.  Although the ACPI
  * spec lists other bits, the PIIX4, which we are emulating, only
@@ -59,6 +59,15 @@ static void pmt_update_sci(PMTState *s)
         hvm_isa_irq_assert(s->vcpu->domain, SCI_IRQ);
     else
         hvm_isa_irq_deassert(s->vcpu->domain, SCI_IRQ);
+}
+
+void hvm_acpi_power_button(struct domain *d)
+{
+    PMTState *s = &d->arch.hvm_domain.pl_time.vpmt;
+    spin_lock(&s->lock);
+    s->pm.pm1a_sts |= PWRBTN_STS;
+    pmt_update_sci(s);
+    spin_unlock(&s->lock);
 }
 
 /* Set the correct value in the timer, accounting for time elapsed
diff -r b5e7c26835c9 xen/include/public/domctl.h
--- a/xen/include/public/domctl.h       Wed Apr 01 16:20:30 2009 +0100
+++ b/xen/include/public/domctl.h       Thu Apr 02 15:35:15 2009 +0900
@@ -430,9 +430,11 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_real_
 
 
 #define XEN_DOMCTL_sendtrigger       28
-#define XEN_DOMCTL_SENDTRIGGER_NMI    0
-#define XEN_DOMCTL_SENDTRIGGER_RESET  1
-#define XEN_DOMCTL_SENDTRIGGER_INIT   2
+#define XEN_DOMCTL_SENDTRIGGER_NMI          0
+#define XEN_DOMCTL_SENDTRIGGER_RESET        1
+#define XEN_DOMCTL_SENDTRIGGER_INIT         2
+#define XEN_DOMCTL_SENDTRIGGER_S3RESUME     3
+#define XEN_DOMCTL_SENDTRIGGER_POWER        4
 struct xen_domctl_sendtrigger {
     uint32_t  trigger;  /* IN */
     uint32_t  vcpu;     /* IN */
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.