From patchwork Wed Feb 4 14:01:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parth Dixit X-Patchwork-Id: 44350 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EC9202029F for ; Wed, 4 Feb 2015 14:06:14 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id b6sf1501710lbj.0 for ; Wed, 04 Feb 2015 06:06:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=tOy98oNKAjM94+wz7I4ruOBLpQpBHvGK3iULfW5tTm8=; b=SVp3RV4WIVdV/ggUj5Jz1c/+33QFW07nbWhdETn3WuULVGNGmqtUDBMNklVfLzboO5 vLlbVy8YaJv+aEt+cldF9vSEQW+8Mg852JPzGiTVt2JnqKM9jyaZJ78tBti0cqYvkg7g Jqd094b8Yhp9RSllynNnJw6fcdYMLUiTpct4IxllrqAcTNhRB2BDZYGYgPQ1c3VkXRRC QucaZ8MpcQOz9p5Xt8UeC9I/AVnLhiRx9wRvcE9BJsz3m6w/6BiC8xGHtYF65NBxGeqB p0yLuQG1AAjDbvU9SuTdT0O152vPe1ADvsdR5DBQ7khpLfPCB0Holhk8ZI3wVWtjW66b QAVQ== X-Gm-Message-State: ALoCoQk7/Ou2avgV4omK9VGWc8BFcJCs9XmKKrc349BMTyw/C2LpT9vFxMOafdjFtrnCOSS40B0Y X-Received: by 10.112.64.171 with SMTP id p11mr460978lbs.12.1423058773979; Wed, 04 Feb 2015 06:06:13 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.130 with SMTP id v2ls30237lae.98.gmail; Wed, 04 Feb 2015 06:06:13 -0800 (PST) X-Received: by 10.152.5.167 with SMTP id t7mr19551741lat.32.1423058773838; Wed, 04 Feb 2015 06:06:13 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id wl10si1405630lbb.90.2015.02.04.06.06.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Feb 2015 06:06:13 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id f15so1656281lbj.5 for ; Wed, 04 Feb 2015 06:06:13 -0800 (PST) X-Received: by 10.152.245.44 with SMTP id xl12mr30530940lac.81.1423058773683; Wed, 04 Feb 2015 06:06:13 -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.35.133 with SMTP id h5csp507535lbj; Wed, 4 Feb 2015 06:06:12 -0800 (PST) X-Received: by 10.220.172.130 with SMTP id l2mr19236305vcz.42.1423058771770; Wed, 04 Feb 2015 06:06:11 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id m6si702704vcr.90.2015.02.04.06.06.10 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 04 Feb 2015 06:06:11 -0800 (PST) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YJ0Z8-00078W-Bl; Wed, 04 Feb 2015 14:04:26 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YJ0Z6-000771-VR for xen-devel@lists.xen.org; Wed, 04 Feb 2015 14:04:25 +0000 Received: from [85.158.143.35] by server-3.bemta-4.messagelabs.com id 4E/9D-02754-8E622D45; Wed, 04 Feb 2015 14:04:24 +0000 X-Env-Sender: parth.dixit@linaro.org X-Msg-Ref: server-15.tower-21.messagelabs.com!1423058662!12457453!1 X-Originating-IP: [209.85.192.179] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.13.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7388 invoked from network); 4 Feb 2015 14:04:23 -0000 Received: from mail-pd0-f179.google.com (HELO mail-pd0-f179.google.com) (209.85.192.179) by server-15.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 4 Feb 2015 14:04:23 -0000 Received: by pdbft15 with SMTP id ft15so875887pdb.5 for ; Wed, 04 Feb 2015 06:04:22 -0800 (PST) X-Received: by 10.68.162.225 with SMTP id yd1mr22001135pbb.75.1423058662398; Wed, 04 Feb 2015 06:04:22 -0800 (PST) Received: from parthd-ubunutu.qualcomm.com ([202.46.23.62]) by mx.google.com with ESMTPSA id kg12sm2161881pbb.44.2015.02.04.06.04.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Feb 2015 06:04:21 -0800 (PST) From: parth.dixit@linaro.org To: xen-devel@lists.xen.org Date: Wed, 4 Feb 2015 19:31:57 +0530 Message-Id: <1423058539-26403-14-git-send-email-parth.dixit@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1423058539-26403-1-git-send-email-parth.dixit@linaro.org> References: <1423058539-26403-1-git-send-email-parth.dixit@linaro.org> Cc: ian.campbell@citrix.com, Naresh Bhat , julien.grall@linaro.org, tim@xen.org, stefano.stabellini@citrix.com, jbeulich@suse.com, christoffer.dall@linaro.org Subject: [Xen-devel] [PATCH RFC 13/35] ACPI: Introduce acpi_parse_entries X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: parth.dixit@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.217.174 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-Archive: From: Naresh Bhat Introduce acpi_parse_entries Signed-off-by: Naresh Bhat --- xen/drivers/acpi/tables.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/acpi.h | 4 +++ 2 files changed, 68 insertions(+) diff --git a/xen/drivers/acpi/tables.c b/xen/drivers/acpi/tables.c index 6754933..5314f0b 100644 --- a/xen/drivers/acpi/tables.c +++ b/xen/drivers/acpi/tables.c @@ -239,6 +239,70 @@ void __init acpi_table_print_madt_entry(struct acpi_subtable_header *header) int __init +acpi_parse_entries(unsigned long table_size, + acpi_table_entry_handler handler, + struct acpi_table_header *table_header, + int entry_id, unsigned int max_entries) +{ + struct acpi_subtable_header *entry; + int count = 0; + unsigned long table_end; + + if (acpi_disabled) + return -ENODEV; + + if (!handler) + return -EINVAL; + + if (!table_size) + return -EINVAL; + + if (!table_header) { + printk("Table header not present\n"); + return -ENODEV; + } + + table_end = (unsigned long)table_header + table_header->length; + + /* Parse all entries looking for a match. */ + + entry = (struct acpi_subtable_header *) + ((unsigned long)table_header + table_size); + + while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < + table_end) { + if (entry->type == entry_id + && (!max_entries || count++ < max_entries)) + 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) { + printk("[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) { + printk("[0x%02x] ignored %i entries of %i found\n", + entry_id, count - max_entries, count); + } + +err: + return count; +} + + +int __init acpi_table_parse_entries(char *id, unsigned long table_size, int entry_id, diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h index 9387b36..bf60334 100644 --- a/xen/include/xen/acpi.h +++ b/xen/include/xen/acpi.h @@ -81,6 +81,10 @@ void acpi_hest_init(void); int acpi_table_init (void); int acpi_table_parse(char *id, acpi_table_handler handler); +int __init acpi_parse_entries(unsigned long table_size, + acpi_table_entry_handler handler, + struct acpi_table_header *table_header, + int entry_id, unsigned int max_entries); int acpi_table_parse_entries(char *id, unsigned long table_size, int entry_id, acpi_table_entry_handler handler, unsigned int max_entries); int acpi_table_parse_madt(enum acpi_madt_type id, acpi_table_entry_handler handler, unsigned int max_entries);