]> xenbits.xen.org Git - xenclient/ioemu.git/commitdiff
Base thermal management support.
authorKamala Narasimhan <kamala.narasimhan@citrix.com>
Tue, 24 Mar 2009 21:24:34 +0000 (17:24 -0400)
committerKamala Narasimhan <kamala.narasimhan@citrix.com>
Tue, 24 Mar 2009 21:24:34 +0000 (17:24 -0400)
hw/piix4acpi.c
hw/thermal_mgmt.c [new file with mode: 0644]
hw/thermal_mgmt.h [new file with mode: 0644]
qemu-xen.h
xen-hooks.mak
xenstore.c

index e39a3497b5be5094a05139a5dc78cd87b7031fd7..0d7888084551dd4c2dc8f8df72c71c498ef4c0ec 100644 (file)
@@ -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 (file)
index 0000000..649b622
--- /dev/null
@@ -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 (file)
index 0000000..d83273b
--- /dev/null
@@ -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
+
index c756e04903cf8e9c8e6e027c5b68faa91d2ebbb7..f07f1856442a7d4696181efae40589febb0b724e 100644 (file)
@@ -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);
 
index fc440fcd0ef704046f013c7df0443a5e0d9ac1aa..22b70b58db84c7655b64a07deaea3b67b49b6733 100644 (file)
@@ -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)
index aa676048bf39f6ba2e8e8ff705659ec3e0c770b6..7e00568a3a8b252aacb8a773c7274ee09c1dff51 100644 (file)
@@ -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);
 }
 
 /*