From patchwork Sat Feb 27 06:37:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 63268 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1573818lbc; Mon, 29 Feb 2016 18:19:10 -0800 (PST) X-Received: by 10.107.165.17 with SMTP id o17mr26208681ioe.42.1456798317942; Mon, 29 Feb 2016 18:11:57 -0800 (PST) Return-Path: Received: from lists.xen.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id x1si21029335igl.76.2016.02.29.18.11.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Feb 2016 18:11:57 -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 1aZYXk-0005HT-Kw; Sat, 27 Feb 2016 06:39:56 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1aZYXj-0005HM-3Y for xen-devel@lists.xen.org; Sat, 27 Feb 2016 06:39:55 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 70/3E-04060-AB441D65; Sat, 27 Feb 2016 06:39:54 +0000 X-Env-Sender: zhaoshenglong@huawei.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1456555179!24885953!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 46975 invoked from network); 27 Feb 2016 06:39:52 -0000 Received: from szxga01-in.huawei.com (HELO szxga01-in.huawei.com) (58.251.152.64) by server-13.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 27 Feb 2016 06:39:52 -0000 Received: from 172.24.1.51 (EHLO szxeml425-hub.china.huawei.com) ([172.24.1.51]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DFI15913; Sat, 27 Feb 2016 14:37:48 +0800 (CST) Received: from HGHY1Z002260041.china.huawei.com (10.177.16.142) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.235.1; Sat, 27 Feb 2016 14:37:40 +0800 From: Shannon Zhao To: Date: Sat, 27 Feb 2016 14:37:21 +0800 Message-ID: <1456555041-15180-1-git-send-email-zhaoshenglong@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1456467780-8476-11-git-send-email-zhaoshenglong@huawei.com> References: <1456467780-8476-11-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.56D1443D.000A, 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: b7e911d920a4a2917288c69f41998b6a Cc: ian.campbell@citrix.com, peter.huangpeng@huawei.com, stefano.stabellini@citrix.com, shannon.zhao@linaro.org, Jan Beulich , zhaoshenglong@huawei.com Subject: [Xen-devel] [PATCH v6 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 --- V6: address Jan's comments --- xen/drivers/acpi/tables.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/acpi.h | 2 ++ 2 files changed, 61 insertions(+) diff --git a/xen/drivers/acpi/tables.c b/xen/drivers/acpi/tables.c index f81c369..1d15d3a 100644 --- a/xen/drivers/acpi/tables.c +++ b/xen/drivers/acpi/tables.c @@ -221,6 +221,65 @@ 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 = (void *)table_header + table_size; + + while ((unsigned long)(entry + 1) < 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 = (void *)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; + 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 f05b160..946877f 100644 --- a/xen/include/xen/acpi.h +++ b/xen/include/xen/acpi.h @@ -79,6 +79,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);