From patchwork Wed Nov 14 22:49:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10683295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD04E13BF for ; Wed, 14 Nov 2018 22:53:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B04A42BF63 for ; Wed, 14 Nov 2018 22:53:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A48302BF72; Wed, 14 Nov 2018 22:53:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B0962BF63 for ; Wed, 14 Nov 2018 22:53:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4D8D6B0269; Wed, 14 Nov 2018 17:53:06 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BFD4A6B026B; Wed, 14 Nov 2018 17:53:06 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B15EB6B026A; Wed, 14 Nov 2018 17:53:06 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id 68CB06B026B for ; Wed, 14 Nov 2018 17:53:06 -0500 (EST) Received: by mail-pf1-f200.google.com with SMTP id a72-v6so14397793pfj.14 for ; Wed, 14 Nov 2018 14:53:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=bLMs4Au7DiESCDOxLKd8+oMw9C/A5EHH/t0scKwgs+c=; b=mf31mAWSLPOw0uXUEAig0jY3fUnMiE+2qkVvrVlmhlyFRoqAiViKTWf8FIe86KFfAW KKZeYvf49Y1uNBr80k1ICcgofCqTfT32UEnt2hK+M9uTF/OaTL/6rNBcJqrEu6vaDPCE 1bkzdpyAdgalOIZyvj3q9qMHJEEkmAoINLfogFOTOg3PgmUPedCLs8y7CNcm6mxJeOXt k3u25DveTZTg6c+hZfBfQqHkNE+Mvt4T83n1TBZe/XAJaKkZs+/LuS92GotnYnFyQ6Iu Qg/9rh6s3BmODtWnE1B7W8zriQ3qX8PbYIx2wm7wp06s1Ugh5jAdVK/usAchZxfs90ac xKfg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AGRZ1gLg+9yhGcXxZ1NjX7FIdvh8QmLz2YzpEGjt3gi5yXZL8Z2TOC+l tIK1xP5nc8pdS5gRTLFGDFVaovHhq2MywFVtxk68vZui7IofD1ixglx5URTRVNQvExAfg9Encb+ 0dHiqPuWjwpG6h3Iq3HVzrUqw7hp5vGl8LcYGibQNcmb9/h+lwBR7k5w87aRkG3ubzA== X-Received: by 2002:a63:a612:: with SMTP id t18-v6mr3487409pge.338.1542235986074; Wed, 14 Nov 2018 14:53:06 -0800 (PST) X-Google-Smtp-Source: AJdET5eJRzmNTGiDF5DUxSHfHlB6k9EfEq3+lc9nonIw3GXicmo6/fZLx1qDOKRh3oaEbnsR5TkC X-Received: by 2002:a63:a612:: with SMTP id t18-v6mr3487361pge.338.1542235985201; Wed, 14 Nov 2018 14:53:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542235985; cv=none; d=google.com; s=arc-20160816; b=hKAHnk4uLR2YvrgA6+M/1RwTtHrOO0jbLSq2Ir8NVM+xk1iH6m1piKkNcHqk7Gxr5f SLJNyuVf/pol1Eo8q/neyBw6fQY7ijB3rTYB/GtboMenXkxPeADthc7VyPo07LZKoqXo 7gThx1vrEaEOSb2lcL09qv2OuCQxZLXP0geefvvV13a4J8h6j9EoOMdP9D4zS4IRd1Kh N7psyTzR83my+Oks1KVLc3G+cJxHSv4sLHVaaZOU1ssJN/HwK2mKd7mWuIcwiDf1ZDNY r25LkQ+6ZvZ/qETKY3vYyX+v2LaRaewymWWdKol3NwfaYRSYh9iBlMr8rH/RgvBAebTP Swxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=bLMs4Au7DiESCDOxLKd8+oMw9C/A5EHH/t0scKwgs+c=; b=dv+cq44pxzYWRcWeKR0NuRsHk0JB5LE+zpvwlv9r2FLIHgfPLkOWL+FPU4QzafdU1Q 1TZbmh52PlsBdpZ0JwUJx5yis49d7vEW6Vp5b80BFKfAWeWIZpF8Jgb3MCMfZMxOpUhN ZXhnIb+BZx7S4VOoRYND8ijv78dgu56KgWzLLDr2iohdALdYtgR076j94DhHTZ7VZQ6k W8O3IkFKCjoMbwj2Wt+KxcXdHePVrXMAvANJfZIzGWaN6GppuSe6D93yl2+epzs5DHgz h5u3KpP1ZuH4YbUx5NBG0ro9p/sozu/oqxs4RO/yj1Tne7Oc3F60Q0c+9pnlQv4rBcNR NVCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id h18-v6si21592604pgv.47.2018.11.14.14.53.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 14:53:05 -0800 (PST) Received-SPF: pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of keith.busch@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=keith.busch@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2018 14:53:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,234,1539673200"; d="scan'208";a="106314894" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga004.fm.intel.com with ESMTP; 14 Nov 2018 14:53:04 -0800 From: Keith Busch To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-mm@kvack.org Cc: Greg Kroah-Hartman , Rafael Wysocki , Dave Hansen , Dan Williams , Keith Busch Subject: [PATCH 6/7] acpi: Create subtable parsing infrastructure Date: Wed, 14 Nov 2018 15:49:19 -0700 Message-Id: <20181114224921.12123-7-keith.busch@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20181114224921.12123-2-keith.busch@intel.com> References: <20181114224921.12123-2-keith.busch@intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Parsing entries in an ACPI table had assumed a generic header structure that is most common. There is no standard ACPI header, though, so less common types would need custom parsers if they want go walk their subtable entry list. Create the infrastructure for adding different table types so parsing the entries array may be more reused for all ACPI system tables. Signed-off-by: Keith Busch --- drivers/acpi/tables.c | 75 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 61203eebf3a1..15ee77780f68 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -49,6 +49,19 @@ static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata; static int acpi_apic_instance __initdata; +enum acpi_subtable_type { + ACPI_SUBTABLE_COMMON, +}; + +union acpi_subtable_headers { + struct acpi_subtable_header common; +}; + +struct acpi_subtable_entry { + union acpi_subtable_headers *hdr; + enum acpi_subtable_type type; +}; + /* * Disable table checksum verification for the early stage due to the size * limitation of the current x86 early mapping implementation. @@ -217,6 +230,45 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) } } +static unsigned long __init +acpi_get_entry_type(struct acpi_subtable_entry *entry) +{ + switch (entry->type) { + case ACPI_SUBTABLE_COMMON: + return entry->hdr->common.type; + } + WARN_ONCE(1, "invalid acpi type\n"); + return 0; +} + +static unsigned long __init +acpi_get_entry_length(struct acpi_subtable_entry *entry) +{ + switch (entry->type) { + case ACPI_SUBTABLE_COMMON: + return entry->hdr->common.length; + } + WARN_ONCE(1, "invalid acpi type\n"); + return 0; +} + +static unsigned long __init +acpi_get_subtable_header_length(struct acpi_subtable_entry *entry) +{ + switch (entry->type) { + case ACPI_SUBTABLE_COMMON: + return sizeof(entry->hdr->common); + } + WARN_ONCE(1, "invalid acpi type\n"); + return 0; +} + +static enum acpi_subtable_type __init +acpi_get_subtable_type(char *id) +{ + return ACPI_SUBTABLE_COMMON; +} + /** * acpi_parse_entries_array - for each proc_num find a suitable subtable * @@ -246,8 +298,8 @@ acpi_parse_entries_array(char *id, unsigned long table_size, struct acpi_subtable_proc *proc, int proc_num, unsigned int max_entries) { - struct acpi_subtable_header *entry; - unsigned long table_end; + struct acpi_subtable_entry entry; + unsigned long table_end, subtable_len, entry_len; int count = 0; int errs = 0; int i; @@ -270,19 +322,21 @@ acpi_parse_entries_array(char *id, unsigned long table_size, /* Parse all entries looking for a match. */ - entry = (struct acpi_subtable_header *) + entry.type = acpi_get_subtable_type(id); + entry.hdr = (union acpi_subtable_headers *) ((unsigned long)table_header + table_size); + subtable_len = acpi_get_subtable_header_length(&entry); - while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < - table_end) { + while (((unsigned long)entry.hdr) + subtable_len < table_end) { if (max_entries && count >= max_entries) break; for (i = 0; i < proc_num; i++) { - if (entry->type != proc[i].id) + if (acpi_get_entry_type(&entry) != proc[i].id) continue; if (!proc[i].handler || - (!errs && proc[i].handler(entry, table_end))) { + (!errs && proc[i].handler(&entry.hdr->common, + table_end))) { errs++; continue; } @@ -297,13 +351,14 @@ acpi_parse_entries_array(char *id, unsigned long table_size, * If entry->length is 0, break from this loop to avoid * infinite loop. */ - if (entry->length == 0) { + entry_len = acpi_get_entry_length(&entry); + if (entry_len == 0) { pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, proc->id); return -EINVAL; } - entry = (struct acpi_subtable_header *) - ((unsigned long)entry + entry->length); + entry.hdr = (union acpi_subtable_headers *) + ((unsigned long)entry.hdr + entry_len); } if (max_entries && count > max_entries) {