ia64/xen-unstable

changeset 19499:567d312e80ad

hvm: add ACPI power button for HVM

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

Signed-off-by: Kouya Shimura <kouya@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Apr 02 12:40:09 2009 +0100 (2009-04-02)
parents cb5b609c4164
children 59fff20323b1
files tools/firmware/hvmloader/acpi/static_tables.c tools/python/xen/xend/XendConstants.py tools/python/xen/xm/main.py xen/arch/x86/domctl.c xen/arch/x86/hvm/pmtimer.c xen/include/public/domctl.h
line diff
     1.1 --- a/tools/firmware/hvmloader/acpi/static_tables.c	Thu Apr 02 11:48:32 2009 +0100
     1.2 +++ b/tools/firmware/hvmloader/acpi/static_tables.c	Thu Apr 02 12:40:09 2009 +0100
     1.3 @@ -69,7 +69,7 @@ struct acpi_20_fadt Fadt = {
     1.4      .p_lvl3_lat = 0x0fff, /* >1000, means we do not support C3 state */
     1.5      .iapc_boot_arch = ACPI_8042,
     1.6      .flags = (ACPI_PROC_C1 | ACPI_SLP_BUTTON |
     1.7 -              ACPI_WBINVD | ACPI_PWR_BUTTON |
     1.8 +              ACPI_WBINVD |
     1.9                ACPI_FIX_RTC | ACPI_TMR_VAL_EXT),
    1.10  
    1.11      .reset_reg = {
     2.1 --- a/tools/python/xen/xend/XendConstants.py	Thu Apr 02 11:48:32 2009 +0100
     2.2 +++ b/tools/python/xen/xend/XendConstants.py	Thu Apr 02 12:40:09 2009 +0100
     2.3 @@ -105,13 +105,15 @@ LAST_SHUTDOWN_REASON = 'xend/last_shutdo
     2.4  TRIGGER_NMI   = 0
     2.5  TRIGGER_RESET = 1
     2.6  TRIGGER_INIT  = 2
     2.7 -TRIGGER_S3RESUME = 3
     2.8 +TRIGGER_POWER = 3
     2.9 +TRIGGER_S3RESUME = 4
    2.10  
    2.11  TRIGGER_TYPE = {
    2.12      "nmi"   : TRIGGER_NMI,
    2.13      "reset" : TRIGGER_RESET,
    2.14      "init"  : TRIGGER_INIT,
    2.15 -    "s3resume": TRIGGER_S3RESUME
    2.16 +    "s3resume": TRIGGER_S3RESUME,
    2.17 +    "power": TRIGGER_POWER
    2.18  }
    2.19  
    2.20  #
     3.1 --- a/tools/python/xen/xm/main.py	Thu Apr 02 11:48:32 2009 +0100
     3.2 +++ b/tools/python/xen/xm/main.py	Thu Apr 02 12:40:09 2009 +0100
     3.3 @@ -151,7 +151,7 @@ SUBCOMMAND_HELP = {
     3.4                       'Get/set credit scheduler parameters.'),
     3.5      'sysrq'       : ('<Domain> <letter>', 'Send a sysrq to a domain.'),
     3.6      'debug-keys'  : ('<Keys>', 'Send debug keys to Xen.'),
     3.7 -    'trigger'     : ('<Domain> <nmi|reset|init|s3resume> [<VCPU>]',
     3.8 +    'trigger'     : ('<Domain> <nmi|reset|init|s3resume|power> [<VCPU>]',
     3.9                       'Send a trigger to a domain.'),
    3.10      'vcpu-list'   : ('[Domain, ...]',
    3.11                       'List the VCPUs for all/some domains.'),
     4.1 --- a/xen/arch/x86/domctl.c	Thu Apr 02 11:48:32 2009 +0100
     4.2 +++ b/xen/arch/x86/domctl.c	Thu Apr 02 12:40:09 2009 +0100
     4.3 @@ -587,6 +587,19 @@ long arch_do_domctl(
     4.4          }
     4.5          break;
     4.6  
     4.7 +        case XEN_DOMCTL_SENDTRIGGER_POWER:
     4.8 +        {
     4.9 +            extern void hvm_acpi_power_button(struct domain *d);
    4.10 +
    4.11 +            ret = -EINVAL;
    4.12 +            if ( is_hvm_domain(d) ) 
    4.13 +            {
    4.14 +                ret = 0;
    4.15 +                hvm_acpi_power_button(d);
    4.16 +            }
    4.17 +        }
    4.18 +        break;
    4.19 +
    4.20          default:
    4.21              ret = -ENOSYS;
    4.22          }
     5.1 --- a/xen/arch/x86/hvm/pmtimer.c	Thu Apr 02 11:48:32 2009 +0100
     5.2 +++ b/xen/arch/x86/hvm/pmtimer.c	Thu Apr 02 12:40:09 2009 +0100
     5.3 @@ -29,18 +29,15 @@
     5.4  
     5.5  /* The interesting bits of the PM1a_STS register */
     5.6  #define TMR_STS    (1 << 0)
     5.7 -#define PWRBTN_STS (1 << 5)
     5.8 -#define GBL_STS    (1 << 8)
     5.9 +#define GBL_STS    (1 << 5)
    5.10 +#define PWRBTN_STS (1 << 8)
    5.11  
    5.12  /* The same in PM1a_EN */
    5.13  #define TMR_EN     (1 << 0)
    5.14 -#define PWRBTN_EN  (1 << 5)
    5.15 -#define GBL_EN     (1 << 8)
    5.16 +#define GBL_EN     (1 << 5)
    5.17 +#define PWRBTN_EN  (1 << 8)
    5.18  
    5.19 -/* Mask of bits in PM1a_STS that can generate an SCI.  Although the ACPI
    5.20 - * spec lists other bits, the PIIX4, which we are emulating, only
    5.21 - * supports these three.  For now, we only use TMR_STS; in future we
    5.22 - * will let qemu set the other bits */
    5.23 +/* Mask of bits in PM1a_STS that can generate an SCI. */
    5.24  #define SCI_MASK (TMR_STS|PWRBTN_STS|GBL_STS) 
    5.25  
    5.26  /* SCI IRQ number (must match SCI_INT number in ACPI FADT in hvmloader) */
    5.27 @@ -61,6 +58,15 @@ static void pmt_update_sci(PMTState *s)
    5.28          hvm_isa_irq_deassert(s->vcpu->domain, SCI_IRQ);
    5.29  }
    5.30  
    5.31 +void hvm_acpi_power_button(struct domain *d)
    5.32 +{
    5.33 +    PMTState *s = &d->arch.hvm_domain.pl_time.vpmt;
    5.34 +    spin_lock(&s->lock);
    5.35 +    s->pm.pm1a_sts |= PWRBTN_STS;
    5.36 +    pmt_update_sci(s);
    5.37 +    spin_unlock(&s->lock);
    5.38 +}
    5.39 +
    5.40  /* Set the correct value in the timer, accounting for time elapsed
    5.41   * since the last time we did that. */
    5.42  static void pmt_update_time(PMTState *s)
     6.1 --- a/xen/include/public/domctl.h	Thu Apr 02 11:48:32 2009 +0100
     6.2 +++ b/xen/include/public/domctl.h	Thu Apr 02 12:40:09 2009 +0100
     6.3 @@ -433,6 +433,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_real_
     6.4  #define XEN_DOMCTL_SENDTRIGGER_NMI    0
     6.5  #define XEN_DOMCTL_SENDTRIGGER_RESET  1
     6.6  #define XEN_DOMCTL_SENDTRIGGER_INIT   2
     6.7 +#define XEN_DOMCTL_SENDTRIGGER_POWER  3
     6.8  struct xen_domctl_sendtrigger {
     6.9      uint32_t  trigger;  /* IN */
    6.10      uint32_t  vcpu;     /* IN */