From patchwork Wed Nov 26 14:01:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 41538 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 38BD725E18 for ; Wed, 26 Nov 2014 14:01:49 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id l15sf1988941wiw.8 for ; Wed, 26 Nov 2014 06:01:48 -0800 (PST) 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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=2+UtLdl0aSpqSGVAdzGDCU0uOjLQpI3HlT6xL9Wla38=; b=RTDc44VVGFOqXnTaEwJnMCWBdcoCuwNDp/nKCzQwX4vO68dEChpgjN9pazhs6ElPqX kFbS14FS66nwX2Cq7hHRWySLREYFLpCS2xJo1IEq9Zl6W44TZfjX+oXwxlNbcxKe8wgE xFu48j57LB+Aj0+uoTiSXYeaUHJW1MHoRxyfqKnlpzDcxHhAnE94nnqHwyjV8NOXlPP2 l71RVY6vbbeohtKknq1gFJFgt809V/yKfshEGrw1rTkWuSbdB83+E6FKAt2tjKc0VWJ1 9Gg+mtUSHN54+OlyD579wy4Nw4Ymk02+2Wdnu+CXY062qji2XKizlX0EEWys/wFPUJ8M s0oQ== X-Gm-Message-State: ALoCoQnASInjQfii4C6oeoRszFv+Ov/9Gxm5FlcnLnLqmG1N95Nd0kGa6OwKMNB51E7RRHcfbwtQ X-Received: by 10.112.169.101 with SMTP id ad5mr1571083lbc.1.1417010508478; Wed, 26 Nov 2014 06:01:48 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.134 with SMTP id t6ls26645lag.78.gmail; Wed, 26 Nov 2014 06:01:48 -0800 (PST) X-Received: by 10.112.235.135 with SMTP id um7mr33429863lbc.96.1417010508226; Wed, 26 Nov 2014 06:01:48 -0800 (PST) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id g7si4533979lbs.0.2014.11.26.06.01.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 26 Nov 2014 06:01:48 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id gf13so2441063lab.41 for ; Wed, 26 Nov 2014 06:01:48 -0800 (PST) X-Received: by 10.153.7.170 with SMTP id dd10mr33801375lad.44.1417010508118; Wed, 26 Nov 2014 06:01:48 -0800 (PST) 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.184.201 with SMTP id ew9csp624398lbc; Wed, 26 Nov 2014 06:01:46 -0800 (PST) X-Received: by 10.70.126.161 with SMTP id mz1mr24597919pdb.14.1417010505327; Wed, 26 Nov 2014 06:01:45 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hh2si6965755pbb.80.2014.11.26.06.01.44 for ; Wed, 26 Nov 2014 06:01:45 -0800 (PST) Received-SPF: none (google.com: linux-acpi-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 S1752831AbaKZOBg (ORCPT + 6 others); Wed, 26 Nov 2014 09:01:36 -0500 Received: from mail-pd0-f177.google.com ([209.85.192.177]:47933 "EHLO mail-pd0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752722AbaKZOBe (ORCPT ); Wed, 26 Nov 2014 09:01:34 -0500 Received: by mail-pd0-f177.google.com with SMTP id ft15so2845841pdb.36 for ; Wed, 26 Nov 2014 06:01:34 -0800 (PST) X-Received: by 10.70.136.202 with SMTP id qc10mr53332617pdb.152.1417010493770; Wed, 26 Nov 2014 06:01:33 -0800 (PST) Received: from localhost ([39.181.45.161]) by mx.google.com with ESMTPSA id se3sm4440456pbc.24.2014.11.26.06.01.30 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 26 Nov 2014 06:01:31 -0800 (PST) From: Hanjun Guo To: "Rafael J. Wysocki" Cc: linux-acpi@vger.kernel.org, linaro-acpi@lists.linaro.org, Ashwin Chaugule , Tomasz Nowicki , Hanjun Guo Subject: [PATCH 1/2] ACPI / table: Add new function to get table entries Date: Wed, 26 Nov 2014 22:01:13 +0800 Message-Id: <1417010474-2399-1-git-send-email-hanjun.guo@linaro.com> X-Mailer: git-send-email 1.9.1 Sender: linux-acpi-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-acpi@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.54 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 | 63 +++++++++++++++++++++++++++++++++++---------------- include/linux/acpi.h | 4 ++++ 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 6d5a6cd..f1debe9 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -190,30 +190,24 @@ 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(char *id, 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; - if (!handler) + if (!id || !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); @@ -232,7 +226,7 @@ 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 @@ -240,22 +234,53 @@ acpi_table_parse_entries(char *id, */ if (entry->length == 0) { pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id); - goto err; + 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); } - 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; + u32 instance = 0; + + if (acpi_disabled) + return -ENODEV; + + if (!id || !handler) + return -EINVAL; + + if (!strncmp(id, ACPI_SIG_MADT, 4)) + instance = acpi_apic_instance; + + acpi_get_table_with_size(id, instance, &table_header, &tbl_size); + if (!table_header) { + pr_warn("%4.4s not present\n", id); + return -ENODEV; + } + + count = acpi_parse_entries(id, 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 e09f7f4..d7a5fcf 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(char *id, 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,