From patchwork Thu Jul 11 16:09:06 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: 13730846 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 896F0C3DA45 for ; Thu, 11 Jul 2024 16:12:05 +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=wQhdapamluBAfc8XGnRa3MW4EtqflamJ15me40OhWOo=; b=T9ex5qURUpTxqNF1RH5cbtLatS cT5Y12wrENRxVcaR+LL/+otCOmdSTCBTy0lDT5gZoFP1fOswcM4m6uwd63V9GgSaCp6BWtSZbpkP2 OQhhr6cgH9WuDxd2iGopPq9hgfL7km+0k/2VP3JwPeoZ0MvWi6Kozm6eGZi7F7f9LcUIDd7ZiWZVX 9XEzZfQBQzuE3v+wmjyMiD1Nzdc0iPhGwqSNFefLGJ8ZMLid/nCGqwxMwHL5r7RvHTidifm6lmCmH 9SWRDUrEA5eBj3pKca3UccIySExeh2H09TkWDHQidVUyiAOYe2zHI3A8dpTqyhoey0U4mGB8/exlg poPnugsw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRwOg-0000000EdjC-0dcE; Thu, 11 Jul 2024 16:11:54 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRwMS-0000000EcmW-3PTf for linux-arm-kernel@lists.infradead.org; Thu, 11 Jul 2024 16:09:38 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5231D61D61; Thu, 11 Jul 2024 16:09:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF03DC4AF07; Thu, 11 Jul 2024 16:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720714176; bh=csVsCA8RqdrodTpKAa/5SnRiGJhJusByv19pah2IBYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b+hAy3UtSa9zUr2w3XXR58383a7qe3EunqE7I61rHQaO1jBgOKWpUyApF9cFllQcc cFyrTOKkCIEsB9u5fChgZhxOPwV15q41w/mN/UJE9TNmOTx8imhbfN3GBlV9TnIp2q ibHaGp57UYTAlM4RHfO10bUrtoF9vMgFsYNTFTkKenL/kJcC6nXiFUGFJ8f+Uxjchm zfuPKYj8G56qpi6LMIqTICBJHJngKz8Ibr/mA/beUqwFMnvp47g2UWThKy58y3gSiX rYi422bjF71i05HmgBZV2O1C+W7+9Oh5pXCB42bWwvvLHUqSixtuQFTrudtripWC0T CatgMNXfmF/6A== 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 09/10] irqchip/armada-370-xp: Refactor initial memory regions mapping Date: Thu, 11 Jul 2024 18:09:06 +0200 Message-ID: <20240711160907.31012-10-kabel@kernel.org> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240711160907.31012-1-kabel@kernel.org> References: <20240711160907.31012-1-kabel@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240711_090936_960807_57FEB23B X-CRM114-Status: GOOD ( 16.48 ) 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..dccc69aa2bf4 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 __init 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);