* [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power.
@ 2010-01-13 10:16 Paul Durrant
2010-01-13 10:16 ` [PATCH 1 of 2] Add ACPI fixed sleep button for HVM Paul Durrant
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Paul Durrant @ 2010-01-13 10:16 UTC (permalink / raw)
To: xen-devel; +Cc: paul.durrant
The first patch in this series adds a static ACPI sleep button to HVM guests
(akin to the power button that was added some time ago). The second patch
adds support into libxenlight for pressing either the power or sleep buttons.
Paul
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 1 of 2] Add ACPI fixed sleep button for HVM 2010-01-13 10:16 [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power Paul Durrant @ 2010-01-13 10:16 ` Paul Durrant 2010-01-13 11:01 ` Ian Campbell 2010-01-13 10:16 ` [PATCH 2 of 2] Add support to libxl to trigger power or sleep button pushes Paul Durrant 2010-01-13 10:30 ` [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power Pasi Kärkkäinen 2 siblings, 1 reply; 9+ messages in thread From: Paul Durrant @ 2010-01-13 10:16 UTC (permalink / raw) To: xen-devel; +Cc: paul.durrant # HG changeset patch # User Paul Durrant <paul.durrant@citrix.com> # Date 1263377694 0 # Node ID cdf348c11aba31171bdc838ffe3a457acab0f7de # Parent 13d4e78ede977ee92c4a4adf78a92b31ec52c00e Add ACPI fixed sleep button for HVM. signed-off-by: Paul Durrant <paul.durrant@citrix.com> diff -r 13d4e78ede97 -r cdf348c11aba tools/firmware/hvmloader/acpi/static_tables.c --- a/tools/firmware/hvmloader/acpi/static_tables.c Wed Jan 13 08:33:34 2010 +0000 +++ b/tools/firmware/hvmloader/acpi/static_tables.c Wed Jan 13 10:14:54 2010 +0000 @@ -68,7 +68,7 @@ .p_lvl2_lat = 0x0fff, /* >100, means we do not support C2 state */ .p_lvl3_lat = 0x0fff, /* >1000, means we do not support C3 state */ .iapc_boot_arch = ACPI_8042, - .flags = (ACPI_PROC_C1 | ACPI_SLP_BUTTON | + .flags = (ACPI_PROC_C1 | ACPI_WBINVD | ACPI_FIX_RTC | ACPI_TMR_VAL_EXT), diff -r 13d4e78ede97 -r cdf348c11aba xen/arch/x86/domctl.c --- a/xen/arch/x86/domctl.c Wed Jan 13 08:33:34 2010 +0000 +++ b/xen/arch/x86/domctl.c Wed Jan 13 10:14:54 2010 +0000 @@ -723,6 +723,19 @@ { ret = 0; hvm_acpi_power_button(d); + } + } + break; + + case XEN_DOMCTL_SENDTRIGGER_SLEEP: + { + extern void hvm_acpi_sleep_button(struct domain *d); + + ret = -EINVAL; + if ( is_hvm_domain(d) ) + { + ret = 0; + hvm_acpi_sleep_button(d); } } break; diff -r 13d4e78ede97 -r cdf348c11aba xen/arch/x86/hvm/pmtimer.c --- a/xen/arch/x86/hvm/pmtimer.c Wed Jan 13 08:33:34 2010 +0000 +++ b/xen/arch/x86/hvm/pmtimer.c Wed Jan 13 10:14:54 2010 +0000 @@ -32,14 +32,16 @@ #define TMR_STS (1 << 0) #define GBL_STS (1 << 5) #define PWRBTN_STS (1 << 8) +#define SLPBTN_STS (1 << 9) /* The same in PM1a_EN */ #define TMR_EN (1 << 0) #define GBL_EN (1 << 5) #define PWRBTN_EN (1 << 8) +#define SLPBTN_EN (1 << 9) /* Mask of bits in PM1a_STS that can generate an SCI. */ -#define SCI_MASK (TMR_STS|PWRBTN_STS|GBL_STS) +#define SCI_MASK (TMR_STS|PWRBTN_STS|SLPBTN_STS|GBL_STS) /* SCI IRQ number (must match SCI_INT number in ACPI FADT in hvmloader) */ #define SCI_IRQ 9 @@ -64,6 +66,15 @@ 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); +} + +void hvm_acpi_sleep_button(struct domain *d) +{ + PMTState *s = &d->arch.hvm_domain.pl_time.vpmt; + spin_lock(&s->lock); + s->pm.pm1a_sts |= SLPBTN_STS; pmt_update_sci(s); spin_unlock(&s->lock); } diff -r 13d4e78ede97 -r cdf348c11aba xen/include/public/domctl.h --- a/xen/include/public/domctl.h Wed Jan 13 08:33:34 2010 +0000 +++ b/xen/include/public/domctl.h Wed Jan 13 10:14:54 2010 +0000 @@ -439,6 +439,7 @@ #define XEN_DOMCTL_SENDTRIGGER_RESET 1 #define XEN_DOMCTL_SENDTRIGGER_INIT 2 #define XEN_DOMCTL_SENDTRIGGER_POWER 3 +#define XEN_DOMCTL_SENDTRIGGER_SLEEP 4 struct xen_domctl_sendtrigger { uint32_t trigger; /* IN */ uint32_t vcpu; /* IN */ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1 of 2] Add ACPI fixed sleep button for HVM 2010-01-13 10:16 ` [PATCH 1 of 2] Add ACPI fixed sleep button for HVM Paul Durrant @ 2010-01-13 11:01 ` Ian Campbell 0 siblings, 0 replies; 9+ messages in thread From: Ian Campbell @ 2010-01-13 11:01 UTC (permalink / raw) To: Paul Durrant; +Cc: xen-devel@lists.xensource.com On Wed, 2010-01-13 at 10:16 +0000, Paul Durrant wrote: > + case XEN_DOMCTL_SENDTRIGGER_SLEEP: > + { > + extern void hvm_acpi_sleep_button(struct domain *d); I think this belongs in xen/include/asm-x86/acpi.h Ian. ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2 of 2] Add support to libxl to trigger power or sleep button pushes 2010-01-13 10:16 [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power Paul Durrant 2010-01-13 10:16 ` [PATCH 1 of 2] Add ACPI fixed sleep button for HVM Paul Durrant @ 2010-01-13 10:16 ` Paul Durrant 2010-01-13 11:00 ` Vincent Hanquez 2010-01-13 10:30 ` [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power Pasi Kärkkäinen 2 siblings, 1 reply; 9+ messages in thread From: Paul Durrant @ 2010-01-13 10:16 UTC (permalink / raw) To: xen-devel; +Cc: paul.durrant # HG changeset patch # User Paul Durrant <paul.durrant@citrix.com> # Date 1263377694 0 # Node ID 679f0a189c7280053cc172d1ed80b6312702f4d8 # Parent cdf348c11aba31171bdc838ffe3a457acab0f7de Add support to libxl to trigger power or sleep button pushes in HVM guests. signed-off-by: Paul Durrant <paul.durrant@citrix.com> diff -r cdf348c11aba -r 679f0a189c72 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Jan 13 10:14:54 2010 +0000 +++ b/tools/libxl/libxl.c Wed Jan 13 10:14:54 2010 +0000 @@ -2153,3 +2153,21 @@ rc = xc_domain_memory_set_pod_target(ctx->xch, domid, (target_memkb - videoram) / 4, NULL, NULL, NULL); return rc; } + +int libxl_button_press(struct libxl_ctx *ctx, uint32_t domid, libxl_button button) +{ + int rc = -1; + + switch (button) { + case POWER_BUTTON: + rc = xc_domain_send_trigger(ctx->xch, domid, XEN_DOMCTL_SENDTRIGGER_POWER, 0); + break; + case SLEEP_BUTTON: + rc = xc_domain_send_trigger(ctx->xch, domid, XEN_DOMCTL_SENDTRIGGER_SLEEP, 0); + break; + default: + break; + } + + return rc; +} diff -r cdf348c11aba -r 679f0a189c72 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Jan 13 10:14:54 2010 +0000 +++ b/tools/libxl/libxl.h Wed Jan 13 10:14:54 2010 +0000 @@ -343,4 +343,12 @@ unsigned int bus, unsigned int dev, unsigned int func, unsigned int vdevfn); -#endif +typedef enum { + POWER_BUTTON, + SLEEP_BUTTON +} libxl_button; + +int libxl_button_press(struct libxl_ctx *ctx, uint32_t domid, libxl_button button); + +#endif /* LIBXL_H */ + diff -r cdf348c11aba -r 679f0a189c72 tools/libxl/xl.c --- a/tools/libxl/xl.c Wed Jan 13 10:14:54 2010 +0000 +++ b/tools/libxl/xl.c Wed Jan 13 10:14:54 2010 +0000 @@ -933,6 +933,7 @@ printf(" cd-insert insert a cdrom into a guest's cd drive\n\n"); printf(" cd-eject eject a cdrom from a guest's cd drive\n\n"); printf(" mem-set set the current memory usage for a domain\n\n"); + printf(" button-press indicate an ACPI button press to the domain\n\n"); } else if(!strcmp(command, "create")) { printf("Usage: xl create <ConfigFile> [options] [vars]\n\n"); printf("Create a domain based on <ConfigFile>.\n\n"); @@ -986,6 +987,10 @@ } else if (!strcmp(command, "mem-set")) { printf("Usage: xl mem-set <Domain> <MemKB>\n\n"); printf("Set the current memory usage for a domain.\n\n"); + } else if (!strcmp(command, "button-press")) { + printf("Usage: xl button-press <Domain> <Button>\n\n"); + printf("Indicate <Button> press to a domain.\n"); + printf("<Button> may be 'power' or 'sleep'.\n\n"); } } @@ -1668,6 +1673,60 @@ exit(0); } +void button_press(char *p, char *b) +{ + struct libxl_ctx ctx; + uint32_t domid; + libxl_button button; + + libxl_ctx_init(&ctx, LIBXL_VERSION); + libxl_ctx_set_log(&ctx, log_callback, NULL); + + if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) { + fprintf(stderr, "%s is an invalid domain identifier\n", p); + exit(2); + } + + if (!strcmp(b, "power")) { + button = POWER_BUTTON; + } else if (!strcmp(b, "sleep")) { + button = SLEEP_BUTTON; + } else { + fprintf(stderr, "%s is an invalid button identifier\n", b); + exit(2); + } + + libxl_button_press(&ctx, domid, button); +} + +int main_button_press(int argc, char **argv) +{ + int opt; + char *p; + char *b; + + while ((opt = getopt(argc, argv, "h")) != -1) { + switch (opt) { + case 'h': + help("button-press"); + exit(0); + default: + fprintf(stderr, "option not supported\n"); + break; + } + } + if (optind >= argc - 1) { + help("button-press"); + exit(2); + } + + p = argv[optind]; + b = argv[optind + 1]; + + button_press(p, b); + exit(0); +} + int main(int argc, char **argv) { if (argc < 2) { @@ -1705,6 +1764,8 @@ main_cd_eject(argc - 1, argv + 1); } else if (!strcmp(argv[1], "mem-set")) { main_memset(argc - 1, argv + 1); + } else if (!strcmp(argv[1], "button-press")) { + main_button_press(argc - 1, argv + 1); } else if (!strcmp(argv[1], "help")) { if (argc > 2) help(argv[2]); ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2 of 2] Add support to libxl to trigger power or sleep button pushes 2010-01-13 10:16 ` [PATCH 2 of 2] Add support to libxl to trigger power or sleep button pushes Paul Durrant @ 2010-01-13 11:00 ` Vincent Hanquez 0 siblings, 0 replies; 9+ messages in thread From: Vincent Hanquez @ 2010-01-13 11:00 UTC (permalink / raw) To: Paul Durrant; +Cc: xen-devel@lists.xensource.com Paul Durrant wrote: > # HG changeset patch > # User Paul Durrant <paul.durrant@citrix.com> > # Date 1263377694 0 > # Node ID 679f0a189c7280053cc172d1ed80b6312702f4d8 > # Parent cdf348c11aba31171bdc838ffe3a457acab0f7de > Add support to libxl to trigger power or sleep button pushes > in HVM guests. Thanks ! Acked-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com> minor comment inline (but can be applied nonetheless): > +void button_press(char *p, char *b) > +{ > + struct libxl_ctx ctx; > + uint32_t domid; > + libxl_button button; > + > + libxl_ctx_init(&ctx, LIBXL_VERSION); ctx_init can fails in bad situation; it is always better to check the return value just in case. > + libxl_ctx_set_log(&ctx, log_callback, NULL); > + > + if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) { > + fprintf(stderr, "%s is an invalid domain identifier\n", p); > + exit(2); > + } > + > + if (!strcmp(b, "power")) { > + button = POWER_BUTTON; > + } else if (!strcmp(b, "sleep")) { > + button = SLEEP_BUTTON; > + } else { > + fprintf(stderr, "%s is an invalid button identifier\n", b); > + exit(2); > + } > + > + libxl_button_press(&ctx, domid, button); > +} > + and while it doesn't matter because the program is short lived, you're suppose to call libxl_ctx_free when you're done with libxl. -- Vincent Hanquez ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power. 2010-01-13 10:16 [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power Paul Durrant 2010-01-13 10:16 ` [PATCH 1 of 2] Add ACPI fixed sleep button for HVM Paul Durrant 2010-01-13 10:16 ` [PATCH 2 of 2] Add support to libxl to trigger power or sleep button pushes Paul Durrant @ 2010-01-13 10:30 ` Pasi Kärkkäinen 2010-01-13 10:37 ` Paul Durrant 2010-01-13 12:46 ` Ian Pratt 2 siblings, 2 replies; 9+ messages in thread From: Pasi Kärkkäinen @ 2010-01-13 10:30 UTC (permalink / raw) To: Paul Durrant; +Cc: xen-devel On Wed, Jan 13, 2010 at 10:16:10AM +0000, Paul Durrant wrote: > The first patch in this series adds a static ACPI sleep button to HVM guests > (akin to the power button that was added some time ago). The second patch > adds support into libxenlight for pressing either the power or sleep buttons. > So HVM guests without PV drivers can now be shutdown using ACPI.. Is there 'xm' command for this aswell? -- Pasi ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power. 2010-01-13 10:30 ` [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power Pasi Kärkkäinen @ 2010-01-13 10:37 ` Paul Durrant 2010-01-14 0:39 ` Kouya Shimura 2010-01-13 12:46 ` Ian Pratt 1 sibling, 1 reply; 9+ messages in thread From: Paul Durrant @ 2010-01-13 10:37 UTC (permalink / raw) To: Pasi Kärkkäinen; +Cc: xen-devel@lists.xensource.com Pasi Kärkkäinen wrote: > On Wed, Jan 13, 2010 at 10:16:10AM +0000, Paul Durrant wrote: >> The first patch in this series adds a static ACPI sleep button to HVM guests >> (akin to the power button that was added some time ago). The second patch >> adds support into libxenlight for pressing either the power or sleep buttons. >> > So HVM guests without PV drivers can now be shutdown using ACPI.. Yep :-) > Is there 'xm' command for this aswell? > No, I didn't have time to do an xm command for it. You can obviously use the xl command even on a domain started with xm though. Paul -- =============================== Paul Durrant, Software Engineer Citrix Systems (R&D) Ltd. First Floor, Building 101 Cambridge Science Park Milton Road Cambridge CB4 0FY United Kingdom =============================== ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power. 2010-01-13 10:37 ` Paul Durrant @ 2010-01-14 0:39 ` Kouya Shimura 0 siblings, 0 replies; 9+ messages in thread From: Kouya Shimura @ 2010-01-14 0:39 UTC (permalink / raw) To: Paul Durrant; +Cc: xen-devel@lists.xensource.com "xm trigger <Domain> power" has worked since xen-3.4.0. It's quite easy to add support "xm trigger <Domain> sleep". -- Kouya Paul Durrant writes: > Pasi Kärkkäinen wrote: > > On Wed, Jan 13, 2010 at 10:16:10AM +0000, Paul Durrant wrote: > >> The first patch in this series adds a static ACPI sleep button to HVM guests > >> (akin to the power button that was added some time ago). The second patch > >> adds support into libxenlight for pressing either the power or sleep buttons. > >> > > So HVM guests without PV drivers can now be shutdown using ACPI.. > > Yep :-) > > > Is there 'xm' command for this aswell? > > > > No, I didn't have time to do an xm command for it. You can obviously use > the xl command even on a domain started with xm though. > > Paul > > -- > =============================== > Paul Durrant, Software Engineer > > Citrix Systems (R&D) Ltd. > First Floor, Building 101 > Cambridge Science Park > Milton Road > Cambridge CB4 0FY > United Kingdom > =============================== > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel ^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power. 2010-01-13 10:30 ` [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power Pasi Kärkkäinen 2010-01-13 10:37 ` Paul Durrant @ 2010-01-13 12:46 ` Ian Pratt 1 sibling, 0 replies; 9+ messages in thread From: Ian Pratt @ 2010-01-13 12:46 UTC (permalink / raw) To: Pasi Kärkkäinen, Paul Durrant Cc: Ian Pratt, xen-devel@lists.xensource.com > So HVM guests without PV drivers can now be shutdown using ACPI.. > Is there 'xm' command for this aswell? Well, they'll do whatever the guest is internally configured to do when the power button is pressed e.g. nothing/shutdown/sleep/hibernate/crash It is possible to send an ACPI "fatal" event that will likely result in the system shutting down. However, the shutdown certainly isn't as graceful as a user initiated one -- I know windows doesn't prompt you to save files or close programs; I don't know if it even notifies user space applications. We could add ACPI support for 'Fatal' events, though someone would need to volunteer to do some more testing to understand the effects on different OSes. Ian ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-01-14 0:39 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-01-13 10:16 [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power Paul Durrant 2010-01-13 10:16 ` [PATCH 1 of 2] Add ACPI fixed sleep button for HVM Paul Durrant 2010-01-13 11:01 ` Ian Campbell 2010-01-13 10:16 ` [PATCH 2 of 2] Add support to libxl to trigger power or sleep button pushes Paul Durrant 2010-01-13 11:00 ` Vincent Hanquez 2010-01-13 10:30 ` [PATCH 0 of 2] Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power Pasi Kärkkäinen 2010-01-13 10:37 ` Paul Durrant 2010-01-14 0:39 ` Kouya Shimura 2010-01-13 12:46 ` Ian Pratt
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).