devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Courtney Cavin <courtney.cavin@sonymobile.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: "s-anna@ti.com" <s-anna@ti.com>,
	"rob.herring@calxeda.com" <rob.herring@calxeda.com>,
	"rafael.j.wysocki@intel.com" <rafael.j.wysocki@intel.com>,
	"mark.langsdorf@calxeda.com" <mark.langsdorf@calxeda.com>,
	"tony@atomide.com" <tony@atomide.com>,
	"omar.ramirez@copitl.com" <omar.ramirez@copitl.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"pawel.moll@arm.com" <pawel.moll@arm.com>,
	"mark.rutland@arm.com" <mark.rutland@arm.com>,
	"ijc+devicetree@hellion.org.uk" <ijc+devicetree@hellion.org.uk>,
	"galak@codeaurora.org" <galak@codeaurora.org>,
	"rob@landley.net" <rob@landley.net>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC 1/6] mailbox: add core framework
Date: Mon, 10 Feb 2014 09:17:06 -0800	[thread overview]
Message-ID: <20140210171706.GR1706@sonymobile.com> (raw)
In-Reply-To: <4706525.lB7VmvWQMJ@wuerfel>

On Mon, Feb 10, 2014 at 03:11:00PM +0100, Arnd Bergmann wrote:
> On Friday 07 February 2014 16:50:14 Courtney Cavin wrote:
> > The mailbox drivers are fragmented, and some implement their own core.
> > Unify the drivers and implement common functionality in a framework.
> > 
> > Signed-off-by: Courtney Cavin <courtney.cavin@sonymobile.com>
> 
> This seems pretty cool overall, great to see someone getting at it@

I'm glad to hear that there's some interest!

> > +static void of_mbox_adapter_add(struct mbox_adapter *adap)
> > +{
> > +	if (!adap->dev)
> > +		return;
> > +
> > +	if (!adap->of_xlate) {
> > +		adap->of_xlate = of_mbox_simple_xlate;
> > +		adap->of_n_cells = 1;
> > +	}
> > +
> > +	of_node_get(adap->dev->of_node);
> > +}
> 
> You should probably check if of_n_cells matches the device node
> #mbox-cells value, otherwise the xlate function will get confused.

Ok.  I was under the impression that the adapter implementations would
add something like that, but I see no reason why putting it here would
hurt.

> > +
> > +	mutex_lock(&mbox_lock);
> > +	list_add(&adap->list, &mbox_adapters);
> > +
> > +	of_mbox_adapter_add(adap);
> > +	mutex_unlock(&mbox_lock);
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(mbox_adapter_add);
> 
> Please use EXPORT_SYMBOL_GPL here and elsewhere.

Ok.

> > +/**
> > + * mbox_channel_notify() - notify the core that a channel has a message
> > + * @chan: the channel which has data
> > + * @data: the location of said data
> > + * @len: the length of specified data
> > + *
> > + * This function may be called from interrupt/no-sleep context.
> > + */
> > +int mbox_channel_notify(struct mbox_channel *chan,
> > +		const void *data, unsigned int len)
> > +{
> > +	return atomic_notifier_call_chain(&chan->notifier, len, (void *)data);
> > +}
> > +EXPORT_SYMBOL(mbox_channel_notify);
> 
> What is the reason to use a notifier chain here? Isn't a simple
> callback function pointer enough? I would expect that each mailbox
> can have exactly one consumer, not multiple ones.

Mostly because I didn't see a reason not to.  While a callback function
(and private data) would probably be sufficient, I don't see a specific
reason why a mailbox cannot have multiple consumers, and the API
currently is designed around that concept.

> > +/**
> > + * mbox_add_table() - add a lookup table for adapter consumers
> > + * @table: array of consumers to register
> > + * @num: number of consumers in array
> > + */
> > +void __init mbox_add_table(struct mbox_lookup *table, unsigned int num)
> > +{
> > +	mutex_lock(&mbox_lookup_lock);
> > +	while (num--) {
> > +		if (table->provider && (table->dev_id || table->con_id))
> > +			list_add_tail(&table->list, &mbox_lookup_list);
> > +		table++;
> > +	}
> > +	mutex_unlock(&mbox_lookup_lock);
> > +}
> > +EXPORT_SYMBOL(mbox_add_table);
> 
> I don't understand this part of the API. Why do you need a separate
> lookup table here? Isn't that what the DT lookup does already?

It is.  The lookup/table stuff here is specifically for non-DT-based
mailboxes.

