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)
--- /dev/null
+/*
+ * 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
+
--- /dev/null
+/*
+ * 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
+
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);
OBJS += pt_pckbd.o
OBJS += xen_acpi_wmi.o
OBJS += hid-linux.o
+OBJS += thermal_mgmt.o
ifdef CONFIG_STUBDOM
CPPFLAGS += $(TARGET_CPPFLAGS)
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
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");
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);
}
/*