From mboxrd@z Thu Jan 1 00:00:00 1970 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 9A592C677C4 for ; Wed, 11 Jun 2025 07:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=580U2GsZmR+8YQkVplK9xzNMPEU808Vreh9sED/3tEs=; b=spMzG88zzteScu BVrTON8JG2/T+lkG41bEkrQcZxrMM04WRhuq95kdk6DznPm7Swc0FVp95wM+5OYbKnT3WH9s2hH8K mv9GYPjO4Lwjmz+Zhz++ay/CEw04ig4PsnmC5MNjhs1H3YPliFw7HEXZgFlLm00jgswyvxgLGyZVj XOdTKfH7mWSXUOE5VC6ZCzZyww4fYcL2eG7oOhJ9cUFkJmbQxr1hcFiDbLDeE8zVnD1EL7A/tmH/o JQ6g1QvCKaVFKu6el5YDKUgFenbJ5PmLGXFLk8HPfFUKE09zaFDBXPEm0AomGXKn7SAvgAGLI50Rk IGC2rdQ+eLVsJlioim1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uPFoj-000000095cc-1E2X; Wed, 11 Jun 2025 07:24:13 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uPEs5-00000008z6c-3RAL for linux-riscv@lists.infradead.org; Wed, 11 Jun 2025 06:23:38 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2350fc2591dso5360285ad.1 for ; Tue, 10 Jun 2025 23:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1749623017; x=1750227817; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Oq58nUDRWeIOl1x38zmkh2+ZPHCgo0OptvyvyNxudhg=; b=dDNrT0vdnN395+PaObrxBPsEc4gzC0wQSz1oDEzfvvnG8qv+sTRrW7AYECLqNsLa1q qfugxElju4i5thBj5JkzbIie3tkBf3N1Ut4WKjYI1q0iQw7ZQZ8cyDHatmM3wFBUbqz4 mvozt8UgC6wD8b+TOoofuxO/sjHQb7GhbEHULYb3JThyVs7UWV/GoyyvzDHb+PLZ7eyJ 7i0u8R7J/DrMzfjJjN8t0yJHQO7cXeCYEwhR0XJM3YIGuWH7bTo4vC+BY3/JqydRuQrA PQzA8/wKBKwMFHMGb4c2/YlrusThIKA8DZ1/WfAS/G/PGNnHvTR2MiUVW0dpeXEqgPyA W32A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749623017; x=1750227817; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Oq58nUDRWeIOl1x38zmkh2+ZPHCgo0OptvyvyNxudhg=; b=Hksqn73Sk/BObhX2t1deFyfJGCNAM9DMlm0Z9vP67YaEYjYRWlVjbhjS2VN7WwhBWj MjuHVXQhp2ebi2xSQn/UBYiJP77vbw1jbXrwUCkXB9WM8NMYamGEM5z3foyGqHZtoTCN soY6WV824lohtc3jnB5InTamg+n9VfHgcvtdwCMbjSvM38dwotMqmC3J9wxC4FjCmS08 kZ/kSEwkiJvASdfHd2QnqCE2UemIDPAHHlFtdTw1WDC1zDO6kLjwASofud9cTxqAITn7 YIC994uIbc8lGqckAhKw5ZbUOfWdL4jv+tR7fCS/RpXg8dCtswyaTUGzCf2g9I41eqwI yTAg== X-Forwarded-Encrypted: i=1; AJvYcCXBjb10S34idvKgSgLuBAWukYXanopRsIv77nB+WFIlTPHzVIcdLszKLUzpnn0lPR7D/R6EqnejT2E5uw==@lists.infradead.org X-Gm-Message-State: AOJu0YwHr48at4C5hq2yERbWR9luvLLvhtd6Cu6X7idXENx4/n7f0Hvc K71Fkvhs7J0jjHUjO4u6/AGCMrkfATc7J5IjV8qWiA4vvPLsCmCV2aT4cwGCBNKbqct7z0I2dzk gYTXt0h4= X-Gm-Gg: ASbGncuMU+v2wghMY/WRZtOCc+1SM1kCBmz/Snvu+jwTvLy2e2rTjmGgbX0pisd8I/s OK3dImdLrAF1Z/sfgPZmfDhV9cbRlFp7Q3LrEekuBKALRfOlmrxZKyW4JYTyZph2qh1ELm1oLvt XQPgMT/Jm/jkr46+oCvq4Fc7Bt9KUi0StVesGDgYinDgPOqV7dPt67krpZdlX73K3wVeaA9j5Y6 rVW162rK5wRJqxobPC61jaXCxjQ+BBActYXhE2jWit2G41fggZgWpQQpvA7SKRta2Y68F9DTeA1 4NU9ajPIvc6keIpjZlXqaKYj015MlB+1jCdcJZ047eNwyIiLb/xsKrNjlFJwwEF9+G9dVWcSzxP UFhtzcaDazAFSflF00ZysKod47xp2PdvtFs1Z X-Google-Smtp-Source: AGHT+IHtGB2PUpXqZ9bfGLD+kJcw/Vmqw/rX+F5NwlfdOTouRiwUdlxzNr+s19qiVuX1b57i0EotKQ== X-Received: by 2002:a17:903:3203:b0:21f:5063:d3ca with SMTP id d9443c01a7336-236418343e6mr33134145ad.16.1749623016901; Tue, 10 Jun 2025 23:23:36 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23603092677sm79976295ad.64.2025.06.10.23.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 23:23:36 -0700 (PDT) From: Anup Patel To: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jassi Brar , Thomas Gleixner , "Rafael J . Wysocki" , Mika Westerberg , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Subject: [PATCH v5 05/23] mailbox: Allow controller specific mapping using fwnode Date: Wed, 11 Jun 2025 11:52:20 +0530 Message-ID: <20250611062238.636753-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250611062238.636753-1-apatel@ventanamicro.com> References: <20250611062238.636753-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250610_232337_861314_8BFFD935 X-CRM114-Status: GOOD ( 21.07 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , devicetree@vger.kernel.org, Andrew Jones , Atish Patra , Leyfoon Tan , Anup Patel , linux-kernel@vger.kernel.org, Samuel Holland , Palmer Dabbelt , Paul Walmsley , linux-riscv@lists.infradead.org, Len Brown , linux-clk@vger.kernel.org, Rahul Pathak Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Introduce optional fw_node() callback which allows a mailbox controller driver to provide controller specific mapping using fwnode. The Linux OF framework already implements fwnode operations for the Linux DD framework so the fw_xlate() callback works fine with device tree as well. Signed-off-by: Anup Patel --- drivers/mailbox/mailbox.c | 45 +++++++++++++++++------------- include/linux/mailbox_controller.h | 3 ++ 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 5cd8ae222073..d1840eace725 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "mailbox.h" @@ -383,34 +384,46 @@ EXPORT_SYMBOL_GPL(mbox_bind_client); */ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) { + struct fwnode_reference_args fwspec; struct device *dev = cl->dev; struct mbox_controller *mbox; struct of_phandle_args spec; struct mbox_chan *chan; + unsigned int i; int ret; - if (!dev || !dev->of_node) { - pr_debug("%s: No owner device node\n", __func__); + if (!dev || !dev_fwnode(dev)) { + pr_debug("No owner %s\n", dev ? "fwnode" : "device"); return ERR_PTR(-ENODEV); } - ret = of_parse_phandle_with_args(dev->of_node, "mboxes", "#mbox-cells", - index, &spec); + ret = fwnode_property_get_reference_args(dev_fwnode(dev), "mboxes", + "#mbox-cells", 0, index, &fwspec); if (ret) { dev_err(dev, "%s: can't parse \"mboxes\" property\n", __func__); return ERR_PTR(ret); } + spec.np = to_of_node(fwspec.fwnode); + spec.args_count = fwspec.nargs; + for (i = 0; i < spec.args_count; i++) + spec.args[i] = fwspec.args[i]; + scoped_guard(mutex, &con_mutex) { chan = ERR_PTR(-EPROBE_DEFER); - list_for_each_entry(mbox, &mbox_cons, node) - if (mbox->dev->of_node == spec.np) { + list_for_each_entry(mbox, &mbox_cons, node) { + if (mbox->fw_xlate && dev_fwnode(mbox->dev) == fwspec.fwnode) { + chan = mbox->fw_xlate(mbox, &fwspec); + if (!IS_ERR(chan)) + break; + } else if (mbox->of_xlate && mbox->dev->of_node == spec.np) { chan = mbox->of_xlate(mbox, &spec); if (!IS_ERR(chan)) break; } + } - of_node_put(spec.np); + fwnode_handle_put(fwspec.fwnode); if (IS_ERR(chan)) return chan; @@ -427,15 +440,8 @@ EXPORT_SYMBOL_GPL(mbox_request_channel); struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, const char *name) { - struct device_node *np = cl->dev->of_node; - int index; - - if (!np) { - dev_err(cl->dev, "%s() currently only supports DT\n", __func__); - return ERR_PTR(-EINVAL); - } + int index = device_property_match_string(cl->dev, "mbox-names", name); - index = of_property_match_string(np, "mbox-names", name); if (index < 0) { dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n", __func__, name); @@ -470,9 +476,8 @@ void mbox_free_channel(struct mbox_chan *chan) } EXPORT_SYMBOL_GPL(mbox_free_channel); -static struct mbox_chan * -of_mbox_index_xlate(struct mbox_controller *mbox, - const struct of_phandle_args *sp) +static struct mbox_chan *fw_mbox_index_xlate(struct mbox_controller *mbox, + const struct fwnode_reference_args *sp) { int ind = sp->args[0]; @@ -523,8 +528,8 @@ int mbox_controller_register(struct mbox_controller *mbox) spin_lock_init(&chan->lock); } - if (!mbox->of_xlate) - mbox->of_xlate = of_mbox_index_xlate; + if (!mbox->fw_xlate && !mbox->of_xlate) + mbox->fw_xlate = fw_mbox_index_xlate; scoped_guard(mutex, &con_mutex) list_add_tail(&mbox->node, &mbox_cons); diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h index ad01c4082358..80a427c7ca29 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -66,6 +66,7 @@ struct mbox_chan_ops { * no interrupt rises. Ignored if 'txdone_irq' is set. * @txpoll_period: If 'txdone_poll' is in effect, the API polls for * last TX's status after these many millisecs + * @fw_xlate: Controller driver specific mapping of channel via fwnode * @of_xlate: Controller driver specific mapping of channel via DT * @poll_hrt: API private. hrtimer used to poll for TXDONE on all * channels. @@ -79,6 +80,8 @@ struct mbox_controller { bool txdone_irq; bool txdone_poll; unsigned txpoll_period; + struct mbox_chan *(*fw_xlate)(struct mbox_controller *mbox, + const struct fwnode_reference_args *sp); struct mbox_chan *(*of_xlate)(struct mbox_controller *mbox, const struct of_phandle_args *sp); /* Internal to API */ -- 2.43.0 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv