From patchwork Tue Jul 2 11:43:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 13719507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EFEE1C30658 for ; Tue, 2 Jul 2024 11:48:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qHEM8B4hpxEP2CJTY1a6yL1M7UMHYq+Z/UHriApeLB8=; b=05fZRjBZd/9b27x91yProT+K7V GHS5E5YIDMYNN17D2Y6fE4fNZDRiTev3UhygwK4NhHlOC9SOk67tD6HK2wDKAyHPKThdiF7GdelYQ /esEAvNVe7WqVMEWYGo9S/rnagdgbvWUviWeO9JnzLmWKnwKh4iqoSUPOjPJ3I3+9/IVQiAfnFhE+ sdMUTYHh1KiTgaH2VBaGo/aWukmtRRNpP6WRgWok+DBr+sA79aGdrd9SJ70xozUr4iaCS+FDWsaBa SmrJRGb8eHpSRTfNxjPNbVI9qv4p1VFsVOlj4Pg6LqC4ZaFiRZj0C0rukPzANCdFkSrqeZjVRvsPE Xyoetezg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sObzR-00000006YUP-0FRR; Tue, 02 Jul 2024 11:48:05 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sObvt-00000006WeY-3g5K for linux-arm-kernel@lists.infradead.org; Tue, 02 Jul 2024 11:44:27 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 48643CE1DCD; Tue, 2 Jul 2024 11:44:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CE33C4AF0E; Tue, 2 Jul 2024 11:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719920663; bh=g5owrnGltphsZPgN/WHaz4iqhikoGfDg0TC6c4BJBuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BCBoTs8E51L+XejrlYo7tPDMnqyikSXHApA1iKJ8eOnxDOXPX66bVDTXazwqkR8vT +WP/5rY5snQ8taK5/1UOzol00zR6C6Zd7fmS5et+shQmI3SRIXXyAp8I1J+5Ym6+TT idTJUFc8pr5XrZTqb8OjoCxJQZwic0ZDbhubPZ/h2Jps7X3qaD8Xf2nU2B+a+fIKig Fl0dShap8P7hOJ4GE3n8LYBArEIXFgjghfnLcLfgmZzbONEs83ouMFbgRNbDWiXWU8 XqhSLaxbps9+3Xbp8KAYa9YwafW8wzqUT6nCr1naR7DCVVMmD6I81nH5JpmOFP6+vN VV56crGXkDt7Q== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, arm@kernel.org, Andy Shevchenko , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH v2 29/30] irqchip/armada-370-xp: Refactor initial memory regions mapping Date: Tue, 2 Jul 2024 13:43:01 +0200 Message-ID: <20240702114302.22475-30-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240702114302.22475-1-kabel@kernel.org> References: <20240702114302.22475-1-kabel@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240702_044426_320125_F3EC4EAF X-CRM114-Status: GOOD ( 17.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Refactor the initial memory regions mapping: - put into its own function - return error numbers on failure - use WARN_ON() instead of BUG_ON() Signed-off-by: Marek BehĂșn --- drivers/irqchip/irq-armada-370-xp.c | 62 ++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/drivers/irqchip/irq-armada-370-xp.c b/drivers/irqchip/irq-armada-370-xp.c index 2c8272fe7150..d9154f75d7f3 100644 --- a/drivers/irqchip/irq-armada-370-xp.c +++ b/drivers/irqchip/irq-armada-370-xp.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -766,29 +767,54 @@ static struct syscore_ops mpic_syscore_ops = { .resume = mpic_resume, }; +static int mpic_map_region(struct device_node *np, int index, + void __iomem **base, phys_addr_t *phys_base) +{ + struct resource res; + int err; + + err = of_address_to_resource(np, index, &res); + if (WARN_ON(err)) + goto fail; + + if (WARN_ON(!request_mem_region(res.start, resource_size(&res), + np->full_name))) { + err = -EBUSY; + goto fail; + } + + *base = ioremap(res.start, resource_size(&res)); + if (WARN_ON(!*base)) { + err = -ENOMEM; + goto fail; + } + + if (phys_base) + *phys_base = res.start; + + return 0; + +fail: + pr_err("%pOF: Unable to map resource %d: %pE\n", np, index, + ERR_PTR(err)); + + return err; +} + static int __init mpic_of_init(struct device_node *node, struct device_node *parent) { - struct resource main_int_res, per_cpu_int_res; + phys_addr_t phys_base; unsigned int nr_irqs; + int err; - BUG_ON(of_address_to_resource(node, 0, &main_int_res)); - BUG_ON(of_address_to_resource(node, 1, &per_cpu_int_res)); - - BUG_ON(!request_mem_region(main_int_res.start, - resource_size(&main_int_res), - node->full_name)); - BUG_ON(!request_mem_region(per_cpu_int_res.start, - resource_size(&per_cpu_int_res), - node->full_name)); - - main_int_base = ioremap(main_int_res.start, - resource_size(&main_int_res)); - BUG_ON(!main_int_base); + err = mpic_map_region(node, 0, &main_int_base, &phys_base); + if (err) + return err; - per_cpu_int_base = ioremap(per_cpu_int_res.start, - resource_size(&per_cpu_int_res)); - BUG_ON(!per_cpu_int_base); + err = mpic_map_region(node, 1, &per_cpu_int_base, NULL); + if (err) + return err; nr_irqs = FIELD_GET(MPIC_INT_CONTROL_NUMINT_MASK, readl(main_int_base + MPIC_INT_CONTROL)); @@ -810,7 +836,7 @@ static int __init mpic_of_init(struct device_node *node, mpic_perf_init(); mpic_smp_cpu_init(); - mpic_msi_init(node, main_int_res.start); + mpic_msi_init(node, phys_base); if (parent_irq <= 0) { irq_set_default_host(mpic_domain);