From patchwork Fri Jul 10 10:45:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 51024 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5F53B2290A for ; Fri, 10 Jul 2015 10:46:11 +0000 (UTC) Received: by laar3 with SMTP id r3sf81972220laa.1 for ; Fri, 10 Jul 2015 03:46:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=zZhL0k2uZlzFX++/XcWukFf5JNIJar4FIsPMQsvv2PQ=; b=jbW+tMm6rcb4bK3cUqUkAtimgz9I4eyFRtx8pc8zBn06Un+rr8z4pQCPElIA8C8E5r m4iZypWIKS+L/9WKjZ+EhSzkJxWNaOfTox95hx+ply6hjYXmaAAKfNtKDCK6B+gu7vRz RKKCHJqBJuiOoy3sZWk1e10rzswU1oPvKmYJBmyZFe/8OUcoty0jOTfLpoMJtV5XlsPE f2daZsZ21ac/OdWRvMPvVdwe3bQ33ATQREiK7rmGgsvEg7rzHjJhR2+MSAFn02BtmBHH s9+6lHz3yD3Nk3Cxcuz+0aEy39bGiuwUhPLx2zgK7XqnvNO12Sy5JcBTLipiAamUdCvu VbAA== X-Gm-Message-State: ALoCoQkyJHU4cyCp1RHcNlTV23KTKCjD0iZxbRDAtrFTP9OKkztLJTtfRrCzCscetpwgaEsg5Q3I X-Received: by 10.112.91.166 with SMTP id cf6mr10499135lbb.8.1436525170385; Fri, 10 Jul 2015 03:46:10 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.36 with SMTP id ll4ls1110782lac.36.gmail; Fri, 10 Jul 2015 03:46:10 -0700 (PDT) X-Received: by 10.152.10.97 with SMTP id h1mr19418823lab.45.1436525170206; Fri, 10 Jul 2015 03:46:10 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id er7si7005899lac.153.2015.07.10.03.46.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Jul 2015 03:46:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by labgy5 with SMTP id gy5so110701180lab.2 for ; Fri, 10 Jul 2015 03:46:10 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr18877717lbc.41.1436525170044; Fri, 10 Jul 2015 03:46:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1287858lbb; Fri, 10 Jul 2015 03:46:08 -0700 (PDT) X-Received: by 10.68.57.168 with SMTP id j8mr40055204pbq.99.1436525168019; Fri, 10 Jul 2015 03:46:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id iu9si13343962pbc.77.2015.07.10.03.46.07; Fri, 10 Jul 2015 03:46:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754237AbbGJKqC (ORCPT + 29 others); Fri, 10 Jul 2015 06:46:02 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:35131 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754043AbbGJKpn (ORCPT ); Fri, 10 Jul 2015 06:45:43 -0400 Received: by pactm7 with SMTP id tm7so166723729pac.2 for ; Fri, 10 Jul 2015 03:45:43 -0700 (PDT) X-Received: by 10.66.129.161 with SMTP id nx1mr41484399pab.84.1436525143117; Fri, 10 Jul 2015 03:45:43 -0700 (PDT) Received: from localhost (211-79-127-12.veetime.com. [211.79.127.12]) by smtp.googlemail.com with ESMTPSA id fr2sm9113823pdb.22.2015.07.10.03.45.41 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 10 Jul 2015 03:45:42 -0700 (PDT) From: Hanjun Guo To: Marc Zyngier , Jason Cooper , Will Deacon , Catalin Marinas , "Rafael J. Wysocki" Cc: Thomas Gleixner , Jiang Liu , Lorenzo Pieralisi , Arnd Bergmann , Tomasz Nowicki , Grant Likely , Mark Brown , Wei Huang , linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linaro-acpi@lists.linaro.org, Hanjun Guo Subject: [PATCH v3 2/8] ACPI / irqchip: Add self-probe infrastructure to initialize IRQ controller Date: Fri, 10 Jul 2015 18:45:08 +0800 Message-Id: <1436525114-14425-3-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436525114-14425-1-git-send-email-hanjun.guo@linaro.org> References: <1436525114-14425-1-git-send-email-hanjun.guo@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: hanjun.guo@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This self-probe infrastructure works in the similar way as OF, but there is some different in the mechanism: For DT, the init fn will be called once it finds compatible strings in DT, but for ACPI, we init irqchips by static tables, and in static ACPI tables, there are no compatible strings to indicate irqchips, but thanks to the GIC version presented in ACPI table, we can call the corresponding GIC drivers matching the GIC version with this framework. This mechanism can also be used for clock declare and may also works on x86 for some table parsing too. Part of this patch is based on Tomasz Nowicki's work. Signed-off-by: Tomasz Nowicki Signed-off-by: Hanjun Guo --- drivers/irqchip/irq-gic-acpi.c | 29 +++++++++++++++++++++++++++++ include/asm-generic/vmlinux.lds.h | 13 +++++++++++++ include/linux/acpi.h | 16 ++++++++++++++++ include/linux/irqchip.h | 13 +++++++++++++ include/linux/mod_devicetable.h | 8 ++++++++ 5 files changed, 79 insertions(+) diff --git a/drivers/irqchip/irq-gic-acpi.c b/drivers/irqchip/irq-gic-acpi.c index 6537b43..e003a89 100644 --- a/drivers/irqchip/irq-gic-acpi.c +++ b/drivers/irqchip/irq-gic-acpi.c @@ -107,3 +107,32 @@ static int __init acpi_gic_version_init(void) return 0; } + +/* + * This special acpi_table_id is the sentinel at the end of the + * acpi_table_id[] array of all irqchips. It is automatically placed at + * the end of the array by the linker, thanks to being part of a + * special section. + */ +static const struct acpi_table_id +irqchip_acpi_match_end __used __section(__irqchip_acpi_table_end); + +extern struct acpi_table_id __irqchip_acpi_table[]; + +void __init acpi_irqchip_init(void) +{ + struct acpi_table_id *id; + + if (acpi_disabled) + return; + + if (acpi_gic_version_init()) + return; + + /* scan the irqchip table to match the GIC version and its driver */ + for (id = __irqchip_acpi_table; id->id[0]; id++) { + if (gic_version == (u8)id->driver_data) + acpi_table_parse(id->id, + (acpi_tbl_table_handler)id->handler); + } +} diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 8bd374d..625776c 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -181,6 +181,18 @@ #define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method) #define EARLYCON_OF_TABLES() OF_TABLE(CONFIG_SERIAL_EARLYCON, earlycon) +#ifdef CONFIG_ACPI +#define ACPI_TABLE(name) \ + . = ALIGN(8); \ + VMLINUX_SYMBOL(__##name##_acpi_table) = .; \ + *(__##name##_acpi_table) \ + *(__##name##_acpi_table_end) + +#define IRQCHIP_ACPI_MATCH_TABLE() ACPI_TABLE(irqchip) +#else +#define IRQCHIP_ACPI_MATCH_TABLE() +#endif + #define KERNEL_DTB() \ STRUCT_ALIGN(); \ VMLINUX_SYMBOL(__dtb_start) = .; \ @@ -516,6 +528,7 @@ CPUIDLE_METHOD_OF_TABLES() \ KERNEL_DTB() \ IRQCHIP_OF_MATCH_TABLE() \ + IRQCHIP_ACPI_MATCH_TABLE() \ EARLYCON_TABLE() \ EARLYCON_OF_TABLES() diff --git a/include/linux/acpi.h b/include/linux/acpi.h index c471dfc..7b058f0 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -811,4 +811,20 @@ static inline struct acpi_device *acpi_get_next_child(struct device *dev, #endif +#ifdef CONFIG_ACPI +#define ACPI_DECLARE(table, name, table_id, data, fn) \ + static const struct acpi_table_id __acpi_table_##name \ + __used __section(__##table##_acpi_table) \ + = { .id = table_id, \ + .handler = (void *)fn, \ + .driver_data = data } +#else +#define ACPI_DECLARE(table, name, table_id, data, fn) \ + static const struct acpi_table_id __acpi_table_##name \ + __attribute__((unused)) \ + = { .id = table_id, \ + .handler = (void *)fn, \ + .driver_data = data } +#endif + #endif /*_LINUX_ACPI_H*/ diff --git a/include/linux/irqchip.h b/include/linux/irqchip.h index 6388873..6b66d3e 100644 --- a/include/linux/irqchip.h +++ b/include/linux/irqchip.h @@ -11,6 +11,7 @@ #ifndef _LINUX_IRQCHIP_H #define _LINUX_IRQCHIP_H +#include #include /* @@ -25,6 +26,18 @@ */ #define IRQCHIP_DECLARE(name, compat, fn) OF_DECLARE_2(irqchip, name, compat, fn) +/* + * This macro must be used by the different ARM GIC drivers to declare + * the association between their version and their initialization function. + * + * @name: name that must be unique accross all IRQCHIP_ACPI_DECLARE of the + * same file. + * @gic_version: version of GIC + * @fn: initialization function + */ +#define IRQCHIP_ACPI_DECLARE(name, gic_version, fn) \ + ACPI_DECLARE(irqchip, name, ACPI_SIG_MADT, gic_version, fn) + #ifdef CONFIG_IRQCHIP void irqchip_init(void); #else diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index 8183d66..c74855f 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -191,6 +191,14 @@ struct acpi_device_id { kernel_ulong_t driver_data; }; +#define ACPI_TABLE_ID_LEN 5 + +struct acpi_table_id { + __u8 id[ACPI_TABLE_ID_LEN]; + const void *handler; + kernel_ulong_t driver_data; +}; + #define PNP_ID_LEN 8 #define PNP_MAX_DEVICES 8