Commit a8803d74 authored by Thierry Reding's avatar Thierry Reding Committed by Jassi Brar

mailbox: Support blocking transfers in atomic context

The mailbox framework supports blocking transfers via completions for
clients that can sleep. In order to support blocking transfers in cases
where the transmission is not permitted to sleep, add a new ->flush()
callback that controller drivers can implement to busy loop until the
transmission has been completed. A new mbox_flush() function can be
called by mailbox consumers in atomic context to make sure a transfer
has completed.
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
Signed-off-by: default avatarJassi Brar <jaswinder.singh@linaro.org>
parent 2298a6f0
...@@ -283,6 +283,34 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg) ...@@ -283,6 +283,34 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg)
} }
EXPORT_SYMBOL_GPL(mbox_send_message); EXPORT_SYMBOL_GPL(mbox_send_message);
/**
* mbox_flush - flush a mailbox channel
* @chan: mailbox channel to flush
* @timeout: time, in milliseconds, to allow the flush operation to succeed
*
* Mailbox controllers that need to work in atomic context can implement the
* ->flush() callback to busy loop until a transmission has been completed.
* The implementation must call mbox_chan_txdone() upon success. Clients can
* call the mbox_flush() function at any time after mbox_send_message() to
* flush the transmission. After the function returns success, the mailbox
* transmission is guaranteed to have completed.
*
* Returns: 0 on success or a negative error code on failure.
*/
int mbox_flush(struct mbox_chan *chan, unsigned long timeout)
{
int ret;
if (!chan->mbox->ops->flush)
return -ENOTSUPP;
ret = chan->mbox->ops->flush(chan, timeout);
if (ret < 0)
tx_tick(chan, ret);
return ret;
}
/** /**
* mbox_request_channel - Request a mailbox channel. * mbox_request_channel - Request a mailbox channel.
* @cl: Identity of the client requesting the channel. * @cl: Identity of the client requesting the channel.
......
...@@ -44,6 +44,7 @@ struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl, ...@@ -44,6 +44,7 @@ struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl,
const char *name); const char *name);
struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index); struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index);
int mbox_send_message(struct mbox_chan *chan, void *mssg); int mbox_send_message(struct mbox_chan *chan, void *mssg);
int mbox_flush(struct mbox_chan *chan, unsigned long timeout);
void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */ void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */
bool mbox_client_peek_data(struct mbox_chan *chan); /* atomic */ bool mbox_client_peek_data(struct mbox_chan *chan); /* atomic */
void mbox_free_channel(struct mbox_chan *chan); /* may sleep */ void mbox_free_channel(struct mbox_chan *chan); /* may sleep */
......
...@@ -24,6 +24,9 @@ struct mbox_chan; ...@@ -24,6 +24,9 @@ struct mbox_chan;
* transmission of data is reported by the controller via * transmission of data is reported by the controller via
* mbox_chan_txdone (if it has some TX ACK irq). It must not * mbox_chan_txdone (if it has some TX ACK irq). It must not
* sleep. * sleep.
* @flush: Called when a client requests transmissions to be blocking but
* the context doesn't allow sleeping. Typically the controller
* will implement a busy loop waiting for the data to flush out.
* @startup: Called when a client requests the chan. The controller * @startup: Called when a client requests the chan. The controller
* could ask clients for additional parameters of communication * could ask clients for additional parameters of communication
* to be provided via client's chan_data. This call may * to be provided via client's chan_data. This call may
...@@ -46,6 +49,7 @@ struct mbox_chan; ...@@ -46,6 +49,7 @@ struct mbox_chan;
*/ */
struct mbox_chan_ops { struct mbox_chan_ops {
int (*send_data)(struct mbox_chan *chan, void *data); int (*send_data)(struct mbox_chan *chan, void *data);
int (*flush)(struct mbox_chan *chan, unsigned long timeout);
int (*startup)(struct mbox_chan *chan); int (*startup)(struct mbox_chan *chan);
void (*shutdown)(struct mbox_chan *chan); void (*shutdown)(struct mbox_chan *chan);
bool (*last_tx_done)(struct mbox_chan *chan); bool (*last_tx_done)(struct mbox_chan *chan);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment