[PATCH v5 4/5] firmware: tegra: bpmp: Add MBWT BPMP helpers

From: Aniruddha Rao

Date: Tue Sep 29 2026 - 06:05:03 EST


Add helper functions that send MBWT requests to BPMP firmware.

The helpers implement the GET_BW and SET_BW operations.

They also provide a QUERY_ABI-based probe for command availability.

Signed-off-by: Aniruddha Rao <anrao@xxxxxxxxxx>
---
Changes since v4:
- No change.

Changes since v3:
- No change.

Changes since v2:
- Move the MBWT helpers near probe.
- Explain why the MBWT helpers are needed in the commit message.

Changes since v1:
- Use generic MBWT helper names.
- Fold the MBWT helpers into bpmp.c.
- Drop MBWT Kconfig dependencies.
- Add firmware error handling for MBWT requests.

drivers/firmware/tegra/bpmp-private.h | 7 ++
drivers/firmware/tegra/bpmp.c | 111 +++++++++++++++++++++++++-
2 files changed, 117 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/tegra/bpmp-private.h b/drivers/firmware/tegra/bpmp-private.h
index 163b1c82d445..f0a7d6254bdc 100644
--- a/drivers/firmware/tegra/bpmp-private.h
+++ b/drivers/firmware/tegra/bpmp-private.h
@@ -32,4 +32,11 @@ int tegra_bpmp_init_ping(struct tegra_bpmp *bpmp);
void tegra_bpmp_deinit_ping(struct tegra_bpmp *bpmp);
int tegra_bpmp_init_dt_providers(struct tegra_bpmp *bpmp);

+bool tegra_bpmp_mbwt_cmd_is_supported(struct tegra_bpmp *bpmp,
+ unsigned int cmd_code);
+int tegra_bpmp_mbwt_get(struct tegra_bpmp *bpmp, unsigned int instance,
+ unsigned int vc_type, unsigned int *bandwidth);
+int tegra_bpmp_mbwt_set(struct tegra_bpmp *bpmp, unsigned int instance,
+ unsigned int vc_type, unsigned int bandwidth);
+
#endif
diff --git a/drivers/firmware/tegra/bpmp.c b/drivers/firmware/tegra/bpmp.c
index bd8564865638..f2b739977f13 100644
--- a/drivers/firmware/tegra/bpmp.c
+++ b/drivers/firmware/tegra/bpmp.c
@@ -844,8 +844,117 @@ void tegra_bpmp_handle_rx(struct tegra_bpmp *bpmp)
spin_unlock(&bpmp->lock);
}

-int tegra_bpmp_init_channels(struct tegra_bpmp *bpmp)

+/*
+ * MBWT controls are not exposed through ordinary host MMIO and are accessed
+ * through BPMP firmware requests. These helpers provide the request wrappers
+ * used by bandwidth control callers.
+ */
+bool tegra_bpmp_mbwt_cmd_is_supported(struct tegra_bpmp *bpmp,
+ unsigned int cmd_code)
+{
+ struct mrq_sochub_mbwt_request request = {
+ .cmd = CMD_SOCHUB_MBWT_QUERY_ABI,
+ .query_abi.cmd_code = cmd_code,
+ };
+ struct tegra_bpmp_message msg = {
+ .mrq = MRQ_SOCHUB_MBWT,
+ .tx = {
+ .data = &request,
+ .size = sizeof(request),
+ },
+ };
+ int err;
+
+ err = tegra_bpmp_transfer(bpmp, &msg);
+ if (err || msg.rx.ret)
+ return false;
+
+ return true;
+}
+
+int tegra_bpmp_mbwt_get(struct tegra_bpmp *bpmp, unsigned int instance,
+ unsigned int vc_type, unsigned int *bandwidth)
+{
+ struct mrq_sochub_mbwt_request request = {
+ .cmd = CMD_SOCHUB_MBWT_GET_BW,
+ .get_bw = {
+ .instance = instance,
+ .vc_type = vc_type,
+ },
+ };
+ struct mrq_sochub_mbwt_response response = {};
+ struct tegra_bpmp_message msg = {
+ .mrq = MRQ_SOCHUB_MBWT,
+ .tx = {
+ .data = &request,
+ .size = sizeof(request),
+ },
+ .rx = {
+ .data = &response,
+ .size = sizeof(response),
+ },
+ };
+ int err;
+
+ if (!bandwidth)
+ return -EINVAL;
+
+ err = tegra_bpmp_transfer(bpmp, &msg);
+ if (err) {
+ dev_err(bpmp->dev, "MBWT get bandwidth transfer failed: %d\n",
+ err);
+ return err;
+ }
+
+ if (msg.rx.ret) {
+ dev_err(bpmp->dev, "MBWT get bandwidth failed: BPMP error %d\n",
+ msg.rx.ret);
+ return -EIO;
+ }
+
+ *bandwidth = response.get_bw.bw;
+
+ return 0;
+}
+
+int tegra_bpmp_mbwt_set(struct tegra_bpmp *bpmp, unsigned int instance,
+ unsigned int vc_type, unsigned int bandwidth)
+{
+ struct mrq_sochub_mbwt_request request = {
+ .cmd = CMD_SOCHUB_MBWT_SET_BW,
+ .set_bw = {
+ .instance = instance,
+ .vc_type = vc_type,
+ .bw = bandwidth,
+ },
+ };
+ struct tegra_bpmp_message msg = {
+ .mrq = MRQ_SOCHUB_MBWT,
+ .tx = {
+ .data = &request,
+ .size = sizeof(request),
+ },
+ };
+ int err;
+
+ err = tegra_bpmp_transfer(bpmp, &msg);
+ if (err) {
+ dev_err(bpmp->dev, "MBWT set bandwidth transfer failed: %d\n",
+ err);
+ return err;
+ }
+
+ if (msg.rx.ret) {
+ dev_err(bpmp->dev, "MBWT set bandwidth failed: BPMP error %d\n",
+ msg.rx.ret);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int tegra_bpmp_init_channels(struct tegra_bpmp *bpmp)
{
size_t size;

--
2.43.0