Re: [PATCH 3/9] soc: google: Add CPM over MailBox Array driver

From: Peter Griffin

Date: Tue Nov 24 2026 - 07:28:41 EST


Hi Brian,

Thanks for your series; it's great to see more Laguna support being posted.

On Mon, 26 Oct 2026 at 21:45, Brian Norris <briannorris@xxxxxxxxxxxx> wrote:
>
> The Central Power Manager (CPM) is a co-processor on the Google Tensor
> SoCs, as used on Pixel phones. CPM supports power-management and a
> number of other features.
>
> The Application Processor communicates with CPM over a pair of mailbox
> channels (the "MailBox Array" (MBA)). CPM provides clock, power-domain,
> reset, interrupt services, and more.

[..]

+++ b/drivers/soc/google/Kconfig
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config GOOGLE_CPM_MBA
+ tristate "Google Tensor CPM MailBox Array Interface"
+ depends on ARCH_GOOGLE || COMPILE_TEST
+ depends on MAILBOX

Should we also have "depends on OF"?

+ select AUXILIARY_BUS
+ help
+ Driver for interfacing with the Central Power Manager (CPM) MailBox
+ Array (MBA) found on Google Tensor SoCs. The driver provides APIs for
+ communication between the Application Processor and the CPM, and
+ is required by CPM client drivers such as clock, reset, power
+ domain, and more.

> diff --git a/drivers/soc/google/google-cpm-mba.c b/drivers/soc/google/google-cpm-mba.c
> new file mode 100644
> index 000000000000..629a071e202c
> --- /dev/null
> +++ b/drivers/soc/google/google-cpm-mba.c
> @@ -0,0 +1,964 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Google MailBox Array (MBA) CPM Interface
> + *
> + * Copyright 2023-2026 Google LLC
> + */
> +
> +#include <linux/auxiliary_bus.h>
> +#include <linux/bitfield.h>
> +#include <linux/bits.h>
> +#include <linux/cleanup.h>
> +#include <linux/completion.h>
> +#include <linux/device.h>
> +#include <linux/jiffies.h>
> +#include <linux/kref.h>
> +#include <linux/list.h>
> +#include <linux/lockdep.h>
> +#include <linux/mailbox/goog-mba-message.h>
> +#include <linux/mailbox_client.h>
> +#include <linux/mailbox_controller.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/of_platform.h>
> +#include <linux/platform_device.h>
> +#include <linux/spinlock.h>

Missing `#include <linux/slab.h>` header here as later it calls
kfree(), kzalloc_obj().
This can cause "implicit declaration of function kfree / kzalloc_obj"
errors with COMPILE_TEST. Also similar issue in clk-cpm.c

> +
> +#include <soc/google/google-cpm-mba.h>
> +
> +#include "google-cpm-mba.h"
> +

[..]
> +static bool cpm_iface_is_valid_req(struct cpm_data *cpm,
> + struct cpm_request *cpm_req)
> +{
> + struct device *dev = cpm->dev;
> +
> + if (!cpm_req) {
> + dev_err(dev, "cpm_req is NULL\n");
> + return false;
> + }
> +
> + if (!cpm_req->req_msg) {
> + dev_err(dev, "cpm_req->req_msg is NULL\n");
> + return false;
> + }
> +
> + if (cpm_req->msg_type > RESPONSE_MSG || cpm_req->msg_type < ONEWAY_MSG) {
> + dev_err(dev, "Invalid msg_type: %d\n", cpm_req->msg_type);
> + return false;
> + }

Should cpm_req->dst_id also be range checked?

> +
> + if (cpm_is_request_msg(cpm_req) && !cpm_req->resp_msg) {
> + dev_err(dev, "cpm_req->resp_msg is NULL when msg_type is REQUEST_MSG\n");
> + return false;
> + }
> +
> + if (cpm_is_response_msg(cpm_req)) {
> + if (!goog_mba_q_get_valid(&cpm_req->resp_context)) {
> + dev_err(dev, "Invalid valid bit in resp_context: %#x\n",
> + cpm_req->resp_context);
> + return false;
> + }
> +
> + if (!cpm_is_response_header(&cpm_req->resp_context)) {
> + dev_err(dev, "Invalid response type in resp_context: %#x\n",
> + cpm_req->resp_context);
> + return false;
> + }
> + }
> +
> + return true;
> +}
> +

[..]

> +
> +static int cpm_init_q_mode_proto(struct cpm_data *cpm)
> +{
> + struct cpm_payload msg_payload = {};
> + struct cpm_request req = {
> + .msg_type = ONEWAY_MSG,
> + .req_msg = &msg_payload,
> + };
> +
> + return __cpm_send_message(cpm, &req, GOOG_MBA_Q_INIT_PROTO_VAL, 0);

Do we want this to have an infinite timeout? If the CPM firmware never
responds, it will hang the boot (as MAX_SCHEDULE_TIMEOUT doesn't arm a
timer).
I guess it is game over anyway if the CPM firmware is dead, but it
would be nice to log an error and return from probe()


> +}
> +
> +static int cpm_init_q_mode(struct cpm_data *cpm)
> +{
> + int ret;
> +
> + ret = cpm_init_q_mode_proto(cpm);
> + if (ret < 0)
> + return ret;
> +
> + cpm->seq_num = GOOG_MBA_Q_MIN_SEQ_VAL;
> +
> + return 0;
> +}
> +
> +static void cpm_adev_release(struct device *dev)
> +{
> + struct auxiliary_device *adev = to_auxiliary_dev(dev);
> +
> + of_node_put(dev->of_node);
> + kfree(adev);
> +}
> +
> +static void cpm_unregister_adev_action(void *data)
> +{
> + struct auxiliary_device *adev = data;
> +
> + auxiliary_device_delete(adev);
> + auxiliary_device_uninit(adev);
> +}
> +

Can we use devm_auxiliary_device_create() instead of open coding these?

> +static int cpm_register_adev(struct cpm_data *cpm, const char *name)
> +{
> + struct auxiliary_device *adev;
> + int ret;
> +
> + adev = kzalloc_obj(*adev, GFP_KERNEL);
> + if (!adev)
> + return -ENOMEM;
> +
> + adev->name = name;
> + adev->id = 0;
> + adev->dev.parent = cpm->dev;
> + adev->dev.release = cpm_adev_release;
> + device_set_of_node_from_dev(&adev->dev, cpm->dev);
> +
> + ret = auxiliary_device_init(adev);
> + if (ret) {
> + of_node_put(adev->dev.of_node);
> + kfree(adev);
> + return ret;
> + }
> +
> + ret = auxiliary_device_add(adev);
> + if (ret) {
> + auxiliary_device_uninit(adev);
> + return ret;
> + }
> +
> + return devm_add_action_or_reset(cpm->dev, cpm_unregister_adev_action, adev);
> +}
> +

[..]

> +
> +MODULE_DESCRIPTION("Google MBA CPM interface");
> +MODULE_AUTHOR("Lucas Wei <lucaswei@xxxxxxxxxx>");

I think you should add Lucas Wei's SoB tag to the patch as part of the DCO

regards,

Peter