aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2018-11-28 04:54:10 -0500
committerJassi Brar <jaswinder.singh@linaro.org>2018-12-21 23:31:26 -0500
commita8803d7421cc2be2ac12a8155e5d824f04259eff (patch)
tree76495c4a0e449dfaedfc1dc39b65f39ec8a33f67
parent2298a6f09f455f64bf253e6fb5c1ff72f38a6249 (diff)
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: Thierry Reding <treding@nvidia.com> Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
-rw-r--r--drivers/mailbox/mailbox.c28
-rw-r--r--include/linux/mailbox_client.h1
-rw-r--r--include/linux/mailbox_controller.h4
3 files changed, 33 insertions, 0 deletions
diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index 08ce9a1ab53a..6abb35ff49fa 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -284,6 +284,34 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg)
284EXPORT_SYMBOL_GPL(mbox_send_message); 284EXPORT_SYMBOL_GPL(mbox_send_message);
285 285
286/** 286/**
287 * mbox_flush - flush a mailbox channel
288 * @chan: mailbox channel to flush
289 * @timeout: time, in milliseconds, to allow the flush operation to succeed
290 *
291 * Mailbox controllers that need to work in atomic context can implement the
292 * ->flush() callback to busy loop until a transmission has been completed.
293 * The implementation must call mbox_chan_txdone() upon success. Clients can
294 * call the mbox_flush() function at any time after mbox_send_message() to
295 * flush the transmission. After the function returns success, the mailbox
296 * transmission is guaranteed to have completed.
297 *
298 * Returns: 0 on success or a negative error code on failure.
299 */
300int mbox_flush(struct mbox_chan *chan, unsigned long timeout)
301{
302 int ret;
303
304 if (!chan->mbox->ops->flush)
305 return -ENOTSUPP;
306
307 ret = chan->mbox->ops->flush(chan, timeout);
308 if (ret < 0)
309 tx_tick(chan, ret);
310
311 return ret;
312}
313
314/**
287 * mbox_request_channel - Request a mailbox channel. 315 * mbox_request_channel - Request a mailbox channel.
288 * @cl: Identity of the client requesting the channel. 316 * @cl: Identity of the client requesting the channel.
289 * @index: Index of mailbox specifier in 'mboxes' property. 317 * @index: Index of mailbox specifier in 'mboxes' property.
diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h
index 44348710953f..faa7da3c9c8b 100644
--- a/include/linux/mailbox_client.h
+++ b/include/linux/mailbox_client.h
@@ -44,6 +44,7 @@ struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl,
44 const char *name); 44 const char *name);
45struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index); 45struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index);
46int mbox_send_message(struct mbox_chan *chan, void *mssg); 46int mbox_send_message(struct mbox_chan *chan, void *mssg);
47int mbox_flush(struct mbox_chan *chan, unsigned long timeout);
47void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */ 48void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */
48bool mbox_client_peek_data(struct mbox_chan *chan); /* atomic */ 49bool mbox_client_peek_data(struct mbox_chan *chan); /* atomic */
49void mbox_free_channel(struct mbox_chan *chan); /* may sleep */ 50void mbox_free_channel(struct mbox_chan *chan); /* may sleep */
diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h
index 9b0b21207345..4994a438444c 100644
--- a/include/linux/mailbox_controller.h
+++ b/include/linux/mailbox_controller.h
@@ -24,6 +24,9 @@ struct mbox_chan;
24 * transmission of data is reported by the controller via 24 * transmission of data is reported by the controller via
25 * mbox_chan_txdone (if it has some TX ACK irq). It must not 25 * mbox_chan_txdone (if it has some TX ACK irq). It must not
26 * sleep. 26 * sleep.
27 * @flush: Called when a client requests transmissions to be blocking but
28 * the context doesn't allow sleeping. Typically the controller
29 * will implement a busy loop waiting for the data to flush out.
27 * @startup: Called when a client requests the chan. The controller 30 * @startup: Called when a client requests the chan. The controller
28 * could ask clients for additional parameters of communication 31 * could ask clients for additional parameters of communication
29 * to be provided via client's chan_data. This call may 32 * to be provided via client's chan_data. This call may
@@ -46,6 +49,7 @@ struct mbox_chan;
46 */ 49 */
47struct mbox_chan_ops { 50struct mbox_chan_ops {
48 int (*send_data)(struct mbox_chan *chan, void *data); 51 int (*send_data)(struct mbox_chan *chan, void *data);
52 int (*flush)(struct mbox_chan *chan, unsigned long timeout);
49 int (*startup)(struct mbox_chan *chan); 53 int (*startup)(struct mbox_chan *chan);
50 void (*shutdown)(struct mbox_chan *chan); 54 void (*shutdown)(struct mbox_chan *chan);
51 bool (*last_tx_done)(struct mbox_chan *chan); 55 bool (*last_tx_done)(struct mbox_chan *chan);