[PATCH] pcie: aspm: add aspm option and detect if the "PCIe ASPM Controls" bit is set in FADT.
Alex Hung
alex.hung at canonical.com
Tue Dec 6 06:48:07 UTC 2011
Signed-off-by: Alex Hung <alex.hung at canonical.com>
---
src/lib/include/fwts.h | 1 +
src/lib/include/fwts_aspm.h | 42 +++++++++++++++++++++
src/lib/src/Makefile.am | 3 +-
src/lib/src/fwts_aspm.c | 84 ++++++++++++++++++++++++++++++++++++++++++
src/lib/src/fwts_framework.c | 4 ++
5 files changed, 133 insertions(+), 1 deletions(-)
create mode 100644 src/lib/include/fwts_aspm.h
create mode 100644 src/lib/src/fwts_aspm.c
diff --git a/src/lib/include/fwts.h b/src/lib/include/fwts.h
index f5602ea..abea55a 100644
--- a/src/lib/include/fwts.h
+++ b/src/lib/include/fwts.h
@@ -75,5 +75,6 @@
#include "fwts_ac_adapter.h"
#include "fwts_battery.h"
#include "fwts_button.h"
+#include "fwts_aspm.h"
#endif
diff --git a/src/lib/include/fwts_aspm.h b/src/lib/include/fwts_aspm.h
new file mode 100644
index 0000000..9695fe9
--- /dev/null
+++ b/src/lib/include/fwts_aspm.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2010-2011 Canonical
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef __FWTS_ASPM_H__
+#define __FWTS_ASPM_H__
+
+#define FWTS_SYS_FIRMWARE_ACPI_TABLE_FACP "/sys/firmware/acpi/tables/FACP"
+
+#define FACP_IAPC_BOOT_ARCH_LOW_BYTE_OFFSET 109
+#define FACP_IAPC_BOOT_ARCH_HIGH_BYTE_OFFSET 110
+#define FACP_TABLE_MAX 1024
+
+#define BIT0 0x01
+#define BIT1 0x02
+#define BIT2 0x04
+#define BIT3 0x08
+#define BIT4 0x10
+#define BIT5 0x20
+#define BIT6 0x40
+#define BIT7 0x80
+
+
+
+int fwts_aspm_check_configuration(fwts_framework *fw);
+
+#endif
diff --git a/src/lib/src/Makefile.am b/src/lib/src/Makefile.am
index 2aac13e..d76d4cd 100644
--- a/src/lib/src/Makefile.am
+++ b/src/lib/src/Makefile.am
@@ -56,4 +56,5 @@ libfwts_la_SOURCES = \
fwts_wakealarm.c \
fwts_ac_adapter.c \
fwts_battery.c \
- fwts_button.c
+ fwts_button.c \
+ fwts_aspm.c
diff --git a/src/lib/src/fwts_aspm.c b/src/lib/src/fwts_aspm.c
new file mode 100644
index 0000000..397dfc8
--- /dev/null
+++ b/src/lib/src/fwts_aspm.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2010-2011 Canonical
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <linux/pci.h>
+
+#include "fwts.h"
+
+int fwts_facp_get_aspm_control(fwts_framework *fw, int *aspm)
+{
+ FILE *fp;
+ char path[PATH_MAX], facp[FACP_TABLE_MAX];
+ char c;
+ int i = 0;
+ uint16_t iapc_boot_arch_low_byte;
+
+ snprintf(path, sizeof(path), "%s", FWTS_SYS_FIRMWARE_ACPI_TABLE_FACP);
+ if ((fp = fopen(path, "rb")) == NULL) {
+ fwts_log_info(fw, "FACP is not present in %s.", path);
+ return FWTS_ERROR;
+ }
+
+ c = fgetc(fp);
+ do {
+ facp[i] = c;
+ c = fgetc(fp);
+ i++;
+ } while(c != EOF);
+ fclose(fp);
+
+ iapc_boot_arch_low_byte = facp[FACP_IAPC_BOOT_ARCH_LOW_BYTE_OFFSET];
+ if ((iapc_boot_arch_low_byte & BIT4) == 0)
+ {
+ *aspm = 1;
+ fwts_log_info(fw, "PCIE ASPM is controlled by Linux kernel.");
+ } else
+ {
+ *aspm = 0;
+ fwts_log_info(fw, "PCIE ASPM is not controlled by Linux kernel.");
+ }
+
+ return FWTS_OK;
+}
+
+int fwts_aspm_check_configuration(fwts_framework *fw)
+{
+ int ret;
+ int aspm_facp;
+
+ ret = fwts_facp_get_aspm_control(fw, &aspm_facp);
+ if (ret == FWTS_ERROR)
+ {
+ fwts_log_info(fw, "No valid FACP information present: cannot test aspm.");
+ return FWTS_ERROR;
+ }
+
+ return ret;
+}
+
+
diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
index 9898537..7064c44 100644
--- a/src/lib/src/fwts_framework.c
+++ b/src/lib/src/fwts_framework.c
@@ -76,6 +76,7 @@ static fwts_option fwts_framework_options[] = {
{ "json-data-path", "j:", 1, "Specify path to fwts json data files - default is /usr/share/fwts." },
{ "lp-tags-log", "", 0, "Output LaunchPad bug tags in results log." },
{ "disassemble-aml", "", 0, "Disassemble AML from DSDT and SSDT tables." },
+ { "aspm", "", 0, "Test ASPM configuration." },
{ NULL, NULL, 0, NULL }
};
@@ -967,6 +968,9 @@ int fwts_framework_options_handler(fwts_framework *fw, int argc, char * const ar
case 31: /* --disassemble-aml */
fwts_iasl_disassemble_all_to_file(fw);
return FWTS_COMPLETE;
+ case 32: /* --aspm */
+ fwts_aspm_check_configuration(fw);
+ return FWTS_COMPLETE;
}
break;
case 'a': /* --all */
--
1.7.5.4
More information about the fwts-devel
mailing list