From patchwork Mon Aug 4 15:28:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 34868 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f198.google.com (mail-ig0-f198.google.com [209.85.213.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 14E2E21F5F for ; Mon, 4 Aug 2014 15:31:06 +0000 (UTC) Received: by mail-ig0-f198.google.com with SMTP id h18sf14838720igc.5 for ; Mon, 04 Aug 2014 08:31:05 -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=Fy9JaqzC4o245lh8ujNtJ3hLslad6XdHih45t+EDEMU=; b=PcHKYpKLtEDwweTm87NMB/rg55WxtFNd3WMu8beN4CQG8Sx18nDvGlp3xgf8EXyEZh Ybc+Rk2acEi4+1FWmAIxz2WXXYSjmT5rKecEHBtvpR6Mfl0c///HmwT2U4nsdQoBXVKU SrLcQE4s56mo+Bd4RYQgmUhYOUrtBf58xEOwV3afPBB/L8JWZLr9ln8yrVQxPNVkRTub pWKmyBEyFXvAkM51ZUxYf1nEJ++E/bTIyRt99jfbouiagTYNARP4NBa0t24IArQ+KpDH mvN4cVAsv+nC6z5YDYSTs51cudd6jUu9n2oKCKVnzyV1jNIiySIkmozoTQS4nHtxHemW 0ulg== X-Gm-Message-State: ALoCoQmO+kADeiKc22cEHi9SP91FJb2ogH9J4OrL8uzgwOyBTtF/YCTnYbdKQFRlinFjJ4Xqu7GZ X-Received: by 10.50.126.9 with SMTP id mu9mr9073612igb.6.1407166265606; Mon, 04 Aug 2014 08:31:05 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.32.97 with SMTP id g88ls490529qgg.1.gmail; Mon, 04 Aug 2014 08:31:05 -0700 (PDT) X-Received: by 10.220.95.132 with SMTP id d4mr24216956vcn.33.1407166265508; Mon, 04 Aug 2014 08:31:05 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id jp10si12179315vdb.9.2014.08.04.08.31.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Aug 2014 08:31:05 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf12so11381804vcb.29 for ; Mon, 04 Aug 2014 08:31:05 -0700 (PDT) X-Received: by 10.52.3.40 with SMTP id 8mr6382379vdz.24.1407166265180; Mon, 04 Aug 2014 08:31:05 -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.221.37.5 with SMTP id tc5csp313369vcb; Mon, 4 Aug 2014 08:31:04 -0700 (PDT) X-Received: by 10.66.119.174 with SMTP id kv14mr24840041pab.52.1407166264101; Mon, 04 Aug 2014 08:31:04 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q9si9009207pdj.265.2014.08.04.08.30.59 for ; Mon, 04 Aug 2014 08:31:04 -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 S1753199AbaHDPav (ORCPT + 21 others); Mon, 4 Aug 2014 11:30:51 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:41915 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752085AbaHDPas (ORCPT ); Mon, 4 Aug 2014 11:30:48 -0400 Received: by mail-pd0-f176.google.com with SMTP id y10so9796524pdj.21 for ; Mon, 04 Aug 2014 08:30:48 -0700 (PDT) X-Received: by 10.70.90.79 with SMTP id bu15mr2940119pdb.158.1407166248180; Mon, 04 Aug 2014 08:30:48 -0700 (PDT) Received: from localhost ([39.182.20.233]) by mx.google.com with ESMTPSA id ry10sm64367533pab.38.2014.08.04.08.30.40 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 04 Aug 2014 08:30:46 -0700 (PDT) From: Hanjun Guo To: Catalin Marinas , "Rafael J. Wysocki" , Mark Rutland Cc: Graeme Gregory , Arnd Bergmann , Olof Johansson , Grant Likely , Sudeep Holla , Will Deacon , 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, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linaro-acpi@lists.linaro.org, Ashwin Chaugule , Hanjun Guo Subject: [PATCH v2 11/18] ACPI / table: Add new function to get table entries Date: Mon, 4 Aug 2014 23:28:18 +0800 Message-Id: <1407166105-17675-12-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1407166105-17675-1-git-send-email-hanjun.guo@linaro.org> References: <1407166105-17675-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.220.170 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(). 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 77f8bb1..a58fce4 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -229,17 +229,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; @@ -247,13 +244,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; } @@ -268,31 +263,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 e4b6e9a..18ed9f4 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,