From patchwork Mon Jul 6 07:29:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Hung X-Patchwork-Id: 491449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 69E00140D5E; Mon, 6 Jul 2015 17:29:36 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1ZC0qN-0007pz-5o; Mon, 06 Jul 2015 07:29:35 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1ZC0qI-0007o9-5U for fwts-devel@lists.ubuntu.com; Mon, 06 Jul 2015 07:29:30 +0000 Received: from [175.41.48.77] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1ZC0qH-0006Xc-JM; Mon, 06 Jul 2015 07:29:30 +0000 From: Alex Hung To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/2] acpi: add XENV table test Date: Mon, 6 Jul 2015 15:29:23 +0800 Message-Id: <1436167764-15467-2-git-send-email-alex.hung@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436167764-15467-1-git-send-email-alex.hung@canonical.com> References: <1436167764-15467-1-git-send-email-alex.hung@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com Signed-off-by: Alex Hung Acked-by: Colin Ian King Acked-by: Ivan Hu --- src/Makefile.am | 1 + src/acpi/xenv/xenv.c | 103 ++++++++++++++++++++++++++++++++++++++++++++ src/lib/include/fwts_acpi.h | 9 ++++ 3 files changed, 113 insertions(+) create mode 100644 src/acpi/xenv/xenv.c diff --git a/src/Makefile.am b/src/Makefile.am index 7cf5125..3ee3b4e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -81,6 +81,7 @@ fwts_SOURCES = main.c \ acpi/wakealarm/wakealarm.c \ acpi/wmi/wmi.c \ acpi/xsdt/xsdt.c \ + acpi/xenv/xenv.c \ apic/apicedge/apicedge.c \ bios/bios_info/bios_info.c \ bios/bios32/bios32.c \ diff --git a/src/acpi/xenv/xenv.c b/src/acpi/xenv/xenv.c new file mode 100644 index 0000000..c33942b --- /dev/null +++ b/src/acpi/xenv/xenv.c @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2006, Intel Corporation + * Copyright (C) 2010-2015 Canonical + * + * This code was originally part of the Linux-ready Firmware Developer Kit + * + * 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 "fwts.h" + +static fwts_acpi_table_info *table; + +static int xenv_init(fwts_framework *fw) +{ + if (fwts_acpi_find_table(fw, "XENV", 0, &table) != FWTS_OK) { + fwts_log_error(fw, "Cannot load ACPI table"); + return FWTS_ERROR; + } + if (table == NULL) { + fwts_log_error(fw, "ACPI XENV table does not exist, skipping test"); + return FWTS_ERROR; + } + + return FWTS_OK; +} + +/* + * Sanity check XENV table, see: + * http://wiki.xenproject.org/mediawiki/images/c/c4/Xen-environment-table.pdf + */ +static int xenv_test1(fwts_framework *fw) +{ + fwts_acpi_table_xenv *xenv = (fwts_acpi_table_xenv*)table->data; + bool passed = true; + + if (table->length < sizeof(fwts_acpi_table_xenv)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "XENVAcpiTableTooSmall", + "XENV ACPI table is %zd bytes long which is smaller " + "than the expected size of %zd bytes.", + table->length, sizeof(fwts_acpi_table_xenv)); + return FWTS_ERROR; + } + + if (xenv->header.revision != 1) { + passed = false; + fwts_failed(fw, LOG_LEVEL_HIGH, + "XENVBadRevision", + "XENV revision is incorrect, expecting 0x01, " + "instead got 0x%2.2" PRIx8, + xenv->header.revision); + } + + fwts_log_info_verbatum(fw, "XENV Table:"); + fwts_log_info_verbatum(fw, " GNT Start Address 0x%16.16" PRIx64, xenv->gnt_start); + fwts_log_info_verbatum(fw, " GNT Sizne 0x%16.16" PRIx64, xenv->gnt_size); + fwts_log_info_verbatum(fw, " Evtchn Intr: 0x%8.8" PRIx32, xenv->evtchn_intr); + fwts_log_info_verbatum(fw, " Evtchn Intr Flags: 0x%2.2" PRIx8, xenv->evtchn_intr_flags); + + if (xenv->evtchn_intr_flags & ~3) { + passed = false; + fwts_failed(fw, LOG_LEVEL_HIGH, + "XENVBadEvtchnIntrFlags", + "XENV Evtchn Intr Flags was 0x%2.2" PRIx8 + " and reserved bits [7:2] are not zero.", + xenv->evtchn_intr_flags); + } + + if (passed) + fwts_passed(fw, "No issues found in XENV table."); + + return FWTS_OK; +} + +static fwts_framework_minor_test xenv_tests[] = { + { xenv_test1, "Validate XEVN table." }, + { NULL, NULL } +}; + +static fwts_framework_ops xenv_check_ops = { + .description = "Xen Environment Table tests.", + .init = xenv_init, + .minor_tests = xenv_tests +}; + +FWTS_REGISTER("xenv", &xenv_check_ops, FWTS_TEST_ANYTIME, + FWTS_FLAG_BATCH | FWTS_FLAG_TEST_ACPI) + diff --git a/src/lib/include/fwts_acpi.h b/src/lib/include/fwts_acpi.h index 93d3817..e4d7288 100644 --- a/src/lib/include/fwts_acpi.h +++ b/src/lib/include/fwts_acpi.h @@ -535,6 +535,15 @@ typedef struct { }; } __attribute__ ((packed)) fwts_acpi_table_tcpa; +/* From http://wiki.xenproject.org/mediawiki/images/c/c4/Xen-environment-table.pdf */ +typedef struct { + fwts_acpi_table_header header; + uint64_t gnt_start; + uint64_t gnt_size; + uint32_t evtchn_intr; + uint8_t evtchn_intr_flags; +} __attribute__ ((packed)) fwts_acpi_table_xenv; + /* Following ASF definitions from http://dmtf.org/documents/asf/alert-standard-format-asf-specification-200 */ typedef struct {