From patchwork Fri Feb 26 06:22:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 63265 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1573594lbc; Mon, 29 Feb 2016 18:18:28 -0800 (PST) X-Received: by 10.50.160.37 with SMTP id xh5mr1089201igb.49.1456798315706; Mon, 29 Feb 2016 18:11:55 -0800 (PST) Return-Path: Received: from lists.xen.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id v6si21032869igz.77.2016.02.29.18.11.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Feb 2016 18:11:55 -0800 (PST) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aZBpq-00078W-Vq; Fri, 26 Feb 2016 06:25:06 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aZBpp-00076C-Tn for xen-devel@lists.xen.org; Fri, 26 Feb 2016 06:25:06 +0000 Received: from [85.158.137.68] by server-14.bemta-3.messagelabs.com id B0/BD-03098-1CFEFC65; Fri, 26 Feb 2016 06:25:05 +0000 X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1456467898!25171243!1 X-Originating-IP: [58.251.152.64] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 52571 invoked from network); 26 Feb 2016 06:25:03 -0000 Received: from szxga01-in.huawei.com (HELO szxga01-in.huawei.com) (58.251.152.64) by server-6.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 26 Feb 2016 06:25:03 -0000 Received: from 172.24.1.47 (EHLO SZXEML429-HUB.china.huawei.com) ([172.24.1.47]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DFG21616; Fri, 26 Feb 2016 14:24:11 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by SZXEML429-HUB.china.huawei.com (10.82.67.184) with Microsoft SMTP Server id 14.3.235.1; Fri, 26 Feb 2016 14:23:56 +0800 From: Shannon Zhao To: Date: Fri, 26 Feb 2016 14:22:48 +0800 Message-ID: <1456467780-8476-11-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1456467780-8476-1-git-send-email-zhaoshenglong@huawei.com> References: <1456467780-8476-1-git-send-email-zhaoshenglong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.16.142] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.56CFEF8C.0013, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 98466c48c4f0a826e184eb007f43c6d3 Cc: peter.huangpeng@huawei.com, stefano.stabellini@citrix.com, ian.campbell@citrix.com, Jan Beulich , shannon.zhao@linaro.org Subject: [Xen-devel] [PATCH v5 10/22] acpi/table: Introduce acpi_table_get_entry_madt to get specified entry X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" From: Shannon Zhao This function could get the specified index entry of MADT table. This would be useful when it needs to get the contens of the entry. Cc: Jan Beulich Signed-off-by: Shannon Zhao --- V5: address Jan's comments V4: Fix coding style and make the function only for MADT table --- xen/drivers/acpi/tables.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/acpi.h | 2 ++ 2 files changed, 64 insertions(+) diff --git a/xen/drivers/acpi/tables.c b/xen/drivers/acpi/tables.c index f81c369..fa4e666 100644 --- a/xen/drivers/acpi/tables.c +++ b/xen/drivers/acpi/tables.c @@ -221,6 +221,68 @@ void __init acpi_table_print_madt_entry(struct acpi_subtable_header *header) } } +static struct acpi_subtable_header * __init +acpi_get_entry(const char *id, unsigned long table_size, + const struct acpi_table_header *table_header, + enum acpi_madt_type entry_id, unsigned int entry_index) +{ + struct acpi_subtable_header *entry; + int count = 0; + unsigned long table_end; + + if (!table_size) + return NULL; + + if (!table_header) { + printk(KERN_WARNING PREFIX "%4.4s not present\n", id); + return NULL; + } + + 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->length < sizeof(*entry)) { + printk(KERN_ERR PREFIX "[%4.4s:%#x] Invalid length\n", + id, entry_id); + return NULL; + } + + if (entry->type == entry_id) { + if (count == entry_index) + return entry; + count++; + } + + entry = (struct acpi_subtable_header *) + ((unsigned long)entry + entry->length); + } + + return NULL; +} + +struct acpi_subtable_header * __init +acpi_table_get_entry_madt(enum acpi_madt_type entry_id, + unsigned int entry_index) +{ + struct acpi_table_header *table_header = NULL; + acpi_status status; + + status = acpi_get_table(ACPI_SIG_MADT, acpi_apic_instance, + &table_header); + if (ACPI_FAILURE(status)) { + printk(KERN_WARNING PREFIX "%4.4s not present\n", + ACPI_SIG_MADT); + return NULL; + } + + return acpi_get_entry(ACPI_SIG_MADT, sizeof(struct acpi_table_madt), + table_header, entry_id, entry_index); +} int __init acpi_parse_entries(char *id, unsigned long table_size, diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h index 894917b..2c2d6ca 100644 --- a/xen/include/xen/acpi.h +++ b/xen/include/xen/acpi.h @@ -74,6 +74,8 @@ int acpi_parse_entries(char *id, unsigned long table_size, 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); +struct acpi_subtable_header *acpi_table_get_entry_madt(enum acpi_madt_type id, + unsigned int entry_index); int acpi_table_parse_madt(enum acpi_madt_type id, acpi_table_entry_handler handler, unsigned int max_entries); int acpi_table_parse_srat(int id, acpi_madt_entry_handler handler, unsigned int max_entries);