LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Jon Hunter <jonathanh@nvidia.com>
To: Mikko Perttunen <mperttunen@nvidia.com>, <robh+dt@kernel.org>,
	<mark.rutland@arm.com>, <jassisinghbrar@gmail.com>,
	<gregkh@linuxfoundation.org>, <thierry.reding@gmail.com>
Cc: <araza@nvidia.com>, <devicetree@vger.kernel.org>,
	<linux-serial@vger.kernel.org>, <linux-tegra@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 4/8] mailbox: tegra-hsp: Refactor in preparation of mailboxes
Date: Tue, 22 May 2018 16:36:24 +0100	[thread overview]
Message-ID: <8306b033-e7f5-748c-6e6a-131dfd6a26b8@nvidia.com> (raw)
In-Reply-To: <20180508114403.14499-5-mperttunen@nvidia.com>


On 08/05/18 12:43, Mikko Perttunen wrote:
> The HSP driver is currently in many places written with the assumption
> of only supporting doorbells. Prepare for the addition of shared
> mailbox support by removing these assumptions and cleaning up the code.
> 
> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> ---
>   drivers/mailbox/tegra-hsp.c | 124 +++++++++++++++++++++++++++++---------------
>   1 file changed, 82 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/mailbox/tegra-hsp.c b/drivers/mailbox/tegra-hsp.c
> index 0cde356c11ab..16eb970f2c9f 100644
> --- a/drivers/mailbox/tegra-hsp.c
> +++ b/drivers/mailbox/tegra-hsp.c
> @@ -1,5 +1,5 @@
>   /*
> - * Copyright (c) 2016, NVIDIA CORPORATION.  All rights reserved.
> + * Copyright (c) 2016-2018, NVIDIA CORPORATION.  All rights reserved.
>    *
>    * This program is free software; you can redistribute it and/or modify it
>    * under the terms and conditions of the GNU General Public License,
> @@ -42,6 +42,7 @@ struct tegra_hsp_channel;
>   struct tegra_hsp;
>   
>   struct tegra_hsp_channel {
> +	unsigned int type;
>   	struct tegra_hsp *hsp;
>   	struct mbox_chan *chan;
>   	void __iomem *regs;
> @@ -55,6 +56,12 @@ struct tegra_hsp_doorbell {
>   	unsigned int index;
>   };
>   
> +static inline struct tegra_hsp_doorbell *
> +channel_to_doorbell(struct tegra_hsp_channel *channel)
> +{
> +	return container_of(channel, struct tegra_hsp_doorbell, channel);
> +}
> +
>   struct tegra_hsp_db_map {
>   	const char *name;
>   	unsigned int master;
> @@ -69,7 +76,7 @@ struct tegra_hsp {
>   	const struct tegra_hsp_soc *soc;
>   	struct mbox_controller mbox;
>   	void __iomem *regs;
> -	unsigned int irq;
> +	unsigned int doorbell_irq;
>   	unsigned int num_sm;
>   	unsigned int num_as;
>   	unsigned int num_ss;
> @@ -194,7 +201,7 @@ tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name,
>   	if (!db)
>   		return ERR_PTR(-ENOMEM);
>   
> -	offset = (1 + (hsp->num_sm / 2) + hsp->num_ss + hsp->num_as) << 16;
> +	offset = (1 + (hsp->num_sm / 2) + hsp->num_ss + hsp->num_as) * SZ_64K;
>   	offset += index * 0x100;
>   
>   	db->channel.regs = hsp->regs + offset;
> @@ -218,18 +225,8 @@ static void __tegra_hsp_doorbell_destroy(struct tegra_hsp_doorbell *db)
>   	kfree(db);
>   }
>   
> -static int tegra_hsp_doorbell_send_data(struct mbox_chan *chan, void *data)
> -{
> -	struct tegra_hsp_doorbell *db = chan->con_priv;
> -
> -	tegra_hsp_channel_writel(&db->channel, 1, HSP_DB_TRIGGER);
> -
> -	return 0;
> -}
> -
> -static int tegra_hsp_doorbell_startup(struct mbox_chan *chan)
> +static int tegra_hsp_doorbell_startup(struct tegra_hsp_doorbell *db)
>   {
> -	struct tegra_hsp_doorbell *db = chan->con_priv;
>   	struct tegra_hsp *hsp = db->channel.hsp;
>   	struct tegra_hsp_doorbell *ccplex;
>   	unsigned long flags;
> @@ -260,9 +257,8 @@ static int tegra_hsp_doorbell_startup(struct mbox_chan *chan)
>   	return 0;
>   }
>   
> -static void tegra_hsp_doorbell_shutdown(struct mbox_chan *chan)
> +static void tegra_hsp_doorbell_shutdown(struct tegra_hsp_doorbell *db)
>   {
> -	struct tegra_hsp_doorbell *db = chan->con_priv;
>   	struct tegra_hsp *hsp = db->channel.hsp;
>   	struct tegra_hsp_doorbell *ccplex;
>   	unsigned long flags;
> @@ -281,35 +277,61 @@ static void tegra_hsp_doorbell_shutdown(struct mbox_chan *chan)
>   	spin_unlock_irqrestore(&hsp->lock, flags);
>   }
>   
> -static const struct mbox_chan_ops tegra_hsp_doorbell_ops = {
> -	.send_data = tegra_hsp_doorbell_send_data,
> -	.startup = tegra_hsp_doorbell_startup,
> -	.shutdown = tegra_hsp_doorbell_shutdown,
> +static int tegra_hsp_send_data(struct mbox_chan *chan, void *data)
> +{
> +	struct tegra_hsp_channel *channel = chan->con_priv;
> +	struct tegra_hsp_doorbell *db;
> +
> +	switch (channel->type) {
> +	case TEGRA_HSP_MBOX_TYPE_DB:
> +		db = channel_to_doorbell(channel);
> +		tegra_hsp_channel_writel(&db->channel, 1, HSP_DB_TRIGGER);

The above appears to be redundant. We go from channel to db and then end 
up passing channels. Do we really need the 'db' struct above?

> +	}
> +
> +	return -EINVAL;

Does this function always return -EINVAL?

> +}
> +
> +static int tegra_hsp_startup(struct mbox_chan *chan)
> +{
> +	struct tegra_hsp_channel *channel = chan->con_priv;
> +
> +	switch (channel->type) {
> +	case TEGRA_HSP_MBOX_TYPE_DB:
> +		return tegra_hsp_doorbell_startup(channel_to_doorbell(channel));
> +	}
> +
> +	return -EINVAL;
> +}
> +
> +static void tegra_hsp_shutdown(struct mbox_chan *chan)
> +{
> +	struct tegra_hsp_channel *channel = chan->con_priv;
> +
> +	switch (channel->type) {
> +	case TEGRA_HSP_MBOX_TYPE_DB:
> +		tegra_hsp_doorbell_shutdown(channel_to_doorbell(channel));
> +		break;
> +	}
> +}
> +
> +static const struct mbox_chan_ops tegra_hsp_ops = {
> +	.send_data = tegra_hsp_send_data,
> +	.startup = tegra_hsp_startup,
> +	.shutdown = tegra_hsp_shutdown,
>   };
>   
> -static struct mbox_chan *of_tegra_hsp_xlate(struct mbox_controller *mbox,
> -					    const struct of_phandle_args *args)
> +static struct mbox_chan *tegra_hsp_doorbell_xlate(struct tegra_hsp *hsp,
> +						  unsigned int master)
>   {
>   	struct tegra_hsp_channel *channel = ERR_PTR(-ENODEV);
> -	struct tegra_hsp *hsp = to_tegra_hsp(mbox);
> -	unsigned int type = args->args[0];
> -	unsigned int master = args->args[1];
>   	struct tegra_hsp_doorbell *db;
>   	struct mbox_chan *chan;
>   	unsigned long flags;
>   	unsigned int i;
>   
> -	switch (type) {
> -	case TEGRA_HSP_MBOX_TYPE_DB:
> -		db = tegra_hsp_doorbell_get(hsp, master);
> -		if (db)
> -			channel = &db->channel;
> -
> -		break;
> -
> -	default:
> -		break;
> -	}
> +	db = tegra_hsp_doorbell_get(hsp, master);
> +	if (db)
> +		channel = &db->channel;
>   
>   	if (IS_ERR(channel))
>   		return ERR_CAST(channel);
> @@ -321,6 +343,7 @@ static struct mbox_chan *of_tegra_hsp_xlate(struct mbox_controller *mbox,
>   		if (!chan->con_priv) {
>   			chan->con_priv = channel;
>   			channel->chan = chan;
> +			channel->type = TEGRA_HSP_MBOX_TYPE_DB;
>   			break;

I see that you are making the above only used for doorbells, but don't 
we still need to set the chan->con_priv for shared mailboxes as well?

Cheers
Jon

-- 
nvpublic

  reply	other threads:[~2018-05-22 15:36 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-08 11:43 [PATCH 0/8] Tegra Combined UART driver Mikko Perttunen
2018-05-08 11:43 ` [PATCH 1/8] dt-bindings: tegra186-hsp: Add shared interrupts Mikko Perttunen
2018-05-22 15:15   ` Jon Hunter
2018-06-19 12:41     ` Mikko Perttunen
2018-05-08 11:43 ` [PATCH 2/8] dt-bindings: serial: Add bindings for nvidia,tegra194-tcu Mikko Perttunen
2018-05-22 15:15   ` Jon Hunter
2018-05-22 20:18     ` Rob Herring
2018-05-22 20:20   ` Rob Herring
2018-05-08 11:43 ` [PATCH 3/8] mailbox: Add transmit done by blocking option Mikko Perttunen
2018-05-08 11:43 ` [PATCH 4/8] mailbox: tegra-hsp: Refactor in preparation of mailboxes Mikko Perttunen
2018-05-22 15:36   ` Jon Hunter [this message]
2018-06-19 12:52     ` Mikko Perttunen
2018-05-08 11:44 ` [PATCH 5/8] mailbox: tegra-hsp: Add support for shared mailboxes Mikko Perttunen
2018-05-22 16:20   ` Jon Hunter
2018-05-08 11:44 ` [PATCH 6/8] serial: Add Tegra Combined UART driver Mikko Perttunen
2018-05-13 14:16   ` Andy Shevchenko
2018-05-13 18:04     ` Mikko Perttunen
2018-05-13 22:20       ` Andy Shevchenko
2018-05-14  7:36         ` Mikko Perttunen
2018-05-13 15:36   ` Jassi Brar
2018-05-13 18:06     ` Mikko Perttunen
2018-05-08 11:44 ` [PATCH 7/8] arm64: tegra: Add nodes for tcu on Tegra194 Mikko Perttunen
2018-05-22 16:28   ` Jon Hunter
2018-05-08 11:44 ` [PATCH 8/8] arm64: tegra: Mark tcu as primary serial port on Tegra194 P2888 Mikko Perttunen
2018-05-22 16:29   ` Jon Hunter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8306b033-e7f5-748c-6e6a-131dfd6a26b8@nvidia.com \
    --to=jonathanh@nvidia.com \
    --cc=araza@nvidia.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jassisinghbrar@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mperttunen@nvidia.com \
    --cc=robh+dt@kernel.org \
    --cc=thierry.reding@gmail.com \
    --subject='Re: [PATCH 4/8] mailbox: tegra-hsp: Refactor in preparation of mailboxes' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).