Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1813419lqp; Sat, 23 Mar 2024 09:44:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUaIrHdWNGlRIlCngCb+eDbWaV5E3Y9F9y4EMBk/JYhT15uJ7vpL+59xdn1UwAOMQ/OQpJoAugAVYaV7i2/gIVLUKO2+A5rD+6ovw3tjQ== X-Google-Smtp-Source: AGHT+IEaVXi1/OTUhDXQjjuqnHMVf0TYchn/4J7HzdrdVWgXx73A6hBzz2GEVlkyik53hMkCI63/ X-Received: by 2002:a50:9e44:0:b0:567:e0e:dda5 with SMTP id z62-20020a509e44000000b005670e0edda5mr1886277ede.17.1711212267335; Sat, 23 Mar 2024 09:44:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711212267; cv=pass; d=google.com; s=arc-20160816; b=mNaxOdkpnh+2KAhUOJBTxnQQ60y1MHnYLCEj8kRVAYzJ/O/uH0fkpVFWOOk2ahsk3G gO4o61+1Vu1GHkb6Xj8bIUd/B5r8kNFVnxBX0QQIw4tp0oepwsrYV3oV980RELJNkBqy +zQ4soTAdCsvZiyL/eU8qVbbNKX7u7oV3GtU7Uw0fMwbQPiku3QDQP/78SquFZN+MQC8 WUU/1q/hHEu+gwAsZUApK0lquCWCixVtK09vQRmhmf12z8LELjIzMIz3O/hCTISdLr/C I+9UPTSZJIL3pUfzxksco76KJs+8gzOZvFu+zGziW4DFkA+m/MDBKKxqMXi3gIeIkhgO RCGQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=A8HOuL6a/QjQfRz3qqDq96gQTLQaATmwQBW8afNgiYc=; fh=E3lYNGf/iVy5iQbn2+p4+VtT1bF9RF5lHarPbuXPeUw=; b=U0tnNz7ScgP7ErSAm/8gtmklF4243oHqYvUlSizYrtmXalmqUf1zPOWV5e2kej5Jr8 eUZr8PnqzL4JbHBPAODTQg3cTyDhK9NdDYOFOKj8tuhq2UpE2u/RE1JDorXZ9jGtXMwy BKHjVVvjwqXeKCWpghxgn3pG/Fk6VvWxVXEz9zsASjgYsCffol+d/sVNeLDMQWhWPXSn 66E5x/X2qSOK5pPAt8k33vondnrt1Nd4M1tbGP0ZoxJv3hqYv/3OzRuAHcsKAzh2j+Ma VQL5I9ADSfmLJgcgrnWK+OhCZVKli1S9Cx1p1AfoBFhhgYdX8eCw4xY3GrPCn8Sctbp7 yThg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=YL0U+Pdw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-2834-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2834-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id en12-20020a056402528c00b005688b2cb9b3si948573edb.331.2024.03.23.09.44.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 09:44:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-2834-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=YL0U+Pdw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-2834-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2834-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EF97A1F219A3 for ; Sat, 23 Mar 2024 16:44:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33C2B47A5D; Sat, 23 Mar 2024 16:44:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YL0U+Pdw" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6DA047A58 for ; Sat, 23 Mar 2024 16:44:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711212262; cv=none; b=rkeCHP5lIrzkL0equmzt2c5h7rG91dgoZ42aZKQfEpHdLw69nQvCmBrjdYl7mgzBmtak+OfDxaWrwa8tLrI6d1F7cGd5af1f9drq7yO7VihIONrDtd9SabzW8TYZs5o322F4srkJCQ1/QUJpDURBxlZetGdRXfE+jXbSQL3i+/o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711212262; c=relaxed/simple; bh=SsQrRejK0w4EjROLcLU+YTlqAB1NnSbndHoHZRoGtMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jIh9JzNtyATnjOAiUulBcB4qEs2rwo8sG/a8j/t2XwVFjYvbh80tXMZfb1xnav+Vw67YscZ+yStPxTTQV4nfSRKCEqeSoN09SaGm1Jat6a/cvk5HVJ2Hl9io+7R8pV48Uoc5aNGlnK4ewivOxV2qIGCj2S29B1t7cEJ9MKWxic8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YL0U+Pdw; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36624C433C7; Sat, 23 Mar 2024 16:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711212261; bh=SsQrRejK0w4EjROLcLU+YTlqAB1NnSbndHoHZRoGtMc=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=YL0U+Pdw87dwIB0KF6tRoqyubTzRQdW+PdSzoW1DCs9GTGT9iUDT1YPW+qtL8vNEi lCZ/j3K35rVTdbWZoUytLdLG8YeH3Bq3DpIDgPjlIe2e2/c9e6V94e6sO/LvZEJagu xsIpIMB8aDfV3QgV048vR9Ux/6ZSuJesx38TsuZxhKXacuNKtgSEtF309mmmE9pXtd 93/P69j07gxh36J/YAtL+ZkOIfxPrjR9VmNrHOfhHW9RGHqOk3oAyLXPtDA4HBsQBm JuMUSbzFNyapVB4T7B/Pay2tUan7Un8GD0Du+/3DNIkTfT2SEWmpSC3hMNCsXaLmEU Qm5/OmoGC7/0w== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Arnd Bergmann , Gregory CLEMENT , soc@kernel.org, arm@kernel.org, Hans de Goede , Matti Vaittinen , =?UTF-8?q?Horia=20Geant=C4=83?= , Pankaj Gupta , Gaurav Jain , linux-crypto@vger.kernel.org, Herbert Xu Cc: =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH v5 06/11] devm-helpers: Add resource managed version of irq_create_mapping() Date: Sat, 23 Mar 2024 17:43:54 +0100 Message-ID: <20240323164359.21642-7-kabel@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240323164359.21642-1-kabel@kernel.org> References: <20240323164359.21642-1-kabel@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add resource managed version of irq_create_mapping(), to help drivers automatically dispose a linux irq mapping when driver is detached. The new function devm_irq_create_mapping() is not yet used, but the action function can be used in the FSL CAAM driver. Signed-off-by: Marek BehĂșn --- drivers/crypto/caam/jr.c | 8 ++---- include/linux/devm-helpers.h | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index 26eba7de3fb0..ad0295b055f8 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -7,6 +7,7 @@ * Copyright 2019, 2023 NXP */ +#include #include #include #include @@ -576,11 +577,6 @@ static int caam_jr_init(struct device *dev) return error; } -static void caam_jr_irq_dispose_mapping(void *data) -{ - irq_dispose_mapping((unsigned long)data); -} - /* * Probe routine for each detected JobR subsystem. */ @@ -656,7 +652,7 @@ static int caam_jr_probe(struct platform_device *pdev) return -EINVAL; } - error = devm_add_action_or_reset(jrdev, caam_jr_irq_dispose_mapping, + error = devm_add_action_or_reset(jrdev, devm_irq_mapping_drop, (void *)(unsigned long)jrpriv->irq); if (error) return error; diff --git a/include/linux/devm-helpers.h b/include/linux/devm-helpers.h index 74891802200d..3805551fd433 100644 --- a/include/linux/devm-helpers.h +++ b/include/linux/devm-helpers.h @@ -24,6 +24,8 @@ */ #include +#include +#include #include static inline void devm_delayed_work_drop(void *res) @@ -76,4 +78,56 @@ static inline int devm_work_autocancel(struct device *dev, return devm_add_action(dev, devm_work_drop, w); } +/** + * devm_irq_mapping_drop - devm action for disposing an irq mapping + * @res: linux irq number cast to the void * type + * + * devm_irq_mapping_drop() can be used as an action parameter for the + * devm_add_action_or_reset() function in order to automatically dispose + * a linux irq mapping when a device driver is detached. + */ +static inline void devm_irq_mapping_drop(void *res) +{ + irq_dispose_mapping((unsigned int)(unsigned long)res); +} + +/** + * devm_irq_create_mapping - Resource managed version of irq_create_mapping() + * @dev: Device which lifetime the mapping is bound to + * @domain: domain owning this hardware interrupt or NULL for default domain + * @hwirq: hardware irq number in that domain space + * + * Create an irq mapping to linux irq space which is automatically disposed when + * the driver is detached. + * devm_irq_create_mapping() can be used to omit the explicit + * irq_dispose_mapping() call when driver is detached. + * + * Returns a linux irq number on success, 0 if mapping could not be created, or + * a negative error number if devm action could not be added. + */ +static inline int devm_irq_create_mapping(struct device *dev, + struct irq_domain *domain, + irq_hw_number_t hwirq) +{ + unsigned int virq = irq_create_mapping(domain, hwirq); + + if (!virq) + return 0; + + /* + * irq_dispose_mapping() is an empty function if CONFIG_IRQ_DOMAIN is + * disabled. No need to register an action in that case. + */ + if (IS_ENABLED(CONFIG_IRQ_DOMAIN)) { + int err; + + err = devm_add_action_or_reset(dev, devm_irq_mapping_drop, + (void *)(unsigned long)virq); + if (err) + return err; + } + + return virq; +} + #endif -- 2.43.2