From patchwork Fri Jul 17 02:44:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 11668857 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BED3A138C for ; Fri, 17 Jul 2020 02:46:37 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 960D920838 for ; Fri, 17 Jul 2020 02:46:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="R/ka8R2C"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="edzH6w1t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 960D920838 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:Mime-Version:Message-Id:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=VLc7aWISfOi8zT0WtsBFCiqngrl1FkH1pLQu3pzTSHY=; b=R/ka8R2C+R3TAeldQHsYvEYpnS cVjEI/bhhMjlQkUicdfIfU/bM8BkmF53lQGoB7fnIQ/tbvDWPYqWiJvVavuYFe9gUH2Ol0qKTES9F bCXWVf8ZHvYhe924WUoCM7tfBbIUu54Z1d2WJWGqLs5YuKZqrS3igKANESnddio+B/vr8QemqZTkn 1U13NbNvvCj/7n3U7gxsM+x2cunyX4rZMd0Kl7zVrv3/yBqlluKC+uAyTlQkRu4Ta4giPX3H81L0n D0tCNrQ8KOzXtcsCOH1wzMzpuHuK983lMnTJgV2pV9u1Vy/MD9JNmG593f1rrpgHJGofx47eZF3nh FUO5R9Rg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwGMs-0006Pg-2e; Fri, 17 Jul 2020 02:44:58 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwGMp-0006Oq-PQ for linux-arm-kernel@lists.infradead.org; Fri, 17 Jul 2020 02:44:56 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id u64so9558268ybf.13 for ; Thu, 16 Jul 2020 19:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=2BxjzP72iQdxP7BBImWs20Rvt3buz2LvW5kNpRsHJrc=; b=edzH6w1tmEp4FV+8F+FvzJxmwPfMcqxN+r0PndFf2NFYuR596Xt4jVy1S/lpZiFYo5 ae7FEfCSqzYLDi7YIWgUMuCeJjkPUB+UPbluOzn0kLYVk6RjxL/cpgkXDb9qWKzFLPPC cRvAHzNnG6mJFDoIVlSSFsd68wZbcYFmytYJ2yBV0rZavd1olwPZZqP37WSypAmsKBQS Wbf4R/F3y3DxQb2LBvm+Y3KugnDSpyOIGmEwiTBG2DnOFsT4ywnYvxv0y/PE7n7WnJJK V6y75QybSjrtKuOqY8ds0cCJwlLHynUw1YbaNSXcvzxI8skPsfGKq43PzLdrLvL9qVe+ QboA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=2BxjzP72iQdxP7BBImWs20Rvt3buz2LvW5kNpRsHJrc=; b=N87Kk3WxyIONHiz1wqT2Ptvg0DIp4HWOkKpdz031Tft206rFOknzkxHT27PlqQqyR8 TZuHPDjktONM+j1jh2dNEItiBIj1m4BM8WjqSsKo6cU6ZYJh4qXR3rdmvW6SDEtMnAtA bFExVsl+aTfXmnbNrvaWkBJmBfDiy5QqladX8WlMcIRVW2R8oPNxxSYnhCwH7Q73nbqB LB62Kw8+IBEYxhjzX8GtOij5emq5G9EP8gWegWIsbeib6n/XT6byMMMzJZ4OvzpOlEEr 0SnglCBOFiEIITYii0CJPs0Tz8rx0adtZ9nUujXvKaTOofcxmOXNnimWzqOToKf5nWCY r+3A== X-Gm-Message-State: AOAM5319Yo3hsAC3/ylb1Q4rqh+hD/ytxwv6TQvyXLvqq8Q+hD8Xlw77 FdFU41Oyidg/2wBkf8sEFgnB/9pHxpcrJU8= X-Google-Smtp-Source: ABdhPJxSbi/so9LC9Hx2K/NJBPQpWfhio3DksqcrkFYd3YFZSePPAWPP+AQatb0XaXyze7GjIuJH4VCknBdbDlE= X-Received: by 2002:a25:73c2:: with SMTP id o185mr10556755ybc.169.1594953891393; Thu, 16 Jul 2020 19:44:51 -0700 (PDT) Date: Thu, 16 Jul 2020 19:44:47 -0700 Message-Id: <20200717024447.3128361-1-saravanak@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH v2] irqchip: Add IRQCHIP_PLATFORM_DRIVER_BEGIN/END and IRQCHIP_MATCH helper macros From: Saravana Kannan To: Thomas Gleixner , Jason Cooper , Marc Zyngier , Matthias Brugger X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200716_224455_871925_509C5D99 X-CRM114-Status: GOOD ( 16.96 ) X-Spam-Score: -7.7 (-------) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-7.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:b4a listed in] [list.dnswl.org] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_MED DKIMwl.org - Medium sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: CC Hwang , Saravana Kannan , Hanks Chen , Loda Chou , linux-kernel@vger.kernel.org, John Stultz , linux-mediatek@lists.infradead.org, kernel-team@android.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Compiling an irqchip driver as a platform driver needs to bunch of things to be done right: - Making sure the parent domain is initialized first - Making sure the device can't be unbound from sysfs - Disallowing module unload if it's built as a module - Finding the parent node - Etc. Instead of trying to make sure all future irqchip platform drivers get this right, provide boilerplate macros that take care of all of this. An example use would look something like this. Where acme_foo_init and acme_bar_init are similar to what would be passed to IRQCHIP_DECLARE. IRQCHIP_PLATFORM_DRIVER_BEGIN IRQCHIP_MATCH(foo, "acme,foo", acme_foo_init) IRQCHIP_MATCH(bar, "acme,bar", acme_bar_init) IRQCHIP_PLATFORM_DRIVER_END(acme_irq) Signed-off-by: Saravana Kannan --- drivers/irqchip/irqchip.c | 22 ++++++++++++++++++++++ include/linux/irqchip.h | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/irqchip/irqchip.c b/drivers/irqchip/irqchip.c index 2b35e68bea82..236ea793f01c 100644 --- a/drivers/irqchip/irqchip.c +++ b/drivers/irqchip/irqchip.c @@ -10,8 +10,10 @@ #include #include +#include #include #include +#include /* * This special of_device_id is the sentinel at the end of the @@ -29,3 +31,23 @@ void __init irqchip_init(void) of_irq_init(__irqchip_of_table); acpi_probe_device_table(irqchip); } + +int platform_irqchip_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct device_node *par_np = of_irq_find_parent(np); + of_irq_init_cb_t irq_init_cb = of_device_get_match_data(&pdev->dev); + + if (!irq_init_cb) + return -EINVAL; + + if (par_np == np) + par_np = NULL; + + /* If there's a parent irqchip, make sure it has been initialized. */ + if (par_np && !irq_find_matching_host(np, DOMAIN_BUS_ANY)) + return -EPROBE_DEFER; + + return irq_init_cb(np, par_np); +} +EXPORT_SYMBOL_GPL(platform_irqchip_probe); diff --git a/include/linux/irqchip.h b/include/linux/irqchip.h index 950e4b2458f0..6d5eba7cbbb7 100644 --- a/include/linux/irqchip.h +++ b/include/linux/irqchip.h @@ -13,6 +13,7 @@ #include #include +#include /* * This macro must be used by the different irqchip drivers to declare @@ -26,6 +27,28 @@ */ #define IRQCHIP_DECLARE(name, compat, fn) OF_DECLARE_2(irqchip, name, compat, fn) +extern int platform_irqchip_probe(struct platform_device *pdev); + +#define IRQCHIP_PLATFORM_DRIVER_BEGIN \ +static const struct of_device_id __irqchip_match_table[] = { + +#define IRQCHIP_MATCH(compat, fn) { .compatible = compat, .data = fn }, + +#define IRQCHIP_PLATFORM_DRIVER_END(drv_name) \ + {}, \ +}; \ +MODULE_DEVICE_TABLE(of, __irqchip_match_table); \ +static struct platform_driver drv_name##_driver = { \ + .probe = platform_irqchip_probe, \ + .driver = { \ + .name = #drv_name, \ + .owner = THIS_MODULE, \ + .of_match_table = __irqchip_match_table,\ + .suppress_bind_attrs = true, \ + }, \ +}; \ +builtin_platform_driver(drv_name##_driver) + /* * This macro must be used by the different irqchip drivers to declare * the association between their version and their initialization function.