> > +/**
> > + * mbox_request() - lookup and request a MBOX channel
> > + * @dev: device for channel consumer
> > + * @con_id: consumer name
> > + * @nb: notifier block used for receiving messages
> > + *
> > + * The notifier is called as atomic on new messages, so you may not sleep
> > + * in the notifier callback function.
> > + */
> > +struct mbox *mbox_request(struct device *dev, const char *con_id,
> > +		struct notifier_block *nb)
> > +{
> > +	struct mbox_adapter *adap;
> > +	struct mbox_channel *chan;
> > +	struct mbox *mbox;
> > +	int index = 0;
> > +
> > +	if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node)
> > +		return of_mbox_request(dev->of_node, con_id, nb);
> 
> What use case do you have in mind for !CONFIG_OF?

None particularly, except for the existing implementations in
drivers/mailbox.  I simply presumed it wouldn't hurt to implement lookup
tables similar to those the pwm core.

> > +/**
> > + * struct mbox_adapter_ops - MBOX adapter operations
> > + * @put_message: hook for putting messages in the channels MBOX
> > + * @request: optional hook for requesting an MBOX channel
> > + * @release: optional hook for releasing an MBOX channel
> > + * @owner: helps prevent removal of modules exporting active MBOX channels
> > + */
> > +struct mbox_adapter_ops {
> > +	int (*put_message)(struct mbox_adapter *, struct mbox_channel *,
> > +				const void *, unsigned int);
> > +	int (*request)(struct mbox_adapter *, struct mbox_channel *);
> > +	int (*release)(struct mbox_adapter *, struct mbox_channel *);
> > +	struct module *owner;
> > +};
> 
> I think we will need a peek_message() callback for the upcoming
> QMTM driver, to allow client drivers to get a message out before
> the mailbox driver gets an IRQ. This will be used for IRQ mitigation
> in the network driver.

Eeek!  I'm not very fond of 'peek' functions, but I guess I can see a
reason for IRQ mitigation here.  I still cannot help but to try to think
my way out of implementing peek.

What would be the callback flow here?  There's no guarantee that a
mailbox implementation isn't implemented over a sleepy bus, which would
render peek somewhat useless.  Additionally, we have the adapter
protection mutex which can sleep anyway.  This means that a consumer can
not call peek from anywhere atomic, including a notifier, which I think
is your use-case.

Perhaps a FEED_ME return from a notifier, requesting more 'mail' if
available?

> 
> 	Arnd

Thanks for looking!  I appreciate the feedback.

-Courtney

  reply	other threads:[~2014-02-10 17:17 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-08  0:50 [RFC 0/6] mailbox: add common framework and port drivers Courtney Cavin
     [not found] ` <1391820619-25487-1-git-send-email-courtney.cavin-/MT0OVThwyLZJqsBc5GL+g@public.gmane.org>
2014-02-08  0:50   ` [RFC 1/6] mailbox: add core framework Courtney Cavin
2014-02-10 14:11     ` Arnd Bergmann
2014-02-10 17:17       ` Courtney Cavin [this message]
2014-02-10 17:52       ` Rob Herring
2014-02-10 19:09         ` Josh Cartwright
2014-02-10 19:59           ` Courtney Cavin
2014-02-10 20:45             ` Rob Herring
2014-02-11  0:23               ` Courtney Cavin
2014-02-11  8:35                 ` Arnd Bergmann
2014-02-12 18:31                   ` Courtney Cavin
2014-02-14 19:48                     ` Arnd Bergmann
2014-02-14 20:16                       ` Courtney Cavin
2014-02-08  0:50 ` [RFC 2/6] mailbox: document bindings Courtney Cavin
2014-02-08  0:50 ` [RFC 3/6] mailbox: pl320: migrate to mbox framework Courtney Cavin
2014-02-10 18:28   ` Rob Herring
2014-02-10 19:12     ` Courtney Cavin
2014-02-08  0:50 ` [RFC 4/6] mailbox: omap: remove omap-specific framework Courtney Cavin
2014-02-08  0:50 ` [RFC 5/6] mailbox: omap1: move to common mbox framework Courtney Cavin
2014-02-08  0:50 ` [RFC 6/6] mailbox: omap2+: " Courtney Cavin
2014-02-15  3:32 ` [RFC 0/6] mailbox: add common framework and port drivers Jassi Brar
2014-02-15  3:40   ` Greg Kroah-Hartman
2014-02-15  3:57     ` Jassi Brar
2014-02-15  4:11       ` Greg Kroah-Hartman
2014-02-15  4:14         ` Jassi Brar

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=20140210171706.GR1706@sonymobile.com \
    --to=courtney.cavin@sonymobile.com \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.langsdorf@calxeda.com \
    --cc=mark.rutland@arm.com \
    --cc=omar.ramirez@copitl.com \
    --cc=pawel.moll@arm.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=s-anna@ti.com \
    --cc=tony@atomide.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).