From patchwork Sat Jan 23 09:20:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 60242 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp352261lbb; Sat, 23 Jan 2016 01:24:51 -0800 (PST) X-Received: by 10.55.41.91 with SMTP id p88mr9085300qkh.86.1453541082902; Sat, 23 Jan 2016 01:24:42 -0800 (PST) Return-Path: Received: from lists.xen.org (lists.xenproject.org. [50.57.142.19]) by mx.google.com with ESMTPS id a65si12225904qga.23.2016.01.23.01.24.42 (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 23 Jan 2016 01:24:42 -0800 (PST) Received-SPF: neutral (google.com: 50.57.142.19 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=50.57.142.19; Authentication-Results: mx.google.com; spf=neutral (google.com: 50.57.142.19 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.72) (envelope-from ) id 1aMuPA-0007cW-KI; Sat, 23 Jan 2016 09:22:48 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aMuP9-0007cK-Cl for xen-devel@lists.xen.org; Sat, 23 Jan 2016 09:22:47 +0000 Received: from [85.158.143.35] by server-3.bemta-4.messagelabs.com id 51/1C-31122-66643A65; Sat, 23 Jan 2016 09:22:46 +0000 X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-15.tower-21.messagelabs.com!1453540961!11687648!1 X-Originating-IP: [119.145.14.65] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTE5LjE0NS4xNC42NSA9PiA3NzQ2Mw==\n X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 63962 invoked from network); 23 Jan 2016 09:22:45 -0000 Received: from szxga02-in.huawei.com (HELO szxga02-in.huawei.com) (119.145.14.65) by server-15.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 23 Jan 2016 09:22:45 -0000 Received: from 172.24.1.47 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DAK81956; Sat, 23 Jan 2016 17:22:25 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Sat, 23 Jan 2016 17:22:18 +0800 From: Shannon Zhao To: Date: Sat, 23 Jan 2016 17:20:02 +0800 Message-ID: <1453540813-15764-11-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1453540813-15764-1-git-send-email-zhaoshenglong@huawei.com> References: <1453540813-15764-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.0A090202.56A34652.0030, 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: a7cf5102fddfe9412bb98f607aadd099 Cc: ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, peter.huangpeng@huawei.com, julien.grall@citrix.com, stefano.stabellini@citrix.com, shannon.zhao@linaro.org, Jan Beulich Subject: [Xen-devel] [PATCH v4 10/21] acpi/table: Introduce acpi_table_get_entry_madt to get specified entry X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org 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 --- V4: Fix coding style and make the function only for MADT table --- xen/drivers/acpi/tables.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/acpi.h | 2 ++ 2 files changed, 61 insertions(+) -- 2.0.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel diff --git a/xen/drivers/acpi/tables.c b/xen/drivers/acpi/tables.c index 84a290f..c50bae4 100644 --- a/xen/drivers/acpi/tables.c +++ b/xen/drivers/acpi/tables.c @@ -219,6 +219,65 @@ void __init acpi_table_print_madt_entry(struct acpi_subtable_header *header) } } +static struct acpi_subtable_header * __init +acpi_get_entry(char *id, unsigned long table_size, + struct acpi_table_header *table_header, int 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 id, unsigned int entry_index) +{ + struct acpi_table_header *table_header = NULL; + + acpi_get_table(ACPI_SIG_MADT, acpi_apic_instance, &table_header); + if (!table_header) { + 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, 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 bc73310..32d7a4f 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);