From patchwork Fri Oct 17 13:36:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 38859 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 42C582054E for ; Fri, 17 Oct 2014 13:38:41 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id d1sf569916wiv.6 for ; Fri, 17 Oct 2014 06:38: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:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=PhU5G/D6o2EB4D4952vt2A/e0mhaKJwO+U1b4qjOZNs=; b=HJlrrwAygtkeeoMQSAE6pJg7Tr3jxupIBs2PY31EC/S5AsT42YlX9y0uyU+fJaGVFi cRyR5sT9uipeS6UhU57Q3Inu88f3oD9S2RJ8lUSQzZtcHKuvdefJzhLVg/LTJoKJHGr7 GNjOa6isw/cU3iJKrlcuahElWOT0ogDD73Vh6EY+YpD9EFMUP6r/3e2ilaQykRRedFDi x/tGLm02YhKVGiz7Jhr/PNlo3lemGdigrJcXxVTcl0By18sKMkee6wcuF4yDVf3VEhyq w5rzSh2ljRccztrGKu6oh91i2toOZZzhl+ow34UKKlGLxv0GxOdUyge3pxPoKa5kDXTU G4Dg== X-Gm-Message-State: ALoCoQmxl9YL9bUNTc7VOgQMfMWPXZsHtnmGcIA0l9n3P2ZILbfFCGS2PVI0HE3u/DZCbtjO0b2w X-Received: by 10.112.140.132 with SMTP id rg4mr439388lbb.12.1413553120421; Fri, 17 Oct 2014 06:38:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.133 with SMTP id b5ls239007lah.26.gmail; Fri, 17 Oct 2014 06:38:40 -0700 (PDT) X-Received: by 10.152.179.164 with SMTP id dh4mr8829603lac.55.1413553120089; Fri, 17 Oct 2014 06:38:40 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id lc6si2045451lbb.129.2014.10.17.06.38.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Oct 2014 06:38:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id gf13so795226lab.1 for ; Fri, 17 Oct 2014 06:38:40 -0700 (PDT) X-Received: by 10.153.8.164 with SMTP id dl4mr8877949lad.29.1413553119958; Fri, 17 Oct 2014 06:38:39 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp228243lbz; Fri, 17 Oct 2014 06:38:39 -0700 (PDT) X-Received: by 10.70.124.196 with SMTP id mk4mr8763941pdb.14.1413553118249; Fri, 17 Oct 2014 06:38:38 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ru9si1142685pab.173.2014.10.17.06.38.35 for ; Fri, 17 Oct 2014 06:38:38 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752950AbaJQNiI (ORCPT + 27 others); Fri, 17 Oct 2014 09:38:08 -0400 Received: from mail-pd0-f177.google.com ([209.85.192.177]:58391 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752077AbaJQNiD (ORCPT ); Fri, 17 Oct 2014 09:38:03 -0400 Received: by mail-pd0-f177.google.com with SMTP id v10so805885pde.36 for ; Fri, 17 Oct 2014 06:38:03 -0700 (PDT) X-Received: by 10.67.15.69 with SMTP id fm5mr8351407pad.91.1413553082946; Fri, 17 Oct 2014 06:38:02 -0700 (PDT) Received: from localhost ([220.202.153.90]) by mx.google.com with ESMTPSA id fv4sm1624938pbd.47.2014.10.17.06.37.58 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 17 Oct 2014 06:38:01 -0700 (PDT) From: Hanjun Guo To: Catalin Marinas , "Rafael J. Wysocki" , Mark Rutland , Olof Johansson , Grant Likely , Will Deacon Cc: Graeme Gregory , Arnd Bergmann , Sudeep Holla , Jon Masters , Jason Cooper , Marc Zyngier , Bjorn Helgaas , Daniel Lezcano , Mark Brown , Rob Herring , Robert Richter , Lv Zheng , Robert Moore , Lorenzo Pieralisi , Liviu Dudau , Randy Dunlap , Charles.Garcia-Tobin@arm.com, Kangkang.Shen@huawei.com, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linaro-acpi@lists.linaro.org, Ashwin Chaugule , Tomasz Nowicki , Hanjun Guo Subject: [PATCH v5 02/18] ACPI / table: Add new function to get table entries Date: Fri, 17 Oct 2014 21:36:58 +0800 Message-Id: <1413553034-20956-3-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1413553034-20956-1-git-send-email-hanjun.guo@linaro.org> References: <1413553034-20956-1-git-send-email-hanjun.guo@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: hanjun.guo@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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(). Acked-by: Grant Likely Signed-off-by: Ashwin Chaugule Signed-off-by: Tomasz Nowicki Signed-off-by: Hanjun Guo --- drivers/acpi/tables.c | 67 ++++++++++++++++++++++++++++++++++--------------- include/linux/acpi.h | 4 +++ 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 6d5a6cd..21ae521 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -192,17 +192,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; @@ -210,13 +207,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; } @@ -232,30 +227,62 @@ acpi_table_parse_entries(char *id, if (entry->type == entry_id && (!max_entries || count++ < max_entries)) if (handler(entry, table_end)) - goto err; + return -EINVAL; /* * 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); - goto err; + pr_err("[0x%02x] Invalid zero length\n", entry_id); + return -EINVAL; } 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); + table_header->signature, entry_id, count - max_entries, + count); } - early_acpi_os_unmap_memory((char *)table_header, tbl_size); return count; -err: +} + +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 807cbc4..36d5012 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -123,6 +123,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,