From patchwork Wed Mar 19 23:09:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashwin Chaugule X-Patchwork-Id: 26614 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f200.google.com (mail-vc0-f200.google.com [209.85.220.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 88D6520534 for ; Wed, 19 Mar 2014 23:10:10 +0000 (UTC) Received: by mail-vc0-f200.google.com with SMTP id lg15sf103412vcb.11 for ; Wed, 19 Mar 2014 16:10:10 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=6DNOKCC5QdOv81ls9i9ayHv88X9or/PpxZbWbBzrijk=; b=XlMQL0cq0foMZNYLvIGbAEd0UzqgXRsQDRaxNu/XqtkpGVL1VF6ts5huTx/X6eObZs 7nyS/3NMIHRStjFuGAM1z+Ef8G9OQ167W4VvzfeMbI5jioQsG6rl6zFcfyAdQpdk8F8k 8BbmZyCtlBogaX09CCJK2TS95VFoTDo0cuUHKDbq+7Rb8mE/XsE/0PkhtjShM5WYG76s qk5si6Vu9OXNGBqFX/RfUhaNyQYd5b5VywKAFfM9dGuMpFQJFjyl05p230Pq8B4dDZnJ srfKzznbN2MwC6eq+q9H8OjtDqaK/9bJ9ZCC6CpttzlVAs+JIa1D6P8OItw4fZ29yHV0 gg2g== X-Gm-Message-State: ALoCoQnkAjMtP35zuGJzGUQNjGvQz8f5ydelKO/ttduFMSZwPWcM577FQZT/we1uPOA/zDPBJohc X-Received: by 10.236.25.175 with SMTP id z35mr13981512yhz.32.1395270610071; Wed, 19 Mar 2014 16:10:10 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.70 with SMTP id u64ls7360qgd.80.gmail; Wed, 19 Mar 2014 16:10:09 -0700 (PDT) X-Received: by 10.58.161.205 with SMTP id xu13mr11399075veb.4.1395270609739; Wed, 19 Mar 2014 16:10:09 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id m3si2531vcr.131.2014.03.19.16.10.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Mar 2014 16:10:09 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id oz11so41013veb.20 for ; Wed, 19 Mar 2014 16:10:09 -0700 (PDT) X-Received: by 10.221.53.194 with SMTP id vr2mr754353vcb.41.1395270609417; Wed, 19 Mar 2014 16:10:09 -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.220.78.9 with SMTP id i9csp341982vck; Wed, 19 Mar 2014 16:10:08 -0700 (PDT) X-Received: by 10.69.0.39 with SMTP id av7mr42480747pbd.4.1395270608564; Wed, 19 Mar 2014 16:10:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si10647613paw.414.2014.03.19.16.09.52; Wed, 19 Mar 2014 16:09:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752981AbaCSXJt (ORCPT + 8 others); Wed, 19 Mar 2014 19:09:49 -0400 Received: from mail-qa0-f49.google.com ([209.85.216.49]:48771 "EHLO mail-qa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751295AbaCSXJt (ORCPT ); Wed, 19 Mar 2014 19:09:49 -0400 Received: by mail-qa0-f49.google.com with SMTP id j7so38918qaq.22 for ; Wed, 19 Mar 2014 16:09:48 -0700 (PDT) X-Received: by 10.224.98.197 with SMTP id r5mr45980158qan.47.1395270588183; Wed, 19 Mar 2014 16:09:48 -0700 (PDT) Received: from localhost.localdomain (cpe-098-027-049-158.nc.res.rr.com. [98.27.49.158]) by mx.google.com with ESMTPSA id t104sm68226qga.8.2014.03.19.16.09.46 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Mar 2014 16:09:47 -0700 (PDT) From: Ashwin Chaugule To: linaro-acpi@lists.linaro.org Cc: rjw@rjwysocki.net, lenb@kernel.org, linux-acpi@vger.kernel.org, Ashwin Chaugule Subject: [RFC] ACPI: Add new function to get table entries Date: Wed, 19 Mar 2014 19:09:28 -0400 Message-Id: <1395270568-30021-1-git-send-email-ashwin.chaugule@linaro.org> X-Mailer: git-send-email 1.8.3.2 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: ashwin.chaugule@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , 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 --- drivers/acpi/tables.c | 69 +++++++++++++++++++++++++++++++++++---------------- include/linux/acpi.h | 4 +++ 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 5837f85..b7bd6a3 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -199,19 +199,15 @@ 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; unsigned long table_end; - acpi_size tbl_size; if (acpi_disabled) return -ENODEV; @@ -219,16 +215,14 @@ 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_header) { - printk(KERN_WARNING PREFIX "%4.4s not present\n", id); + pr_warn(PREFIX "Table header not present\n"); return -ENODEV; } + if (!table_size) + table_size = table_header->length; + table_end = (unsigned long)table_header + table_header->length; /* Parse all entries looking for a match. */ @@ -240,15 +234,18 @@ 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(PREFIX "[%4.4s:0x%02x] Invalid zero length\n", id, entry_id); + pr_err(PREFIX "[0x%02x] Invalid zero length\n", entry_id); + count = -EINVAL; goto err; } @@ -256,15 +253,43 @@ acpi_table_parse_entries(char *id, ((unsigned long)entry + entry->length); } if (max_entries && count > max_entries) { - printk(KERN_WARNING PREFIX "[%4.4s:0x%02x] ignored %i entries of " - "%i found\n", id, entry_id, count - max_entries, count); + printk(KERN_WARNING PREFIX "[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: - early_acpi_os_unmap_memory((char *)table_header, tbl_size); - return -EINVAL; + early_acpi_os_unmap_memory((char *)table_header, (acpi_size)table_size); + 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; + + 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; + } + + return acpi_parse_entries(table_header->length, handler, table_header, + entry_id, max_entries); } int __init diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 1151a1d..da959fd 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -118,6 +118,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,