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 63865C5479D for ; Mon, 9 Jan 2023 21:49:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7/ZcKglCA0S52U0LJIkPPYPSPLLWvjEYKWomfDBw+iU=; b=MO3OzfOFX5848F /QpeJIHo97cA9+rpn3J1v7EMip87ya4OyfAa9n0Nz6OpZx05+HrPa9EJjtMcdmNOg0WR85yH/YLyU 07hsWqyFE3Ok/PkRsqI8+enXYtj2eN1WGdqkRLttTCD8I7/BwdmwmoC0UYGrukcYZbva7QcyvGQyA 8qkEJv9VgJQZ+/2de1kqwIR+18HW4ZN52J2/AuKRGUn1xebd4q/sRNLKeM4I4b09rohX8hOFdyjIp 11eRIqNQtM1qP+DtqnPmVOPAAC43U/NCqQG9kMxyzS7O0RilzetSqwpL0YL/ON/7m78kg1fii6bEw qmo4XUqF+Ub1CzzHPFxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pF00T-004Ksj-L4; Mon, 09 Jan 2023 21:48:39 +0000 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pEzmu-004FpI-MK for linux-arm-kernel@lists.infradead.org; Mon, 09 Jan 2023 21:34:38 +0000 Received: by mail-io1-xd2f.google.com with SMTP id 3so5177677iou.12 for ; Mon, 09 Jan 2023 13:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=OfVSdDVOS9780zsdf8R+dkGcr8yzVl06GcKWsbR1DEc=; b=OWuDkEsJUUEF/a3bF7v6PWjBf7SSomQjoG58ol67HZNKuAt+/FaCSt1B1qQZdRrSAe MJXDBJZlFUzauB6uJcl+YNQKT59Pqx7d2ZQ00ZT8dHwiA/0Jp/PDX4+ELqqyISJ1MBio 59QrfGjNlZ59+0/m4jaSzs6W61qSA2uIh1IjOZtV0yTlW5YFbViBH3d79jwIGw0tCbTV CUMd19VvZIQVig4r0Hi/CiAUoCUFxMprNMOxr+5OFmJ9hiOHUAGreLJD5oeZ9Fft/P8t 99nwEke0xWg6c2fOdeNmm/xLkNWBEjHgb76aH5JUblXw4bfDRnCsU/rph6gZmcdoZ0Pl zP5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OfVSdDVOS9780zsdf8R+dkGcr8yzVl06GcKWsbR1DEc=; b=X8/PqTDJdnzZnxPwdlOP48CvV+ScOM00AehH827L4YBrnjwcGnviTtRRPQ9JZxL7Un EfdQ7hbUMGzi19LR0C5o8jglMsC60RXYSblcYvy9/4g2HyS6sns2F583MS8SS8KoXpzO UZ/AT6Q2HVchZO7vTGGkYfpCeCccCtwKjqykzEz1MIwrQHdQuUZCmX2TC/0MH0dzhjKM SZhAejJN4CFT0uleRe6Aji5Gta1DiWnt4pjq7OQ1NSCYgDTFSAnYBEjlTueR4N81fNUl SOsL/aZgnUTjdhPkxafqd7oicPfvo3xukp5xtoNNWCV54Wlh9t0sVBQB84ZvS1Bf5Pzs rZig== X-Gm-Message-State: AFqh2kpMtdbZELs961D0ySDkeIpRZ5oXbhud/+q5/1tl2O64h3Wt0m6R OpCRtKC6OilzWRykc8LnR5++vg== X-Google-Smtp-Source: AMrXdXs9Rro9BMGQQf3u+WoQxaXEuT6LwOhLg0LrwboxDwqJTLccq+3lMGeciJLN1+p0713P37aE2A== X-Received: by 2002:a5e:970c:0:b0:6df:f777:ba81 with SMTP id w12-20020a5e970c000000b006dff777ba81mr44330363ioj.3.1673300075308; Mon, 09 Jan 2023 13:34:35 -0800 (PST) Received: from [172.22.22.4] ([98.61.227.136]) by smtp.googlemail.com with ESMTPSA id i19-20020a0566022c9300b006e2d21ab686sm3562792iow.38.2023.01.09.13.34.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Jan 2023 13:34:34 -0800 (PST) Message-ID: <942f20cc-87d3-d014-1527-8d3d3e1ae44b@linaro.org> Date: Mon, 9 Jan 2023 15:34:33 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v8 07/28] mailbox: Allow direct registration to a channel Content-Language: en-US To: Elliot Berman , Bjorn Andersson , Jassi Brar , Sudeep Holla Cc: Murali Nalajala , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Prakruthi Deepak Heragu , Arnd Bergmann , Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , Bagas Sanjaya , Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Dmitry Baryshkov , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org References: <20221219225850.2397345-1-quic_eberman@quicinc.com> <20221219225850.2397345-8-quic_eberman@quicinc.com> From: Alex Elder In-Reply-To: <20221219225850.2397345-8-quic_eberman@quicinc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230109_133436_815659_FDB8DA8B X-CRM114-Status: GOOD ( 33.14 ) 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: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 12/19/22 4:58 PM, Elliot Berman wrote: > Support virtual mailbox controllers and clients which are not platform > devices or come from the devicetree by allowing them to match client to > channel via some other mechanism. The new function behaves very much like mbox_request_channel() did before. The new function differs from omap_mbox_request_channel() in that it can change the if chan->txdone_method is TXDONE_BY_POLL, it is changed to TXDONE_BY_ACK if the client's knows_txdone field is set. Is this OK? Why? It also assumes chan->mbox->ops->startup us non-null (though that isn't really a problem). > > Signed-off-by: Elliot Berman > --- > drivers/mailbox/mailbox.c | 96 ++++++++++++++++++++++++---------- > drivers/mailbox/omap-mailbox.c | 18 ++----- > drivers/mailbox/pcc.c | 18 ++----- > include/linux/mailbox_client.h | 1 + > 4 files changed, 76 insertions(+), 57 deletions(-) > > diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c > index 4229b9b5da98..adf36c05fa43 100644 > --- a/drivers/mailbox/mailbox.c > +++ b/drivers/mailbox/mailbox.c > @@ -317,6 +317,71 @@ int mbox_flush(struct mbox_chan *chan, unsigned long timeout) > } > EXPORT_SYMBOL_GPL(mbox_flush); > > +static int __mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl) There should be an unbind_client() call. At a minimum, you are calling try_module_get(), and the matching module_put() call would belong there. And even though one might just call module_put() elsewhere for this, it would be cleaner to have a function that similarly encapsulates the shutdown call as well. -Alex > +{ > + struct device *dev = cl->dev; > + unsigned long flags; > + int ret; > + > + if (chan->cl || !try_module_get(chan->mbox->dev->driver->owner)) { > + dev_dbg(dev, "%s: mailbox not free\n", __func__); > + return -EBUSY; > + } > + > + spin_lock_irqsave(&chan->lock, flags); > + chan->msg_free = 0; > + chan->msg_count = 0; > + chan->active_req = NULL; > + chan->cl = cl; > + init_completion(&chan->tx_complete); > + > + if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) > + chan->txdone_method = TXDONE_BY_ACK; > + > + spin_unlock_irqrestore(&chan->lock, flags); > + > + if (chan->mbox->ops->startup) { > + ret = chan->mbox->ops->startup(chan); > + > + if (ret) { > + dev_err(dev, "Unable to startup the chan (%d)\n", ret); > + mbox_free_channel(chan); > + return ret; > + } > + } > + > + return 0; > +} > + > +/** > + * mbox_bind_client - Request a mailbox channel. > + * @chan: The mailbox channel to bind the client to. > + * @cl: Identity of the client requesting the channel. > + * > + * The Client specifies its requirements and capabilities while asking for > + * a mailbox channel. It can't be called from atomic context. > + * The channel is exclusively allocated and can't be used by another > + * client before the owner calls mbox_free_channel. > + * After assignment, any packet received on this channel will be > + * handed over to the client via the 'rx_callback'. > + * The framework holds reference to the client, so the mbox_client > + * structure shouldn't be modified until the mbox_free_channel returns. > + * > + * Return: 0 if the channel was assigned to the client successfully. > + * <0 for request failure. > + */ > +int mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl) > +{ > + int ret; > + > + mutex_lock(&con_mutex); > + ret = __mbox_bind_client(chan, cl); > + mutex_unlock(&con_mutex); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(mbox_bind_client); > + > /** > * mbox_request_channel - Request a mailbox channel. > * @cl: Identity of the client requesting the channel. > @@ -340,7 +405,6 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) > struct mbox_controller *mbox; > struct of_phandle_args spec; > struct mbox_chan *chan; > - unsigned long flags; > int ret; > > if (!dev || !dev->of_node) { > @@ -372,33 +436,9 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) > return chan; > } > > - if (chan->cl || !try_module_get(mbox->dev->driver->owner)) { > - dev_dbg(dev, "%s: mailbox not free\n", __func__); > - mutex_unlock(&con_mutex); > - return ERR_PTR(-EBUSY); > - } > - > - spin_lock_irqsave(&chan->lock, flags); > - chan->msg_free = 0; > - chan->msg_count = 0; > - chan->active_req = NULL; > - chan->cl = cl; > - init_completion(&chan->tx_complete); > - > - if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) > - chan->txdone_method = TXDONE_BY_ACK; > - > - spin_unlock_irqrestore(&chan->lock, flags); > - > - if (chan->mbox->ops->startup) { > - ret = chan->mbox->ops->startup(chan); > - > - if (ret) { > - dev_err(dev, "Unable to startup the chan (%d)\n", ret); > - mbox_free_channel(chan); > - chan = ERR_PTR(ret); > - } > - } > + ret = __mbox_bind_client(chan, cl); > + if (ret) > + chan = ERR_PTR(ret); > > mutex_unlock(&con_mutex); > return chan; > diff --git a/drivers/mailbox/omap-mailbox.c b/drivers/mailbox/omap-mailbox.c > index 098c82d87137..711a56ec8592 100644 > --- a/drivers/mailbox/omap-mailbox.c > +++ b/drivers/mailbox/omap-mailbox.c > @@ -441,21 +441,9 @@ struct mbox_chan *omap_mbox_request_channel(struct mbox_client *cl, > if (!mbox || !mbox->chan) > return ERR_PTR(-ENOENT); > > - chan = mbox->chan; > - spin_lock_irqsave(&chan->lock, flags); > - chan->msg_free = 0; > - chan->msg_count = 0; > - chan->active_req = NULL; > - chan->cl = cl; > - init_completion(&chan->tx_complete); > - spin_unlock_irqrestore(&chan->lock, flags); > - > - ret = chan->mbox->ops->startup(chan); > - if (ret) { > - pr_err("Unable to startup the chan (%d)\n", ret); > - mbox_free_channel(chan); > - chan = ERR_PTR(ret); > - } > + ret = mbox_bind_client(mbox->chan, cl); > + if (ret) > + return ERR_PTR(ret); > > return chan; > } > diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c > index 3c2bc0ca454c..f655be083369 100644 > --- a/drivers/mailbox/pcc.c > +++ b/drivers/mailbox/pcc.c > @@ -283,7 +283,7 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id) > struct pcc_chan_info *pchan; > struct mbox_chan *chan; > struct device *dev; > - unsigned long flags; > + int rc; > > if (subspace_id < 0 || subspace_id >= pcc_chan_count) > return ERR_PTR(-ENOENT); > @@ -296,21 +296,11 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id) > } > dev = chan->mbox->dev; > > - spin_lock_irqsave(&chan->lock, flags); > - chan->msg_free = 0; > - chan->msg_count = 0; > - chan->active_req = NULL; > - chan->cl = cl; > - init_completion(&chan->tx_complete); > - > - if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) > - chan->txdone_method = TXDONE_BY_ACK; > - > - spin_unlock_irqrestore(&chan->lock, flags); > + rc = mbox_bind_client(chan, cl); > + if (rc) > + return ERR_PTR(rc); > > if (pchan->plat_irq > 0) { > - int rc; > - > rc = devm_request_irq(dev, pchan->plat_irq, pcc_mbox_irq, 0, > MBOX_IRQ_NAME, chan); > if (unlikely(rc)) { > diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h > index 65229a45590f..734694912ef7 100644 > --- a/include/linux/mailbox_client.h > +++ b/include/linux/mailbox_client.h > @@ -37,6 +37,7 @@ struct mbox_client { > void (*tx_done)(struct mbox_client *cl, void *mssg, int r); > }; > > +int mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl); > struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, > const char *name); > struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel