From patchwork Fri Feb 12 17:43:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 8294471 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 817EDC02AA for ; Fri, 12 Feb 2016 17:51:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 93D9C20219 for ; Fri, 12 Feb 2016 17:51:10 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A002820212 for ; Fri, 12 Feb 2016 17:51:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aUHqm-0007yW-Jd; Fri, 12 Feb 2016 17:49:48 +0000 Received: from mail-lf0-x234.google.com ([2a00:1450:4010:c07::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aUHqH-0007i5-ES for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2016 17:49:19 +0000 Received: by mail-lf0-x234.google.com with SMTP id l143so56383115lfe.2 for ; Fri, 12 Feb 2016 09:48:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IVFgGZp1o1pxcAZbdYb3IdO1khoCPS/Y6/BYiGQeLoQ=; b=QKjIsSGlm8bxuoSvEopNtiEzTuiMjBJgGM4NtHDRoCSXh78KyyjyHq3ZThxhCrFnAq 6lwDgQ6k9m+tbbMwf8TKqAQrUYsI79PCD5Y+0DlVpobaUeKbMY3nGsNydnIAkNC0l2dY AnsgxICfK+8xpWjO9kQ5jjVjNR8FB9xoADYOk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IVFgGZp1o1pxcAZbdYb3IdO1khoCPS/Y6/BYiGQeLoQ=; b=bJYxB5ZHwuCaS9O7QbQlwLFTgb/ZGOo/JNerz22Byzqe3mXk53aeBVnHKrzuPkMYYO 9663Tz8VBA6HcjvDAdNhC/AopjbFLmN+VPhPSA6407psz/d/dKM96ARhEngOdjOaYuYO 7CVtf89f3gs4cAU08uyjRcs2bK9op+PUFHVL+dXQelcLd6yQp7HoS3vu6G7Alp/v8nfB AutQWURtHAHSVeykiwAmaw7CQos769dCUnTxgTirwzfESm+TqZSJvK6Rwn9qilZEsc9i LHoU1B/JR9bo8XNy91YLFPBqh50xu7GMc6fAHLoKC08rqOBKX7m6RB3Cy2Vz+yn8TnUp yJIg== X-Gm-Message-State: AG10YOSezUkdeJLSuEUlT1H5xeDMRGdZ14J9QQDolxhQSw9q16jABUYGfsZdeHOY/qnCWos4 X-Received: by 10.25.148.208 with SMTP id w199mr1233346lfd.124.1455299335490; Fri, 12 Feb 2016 09:48:55 -0800 (PST) Received: from turnip.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id ei4sm2017549lbb.18.2016.02.12.09.48.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Feb 2016 09:48:54 -0800 (PST) From: Aleksey Makarov To: linux-acpi@vger.kernel.org Subject: [PATCH v2 3/9] ACPI: introduce acpi_table_parse2() Date: Fri, 12 Feb 2016 20:43:34 +0300 Message-Id: <1455299022-11641-4-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1455299022-11641-1-git-send-email-aleksey.makarov@linaro.org> References: <1455299022-11641-1-git-send-email-aleksey.makarov@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160212_094917_740045_35561128 X-CRM114-Status: GOOD ( 15.57 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Russell King , Graeme Gregory , Greg Kroah-Hartman , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, Leif Lindholm , Aleksey Makarov , Christopher Covington , linux-serial@vger.kernel.org, Al Stone , linux-arm-kernel@lists.infradead.org, Len Brown MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The function acpi_table_parse() has some problems: 1 It can be called only from __init code 2 It does not pass any data to the handler 3 It just throws out the value returned from the handler These issues are addressed in this patch Signed-off-by: Aleksey Makarov --- drivers/acpi/tables.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- include/linux/acpi.h | 8 ++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index 6c0f079..98ae052 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -40,7 +40,7 @@ static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" }; static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata; -static int acpi_apic_instance __initdata; +static int acpi_apic_instance; /* * Disable table checksum verification for the early stage due to the size @@ -374,19 +374,27 @@ acpi_table_parse_madt(enum acpi_madt_type id, } /** - * acpi_table_parse - find table with @id, run @handler on it + * acpi_table_parse2 - find table with @id, run @handler on it * @id: table id to find * @handler: handler to run + * @data: data to pass to handler * * Scan the ACPI System Descriptor Table (STD) for a table matching @id, * run @handler on it. * - * Return 0 if table found, -errno if not. + * How it differs from acpi_table_parse() + * 1. It respect the return value of the handler function + * 2. It has additional data argument to make closures + * 3. It can be called from everywhere from the kernel (no __init) + * + * Return: the value returned by the handler if table found, -errno if not. */ -int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler) +int acpi_table_parse2(char *id, + int (*handler)(struct acpi_table_header *table, void *data), void *data) { struct acpi_table_header *table = NULL; acpi_size tbl_size; + int err; if (acpi_disabled) return -ENODEV; @@ -395,16 +403,43 @@ int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler) return -EINVAL; if (strncmp(id, ACPI_SIG_MADT, 4) == 0) - acpi_get_table_with_size(id, acpi_apic_instance, &table, &tbl_size); + acpi_get_table_with_size(id, acpi_apic_instance, &table, + &tbl_size); else acpi_get_table_with_size(id, 0, &table, &tbl_size); if (table) { - handler(table); + err = handler(table, data); early_acpi_os_unmap_memory(table, tbl_size); - return 0; + return err; } else return -ENODEV; + +} + +/* + * 1. fix the signature + * 2. always return 0, don't respect the value returned from the handler + */ +static int legacy_acpi_table_handler(struct acpi_table_header *table, void *d) +{ + ((acpi_tbl_table_handler)d)(table); + return 0; +} + +/** + * acpi_table_parse - find table with @id, run @handler on it + * @id: table id to find + * @handler: handler to run + * + * Scan the ACPI System Descriptor Table (STD) for a table matching @id, + * run @handler on it. + * + * Return 0 if table found, -errno if not. + */ +int __init acpi_table_parse(char *id, acpi_tbl_table_handler handler) +{ + return acpi_table_parse2(id, legacy_acpi_table_handler, handler); } /* diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 06ed7e5..bed9b89 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -218,6 +218,8 @@ int acpi_numa_init (void); int acpi_table_init (void); int acpi_table_parse(char *id, acpi_tbl_table_handler handler); +int acpi_table_parse2(char *id, int (*handler)(struct acpi_table_header *table, + void *data), void *data); int __init acpi_parse_entries(char *id, unsigned long table_size, acpi_tbl_entry_handler handler, struct acpi_table_header *table_header, @@ -636,6 +638,12 @@ static inline int acpi_table_parse(char *id, return -ENODEV; } +int acpi_table_parse2(char *id, int (*handler)(struct acpi_table_header *table, + void *data), void *data) +{ + return -ENODEV; +} + static inline int acpi_nvs_register(__u64 start, __u64 size) { return 0;