initial suspend support
v4 cover initial suspend support
Hi,
Next round, this time with a proper acpi integration as auggested by gleb. Also features some acpi cleanup bits. New is pmtimer support, which is not tested yet though. Commit messages are still a bit rougth, but I expect I'll need a v5 anyway so I try to get that one quickly out of the door for review, especially on the infrastructure bits (patch #5 now).
cheers,
Gerd
Gerd Hoffmann (11):
acpi: move around structs
acpi: add ACPIREGS
acpi: don't pass overflow_time to acpi_pm1_evt_get_sts
acpi: add acpi_pm1_evt_write_en
suspend: add infrastructure
suspend: switch acpi s3 to new infrastructure.
suspend: add system_wakeup monitor command
suspend: make ps/2 devices wakeup the guest
suspend: make serial ports wakeup the guest.
suspend: make rtc alarm wakeup the guest.
suspend: pmtimer s3 wakeup
hmp-commands.hx | 14 +++++ hmp.c | 5 ++ hmp.h | 1 + hw/acpi.c | 172 +++++++++++++++++++++++++++++++----------------------- hw/acpi.h | 93 ++++++++++++++++------------- hw/acpi_piix4.c | 70 ++++++++++------------ hw/mc146818rtc.c | 13 ++++ hw/mips_malta.c | 2 +- hw/pc.c | 11 ---- hw/pc.h | 3 +- hw/pc_piix.c | 8 +-- hw/ps2.c | 6 ++ hw/serial.c | 6 ++ hw/vt82c686.c | 42 ++++++------- qapi-schema.json | 11 ++++ qmp-commands.hx | 21 +++++++ qmp.c | 5 ++ sysemu.h | 11 ++++ vl.c | 49 +++++++++++++++ xen-all.c | 11 ++-- 20 files changed, 355 insertions(+), 199 deletions(-)
PATCH v4 1/11 acpi: move around structs
--- hw/acpi.h | 48 +++++++++++++++++++++++------------------------- 1 files changed, 23 insertions(+), 25 deletions(-)
hw/acpi.h +23 -25
@@ -73,9 +73,11 @@/* PM2_CNT */ #define ACPI_BITMASK_ARB_DISABLE 0x0001 -/* PM_TMR */ -struct ACPIPMTimer ; +/* structs */ typedef struct ACPIPMTimer ACPIPMTimer ; +typedef struct ACPIPM1EVT ACPIPM1EVT ; +typedef struct ACPIPM1CNT ACPIPM1CNT ; +typedef struct ACPIGPE ACPIGPE ;typedef void (*acpi_update_sci_fn )(ACPIPMTimer *tmr);
@@ -86,6 +88,25 @@ struct ACPIPMTimer {acpi_update_sci_fn update_sci; }; +struct ACPIPM1EVT { +uint16_t sts; +uint16_t en; +}; + +struct ACPIPM1CNT { +uint16_t cnt; +qemu_irq cmos_s3; +}; + +struct ACPIGPE { +uint32_t blk; +uint8_t len; + +uint8_t *sts; +uint8_t *en; +}; + +/* PM_TMR */ void acpi_pm_tmr_update (ACPIPMTimer *tmr,bool enable);void acpi_pm_tmr_calc_overflow_time (ACPIPMTimer *tmr);uint32_t acpi_pm_tmr_get (ACPIPMTimer *tmr);
@@ -100,26 +121,12 @@ static inline int64_t acpi_pm_tmr_get_clock(void) }/* PM1a_EVT: piix and ich9 don't implement PM1b. */ -struct ACPIPM1EVT -{ -uint16_t sts; -uint16_t en; -}; -typedef struct ACPIPM1EVT ACPIPM1EVT ; -uint16_t acpi_pm1_evt_get_sts (ACPIPM1EVT *pm1,int64_t overflow_time);void acpi_pm1_evt_write_sts (ACPIPM1EVT *pm1,ACPIPMTimer *tmr,uint16_t val);void acpi_pm1_evt_power_down (ACPIPM1EVT *pm1,ACPIPMTimer *tmr);void acpi_pm1_evt_reset (ACPIPM1EVT *pm1);/* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */ -struct ACPIPM1CNT { -uint16_t cnt; - -qemu_irq cmos_s3; -}; -typedef struct ACPIPM1CNT ACPIPM1CNT ; -void acpi_pm1_cnt_init (ACPIPM1CNT *pm1_cnt,qemu_irq cmos_s3);void acpi_pm1_cnt_write (ACPIPM1EVT *pm1a,ACPIPM1CNT *pm1_cnt,uint16_t val); void acpi_pm1_cnt_update(ACPIPM1CNT *pm1_cnt,
@@ -127,15 +134,6 @@ void acpi_pm1_cnt_update(ACPIPM1CNT *pm1_cnt,void acpi_pm1_cnt_reset (ACPIPM1CNT *pm1_cnt);/* GPE0 */ -struct ACPIGPE { -uint32_t blk; -uint8_t len; - -uint8_t *sts; -uint8_t *en; -}; -typedef struct ACPIGPE ACPIGPE ; -void acpi_gpe_init (ACPIGPE *gpe,uint8_t len);void acpi_gpe_blk (ACPIGPE *gpe,uint32_t blk);void acpi_gpe_reset (ACPIGPE *gpe);
Signature · 1 line
1.7.1
PATCH v4 2/11 acpi: add ACPIREGS
In reply to Gerd Hoffmannbundle acpi structs there, use it everythere pass around acpi state.
--- hw/acpi.c | 130 +++++++++++++++++++++++++++---------------------------- hw/acpi.h | 48 ++++++++++++-------- hw/acpi_piix4.c | 68 +++++++++++++--------------- hw/vt82c686.c | 42 ++++++++--------- 4 files changed, 145 insertions(+), 143 deletions(-)
hw/acpi.c +64 -66
@@ -249,63 +249,61 @@ int acpi_table_add(const char *t) }/* ACPI PM1a EVT */ -uint16_t acpi_pm1_evt_get_sts (ACPIPM1EVT *pm1,int64_t overflow_time) +uint16_t acpi_pm1_evt_get_sts (ACPIREGS *ar,int64_t overflow_time) {int64_t d =acpi_pm_tmr_get_clock ();if (d >= overflow_time) { - pm1->sts |=ACPI_BITMASK_TIMER_STATUS ; + ar->pm1.evt.sts |=ACPI_BITMASK_TIMER_STATUS ; } -return pm1->sts; +return ar->pm1.evt.sts; } -void acpi_pm1_evt_write_sts (ACPIPM1EVT *pm1,ACPIPMTimer *tmr,uint16_t val) +void acpi_pm1_evt_write_sts (ACPIREGS *ar,uint16_t val) { -uint16_t pm1_sts =acpi_pm1_evt_get_sts (pm1, tmr->overflow_time); +uint16_t pm1_sts =acpi_pm1_evt_get_sts (ar, ar->tmr.overflow_time);if (pm1_sts & val &ACPI_BITMASK_TIMER_STATUS ) {/* if TMRSTS is reset, then compute the new overflow time */ -acpi_pm_tmr_calc_overflow_time (tmr); +acpi_pm_tmr_calc_overflow_time (ar); } - pm1->sts &= ~val; + ar->pm1.evt.sts &= ~val; } -void acpi_pm1_evt_power_down (ACPIPM1EVT *pm1,ACPIPMTimer *tmr) +void acpi_pm1_evt_power_down (ACPIREGS *ar) { -if (!pm1) { -qemu_system_shutdown_request (); - }else if (pm1->en &ACPI_BITMASK_POWER_BUTTON_ENABLE ) { - pm1->sts |=ACPI_BITMASK_POWER_BUTTON_STATUS ; - tmr->update_sci (tmr); +if (ar->pm1.evt.en &ACPI_BITMASK_POWER_BUTTON_ENABLE ) { + ar->pm1.evt.sts |=ACPI_BITMASK_POWER_BUTTON_STATUS ; + ar->tmr.update_sci (ar); } } -void acpi_pm1_evt_reset (ACPIPM1EVT *pm1) +void acpi_pm1_evt_reset (ACPIREGS *ar) { - pm1->sts =0 ; - pm1->en =0 ; + ar->pm1.evt.sts =0 ; + ar->pm1.evt.en =0 ; }/* ACPI PM_TMR */ -void acpi_pm_tmr_update (ACPIPMTimer *tmr,bool enable) +void acpi_pm_tmr_update (ACPIREGS *ar,bool enable) {int64_t expire_time;/* schedule a timer interruption if needed */ if (enable) { - expire_time =muldiv64 (tmr->overflow_time,get_ticks_per_sec (), + expire_time =muldiv64 (ar->tmr.overflow_time,get_ticks_per_sec (),PM_TIMER_FREQUENCY ); -qemu_mod_timer (tmr->timer, expire_time); +qemu_mod_timer (ar->tmr.timer, expire_time); }else { -qemu_del_timer (tmr->timer); +qemu_del_timer (ar->tmr.timer); } } -void acpi_pm_tmr_calc_overflow_time (ACPIPMTimer *tmr) +void acpi_pm_tmr_calc_overflow_time (ACPIREGS *ar) {int64_t d =acpi_pm_tmr_get_clock (); - tmr->overflow_time = (d +0x800000LL ) & ~0x7fffffLL ; + ar->tmr.overflow_time = (d +0x800000LL ) & ~0x7fffffLL ; } -uint32_t acpi_pm_tmr_get (ACPIPMTimer *tmr) +uint32_t acpi_pm_tmr_get (ACPIREGS *ar) {uint32_t d =acpi_pm_tmr_get_clock ();return d &0xffffff ;
@@ -313,31 +311,31 @@ uint32_t acpi_pm_tmr_get(ACPIPMTimer *tmr)static void acpi_pm_tmr_timer (void *opaque) { -ACPIPMTimer *tmr = opaque; - tmr->update_sci (tmr); +ACPIREGS *ar = opaque; + ar->tmr.update_sci (ar); } -void acpi_pm_tmr_init (ACPIPMTimer *tmr,acpi_update_sci_fn update_sci) +void acpi_pm_tmr_init (ACPIREGS *ar,acpi_update_sci_fn update_sci) { - tmr->update_sci = update_sci; - tmr->timer =qemu_new_timer_ns (vm_clock, acpi_pm_tmr_timer, tmr); + ar->tmr.update_sci = update_sci; + ar->tmr.timer =qemu_new_timer_ns (vm_clock, acpi_pm_tmr_timer, ar); } -void acpi_pm_tmr_reset (ACPIPMTimer *tmr) +void acpi_pm_tmr_reset (ACPIREGS *ar) { - tmr->overflow_time =0 ; -qemu_del_timer (tmr->timer); + ar->tmr.overflow_time =0 ; +qemu_del_timer (ar->tmr.timer); }/* ACPI PM1aCNT */ -void acpi_pm1_cnt_init (ACPIPM1CNT *pm1_cnt,qemu_irq cmos_s3) +void acpi_pm1_cnt_init (ACPIREGS *ar,qemu_irq cmos_s3) { - pm1_cnt->cmos_s3 = cmos_s3; + ar->pm1.cnt.cmos_s3 = cmos_s3; } -void acpi_pm1_cnt_write (ACPIPM1EVT *pm1a,ACPIPM1CNT *pm1_cnt,uint16_t val) +void acpi_pm1_cnt_write (ACPIREGS *ar,uint16_t val) { - pm1_cnt->cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE ); + ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE );if (val &ACPI_BITMASK_SLEEP_ENABLE ) {/* change suspend type */
@@ -349,62 +347,62 @@ void acpi_pm1_cnt_write(ACPIPM1EVT *pm1a, ACPIPM1CNT *pm1_cnt, uint16_t val)case 1 :/* ACPI_BITMASK_WAKE_STATUS should be set on resume. Pretend that resume was caused by power button */ - pm1a->sts |= + ar->pm1.evt.sts |= (ACPI_BITMASK_WAKE_STATUS |ACPI_BITMASK_POWER_BUTTON_STATUS );qemu_system_reset_request (); -qemu_irq_raise (pm1_cnt->cmos_s3); +qemu_irq_raise (ar->pm1.cnt.cmos_s3);default :break ; } } } -void acpi_pm1_cnt_update (ACPIPM1CNT *pm1_cnt, +void acpi_pm1_cnt_update (ACPIREGS *ar,bool sci_enable,bool sci_disable) {/* ACPI specs 3.0, 4.7.2.5 */ if (sci_enable) { - pm1_cnt->cnt |=ACPI_BITMASK_SCI_ENABLE ; + ar->pm1.cnt.cnt |=ACPI_BITMASK_SCI_ENABLE ; }else if (sci_disable) { - pm1_cnt->cnt &= ~ACPI_BITMASK_SCI_ENABLE ; + ar->pm1.cnt.cnt &= ~ACPI_BITMASK_SCI_ENABLE ; } } -void acpi_pm1_cnt_reset (ACPIPM1CNT *pm1_cnt) +void acpi_pm1_cnt_reset (ACPIREGS *ar) { - pm1_cnt->cnt =0 ; -if (pm1_cnt->cmos_s3) { -qemu_irq_lower (pm1_cnt->cmos_s3); + ar->pm1.cnt.cnt =0 ; +if (ar->pm1.cnt.cmos_s3) { +qemu_irq_lower (ar->pm1.cnt.cmos_s3); } }/* ACPI GPE */ -void acpi_gpe_init (ACPIGPE *gpe,uint8_t len) +void acpi_gpe_init (ACPIREGS *ar,uint8_t len) { - gpe->len = len; - gpe->sts =g_malloc0 (len /2 ); - gpe->en =g_malloc0 (len /2 ); + ar->gpe.len = len; + ar->gpe.sts =g_malloc0 (len /2 ); + ar->gpe.en =g_malloc0 (len /2 ); } -void acpi_gpe_blk (ACPIGPE *gpe,uint32_t blk) +void acpi_gpe_blk (ACPIREGS *ar,uint32_t blk) { - gpe->blk = blk; + ar->gpe.blk = blk; } -void acpi_gpe_reset (ACPIGPE *gpe) +void acpi_gpe_reset (ACPIREGS *ar) { -memset (gpe->sts,0 , gpe->len /2 ); -memset (gpe->en,0 , gpe->len /2 ); +memset (ar->gpe.sts,0 , ar->gpe.len /2 ); +memset (ar->gpe.en,0 , ar->gpe.len /2 ); } -static uint8_t *acpi_gpe_ioport_get_ptr (ACPIGPE *gpe,uint32_t addr) +static uint8_t *acpi_gpe_ioport_get_ptr (ACPIREGS *ar,uint32_t addr) {uint8_t *cur =NULL ; -if (addr < gpe->len /2 ) { - cur = gpe->sts + addr; - }else if (addr < gpe->len) { - cur = gpe->en + addr - gpe->len /2 ; +if (addr < ar->gpe.len /2 ) { + cur = ar->gpe.sts + addr; + }else if (addr < ar->gpe.len) { + cur = ar->gpe.en + addr - ar->gpe.len /2 ; }else {abort (); }
@@ -412,16 +410,16 @@ static uint8_t *acpi_gpe_ioport_get_ptr(ACPIGPE *gpe, uint32_t addr)return cur; } -void acpi_gpe_ioport_writeb (ACPIGPE *gpe,uint32_t addr,uint32_t val) +void acpi_gpe_ioport_writeb (ACPIREGS *ar,uint32_t addr,uint32_t val) {uint8_t *cur; - addr -= gpe->blk; - cur =acpi_gpe_ioport_get_ptr (gpe, addr); -if (addr < gpe->len /2 ) { + addr -= ar->gpe.blk; + cur =acpi_gpe_ioport_get_ptr (ar, addr); +if (addr < ar->gpe.len /2 ) {/* GPE_STS */ *cur = (*cur) & ~val; - }else if (addr < gpe->len) { + }else if (addr < ar->gpe.len) {/* GPE_EN */ *cur = val; }else {
@@ -429,13 +427,13 @@ void acpi_gpe_ioport_writeb(ACPIGPE *gpe, uint32_t addr, uint32_t val) } } -uint32_t acpi_gpe_ioport_readb (ACPIGPE *gpe,uint32_t addr) +uint32_t acpi_gpe_ioport_readb (ACPIREGS *ar,uint32_t addr) {uint8_t *cur;uint32_t val; - addr -= gpe->blk; - cur =acpi_gpe_ioport_get_ptr (gpe, addr); + addr -= ar->gpe.blk; + cur =acpi_gpe_ioport_get_ptr (ar, addr); val =0 ;if (cur !=NULL ) { val = *cur;
hw/acpi.h +29 -19
73 lines not on this page · raw message
hw/acpi_piix4.c +32 -36
185 lines not on this page · raw message
hw/vt82c686.c +20 -22
106 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v4 3/11 acpi: don't pass overflow_time to acpi_pm1_evt_get_sts
In reply to Gerd HoffmannPretty pointless, can be reached via ACPIREGS now.
--- hw/acpi.c | 6 +++--- hw/acpi.h | 2 +- hw/acpi_piix4.c | 4 ++-- hw/vt82c686.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)
hw/acpi.c +3 -3
@@ -249,10 +249,10 @@ int acpi_table_add(const char *t) }/* ACPI PM1a EVT */ -uint16_t acpi_pm1_evt_get_sts (ACPIREGS *ar,int64_t overflow_time) +uint16_t acpi_pm1_evt_get_sts (ACPIREGS *ar) {int64_t d =acpi_pm_tmr_get_clock (); -if (d >= overflow_time) { +if (d >= ar->tmr.overflow_time) { ar->pm1.evt.sts |=ACPI_BITMASK_TIMER_STATUS ; }return ar->pm1.evt.sts;
@@ -260,7 +260,7 @@ uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar, int64_t overflow_time)void acpi_pm1_evt_write_sts (ACPIREGS *ar,uint16_t val) { -uint16_t pm1_sts =acpi_pm1_evt_get_sts (ar, ar->tmr.overflow_time); +uint16_t pm1_sts =acpi_pm1_evt_get_sts (ar);if (pm1_sts & val &ACPI_BITMASK_TIMER_STATUS ) {/* if TMRSTS is reset, then compute the new overflow time */ acpi_pm_tmr_calc_overflow_time (ar);
hw/acpi.h +1 -1
@@ -131,7 +131,7 @@ static inline int64_t acpi_pm_tmr_get_clock(void) }/* PM1a_EVT: piix and ich9 don't implement PM1b. */ -uint16_t acpi_pm1_evt_get_sts (ACPIREGS *ar,int64_t overflow_time); +uint16_t acpi_pm1_evt_get_sts (ACPIREGS *ar);void acpi_pm1_evt_write_sts (ACPIREGS *ar,uint16_t val);void acpi_pm1_evt_power_down (ACPIREGS *ar);void acpi_pm1_evt_reset (ACPIREGS *ar);
hw/acpi_piix4.c +2 -2
@@ -80,7 +80,7 @@ static void pm_update_sci(PIIX4PMState *s) {int sci_level, pmsts; - pmsts =acpi_pm1_evt_get_sts (&s->ar, s->ar.tmr.overflow_time); + pmsts =acpi_pm1_evt_get_sts (&s->ar); sci_level = (((pmsts & s->ar.pm1.evt.en) & (ACPI_BITMASK_RT_CLOCK_ENABLE | ACPI_BITMASK_POWER_BUTTON_ENABLE |
@@ -138,7 +138,7 @@ static void pm_ioport_read(IORange *ioport, uint64_t addr, unsigned width,switch (addr) {case 0x00 : - val =acpi_pm1_evt_get_sts (&s->ar, s->ar.tmr.overflow_time); + val =acpi_pm1_evt_get_sts (&s->ar);break ;case 0x02 : val = s->ar.pm1.evt.en;
hw/vt82c686.c +2 -2
@@ -177,7 +177,7 @@ static void pm_update_sci(VT686PMState *s) {int sci_level, pmsts; - pmsts =acpi_pm1_evt_get_sts (&s->ar, s->ar.tmr.overflow_time); + pmsts =acpi_pm1_evt_get_sts (&s->ar); sci_level = (((pmsts & s->ar.pm1.evt.en) & (ACPI_BITMASK_RT_CLOCK_ENABLE | ACPI_BITMASK_POWER_BUTTON_ENABLE |
@@ -226,7 +226,7 @@ static uint32_t pm_ioport_readw(void *opaque, uint32_t addr) addr &=0x0f ;switch (addr) {case 0x00 : - val =acpi_pm1_evt_get_sts (&s->ar, s->ar.tmr.overflow_time); + val =acpi_pm1_evt_get_sts (&s->ar);break ;case 0x02 : val = s->ar.pm1.evt.en;
Signature · 1 line
1.7.1
PATCH v4 4/11 acpi: add acpi_pm1_evt_write_en
In reply to Gerd Hoffmann--- hw/acpi.c | 5 +++++ hw/acpi.h | 1 + hw/acpi_piix4.c | 2 +- hw/vt82c686.c | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-)
hw/acpi.c +5 -0
@@ -268,6 +268,11 @@ void acpi_pm1_evt_write_sts(ACPIREGS *ar, uint16_t val) ar->pm1.evt.sts &= ~val; } +void acpi_pm1_evt_write_en (ACPIREGS *ar,uint16_t val) +{ + ar->pm1.evt.en = val; +} +void acpi_pm1_evt_power_down (ACPIREGS *ar) {if (ar->pm1.evt.en &ACPI_BITMASK_POWER_BUTTON_ENABLE ) {
hw/acpi.h +1 -0
@@ -133,6 +133,7 @@ static inline int64_t acpi_pm_tmr_get_clock(void)/* PM1a_EVT: piix and ich9 don't implement PM1b. */ uint16_t acpi_pm1_evt_get_sts (ACPIREGS *ar);void acpi_pm1_evt_write_sts (ACPIREGS *ar,uint16_t val); +void acpi_pm1_evt_write_en (ACPIREGS *ar,uint16_t val);void acpi_pm1_evt_power_down (ACPIREGS *ar);void acpi_pm1_evt_reset (ACPIREGS *ar);
hw/acpi_piix4.c +1 -1
@@ -117,7 +117,7 @@ static void pm_ioport_write(IORange *ioport, uint64_t addr, unsigned width,pm_update_sci (s);break ;case 0x02 : - s->ar.pm1.evt.en = val; +acpi_pm1_evt_write_en (&s->ar, val);pm_update_sci (s);break ;case 0x04 :
hw/vt82c686.c +1 -1
@@ -206,7 +206,7 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, uint32_t val)pm_update_sci (s);break ;case 0x02 : - s->ar.pm1.evt.en = val; +acpi_pm1_evt_write_en (&s->ar, val);pm_update_sci (s);break ;case 0x04 :
Signature · 1 line
1.7.1
PATCH v4 5/11 suspend: add infrastructure
In reply to Gerd HoffmannThis patch adds some infrastructure to handle suspend and resume to qemu. First there are two functions to switch state and second there is a suspend notifier:
* qemu_system_suspend_request is supposed to be called when the guest asks for being be suspended, for example via ACPI.
* qemu_system_wakeup_request is supposed to be called on events which should wake up the guest.
* qemu_register_suspend_notifier can be used to register a notifier which will be called when the guest is suspended. Machine types and device models can hook in there to modify state if needed.
* qemu_register_wakeup_notifier can be used to register a notifier which will be called when the guest is woken up. Machine types and device models can hook in there to modify state if needed.
* qemu_system_wakeup_enable can be used to enable/disable wakeup events.
--- sysemu.h | 9 +++++++++ vl.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 0 deletions(-)
sysemu.h +9 -0
@@ -38,7 +38,16 @@ void vm_start(void);void vm_stop (RunState state);void vm_stop_force_state (RunState state); +typedef enum WakeupReason { +QEMU_WAKEUP_REASON_OTHER =0 , +}WakeupReason ; +void qemu_system_reset_request (void ); +void qemu_system_suspend_request (void ); +void qemu_register_suspend_notifier (Notifier *notifier); +void qemu_system_wakeup_request (WakeupReason reason); +void qemu_system_wakeup_enable (WakeupReason reason,bool enabled); +void qemu_register_wakeup_notifier (Notifier *notifier);void qemu_system_shutdown_request (void );void qemu_system_powerdown_request (void );void qemu_system_debug_request (void );
vl.c +49 -0
61 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v4 05/11] suspend: add infrastructure
Quoted 69 lines · Gerd Hoffmann
This patch adds some infrastructure to handle suspend and resume to qemu. First there are two functions to switch state and second there is a suspend notifier:
*
qemu_system_suspend_requestis supposed to be called when the guest asks for being be suspended, for example via ACPI.*
qemu_system_wakeup_requestis supposed to be called on events which should wake up the guest.*
qemu_register_suspend_notifiercan be used to register a notifier which will be called when the guest is suspended. Machine types and device models can hook in there to modify state if needed.*
qemu_register_wakeup_notifiercan be used to register a notifier which will be called when the guest is woken up. Machine types and device models can hook in there to modify state if needed.*
qemu_system_wakeup_enablecan be used to enable/disable wakeup events.Signed-off-by Gerd Hoffmann <[email protected]>--- sysemu.h | 9 +++++++++ vl.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 0 deletions(-)sysemu.h +9
-0@@ -38,7 +38,16 @@ void vm_start(void);void vm_stop (RunState state);void vm_stop_force_state (RunState state); +typedef enum WakeupReason { +QEMU_WAKEUP_REASON_OTHER =0 , +}WakeupReason ; +void qemu_system_reset_request (void ); +void qemu_system_suspend_request (void ); +void qemu_register_suspend_notifier (Notifier *notifier); +void qemu_system_wakeup_request (WakeupReason reason); +void qemu_system_wakeup_enable (WakeupReason reason,bool enabled); +void qemu_register_wakeup_notifier (Notifier *notifier);void qemu_system_shutdown_request (void );void qemu_system_powerdown_request (void );void qemu_system_debug_request (void );vl.c +6
-0@@ -1283,6 +1283,12 @@ static int shutdown_requested, shutdown_signal = -1;static pid_t shutdown_pid;static int powerdown_requested;static int debug_requested; +static bool is_suspended; +static NotifierList suspend_notifiers = +NOTIFIER_LIST_INITIALIZER (suspend_notifiers); +static NotifierList wakeup_notifiers = +NOTIFIER_LIST_INITIALIZER (wakeup_notifiers); +static uint32_t wakeup_reason_mask = ~0 ;static RunState vmstop_requested =RUN_STATE_MAX ;int qemu_shutdown_requested_get (void )@@ -1398,6 +1404,49 @@ void qemu_system_reset_request(void)qemu_notify_event (); }
vl.c void qemu_system_reset_request(void) · line 1416
Quoted 10 lines
vl.c +10
-0+void qemu_system_suspend_request (void ) +{ +if (is_suspended) { +return ; + } +cpu_stop_current (); +notifier_list_notify (&suspend_notifiers,NULL ); + is_suspended = true; +} +
Shouldn't we stop the whole VM at some point, not only vcpu that does ACPI IO? May be I missed where it is done in the patch series.
Quoted 38 lines
vl.c +33
-0+void qemu_register_suspend_notifier (Notifier *notifier) +{ +notifier_list_add (&suspend_notifiers, notifier); +} + +void qemu_system_wakeup_request (WakeupReason reason) +{ +if (!is_suspended) { +return ; + } +if (!(wakeup_reason_mask & (1 << reason))) { +return ; + } +notifier_list_notify (&wakeup_notifiers, &reason); + reset_requested =1 ; +qemu_notify_event (); + is_suspended = false; +} + +void qemu_system_wakeup_enable (WakeupReason reason,bool enabled) +{ +if (enabled) { + wakeup_reason_mask |= (1 << reason); + }else { + wakeup_reason_mask &= ~(1 << reason); + } +} + +void qemu_register_wakeup_notifier (Notifier *notifier) +{ +notifier_list_add (&wakeup_notifiers, notifier); +} +void qemu_system_killed (int signal,pid_t pid) { shutdown_signal = signal;Signature · 1 line
1.7.1
--
Gleb.
Re: [Qemu-devel] [PATCH v4 05/11] suspend: add infrastructure
Hi,
Quoted 2 lines
Shouldn't we stop the whole VM at some point, not only vcpu that does ACPI IO? May be I missed where it is done in the patch series.
It isn't hidden elsewhere, qemu doesn't do it. The code was like that
before, and I think the reason is that the guest has to stop the other cpus before entering s3.
cheers,
Gerd
Re: [Qemu-devel] [PATCH v4 05/11] suspend: add infrastructure
Quoted 9 lines · Gerd Hoffmann
Hi,
Quoted 2 lines
Shouldn't we stop the whole VM at some point, not only vcpu that does ACPI IO? May be I missed where it is done in the patch series.
It isn't hidden elsewhere, qemu doesn't do it. The code was like that
before, and I think the reason is that the guest has to stop the other cpus before entering s3.
Current code calls qemu_system_reset_request() which takes care of stopping (and reseting) all vcpus (and rest of the machine) by setting reset_requested flag immediately on suspend. We cannot just stop current cpu on S3 and delay reset till wakeup since guest can leave other vcpus in spinning state and they will take 100% of host cpu while guest is suspended. I think it is also important to reset all device immediately to ensure that no device will do DMA into main memory after suspend. Technically if this happens it would be a guest bug since guest should make sure that devices are stopped before entering S3, but I wouldn't want to debug such bug report :)
--
Gleb.
Re: [Qemu-devel] [PATCH v4 05/11] suspend: add infrastructure
Quoted 6 lines · Gleb Natapov
Quoted 5 lines · Gerd Hoffmann
Hi,
Quoted 2 lines
Shouldn't we stop the whole VM at some point, not only vcpu that does ACPI IO? May be I missed where it is done in the patch series.
Quoted 7 lines
Quoted 4 lines
It isn't hidden elsewhere, qemu doesn't do it. The code was like that
before, and I think the reason is that the guest has to stop the other cpus before entering s3.Current code calls
qemu_system_reset_request()which takes care of stopping (and reseting) all vcpus (and rest of the machine) by settingreset_requestedflag immediately on suspend.
No. The current code simply has no separate suspend and wakeup steps.
Quoted 4 lines
We cannot just stop
current cpu on S3 and delay reset till wakeup since guest can leave other vcpus in spinning state and they will take 100% of host cpu while guest is suspended.
I see. I've expeced the the guest os putting them into a hlt loop or some simliar idle state. Play save and expliticly pausing them all is certainly good from a robustness perspective.
Quoted 3 lines
I think it is also important to reset all device
immediately to ensure that no device will do DMA into main memory after suspend.
Didn't investigate yet, but I suspect this could break wakeup from pci devices (nic, usb-tablet via uhci) ...
Quoted 3 lines
Technically if this happens it would be a guest bug since guest should make sure that devices are stopped before entering S3, but I wouldn't want to debug such bug report :)
... and it shouldn't be needed. Although I agree that bugs in that area are nasty to debug ...
cheers,
Gerd
Re: [Qemu-devel] [PATCH v4 05/11] suspend: add infrastructure
Quoted 11 lines · Gerd Hoffmann
Quoted 10 lines · Gleb Natapov
Quoted 9 lines · Gerd Hoffmann
Hi,
Quoted 2 lines
Shouldn't we stop the whole VM at some point, not only vcpu that does ACPI IO? May be I missed where it is done in the patch series.
It isn't hidden elsewhere, qemu doesn't do it. The code was like that
before, and I think the reason is that the guest has to stop the other cpus before entering s3.
Quoted 6 lines
Quoted 3 lines
Current code calls
qemu_system_reset_request()which takes care of stopping (and reseting) all vcpus (and rest of the machine) by settingreset_requestedflag immediately on suspend.No. The current code simply has no separate suspend and wakeup steps.
Nod.
Quoted 8 lines
Quoted 4 lines
We cannot just stop
current cpu on S3 and delay reset till wakeup since guest can leave other vcpus in spinning state and they will take 100% of host cpu while guest is suspended.I see. I've expeced the the guest os putting them into a hlt loop or some simliar idle state. Play save and expliticly pausing them all is certainly good from a robustness perspective.
Yes. We should not trust a guest to do the "right thing".
Quoted 7 lines
Quoted 4 lines
I think it is also important to reset all device
immediately to ensure that no device will do DMA into main memory after suspend.Didn't investigate yet, but I suspect this could break wakeup from pci devices (nic, usb-tablet via uhci) ...
Yes. Can't say I fully understand how this works on real HW. I know that there are separate "power planes" for different system sates (this is defined in ACPI spec). So in S3 some devices (or even part of a device?) may be powered down, but others still have power. Not sure we should dive into emulating that in this patch series.
Quoted 10 lines
Quoted 4 lines
Technically if this happens it would be a guest bug since guest should make sure that devices are stopped before entering S3, but I wouldn't want to debug such bug report :)
... and it shouldn't be needed. Although I agree that bugs in that area are nasty to debug ...
cheers,
Gerd
--
Gleb.
Re: [Qemu-devel] [PATCH v4 05/11] suspend: add infrastructure
Hi,
Quoted 4 lines
Quoted 3 lines
I see. I've expeced the the guest os putting them into a hlt loop or some simliar idle state. Play save and expliticly pausing them all is certainly good from a robustness perspective.
Yes. We should not trust a guest to do the "right thing".
Updated patch attached.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I think it is also important to reset all device
immediately to ensure that no device will do DMA into main memory after suspend.
Quoted 8 lines
Quoted 2 lines
Didn't investigate yet, but I suspect this could break wakeup from pci devices (nic, usb-tablet via uhci) ...
Yes. Can't say I fully understand how this works on real HW. I know that there are separate "power planes" for different system sates (this is defined in ACPI spec). So in S3 some devices (or even part of a device?) may be powered down, but others still have power. Not sure we should dive into emulating that in this patch series.
We'll do that later, one step at a time.
cheers,
Gerd
Quoted 1 line
From
fa91a3c496e1a3795622b91079dd588d38fe59b4Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Wed, 11 Jan 2012 13:09:38 +0100
Subject: [PATCH] suspend: add infrastructure
This patch adds some infrastructure to handle suspend and resume to qemu. First there are two functions to switch state and second there is a suspend notifier:
* qemu_system_suspend_request is supposed to be called when the guest asks for being be suspended, for example via ACPI.
* qemu_system_wakeup_request is supposed to be called on events which should wake up the guest.
* qemu_register_suspend_notifier can be used to register a notifier which will be called when the guest is suspended. Machine types and device models can hook in there to modify state if needed.
* qemu_register_wakeup_notifier can be used to register a notifier which will be called when the guest is woken up. Machine types and device models can hook in there to modify state if needed.
* qemu_system_wakeup_enable can be used to enable/disable wakeup events.
--- sysemu.h | 9 ++++++++ vl.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 0 deletions(-)
sysemu.h +9 -0
@@ -38,7 +38,16 @@ void vm_start(void);void vm_stop (RunState state);void vm_stop_force_state (RunState state); +typedef enum WakeupReason { +QEMU_WAKEUP_REASON_OTHER =0 , +}WakeupReason ; +void qemu_system_reset_request (void ); +void qemu_system_suspend_request (void ); +void qemu_register_suspend_notifier (Notifier *notifier); +void qemu_system_wakeup_request (WakeupReason reason); +void qemu_system_wakeup_enable (WakeupReason reason,bool enabled); +void qemu_register_wakeup_notifier (Notifier *notifier);void qemu_system_shutdown_request (void );void qemu_system_powerdown_request (void );void qemu_system_debug_request (void );
vl.c +67 -0
91 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v4 6/11 suspend: switch acpi s3 to new infrastructure.
In reply to Gerd HoffmannThis patch switches pc s3 suspend over to the new infrastructure. The cmos_s3 qemu_irq is killed, the new notifier is used instead. The xen hack goes away with that too, the hypercall can simply be done in a notifier function now.
This patch also makes the guest actually stay suspended instead of leaving suspend instantly, so it is useful for more than just testing whenever the suspend/resume cycle actually works.
--- hw/acpi.c | 32 +++++++++++++++++++++----------- hw/acpi.h | 4 ++-- hw/acpi_piix4.c | 4 ++-- hw/mc146818rtc.c | 12 ++++++++++++ hw/mips_malta.c | 2 +- hw/pc.c | 11 ----------- hw/pc.h | 3 +-- hw/pc_piix.c | 8 +------- hw/vt82c686.c | 2 +- xen-all.c | 11 ++++++----- 10 files changed, 47 insertions(+), 42 deletions(-)
hw/acpi.c +21 -11
@@ -248,6 +248,22 @@ int acpi_table_add(const char *t) } +static void acpi_notify_wakeup (Notifier *notifier,void *data) +{ +ACPIREGS *ar =container_of (notifier,ACPIREGS , wakeup); +WakeupReason *reason = data; + +switch (*reason) { +case QEMU_WAKEUP_REASON_OTHER : +default : +/* ACPI_BITMASK_WAKE_STATUS should be set on resume. +Pretend that resume was caused by power button */ + ar->pm1.evt.sts |= + (ACPI_BITMASK_WAKE_STATUS |ACPI_BITMASK_POWER_BUTTON_STATUS ); +break ; + } +} +/* ACPI PM1a EVT */ uint16_t acpi_pm1_evt_get_sts (ACPIREGS *ar) {
@@ -333,9 +349,10 @@ void acpi_pm_tmr_reset(ACPIREGS *ar) }/* ACPI PM1aCNT */ -void acpi_pm1_cnt_init (ACPIREGS *ar,qemu_irq cmos_s3) +void acpi_pm1_cnt_init (ACPIREGS *ar) { - ar->pm1.cnt.cmos_s3 = cmos_s3; + ar->wakeup.notify = acpi_notify_wakeup; +qemu_register_wakeup_notifier (&ar->wakeup); }void acpi_pm1_cnt_write (ACPIREGS *ar,uint16_t val)
@@ -350,12 +367,8 @@ void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)qemu_system_shutdown_request ();break ;case 1 : -/* ACPI_BITMASK_WAKE_STATUS should be set on resume. -Pretend that resume was caused by power button */ - ar->pm1.evt.sts |= - (ACPI_BITMASK_WAKE_STATUS |ACPI_BITMASK_POWER_BUTTON_STATUS ); -qemu_system_reset_request (); -qemu_irq_raise (ar->pm1.cnt.cmos_s3); +qemu_system_suspend_request (); +break ;default :break ; }
@@ -376,9 +389,6 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,void acpi_pm1_cnt_reset (ACPIREGS *ar) { ar->pm1.cnt.cnt =0 ; -if (ar->pm1.cnt.cmos_s3) { -qemu_irq_lower (ar->pm1.cnt.cmos_s3); - } }/* ACPI GPE */
hw/acpi.h +2 -2
@@ -96,7 +96,6 @@ struct ACPIPM1EVT {struct ACPIPM1CNT {uint16_t cnt; -qemu_irq cmos_s3; };struct ACPIGPE {
@@ -114,6 +113,7 @@ struct ACPIREGS {ACPIPM1EVT evt;ACPIPM1CNT cnt; } pm1; +Notifier wakeup; };/* PM_TMR */
@@ -138,7 +138,7 @@ void acpi_pm1_evt_power_down(ACPIREGS *ar);void acpi_pm1_evt_reset (ACPIREGS *ar);/* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */ -void acpi_pm1_cnt_init (ACPIREGS *ar,qemu_irq cmos_s3); +void acpi_pm1_cnt_init (ACPIREGS *ar);void acpi_pm1_cnt_write (ACPIREGS *ar,uint16_t val);void acpi_pm1_cnt_update (ACPIREGS *ar,bool sci_enable,bool sci_disable);
hw/acpi_piix4.c +2 -2
@@ -372,7 +372,7 @@ static int piix4_pm_initfn(PCIDevice *dev) }i2c_bus *piix4_pm_init (PCIBus *bus,int devfn,uint32_t smb_io_base, -qemu_irq sci_irq,qemu_irq cmos_s3,qemu_irq smi_irq, +qemu_irq sci_irq,qemu_irq smi_irq,int kvm_enabled) {PCIDevice *dev;
@@ -383,7 +383,7 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, s =DO_UPCAST (PIIX4PMState, dev, dev); s->irq = sci_irq; -acpi_pm1_cnt_init (&s->ar, cmos_s3); +acpi_pm1_cnt_init (&s->ar); s->smi_irq = smi_irq; s->kvm_enabled = kvm_enabled;
hw/mc146818rtc.c +12 -0
@@ -102,6 +102,7 @@ typedef struct RTCState {QEMUTimer *second_timer2;Notifier clock_reset_notifier;LostTickPolicy lost_tick_policy; +Notifier suspend_notifier; } RTCState;static void rtc_set_time (RTCState *s);
@@ -596,6 +597,14 @@ static void rtc_notify_clock_reset(Notifier *notifier, void *data)#endif } +/* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE) +BIOS will read it and start S3 resume at POST Entry */ +static void rtc_notify_suspend (Notifier *notifier,void *data) +{ +RTCState *s =container_of (notifier, RTCState, suspend_notifier); +rtc_set_memory (&s->dev,0xF ,0xFE ); +} +static void rtc_reset (void *opaque) {RTCState *s = opaque;
@@ -676,6 +685,9 @@ static int rtc_initfn(ISADevice *dev) s->clock_reset_notifier.notify = rtc_notify_clock_reset;qemu_register_clock_reset_notifier (rtc_clock, &s->clock_reset_notifier); + s->suspend_notifier.notify = rtc_notify_suspend; +qemu_register_suspend_notifier (&s->suspend_notifier); + s->next_second_time =qemu_get_clock_ns (rtc_clock) + (get_ticks_per_sec () *99 ) /100 ;qemu_mod_timer (s->second_timer2, s->next_second_time);
hw/mips_malta.c +1 -1
@@ -966,7 +966,7 @@ void mips_malta_init (ram_addr_t ram_size,pci_piix4_ide_init (pci_bus, hd, piix4_devfn +1 );usb_uhci_piix4_init (pci_bus, piix4_devfn +2 ); smbus =piix4_pm_init (pci_bus, piix4_devfn +3 ,0x1100 , -isa_get_irq (NULL ,9 ),NULL ,NULL ,0 ); +isa_get_irq (NULL ,9 ),NULL ,0 );/* TODO: Populate SPD eeprom data. */ smbus_eeprom_init (smbus,8 ,NULL ,0 ); pit =pit_init (isa_bus,0x40 ,0 );
hw/pc.c +0 -11
@@ -915,17 +915,6 @@ static DeviceState *apic_init(void *env, uint8_t apic_id)return dev; } -/* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE) -BIOS will read it and start S3 resume at POST Entry */ -void pc_cmos_set_s3_resume (void *opaque,int irq,int level) -{ -ISADevice *s = opaque; - -if (level) { -rtc_set_memory (s,0xF ,0xFE ); - } -} -void pc_acpi_smi_interrupt (void *opaque,int irq,int level) {CPUState *s = opaque;
hw/pc.h +1 -2
@@ -128,7 +128,6 @@ void i8042_setup_a20_line(ISADevice *dev, qemu_irq *a20_out);extern int fd_bootchk;void pc_register_ferr_irq (qemu_irq irq); -void pc_cmos_set_s3_resume (void *opaque,int irq,int level);void pc_acpi_smi_interrupt (void *opaque,int irq,int level);void pc_cpus_init (const char *cpu_model);
@@ -167,7 +166,7 @@ int acpi_table_add(const char *table_desc);/* acpi_piix.c */ i2c_bus *piix4_pm_init (PCIBus *bus,int devfn,uint32_t smb_io_base, -qemu_irq sci_irq,qemu_irq cmos_s3,qemu_irq smi_irq, +qemu_irq sci_irq,qemu_irq smi_irq,int kvm_enabled);void piix4_smbus_register_device (SMBusDevice *dev,uint8_t addr);
hw/pc_piix.c +1 -7
@@ -139,7 +139,6 @@ static void pc_init1(MemoryRegion *system_memory,qemu_irq *cpu_irq;qemu_irq *gsi;qemu_irq *i8259; -qemu_irq *cmos_s3;qemu_irq *smi_irq;GSIState *gsi_state;DriveInfo *hd[MAX_IDE_BUS *MAX_IDE_DEVS ];
@@ -291,15 +290,10 @@ static void pc_init1(MemoryRegion *system_memory,if (pci_enabled && acpi_enabled) {i2c_bus *smbus; -if (!xen_enabled ()) { - cmos_s3 =qemu_allocate_irqs (pc_cmos_set_s3_resume, rtc_state,1 ); - }else { - cmos_s3 =qemu_allocate_irqs (xen_cmos_set_s3_resume, rtc_state,1 ); - } smi_irq =qemu_allocate_irqs (pc_acpi_smi_interrupt, first_cpu,1 );/* TODO: Populate SPD eeprom data. */ smbus =piix4_pm_init (pci_bus, piix3_devfn +3 ,0xb100 , - gsi[9 ], *cmos_s3, *smi_irq, + gsi[9 ], *smi_irq,kvm_enabled ());smbus_eeprom_init (smbus,8 ,NULL ,0 ); }
hw/vt82c686.c +1 -1
@@ -444,7 +444,7 @@ static int vt82c686b_pm_initfn(PCIDevice *dev)apm_init (&s->apm,NULL , s);acpi_pm_tmr_init (&s->ar, pm_tmr_timer); -acpi_pm1_cnt_init (&s->ar,NULL ); +acpi_pm1_cnt_init (&s->ar);pm_smbus_init (&s->dev.qdev, &s->smb);
xen-all.c +6 -5
@@ -89,6 +89,7 @@ typedef struct XenIOState {const XenPhysmap *log_for_dirtybit;Notifier exit; +Notifier suspend; } XenIOState;/* Xen specific function for piix pci */
@@ -121,12 +122,9 @@ void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len) } } -void xen_cmos_set_s3_resume (void *opaque,int irq,int level) +static void xen_suspend_notifier (Notifier *notifier,void *data) { -pc_cmos_set_s3_resume (opaque, irq, level); -if (level) { -xc_set_hvm_param (xen_xc, xen_domid,HVM_PARAM_ACPI_S_STATE ,3 ); - } +xc_set_hvm_param (xen_xc, xen_domid,HVM_PARAM_ACPI_S_STATE ,3 ); }/* Xen Interrupt Controller */
@@ -936,6 +934,9 @@ int xen_hvm_init(void) state->exit.notify = xen_exit_notifier;qemu_add_exit_notifier (&state->exit); + state->suspend.notify = xen_suspend_notifier; +qemu_register_suspend_notifier (&state->suspend); +xc_get_hvm_param (xen_xc, xen_domid,HVM_PARAM_IOREQ_PFN , &ioreq_pfn);DPRINTF ("shared page at pfn %lx\n" , ioreq_pfn); state->shared_page = xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
Signature · 1 line
1.7.1
PATCH v4 7/11 suspend: add system_wakeup monitor command
In reply to Gerd HoffmannThis patch adds the system_wakeup monitor command which will simply wake up suspended guests.
--- hmp-commands.hx | 14 ++++++++++++++ hmp.c | 5 +++++ hmp.h | 1 + qapi-schema.json | 11 +++++++++++ qmp-commands.hx | 21 +++++++++++++++++++++ qmp.c | 5 +++++ 6 files changed, 57 insertions(+), 0 deletions(-)
hmp-commands.hx +14 -0
@@ -352,6 +352,20 @@ Resume emulation. ETEXI { + .name = "system_wakeup", + .args_type = "", + .params = "", + .help = "wakeup guest from suspend", + .mhandler.cmd = hmp_system_wakeup, + }, + +STEXI +@item system_wakeup +@findex system_wakeup +Wakeup guest from suspend. +ETEXI + + { .name = "gdbserver", .args_type = "device:s?", .params = "[device]",
hmp.c +5 -0
@@ -632,6 +632,11 @@ void hmp_cont(Monitor *mon, const QDict *qdict) } } +void hmp_system_wakeup (Monitor *mon,const QDict *qdict) +{ +qmp_system_wakeup (NULL ); +} +void hmp_inject_nmi (Monitor *mon,const QDict *qdict) {Error *errp =NULL ;
hmp.h +1 -0
@@ -41,6 +41,7 @@ void hmp_cpu(Monitor *mon, const QDict *qdict);void hmp_memsave (Monitor *mon,const QDict *qdict);void hmp_pmemsave (Monitor *mon,const QDict *qdict);void hmp_cont (Monitor *mon,const QDict *qdict); +void hmp_system_wakeup (Monitor *mon,const QDict *qdict);void hmp_inject_nmi (Monitor *mon,const QDict *qdict);void hmp_set_link (Monitor *mon,const QDict *qdict);void hmp_block_passwd (Monitor *mon,const QDict *qdict);
qapi-schema.json +11 -0
@@ -999,6 +999,17 @@ { 'command': 'cont' } ## +# @system_wakeup: +# +# Wakeup guest from suspend +# +# Since: 1.1 +# +# Returns: nothing. +## +{ 'command': 'system_wakeup' } + +## # @inject-nmi: # # Injects an Non-Maskable Interrupt into all guest's VCPUs.
qmp-commands.hx +21 -0
@@ -212,6 +212,27 @@ Example: EQMP { + .name = "system_wakeup", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_system_wakeup, + }, + +SQMP +system_wakeup +------------- + +Wakeup guest from suspend. + +Arguments: None. + +Example: + +-> { "execute": "system_wakeup" } +<- { "return": {} } + +EQMP + + { .name = "system_reset", .args_type = "", .mhandler.cmd_new = qmp_marshal_input_system_reset,
qmp.c +5 -0
@@ -164,6 +164,11 @@ void qmp_cont(Error **errp)vm_start (); } +void qmp_system_wakeup (Error **errp) +{ +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ); +} +ObjectPropertyInfoList *qmp_qom_list (const char *path,Error **errp) {Object *obj;
Signature · 1 line
1.7.1
PATCH v4 8/11 suspend: make ps/2 devices wakeup the guest
In reply to Gerd HoffmannThis patch adds wakeup support to ps/2 emulation. Any key press on the ps/2 keyboard will wakeup the guest. Likewise any mouse button press will wakeup the guest. Mouse moves are ignored, so the guest will not wakeup in case your mouse crosses the vnc window of a suspended guest by accident.
--- hw/ps2.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
hw/ps2.c +6 -0
@@ -24,6 +24,7 @@#include "hw.h" #include "ps2.h" #include "console.h" +#include "sysemu.h" /* debug PC keyboard */ //#define DEBUG_KBD
@@ -154,6 +155,7 @@ static void ps2_put_keycode(void *opaque, int keycode) {PS2KbdState *s = opaque; +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER );/* XXX: add support for scancode set 1 */ if (!s->translate && keycode <0xe0 && s->scancode_set >1 ) {if (keycode &0x80 ) {
@@ -368,6 +370,10 @@ static void ps2_mouse_event(void *opaque,return ; s->mouse_buttons = buttons_state; +if (buttons_state) { +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ); + } +if (!(s->mouse_status &MOUSE_STATUS_REMOTE ) && (s->common.queue.count < (PS2_QUEUE_SIZE -16 ))) {for (;;) {
Signature · 1 line
1.7.1
PATCH v4 9/11 suspend: make serial ports wakeup the guest.
In reply to Gerd HoffmannAdd a 'wakeup' property to the serial port. It is off by default. When enabled any incoming character on the serial line will wake up the guest. Useful for guests which have a serial console configured.
--- hw/serial.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
hw/serial.c +6 -0
@@ -139,6 +139,7 @@ struct SerialState {int it_shift;int baudbase;int tsr_retry; +uint32_t wakeup;uint64_t last_xmit_ts;/* Time when the last byte was successfully sent out of the tsr */ SerialFIFO recv_fifo;
@@ -635,6 +636,10 @@ static int serial_can_receive1(void *opaque)static void serial_receive1 (void *opaque,const uint8_t *buf,int size) {SerialState *s = opaque; + +if (s->wakeup) { +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ); + }if (s->fcr &UART_FCR_FE ) {int i;for (i =0 ; i < size; i++) {
@@ -884,6 +889,7 @@ static Property serial_isa_properties[] = {DEFINE_PROP_HEX32 ("iobase" , ISASerialState, iobase,-1 ),DEFINE_PROP_UINT32 ("irq" , ISASerialState, isairq,-1 ),DEFINE_PROP_CHR ("chardev" , ISASerialState, state.chr), +DEFINE_PROP_UINT32 ("wakeup" , ISASerialState, state.wakeup,0 ), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
1.7.1
PATCH v4 10/11 suspend: make rtc alarm wakeup the guest.
In reply to Gerd HoffmannMake the rtc wake up the guest when the alarm fires. Add acpi windup to property support RTC_EN.
--- hw/acpi.c | 7 +++++++ hw/mc146818rtc.c | 1 + sysemu.h | 1 + 3 files changed, 9 insertions(+), 0 deletions(-)
hw/acpi.c +7 -0
@@ -254,6 +254,10 @@ static void acpi_notify_wakeup(Notifier *notifier, void *data)WakeupReason *reason = data;switch (*reason) { +case QEMU_WAKEUP_REASON_RTC : + ar->pm1.evt.sts |= + (ACPI_BITMASK_WAKE_STATUS |ACPI_BITMASK_RT_CLOCK_STATUS ); +break ;case QEMU_WAKEUP_REASON_OTHER :default :/* ACPI_BITMASK_WAKE_STATUS should be set on resume.
@@ -287,6 +291,8 @@ void acpi_pm1_evt_write_sts(ACPIREGS *ar, uint16_t val)void acpi_pm1_evt_write_en (ACPIREGS *ar,uint16_t val) { ar->pm1.evt.en = val; +qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_RTC , + val &ACPI_BITMASK_RT_CLOCK_ENABLE ); }void acpi_pm1_evt_power_down (ACPIREGS *ar)
@@ -301,6 +307,7 @@ void acpi_pm1_evt_reset(ACPIREGS *ar) { ar->pm1.evt.sts =0 ; ar->pm1.evt.en =0 ; +qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_RTC ,0 ); }/* ACPI PM_TMR */
hw/mc146818rtc.c +1 -0
@@ -437,6 +437,7 @@ static void rtc_update_second2(void *opaque) s->cmos_data[RTC_REG_C ] |=REG_C_AF ;if (s->cmos_data[RTC_REG_B ] ®_B_AIE ) { +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_RTC );qemu_irq_raise (s->irq); s->cmos_data[RTC_REG_C ] |=REG_C_IRQF ; }
sysemu.h +1 -0
@@ -40,6 +40,7 @@ void vm_stop_force_state(RunState state);typedef enum WakeupReason {QEMU_WAKEUP_REASON_OTHER =0 , +QEMU_WAKEUP_REASON_RTC , }WakeupReason ;void qemu_system_reset_request (void );
Signature · 1 line
1.7.1
PATCH v4 11/11 suspend: pmtimer s3 wakeup
In reply to Gerd Hoffmann--- hw/acpi.c | 8 ++++++++ sysemu.h | 1 + 2 files changed, 9 insertions(+), 0 deletions(-)
hw/acpi.c +8 -0
@@ -258,6 +258,10 @@ static void acpi_notify_wakeup(Notifier *notifier, void *data) ar->pm1.evt.sts |= (ACPI_BITMASK_WAKE_STATUS |ACPI_BITMASK_RT_CLOCK_STATUS );break ; +case QEMU_WAKEUP_REASON_PMTIMER : + ar->pm1.evt.sts |= + (ACPI_BITMASK_WAKE_STATUS |ACPI_BITMASK_TIMER_STATUS ); +break ;case QEMU_WAKEUP_REASON_OTHER :default :/* ACPI_BITMASK_WAKE_STATUS should be set on resume.
@@ -293,6 +297,8 @@ void acpi_pm1_evt_write_en(ACPIREGS *ar, uint16_t val) ar->pm1.evt.en = val;qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_RTC , val &ACPI_BITMASK_RT_CLOCK_ENABLE ); +qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_PMTIMER , + val &ACPI_BITMASK_TIMER_ENABLE ); }void acpi_pm1_evt_power_down (ACPIREGS *ar)
@@ -308,6 +314,7 @@ void acpi_pm1_evt_reset(ACPIREGS *ar) ar->pm1.evt.sts =0 ; ar->pm1.evt.en =0 ;qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_RTC ,0 ); +qemu_system_wakeup_enable (QEMU_WAKEUP_REASON_PMTIMER ,0 ); }/* ACPI PM_TMR */
@@ -340,6 +347,7 @@ uint32_t acpi_pm_tmr_get(ACPIREGS *ar)static void acpi_pm_tmr_timer (void *opaque) {ACPIREGS *ar = opaque; +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_PMTIMER ); ar->tmr.update_sci (ar); }
sysemu.h +1 -0
@@ -41,6 +41,7 @@ void vm_stop_force_state(RunState state);typedef enum WakeupReason {QEMU_WAKEUP_REASON_OTHER =0 ,QEMU_WAKEUP_REASON_RTC , +QEMU_WAKEUP_REASON_PMTIMER , }WakeupReason ;void qemu_system_reset_request (void );
Signature · 1 line
1.7.1
[Qemu-devel] [PATCH 12/11] suspend: add qmp events
In reply to Gerd HoffmannSend qmp events on suspend and wakeup so libvirt
has a chance to track the vm state.
--- monitor.c | 6 ++++++ monitor.h | 2 ++ vl.c | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 0 deletions(-)
monitor.c +6 -0
@@ -485,6 +485,12 @@ void monitor_protocol_event(MonitorEvent event, QObject *data)case QEVENT_BLOCK_JOB_CANCELLED : event_name ="BLOCK_JOB_CANCELLED" ;break ; +case QEVENT_SUSPEND : + event_name ="SUSPEND" ; +break ; +case QEVENT_WAKEUP : + event_name ="WAKEUP" ; +break ;default :abort ();break ;
monitor.h +2 -0
@@ -38,6 +38,8 @@ typedef enum MonitorEvent {QEVENT_SPICE_DISCONNECTED ,QEVENT_BLOCK_JOB_COMPLETED ,QEVENT_BLOCK_JOB_CANCELLED , +QEVENT_SUSPEND , +QEVENT_WAKEUP ,QEVENT_MAX , } MonitorEvent;
vl.c +15 -0
@@ -1411,6 +1411,7 @@ void qemu_system_suspend_request(void) }cpu_stop_current ();notifier_list_notify (&suspend_notifiers,NULL ); +monitor_protocol_event (QEVENT_SUSPEND ,NULL ); is_suspended = true; }
@@ -1421,12 +1422,26 @@ void qemu_register_suspend_notifier(Notifier *notifier)void qemu_system_wakeup_request (WakeupReason reason) { +static const char *names[] = { + [QEMU_WAKEUP_REASON_OTHER ] ="other" , + [QEMU_WAKEUP_REASON_RTC ] ="rtc" , + [QEMU_WAKEUP_REASON_PMTIMER ] ="pmtimer" , + }; +const char *name; +QObject *data; +if (!is_suspended) {return ; }if (!(wakeup_reason_mask & (1 << reason))) {return ; } + + name = (reason <ARRAY_SIZE (names)) ? names[reason] :"unknown" ; + data =qobject_from_jsonf ("{ 'reason': %s }" , name); +monitor_protocol_event (QEVENT_WAKEUP , data); +qobject_decref (data); +notifier_list_notify (&wakeup_notifiers, &reason); reset_requested =1 ;qemu_notify_event ();
Signature · 1 line
1.7.1