From patchwork Thu Jul 6 21:52:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 9829049 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BD0FD602BD for ; Thu, 6 Jul 2017 21:52:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD42A27DCD for ; Thu, 6 Jul 2017 21:52:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A1D952842E; Thu, 6 Jul 2017 21:52:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4707E27DCD for ; Thu, 6 Jul 2017 21:52:51 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B708821CB74CD; Thu, 6 Jul 2017 14:51:05 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CD82320958992 for ; Thu, 6 Jul 2017 14:51:04 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2017 14:52:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,319,1496127600"; d="scan'208";a="989770592" Received: from theros.lm.intel.com ([10.232.112.77]) by orsmga003.jf.intel.com with ESMTP; 06 Jul 2017 14:52:44 -0700 From: Ross Zwisler To: linux-kernel@vger.kernel.org Subject: [RFC v2 2/5] acpi: HMAT support in acpi_parse_entries_array() Date: Thu, 6 Jul 2017 15:52:30 -0600 Message-Id: <20170706215233.11329-3-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170706215233.11329-1-ross.zwisler@linux.intel.com> References: <20170706215233.11329-1-ross.zwisler@linux.intel.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Box, David E" , Dave Hansen , "Zheng, Lv" , linux-nvdimm@lists.01.org, "Rafael J. Wysocki" , "Anaczkowski, Lukasz" , "Moore, Robert" , linux-acpi@vger.kernel.org, "Odzioba, Lukasz" , "Schmauss, Erik" , Len Brown , Jerome Glisse , devel@acpica.org, "Kogut, Jaroslaw" , linux-mm@kvack.org, Greg Kroah-Hartman , "Nachimuthu, Murugasamy" , "Rafael J. Wysocki" , "Lahtinen, Joonas" , Andrew Morton , Tim Chen MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP The current implementation of acpi_parse_entries_array() assumes that each subtable has a standard ACPI subtable entry of type struct acpi_sutbable_header. This standard subtable header has a one byte length followed by a one byte type. The HMAT subtables have to allow for a longer length so they have subtable headers of type struct acpi_hmat_structure which has a 2 byte type and a 4 byte length. Enhance the subtable parsing in acpi_parse_entries_array() so that it can handle these new HMAT subtables. Signed-off-by: Ross Zwisler --- drivers/acpi/numa.c | 2 +- drivers/acpi/tables.c | 52 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c index edb0c79..917f1cc 100644 --- a/drivers/acpi/numa.c +++ b/drivers/acpi/numa.c @@ -443,7 +443,7 @@ int __init acpi_numa_init(void) * So go over all cpu entries in SRAT to get apicid to node mapping. */ - /* SRAT: Static Resource Affinity Table */ + /* SRAT: System Resource Affinity Table */ if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) { struct acpi_subtable_proc srat_proc[3]; diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index ff42539..7979171 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -218,6 +218,33 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) } } +static unsigned long __init +acpi_get_entry_type(char *id, void *entry) +{ + if (!strncmp(id, ACPI_SIG_HMAT, 4)) + return ((struct acpi_hmat_structure *)entry)->type; + else + return ((struct acpi_subtable_header *)entry)->type; +} + +static unsigned long __init +acpi_get_entry_length(char *id, void *entry) +{ + if (!strncmp(id, ACPI_SIG_HMAT, 4)) + return ((struct acpi_hmat_structure *)entry)->length; + else + return ((struct acpi_subtable_header *)entry)->length; +} + +static unsigned long __init +acpi_get_subtable_header_length(char *id) +{ + if (!strncmp(id, ACPI_SIG_HMAT, 4)) + return sizeof(struct acpi_hmat_structure); + else + return sizeof(struct acpi_subtable_header); +} + /** * acpi_parse_entries_array - for each proc_num find a suitable subtable * @@ -242,10 +269,10 @@ acpi_parse_entries_array(char *id, unsigned long table_size, struct acpi_subtable_proc *proc, int proc_num, unsigned int max_entries) { - struct acpi_subtable_header *entry; - unsigned long table_end; + unsigned long table_end, subtable_header_length; int count = 0; int errs = 0; + void *entry; int i; if (acpi_disabled) @@ -263,19 +290,23 @@ acpi_parse_entries_array(char *id, unsigned long table_size, } table_end = (unsigned long)table_header + table_header->length; + subtable_header_length = acpi_get_subtable_header_length(id); /* Parse all entries looking for a match. */ - entry = (struct acpi_subtable_header *) - ((unsigned long)table_header + table_size); + entry = (void *)table_header + table_size; + + while (((unsigned long)entry) + subtable_header_length < table_end) { + unsigned long entry_type, entry_length; - while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < - table_end) { if (max_entries && count >= max_entries) break; + entry_type = acpi_get_entry_type(id, entry); + entry_length = acpi_get_entry_length(id, entry); + for (i = 0; i < proc_num; i++) { - if (entry->type != proc[i].id) + if (entry_type != proc[i].id) continue; if (!proc[i].handler || (!errs && proc[i].handler(entry, table_end))) { @@ -290,16 +321,15 @@ acpi_parse_entries_array(char *id, unsigned long table_size, count++; /* - * If entry->length is 0, break from this loop to avoid + * If entry_length is 0, break from this loop to avoid * infinite loop. */ - if (entry->length == 0) { + if (entry_length == 0) { pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, proc->id); return -EINVAL; } - entry = (struct acpi_subtable_header *) - ((unsigned long)entry + entry->length); + entry += entry_length; } if (max_entries && count > max_entries) {