From patchwork Tue Dec 6 06:48:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Hung X-Patchwork-Id: 129571 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 5004D1007DA for ; Tue, 6 Dec 2011 17:48:17 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1RXop6-0006lg-22 for incoming@patchwork.ozlabs.org; Tue, 06 Dec 2011 06:48:16 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1RXop3-0006lb-Ul for fwts-devel@lists.ubuntu.com; Tue, 06 Dec 2011 06:48:13 +0000 Received: from [210.242.151.101] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1RXop2-00060z-PO; Tue, 06 Dec 2011 06:48:13 +0000 From: Alex Hung To: fwts-devel@lists.ubuntu.com Subject: [PATCH] pcie: aspm: add aspm option and detect if the "PCIe ASPM Controls" bit is set in FADT. Date: Tue, 6 Dec 2011 14:48:07 +0800 Message-Id: <1323154087-14142-1-git-send-email-alex.hung@canonical.com> X-Mailer: git-send-email 1.7.5.4 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com Signed-off-by: Alex Hung --- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 */