From nobody Sat Jul 25 18:53:39 2026 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE571423EB7 for ; Tue, 14 Jul 2026 22:24:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067877; cv=none; b=jBi+oerLIv4Y9uRz/T1hnDkaE5xHwDrlQXtxDY95JDacMdrrk7aO+USiqbbqjamKK+lX+crhLKjnbvhhGdTKnnHMdc1BQMIF6yN1XmZ4sqOH4JX/6ald7JsViBqHXYtKfAfpBR0bIvNanejskgRhC9X08F47aZWaa+/AOYRm+SY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067877; c=relaxed/simple; bh=9EcvQ7bzdbbpYQtywxOuWlPXMV8TI4bnO8pzl4xaPPE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Whq2f4ZjMIgpcNDcDiCeOZR3KjFV5IhAfchLXy/T9p00ScYEDWRVmzd1O8B7cuw3ghqwvJAbtPKw59tdb2wM7GQrmcVTuQMmY9y0hyWAv7Ts9wLG66quLQ3EdHjGmdui1JlXGT03tVS8uKPYajULB4RjoWo0DjHCacqNMrmiHDM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=fFgGYWXw; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fFgGYWXw" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-38e1a9d9105so1051971a91.1 for ; Tue, 14 Jul 2026 15:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1784067875; x=1784672675; darn=vger.kernel.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:content-type; bh=uns/By3GJ6ELjCtz5l0jrpnosmKAdWu2Pl5uOFquXDE=; b=fFgGYWXwnCDGM10+eVvLpbTjtBVwgRF5Zom1+Ye+G/D92/oPwTU8VtFO+fZu3rkuUA ycwvF1gLmj0T9VI6gCTo7efAlyOOy54SJUXzio522E/lSo7ZMbumwx5CHqNnSdZih9Dr YTDts1EoUwwQe2KglgbQEfl4b/pxaLMGzI1Z0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784067875; x=1784672675; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=uns/By3GJ6ELjCtz5l0jrpnosmKAdWu2Pl5uOFquXDE=; b=ZZoUaF288hE8Vui19NQZu11ZXtefVqhIC5rm19RGEOmH5nV9QPh8ZZ4TA6Apfvllu2 gAuPzwBxyAPS/JrNIDHcnMTQ7LKCMMsNERKlL8qKPToDsLDoqVzEDW81Flp5cqFFdUmB mGhH6UBC1PXBF7nxYbqoSkQVfU9xKbPLhCcgGlB6GUaIlOe4mhtGHD3esMiI5/sbOm2X Diws2leEYgctwWEKBaSALEwPmKjwgMfn+6j4Ra7i+d2tvsntjU5+BxpRXgua1H4EocTZ lfTyDAjjJYZoadCcNd7fLV9W1GGL6DaQ2DAqlwGPj0dEncLBfsStbJ3Ayl9WmGlKKsWV rpwQ== X-Forwarded-Encrypted: i=1; AHgh+Rq40VhMp+r1ymOyRI90m2R8JmwMMrjBtsfyeLx0Lqcq8RB4cL/Jt93wIUEQVYM+Od4VPx30nyWkVXbjR28=@vger.kernel.org X-Gm-Message-State: AOJu0YwfLV4HWf2K1mngJUFaQcA4PJhiQ2oNzRlkLW4jEfS+26zL+W3L EYlowT8Qgie0mCpvPs0iSpPLyU5llylMPTgANkf/+EFq38uqfBRvCvy3kmnGWwl8kQ== X-Gm-Gg: AfdE7ckqQXrR7a4ji2kL45XJEdDtYGuJSfWjrlMxVDiQFpobYb1HiPtVShtM0MsrcZd q61h3FPpynANrDgxmcwXnGDjE+gTQsf2G2ME5uaVT2A0KpPeQPCGUcnx0nJYX2I/lP638NQhrnh IUa0rioQsPq4lPaVtdgiNtFXxvlYaxOz1QBKLLzIHWYi5rbkFocSxGuM/ZA1olvpHSorLfHSzUY 50H1iG+F7cU/v4JR40+6IRgz+YQGqPgiLz33Ty00IY6lZH0s/GPVCTgsChkRFZxQe5T/xkd7M6k +A+tEpXMizPEWXCiCPAoTMSWIxKXM+UWFotEbHrdW97MM/7kfzA8pHgcorE7IbXmGRJMd27Nes5 9nBgOnJfkihqkmtrhjcpfSxGssThoIMeifjA7cqla7LhKm8rVJYT+1tuwoRHTUwfMcahjbz1dAD TxmwdLuI0fYsxXeN5p9BW+zg3MLAmHC/Kdv0Mdauw404AvydIrzvVEb7PU/e7cDob1SMjcCQ== X-Received: by 2002:a17:90b:57e5:b0:38d:e7b7:5125 with SMTP id 98e67ed59e1d1-38e2a030175mr400186a91.17.1784067875104; Tue, 14 Jul 2026 15:24:35 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:32cb:eed4:7c:dc87]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31189cd8234sm76540741eec.9.2026.07.14.15.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 15:24:34 -0700 (PDT) From: Douglas Anderson To: Jassi Brar Cc: Joonwon Kang , Subhash Jadavani , Tudor Ambarus , Lucas Wei , Brian Norris , Peter Griffin , =?UTF-8?q?Andr=C3=A9=20Draszik?= , Douglas Anderson , Conor Dooley , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/7] dt-bindings: mailbox: Don't require #mbox-cells to be 1 Date: Tue, 14 Jul 2026 15:21:40 -0700 Message-ID: <20260714152138.1.I814d768336e8de933580d467140ce340f3d4f55d@changeid> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260714222338.2965707-1-dianders@chromium.org> References: <20260714222338.2965707-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Existing mailboxes have #mbox-cells and this makes sense if a mailbox only exposes one channel. Update the bindings to match. Signed-off-by: Douglas Anderson --- I assume this is worth doing (?). As noted [1], mailbox bindings are already in the core schema, so what's here just provides extra context and descriptions. [1] https://lore.kernel.org/all/20260322-mailbox-v1-1-c6251f18187c@gmail.co= m/ Documentation/devicetree/bindings/mailbox/mailbox.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/mailbox/mailbox.txt b/Docume= ntation/devicetree/bindings/mailbox/mailbox.txt index af8ecee2ac68..f50727e9686f 100644 --- a/Documentation/devicetree/bindings/mailbox/mailbox.txt +++ b/Documentation/devicetree/bindings/mailbox/mailbox.txt @@ -6,8 +6,7 @@ assign appropriate mailbox channel to client drivers. * Mailbox Controller =20 Required property: -- #mbox-cells: Must be at least 1. Number of cells in a mailbox - specifier. +- #mbox-cells: Number of cells in a mailbox specifier. =20 Example: mailbox: mailbox { @@ -19,7 +18,8 @@ Example: * Mailbox Client =20 Required property: -- mboxes: List of phandle and mailbox channel specifiers. +- mboxes: List of phandle and mailbox channel specifiers. If #mbox-cells i= s 0 + then a mailbox only provides one channel and only a phandle is n= eeded. =20 Optional property: - mbox-names: List of identifier strings for each mailbox channel. --=20 2.55.0.141.g00534a21ce-goog From nobody Sat Jul 25 18:53:39 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBD4D423EA0 for ; Tue, 14 Jul 2026 22:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067880; cv=none; b=QTRoahexXdoxej2k3JZZ0+CMG9H1J/1GzjrOwE4J2zQnPUy+vhInw1syjXYQK67FynksHmUPa9Y0uaTHRngnRjxMRx5Ixq93Pd9YyYt8xZUJhQkILxmjK8lpS09EO6RI+mhB4q3j0UVJBHLXLKJ4EQNG+Oi8m2JqVbZCotP/paw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067880; c=relaxed/simple; bh=x2DeUMk1ktCoJZ0C/Gjb8CJgpwaMdmf5AfBjVMufH/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dqQEnJMoh0zaPpLiVLZT++o5OFAnJvrgNFYS7i+3stBuucFNXi9oeUmFd/NFQJ38uzSZE5sBG4fEZNbFe4lT+Vp+4iTbARvGHFF6RAA+N5LCDwD1g3z4po3fTxcIZpI0XpolED4TQy3/XidTG5e5+pPhiJdr1rlh7Id7a0OFeZw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Ckt4hS57; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Ckt4hS57" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-38dd55ad76cso1125156a91.1 for ; Tue, 14 Jul 2026 15:24:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1784067878; x=1784672678; darn=vger.kernel.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:content-type; bh=jQCzG2UzjiTiGkixdSPVfHpRNCO6SDWgWMiFgRomhQs=; b=Ckt4hS570dB/64BDlDuO9WG8xk0lp5bYaOO66kCU1nlL4ercMTINhWTXju50cDcN/R PxbFwqTUNVpgWJL+2chCE52WbC901XM9FUh323svSXTUG2K/vNlIJDBwTG1so43o/5Ai dSwL/5BoE2saeeHfsueWuSRECIZLSbXLfEO4E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784067878; x=1784672678; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=jQCzG2UzjiTiGkixdSPVfHpRNCO6SDWgWMiFgRomhQs=; b=b80g8uyAomvpiKKRi2arte3mCoLG1gbaA23a1m9kitTN4DLrJ0f46U9RsZ9FWO5CCi e/WFGiOS1Pm5OjMEhzDk7gQGXanBBTWFqWFbI5GjfCHKtxbwXaNaGIrZbYWn6Cf4pxC1 iEXbCld/5h4VuJolBk4swZq//AxhD1gvB1pglVIYycrZdykzLm3Bn9xj71sGMjvrhPnx KviSG/4mHw0YGzc9w+ZLH6nt4OUzxgLuj3VJjibq/6WaHeZIF1l28yLAc4MCdv3cC9XV LnDeZ+Q+uw9HUR8/ctpgcoYso+T/po+W4CBXQ5hgVIqRFpujgK+L2UhdXhaz6+Frk8jg WdlA== X-Forwarded-Encrypted: i=1; AHgh+RrMeo7qv2JefFfjucXKI0e56ztukosr/ODMw3wmRwJP87eFfyjT160i1UW/ap3cwqV4IlBx3ia7f5VOW6o=@vger.kernel.org X-Gm-Message-State: AOJu0YwFm7YKWL1aTwtZJiceDxGkXTG5rTrDHgDj1DB3pCSJoG9KBdzy b6CMe06Ta2w6uI3y4Acxk0WxBPGUC5Qw8BqYk+nUjSMeQZnLfx6+8sgdmT8aLTlWvA== X-Gm-Gg: AfdE7ckfhubm5HwytLDg7zDi0wMiIWuDxlvpfapSEpMvmX/d5vMlXfNKgm3hpNS6Pad qGwlJjzwR9zK/P2JK70lLMQMarzVyZo7CqtyPnKkiPQjBe9soyW/vm+67q7pAG8+NQZUi6RwBWi 3d0nKcuC2eck1GrHn3srDPOvKNXfSrtNBVrKHOxcKx99yjvcKia5jtD2UzKUCxvInuYNsM6WnUx 1Yq1dO+x61oYqeDIGeliIKsNOTb3q7zsqS33V58TOvZ6vtAUrLuM0/iQL+jCtOer1r0irgVN9u0 np6vadoWCYjGKApzg7vIQqZaL8D9e01DGa+DVQmfAKraemDt6+k09GwPUQnBEuwXZE63zpZLhaA /UKoll/p9M0MnNh4/vtQ4JJVbxCbzsXiJ3A5prW38J8pgHIRVXgMKc+qB38BZ9DDyDEiZgsmBLl 26K8f1Ot+xKsuSJlP+63B00SA/ki55z75HQ4qnyuXYW+tiNx8VrkC/Bp/93AEyhMmiXSzH5Q== X-Received: by 2002:a17:90a:d647:b0:381:10a3:8b10 with SMTP id 98e67ed59e1d1-38d15781964mr20694940a91.14.1784067878215; Tue, 14 Jul 2026 15:24:38 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:32cb:eed4:7c:dc87]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31189cd8234sm76540741eec.9.2026.07.14.15.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 15:24:36 -0700 (PDT) From: Douglas Anderson To: Jassi Brar Cc: Joonwon Kang , Subhash Jadavani , Tudor Ambarus , Lucas Wei , Brian Norris , Peter Griffin , =?UTF-8?q?Andr=C3=A9=20Draszik?= , Douglas Anderson , linux-kernel@vger.kernel.org Subject: [PATCH 2/7] mailbox: Allow #mbox-cells = <0> without specifying a custom xlate Date: Tue, 14 Jul 2026 15:21:41 -0700 Message-ID: <20260714152138.2.If447263dcf15e73068905eb9c21a9e630f749615@changeid> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260714222338.2965707-1-dianders@chromium.org> References: <20260714222338.2965707-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If a mailbox is only providing one channel, there is no reason to require any extra mbox-cells. Allow specifying 0. Signed-off-by: Douglas Anderson --- drivers/mailbox/mailbox.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index efacd24a085d..6c9d426f4e58 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -524,7 +524,13 @@ EXPORT_SYMBOL_GPL(mbox_free_channel); static struct mbox_chan *fw_mbox_index_xlate(struct mbox_controller *mbox, const struct fwnode_reference_args *sp) { - if (sp->nargs < 1 || sp->args[0] >=3D mbox->num_chans) + if (!sp->nargs) { + if (mbox->num_chans =3D=3D 1) + return &mbox->chans[0]; + return ERR_PTR(-EINVAL); + } + + if (sp->args[0] >=3D mbox->num_chans) return ERR_PTR(-EINVAL); =20 return &mbox->chans[sp->args[0]]; --=20 2.55.0.141.g00534a21ce-goog From nobody Sat Jul 25 18:53:39 2026 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44A7641A917 for ; Tue, 14 Jul 2026 22:24:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067882; cv=none; b=cdnResDfPLA6sSIE362gjSl0sV1IUWFCAGQJOkFOpuBwm0q1FAJxPutDZbgI5odJsmBlqLxJHj7MFcAYLtpgOBEE5VGKqDOUT3rmD1LuPiZ6PHTLOT90nl1D+ovbIDotMIl2dBDSgVjBqk6hhrK+zmxpZkaLBG6zDQyK4dcJttE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067882; c=relaxed/simple; bh=OBWBvZwFC4i2UBn5AmUtPqtNcTYhnRJA6IzkVO8B2sY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=shfw8OZFMmlXDnhOCE3fuNQ8NKkJfX4T56eaSkYUpSxtRk1WKejSX4CuVMk/7bTdNbr8sHwQyJRTSdG4ykyacFuvFGSvOjSj848B8DgUBxJpktZmMQ4ZD/+EpP3KNu/48PNPmzc2NAiHRZtm7GMVSVyAHOSDhm8A6DYB1Ix3ozA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=LYMyoteH; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="LYMyoteH" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-c9eefcf9175so1288182a12.3 for ; Tue, 14 Jul 2026 15:24:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1784067880; x=1784672680; darn=vger.kernel.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:content-type; bh=ey/LCox5ahRsIKxwvZd23BFY/F2+qCNObSvq9MCXfCc=; b=LYMyoteHUDsPTZHv0XR7N+qfbXIPxUeDdj5ABRswbBjOUEj7W0ilzywhrW+Crj3S6p BYK2iHvs9VzIFEWokirU5oL930b2uiVU1aaGZKPrHVp+M2XDiOLMU+dPKvES3gKxqRVV Ratq0BWT6JGDIFZauOqFoiaUhUfMz8ePePDE0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784067880; x=1784672680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ey/LCox5ahRsIKxwvZd23BFY/F2+qCNObSvq9MCXfCc=; b=BoUbsSAXrnKuhG79XTqL3ndgdD9JmOPgQljF7Z1OcnayjXkCvzkCwCMTEn2hMQYflt YQkFyzbPIbAdoLppyOeh29WFuUSqGZYqY4LYy27KUAgnN9asiisxPosk2usp53SM8wYA PAxxoV+E0VIExieO1nnzE/aV7jFqaT5ZausNBT8p1VF+v0D/m1b8uBlCt8OBYR8tSVHa /IBldgIURKE/pHEDT2CbfY9EcjMZMfb9K5WiacOcXUjFpxXI5HPqcO3aEpXaXIxMbgfX i0pxrRFmS6vjDQco7+yLspVrXU9zycMqRax2I7CWP2wU/hLEVkpWlVmokCy727Gr4Uei Ircw== X-Forwarded-Encrypted: i=1; AHgh+RrrhCe4kAantBq2BtFH/YCWUkaG3dG2tNL03aG0WNbqbFjLQOOxiJFtXdGaecY+Soe0QAUHJNzcIvLV/uY=@vger.kernel.org X-Gm-Message-State: AOJu0YxpnVj9uqHNPJpGdb3EsOmLaBKemjOxs06MdZuKJ0lsk+BS7PFm bbIlgTkhhjsxZPV2Jnwf1fnu21vxaxX+Z4rJUgOWKHcsMN+xRvTYOdgqoJCHFAzPgD87SCbZRZD nG5Y= X-Gm-Gg: AfdE7cnomlolzeBQBjx86V2MUq7IDxIANbQxT4CGxMfg1BBK3bQhzDGCnsj7dx2OFfu Oo/3K2tLm21VZjz07TS24tPeD3ymLFq/Mm6HpxjATEH9fw0jNnXFz0dssE2iKYUFBmkSh6DVaF4 CPf2VNbcUcp/eq5ebzPzu6fpQ7bBBx8Hcrk5pkH9Q9hyo5mG6pyWMs0drPsxmRsN3G/nRQyf4GW iWiVboDs399t4LrHL1TYIC9lxB6enice3gDzCp8c09V4uOr4ZBkFYjTcGi0jaBggyQ8WRXpOs0l 9LTosx1dxGD7x9MuNagl2ODce+DiexQVfJBPcniWLlw93Pvrv/AmGrJZ8JWoKlR4Qyui/iEYEu1 aaR79Q/V5xZsu8ajWVA8KY6PdMGABW2Ohb88+ZqVg+d38S/lkczw/IW63iVfnF/K3D7hbx5CH1o JOYc8bcrI1Vrlr09nRPLNOdDvC8wZLnD1UE9npoF/qpfkDWWhAKOy24OzeE3I3EkdvSFg3JA== X-Received: by 2002:a05:6a21:4591:b0:3bf:6c08:2841 with SMTP id adf61e73a8af0-3c110775a5bmr16647268637.48.1784067880690; Tue, 14 Jul 2026 15:24:40 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:32cb:eed4:7c:dc87]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31189cd8234sm76540741eec.9.2026.07.14.15.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 15:24:39 -0700 (PDT) From: Douglas Anderson To: Jassi Brar Cc: Joonwon Kang , Subhash Jadavani , Tudor Ambarus , Lucas Wei , Brian Norris , Peter Griffin , =?UTF-8?q?Andr=C3=A9=20Draszik?= , Douglas Anderson , linux-kernel@vger.kernel.org Subject: [PATCH 3/7] mailbox: Find a matching mailbox by fwnode rather than device Date: Tue, 14 Jul 2026 15:21:42 -0700 Message-ID: <20260714152138.3.I23f9ba38d31789f37c02843132172236b96caa6c@changeid> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260714222338.2965707-1-dianders@chromium.org> References: <20260714222338.2965707-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sometimes, instead of registering one mailbox with a number of channels, it makes for a cleaner design to register more than one mailbox. To make it concrete, you might want a device to look like this when represented in device tree: mailbox@abc { compatible =3D "my,mailbox"; reg =3D ; north_mailbox: mailbox-north { #mbox-cells =3D <0>; }; south_mailbox: mailbox-south { #mbox-cells =3D <0>; }; } mailbox-client@xyz { compatible =3D "my,mailbox-client"; reg =3D ; mboxes =3D <&north_mailbox>; }; You might want a design like the above for a few reasons, including (but not limited to): * There may not be an obvious numbering of mailboxes. In the above example, it's not clear which of the "north" or "south" mailbox should be ID 0 vs ID 1. While an arbitrary mapping could be created, it's cleaner not to introduce an arbitrary mapping. * A single device could have mailboxes with very different properties from each other. A mailbox with "channels" implies that all the channels are fairly homogeneous. A design with sub-nodes and no "channels" allows each sub-node to be independent. At the moment a device tree design like the above doesn't work because, when searching the mailbox list in mbox_request_channel() we check against the main `fwnode` of a device. Extend the mailbox interface to allow a `mbox_controller` to specify a `fwnode` to use. If this `fwnode` is NULL then keep using the `fwnode` from the `mbox_controller`'s `struct device` so that existing code will keep working with no changes. Signed-off-by: Douglas Anderson --- drivers/mailbox/mailbox.c | 8 +++++++- include/linux/mailbox_controller.h | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 6c9d426f4e58..692087d461a5 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -463,7 +463,7 @@ struct mbox_chan *mbox_request_channel(struct mbox_clie= nt *cl, int index) scoped_guard(mutex, &con_mutex) { chan =3D ERR_PTR(-EPROBE_DEFER); list_for_each_entry(mbox, &mbox_cons, node) { - if (device_match_fwnode(mbox->dev, fwspec.fwnode)) { + if (mbox->fwnode =3D=3D fwspec.fwnode) { if (mbox->fw_xlate) { chan =3D mbox->fw_xlate(mbox, &fwspec); if (!IS_ERR(chan)) @@ -580,6 +580,10 @@ int mbox_controller_register(struct mbox_controller *m= box) if (!mbox->fw_xlate && !mbox->of_xlate) mbox->fw_xlate =3D fw_mbox_index_xlate; =20 + if (!mbox->fwnode) + mbox->fwnode =3D dev_fwnode(mbox->dev); + mbox->fwnode =3D fwnode_handle_get(mbox->fwnode); + scoped_guard(mutex, &con_mutex) list_add_tail(&mbox->node, &mbox_cons); =20 @@ -607,6 +611,8 @@ void mbox_controller_unregister(struct mbox_controller = *mbox) if (mbox->txdone_poll) hrtimer_cancel(&mbox->poll_hrt); } + + fwnode_handle_put(mbox->fwnode); } EXPORT_SYMBOL_GPL(mbox_controller_unregister); =20 diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_con= troller.h index 26a238a6f941..591ccce3de3a 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -63,6 +63,9 @@ struct mbox_chan_ops { /** * struct mbox_controller - Controller of a class of communication channels * @dev: Device backing this controller. Required. + * @fwnode: Firmware node related to this controller. If NULL + * the firmware node of `dev` will be used. Register + * will grab a refcount and unregister will drop it. * @ops: Operators that work on each communication chan. Required. * @chans: Array of channels. Required. * @num_chans: Number of channels in the 'chans' array. Required. @@ -83,6 +86,7 @@ struct mbox_chan_ops { */ struct mbox_controller { struct device *dev; + struct fwnode_handle *fwnode; const struct mbox_chan_ops *ops; struct mbox_chan *chans; int num_chans; --=20 2.55.0.141.g00534a21ce-goog From nobody Sat Jul 25 18:53:39 2026 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6870F427F81 for ; Tue, 14 Jul 2026 22:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067885; cv=none; b=ojE2MARWimUVPO99pACt+VRjgsM+osiL9VPRW6b7YgT7TmWtCttKg5oFYcSbjn6EahJ/0c9x8JHbGYpBd98i8HzZc3+pnDiUptJF84wwaCg/FrS1Lip2pjMiobmyvAk287srG5KdZe89wq8d8NDdtR+Yf4znk7v3YXpMibCHbgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067885; c=relaxed/simple; bh=M5H2PmYWEQIVpC1LG0SrWcmfoLk0Ow7e9MjtxAF3OsE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IH1FQfK+W9Noy6tRhw4l3/1P6A28eyZxp25ojLiFotAy0ThBTEISyxCq3vxV6kpJd9sBkGKv5Dx96JHiYkYAwUdm2BEd8GYC/fFNHRnKnumwHf7hVqH5RgWVS28399n0FjIsjT0UxMoNLZmDJtXsMbBBGqaosCft3wcbrnT07XU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=SBQGMtZL; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SBQGMtZL" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-381216921aaso5111224a91.1 for ; Tue, 14 Jul 2026 15:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1784067884; x=1784672684; darn=vger.kernel.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:content-type; bh=f7yB6qOyIKE5LVJKJtZJsq+pdHh8fn9+grxCFBhVgN4=; b=SBQGMtZLOATNnG4hPbEnVWXnMn+mcGMmFUpqlIEbRwcSPqfKzcgtfv21wzUTv5jsIk V4id0ChWIpuJ0L1Jqc58ziAelrdgfJCaz5TycdqZNiy/ndWnFZ2jHvlMV7jy9WPWHmsG guaAZfmih/m9ZGwcVOnOTteff7FqV11zVRU8U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784067884; x=1784672684; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=f7yB6qOyIKE5LVJKJtZJsq+pdHh8fn9+grxCFBhVgN4=; b=GLt1NrmBd8safkeaGafRks0t215DuWfpU0IHKNR9t8iD4cnl6lDv5H8UhMUdGbFfnT W/zpqoVEY6R/G8tZfaRHkDpuREyCYt7GwUAyAKBw/zK4YV1zQWEktG5ZbzxfNuCUlXz6 raXH5GlCgTtqvw+ruaYHrJlfaKy2frVLnAGrqN6gWfrHkEc2QnoTeG6msHJNcinjlkEw 9xInMwA4zitTCErzoTJ3xdrk8FpAeFzT6VWFLl/J4FTPQzNLnM0wSM7tQqPjl8QTITFZ p2AOpzp+7YupPJK1ujIPzXuNFMNwIiZccXf9zxBwNBaUkoJZ/pkjSdixbbFGmqchmE5M WWoA== X-Forwarded-Encrypted: i=1; AHgh+Rp8Kfy1XNYjgNmDlhD+5IBr1hjIKVxnVH1umaJtmMrbXpm13GRNUVdLmAolHC+u8neLfAmxjilRw1zrxBs=@vger.kernel.org X-Gm-Message-State: AOJu0YzozPLgWwPRhxt1qADJcgjyrEe7o2tY+jENwj/VrmgYecEw8E/f m6q0I7ZpHap8An54plli6/HKaLUny7VToER1fYcfcHrLnxJmIwMDwYJTZ8YlomPI1Q== X-Gm-Gg: AfdE7ck5j9pp6jLC/v6Bi9CtLaAzchB9ATl/JT5foMTEtplpfTlDfpOtufvr6+xUDFl 5ViQq3vvNQ18vTXAtF0udRnEkpglHg4uSS2qBYHOg9Lr+pCQqeeO6R51xHvGPLTigYV6mYEDdRy UF3qLAliwpx+FnOW49754x19kb8ni16GeVIHbOYsubsZcTc0Mz95sqB8xzlfncOH0owWjIlJaPy c0vwEhD1h9co1XdKxMggDJ1ySLFYRbgch2/UvLP+7MrzkEAyvVZGkhLaYXD/nJ9dJdWVysr+vDY ZbT+aXgrRzi6cO0tLmsXNW6c1v/kCq2gaPFXd9fnjsuauO13XRZ62rDBOMaexKonAHrIqazeNeJ GxL6szYedMIxqAfrPTBan0Eo8zPes6Enofi982Ar3RIJ/OMnxZKGwJBocmTuktSn4C+CnsKSBHq yGbSDt+UkVWDW2l6yGRBrn7jM41X8KIWYb5voivJEjLARaebTEsv5N0xCBfQ1N9yJ1V7tCag== X-Received: by 2002:a17:90b:3ec8:b0:37f:e1af:df22 with SMTP id 98e67ed59e1d1-38e1aefa9a3mr4187238a91.17.1784067883831; Tue, 14 Jul 2026 15:24:43 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:32cb:eed4:7c:dc87]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31189cd8234sm76540741eec.9.2026.07.14.15.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 15:24:41 -0700 (PDT) From: Douglas Anderson To: Jassi Brar Cc: Joonwon Kang , Subhash Jadavani , Tudor Ambarus , Lucas Wei , Brian Norris , Peter Griffin , =?UTF-8?q?Andr=C3=A9=20Draszik?= , Douglas Anderson , linux-kernel@vger.kernel.org Subject: [PATCH 4/7] mailbox: Simplify circular queue math with mod arithmetic Date: Tue, 14 Jul 2026 15:21:43 -0700 Message-ID: <20260714152138.4.I32b5edf2782f9c9524c71ca4ab4284596b3868ca@changeid> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260714222338.2965707-1-dianders@chromium.org> References: <20260714222338.2965707-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The mailbox core keeps a circular queue of messages waiting to be sent. It keeps track of the index of the next free entry in the queue and the number of entries in the queue. Given the index of the next free entry and the number of entries in the queue (count), the index of the first entry in the queue can therefore be found by starting at the next free entry and going backwards in the queue by "count" entries. This is succinctly expressed by the following math, which handles the circular queue wraparound case: first_idx =3D (next_free_idx + MBOX_TX_QUEUE_LEN - count) % MBOX_TX_QUEUE_LEN; Currently the mailbox core doesn't use that math and handles the circular queue wraparound with an "if" test. Replace the code with the equivalent math. This is intended to be a no-op change and just code cleanup. Signed-off-by: Douglas Anderson --- drivers/mailbox/mailbox.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 692087d461a5..d99a08652ef1 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -56,11 +56,7 @@ static void msg_submit(struct mbox_chan *chan) break; =20 count =3D chan->msg_count; - idx =3D chan->msg_free; - if (idx >=3D count) - idx -=3D count; - else - idx +=3D MBOX_TX_QUEUE_LEN - count; + idx =3D (chan->msg_free + MBOX_TX_QUEUE_LEN - count) % MBOX_TX_QUEUE_LEN; =20 data =3D chan->msg_data[idx]; =20 --=20 2.55.0.141.g00534a21ce-goog From nobody Sat Jul 25 18:53:39 2026 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35F5242EEA3 for ; Tue, 14 Jul 2026 22:24:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067888; cv=none; b=UUDWHsAHplukWg3bsjC1r0rKR91Y2U6jrJTWhpdtXDRNkHNW1M1w1Y7vG4PzBc0RV5cM5Kd8SKXzipK+cYY1r5I1dvVQHzVIYEzrEKQCesQdnHenAW48vjOgugciVst/808kTXtGf/iaW22cIw/UyPoEr93Vf4kWhZX/XtXxiI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067888; c=relaxed/simple; bh=UDKxs8llhvTQhoU/XVUrdplf3tVVa9tYC4B/sVHMtks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nrSQ7dkuoCnPB7ebhYewQmRm8D8WyuP8BgS/Qud9oy3/fLXEzAXt7H++2M5rtPb1P7FEcnpw1pbSfi5VqVUgyRuoqGWWltAFm3JSmtvYMtg/f8Zh4rLt+73DzLh+Vl5K6sf/WBDux6RXNatRk8cKhKaICu+XxiMMRazujUgBwgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ljih9Dhb; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ljih9Dhb" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-38dcbade417so3206368a91.1 for ; Tue, 14 Jul 2026 15:24:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1784067886; x=1784672686; darn=vger.kernel.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:content-type; bh=vrvWopwh0snmgBukO+hQMdGbzoC9Uh7Vjr1PY4sFJdo=; b=ljih9DhbD9N8BPtcVVkPp4V2b6hgefJo6kaPFIzTuQdKk3udED1Lxf3QaStKET/OJP ErRwD0foukqjvx/ysF38jH0PQkcS97Hele8jFShuJERI//PdGv9isatsjT4Om4dbKDl7 KNP7Jo++K7v5J6ZvY5VxzSmU0D0QTJ2S/atA4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784067886; x=1784672686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=vrvWopwh0snmgBukO+hQMdGbzoC9Uh7Vjr1PY4sFJdo=; b=Rf3ruWadD9svtsBM27mCIgNnCOPX6iZjtmUrQ4j5z26g5/lV+n9pqvHWhoJMqYYz/z qP/BX+RtboEUc2QwVeIR+1AwiiRASAlxiW8bk+YBWLSV7SeXuIfHmH6lCdAgx5s+QXfM fsOCtL4QGnY4GAbHDZEqjoNEX0Ffqj/y1+tXrlRkufVDDypgzq/52QWLNr/Dirqc7+Kp ywOLsc16o/GrYfxCAOApXVPhCeU+jERIultnUjmQvWyNGC8YEwMO3MlJ4Odg7WOQI642 psLdCvAHe3xvTvx8ziuKKrcr0LQ28kFLo1esdsuz7KQG6WkCEeXQMNsfS6Jov9JJccAk DvPA== X-Forwarded-Encrypted: i=1; AHgh+Rr7JjPAbk0FGDu41lmmH9xBbLSHwpRnHFOpPFEV4TfW14Q9idiCUf+pUN5OmRtsbEgSR0ajOHhxvVyAPp4=@vger.kernel.org X-Gm-Message-State: AOJu0YyKG7m9jBt9WwpSM2KWBIC/1xxYkMWr1FxaF+LnskDgInLHJs1a 7i7Zi/rzdlX9fSuEGqsx/gCaBAi0PnsDe/NJhbgiIBnZ2AFpd36AgPTSYqMUzbsyzw== X-Gm-Gg: AfdE7cml57jxL80kYh0C6ffiq81rSiowMvELiUj8A2FcYV7ECrgmVYuYbuorby9s6CR BSrKDpkNCAg0CqISrFGbqNDzDxh38mUwNfwaaoqGRV/BTBdwN6ORNg+zpmjk+BTxylhmk/67xge 0TseM8/v5MUiu75urOijuQ+j6f2mFZBRTYcBo6XC5HqB4EdsAycNB8tYlBAkbZNAXPPkQlfgg/e zYiDN/kITQDbNtS0RM1ffMrtGZ4xWkzsiWMU00qa1X7O2bum4uZJTF+0/LEH+0bKyxoBdLDo26Q 6HhmO6todxgLGyWddJtSyTw5NR3m2tO4YUIK22O+BfdOg3OYehAE3nXVoD1qyfda/AfXVRP5nbR KOeBtgymsuQV1g83hNqDWLeNA+Q4NvWfHDQ8WnG33LA0DyeaDW9MjA6v18vXob93sLICKO9DChF CjwN6aJ/wMnwTDyfLMzmede0SbETWiCSFLC2gmHMxG9GGPx9zCWXqeGXMz59U42he9vU+Tqn+Vg 48e2pPn X-Received: by 2002:a17:90b:3951:b0:37f:9cdf:f0ac with SMTP id 98e67ed59e1d1-38e17e4295bmr4863205a91.27.1784067886559; Tue, 14 Jul 2026 15:24:46 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:32cb:eed4:7c:dc87]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31189cd8234sm76540741eec.9.2026.07.14.15.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 15:24:44 -0700 (PDT) From: Douglas Anderson To: Jassi Brar Cc: Joonwon Kang , Subhash Jadavani , Tudor Ambarus , Lucas Wei , Brian Norris , Peter Griffin , =?UTF-8?q?Andr=C3=A9=20Draszik?= , Douglas Anderson , linux-kernel@vger.kernel.org Subject: [PATCH 5/7] mailbox: Add support for mailbox controllers that can queue Date: Tue, 14 Jul 2026 15:21:44 -0700 Message-ID: <20260714152138.5.Iddb22a90725719b95e77691cfaa23a92a0696c1a@changeid> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260714222338.2965707-1-dianders@chromium.org> References: <20260714222338.2965707-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The API to mailbox clients already allows more than one message to be queued at once. Mailbox clients can freely queue up several messages without waiting for an Ack and they will be transferred one at a time. Currently, all of this queueing is done by the mailbox core, which never gives more than one message to the actual mailbox controller at once. Newer mailbox controllers may have the ability to queue messages themselves. This can significantly reduce latency in transmitting mailbox messages since we don't need to wait for an interrupt to be Acked before sending the next one. Add support to the mailbox core for mailbox controllers that can queue messages. Support turns out to be relatively easy to add given the current architecture of the code. To keep things as backward compatible as possible and to reduce code changes, still keep the "first" queued message in the `active_req` field, but also allow transmitting data that's in the `msg_data` queue. Whenever a message finishes transmitting, promote the new "first" message to the `active_req` field. Signed-off-by: Douglas Anderson --- drivers/mailbox/mailbox.c | 64 ++++++++++++++++++++++-------- include/linux/mailbox_controller.h | 11 ++++- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index d99a08652ef1..1cd9e0ba3531 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -47,26 +47,34 @@ static int add_to_rbuf(struct mbox_chan *chan, void *ms= sg) =20 static void msg_submit(struct mbox_chan *chan) { + struct mbox_controller *mbox =3D chan->mbox; unsigned count, idx; void *data; int err =3D -EBUSY; =20 scoped_guard(spinlock_irqsave, &chan->lock) { - if (!chan->msg_count || chan->active_req !=3D MBOX_NO_MSG) - break; - - count =3D chan->msg_count; - idx =3D (chan->msg_free + MBOX_TX_QUEUE_LEN - count) % MBOX_TX_QUEUE_LEN; - - data =3D chan->msg_data[idx]; - - if (chan->cl->tx_prepare) - chan->cl->tx_prepare(chan->cl, data); - /* Try to submit a message to the MBOX controller */ - err =3D chan->mbox->ops->send_data(chan, data); - if (!err) { - chan->active_req =3D data; - chan->msg_count--; + while (true) { + count =3D chan->msg_count - chan->num_queued; + if (!count || (!mbox->has_queue && chan->active_req !=3D MBOX_NO_MSG)) + break; + + idx =3D (chan->msg_free + MBOX_TX_QUEUE_LEN - count) % MBOX_TX_QUEUE_LE= N; + + data =3D chan->msg_data[idx]; + + if (chan->cl->tx_prepare) + chan->cl->tx_prepare(chan->cl, data); + /* Try to submit a message to the MBOX controller */ + err =3D chan->mbox->ops->send_data(chan, data); + if (err) + break; + + if (chan->active_req =3D=3D MBOX_NO_MSG) { + chan->active_req =3D data; + chan->msg_count--; + } else { + chan->num_queued++; + } } } =20 @@ -83,7 +91,17 @@ static void tx_tick(struct mbox_chan *chan, int r) =20 scoped_guard(spinlock_irqsave, &chan->lock) { mssg =3D chan->active_req; - chan->active_req =3D MBOX_NO_MSG; + if (chan->num_queued) { + unsigned int idx; + + idx =3D (chan->msg_free + MBOX_TX_QUEUE_LEN - chan->msg_count) % + MBOX_TX_QUEUE_LEN; + chan->active_req =3D chan->msg_data[idx]; + chan->num_queued--; + chan->msg_count--; + } else { + chan->active_req =3D MBOX_NO_MSG; + } } =20 /* Submit next message */ @@ -339,6 +357,7 @@ static void mbox_clean_and_put_channel(struct mbox_chan= *chan) scoped_guard(spinlock_irqsave, &chan->lock) { chan->cl =3D NULL; chan->active_req =3D MBOX_NO_MSG; + chan->num_queued =3D 0; if (chan->txdone_method =3D=3D MBOX_TXDONE_BY_ACK) chan->txdone_method =3D MBOX_TXDONE_BY_POLL; } @@ -359,6 +378,7 @@ static int __mbox_bind_client(struct mbox_chan *chan, s= truct mbox_client *cl) scoped_guard(spinlock_irqsave, &chan->lock) { chan->msg_free =3D 0; chan->msg_count =3D 0; + chan->num_queued =3D 0; chan->active_req =3D MBOX_NO_MSG; chan->cl =3D cl; init_completion(&chan->tx_complete); @@ -552,6 +572,17 @@ int mbox_controller_register(struct mbox_controller *m= box) else /* It has to be ACK then */ txdone =3D MBOX_TXDONE_BY_ACK; =20 + /* + * While it should be possible to make queued controllers work with + * other txdone mechanisms, extra care would be needed when + * scheduling the hrtimer (for "BY_POLL") and extra testing would be + * needed in general. For now, disallow. + */ + if (mbox->has_queue && txdone !=3D MBOX_TXDONE_BY_IRQ) { + dev_err(mbox->dev, "Queued mailboxes currently need a txdone irq\n"); + return -EINVAL; + } + if (txdone =3D=3D MBOX_TXDONE_BY_POLL) { =20 if (!mbox->ops->last_tx_done) { @@ -569,6 +600,7 @@ int mbox_controller_register(struct mbox_controller *mb= ox) chan->cl =3D NULL; chan->mbox =3D mbox; chan->active_req =3D MBOX_NO_MSG; + chan->num_queued =3D 0; chan->txdone_method =3D txdone; spin_lock_init(&chan->lock); } diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_con= troller.h index 591ccce3de3a..6b5d2be7b47e 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -27,7 +27,9 @@ struct mbox_chan; * if the remote hasn't yet read the last data sent. Actual * transmission of data is reported by the controller via * mbox_chan_txdone (if it has some TX ACK irq). It must not - * sleep. + * sleep. If `has_queue` and the controller's queue is full, + * -EBUSY should be returned to maintain consistency with the + * non-queue case. * @flush: Called when a client requests transmissions to be blocking but * the context doesn't allow sleeping. Typically the controller * will implement a busy loop waiting for the data to flush out. @@ -69,6 +71,8 @@ struct mbox_chan_ops { * @ops: Operators that work on each communication chan. Required. * @chans: Array of channels. Required. * @num_chans: Number of channels in the 'chans' array. Required. + * @has_queue: Indicates if the controller can have more than one + * active message at once. Requires txdone_irq. * @txdone_irq: Indicates if the controller can report to API when * the last transmitted data was read by the remote. * Eg, if it has some TX ACK irq. @@ -90,6 +94,7 @@ struct mbox_controller { const struct mbox_chan_ops *ops; struct mbox_chan *chans; int num_chans; + bool has_queue; bool txdone_irq; bool txdone_poll; unsigned txpoll_period; @@ -129,6 +134,9 @@ struct mbox_controller { * @msg_count: No. of mssg currently queued * @msg_free: Index of next available mssg slot * @msg_data: Hook for data packet + * @num_queued: If the mbox `has_queue` then we'll go ahead and try + * to send data in the `msg_data` queue. This is the + * number that have been successfully queued. * @lock: Serialise access to the channel * @con_priv: Hook for controller driver to attach private data */ @@ -140,6 +148,7 @@ struct mbox_chan { int tx_status; void *active_req; unsigned msg_count, msg_free; + unsigned num_queued; void *msg_data[MBOX_TX_QUEUE_LEN]; spinlock_t lock; /* Serialise access to the channel */ void *con_priv; --=20 2.55.0.141.g00534a21ce-goog From nobody Sat Jul 25 18:53:39 2026 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41EEE42DFEA for ; Tue, 14 Jul 2026 22:24:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067892; cv=none; b=tdThwhyRp/e4oEuJ2esT7tt3R9IpqpWh1Hs77SRzPcoDXlVrd7WJdgj1/JsyAU1SBkCiQ240rr3CuuxCM8WCWSmf3Zk4sibSXHa47jKci0tSxRZoMbUIvROdZ+UyI7FT/bpRV8lAViQSEM5VQ+GpdhvPaCkQDHPwdS0CPBmorbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067892; c=relaxed/simple; bh=yfVlUKAddl4kTtUsempt+7UPHqLSqNbbJXlNW55TxBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qb07ZiGfxkGhBsGQWK4xuuqP/pU6mhZA5HL/ZU5zvWucO+wiAj5BjHMBYGB3ltkMvFanLsHK81DD1cQKSRnt1qegrzaXzaT4rQPp9L3B3RiQ3LFMr5x94S1ZKXGQQ0meOr1pez/iD9FTb5idNBKL+qs8fhlq4ccNAUkyFWGKYkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=L8L5wLDe; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="L8L5wLDe" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-38175907a56so49053a91.0 for ; Tue, 14 Jul 2026 15:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1784067888; x=1784672688; darn=vger.kernel.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:content-type; bh=iLHxmEFEAAhUWHFz+6vyD9YF+Shz/3zBH9jPJj0HIOA=; b=L8L5wLDeLUYvsVUmRDerH0FJrE1XxxrPe53QjPmhYEvjkDSH0lTYwGmR0Rf2/R/J3t G73E5dM6YWKF1JtB05QgvraMvv0fOH+jmjvE83qSfZROpl0DCsBi/4vFLK9+74sPc9FN +R4GmTRiy7sfxPQo9cwTEOl0qWlmlEpNVLVYY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784067888; x=1784672688; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=iLHxmEFEAAhUWHFz+6vyD9YF+Shz/3zBH9jPJj0HIOA=; b=i+RBANUZyxhaHmsPw3KUSQMZYxuecLrlDrf6JEk+Vi3iCvWyW1cvrT1JaVieJQ0inj 2KPCIRUWjnkA2dqt9lSeI93pL5gRds+dxL4zkZohZOgWr/iDt8FMgOsqJyW3JbuyMv1j eqF467kGsnEltyMVO+fSdGBD8lMWUmPjcrGalmwClfD2w1n/hpCc9bJUpmVQHtiGWelR ooI+cn7zLQgXW1mRun8UPIqE6gHRePR7ynJV2IN5dM2RggpZ8Xy2qBaI6GTULO6ob5c1 7A7ykbyoOCAVzIJF6ySp75kV1pgG4nj+Gi9bjnBMOPrLbPaNFp3rqEVr2LjbTWASDvhC n4bw== X-Forwarded-Encrypted: i=1; AHgh+RpUf9jucTK1JYvVRw7HiUm6jloFnic+b1WKXDEoZXtMs+17m/QtWuLXmeXtdKbGZKtDPTbH09Ln5FOmWUw=@vger.kernel.org X-Gm-Message-State: AOJu0YwEhSuOqHGNwCAkQ4pvTFH3rBMSLOfWfLKvnJFUJ02xd8Ibap1c lHKaOFip8DTjME4j2QkFOa53wra1yDEI2uv3nAkgI931paxcscFkZqvP0ZG1dzX4TQ== X-Gm-Gg: AfdE7cnbsOOzRVLdx/rvQVTx9r3112hfS2xwdJ+PqwnBB8vywfGVhN2x/f8Bo5s5P8n 01DiWKYgjq4W11COeHSN7wZrGM6esW3DdtnT+L2dUTRFdXIyIG1z0YnhExH9p2vZeUHDi7Lp2gi phfVwFlBjaCbyK1xK9feQVrGAeDcYNrbmSkEoEWRZboJqJJiBCzFkXJbv2YrCNihY6ZQ2jbQeka IU3wBxnXyKVhmxIJXpes0UhwIVPr9BrDaITbrPRQe78pJckjKtdEcNIiroEwvBp37bpmrij7a9B ri5UhCpQsL4UoTLOcSklQ8WVqBh4UWlmgIppk/myjwCT2ItIcSHH6/huu1hIaksq26KkkBzKw88 44+/jzU6N69DBN52AjQ59Ou+2nNh10qKddzy2NDIf/zvbU8xZB18cyGwEoq0002k8gfHbijcpaK 2fpyzazxtGV0EVEBCheZoXBgXBgXk1OfLv5/sqk6fQdtRyAjIx+PxDARsSoFdMevndqDXnEA== X-Received: by 2002:a17:90b:2401:b0:38d:9eda:fa04 with SMTP id 98e67ed59e1d1-38d9edafc8emr12968752a91.2.1784067888503; Tue, 14 Jul 2026 15:24:48 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:32cb:eed4:7c:dc87]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31189cd8234sm76540741eec.9.2026.07.14.15.24.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 15:24:47 -0700 (PDT) From: Douglas Anderson To: Jassi Brar Cc: Joonwon Kang , Subhash Jadavani , Tudor Ambarus , Lucas Wei , Brian Norris , Peter Griffin , =?UTF-8?q?Andr=C3=A9=20Draszik?= , Douglas Anderson , Conor Dooley , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH 6/7] dt-bindings: mailbox: goog-mba: Add goog-mba mailbox bindings Date: Tue, 14 Jul 2026 15:21:45 -0700 Message-ID: <20260714152138.6.Ia186a29119b4b5c409815b755e0c2c3965b0495f@changeid> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260714222338.2965707-1-dianders@chromium.org> References: <20260714222338.2965707-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce bindings for the MailBox Array IP block present in Laguna SoCs (AKA "lga", AKA "Google Tensor G5"). Signed-off-by: Douglas Anderson --- .../bindings/mailbox/google,mba.yaml | 216 ++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/google,mba.ya= ml diff --git a/Documentation/devicetree/bindings/mailbox/google,mba.yaml b/Do= cumentation/devicetree/bindings/mailbox/google,mba.yaml new file mode 100644 index 000000000000..6c4505a369e2 --- /dev/null +++ b/Documentation/devicetree/bindings/mailbox/google,mba.yaml @@ -0,0 +1,216 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright 2025 Google LLC +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mailbox/google,mba.yaml# +$schema: http://devicetree.org/meta-schemas/base.yaml# + +title: Google MailBox Array + +maintainers: + - Douglas Anderson + +description: | + The Google MailBox Array (MBA) is an IP block in Google-designed SoCs + starting in Laguna (AKA "lga", AKA Google Tensor G5). In a typical SoC + that includes this IP block, there are a number of instances of the MBA + controller with each instance having slightly different hardware + parameters and intended for communication with a different remote + processor. + + An MBA instance has a "host" that is defined as the processor "providing" + a "service". This is typically not the main Application Processor (AP) b= ut + is instead some specialized co-processor in the SoC like the Central Pow= er + Manager (CPM). A processor (like the AP) talking to the "host" of the MBA + is a "client" of the MBA. A given MBA instance only ever has one host, b= ut + it may have several clients. For instance, the CPM (an MBA "host") may n= eed + to send/receive mailbox messages not just from the AP but from other + processors in the SoC and each of these other processors can be "clients" + of the same MBA. + + The "host" of an MBA instance has full access to everything in the MBA + instance. It can access its own private set of "host" MBA registers, the + "global" MBA registers (if they exist), and all of the "client" MBA + registers. + + A "client" of an MBA instance has access to the "global" MBA registers (= if + they exist) and one or more sets of "client" MBA registers. + + These bindings are focused on describing the MBA from the point of view = of + a single client. + + As per above, a client may have access to several sets of MBA "client" + registers. Each set of "client" registers represents a logical mailbox + "channel". However, because each channel may have different configuration + parameters and a mailbox "channel" in typical usage means one of a number + of identical channels, each channel in a Google MailBox Array is typical= ly + referred to as a full "mailbox" and the whole collection of mailboxes as + the "mailbox array". + + Mailboxes in an MBA instance have these features: + * 1 to 256 32-bit words of shared memory. + * The ability for the client to ring the main doorbell of the host and be + notified when the host Acks the doorbell. + * The ability for the host to ring the main doorbell of the client and be + notified when the client Acks the doorbell. + + Some mailboxes may also have the ability to have counted doorbells. This + means that the receiver of the doorbell can tell how many times it rung. + This is intended for implementing "queued" mailboxes. See below. + + The MBA hardware doesn't have any specific directionality. That is to + say, both the host and the client have full read and write access to + their shared memory. All mailbox instances have doorbells going both from + the client to the host as well as the host to the client. + + The mailboxes can only be used for communication if the host and client + both agree on conventions. These conventions are described in the + device tree as they describe how the remote firmware is expecting to + communicate. + + Current known in-use conventions: + 1. An RX mailbox with payloads that are of a well-defined size. + On mailboxes of this type, the host is the only one to write shared + memory. After placing a fixed-size message in shared memory, it rings + the main doorbell of the client. The client reads the message and Acks + the doorbell. + 2. A TX mailbox with payloads that could vary in size. + On mailboxes of this type, the mailbox client is the only one to write + shared memory. The client always writes a payload to the start of sha= red + memory and rings the main host doorbell. The client then looks for the + host to Ack the doorbell. The clients of the mailbox have ways to know + the size of any given message. + 3. A half-duplex TX/RX mailbox. This is a mailbox that can switch between + convention #1 and #2 above. Since both sides write data to the start = of + shared memory, the two sides must have some convention to know whose + turn it is to send a message. + 4. A "queued" RX mailbox with a payload of a well-defined size. + This type of mailbox is only possible if the MBA instance can count + doorbells. On mailboxes of this type, the host is the only one to wri= te + shared memory. When the client doorbell rings, the client reads a + fixed-size from the next "slot" in shared memory and then updates its + internal state. The shared memory is treated as a circular queue. + 5. A "queued" TX mailbox with a payload of a well-defined size. + This type of mailbox is only possible if the MBA instance can count + doorbells. On mailboxes of this type, the mailbox client is the only = one + to write shared memory. The shared memory is treated as a circular qu= eue. + The client writes a fixed-sized payload to the next "slot" in the sha= red + memory (where the slot size is determined by the client's first trans= fer), + updates its internal state, and rings the host doorbell. The client c= an + keep writing more messages as long as the circular queue isn't full. = The + client gets an interrupt when the host Acks a doorbell and can tell h= ow + many doorbells still haven't been Acked. + + Conventions will be supported with a small number of properties specified + for each mailbox. + +properties: + compatible: + items: + - enum: + - google,lga-mailbox-array + - const: google,mailbox-array + + reg: + minItems: 1 + items: + - description: Host registers (not accessible to client) + - description: Global registers (not present on newer IP blocks) + + ranges: true + + "#address-cells": + const: 1 + + "#size-cells": + const: 1 + +patternProperties: + "^mailbox@[0-9a-f]+$": + type: object + description: + Each sub-node is a single-channel mailbox. + + properties: + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + "#mbox-cells": + const: 0 + + google,rx-payload-words: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 256 + default: 0 + description: + The number of 32-bit words in each mailbox message from the remo= te + processor. May be 0 for doorbell-only. If not specified this is + assumed to be 0. + + google,mba-queue-mode: + type: boolean + description: + The remote processor is expecting the shared memory to be treated + as a circular queue and that there may be several outstanding + messages at once. Only usable on instances with counted doorbell + interrupts. + + required: + - reg + - interrupts + - "#mbox-cells" + + additionalProperties: false + +required: + - compatible + - ranges + - reg + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + #include + + soc { + #address-cells =3D <2>; + #size-cells =3D <2>; + + cpm_ap_ns_mba: mailbox-array@5240000 { + compatible =3D "google,lga-mailbox-array", "google,mailbox-array"; + reg =3D <0x0 0x05240000 0x0 0x00010000>, + <0x0 0x05250000 0x0 0x00010000>; + ranges =3D <0x0 0x0 0x05260000 0x00020000>; + + #address-cells =3D <1>; + #size-cells =3D <1>; + + cpm_ap_ns_req_mba_client_0: mailbox@0 { + reg =3D <0x0000 0x1000>; + interrupts =3D ; + + #mbox-cells =3D <0>; + + google,mba-queue-mode; + }; + + cpm_ap_ns_resp_mba_client_1: mailbox@1000 { + reg =3D <0x1000 0x1000>; + interrupts =3D ; + + #mbox-cells =3D <0>; + + google,rx-payload-words =3D <4>; + google,mba-queue-mode; + }; + }; + }; + +... --=20 2.55.0.141.g00534a21ce-goog From nobody Sat Jul 25 18:53:39 2026 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1900E43441E for ; Tue, 14 Jul 2026 22:24:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067895; cv=none; b=lLrRAzfA1BYpytSoqrNlszk4kwSJfqc/bTHYbNljWc+jAP+bcoNTtJmUYSTwE2UGEODHlWQu6dGHh/Nixc/dzspIHAHGhFqR2hbnjrZReJMaAOBcsDT1YrMey2kjmM+Nle9KrddBjPzUb7j2DA/MaRGLC230tXcPDlHQYQ+PUYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784067895; c=relaxed/simple; bh=Ujy0XHkirJSJ3wGD92Jb4eJyERiKPRG4jijIky8EgcE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DYJ+Um2E+lMuSJCqkgp4knKEBgJ7SmWgcsF5vAKvHeYTSSDKahhWRpHls8V+e1FIm/Wth8F62hfgPm4MxYiJAI19QB9KhitJltN3Td33xFIJhtLYOzlb6WmjZuIOCeRTWKS3XD5+1lwAQ+D7MWdqkrNpTfErprTFXdmy2cZKzcs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=es80Ke0s; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="es80Ke0s" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-848643382fcso5404911b3a.1 for ; Tue, 14 Jul 2026 15:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1784067891; x=1784672691; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=RlvMMMAfe3VlNvLEnfKxJEvAH3Aa6/N0yJs40GrdW0o=; b=es80Ke0sWBdergolzPuWuiypivqM23mifcDZVldiML5LklcU9CiDktccBNpaqEcmg0 Q94NRhcfFwQzQYjpD4pZMylODwiTeFnjvf7U7MgOEivUZFsB2KwGY9rFe3RZWed2CwA3 3+Lxg7arRZNE/kTw53+RF3bKO2KCsU2oLX0FA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784067891; x=1784672691; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=RlvMMMAfe3VlNvLEnfKxJEvAH3Aa6/N0yJs40GrdW0o=; b=pGgW0zVYg01Bvohhoo7QPZYST+FHVQvbF+gHBJKcr3eE6+vTCp2oTCwVUftd842AGS yT9LaXcQjF/PBNpfX9sj14lcbVYot99V/NYaFGMrOv5e7lzF7jrZjqcUdOjr8JyId4w1 ccRTH1miBQy3XzstvUqQwSBj3Uxs2qwgA9gpCKwNoea10csIwNYcA5W9eKCnUSzStsIw PwAqS9WIgfwD7FrtVsBqP4JZ/6+0m3RRVQPKTS/BNamWFfw7C+mCfLUkjEv6CQ1MK9oh A++D9XYVzfKJyQ4FrMU0zhAlEjadkwK4j7tz1hSnudRJnao9X0W9Ra7NErOQs5MlB0Jk Vb9g== X-Forwarded-Encrypted: i=1; AHgh+Rpqxs69ODiiyxhsBRotH+EE1gUrz1AzexoXcjS08HlA6Q/q4qDHRCGo39CwlLt6JE07R6GG5gCJzI/5XF8=@vger.kernel.org X-Gm-Message-State: AOJu0YzPpX19YUZ1N83xO6/coHaz52dGrZcGcwYPP3zvHML2429164Qg 42BpGc59lCqlTxY4IFjNb+5gSsiUXsKJ6HJ4XEESRQhgjJTQv5fghYYDztVmgzSEIg== X-Gm-Gg: AfdE7cmVpBZWTkHDwjRYEhv+a6PI6MIzMc0PNNanLDhLbBHRVl96gFxgnDEscFIfBAC /hMNF7G0TXgaLSc/ULdAXIK/diCnSOjSRIMJCLmK+96LLL3JiSS3ngTdUaN5qR0zCWOLXAM9/8O ExJvR6ZuLoyrhnW71bhCEukTLt+NP5gXxh360s8MYKAbMK7E9BK59YEr6+VAvE5B3U/sflNJPM3 XOCCZDAPYMam10ktyeDnPgxweCLeVYuQPix06fqMbPc8DHAH4YKFPoD5MDOTpRVOAdppI61vcA7 q+Tlw+XjIx2YrMP1f0WULnMbKJb/eJ0wot8/FfhrmtdYdf204bpnTF7Yi7shznEkuTfDOfiYLlN KkA6uZU921oMUjO35mhYCyE6y12uws+24XNdSQt/IzMk+vcR5lS1D25wg3vNvnepgOJdW1yxjA4 2+G8aamzDRxmdq/z5kyKSlR5uFKjAiPbFYgeXUpopgVLqqR29TZyytgydA21PQQXVwuXV2bw== X-Received: by 2002:a05:6a21:6b83:b0:3bf:6c05:a6 with SMTP id adf61e73a8af0-3c34d880814mr6208792637.53.1784067891162; Tue, 14 Jul 2026 15:24:51 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:32cb:eed4:7c:dc87]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31189cd8234sm76540741eec.9.2026.07.14.15.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 15:24:49 -0700 (PDT) From: Douglas Anderson To: Jassi Brar Cc: Joonwon Kang , Subhash Jadavani , Tudor Ambarus , Lucas Wei , Brian Norris , Peter Griffin , =?UTF-8?q?Andr=C3=A9=20Draszik?= , Douglas Anderson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH 7/7] mailbox: goog-mba: Introduce the goog-mba mailbox driver Date: Tue, 14 Jul 2026 15:21:46 -0700 Message-ID: <20260714152138.7.I5cef580a62c86ba6c3465ad336fa509afbdf1476@changeid> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260714222338.2965707-1-dianders@chromium.org> References: <20260714222338.2965707-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Add a driver for the MailBox Array IP block present in Laguna SoCs (AKA "lga", AKA "Google Tensor G5"). The mailbox hardware and theory of operation is described in detail in the devicetree bindings. This driver requires two improvements to the mailbox core in order to function properly. Notably: * mailbox: Add support for mailbox controllers that can queue * mailbox: Find a matching mailbox by fwnode rather than device The goog-mba hardware and conventions used to communicate to remote processors is described in detail in the bindings file. See the bindings patch ("dt-bindings: mailbox: goog-mba: Add goog-mba mailbox bindings"). Signed-off-by: Douglas Anderson --- This driver is a rewrite from the downstream driver used in Pixel phones and thus is only lightly tested. The downstream driver needed to jump through some awkward hoops in order to work around the above two patches not being present in the mailbox core. MAINTAINERS | 8 + drivers/mailbox/Kconfig | 8 + drivers/mailbox/Makefile | 2 + drivers/mailbox/goog-mba-priv.h | 108 +++++ drivers/mailbox/goog-mba-trace.h | 183 ++++++++ drivers/mailbox/goog-mba.c | 567 +++++++++++++++++++++++ include/linux/mailbox/goog-mba-message.h | 38 ++ 7 files changed, 914 insertions(+) create mode 100644 drivers/mailbox/goog-mba-priv.h create mode 100644 drivers/mailbox/goog-mba-trace.h create mode 100644 drivers/mailbox/goog-mba.c create mode 100644 include/linux/mailbox/goog-mba-message.h diff --git a/MAINTAINERS b/MAINTAINERS index f37a81950e25..09da5b3a0e86 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11070,6 +11070,14 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/g= it/chrome-platform/linux.git F: drivers/firmware/google/ F: include/linux/coreboot.h =20 +GOOGLE MAILBOX ARRAY +M: Douglas Anderson +L: linux-kernel@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/mailbox/google,mba.yaml +F: drivers/mailbox/goog-mba* +F: include/linux/mailbox/goog-mba-message.h + GOOGLE TENSOR SoC SUPPORT M: Peter Griffin R: Andr=C3=A9 Draszik diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index 3062ee352f78..ddd08e473b57 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -399,4 +399,12 @@ config RISCV_SBI_MPXY_MBOX or HS-mode hypervisor). Say Y here, unless you are sure you do not need this. =20 +config GOOG_MBA_MBOX + tristate "Google Tensor MBA Mailbox" + help + An implementation of the Google MailBox Array (MBA) driver present in + Google Tensor SoCs starting with Laguna (G5). It is used for + inter-processor communication between the application processor and + co-processors. + endif diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index 944d8ea39f34..56b18641f50e 100644 --- a/drivers/mailbox/Makefile +++ b/drivers/mailbox/Makefile @@ -84,3 +84,5 @@ obj-$(CONFIG_CIX_MBOX) +=3D cix-mailbox.o obj-$(CONFIG_BCM74110_MAILBOX) +=3D bcm74110-mailbox.o =20 obj-$(CONFIG_RISCV_SBI_MPXY_MBOX) +=3D riscv-sbi-mpxy-mbox.o + +obj-$(CONFIG_GOOG_MBA_MBOX) +=3D goog-mba.o diff --git a/drivers/mailbox/goog-mba-priv.h b/drivers/mailbox/goog-mba-pri= v.h new file mode 100644 index 000000000000..bfe03993a7d4 --- /dev/null +++ b/drivers/mailbox/goog-mba-priv.h @@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2025 Google LLC + */ + +#ifndef _GOOG_MBA_PRIV_H_ +#define _GOOG_MBA_PRIV_H_ + +#include + +struct goog_mbox_info { + /** @mbox: Mailbox controller structure. */ + struct mbox_controller mbox; + + /** @np: Device tree node */ + struct device_node *np; + + /** @chan: Mailbox channel structure; only 1 channel per mailbox. */ + struct mbox_chan chan; + + /** @mba: Pointer to the mailbox array containing this mailbox. */ + struct goog_mba_info *mba; + + /** @iomem: IO memory associated with this mailbox. */ + void __iomem *iomem; + + /** @irq: Linux IRQ associated with this mailbox. */ + int irq; + + /** @msg_buffer_words: Number of 32-bit words present in hardware. */ + unsigned int msg_buffer_words; + + /** + * @tx_payload_words: Number of 32-bit words in a tx mailbox message. + * + * In queue mode this is detected on the first TX transfer and subsequent + * transfers must match. + */ + unsigned int tx_payload_words; + + /** @rx_payload_words: Number of 32-bit words in a rx mailbox message. */ + unsigned int rx_payload_words; + + /** + * @rx_buffer: Memory storage for payload when receiving + * + * When we get a message from the other side we copy it here before + * acknowledging the message and passing it to the client. Buffer + * is `payload_words * 4` bytes big. + */ + u32 *rx_buffer; + + /** + * @queue_mode: If true, the other side uses the "queue mode" protocol. + * + * In the "queue mode" protocol, we can send more than one message at + * once and we treat the message buffer like a circular queue, with + * each entry being `payload_words` big. + */ + bool queue_mode; + + + /* QUEUE MODE ONLY BELOW */ + + /** + * @tx_idx: For queue mode, index into msg buffer to write the next msg. + * + * Always between 0 and msg_buffer_words - 1. Increments by payload_words + * after each transmission and wraps to 0 if it's =3D=3D msg_buffer_words. + */ + unsigned int tx_idx; + + /** + * @rx_idx: For queue mode, index into msg buffer to read the next msg. + * + * Always between 0 and msg_buffer_words - 1. Increments by rx_payload_wo= rds + * after each reception and wraps to 0 if it's =3D=3D msg_buffer_words. + */ + unsigned int rx_idx; + + /** + * @lock: For queue mode, protects outstanding_msgs + * + * We update `outstanding_msgs` in the interrupt handler and when + * queuing up a message. This protects those two accesses. + */ + spinlock_t lock; + + /** + * @outstanding_msgs: For queue mode, num msgs we've written but not acked + * + * After we start each transmission we grab the `lock` and increment + * this by 1. In the interrupt handler when we see that some messages + * were transferred we decrease this and send out the proper number + * of acks. + */ + unsigned int outstanding_msgs; +}; + +struct goog_mba_info { + /** @dev: Pointer to the `struct device` */ + struct device *dev; + + /** @global_iomem: Pointer to global IO memory, or NULL */ + void __iomem *global_iomem; +}; + +#endif /* _GOOG_MBA_PRIV_H_ */ diff --git a/drivers/mailbox/goog-mba-trace.h b/drivers/mailbox/goog-mba-tr= ace.h new file mode 100644 index 000000000000..02be79757fcb --- /dev/null +++ b/drivers/mailbox/goog-mba-trace.h @@ -0,0 +1,183 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM goog_mba + +#if !defined(_GOOG_MBA_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) +#define _GOOG_MBA_TRACE_H + +#include + +#include "goog-mba-priv.h" + +TRACE_EVENT( + goog_mba_process_nq_txdone, + + TP_PROTO(const struct goog_mbox_info *goog_mbox), + + TP_ARGS(goog_mbox), + + TP_STRUCT__entry( + __string(dev_name, dev_name(goog_mbox->mba->dev)) + __string(name, goog_mbox->np->full_name) + ), + + TP_fast_assign( + __assign_str(dev_name); + __assign_str(name); + ), + + TP_printk("%s %s", __get_str(dev_name), __get_str(name)) +); + +TRACE_EVENT( + goog_mba_process_q_txdone, + + TP_PROTO(const struct goog_mbox_info *goog_mbox, u32 reqs_completed, u32 = outstanding_msgs), + + TP_ARGS(goog_mbox, reqs_completed, outstanding_msgs), + + TP_STRUCT__entry( + __string(dev_name, dev_name(goog_mbox->mba->dev)) + __string(name, goog_mbox->np->full_name) + __field(u32, outstanding_msgs) + __field(u32, reqs_completed) + ), + + TP_fast_assign( + __assign_str(dev_name); + __assign_str(name); + __entry->outstanding_msgs =3D outstanding_msgs; + __entry->reqs_completed =3D reqs_completed; + ), + + TP_printk("%s %s: reqs_completed=3D%u outstanding_msgs=3D%u", + __get_str(dev_name), __get_str(name), __entry->reqs_completed, + __entry->outstanding_msgs) +); + +TRACE_EVENT( + goog_mba_send_data_nq, + + TP_PROTO(const struct goog_mbox_info *goog_mbox, const u32 *payload, + unsigned int payload_words), + + TP_ARGS(goog_mbox, payload, payload_words), + + TP_STRUCT__entry( + __string(dev_name, dev_name(goog_mbox->mba->dev)) + __string(name, goog_mbox->np->full_name) + __field(u32, payload_words) + __dynamic_array(u32, payload, payload_words) + ), + + TP_fast_assign( + __assign_str(dev_name); + __assign_str(name); + __entry->payload_words =3D payload_words; + memcpy(__get_dynamic_array(payload), payload, + payload_words * sizeof(u32)); + ), + + TP_printk("%s %s: data=3D%s", + __get_str(dev_name), __get_str(name), + __print_array(__get_dynamic_array(payload), + __entry->payload_words, sizeof(u32))) +); + +TRACE_EVENT( + goog_mba_send_data_q, + + TP_PROTO(const struct goog_mbox_info *goog_mbox, const u32 *payload, + unsigned int payload_words), + + TP_ARGS(goog_mbox, payload, payload_words), + + TP_STRUCT__entry( + __string(dev_name, dev_name(goog_mbox->mba->dev)) + __string(name, goog_mbox->np->full_name) + __field(u32, tx_idx) + __field(u32, payload_words) + __dynamic_array(u32, payload, payload_words) + ), + + TP_fast_assign( + __assign_str(dev_name); + __assign_str(name); + __entry->tx_idx =3D goog_mbox->tx_idx; + __entry->payload_words =3D payload_words; + memcpy(__get_dynamic_array(payload), payload, + payload_words * sizeof(u32)); + ), + + TP_printk("%s %s: tx_idx=3D%u data=3D%s", + __get_str(dev_name), __get_str(name), __entry->tx_idx, + __print_array(__get_dynamic_array(payload), + __entry->payload_words, sizeof(u32))) +); + +TRACE_EVENT( + goog_mba_process_nq_rx, + + TP_PROTO(const struct goog_mbox_info *goog_mbox), + + TP_ARGS(goog_mbox), + + TP_STRUCT__entry( + __string(dev_name, dev_name(goog_mbox->mba->dev)) + __string(name, goog_mbox->np->full_name) + __field(u32, rx_payload_words) + __dynamic_array(u32, payload, goog_mbox->rx_payload_words) + ), + + TP_fast_assign( + __assign_str(dev_name); + __assign_str(name); + __entry->rx_payload_words =3D goog_mbox->rx_payload_words; + memcpy(__get_dynamic_array(payload), goog_mbox->rx_buffer, + goog_mbox->rx_payload_words * sizeof(u32)); + ), + + TP_printk("%s %s: data=3D%s", + __get_str(dev_name), __get_str(name), + __print_array(__get_dynamic_array(payload), + __entry->rx_payload_words, sizeof(u32))) +); + +TRACE_EVENT( + goog_mba_process_q_rx, + + TP_PROTO(const struct goog_mbox_info *goog_mbox), + + TP_ARGS(goog_mbox), + + TP_STRUCT__entry( + __string(dev_name, dev_name(goog_mbox->mba->dev)) + __string(name, goog_mbox->np->full_name) + __field(u32, rx_idx) + __field(u32, rx_payload_words) + __dynamic_array(u32, payload, goog_mbox->rx_payload_words) + ), + + TP_fast_assign( + __assign_str(dev_name); + __assign_str(name); + __entry->rx_idx =3D goog_mbox->rx_idx; + __entry->rx_payload_words =3D goog_mbox->rx_payload_words; + memcpy(__get_dynamic_array(payload), goog_mbox->rx_buffer, + goog_mbox->rx_payload_words * sizeof(u32)); + ), + + TP_printk("%s %s: rx_idx=3D%u data=3D%s", + __get_str(dev_name), __get_str(name), __entry->rx_idx, + __print_array(__get_dynamic_array(payload), + __entry->rx_payload_words, sizeof(u32))) +); + +#endif /* _GOOG_MBA_TRACE_H */ + +/* This part must be outside protection */ +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH ../drivers/mailbox +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE goog-mba-trace +#include diff --git a/drivers/mailbox/goog-mba.c b/drivers/mailbox/goog-mba.c new file mode 100644 index 000000000000..54b6ed787b71 --- /dev/null +++ b/drivers/mailbox/goog-mba.c @@ -0,0 +1,567 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Google MailBox Array (MBA) Driver + * + * Copyright (c) 2025 Google LLC + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "goog-mba-priv.h" + +#define CREATE_TRACE_POINTS +#include "goog-mba-trace.h" + +#define CLIENT_IRQ_TRIG_OFFSET 0x0 +#define SET_HOST_IRQ 0x1 + +#define CLIENT_IRQ_CONFIG_OFFSET 0x4 +#define ENABLE_HOST_AUTO_ACK BIT(8) +#define CLIENT_IRQ_MASK_MSG_INT BIT(16) +#define CLIENT_IRQ_MASK_ACK_INT BIT(24) + +#define CLIENT_IRQ_STATUS_OFFSET 0x8 +#define CLIENT_IRQ_STATUS_MSG_INT 0x1 +#define CLIENT_IRQ_STATUS_ACK_INT 0x100 + +#define CLIENT_MBA_IP_VER 0x30 +#define CLIENT_NUM_MSG_REG 0x34 +#define CLIENT_OUTSTANDING_MSG 0x10 + +#define GLOBAL_NUM_MSG_REG_OFFSET(x) (0x10 + ((x) * 4)) +#define GLOBAL_MBA_IP_VER_OFFSET 4 + +#define CLIENT_CLIENT_DOORBELL_TRIG 0x20 +#define CLIENT_DOORBELL_MASK_OFFSET 0x24 +#define CLIENT_DOORBELL_STATUS_OFFSET 0x28 +#define CLIENT_HOST_DOORBELL_OFFSET 0x38 +#define CLIENT_CLIENT_DOORBELL_OFFSET 0x3c + +#define MAX_MBA_CHANNELS 1 +#define NR_PHANDLE_ARG_COUNT 1 + +#define MSG_OFFSET(i) (0x100 + (i) * sizeof(u32)) + +#define MBA_IP_MAJOR_VER_1 0x1 +#define MBA_IP_MAJOR_VER_3 0x3 + +#define MBA_IP_MAJOR_VER_SHIFT 24 +#define MBA_IP_MAJOR_VER_MASK 0xff +#define MBA_IP_MINOR_VER_SHIFT 16 +#define MBA_IP_MINOR_VER_MASK 0xff +#define MBA_IP_INCREMENTAL_VER_SHIFT 0 +#define MBA_IP_INCREMENTAL_VER_MASK 0xffff + +/** + * goog_mba_handle_tx_interrupt() - Handle interrupt that remote Acked our= msg. + * @goog_mbox: The mailbox info. + */ +static void goog_mba_handle_tx_interrupt(struct goog_mbox_info *goog_mbox) +{ + unsigned int reqs_completed; + int i; + + /* + * ACK interrupt needs to be cleared before reading CLIENT_OUTSTANDING_MS= G. + * Then if a "race" happens and another message gets Acked after we clear + * but before we read CLIENT_OUTSTANDING_MSG then the worst that will + * happen is we'll get a followup interrupt that will show 0 reqs_complet= ed. + */ + writel(CLIENT_IRQ_STATUS_ACK_INT, goog_mbox->iomem + CLIENT_IRQ_STATUS_OF= FSET); + + if (goog_mbox->queue_mode) { + u32 outstanding_msgs; + + outstanding_msgs =3D readl(goog_mbox->iomem + CLIENT_OUTSTANDING_MSG); + spin_lock(&goog_mbox->lock); + + if (goog_mbox->outstanding_msgs >=3D outstanding_msgs) { + reqs_completed =3D goog_mbox->outstanding_msgs - outstanding_msgs; + } else { + /* + * The hardware's track of outstanding messages should always + * be less than or equal to the number of messages we queued. + * If it thinks there are more messages outstanding than we + * queued, something is wrong. Assume nothing was completed. + */ + dev_warn_ratelimited(goog_mbox->mba->dev, + "%pOFP: unexpected outstanding msgs: %u -> %u\n", + goog_mbox->np, goog_mbox->outstanding_msgs, + outstanding_msgs); + reqs_completed =3D 0; + } + goog_mbox->outstanding_msgs =3D outstanding_msgs; + spin_unlock(&goog_mbox->lock); + + trace_goog_mba_process_q_txdone(goog_mbox, reqs_completed, outstanding_m= sgs); + } else { + reqs_completed =3D 1; + trace_goog_mba_process_nq_txdone(goog_mbox); + } + + for (i =3D 0; i < reqs_completed; i++) + mbox_chan_txdone(&goog_mbox->chan, 0); +} + +/** + * goog_mba_handle_rx_interrupt() - Handle interrupt that remote send a ms= g. + * @goog_mbox: The mailbox info. + */ +static void goog_mba_handle_rx_interrupt(struct goog_mbox_info *goog_mbox) +{ + struct goog_mba_rx_msg msg =3D { + .payload =3D goog_mbox->rx_buffer, + .payload_words =3D goog_mbox->rx_payload_words, + }; + int i; + + for (i =3D 0; i < goog_mbox->rx_payload_words; i++) + goog_mbox->rx_buffer[i] =3D readl(goog_mbox->iomem + + MSG_OFFSET(goog_mbox->rx_idx + i)); + + if (goog_mbox->queue_mode) { + goog_mbox->rx_idx =3D (goog_mbox->rx_idx + goog_mbox->rx_payload_words) % + goog_mbox->msg_buffer_words; + trace_goog_mba_process_q_rx(goog_mbox); + } else { + trace_goog_mba_process_nq_rx(goog_mbox); + } + + /* + * Ack the interrupt after we've read the message to local memory but + * before passing it to the client. This frees up space for the remote + * processor to send another message as the client is processing this one. + */ + writel(CLIENT_IRQ_STATUS_MSG_INT, goog_mbox->iomem + CLIENT_IRQ_STATUS_OF= FSET); + + mbox_chan_received_data(&goog_mbox->chan, &msg); +} + +/** + * goog_mba_isr() - Main interrupt routine + * @irq: The IRQ number. + * @data: Data passed when registering (the goog_mbox_info for this IRQ). + * + * Return: IRQ_HANDLED if IRQ was handled; IRQ_NONE if no interrupt was fo= und. + */ +static irqreturn_t goog_mba_isr(int irq, void *data) +{ + struct goog_mbox_info *goog_mbox =3D data; + u32 irq_status; + + irq_status =3D readl(goog_mbox->iomem + CLIENT_IRQ_STATUS_OFFSET); + if (!irq_status) + return IRQ_NONE; + + while (true) { + if (irq_status & CLIENT_IRQ_STATUS_ACK_INT) + goog_mba_handle_tx_interrupt(goog_mbox); + + if (irq_status & CLIENT_IRQ_STATUS_MSG_INT) { + goog_mba_handle_rx_interrupt(goog_mbox); + + /* + * In queue mode the RX interrupt will re-assert itself + * right after we clear it if there is more than one + * message waiting. As an optimization to avoid returning + * and immediately re-triggering our interrupt, re-check. + * + * NOTE: we don't need to loop for the TX (Ack) case + * since TX interrupts aren't counted in the same way. + */ + if (goog_mbox->queue_mode) + irq_status =3D readl(goog_mbox->iomem + CLIENT_IRQ_STATUS_OFFSET); + else + break; + } else { + break; + } + } + + return IRQ_HANDLED; +} + +/** + * goog_mba_send_data() - Mailbox op for send_data. + * @chan: The Linux mbox_chan structure associated with the mailbox. + * @msg: The mailbox message, expected to be of type `struct goog_mba_tx_m= sg`. + * If NULL, we'll assume a 0-byte doorbell-only message. + * + * Return: 0 if the data was sent; -EBUSY if the queue was full; other + * negative error values for other problems. + */ +static int goog_mba_send_data(struct mbox_chan *chan, void *msg) +{ + struct goog_mbox_info *goog_mbox =3D chan->con_priv; + struct device *dev =3D goog_mbox->mba->dev; + bool queue_mode =3D goog_mbox->queue_mode; + unsigned int payload_words =3D 0; + const u32 *payload =3D NULL; + bool is_init =3D false; + unsigned int tx_idx; + unsigned int i; + unsigned long flags; + + if (msg) { + struct goog_mba_tx_msg *mba_msg =3D msg; + + payload_words =3D mba_msg->payload_words; + payload =3D mba_msg->payload; + is_init =3D mba_msg->init; + } + + if (payload_words > goog_mbox->msg_buffer_words) { + dev_err(dev, "%pOFP: Payload too big: %u > %u\n", + goog_mbox->np, payload_words, goog_mbox->msg_buffer_words); + return -EINVAL; + } + + /* + * Currently all queue-mode transfers need to be the same size and + * need to evenly divide the message buffer. If this is the first + * transfer, we need to validate/store the payload_words. For subsequent + * transfers we just need to confirm it hasn't changed. + */ + if (queue_mode) { + if (!goog_mbox->tx_payload_words && payload_words) { + if (goog_mbox->msg_buffer_words % payload_words !=3D 0) { + dev_err(dev, "%pOFP: Invalid initial TX queue payload words: %u\n", + goog_mbox->np, payload_words); + return -EINVAL; + } + goog_mbox->tx_payload_words =3D payload_words; + } else if (payload_words !=3D goog_mbox->tx_payload_words) { + dev_err(dev, "%pOFP: Payload size mismatch: %u vs %u\n", + goog_mbox->np, payload_words, goog_mbox->tx_payload_words); + return -EINVAL; + } + } + + /* + * HW can handle full duplex but there is no current scheme for dividing + * up the message buffer between TX and RX portions. Non-queue mode + * could work half-duplex, but that doesn't make sense in queue mode. + * If space is reserved for RX then disallow using it for TX. + */ + if (queue_mode && payload_words && goog_mbox->rx_payload_words) { + dev_err(dev, "%pOFP: Can't TX if buffer is used for RX\n", goog_mbox->np= ); + return -EINVAL; + } + + if (queue_mode) { + bool out_of_space; + + spin_lock_irqsave(&goog_mbox->lock, flags); + out_of_space =3D payload_words && + (goog_mbox->outstanding_msgs >=3D + goog_mbox->msg_buffer_words / payload_words); + spin_unlock_irqrestore(&goog_mbox->lock, flags); + + /* + * IMPORTANT: don't print an error for this. It's normal and + * expected that the core will keep trying to queue messages + * until the controller reports -EBUSY. + */ + if (out_of_space) + return -EBUSY; + + tx_idx =3D goog_mbox->tx_idx; + trace_goog_mba_send_data_q(goog_mbox, payload, payload_words); + } else { + tx_idx =3D 0; + trace_goog_mba_send_data_nq(goog_mbox, payload, payload_words); + } + + for (i =3D 0; i < payload_words; i++) + writel(payload[i], goog_mbox->iomem + MSG_OFFSET(tx_idx + i)); + + if (queue_mode) { + if (is_init) + goog_mbox->tx_idx =3D 0; + else + goog_mbox->tx_idx =3D (goog_mbox->tx_idx + payload_words) % + goog_mbox->msg_buffer_words; + } + + /* + * We need to be careful on how we deal with `outstanding_msgs`. + * The hardware will give us an interrupt every time it transfers + * a message, but if it transfers two messages before our interrupt + * handler fires then we'll still only get one interrupt. We have + * to look at the difference between the hardware's idea of + * `outstanding_msgs` and ours to figure out how many messages were + * actually transferred. + * + * We need to start the transfer and increment our concept of + * `outstanding_msgs` in lockstep so protect against the interrupt + * handler also touching `outstanding_msgs`. + */ + if (queue_mode) + spin_lock_irqsave(&goog_mbox->lock, flags); + + writel(SET_HOST_IRQ, goog_mbox->iomem + CLIENT_IRQ_TRIG_OFFSET); + + if (queue_mode) { + goog_mbox->outstanding_msgs++; + spin_unlock_irqrestore(&goog_mbox->lock, flags); + } + + return 0; +} + +/** + * goog_mba_startup() - Mailbox op for startup. + * @chan: The Linux mbox_chan structure associated with the mailbox. + * + * Return: 0 for OK; negative error code if problems. + */ +static int goog_mba_startup(struct mbox_chan *chan) +{ + struct goog_mbox_info *goog_mbox =3D chan->con_priv; + + writel(ENABLE_HOST_AUTO_ACK | CLIENT_IRQ_MASK_MSG_INT | CLIENT_IRQ_MASK_A= CK_INT, + goog_mbox->iomem + CLIENT_IRQ_CONFIG_OFFSET); + enable_irq(goog_mbox->irq); + + return 0; +} + +/** + * goog_mba_shutdown() - Mailbox op for shutdown. + * @chan: The Linux mbox_chan structure associated with the mailbox. + */ +static void goog_mba_shutdown(struct mbox_chan *chan) +{ + struct goog_mbox_info *goog_mbox =3D chan->con_priv; + + disable_irq(goog_mbox->irq); + writel(0x0, goog_mbox->iomem + CLIENT_IRQ_CONFIG_OFFSET); +} + +static const struct mbox_chan_ops goog_mba_chan_ops =3D { + .send_data =3D goog_mba_send_data, + .startup =3D goog_mba_startup, + .shutdown =3D goog_mba_shutdown, +}; + +/** + * goog_mba_get_msg_buf_words() - Return # msg buffer words in HW for this= mailbox. + * @goog_mbox: The mailbox info. + * @np: The device tree node associated with this mailbox. + * + * Return: The number of 32-bit words in the hardware message buffer. + */ +static unsigned int goog_mba_get_msg_buf_words(struct goog_mbox_info *goog= _mbox, + struct device_node *np) +{ + struct goog_mba_info *mba =3D goog_mbox->mba; + struct resource res; + unsigned int index; + + /* + * On newer IP there's no global space and the register moved to the + * client address space. + */ + if (!mba->global_iomem) + return readl(goog_mbox->iomem + CLIENT_NUM_MSG_REG); + + /* + * On older IP we need to find the index so we can look up the value + * in the global memory. Our index is based on the physical address + * of the mbox since on older hardware mailboxes are 4K apart. + */ + if (of_address_to_resource(np, 0, &res)) { + dev_err(mba->dev, "%pOFP: Failed to find physical address\n", np); + return 0; + } + index =3D (res.start & 0x1ffff) / 0x1000; + + return readl(mba->global_iomem + GLOBAL_NUM_MSG_REG_OFFSET(index)); +} + +/** + * of_node_put_void() - of_node_put() for passing to devm_add_action_or_re= set(). + * @data: Our struct device_node pointer. + */ +static void of_node_put_void(void *data) +{ + of_node_put(data); +} + +/** + * goog_mba_mbox_init() - Initialize one single mailbox. + * @goog_mbox: The mailbox info. + * @mba: The array containing this mailbox. + * @np: The device tree node associated with this mailbox. + * + * Return: 0 or a negative error code. If an error is returned, the error = has + * already been logged. + */ +static int goog_mba_mbox_init(struct goog_mbox_info *goog_mbox, + struct goog_mba_info *mba, struct device_node *np) +{ + struct mbox_controller *mbox =3D &goog_mbox->mbox; + struct mbox_chan *chan =3D &goog_mbox->chan; + struct device *dev =3D mba->dev; + unsigned int msg_buffer_words; + u32 rx_payload_words; + int ret; + + goog_mbox->mba =3D mba; + + of_node_get(np); + ret =3D devm_add_action_or_reset(dev, of_node_put_void, np); + if (ret) + return ret; + goog_mbox->np =3D np; + + goog_mbox->iomem =3D devm_of_iomap(dev, np, 0, NULL); + if (IS_ERR(goog_mbox->iomem)) + return dev_err_probe(dev, PTR_ERR(goog_mbox->iomem), + "%pOFP: Failed to map memory\n", np); + + /* Start with all interrupts disabled and cleared */ + writel(0x0, goog_mbox->iomem + CLIENT_IRQ_CONFIG_OFFSET); + writel(CLIENT_IRQ_STATUS_MSG_INT | CLIENT_IRQ_STATUS_ACK_INT, + goog_mbox->iomem + CLIENT_IRQ_STATUS_OFFSET); + + goog_mbox->irq =3D of_irq_get(np, 0); + if (goog_mbox->irq <=3D 0) { + if (goog_mbox->irq =3D=3D 0) + goog_mbox->irq =3D -EINVAL; + return dev_err_probe(dev, goog_mbox->irq, "%pOFP: Failed to get IRQ\n", = np); + } + ret =3D devm_request_irq(dev, goog_mbox->irq, goog_mba_isr, + IRQF_NO_SUSPEND | IRQF_NO_AUTOEN, + NULL, goog_mbox); + if (ret) + return dev_err_probe(dev, ret, "%pOFP: Failed to request interrupt\n", n= p); + + goog_mbox->queue_mode =3D of_property_read_bool(np, "google,mba-queue-mod= e"); + + rx_payload_words =3D 0; + ret =3D of_property_read_u32(np, "google,rx-payload-words", &rx_payload_w= ords); + goog_mbox->rx_payload_words =3D rx_payload_words; + + msg_buffer_words =3D goog_mba_get_msg_buf_words(goog_mbox, np); + goog_mbox->msg_buffer_words =3D msg_buffer_words; + + if (goog_mbox->queue_mode && !msg_buffer_words) + return dev_err_probe(dev, -EINVAL, + "%pOFP: Queue mode requires non-zero buffer\n", np); + + if (msg_buffer_words < rx_payload_words) + return dev_err_probe(dev, -EINVAL, + "%pOFP: Buffer (%u) < RX Payload (%u)\n", + np, msg_buffer_words, rx_payload_words); + if (goog_mbox->queue_mode && rx_payload_words && msg_buffer_words % rx_pa= yload_words !=3D 0) + return dev_err_probe(dev, -EINVAL, + "%pOFP: Queue buffer (%u) must be multiple of RX payload (%u)\n", + np, msg_buffer_words, rx_payload_words); + + if (rx_payload_words) { + goog_mbox->rx_buffer =3D devm_kcalloc(dev, rx_payload_words, + sizeof(*goog_mbox->rx_buffer), GFP_KERNEL); + if (!goog_mbox->rx_buffer) + return -ENOMEM; + } + + mbox->fwnode =3D of_fwnode_handle(np); + mbox->dev =3D dev; + mbox->ops =3D &goog_mba_chan_ops; + mbox->chans =3D chan; + mbox->num_chans =3D 1; + mbox->txdone_irq =3D true; + mbox->has_queue =3D goog_mbox->queue_mode; + spin_lock_init(&goog_mbox->lock); + + chan->con_priv =3D goog_mbox; + + ret =3D devm_mbox_controller_register(dev, mbox); + if (ret) + return dev_err_probe(dev, ret, + "%pOFP: Failed to register mailbox controller\n", np); + + return 0; +} + +/** + * goog_mba_probe() - MBA probe routine. + * @pdev: Our platform device. + * + * Return: 0 or a negative error code. + */ +static int goog_mba_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct goog_mbox_info *goog_mboxes; + struct goog_mba_info *mba; + unsigned int num_mboxes; + unsigned int i; + int ret; + + mba =3D devm_kzalloc(dev, sizeof(*mba), GFP_KERNEL); + if (!mba) + return -ENOMEM; + mba->dev =3D dev; + + num_mboxes =3D of_get_available_child_count(dev->of_node); + goog_mboxes =3D devm_kzalloc(dev, sizeof(*goog_mboxes) * num_mboxes, GFP_= KERNEL); + if (!goog_mboxes) + return -ENOMEM; + + /* + * The first memory range is the memory range that the other side + * of the mailbox uses. The second memory range is the shared/global + * range. Note that newer versions of the IP don't have the global + * range, so mba->global_iomem is left NULL on newer IP. + */ + if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) { + mba->global_iomem =3D devm_platform_ioremap_resource(pdev, 1); + if (IS_ERR(mba->global_iomem)) + return dev_err_probe(dev, PTR_ERR(mba->global_iomem), + "Failed to iomap global region\n"); + } + + i =3D 0; + for_each_available_child_of_node_scoped(dev->of_node, child_np) { + ret =3D goog_mba_mbox_init(&goog_mboxes[i], mba, child_np); + if (ret) + return ret; + i++; + } + + return 0; +} + +static const struct of_device_id goog_mba_match[] =3D { + { .compatible =3D "google,mailbox-array" }, + { /* Sentinel */ } +}; +MODULE_DEVICE_TABLE(of, goog_mba_match); + +static struct platform_driver mba =3D { + .driver =3D { + .name =3D "goog-mba", + .of_match_table =3D goog_mba_match, + }, + .probe =3D goog_mba_probe, +}; + +module_platform_driver(mba); + +MODULE_DESCRIPTION("Google MailBox Array (MBA) Driver"); +MODULE_AUTHOR("Douglas Anderson "); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mailbox/goog-mba-message.h b/include/linux/mailb= ox/goog-mba-message.h new file mode 100644 index 000000000000..5c3d47e3ded3 --- /dev/null +++ b/include/linux/mailbox/goog-mba-message.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Google MailBox Array (MBA) Mailbox Message + * + * Copyright (c) 2025 Google LLC + */ + +#ifndef _LINUX_MAILBOX_GOOG_MBA_MESSAGE_H_ +#define _LINUX_MAILBOX_GOOG_MBA_MESSAGE_H_ + +#include + +struct goog_mba_tx_msg { + /** @payload: The contents of the message to send. */ + const u32 *payload; + + /** @payload_words: The number of 32-bit words in the payload. */ + u8 payload_words; + + /** + * @init: Initialize queue settings after sending. + * + * Tell the mailbox driver that this is a special "initialize" + * message for a queue-based mailbox. This allows the mailbox driver + * to keep its state synced with the remote side of the mailbox. + */ + bool init; +}; + +struct goog_mba_rx_msg { + /** @payload: The contents of the message received. */ + const u32 *payload; + + /** @payload_words: The number of 32-bit words in the payload. */ + u8 payload_words; +}; + +#endif /* _LINUX_MAILBOX_GOOG_MBA_MESSAGE_H_ */ --=20 2.55.0.141.g00534a21ce-goog