From: Roger Pau Monne Date: Fri, 4 Sep 2015 11:06:46 +0000 (+0200) Subject: xen/x86: allow disabling power management X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=a399fca12d19d5304e981df69db87ee9bd3aae8a;p=people%2Froyger%2Fxen.git xen/x86: allow disabling power management Signed-off-by: Roger Pau Monné Reviewed-by: Andrew Cooper Cc: Jan Beulich Cc: Andrew Cooper --- Changes since v7: - Add Andrew Cooper Reviewed-by. - Apply renaming from earlier patch (s/PMTIMER/PM/). Changes since v6: - Return ENODEV in pmtimer_load if the timer is disabled. - hvm_acpi_power_button and hvm_acpi_sleep_button become noops if the pmtimer is disabled. - Return ENODEV if pmtimer_change_ioport is called with the pmtimer disabled. - Add a check for disabled pmtimer in pmtimer_reset. Although it's safe to execute this function now, it might change in the future. - Drop Andrew's Ack due to the changes. Changes since v4: - Add Andrew Cooper Acked-by. --- diff --git a/xen/arch/x86/hvm/pmtimer.c b/xen/arch/x86/hvm/pmtimer.c index c8229e0eab..9c2e4bd2d8 100644 --- a/xen/arch/x86/hvm/pmtimer.c +++ b/xen/arch/x86/hvm/pmtimer.c @@ -67,6 +67,10 @@ static void pmt_update_sci(PMTState *s) void hvm_acpi_power_button(struct domain *d) { PMTState *s = &d->arch.hvm_domain.pl_time.vpmt; + + if ( !has_vpm(d) ) + return; + spin_lock(&s->lock); s->pm.pm1a_sts |= PWRBTN_STS; pmt_update_sci(s); @@ -76,6 +80,10 @@ void hvm_acpi_power_button(struct domain *d) void hvm_acpi_sleep_button(struct domain *d) { PMTState *s = &d->arch.hvm_domain.pl_time.vpmt; + + if ( !has_vpm(d) ) + return; + spin_lock(&s->lock); s->pm.pm1a_sts |= SLPBTN_STS; pmt_update_sci(s); @@ -247,6 +255,9 @@ static int pmtimer_save(struct domain *d, hvm_domain_context_t *h) uint32_t x, msb = s->pm.tmr_val & TMR_VAL_MSB; int rc; + if ( !has_vpm(d) ) + return 0; + spin_lock(&s->lock); /* @@ -273,6 +284,9 @@ static int pmtimer_load(struct domain *d, hvm_domain_context_t *h) { PMTState *s = &d->arch.hvm_domain.pl_time.vpmt; + if ( !has_vpm(d) ) + return -ENODEV; + spin_lock(&s->lock); /* Reload the registers */ @@ -301,6 +315,9 @@ int pmtimer_change_ioport(struct domain *d, unsigned int version) { unsigned int old_version; + if ( !has_vpm(d) ) + return -ENODEV; + /* Check that version is changing. */ old_version = d->arch.hvm_domain.params[HVM_PARAM_ACPI_IOPORTS_LOCATION]; if ( version == old_version ) @@ -330,6 +347,9 @@ void pmtimer_init(struct vcpu *v) { PMTState *s = &v->domain->arch.hvm_domain.pl_time.vpmt; + if ( !has_vpm(v->domain) ) + return; + spin_lock_init(&s->lock); s->scale = ((uint64_t)FREQUENCE_PMTIMER << 32) / SYSTEM_TIME_HZ; @@ -350,11 +370,18 @@ void pmtimer_init(struct vcpu *v) void pmtimer_deinit(struct domain *d) { PMTState *s = &d->arch.hvm_domain.pl_time.vpmt; + + if ( !has_vpm(d) ) + return; + kill_timer(&s->timer); } void pmtimer_reset(struct domain *d) { + if ( !has_vpm(d) ) + return; + /* Reset the counter. */ d->arch.hvm_domain.pl_time.vpmt.pm.tmr_val = 0; }