From: Kamala Narasimhan Date: Tue, 24 Mar 2009 21:24:34 +0000 (-0400) Subject: Base thermal management support. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=8ebff5f5716e0ab8d7d6596c88777daf71baee37;p=xenclient%2Fioemu.git Base thermal management support. --- diff --git a/hw/piix4acpi.c b/hw/piix4acpi.c index e39a3497..0d788808 100644 --- a/hw/piix4acpi.c +++ b/hw/piix4acpi.c @@ -197,6 +197,7 @@ static void acpi_map(PCIDevice *pci_dev, int region_num, battery_mgmt_init(pci_dev); xen_acpi_wmi_init(pci_dev); + thermal_mgmt_init(pci_dev); } static inline int test_bit(uint8_t *map, int bit) diff --git a/hw/thermal_mgmt.c b/hw/thermal_mgmt.c new file mode 100644 index 00000000..649b6226 --- /dev/null +++ b/hw/thermal_mgmt.c @@ -0,0 +1,79 @@ +/* + * thermal_mgmt.c + * + * Copyright (c) 2009 Kamala Narasimhan + * Copyright (c) 2009 Citrix Systems, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* Implementation Notes: Following provides a minimal thermal zone implementation for + * HVM guest. The vACPI layer exposes a single thermal zone with critical and current + * temperature objects which when invoked relies on the below to return back the critical + * and current temperature provided by the underlying firmware. + */ + +#include "hw.h" +#include "pc.h" +#include "qemu-xen.h" +#include "isa.h" +#include "thermal_mgmt.h" + +#ifndef CONFIG_NO_THERMAL_MGMT + +/* #define THERMAL_MGMT_DBG */ + +extern FILE *logfile; + +static uint32_t thermal_port_1_readw(void *opaque, uint32_t addr) +{ + int current_temp; + + xenstore_refresh_thermal_info(); + current_temp = xenstore_read_current_temperature(); +#ifdef THERMAL_MGMT_DBG + fprintf(logfile, "Current temperature - %d\n", current_temp); +#endif + return current_temp; +} + +static uint32_t thermal_port_2_readw(void *opaque, uint32_t addr) +{ + int critical_temp; + + xenstore_refresh_thermal_info(); + critical_temp = xenstore_read_critical_temperature(); +#ifdef THERMAL_MGMT_DBG + fprintf(logfile, "Critical trip point temperature - %d\n", critical_temp); +#endif + return critical_temp; +} + +void thermal_mgmt_init(PCIDevice *device) +{ +#ifdef THERMAL_MGMT_DBG + fprintf(logfile, "In thermal management init\n"); +#endif + + register_ioport_read(THERMAL_PORT_1, 1, 2, thermal_port_1_readw, device); + register_ioport_read(THERMAL_PORT_2, 1, 2, thermal_port_2_readw, device); +} + +#else + +void thermal_mgmt_init(PCIDevice *device) { } + +#endif + diff --git a/hw/thermal_mgmt.h b/hw/thermal_mgmt.h new file mode 100644 index 00000000..d83273b6 --- /dev/null +++ b/hw/thermal_mgmt.h @@ -0,0 +1,35 @@ +/* + * thermal_mgmt.h + * + * Copyright (c) 2009 Kamala Narasimhan + * Copyright (c) 2009 Citrix Systems, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _THERMAL_MGMT_H +#define _THERMAL_MGMT_H + +#ifdef CONFIG_STUBDOM +#define CONFIG_NO_THERMAL_MGMT +#endif + +#define THERMAL_PORT_1 0x90 +#define THERMAL_PORT_2 0x92 + +void thermal_mgmt_init(PCIDevice *device); + +#endif + diff --git a/qemu-xen.h b/qemu-xen.h index c756e049..f07f1856 100644 --- a/qemu-xen.h +++ b/qemu-xen.h @@ -110,9 +110,12 @@ char *xenstore_vm_read(int domid, char *key, unsigned int *len); char *xenstore_device_model_read(int domid, char *key, unsigned int *len); char *xenstore_read_battery_data(int battery_status); int xenstore_refresh_battery_status(void); +int xenstore_refresh_thermal_info(void); void xenstore_register_for_pm_events(void); int xenstore_read_ac_adapter_state(void); int xenstore_read_lid_state(void); +int xenstore_read_current_temperature(void); +int xenstore_read_critical_temperature(void); void xenstore_register_for_oem_events(void); diff --git a/xen-hooks.mak b/xen-hooks.mak index fc440fcd..22b70b58 100644 --- a/xen-hooks.mak +++ b/xen-hooks.mak @@ -36,6 +36,7 @@ OBJS += battery_mgmt.o OBJS += pt_pckbd.o OBJS += xen_acpi_wmi.o OBJS += hid-linux.o +OBJS += thermal_mgmt.o ifdef CONFIG_STUBDOM CPPFLAGS += $(TARGET_CPPFLAGS) diff --git a/xenstore.c b/xenstore.c index aa676048..7e00568a 100644 --- a/xenstore.c +++ b/xenstore.c @@ -1273,6 +1273,20 @@ int xenstore_extended_power_mgmt_event_trigger(char *key, char * value) return ret; } +int xenstore_extended_power_mgmt_read_int(char *key, int default_value) +{ + int value = default_value; + char *buffer; + + buffer = xenstore_extended_power_mgmt_read(key, NULL); + if ( buffer == NULL ) + return value; + + value = strtoull(buffer, NULL, 10); + free(buffer); + return value; +} + /* * Xen power management daemon stores battery generic information * like model, make, design volt, capacity etc. under /pm/bif and @@ -1298,6 +1312,11 @@ int xenstore_refresh_battery_status(void) return xenstore_extended_power_mgmt_event_trigger("refreshbatterystatus", "1"); } +int xenstore_refresh_thermal_info(void) +{ + return xenstore_extended_power_mgmt_event_trigger("refreshthermalinfo", "1"); +} + void xenstore_register_for_pm_events(void) { xs_watch(xsh, "/pm/events/acadapterstatechanged", "acadapterstatechangeevt"); @@ -1313,30 +1332,22 @@ void xenstore_register_for_oem_events(void) int xenstore_read_ac_adapter_state(void) { - int ac_state = 1; - char *buffer; - - buffer = xenstore_extended_power_mgmt_read("ac_adapter", NULL); - if ( buffer == NULL ) - return ac_state; - - ac_state = strtoull(buffer, NULL, 10); - free(buffer); - return ac_state; + return xenstore_extended_power_mgmt_read_int("ac_adapter", 1); } int xenstore_read_lid_state(void) { - int lid_state = 1; - char * buffer; + return xenstore_extended_power_mgmt_read_int("lid_state", 1); +} - buffer = xenstore_extended_power_mgmt_read("lid_state", NULL); - if ( buffer == NULL ) - return lid_state; +int xenstore_read_current_temperature(void) +{ + return xenstore_extended_power_mgmt_read_int("current_temperature", 0); +} - lid_state = strtoull(buffer, NULL, 10); - free(buffer); - return lid_state; +int xenstore_read_critical_temperature(void) +{ + return xenstore_extended_power_mgmt_read_int("critical_temperature", 100); } /*