From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B4140D0EE0D for ; Tue, 25 Nov 2025 17:05:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pYgo1d5vBv7JwZFnlBuT9v8v0agvYmWOE6awznPlpPk=; b=k24eL34i6wPKBRzDA0UmeqDMPD RHV/OpMgmnOT1E/J9uiwqNiHiztt4rnd4myEhZlJwTGw6c0P+YKeQfyvX0IHcV6iyVxTgJ/NjG4Fd OgVd5NMiKTyVG4fcqvFnOHobyhipeQKhMsrouVhlM/ULqSHa8VuV1JHGJMdiESZNUn4oC4hDC0+e+ P7FWh4G6p8dzVKlEg21hiboXhiNdNR4aw8A3s4ktcrE8lce2WDo/BR+iAk96OWtRWjXlJUIadB5OO p93brEr89SfnJEjigpC3AbUNZzbhb/9keKC/yMXj8DpQi/mHD5vf522++hRyKD1GwjByn3tHxuLVD SaIXn1jA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vNwTL-0000000DeCR-1u0x; Tue, 25 Nov 2025 17:04:59 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vNwTJ-0000000DeC7-0YUy for linux-arm-kernel@lists.infradead.org; Tue, 25 Nov 2025 17:04:58 +0000 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-7ade456b6abso4655188b3a.3 for ; Tue, 25 Nov 2025 09:04:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1764090296; x=1764695096; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=pYgo1d5vBv7JwZFnlBuT9v8v0agvYmWOE6awznPlpPk=; b=tqMxLNoZP/BvYhm71KQisvF3MrJxzSCBtU10JG4Po8g6QF6ygoDLtYxbBQMrTve+fL DiH7InzqYG8659bD5bz5kY0MfLh9yYZo8UxfWpXSATHrONuNQHwwbV4QFBgLSHG3lN07 LNUwIanxoPsGLP4cs1I44uD/FgnGZyYDSRVMebwJ94KekOY1XzZWUij90vSyZuZe12YT 6fCucIjjuHXtksmlal0WAwET13IJv1gniGKJRe3CtFY+CBJsjlykPZ4vGvy29Iu7grEj Rf8ENsYOlcaI4qZ3bfEtj4SaNYpMWDHi5iMiyJdP6LNGt3c8MAGBMGN8pkEJdNmZ5/sv YVSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764090296; x=1764695096; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pYgo1d5vBv7JwZFnlBuT9v8v0agvYmWOE6awznPlpPk=; b=hW5RXx3Z0qo+IhGI1pt4rZEeRIQZbPz5L2Utrw4Wv4FkVzw0yTzRFSk4ZcqBLva5mq 3jGGMX4H2Et4E7VnPBi7H+uG0Hu77hbvzW822IP0zIKvP61n4o5RQyxdyh7lL7qVqC83 U6PQ7xw5dTvJsChYyzTwZs7PR4j4lue7PgXoGpImnFWBohW98yEWhpf/e7SzQjzaRsrG 9b8gd/1i7r/svxCq61nbgItEwF2wTVFY9MtmbP1Cvabsp0HaZJnB3mLlzjdOZ21qAGTM NYx0FaXqgW5w5LiBqDhuMvGut4tj5cedT5VDYHe2z67jBhodbVSsL0AOMrgmhNYHqXwQ JZUg== X-Forwarded-Encrypted: i=1; AJvYcCUnQRKV0CQhi7BPVI/wyFb80y+4oqta5b4WbI8Pywff/6QQuo0V9I3Vq+aGjybUhieI0tfbKvGdf40O/oMM6F3D@lists.infradead.org X-Gm-Message-State: AOJu0YxpPY/C8qh7PgpOp8XS69SFNJjWu0vuXaFnfSZY84e0CD5mxlK2 u1fVvsD9iyFytU74Vguqfa0iHXcsGZSjQVNL8EIXcpFhumYo7dVzJcme06UCNJZzn/0vO/z0AY2 RoOba/dc= X-Gm-Gg: ASbGncsnedF2nEQ/Y+VWvGu2Ghg6WkJmkzi2poMEUc2QXCHSH5KNkK5f+tS1wL1XLzP ByQOPAO8+R6ccWLGM67ppBnTq+XWZFs5/BxnWsJjZ/Oefqbz62rmTANYYrW1vyEDmhbEBtuQqBm Y1MUOzAJbkY4OKBS8l4O8+R2LurQD0NEVhU4/gqMWoI8wGb42POW0S2DBt3czJpnoOdfiswdq3Q MB24Sg65cDwbZ6H0YPnfRwz6xwbMqAKe0GLErMEKwC1/6Wl2GLJr78rW53D8FlIvojaqheWCbE/ EU0ZgqbLP3ZKYZ2FutamkG4mmmLp9IWOs4EcP0qEphFpFBsfzuE/T209yMtdyd8EkGKp/sjaeX8 Tp/z4rkUWl+cDeuHCdCryErgvVGHd1/fvXmzRYuWSY0SB41JDZPEcM8+ar7IKr+3J8YmZqjPAb1 +VqRLcpr6IuMGUkg== X-Google-Smtp-Source: AGHT+IE3HVI2OSwKYyz2J7aR+dAp3ud2KB0NZWfDEl2yFaQQfh/xXRFxm9LLeRPNFwq1q34sUk9S4w== X-Received: by 2002:a05:6a20:7490:b0:35e:bfe5:ee82 with SMTP id adf61e73a8af0-36150f1ed1emr18535116637.48.1764090295883; Tue, 25 Nov 2025 09:04:55 -0800 (PST) Received: from p14s ([2604:3d09:148c:c800:c0c0:5a6c:d170:84a1]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7c3ed37b0c7sm18550669b3a.20.2025.11.25.09.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 09:04:55 -0800 (PST) Date: Tue, 25 Nov 2025 10:04:52 -0700 From: Mathieu Poirier To: Shenwei Wang Cc: Bjorn Andersson , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Jonathan Corbet , Linus Walleij , Bartosz Golaszewski , Pengutronix Kernel Team , Fabio Estevam , Peng Fan , linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-imx@nxp.com Subject: Re: [PATCH v5 2/5] remoteproc: imx_rproc: Populate devices under "rpmsg" subnode Message-ID: References: <20251104203315.85706-1-shenwei.wang@nxp.com> <20251104203315.85706-3-shenwei.wang@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251104203315.85706-3-shenwei.wang@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251125_090457_207912_66E6201B X-CRM114-Status: GOOD ( 40.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Good morning, Here are some first-pass comments - more to come later. On Tue, Nov 04, 2025 at 02:33:12PM -0600, Shenwei Wang wrote: > Register the RPMsg channel driver and populate remote devices defined > under the "rpmsg" subnode upon receiving their notification messages. > > The following illustrates the expected DTS layout structure: > > cm33: remoteproc-cm33 { > compatible = "fsl,imx8ulp-cm33"; > > rpmsg { > rpmsg-io-channel { > gpio@0 { > compatible = "fsl,imx-rpmsg-gpio"; > reg = <0>; > }; > > gpio@1 { > compatible = "fsl,imx-rpmsg-gpio"; > reg = <1>; > }; > > ... > }; > > rpmsg-i2c-channel { > i2c@0 { > compatible = "fsl,imx-rpmsg-i2c"; > reg = <0>; > }; > }; > > ... > }; > }; 2 observations here: (1) Why are you trying to introduce both i2c and GPIO in the same patchset? (2) My first impression is that i2c, GPIO and others should be bundled with the platform definitions for i2c and GPIO, with a phandle to the remote processor they hang off from. My opinion may change once I have reviewed the other patches in this set. > > Signed-off-by: Shenwei Wang > --- > drivers/remoteproc/imx_rproc.c | 146 ++++++++++++++++++++++++++++++++ > include/linux/rpmsg/imx_rpmsg.h | 48 +++++++++++ > 2 files changed, 194 insertions(+) > create mode 100644 include/linux/rpmsg/imx_rpmsg.h > > diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c > index a6eef0080ca9..e21a7980c490 100644 > --- a/drivers/remoteproc/imx_rproc.c > +++ b/drivers/remoteproc/imx_rproc.c > @@ -8,6 +8,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -15,6 +16,8 @@ > #include > #include > #include > +#include > +#include > #include > #include > #include > @@ -22,6 +25,7 @@ > #include > #include > #include > +#include > #include > > #include "imx_rproc.h" > @@ -1084,6 +1088,144 @@ static int imx_rproc_sys_off_handler(struct sys_off_data *data) > return NOTIFY_DONE; > } > > +struct imx_rpmsg_driver { > + struct rpmsg_driver rpdrv; > + void *driver_data; > +}; > + > +static char *channel_device_map[][2] = { > + {"rpmsg-io-channel", "fsl,imx-rpmsg-gpio"}, > + {"rpmsg-i2c-channel", "fsl,imx-rpmsg-i2c"}, > +}; > + > +static int imx_rpmsg_endpoint_cb(struct rpmsg_device *rpdev, void *data, > + int len, void *priv, u32 src) > +{ > + struct imx_rpmsg_driver_data *drvdata; > + > + drvdata = dev_get_drvdata(&rpdev->dev); > + if (drvdata && drvdata->rx_callback) > + return drvdata->rx_callback(rpdev, data, len, priv, src); > + > + return 0; > +} > + > +static void imx_rpmsg_endpoint_remove(struct rpmsg_device *rpdev) > +{ > + of_platform_depopulate(&rpdev->dev); > +} > + > +static int imx_rpmsg_endpoint_probe(struct rpmsg_device *rpdev) > +{ > + struct imx_rpmsg_driver_data *drvdata; > + struct imx_rpmsg_driver *imx_rpdrv; > + struct device *dev = &rpdev->dev; > + struct of_dev_auxdata *auxdata; > + struct rpmsg_driver *rpdrv; > + int i; > + > + rpdrv = container_of(dev->driver, struct rpmsg_driver, drv); > + imx_rpdrv = container_of(rpdrv, struct imx_rpmsg_driver, rpdrv); > + > + if (!imx_rpdrv->driver_data) > + return -EINVAL; > + > + drvdata = devm_kmemdup(dev, imx_rpdrv->driver_data, sizeof(*drvdata), GFP_KERNEL); Something with the overall design of this feature doesn't work if you need to do this. > + if (!drvdata) > + return -ENOMEM; > + > + i = drvdata->map_idx; > + if (i >= ARRAY_SIZE(channel_device_map)) > + return -ENODEV; > + > + auxdata = devm_kzalloc(dev, sizeof(*auxdata) * 2, GFP_KERNEL); > + if (!auxdata) > + return -ENOMEM; > + > + drvdata->rpdev = rpdev; > + auxdata[0].compatible = channel_device_map[i][1]; > + auxdata[0].platform_data = drvdata; > + dev_set_drvdata(dev, drvdata); > + > + of_platform_populate(drvdata->channel_node, NULL, auxdata, dev); > + of_node_put(drvdata->channel_node); Why is there a need for of_node_put() when imx_of_rprmsg_node_init() is using for_each_child_of_node_scoped()? > + > + return 0; > +} > + > +static int imx_of_rpmsg_is_in_map(const char *name) > +{ > + int i; > + > + for (i = 0; i < ARRAY_SIZE(channel_device_map); i++) { > + if (strcmp(name, channel_device_map[i][0]) == 0) > + return i; > + } > + > + return -1; Please return a real error code. > +} > + > +static int imx_of_rpmsg_register_rpdriver(struct device_node *channel, > + struct device *dev, int idx) > +{ > + struct imx_rpmsg_driver_data *driver_data; > + struct imx_rpmsg_driver *rp_driver; > + struct rpmsg_device_id *rpdev_id; > + > + rpdev_id = devm_kzalloc(dev, sizeof(*rpdev_id) * 2, GFP_KERNEL); I had a really good time figuring out why 2 instances were needed. Reviewing this work without a single line of comment isn't motivating. > + if (!rpdev_id) > + return -ENOMEM; > + > + strscpy(rpdev_id[0].name, channel_device_map[idx][0], RPMSG_NAME_SIZE); > + > + rp_driver = devm_kzalloc(dev, sizeof(*rp_driver), GFP_KERNEL); > + if (!rp_driver) > + return -ENOMEM; > + > + driver_data = devm_kzalloc(dev, sizeof(*driver_data), GFP_KERNEL); > + if (!driver_data) > + return -ENOMEM; > + > + driver_data->rproc_name = dev->of_node->name; > + driver_data->channel_node = channel; > + driver_data->map_idx = idx; struct rpmsg_device_id already contains a @driver_data. As with my other comment above, something in the design of this feature is not working if you need to do something like this. > + > + rp_driver->rpdrv.drv.name = channel_device_map[idx][0]; > + rp_driver->rpdrv.id_table = rpdev_id; > + rp_driver->rpdrv.probe = imx_rpmsg_endpoint_probe; > + rp_driver->rpdrv.remove = imx_rpmsg_endpoint_remove; > + rp_driver->rpdrv.callback = imx_rpmsg_endpoint_cb; > + rp_driver->driver_data = driver_data; > + > + register_rpmsg_driver(&rp_driver->rpdrv); > + > + return 0; > +} > + > +static int imx_of_rpmsg_node_init(struct platform_device *pdev) > +{ > + struct device_node *np __free(device_node); > + struct device *dev = &pdev->dev; > + int idx, ret; > + > + np = of_get_child_by_name(dev->of_node, "rpmsg"); > + if (!np) > + return 0; > + > + for_each_child_of_node_scoped(np, child) { > + idx = imx_of_rpmsg_is_in_map(child->name); > + if (idx < 0) > + ret = of_platform_default_populate(child, NULL, dev); Why is this called? > + else > + ret = imx_of_rpmsg_register_rpdriver(child, dev, idx); > + > + if (ret < 0) > + return ret; In case of an error, the reference to @np is not released. > + } > + > + return 0; > +} > + If we were to keep the current design, all of the above should be in drivers/rpmsg/imx_rpmsg.c. > static int imx_rproc_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > @@ -1177,6 +1319,10 @@ static int imx_rproc_probe(struct platform_device *pdev) > goto err_put_clk; > } > > + ret = imx_of_rpmsg_node_init(pdev); > + if (ret < 0) > + dev_info(dev, "populating 'rpmsg' node failed\n"); > + > return 0; > > err_put_clk: > diff --git a/include/linux/rpmsg/imx_rpmsg.h b/include/linux/rpmsg/imx_rpmsg.h > new file mode 100644 > index 000000000000..04a5ad2d4a1d > --- /dev/null > +++ b/include/linux/rpmsg/imx_rpmsg.h > @@ -0,0 +1,48 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* Copyright 2025 NXP */ > + > +/* > + * @file linux/imx_rpmsg.h > + * > + * @brief Global header file for iMX RPMSG > + * > + * @ingroup RPMSG > + */ > +#ifndef __LINUX_IMX_RPMSG_H__ > +#define __LINUX_IMX_RPMSG_H__ > + > +/* Category define */ > +#define IMX_RMPSG_LIFECYCLE 1 > +#define IMX_RPMSG_PMIC 2 > +#define IMX_RPMSG_AUDIO 3 > +#define IMX_RPMSG_KEY 4 > +#define IMX_RPMSG_GPIO 5 > +#define IMX_RPMSG_RTC 6 > +#define IMX_RPMSG_SENSOR 7 > + > +/* rpmsg version */ > +#define IMX_RMPSG_MAJOR 1 > +#define IMX_RMPSG_MINOR 0 > + > +#define MAX_DEV_PER_CHANNEL 10 > + > +struct imx_rpmsg_head { > + u8 cate; /* Category */ > + u8 major; /* Major version */ > + u8 minor; /* Minor version */ > + u8 type; /* Message type */ > + u8 cmd; /* Command code */ > + u8 reserved[5]; > +} __packed; This structure is not used in this file, please remove. > + > +struct imx_rpmsg_driver_data { > + int map_idx; > + const char *rproc_name; > + struct rpmsg_device *rpdev; > + struct device_node *channel_node; > + int (*rx_callback)(struct rpmsg_device *rpdev, void *data, > + int len, void *priv, u32 src); > + void *channel_devices[MAX_DEV_PER_CHANNEL]; > +}; For the above 2 struct, proper documentation is needed. Thanks, Mathieu > + > +#endif /* __LINUX_IMX_RPMSG_H__ */ > -- > 2.43.0 >