From cc86ad157e1c8405a78c392926bf4f96afaae9c1 Mon Sep 17 00:00:00 2001 From: Teo Hall Date: Mon, 12 Sep 2016 14:12:25 -0500 Subject: [PATCH] MLK-14938-23 mailbox: enable mbox_send non-blocking use Add a timeout to allow non-blocking use in the same way as mbox_recv Signed-off-by: Teo Hall (cherry picked from commit c2296701fa91dc8d4144c84c19ffe40dba3df88c) (cherry picked from commit afcfb7e5105ef01ec46a6c896b20e210a07ee094) --- drivers/mailbox/mailbox-uclass.c | 20 ++++++++++++++++++-- include/mailbox.h | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/mailbox/mailbox-uclass.c b/drivers/mailbox/mailbox-uclass.c index 1b4a5863c9..4be4dd1d53 100644 --- a/drivers/mailbox/mailbox-uclass.c +++ b/drivers/mailbox/mailbox-uclass.c @@ -97,13 +97,29 @@ int mbox_free(struct mbox_chan *chan) return ops->free(chan); } -int mbox_send(struct mbox_chan *chan, const void *data) +int mbox_send(struct mbox_chan *chan, const void *data, ulong timeout_us) { struct mbox_ops *ops = mbox_dev_ops(chan->dev); + ulong start_time; + int ret; debug("%s(chan=%p, data=%p)\n", __func__, chan, data); - return ops->send(chan, data); + start_time = timer_get_us(); + /* + * Account for partial us ticks, but if timeout_us is 0, ensure we + * still don't wait at all. + */ + if (timeout_us) + timeout_us++; + + for (;;) { + ret = ops->send(chan, data); + if (ret != -EBUSY) + return ret; + if ((timer_get_us() - start_time) >= timeout_us) + return -ETIMEDOUT; + } } int mbox_recv(struct mbox_chan *chan, void *data, ulong timeout_us) diff --git a/include/mailbox.h b/include/mailbox.h index 93f4715e16..639ce324c0 100644 --- a/include/mailbox.h +++ b/include/mailbox.h @@ -122,7 +122,7 @@ int mbox_free(struct mbox_chan *chan); * will ignore this parameter. * @return 0 if OK, or a negative error code. */ -int mbox_send(struct mbox_chan *chan, const void *data); +int mbox_send(struct mbox_chan *chan, const void *data, ulong timeout_us); /** * mbox_recv - Receive any available message from a mailbox channel -- 2.17.1