From patchwork Mon Sep 1 14:57:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 4820581 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 383C6C0338 for ; Mon, 1 Sep 2014 15:06:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1F464200F3 for ; Mon, 1 Sep 2014 15:06:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E1C1A20145 for ; Mon, 1 Sep 2014 15:06:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XOT7L-0001h5-NX; Mon, 01 Sep 2014 15:02:03 +0000 Received: from mail-pd0-f179.google.com ([209.85.192.179]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XOT7I-0001NV-GH for linux-arm-kernel@lists.infradead.org; Mon, 01 Sep 2014 15:02:01 +0000 Received: by mail-pd0-f179.google.com with SMTP id z10so6357282pdj.38 for ; Mon, 01 Sep 2014 08:01:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3D8f8JmmAJVyiMr6d7IQxp6ZCa8wdvi2k7H+wevTSFo=; b=G7FZJP22s5/kKRLBeWJjXkjjBDHvEiFCoCsNJpevBzPa+VvXQaMEaxvUgFSTMQ6gGl CZG4FKpInx5IcVZDMylacywZ+aq8g07vHy+uO4kJ26HgIWJqs5ouZPwa7bjua/k35TAP eAAe1ksh1Lg0Lgp2/ncb87GHHzcEaUSHXPsNFjJfhxA/tQi1yCoxmGmoeEbadZ2vOTin Go6QmeBgwkIywBL/pWMCEXSzYGWXPyIEyPRQfMLRuuHToI/Z5GTyqwcpxqGzgDCKAfs4 N//XMoYXN3mPhQDe00G5nePnlnuZkFlfhJwjUWwUYJGviOSbgjdXPftJkAyMbj5fWlan ScJA== X-Gm-Message-State: ALoCoQmMS3yjuWSJUa61H2xLSBklpHz25+MgZtTuNPwaA4QxTsB8P/wEsT2zxe9xBmGgIkDRdNav X-Received: by 10.66.136.12 with SMTP id pw12mr19491460pab.71.1409583699979; Mon, 01 Sep 2014 08:01:39 -0700 (PDT) Received: from localhost ([202.104.114.248]) by mx.google.com with ESMTPSA id pa2sm1551868pdb.84.2014.09.01.08.01.36 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 01 Sep 2014 08:01:39 -0700 (PDT) From: Hanjun Guo To: Catalin Marinas , "Rafael J. Wysocki" , Mark Rutland , Olof Johansson , Grant Likely Subject: [PATCH v3 12/17] ACPI / table: Add new function to get table entries Date: Mon, 1 Sep 2014 22:57:50 +0800 Message-Id: <1409583475-6978-13-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1409583475-6978-1-git-send-email-hanjun.guo@linaro.org> References: <1409583475-6978-1-git-send-email-hanjun.guo@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140901_080200_589206_FC7CB02A X-CRM114-Status: GOOD ( 17.32 ) X-Spam-Score: -1.5 (-) Cc: linaro-acpi@lists.linaro.org, Liviu Dudau , Lv Zheng , Rob Herring , Lorenzo Pieralisi , Daniel Lezcano , Robert Moore , linux-acpi@vger.kernel.org, Charles.Garcia-Tobin@arm.com, Robert Richter , Jason Cooper , Arnd Bergmann , Marc Zyngier , Will Deacon , Mark Brown , Bjorn Helgaas , linux-arm-kernel@lists.infradead.org, Graeme Gregory , Randy Dunlap , linux-kernel@vger.kernel.org, Ashwin Chaugule , Hanjun Guo , Sudeep Holla X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ashwin Chaugule The acpi_table_parse() function has a callback that passes a pointer to a table_header. Add a new function which takes this pointer and parses its entries. This eliminates the need to re-traverse all the tables for each call. e.g. as in acpi_table_parse_madt() which is normally called after acpi_table_parse(). Signed-off-by: Ashwin Chaugule Signed-off-by: Hanjun Guo --- drivers/acpi/tables.c | 70 +++++++++++++++++++++++++++++++++++-------------- include/linux/acpi.h | 4 +++ 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index a97d2aa..4ab7566 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -235,17 +235,14 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) int __init -acpi_table_parse_entries(char *id, - unsigned long table_size, - int entry_id, - acpi_tbl_entry_handler handler, - unsigned int max_entries) +acpi_parse_entries(unsigned long table_size, + acpi_tbl_entry_handler handler, + struct acpi_table_header *table_header, + int entry_id, unsigned int max_entries) { - struct acpi_table_header *table_header = NULL; struct acpi_subtable_header *entry; - unsigned int count = 0; + int count = 0; unsigned long table_end; - acpi_size tbl_size; if (acpi_disabled) return -ENODEV; @@ -253,13 +250,11 @@ acpi_table_parse_entries(char *id, if (!handler) return -EINVAL; - if (strncmp(id, ACPI_SIG_MADT, 4) == 0) - acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size); - else - acpi_get_table_with_size(id, 0, &table_header, &tbl_size); + if (!table_size) + return -EINVAL; if (!table_header) { - pr_warn("%4.4s not present\n", id); + pr_warn("Table header not present\n"); return -ENODEV; } @@ -274,31 +269,66 @@ acpi_table_parse_entries(char *id, table_end) { if (entry->type == entry_id && (!max_entries || count++ < max_entries)) - if (handler(entry, table_end)) + if (handler(entry, table_end)) { + count = -EINVAL; goto err; + } /* * If entry->length is 0, break from this loop to avoid * infinite loop. */ if (entry->length == 0) { - pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id); + pr_err("[0x%02x] Invalid zero length\n", entry_id); + count = -EINVAL; goto err; } entry = (struct acpi_subtable_header *) ((unsigned long)entry + entry->length); } + if (max_entries && count > max_entries) { - pr_warn("[%4.4s:0x%02x] ignored %i entries of %i found\n", - id, entry_id, count - max_entries, count); + pr_warn("[0x%02x] ignored %i entries of %i found\n", + entry_id, count - max_entries, count); } - early_acpi_os_unmap_memory((char *)table_header, tbl_size); - return count; err: + return count; +} + +int __init +acpi_table_parse_entries(char *id, + unsigned long table_size, + int entry_id, + acpi_tbl_entry_handler handler, + unsigned int max_entries) +{ + struct acpi_table_header *table_header = NULL; + acpi_size tbl_size; + int count; + + if (acpi_disabled) + return -ENODEV; + + if (!handler) + return -EINVAL; + + if (strncmp(id, ACPI_SIG_MADT, 4) == 0) + acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size); + else + acpi_get_table_with_size(id, 0, &table_header, &tbl_size); + + if (!table_header) { + pr_warn("%4.4s not present\n", id); + return -ENODEV; + } + + count = acpi_parse_entries(table_size, handler, table_header, + entry_id, max_entries); + early_acpi_os_unmap_memory((char *)table_header, tbl_size); - return -EINVAL; + return count; } int __init diff --git a/include/linux/acpi.h b/include/linux/acpi.h index ed1c2d1..a9d79c2 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -124,6 +124,10 @@ int acpi_numa_init (void); int acpi_table_init (void); int acpi_table_parse(char *id, acpi_tbl_table_handler handler); +int __init acpi_parse_entries(unsigned long table_size, + acpi_tbl_entry_handler handler, + struct acpi_table_header *table_header, + int entry_id, unsigned int max_entries); int __init acpi_table_parse_entries(char *id, unsigned long table_size, int entry_id, acpi_tbl_entry_handler handler,