-diff -Nur a/tools/firmware/hvmloader/acpi/build.c b/tools/firmware/hvmloader/acpi/build.c
---- a/tools/firmware/hvmloader/acpi/build.c 2009-04-01 16:31:10.000000000 -0400
-+++ b/tools/firmware/hvmloader/acpi/build.c 2009-04-01 17:04:59.000000000 -0400
+diff --git a/tools/firmware/hvmloader/acpi/Makefile b/tools/firmware/hvmloader/acpi/Makefile
+index f9f6bc3..6ef2af8 100644
+--- a/tools/firmware/hvmloader/acpi/Makefile
++++ b/tools/firmware/hvmloader/acpi/Makefile
+@@ -19,7 +19,7 @@ XEN_ROOT = ../../../..
+ include $(XEN_ROOT)/tools/firmware/Rules.mk
+
+ C_SRC = build.c dsdt.c static_tables.c
+-H_SRC = $(wildcard *.h) ssdt_pm.h ssdt_tpm.h
++H_SRC = $(wildcard *.h) ssdt_pm.h ssdt_hp_6930p_elitebook.h ssdt_dell_latitude_eseries.h ssdt_lenovo_t_and_x_series.h ssdt_tpm.h
+ OBJS = $(patsubst %.c,%.o,$(C_SRC))
+
+ build.o: $(H_SRC) build.c
+@@ -39,6 +39,27 @@ ssdt_pm.h: ssdt_pm.asl
+ mv $*.hex $@
+ rm -f *.aml
+
++ssdt_hp_6930p_elitebook.h: ssdt_hp_6930p_elitebook.asl
++ $(MAKE) iasl
++ iasl -tc $<
++ sed -i'' -re 's/AmlCode/AmlCode_HP_6930P_ELITEBOOK/g' $*.hex
++ mv $*.hex $@
++ rm -f *.aml
++
++ssdt_dell_latitude_eseries.h: ssdt_dell_latitude_eseries.asl
++ $(MAKE) iasl
++ iasl -tc $<
++ sed -i'' -re 's/AmlCode/AmlCode_DELL_LATITUDE_ESERIES/g' $*.hex
++ mv $*.hex $@
++ rm -f *.aml
++
++ssdt_lenovo_t_and_x_series.h: ssdt_lenovo_t_and_x_series.asl
++ $(MAKE) iasl
++ iasl -tc $<
++ sed -i'' -re 's/AmlCode/AmlCode_LENOVO_T_AND_X_SERIES/g' $*.hex
++ mv $*.hex $@
++ rm -f *.aml
++
+ ssdt_tpm.h: ssdt_tpm.asl
+ $(MAKE) iasl
+ iasl -tc $<
+diff --git a/tools/firmware/hvmloader/acpi/build.c b/tools/firmware/hvmloader/acpi/build.c
+index 0513b9c..02ce969 100644
+--- a/tools/firmware/hvmloader/acpi/build.c
++++ b/tools/firmware/hvmloader/acpi/build.c
@@ -19,8 +19,12 @@
#include "acpi2_0.h"
#include "ssdt_tpm.h"
#include "../config.h"
#include "../util.h"
+#include "../smbios_types.h"
-
+
#define align16(sz) (((sz) + 15) & ~15)
#define fixed_strcpy(d, s) strncpy((d), (s), sizeof(d))
-@@ -33,6 +37,16 @@
+@@ -33,6 +37,16 @@ extern struct acpi_20_facs Facs;
extern unsigned char AmlCode[];
extern int DsdtLen;
-
+
+#define OEM_NAME_DELL "Dell"
+#define OEM_NAME_HP "Hewlett-Packard"
+#define OEM_NAME_LENOVO "LENOVO"
static void set_checksum(
void *table, uint32_t checksum_offset, uint32_t length)
{
-@@ -59,6 +73,12 @@
+@@ -59,6 +73,12 @@ static uint8_t battery_port_exists(void)
return 1;
}
-
+
+static uint8_t oem_value_add_exists(void)
+{
+ outb(0x96, 100);
static void pt_update_acpi_tables(struct acpi_header *header, struct hvm_acinfo_table *va_ac)
{
memcpy(header->oem_id, va_ac->oem_id, HVM_ACINFO_OEM_ID_SIZE);
-@@ -68,6 +88,59 @@
+@@ -68,6 +88,59 @@ static void pt_update_acpi_tables(struct acpi_header *header, struct hvm_acinfo_
header->creator_revision = va_ac->creator_revision;
}
-
+
+static int construct_oem_ssdt(uint8_t *buf)
+{
+ struct smbios_type_1 *type1_info;
static int construct_madt(struct acpi_20_madt *madt, struct hvm_acinfo_table *va_ac)
{
struct acpi_20_madt_intsrcovr *intsrcovr;
-@@ -183,12 +256,13 @@
-
+@@ -183,12 +256,13 @@ static int construct_hpet(struct acpi_20_hpet *hpet, struct hvm_acinfo_table *va
+
static int construct_secondary_tables(uint8_t *buf, unsigned long *table_ptrs, struct hvm_acinfo_table *va_ac)
{
- int offset = 0, nr_tables = 0;
uint16_t *tis_hdr;
+ uint8_t *oem_ssdt;
void *lasa;
-
+
/* MADT. */
-@@ -222,6 +296,17 @@
+@@ -222,6 +296,17 @@ static int construct_secondary_tables(uint8_t *buf, unsigned long *table_ptrs, s
offset += align16(va_ac->slic_length);
}
-
+
+ if ( oem_value_add_exists() )
+ {
+ oem_ssdt = &buf[offset];
/* TPM TCPA and SSDT. */
tis_hdr = (uint16_t *)0xFED40F00;
if ( (tis_hdr[0] == tis_signature[0]) &&
-diff -Nur a/tools/firmware/hvmloader/acpi/Makefile b/tools/firmware/hvmloader/acpi/Makefile
---- a/tools/firmware/hvmloader/acpi/Makefile 2009-04-01 16:30:52.000000000 -0400
-+++ b/tools/firmware/hvmloader/acpi/Makefile 2009-04-01 16:36:38.000000000 -0400
-@@ -19,7 +19,7 @@
- include $(XEN_ROOT)/tools/firmware/Rules.mk
-
- C_SRC = build.c dsdt.c static_tables.c
--H_SRC = $(wildcard *.h) ssdt_pm.h ssdt_tpm.h
-+H_SRC = $(wildcard *.h) ssdt_pm.h ssdt_hp_6930p_elitebook.h ssdt_dell_latitude_eseries.h ssdt_lenovo_t_and_x_series.h ssdt_tpm.h
- OBJS = $(patsubst %.c,%.o,$(C_SRC))
-
- build.o: $(H_SRC) build.c
-@@ -39,6 +39,27 @@
- mv $*.hex $@
- rm -f *.aml
-
-+ssdt_hp_6930p_elitebook.h: ssdt_hp_6930p_elitebook.asl
-+ $(MAKE) iasl
-+ iasl -tc $<
-+ sed -i'' -re 's/AmlCode/AmlCode_HP_6930P_ELITEBOOK/g' $*.hex
-+ mv $*.hex $@
-+ rm -f *.aml
-+
-+ssdt_dell_latitude_eseries.h: ssdt_dell_latitude_eseries.asl
-+ $(MAKE) iasl
-+ iasl -tc $<
-+ sed -i'' -re 's/AmlCode/AmlCode_DELL_LATITUDE_ESERIES/g' $*.hex
-+ mv $*.hex $@
-+ rm -f *.aml
-+
-+ssdt_lenovo_t_and_x_series.h: ssdt_lenovo_t_and_x_series.asl
-+ $(MAKE) iasl
-+ iasl -tc $<
-+ sed -i'' -re 's/AmlCode/AmlCode_LENOVO_T_AND_X_SERIES/g' $*.hex
-+ mv $*.hex $@
-+ rm -f *.aml
-+
- ssdt_tpm.h: ssdt_tpm.asl
- $(MAKE) iasl
- iasl -tc $<
-diff
+diff --git a/tools/firmware/hvmloader/acpi/ssdt_dell_latitude_eseries.asl b/tools/firmware/hvmloader/acpi/ssdt_dell_latitude_eseries.asl
+new file mode 100644
+index 0000000..fa64074
--- /dev/null
-+++ b/tools/firmware/hvmloader/acpi/ssdt_dell_latitude_eseries.asl 2009-04-01 16:35:13.000000000 -0400
++++ b/tools/firmware/hvmloader/acpi/ssdt_dell_latitude_eseries.asl
@@ -0,0 +1,516 @@
+/*
+ * ssdt_dell_latitude_eseries.asl
+ }
+}
+
-diff
+diff --git a/tools/firmware/hvmloader/acpi/ssdt_hp_6930p_elitebook.asl b/tools/firmware/hvmloader/acpi/ssdt_hp_6930p_elitebook.asl
+new file mode 100644
+index 0000000..78c8e56
--- /dev/null
-+++ b/tools/firmware/hvmloader/acpi/ssdt_hp_6930p_elitebook.asl 2009-04-01 16:35:21.000000000 -0400
++++ b/tools/firmware/hvmloader/acpi/ssdt_hp_6930p_elitebook.asl
@@ -0,0 +1,1309 @@
+/*
+ * ssdt_hp_6930p_elitebook.asl
+ }
+}
+
-diff
+diff --git a/tools/firmware/hvmloader/acpi/ssdt_lenovo_t_and_x_series.asl b/tools/firmware/hvmloader/acpi/ssdt_lenovo_t_and_x_series.asl
+new file mode 100644
+index 0000000..f60b372
--- /dev/null
-+++ b/tools/firmware/hvmloader/acpi/ssdt_lenovo_t_and_x_series.asl 2009-04-01 16:35:28.000000000 -0400
++++ b/tools/firmware/hvmloader/acpi/ssdt_lenovo_t_and_x_series.asl
@@ -0,0 +1,616 @@
+/*
+ * ssdt_lenovo_t_and_x_series.asl
+ }
+}
+
-diff -Nur a/tools/xenpmd/acpi-events.c b/tools/xenpmd/acpi-events.c
---- a/tools/xenpmd/acpi-events.c 2009-04-01 16:30:52.000000000 -0400
-+++ b/tools/xenpmd/acpi-events.c 2009-04-01 16:51:29.000000000 -0400
-@@ -41,6 +41,7 @@
- #define XS_LID_EVENT_PATH "/pm/events/lidstatechanged"
- #define XS_PBTN_EVENT_PATH "/pm/events/powerbuttonpressed"
- #define XS_SBTN_EVENT_PATH "/pm/events/sleepbuttonpressed"
-+#define XS_OEM_EVENT_PATH "/oem/event"
-
- static int socket_fd;
- static pthread_t acpi_thread;
-@@ -97,6 +98,11 @@
+diff --git a/tools/xenpmd/acpi-events.c b/tools/xenpmd/acpi-events.c
+index 8baf720..dfd9b84 100644
+--- a/tools/xenpmd/acpi-events.c
++++ b/tools/xenpmd/acpi-events.c
+@@ -79,6 +79,11 @@ void handle_sbtn_pressed_event(void)
xs_write(xs, XBT_NULL, XS_SBTN_EVENT_PATH, "1", 1);
}
-
+
+void handle_oem_event(void)
+{
+ xs_write(xs, XBT_NULL, XS_OEM_EVENT_PATH, "1", 1);
void process_acpi_message(char *acpi_buffer)
{
if ( strstr(acpi_buffer, "ac_adapter") )
-@@ -119,7 +125,14 @@
+@@ -101,7 +106,14 @@ void process_acpi_message(char *acpi_buffer)
}
-
+
if ( strstr(acpi_buffer, "SBTN") )
+ {
handle_sbtn_pressed_event();
+ (strstr(acpi_buffer, "AMW0")) )
+ handle_oem_event();
}
-
+
static void *acpi_events_thread(void *arg)
+diff --git a/tools/xenpmd/xenpmd.h b/tools/xenpmd/xenpmd.h
+index 062675c..c1a462c 100644
+--- a/tools/xenpmd/xenpmd.h
++++ b/tools/xenpmd/xenpmd.h
+@@ -101,4 +101,5 @@ void acpi_events_cleanup(void);
+ #define XS_LID_EVENT_PATH "/pm/events/lidstatechanged"
+ #define XS_PBTN_EVENT_PATH "/pm/events/powerbuttonpressed"
+ #define XS_SBTN_EVENT_PATH "/pm/events/sleepbuttonpressed"
++#define XS_OEM_EVENT_PATH "/oem/event"
+
--include $(DEPS)
diff --git a/tools/xenpmd/acpi-events.c b/tools/xenpmd/acpi-events.c
new file mode 100644
-index 0000000..9e5ad53
+index 0000000..8baf720
--- /dev/null
+++ b/tools/xenpmd/acpi-events.c
-@@ -0,0 +1,167 @@
+@@ -0,0 +1,149 @@
+/*
+ * acpi-events.c
+ *
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
-+#include <stdio.h>
-+#include <string.h>
-+#include <pthread.h>
-+#include <sys/socket.h>
-+#include <sys/un.h>
-+#include <unistd.h>
-+#include <xs.h>
-+
-+#define AC_ADAPTER_STATE_FILE_PATH "/proc/acpi/ac_adapter/AC/state"
-+#define LID_STATE_FILE_PATH "/proc/acpi/button/lid/LID/state"
-+#define ACPID_SOCKET_PATH "/var/run/acpid.socket"
-+
-+#define XS_AC_ADAPTER_STATE_PATH "/pm/ac_adapter"
-+#define XS_LID_STATE_PATH "/pm/lid_state"
-+
-+#define XS_AC_ADAPTER_EVENT_PATH "/pm/events/acadapterstatechanged"
-+#define XS_LID_EVENT_PATH "/pm/events/lidstatechanged"
-+#define XS_PBTN_EVENT_PATH "/pm/events/powerbuttonpressed"
-+#define XS_SBTN_EVENT_PATH "/pm/events/sleepbuttonpressed"
++#include "xenpmd.h"
+
+static int socket_fd;
+static pthread_t acpi_thread;
+}
+
diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c
-index 28de744..db8e292 100644
+index 28de744..50583b8 100644
--- a/tools/xenpmd/xenpmd.c
+++ b/tools/xenpmd/xenpmd.c
-@@ -40,10 +40,11 @@
- #include <dirent.h>
- #include <unistd.h>
- #include <sys/stat.h>
-+#include <pthread.h>
- #include <xs.h>
+@@ -33,68 +33,10 @@
+ * passed to the guest when appropriate battery ports are read/written to.
+ */
- /* #define RUN_STANDALONE */
+-#include <stdio.h>
+-#include <stdarg.h>
+-#include <string.h>
+-#include <stdlib.h>
+-#include <dirent.h>
+-#include <unistd.h>
+-#include <sys/stat.h>
+-#include <xs.h>
+-
+-/* #define RUN_STANDALONE */
-#define RUN_IN_SIMULATE_MODE
-+/* #define RUN_IN_SIMULATE_MODE */
-
- enum BATTERY_INFO_TYPE {
- BIF,
-@@ -84,7 +85,12 @@ struct battery_status {
- unsigned long present_voltage;
- };
-
+-
+-enum BATTERY_INFO_TYPE {
+- BIF,
+- BST
+-};
+-
+-enum BATTERY_PRESENT {
+- NO,
+- YES
+-};
+-
+-enum BATTERY_TECHNOLOGY {
+- NON_RECHARGEABLE,
+- RECHARGEABLE
+-};
+-
+-struct battery_info {
+- enum BATTERY_PRESENT present;
+- unsigned long design_capacity;
+- unsigned long last_full_capacity;
+- enum BATTERY_TECHNOLOGY battery_technology;
+- unsigned long design_voltage;
+- unsigned long design_capacity_warning;
+- unsigned long design_capacity_low;
+- unsigned long capacity_granularity_1;
+- unsigned long capacity_granularity_2;
+- char model_number[32];
+- char serial_number[32];
+- char battery_type[32];
+- char oem_info[32];
+-};
+-
+-struct battery_status {
+- enum BATTERY_PRESENT present;
+- unsigned long state;
+- unsigned long present_rate;
+- unsigned long remaining_capacity;
+- unsigned long present_voltage;
+-};
+-
-static struct xs_handle *xs;
+-
+-#ifdef RUN_IN_SIMULATE_MODE
+- #define BATTERY_DIR_PATH "/tmp/battery"
+- #define BATTERY_INFO_FILE_PATH "/tmp/battery/%s/info"
+- #define BATTERY_STATE_FILE_PATH "/tmp/battery/%s/state"
+-#else
+- #define BATTERY_DIR_PATH "/proc/acpi/battery"
+- #define BATTERY_INFO_FILE_PATH "/proc/acpi/battery/%s/info"
+- #define BATTERY_STATE_FILE_PATH "/proc/acpi/battery/%s/state"
+-#endif
++#include "xenpmd.h"
++
+struct xs_handle *xs;
+static pthread_t worker_thread;
-+
-+extern void initialize_system_state_info(void);
-+extern void monitor_acpi_events(void);
-+extern void acpi_events_cleanup(void);
- #ifdef RUN_IN_SIMULATE_MODE
- #define BATTERY_DIR_PATH "/tmp/battery"
-@@ -218,11 +224,19 @@ void set_attribute_battery_status(char *attrib_name,
+ FILE *get_next_battery_file(DIR *battery_dir,
+ enum BATTERY_INFO_TYPE battery_info_type)
+@@ -218,11 +160,19 @@ void set_attribute_battery_status(char *attrib_name,
{
if ( strstr(attrib_name, "charging state") )
{
return;
}
-@@ -292,11 +306,12 @@ int get_next_battery_info_or_status(DIR *battery_dir,
+@@ -292,11 +242,12 @@ int get_next_battery_info_or_status(DIR *battery_dir,
void *info_or_status)
{
FILE *file;
if (type == BIF)
memset(info_or_status, 0, sizeof(struct battery_info));
else
-@@ -306,8 +321,11 @@ int get_next_battery_info_or_status(DIR *battery_dir,
+@@ -306,8 +257,11 @@ int get_next_battery_info_or_status(DIR *battery_dir,
if ( !file )
return 0;
fclose(file);
return 1;
-@@ -317,14 +335,14 @@ int get_next_battery_info_or_status(DIR *battery_dir,
+@@ -317,14 +271,14 @@ int get_next_battery_info_or_status(DIR *battery_dir,
void print_battery_info(struct battery_info *info)
{
printf("present: %d\n", info->present);
printf("model number: %s\n", info->model_number);
printf("serial number: %s\n", info->serial_number);
printf("battery type: %s\n", info->battery_type);
-@@ -406,10 +424,11 @@ int write_one_time_battery_info(void)
+@@ -406,10 +360,11 @@ int write_one_time_battery_info(void)
void print_battery_status(struct battery_status *status)
{
printf("present: %d\n", status->present);
}
#endif /*RUN_STANDALONE*/
-@@ -469,6 +488,7 @@ int wait_for_and_update_battery_status_request(void)
- return ret;
+@@ -429,46 +384,59 @@ void write_battery_status_to_xenstore(struct battery_status *status)
+ xs_write(xs, XBT_NULL, "/pm/bst", val, 35);
+ }
+
+-int wait_for_and_update_battery_status_request(void)
++void update_battery_status(void)
+ {
+ DIR *dir;
+- int ret = 0;
+- unsigned int count;
+ struct battery_status status;
+
+- while ( true )
+- {
+- /* KN:@TODO - It is rather inefficient to not cache the file handle.
+- * Switch to caching file handle.
+- */
+- dir = opendir(BATTERY_DIR_PATH);
+- if ( !dir )
+- return 0;
++ /* KN:@TODO - It is rather inefficient to not cache the file handle.
++ * Switch to caching file handle.
++ */
++ dir = opendir(BATTERY_DIR_PATH);
++ if ( !dir )
++ return;
+
+- while ( get_next_battery_info_or_status(dir, BST, (void *)&status) )
+- {
++ while ( get_next_battery_info_or_status(dir, BST, (void *)&status) )
++ {
+ #ifdef RUN_STANDALONE
+- print_battery_status(&status);
++ print_battery_status(&status);
+ #endif
+- if ( status.present == YES )
+- {
+- write_battery_status_to_xenstore(&status);
+- ret = 1;
+- /* rethink this; though I have never seen, there might be
+- * systems out there with more than one battery device
+- * present
+- */
+- break;
+- }
++ if ( status.present == YES )
++ {
++ write_battery_status_to_xenstore(&status);
++ /* rethink this; though I have never seen, there might be
++ * systems out there with more than one battery device
++ * present
++ */
++ break;
+ }
+- closedir(dir);
+- xs_watch(xs, "/pm/events", "refreshbatterystatus");
+- xs_read_watch(xs, &count);
+ }
+
+- return ret;
++ closedir(dir);
++ return;
++}
++
++void wait_for_and_update_power_mgmt_info(void)
++{
++ char **buffer;
++ unsigned int count;
++
++ update_battery_status();
++
++ xs_watch(xs, "/pm/events", "refreshbatterystatus");
++ while ( true )
++ {
++ buffer = xs_read_watch(xs, &count);
++ if ( buffer == NULL )
++ continue;
++ if (!strcmp(buffer[XS_WATCH_TOKEN], "refreshbatterystatus")) {
++ update_battery_status();
++ }
++ free(buffer);
++ }
}
+#ifndef RUN_STANDALONE
/* Borrowed daemonize from xenstored - Initially written by Stevens. */
static void daemonize(void)
{
-@@ -493,24 +513,53 @@ static void daemonize(void)
+@@ -493,24 +461,51 @@ static void daemonize(void)
umask(0);
}
xs = (struct xs_handle *)xs_daemon_open();
- if ( xs == NULL )
- return -1;
--
-- if ( write_one_time_battery_info() == 0 )
+ if ( xs == NULL )
+ return NULL;
-+ if ( xs == NULL )
-+ return NULL;
-+
+
+- if ( write_one_time_battery_info() == 0 )
+ initialize_system_state_info();
+ monitor_acpi_events();
+ if ( write_one_time_battery_info() == 0 )
+ return NULL;
}
- wait_for_and_update_battery_status_request();
+- wait_for_and_update_battery_status_request();
++ wait_for_and_update_power_mgmt_info();
+ acpi_events_cleanup();
xs_daemon_close(xs);
- return 0;
+
+ return 0;
+}
+diff --git a/tools/xenpmd/xenpmd.h b/tools/xenpmd/xenpmd.h
+new file mode 100644
+index 0000000..778ba38
+--- /dev/null
++++ b/tools/xenpmd/xenpmd.h
+@@ -0,0 +1,107 @@
++/*
++ * xenpmd.h
++ *
++ * xen power management daemon header
++ *
++ * Copyright (c) 2009 Citrix Systems, Inc.
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a copy
++ * of this software and associated documentation files (the "Software"), to deal
++ * in the Software without restriction, including without limitation the rights
++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the Software is
++ * furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included in
++ * all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
++ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
++ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
++ * THE SOFTWARE.
++ */
++
++#include <stdio.h>
++#include <stdarg.h>
++#include <string.h>
++#include <stdlib.h>
++#include <dirent.h>
++#include <unistd.h>
++#include <sys/stat.h>
++#include <pthread.h>
++#include <syslog.h>
++#include <sys/socket.h>
++#include <sys/un.h>
++#include <xs.h>
++
++/* #define RUN_STANDALONE */
++/* #define RUN_IN_SIMULATE_MODE */
++
++enum BATTERY_INFO_TYPE {
++ BIF,
++ BST
++};
++
++enum BATTERY_PRESENT {
++ NO,
++ YES
++};
++
++enum BATTERY_TECHNOLOGY {
++ NON_RECHARGEABLE,
++ RECHARGEABLE
++};
++
++struct battery_info {
++ enum BATTERY_PRESENT present;
++ unsigned long design_capacity;
++ unsigned long last_full_capacity;
++ enum BATTERY_TECHNOLOGY battery_technology;
++ unsigned long design_voltage;
++ unsigned long design_capacity_warning;
++ unsigned long design_capacity_low;
++ unsigned long capacity_granularity_1;
++ unsigned long capacity_granularity_2;
++ char model_number[32];
++ char serial_number[32];
++ char battery_type[32];
++ char oem_info[32];
++};
++
++struct battery_status {
++ enum BATTERY_PRESENT present;
++ unsigned long state;
++ unsigned long present_rate;
++ unsigned long remaining_capacity;
++ unsigned long present_voltage;
++};
++
++void initialize_system_state_info(void);
++void monitor_acpi_events(void);
++void acpi_events_cleanup(void);
++
++#ifdef RUN_IN_SIMULATE_MODE
++ #define BATTERY_DIR_PATH "/tmp/battery"
++ #define BATTERY_INFO_FILE_PATH "/tmp/battery/%s/info"
++ #define BATTERY_STATE_FILE_PATH "/tmp/battery/%s/state"
++#else
++ #define BATTERY_DIR_PATH "/proc/acpi/battery"
++ #define BATTERY_INFO_FILE_PATH "/proc/acpi/battery/%s/info"
++ #define BATTERY_STATE_FILE_PATH "/proc/acpi/battery/%s/state"
++#endif
++
++#define AC_ADAPTER_STATE_FILE_PATH "/proc/acpi/ac_adapter/AC/state"
++#define LID_STATE_FILE_PATH "/proc/acpi/button/lid/LID/state"
++#define ACPID_SOCKET_PATH "/var/run/acpid.socket"
++
++#define XS_AC_ADAPTER_STATE_PATH "/pm/ac_adapter"
++#define XS_LID_STATE_PATH "/pm/lid_state"
++
++#define XS_AC_ADAPTER_EVENT_PATH "/pm/events/acadapterstatechanged"
++#define XS_LID_EVENT_PATH "/pm/events/lidstatechanged"
++#define XS_PBTN_EVENT_PATH "/pm/events/powerbuttonpressed"
++#define XS_SBTN_EVENT_PATH "/pm/events/sleepbuttonpressed"
++
-diff -Nur a/tools/firmware/hvmloader/acpi/ssdt_pm.asl b/tools/firmware/hvmloader/acpi/ssdt_pm.asl
---- a/tools/firmware/hvmloader/acpi/ssdt_pm.asl 2009-04-01 17:16:42.000000000 -0400
-+++ b/tools/firmware/hvmloader/acpi/ssdt_pm.asl 2009-04-01 17:18:03.000000000 -0400
-@@ -95,6 +95,14 @@
+diff --git a/tools/firmware/hvmloader/acpi/ssdt_pm.asl b/tools/firmware/hvmloader/acpi/ssdt_pm.asl
+index 8f2d7a7..6f2ade9 100644
+--- a/tools/firmware/hvmloader/acpi/ssdt_pm.asl
++++ b/tools/firmware/hvmloader/acpi/ssdt_pm.asl
+@@ -95,6 +95,14 @@ DefinitionBlock ("SSDT_PM.aml", "SSDT", 2, "Xen", "HVM", 0)
P88, 8
}
/* OperationRegion for Power Button */
OperationRegion (PBOP, SystemIO, 0x200, 0x01)
Field (PBOP, ByteAcc, NoLock, WriteAsZeros)
-@@ -529,6 +537,24 @@
+@@ -529,6 +537,24 @@ DefinitionBlock ("SSDT_PM.aml", "SSDT", 2, "Xen", "HVM", 0)
}
}
/* Wire GPE events to notify power state
* changes like ac power to battery use etc.
*/
-diff -Nur a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c
---- a/tools/xenpmd/xenpmd.c 2009-04-01 17:16:42.000000000 -0400
-+++ b/tools/xenpmd/xenpmd.c 2009-04-01 17:22:49.000000000 -0400
-@@ -93,13 +93,17 @@
- extern void acpi_events_cleanup(void);
-
- #ifdef RUN_IN_SIMULATE_MODE
-- #define BATTERY_DIR_PATH "/tmp/battery"
-- #define BATTERY_INFO_FILE_PATH "/tmp/battery/%s/info"
-- #define BATTERY_STATE_FILE_PATH "/tmp/battery/%s/state"
-+ #define BATTERY_DIR_PATH "/tmp/battery"
-+ #define BATTERY_INFO_FILE_PATH "/tmp/battery/%s/info"
-+ #define BATTERY_STATE_FILE_PATH "/tmp/battery/%s/state"
-+ #define THERMAL_TRIP_POINTS_FILE "/tmp/thermal_zone/%s/trip_points"
-+ #define THERMAL_TEMPERATURE_FILE "/tmp/thermal_zone/%s/temperature"
- #else
-- #define BATTERY_DIR_PATH "/proc/acpi/battery"
-- #define BATTERY_INFO_FILE_PATH "/proc/acpi/battery/%s/info"
-- #define BATTERY_STATE_FILE_PATH "/proc/acpi/battery/%s/state"
-+ #define BATTERY_DIR_PATH "/proc/acpi/battery"
-+ #define BATTERY_INFO_FILE_PATH "/proc/acpi/battery/%s/info"
-+ #define BATTERY_STATE_FILE_PATH "/proc/acpi/battery/%s/state"
-+ #define THERMAL_TRIP_POINTS_FILE "/proc/acpi/thermal_zone/%s/trip_points"
-+ #define THERMAL_TEMPERATURE_FILE "/proc/acpi/thermal_zone/%s/temperature"
- #endif
-
- FILE *get_next_battery_file(DIR *battery_dir,
-@@ -448,44 +452,188 @@
- xs_write(xs, XBT_NULL, "/pm/bst", val, 35);
+diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c
+index 50583b8..72742a8 100644
+--- a/tools/xenpmd/xenpmd.c
++++ b/tools/xenpmd/xenpmd.c
+@@ -416,14 +416,144 @@ void update_battery_status(void)
+ return;
}
--int wait_for_and_update_battery_status_request(void)
-+void update_battery_status(void)
- {
- DIR *dir;
-- int ret = 0;
-- unsigned int count;
- struct battery_status status;
-
-- while ( true )
-- {
-- /* KN:@TODO - It is rather inefficient to not cache the file handle.
-- * Switch to caching file handle.
-- */
-- dir = opendir(BATTERY_DIR_PATH);
-- if ( !dir )
-- return 0;
-+ /* KN:@TODO - It is rather inefficient to not cache the file handle.
-+ * Switch to caching file handle.
-+ */
-+ dir = opendir(BATTERY_DIR_PATH);
-+ if ( !dir )
-+ return;
-
-- while ( get_next_battery_info_or_status(dir, BST, (void *)&status) )
-- {
-+ while ( get_next_battery_info_or_status(dir, BST, (void *)&status) )
-+ {
- #ifdef RUN_STANDALONE
-- print_battery_status(&status);
-+ print_battery_status(&status);
- #endif
-- if ( status.present == YES )
-- {
-- write_battery_status_to_xenstore(&status);
-- ret = 1;
-- /* rethink this; though I have never seen, there might be
-- * systems out there with more than one battery device
-- * present
-- */
-- break;
-- }
-+ if ( status.present == YES )
-+ {
-+ write_battery_status_to_xenstore(&status);
-+ /* rethink this; though I have never seen, there might be
-+ * systems out there with more than one battery device
-+ * present
-+ */
-+ break;
- }
-- closedir(dir);
-- xs_watch(xs, "/pm/events", "refreshbatterystatus");
-- xs_read_watch(xs, &count);
- }
-
-- return ret;
-+ closedir(dir);
-+ return;
-+}
-+
+int open_thermal_files(char *subdir, FILE **trip_points_file, FILE **temp_file)
+{
+ char trip_points_file_name[64];
+ }
+ return 0;
+ }
-+
++
+ return 1;
+}
+
-+/* Note: Below is the simplest approach based on studying the
++/* Note: Below is the simplest approach based on studying the
+ * different thermal zones exposed by the OEMs at this point.
+ * In specific Dell E6*00, Lenovo T400, HP 6930p was taken into
+ * consideration before arriving at which thermal zone to expose
+
+ get_thermal_files(&trip_points_file, &temp_file);
+ if ( trip_points_file == NULL || temp_file == NULL )
-+ return;
++ return;
+
+ current_temp = get_thermalzone_value(temp_file, "temperature");
+ critical_trip_point = get_thermalzone_value(trip_points_file, "critical");
+ xs_write(xs, XBT_NULL, "/pm/current_temperature", buffer, strlen(buffer));
+
+ snprintf(buffer, 32, "%d", critical_trip_point);
-+ xs_write(xs, XBT_NULL, "/pm/critical_temperature", buffer, strlen(buffer));
++ xs_write(xs, XBT_NULL, "/pm/critical_temperature", buffer, strlen(buffer));
+}
+
-+void wait_for_and_update_power_mgmt_info(void)
-+{
-+ char **buffer;
-+ unsigned int count;
-+
-+ update_battery_status();
+ void wait_for_and_update_power_mgmt_info(void)
+ {
+ char **buffer;
+ unsigned int count;
+
+ update_battery_status();
+ update_thermal_info();
-+
-+ xs_watch(xs, "/pm/events", "refreshbatterystatus");
+
+ xs_watch(xs, "/pm/events", "refreshbatterystatus");
+ xs_watch(xs, "/pm/events", "refreshthermalinfo");
+
-+ while ( true )
-+ {
-+ buffer = xs_read_watch(xs, &count);
-+ if ( buffer == NULL )
-+ continue;
-+ if (!strcmp(buffer[XS_WATCH_TOKEN], "refreshbatterystatus")) {
-+ update_battery_status();
-+ } else if (!strcmp(buffer[XS_WATCH_TOKEN], "refreshthermalinfo")) {
+ while ( true )
+ {
+ buffer = xs_read_watch(xs, &count);
+@@ -431,7 +561,11 @@ void wait_for_and_update_power_mgmt_info(void)
+ continue;
+ if (!strcmp(buffer[XS_WATCH_TOKEN], "refreshbatterystatus")) {
+ update_battery_status();
++ }
++ else if (!strcmp(buffer[XS_WATCH_TOKEN], "refreshthermalinfo")) {
+ update_thermal_info();
-+ }
-+ free(buffer);
-+ }
- }
-
- #ifndef RUN_STANDALONE
-@@ -539,7 +687,7 @@
- return 0;
+ }
++
+ free(buffer);
}
+ }
+diff --git a/tools/xenpmd/xenpmd.h b/tools/xenpmd/xenpmd.h
+index c1a462c..508196e 100644
+--- a/tools/xenpmd/xenpmd.h
++++ b/tools/xenpmd/xenpmd.h
+@@ -84,10 +84,14 @@ void acpi_events_cleanup(void);
+ #define BATTERY_DIR_PATH "/tmp/battery"
+ #define BATTERY_INFO_FILE_PATH "/tmp/battery/%s/info"
+ #define BATTERY_STATE_FILE_PATH "/tmp/battery/%s/state"
++ #define THERMAL_TRIP_POINTS_FILE "/tmp/thermal_zone/%s/trip_points"
++ #define THERMAL_TEMPERATURE_FILE "/tmp/thermal_zone/%s/temperature"
+ #else
+ #define BATTERY_DIR_PATH "/proc/acpi/battery"
+ #define BATTERY_INFO_FILE_PATH "/proc/acpi/battery/%s/info"
+ #define BATTERY_STATE_FILE_PATH "/proc/acpi/battery/%s/state"
++ #define THERMAL_TRIP_POINTS_FILE "/proc/acpi/thermal_zone/%s/trip_points"
++ #define THERMAL_TEMPERATURE_FILE "/proc/acpi/thermal_zone/%s/temperature"
+ #endif
-- wait_for_and_update_battery_status_request();
-+ wait_for_and_update_power_mgmt_info();
- acpi_events_cleanup();
- xs_daemon_close(xs);
- return 0;
+ #define AC_ADAPTER_STATE_FILE_PATH "/proc/acpi/ac_adapter/AC/state"