From patchwork Mon Feb 29 12:42:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 8453011 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AC8989F38C for ; Mon, 29 Feb 2016 12:46:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 646FA20254 for ; Mon, 29 Feb 2016 12:46:37 +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 1CC6620251 for ; Mon, 29 Feb 2016 12:46:36 +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 1aaNC4-0006pz-Oo; Mon, 29 Feb 2016 12:44:56 +0000 Received: from mail-lf0-x22c.google.com ([2a00:1450:4010:c07::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aaNAg-0005WJ-OK for linux-arm-kernel@lists.infradead.org; Mon, 29 Feb 2016 12:43:36 +0000 Received: by mail-lf0-x22c.google.com with SMTP id j186so16006054lfg.2 for ; Mon, 29 Feb 2016 04:43:10 -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=s1HbZqxqlGerrRs+lAYtX2utH34gYofvPeP0AIedyJg=; b=Frn99yPvM72McQlM6MINkvFQDkETqAtxMcaGlEnsdqoTTGr1/Vl/erYWKsLu3EiO1+ +2gE9qGYHblUgMlb38S4/DGtqcIZxVo52eC78kWFaSHueG8F3Wx5OLqQkItSg/87kH0g S4GicT/BvdL9RyJKJ3hkaVCDs7Kr2JV1quE34= 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=s1HbZqxqlGerrRs+lAYtX2utH34gYofvPeP0AIedyJg=; b=Ec0Mht4AizOc+N6JT1uj80IIL9wrEw4JDNTBzW7PtngK8Zt5o5Nebj7AhjiwKZHugI VQR0sWVflTpazm56+aEaOk0wrkivnndIXzDPcrwqhBWrqSUvS8GRT+pbTKxVxTmaA211 F6k4st32s+z6A1w2OPfxH7SovUL6hCCL5hCL0WqngrNSJKDRS5KLgycLLYmqSzUPMCF4 uvJ/nbXdWtJqmmUli7m46zYqBKu1ZxRXeSca5MIEee3FmvBydOj1EctUC/XRnKTDStIe A7K+5l3mwNIa5C0AsKjLNv9Y/3RsUB8mLyb3u0bFeNDG6dXdprJaf07fKgzL1knoIGKb d4HQ== X-Gm-Message-State: AD7BkJJUgXa51oDO+rhbzofQZQdbnyC6Z1kRpumss4w09UmwKGo+2Ju9NhxoEWL8kGAs4XvY X-Received: by 10.25.161.131 with SMTP id k125mr5452113lfe.83.1456749788926; Mon, 29 Feb 2016 04:43:08 -0800 (PST) Received: from turnip.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id ke9sm3929150lbc.28.2016.02.29.04.43.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Feb 2016 04:43:08 -0800 (PST) From: Aleksey Makarov To: linux-acpi@vger.kernel.org Subject: [PATCH v3 3/7] ACPI: genaralize iterating over subtables in ACPI_PROBE_TABLE() Date: Mon, 29 Feb 2016 15:42:00 +0300 Message-Id: <1456749726-30261-4-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1456749726-30261-1-git-send-email-aleksey.makarov@linaro.org> References: <1456749726-30261-1-git-send-email-aleksey.makarov@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160229_044331_300350_131FFF81 X-CRM114-Status: GOOD ( 23.25 ) 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: Matthias Brugger , Russell King , Jason Cooper , Graeme Gregory , Marc Zyngier , Greg Kroah-Hartman , Daniel Lezcano , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, Leif Lindholm , Aleksey Makarov , John Stultz , Christopher Covington , linux-serial@vger.kernel.org, Thomas Gleixner , 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.1 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 Refactor ACPI_PROBE_TABLE() so that it is possible to iterate over subtables that do not have acpi_subtype header (for example over subtables of DBG2 table) To do so: - Add void * data pointer argument for callback. It will allow to parse the table and iterate over subtables calling the subtable callbacks that are provided via this data pointer. - Save only ACPI table id, callback and callback data in the linker tables. This makes tables more terse and simplifies the semantics of the fields of it's elements. The additional data that required for subtable parsing are saved in static namespace without increasing the size of linker tables. - Introduce two macros with clear meaning of arguments, instead one. The old ACPI_DECLARE_PROBE_ENTRY() macros has arguments that have different meaning if the entry is for table or for subtable. The arguments of the new macroses ACPI_DECLARE_PROBE_ENTRY() and ACPI_DECLARE_PROBE_SUBTYPE_ENTRY() have unambiguous meaning. - Document arguments of those macroses instead of the fields of linker table data. - Fix the issue that prevents using this macros for parsing subtables other than MADT. In the original code, MADT-specific function was used to iterate over subtables, while the name was common. Introduce a new parameter to macors that specifies the size of the table to do it in common way. - Don't expose the internals of the tables to the drivers passing a pointer to struct acpi_probe_entry to the subtable callback validator. Instead, pass the sideband data specified by the driver. - Fix the driver's callback signatures: a. Add an unused pointer to void for table matchers (currently only clocksource callback) b. Change the type of sideband data to kernel_ulong_t. Signed-off-by: Aleksey Makarov --- drivers/acpi/scan.c | 44 ++++++++++----- drivers/clocksource/arm_arch_timer.c | 3 +- drivers/irqchip/irq-gic.c | 4 +- include/linux/acpi.h | 104 ++++++++++++++++++++++++----------- include/linux/clocksource.h | 2 +- include/linux/irqchip.h | 5 +- 6 files changed, 109 insertions(+), 53 deletions(-) diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 5f28cf7..09b5f63 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1969,16 +1969,38 @@ static struct acpi_probe_entry *ape; static int acpi_probe_count; static DEFINE_SPINLOCK(acpi_probe_lock); -static int __init acpi_match_madt(struct acpi_subtable_header *header, - const unsigned long end) +static int __init acpi_match_and_setup(struct acpi_subtable_header *header, + const unsigned long end) { - if (!ape->subtable_valid || ape->subtable_valid(header, ape)) - if (!ape->probe_subtbl(header, end)) + const struct acpi_probe_subtype_data *data = ape->data; + + if (data->valid(header, data->data)) + if (!data->setup(header, end)) acpi_probe_count++; return 0; } +int __init acpi_probe_subtype_setup(struct acpi_table_header *table, + const void *data) +{ + const struct acpi_probe_subtype_data *data_subtype = data; + + return acpi_parse_entries(ape->id, data_subtype->size, + acpi_match_and_setup, table, + data_subtype->subtype, 0); +} + +static int __init acpi_probe_table_handler(struct acpi_table_header *table) +{ + int err = ape->setup(table, ape->data); + + if (ape->setup != acpi_probe_subtype_setup && err >= 0) + acpi_probe_count++; + + return err; +} + int __init __acpi_probe_device_table(struct acpi_probe_entry *ap_head, int nr) { int count = 0; @@ -1988,16 +2010,10 @@ int __init __acpi_probe_device_table(struct acpi_probe_entry *ap_head, int nr) spin_lock(&acpi_probe_lock); for (ape = ap_head; nr; ape++, nr--) { - if (ACPI_COMPARE_NAME(ACPI_SIG_MADT, ape->id)) { - acpi_probe_count = 0; - acpi_table_parse_madt(ape->type, acpi_match_madt, 0); - count += acpi_probe_count; - } else { - int res; - res = acpi_table_parse(ape->id, ape->probe_table); - if (!res) - count++; - } + acpi_probe_count = 0; + if (acpi_table_parse(ape->id, acpi_probe_table_handler) < 0) + continue; + count += acpi_probe_count; } spin_unlock(&acpi_probe_lock); diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c index f492ced..c0df7cb 100644 --- a/drivers/clocksource/arm_arch_timer.c +++ b/drivers/clocksource/arm_arch_timer.c @@ -868,7 +868,8 @@ static int __init map_generic_timer_interrupt(u32 interrupt, u32 flags) } /* Initialize per-processor generic timer */ -static int __init arch_timer_acpi_init(struct acpi_table_header *table) +static int __init arch_timer_acpi_init(struct acpi_table_header *table, + const void *data) { struct acpi_table_gtdt *gtdt; diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c index 282344b..13d8323 100644 --- a/drivers/irqchip/irq-gic.c +++ b/drivers/irqchip/irq-gic.c @@ -1287,12 +1287,12 @@ static bool __init acpi_gic_redist_is_present(void) } static bool __init gic_validate_dist(struct acpi_subtable_header *header, - struct acpi_probe_entry *ape) + kernel_ulong_t driver_data) { struct acpi_madt_generic_distributor *dist; dist = (struct acpi_madt_generic_distributor *)header; - return (dist->version == ape->driver_data && + return (dist->version == driver_data && (dist->version != ACPI_MADT_GIC_VERSION_NONE || !acpi_gic_redist_is_present())); } diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 06ed7e5..9636c32 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -879,47 +879,76 @@ int acpi_dev_prop_read(struct acpi_device *adev, const char *propname, struct fwnode_handle *acpi_get_next_subnode(struct device *dev, struct fwnode_handle *subnode); -struct acpi_probe_entry; typedef bool (*acpi_probe_entry_validate_subtbl)(struct acpi_subtable_header *, - struct acpi_probe_entry *); + kernel_ulong_t); + +typedef int (*acpi_probe_entry_setup)(struct acpi_table_header *, const void *); #define ACPI_TABLE_ID_LEN 5 -/** - * struct acpi_probe_entry - boot-time probing entry - * @id: ACPI table name - * @type: Optional subtable type to match - * (if @id contains subtables) - * @subtable_valid: Optional callback to check the validity of - * the subtable - * @probe_table: Callback to the driver being probed when table - * match is successful - * @probe_subtbl: Callback to the driver being probed when table and - * subtable match (and optional callback is successful) - * @driver_data: Sideband data provided back to the driver - */ struct acpi_probe_entry { __u8 id[ACPI_TABLE_ID_LEN]; - __u8 type; - acpi_probe_entry_validate_subtbl subtable_valid; - union { - acpi_tbl_table_handler probe_table; - acpi_tbl_entry_handler probe_subtbl; - }; - kernel_ulong_t driver_data; + acpi_probe_entry_setup setup; + const void *data; }; -#define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, subtable, valid, data, fn) \ +/** + * ACPI_DECLARE_PROBE_ENTRY() - declare boot-time probing entry + * @table: Name of subsystem to match + * @name: Identifier to compose name of table data + * @table_id: ACPI table name + * @setup_fn: Callback to the driver being probed when table + * matches (of type acpi_probe_entry_setup) + * @data_ptr: Sideband data provided back to the driver + */ +#define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, setup_fn, data_ptr) \ static const struct acpi_probe_entry __acpi_probe_##name \ __used __section(__##table##_acpi_probe_table) \ = { \ .id = table_id, \ - .type = subtable, \ - .subtable_valid = valid, \ - .probe_table = (acpi_tbl_table_handler)fn, \ - .driver_data = data, \ + .setup = setup_fn, \ + .data = data_ptr, \ } +struct acpi_probe_subtype_data { + u8 subtype; + unsigned long size; + acpi_probe_entry_validate_subtbl valid; + acpi_tbl_entry_handler setup; + kernel_ulong_t data; +}; + +int acpi_probe_subtype_setup(struct acpi_table_header *table, const void *data); + +/** + * ACPI_DECLARE_PROBE_SUBTYPE_ENTRY() - declare boot-time probing entry that + * matches subtables + * @table: Name of subsystem to match + * @name: Identifier to compose name of table data + * @table_id: ACPI table name + * @table_size: Size of the table (without subtables) of type table_id + * @subtable: Subtable type to match + * @valid_fn: Callback to check the validity of the subtable + * (of type acpi_probe_entry_validate_subtbl) + * @data_int: Sideband data provided back to the driver + * (of type kernel_ulong_t) + * @setup_fn: Callback to the driver being probed when table and + * subtable match and valid_fn callback is successful + * (of type acpi_tbl_entry_handler) + */ +#define ACPI_DECLARE_PROBE_SUBTYPE_ENTRY(table, name, table_id, table_size, \ + subtable, valid_fn, data_int, setup_fn) \ + static const struct acpi_probe_subtype_data \ + __acpi_probe_subtype_##name __used = { \ + .subtype = subtable, \ + .size = table_size, \ + .valid = valid_fn, \ + .setup = setup_fn, \ + .data = data_int, \ + }; \ + ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, \ + acpi_probe_subtype_setup, &__acpi_probe_subtype_##name) + #define ACPI_PROBE_TABLE(name) __##name##_acpi_probe_table #define ACPI_PROBE_TABLE_END(name) __##name##_acpi_probe_table_end @@ -992,14 +1021,23 @@ static inline struct fwnode_handle *acpi_get_next_subnode(struct device *dev, return NULL; } -#define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, subtable, validate, data, fn) \ +#define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, match, data) \ static const void * __acpi_table_##name[] \ __attribute__((unused)) \ - = { (void *) table_id, \ - (void *) subtable, \ - (void *) valid, \ - (void *) fn, \ - (void *) data } + = { (void *)table_id, \ + (void *)match, \ + (void *)data } + +#define ACPI_DECLARE_PROBE_SUBTYPE_ENTRY(table, name, table_id, table_size, \ + subtable, valid_fn, data_int, setup_fn) \ + static const void *__acpi_table_##name[] \ + __attribute__((unused)) \ + = { (void *)table_id, \ + (void *)table_size, \ + (void *)subtable, \ + (void *)valid_fn, \ + (void *)data_int, \ + (void *)setup_fn } #define acpi_probe_device_table(t) ({ int __r = 0; __r;}) #endif diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index 6013021..2bb5d51 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h @@ -259,6 +259,6 @@ static inline void clocksource_probe(void) {} #endif #define CLOCKSOURCE_ACPI_DECLARE(name, table_id, fn) \ - ACPI_DECLARE_PROBE_ENTRY(clksrc, name, table_id, 0, NULL, 0, fn) + ACPI_DECLARE_PROBE_ENTRY(clksrc, name, table_id, fn, NULL) #endif /* _LINUX_CLOCKSOURCE_H */ diff --git a/include/linux/irqchip.h b/include/linux/irqchip.h index 89c34b2..cc4c455 100644 --- a/include/linux/irqchip.h +++ b/include/linux/irqchip.h @@ -39,8 +39,9 @@ * @fn: initialization function */ #define IRQCHIP_ACPI_DECLARE(name, subtable, validate, data, fn) \ - ACPI_DECLARE_PROBE_ENTRY(irqchip, name, ACPI_SIG_MADT, \ - subtable, validate, data, fn) + ACPI_DECLARE_PROBE_SUBTYPE_ENTRY(irqchip, name, ACPI_SIG_MADT, \ + sizeof(struct acpi_table_madt),\ + subtable, validate, data, fn) #ifdef CONFIG_IRQCHIP void irqchip_init(void);