From patchwork Fri Dec 9 14:01:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 31755 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp794505wrr; Fri, 9 Dec 2022 06:06:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf5HEz12ImGxaLVq8d+SGxTG9JU6aFZ3jTiIH5GDQmydyPquxITzBHui3uVypZqKcAT9oY/n X-Received: by 2002:a05:6a20:c18d:b0:9d:efbe:a11b with SMTP id bg13-20020a056a20c18d00b0009defbea11bmr7643665pzb.43.1670594797540; Fri, 09 Dec 2022 06:06:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670594797; cv=none; d=google.com; s=arc-20160816; b=hwzdHc5FiAV5x3QyVmpcrNHnTiT1Fry1FCihz5MpfRQ3dOavbuQYpGDCBoR423ppqu jt+MwPVjSQSdaAr4dKMfX3/U7j6pbbL3EPsHpLvMBvYJTv0/4JhSgKuz+2JmnJL9b37b 3LzumJqCG4m20TADAxuClUgtmtTVDw6ml7PJL53JLlhSuq8NELP2VPtvqxX1NgEN3WvR 7p3OdX31+PfrAre0D989/2/T13WM3a1unbI6lHgRHguxSzyDZlZbRMoURPsae0wW0dZ3 2VppJP+HkP5jaXMVUFm/JvnUv2oQQF+Al1wDFppazMg4JvlK0O06b0u7mTFmEGD5b9n5 82Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DtZzKYhE9ZSYQsC3O9iDREX3KPksRZt95W4w53P55Zk=; b=jUy/yeA0w7wBHmT0xFXZATnfvHkHT/OZkWltWiB1JjvpcThAoWHIzc0gOMkgAS68YC BNUmWTpucgX4fVQz0SROPuTwEim7m8JGPxcxhWA6o/nZuxCd4DdLx7W7oVvf06z148IM hwm0fvneY90SMiK+9B6SDVM+XtINxT+A3z2aSd93mwWs2pBE75vwSacucnqlnyHABfOS Hk2aPF2lrcWlb7BL2YINJrfullT2eTySjt93rVcr2MrF6KFS1siCzN22kqw2AI3tmO+s Yfr/m5J22TqY7KDlo9BpA14HoVpEFK1AI9VeFq5LDPBMMWmIJ1f53Awfk9YsVGLlCP+F G09g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lesnMst8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w70-20020a628249000000b0056e0ac0f382si1861462pfd.233.2022.12.09.06.06.16; Fri, 09 Dec 2022 06:06:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lesnMst8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230044AbiLIOFb (ORCPT + 99 others); Fri, 9 Dec 2022 09:05:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbiLIOFR (ORCPT ); Fri, 9 Dec 2022 09:05:17 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 210387682B; Fri, 9 Dec 2022 06:05:15 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AFD346226F; Fri, 9 Dec 2022 14:05:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84661C433AC; Fri, 9 Dec 2022 14:05:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670594713; bh=1UsTmUxkh2RO4JtVXWdoi0GSvnFbd1ZBNIWS//6pOwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lesnMst8ZMnQFRl6LMW0T4LFSGmVlDGTS8EafxqYjlGQsJC81FBUeJt8WMsuJ/TDz r+PPCTtfBNWzTB76qamYg8zRlBxoDn9bsJBFIGPAPFH5f2qLUSRFh7kAtaDtV1GDG0 I4WhkZGYz1CsaMtfC5SLmZczWBFUpSZwSMAtwpcbR/t3PwfJFmEQlpdNpniL7KID4q PBpQi8zys3EBMtQ6wc+5PCp2ZMy++T49fhpcgZ0VufYyx5xmKB0uvGN9h0lmXYy+Dn GlTZEe23TEc+tqeqb7YzcTjZJMROSQ7XmL/VwUuZfzmeDwyIvO4u/egCcM1fTWeqvd kC+qduj1gftsA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1p3e0I-0000Rg-Nl; Fri, 09 Dec 2022 15:05:30 +0100 From: Johan Hovold To: Marc Zyngier Cc: Thomas Gleixner , x86@kernel.org, platform-driver-x86@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH v3 07/19] irqdomain: Look for existing mapping only once Date: Fri, 9 Dec 2022 15:01:38 +0100 Message-Id: <20221209140150.1453-8-johan+linaro@kernel.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221209140150.1453-1-johan+linaro@kernel.org> References: <20221209140150.1453-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751745610009939631?= X-GMAIL-MSGID: =?utf-8?q?1751745610009939631?= Avoid looking for an existing mapping twice when creating a new mapping using irq_create_fwspec_mapping() by factoring out the actual allocation which is shared with irq_create_mapping_affinity(). Signed-off-by: Johan Hovold --- kernel/irq/irqdomain.c | 60 +++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index 248e6acfafbe..894bc6ee6348 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -675,6 +675,34 @@ unsigned int irq_create_direct_mapping(struct irq_domain *domain) EXPORT_SYMBOL_GPL(irq_create_direct_mapping); #endif +static unsigned int __irq_create_mapping_affinity(struct irq_domain *domain, + irq_hw_number_t hwirq, + const struct irq_affinity_desc *affinity) +{ + struct device_node *of_node = irq_domain_get_of_node(domain); + int virq; + + pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq); + + /* Allocate a virtual interrupt number */ + virq = irq_domain_alloc_descs(-1, 1, hwirq, of_node_to_nid(of_node), + affinity); + if (virq <= 0) { + pr_debug("-> virq allocation failed\n"); + return 0; + } + + if (irq_domain_associate(domain, virq, hwirq)) { + irq_free_desc(virq); + return 0; + } + + pr_debug("irq %lu on domain %s mapped to virtual irq %u\n", + hwirq, of_node_full_name(of_node), virq); + + return virq; +} + /** * irq_create_mapping_affinity() - Map a hardware interrupt into linux irq space * @domain: domain owning this hardware interrupt or NULL for default domain @@ -687,14 +715,11 @@ EXPORT_SYMBOL_GPL(irq_create_direct_mapping); * on the number returned from that call. */ unsigned int irq_create_mapping_affinity(struct irq_domain *domain, - irq_hw_number_t hwirq, - const struct irq_affinity_desc *affinity) + irq_hw_number_t hwirq, + const struct irq_affinity_desc *affinity) { - struct device_node *of_node; int virq; - pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq); - /* Look for default domain if necessary */ if (domain == NULL) domain = irq_default_domain; @@ -702,34 +727,15 @@ unsigned int irq_create_mapping_affinity(struct irq_domain *domain, WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq); return 0; } - pr_debug("-> using domain @%p\n", domain); - - of_node = irq_domain_get_of_node(domain); /* Check if mapping already exists */ virq = irq_find_mapping(domain, hwirq); if (virq) { - pr_debug("-> existing mapping on virq %d\n", virq); + pr_debug("existing mapping on virq %d\n", virq); return virq; } - /* Allocate a virtual interrupt number */ - virq = irq_domain_alloc_descs(-1, 1, hwirq, of_node_to_nid(of_node), - affinity); - if (virq <= 0) { - pr_debug("-> virq allocation failed\n"); - return 0; - } - - if (irq_domain_associate(domain, virq, hwirq)) { - irq_free_desc(virq); - return 0; - } - - pr_debug("irq %lu on domain %s mapped to virtual irq %u\n", - hwirq, of_node_full_name(of_node), virq); - - return virq; + return __irq_create_mapping_affinity(domain, hwirq, affinity); } EXPORT_SYMBOL_GPL(irq_create_mapping_affinity); @@ -834,7 +840,7 @@ unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec) return 0; } else { /* Create mapping */ - virq = irq_create_mapping(domain, hwirq); + virq = __irq_create_mapping_affinity(domain, hwirq, NULL); if (!virq) return virq; }