Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp596872pxb; Thu, 14 Jan 2021 13:39:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzvS3oVtTtkrVKOPt78qTsz2EKdh00zcyoe4JFuk0GiiPL+9iMy567ogzLU5G5NZmwmpLR X-Received: by 2002:a05:6402:1748:: with SMTP id v8mr7334792edx.136.1610660368005; Thu, 14 Jan 2021 13:39:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610660367; cv=none; d=google.com; s=arc-20160816; b=azOZA8dSupH4y4Rj0QbD9F5E0auPxWn94e0rvCWytY5klYxy8zGT/8XU/nU2Y59LYy VD4pZHUnkt2uuxoylFk9ZrQwfCkZX1OTJMgtbT+ccMkQhjbQMlv7u9fvOvFGXsuiaQlh uKcW9BpAuT4DGkNitUK20G2tWLlKZ1XbyqMZuzPBeDGobVdX0Qw/HRBiduuXNLVPA4cH PK9GylnaA7HKmhbDUIDAvKLfMuKw+iCn08aBdDG/M/YZlWzZ11+pjlf6+RDN04ZmP1vH EE8BdlbgBD023TaxltqS+rDgky6/NBCrVN7Too5wAPlM4qglD2KTCVFKYXAGigledqFK U/1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=YB/usFiirVWxEZVtVDq8y6qGwNPmfUlSz4nYt8ghwLM=; b=gIz2hm7Ig3Ke94NhSY3M0doKaidMSnEhetLcx1oGkQVIrI0QurQ/XeJE1MoIe5MIRw AjZ8+mA5nsIBIo+7TPInGuSlKPCm20eVKf5TeT0qQ5US0z/EkFX7SBNT8PeA1m7fTbHg YV78A/clTiAOmPtit4SiJqzXh4sFzRVDt/naoHhSexn44DUDeM7HxePG4G11gD0CmwEZ Q0X6iKRd69raEBt522+9YOrgufqJ6b2gJrGyHCRSAg+HwPY5OUFis0TotzS7hJ8PcpUV M15ydqq/XZDIpbdrEG7uMd+GEhXHFj7lsA3lMYn/YnA9+vsZQV/kKf7jHy/ra7Jpu8Rm 9Low== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o4TqmmQ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l18si3004195ejr.658.2021.01.14.13.39.03; Thu, 14 Jan 2021 13:39:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o4TqmmQ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727479AbhANVg6 (ORCPT + 99 others); Thu, 14 Jan 2021 16:36:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726239AbhANVgu (ORCPT ); Thu, 14 Jan 2021 16:36:50 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F040C061575 for ; Thu, 14 Jan 2021 13:36:10 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id t6so3606465plq.1 for ; Thu, 14 Jan 2021 13:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=YB/usFiirVWxEZVtVDq8y6qGwNPmfUlSz4nYt8ghwLM=; b=o4TqmmQ5juxPZYXctha84Xc20NjANvD7x93pUKXyvJCOY3BHPSorInDT3t55pyvJyo DuIrbdvRUPnxbHQBSzRkF3m3amGFDAE5p2vkHNoooyH6pz1QOAIydQ25xmhtdQcPorxN 61HLtRpJkTUPGohIEAWbR0/3SmoeT+wDrl39bwLsgazYFclCVg1/KdTkpmxFwjXvZhsN G6LCdrSIVTnltKpS0GVJdLTpYjBLK/deSsQUXItSM43zECnz7Mc3IxFvVomWGFvGcPRT kaBQxpsZ7cI0eNmidZSZfPSEl1chQKDFhSTt/XeSieLstaW6X07RT54BNBmnEz30MtIk jHbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=YB/usFiirVWxEZVtVDq8y6qGwNPmfUlSz4nYt8ghwLM=; b=qvNpEewcpP6sQX3rOkz0Mr0qgZ9WTEdiuE0rFDDmxOtysP15Ud6D9pqsx5gleWgdp6 7XDVSXO4QOpeX5wiKXsCG4yV9WZANhHSEm7QSOu+I/eMym1pNmhZVwqRnWSvAK5NFrer vkHKiwES1rjHBFmXc0vVtxvcOGt8U2fin07wGLg1FNlCWnh9oM8cjVSJOfaOW7Qv0nng pzJUCCD9Fw0PLVEMeKuRXcmgvNgyNO6707KgRBIUpVWuZ7EJYuEVlcd6FakgCjDGc1fB q1nRDWPMCS6v44D8j6cGCDV4PTebhv8pSgerY6tFA1+T6OFjw27tvsIAQF3jG1hmTETQ fNEg== X-Gm-Message-State: AOAM532cHxbn7+eKMutH4aDPJDWcFdSgnqP6ltSqU01LoNQbYIM4gIW/ KCet4Z96Dw8icCMUfP1iKzlKeA== X-Received: by 2002:a17:902:ec8b:b029:de:577f:2bfe with SMTP id x11-20020a170902ec8bb02900de577f2bfemr5617199plg.2.1610660169813; Thu, 14 Jan 2021 13:36:09 -0800 (PST) Received: from xps15 (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id t1sm6017321pfq.154.2021.01.14.13.36.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jan 2021 13:36:08 -0800 (PST) Date: Thu, 14 Jan 2021 14:36:06 -0700 From: Mathieu Poirier To: peng.fan@nxp.com Cc: ohad@wizery.com, bjorn.andersson@linaro.org, o.rempel@pengutronix.de, robh+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-remoteproc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, paul@crapouillou.net, matthias.bgg@gmail.com, agross@kernel.org, patrice.chotard@st.com Subject: Re: [PATCH V6 10/10] remoteproc: imx_proc: enable virtio/mailbox Message-ID: <20210114213606.GD255481@xps15> References: <1610444359-1857-1-git-send-email-peng.fan@nxp.com> <1610444359-1857-11-git-send-email-peng.fan@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1610444359-1857-11-git-send-email-peng.fan@nxp.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 05:39:19PM +0800, peng.fan@nxp.com wrote: > From: Peng Fan > > Use virtio/mailbox to build connection between Remote Proccessors > and Linux. Add work queue to handle incoming messages. > > Reviewed-by: Richard Zhu > Signed-off-by: Peng Fan > --- > drivers/remoteproc/imx_rproc.c | 115 ++++++++++++++++++++++++++++++++- > 1 file changed, 112 insertions(+), 3 deletions(-) > > diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c > index e62a53ee128e..812b077f1282 100644 > --- a/drivers/remoteproc/imx_rproc.c > +++ b/drivers/remoteproc/imx_rproc.c > @@ -7,6 +7,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -15,6 +16,9 @@ > #include > #include > #include > +#include > + > +#include "remoteproc_internal.h" > > #define IMX7D_SRC_SCR 0x0C > #define IMX7D_ENABLE_M4 BIT(3) > @@ -86,6 +90,11 @@ struct imx_rproc { > const struct imx_rproc_dcfg *dcfg; > struct imx_rproc_mem mem[IMX7D_RPROC_MEM_MAX]; > struct clk *clk; > + struct mbox_client cl; > + struct mbox_chan *tx_ch; > + struct mbox_chan *rx_ch; > + struct work_struct rproc_work; > + struct workqueue_struct *workqueue; > }; > > static const struct imx_rproc_att imx_rproc_att_imx8mq[] = { > @@ -366,9 +375,33 @@ static int imx_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) > return 0; > } > > +static void imx_rproc_kick(struct rproc *rproc, int vqid) > +{ > + struct imx_rproc *priv = rproc->priv; > + int err; > + __u32 mmsg; > + > + if (!priv->tx_ch) { > + dev_err(priv->dev, "No initialized mbox tx channel\n"); > + return; > + } > + > + /* > + * Send the index of the triggered virtqueue as the mu payload. > + * Let remote processor know which virtqueue is used. > + */ > + mmsg = vqid << 16; > + > + err = mbox_send_message(priv->tx_ch, (void *)&mmsg); > + if (err < 0) > + dev_err(priv->dev, "%s: failed (%d, err:%d)\n", > + __func__, vqid, err); > +} > + > static const struct rproc_ops imx_rproc_ops = { > .start = imx_rproc_start, > .stop = imx_rproc_stop, > + .kick = imx_rproc_kick, > .da_to_va = imx_rproc_da_to_va, > .load = rproc_elf_load_segments, > .parse_fw = imx_rproc_parse_fw, > @@ -444,6 +477,65 @@ static int imx_rproc_addr_init(struct imx_rproc *priv, > return 0; > } > > +static void imx_rproc_vq_work(struct work_struct *work) > +{ > + struct imx_rproc *priv = container_of(work, struct imx_rproc, > + rproc_work); > + > + rproc_vq_interrupt(priv->rproc, 0); > + rproc_vq_interrupt(priv->rproc, 1); > +} > + > +static void imx_rproc_rx_callback(struct mbox_client *cl, void *msg) > +{ > + struct rproc *rproc = dev_get_drvdata(cl->dev); > + struct imx_rproc *priv = rproc->priv; > + > + queue_work(priv->workqueue, &priv->rproc_work); > +} > + > +static int imx_rproc_xtr_mbox_init(struct rproc *rproc) > +{ > + struct imx_rproc *priv = rproc->priv; > + struct device *dev = priv->dev; > + struct mbox_client *cl; > + int ret; > + > + if (!of_get_property(dev->of_node, "mbox-names", NULL)) > + return 0; > + > + cl = &priv->cl; > + cl->dev = dev; > + cl->tx_block = true; > + cl->tx_tout = 100; > + cl->knows_txdone = false; > + cl->rx_callback = imx_rproc_rx_callback; > + > + priv->tx_ch = mbox_request_channel_byname(cl, "tx"); > + if (IS_ERR(priv->tx_ch)) { > + ret = PTR_ERR(priv->tx_ch); > + return dev_err_probe(cl->dev, PTR_ERR(priv->tx_ch), > + "failed to request tx mailbox channel: %d\n", ret); return dev_err_probe(cl->dev, ret, "failed to request tx mailbox channel: %d\n", ret); > + } > + > + priv->rx_ch = mbox_request_channel_byname(cl, "rx"); > + if (IS_ERR(priv->rx_ch)) { > + mbox_free_channel(priv->tx_ch); > + return dev_err_probe(cl->dev, PTR_ERR(priv->rx_ch), > + "failed to request mbox tx chan\n"); ret = PTR_ERR(priv->rx_ch); return dev_err_probe(cl->dev, ret, "failed to request rx mailbox channel: %d\n", ret); > + } > + > + return 0; > +} > + > +static void imx_rproc_free_mbox(struct rproc *rproc) > +{ > + struct imx_rproc *priv = rproc->priv; > + > + mbox_free_channel(priv->tx_ch); > + mbox_free_channel(priv->rx_ch); > +} > + > static int imx_rproc_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > @@ -481,18 +573,28 @@ static int imx_rproc_probe(struct platform_device *pdev) > priv->dev = dev; > > dev_set_drvdata(dev, rproc); > + priv->workqueue = create_workqueue(dev_name(dev)); > + if (!priv->workqueue) { > + dev_err(dev, "cannot create workqueue\n"); > + ret = -ENOMEM; > + goto err_put_rproc; > + } > + > + ret = imx_rproc_xtr_mbox_init(rproc); > + if (ret) > + goto err_put_wkq; > > ret = imx_rproc_addr_init(priv, pdev); > if (ret) { > dev_err(dev, "failed on imx_rproc_addr_init\n"); > - goto err_put_rproc; > + goto err_put_mbox; > } > > priv->clk = devm_clk_get(dev, NULL); > if (IS_ERR(priv->clk)) { > dev_err(dev, "Failed to get clock\n"); > ret = PTR_ERR(priv->clk); > - goto err_put_rproc; > + goto err_put_mbox; > } > > /* > @@ -502,9 +604,11 @@ static int imx_rproc_probe(struct platform_device *pdev) > ret = clk_prepare_enable(priv->clk); > if (ret) { > dev_err(&rproc->dev, "Failed to enable clock\n"); > - goto err_put_rproc; > + goto err_put_mbox; > } > > + INIT_WORK(&(priv->rproc_work), imx_rproc_vq_work); > + > ret = rproc_add(rproc); > if (ret) { > dev_err(dev, "rproc_add failed\n"); > @@ -515,6 +619,10 @@ static int imx_rproc_probe(struct platform_device *pdev) > > err_put_clk: > clk_disable_unprepare(priv->clk); > +err_put_mbox: > + imx_rproc_free_mbox(rproc); > +err_put_wkq: > + destroy_workqueue(priv->workqueue); > err_put_rproc: > rproc_free(rproc); > > @@ -527,6 +635,7 @@ static int imx_rproc_remove(struct platform_device *pdev) > struct imx_rproc *priv = rproc->priv; > > clk_disable_unprepare(priv->clk); > + imx_rproc_free_mbox(rproc); Function rproc_del() needs to be called first so that rproc_shutdown() is executed (because rproc->auto_boot is true). Thanks, Mathieu > rproc_del(rproc); > rproc_free(rproc); > > -- > 2.28.0 >