• Home
  • Raw
  • Download

Lines Matching +full:buffered +full:- +full:negative

4  * Copyright (C) 2013-2014 Linaro Ltd.
34 spin_lock_irqsave(&chan->lock, flags); in add_to_rbuf()
37 if (chan->msg_count == MBOX_TX_QUEUE_LEN) { in add_to_rbuf()
38 spin_unlock_irqrestore(&chan->lock, flags); in add_to_rbuf()
39 return -ENOBUFS; in add_to_rbuf()
42 idx = chan->msg_free; in add_to_rbuf()
43 chan->msg_data[idx] = mssg; in add_to_rbuf()
44 chan->msg_count++; in add_to_rbuf()
46 if (idx == MBOX_TX_QUEUE_LEN - 1) in add_to_rbuf()
47 chan->msg_free = 0; in add_to_rbuf()
49 chan->msg_free++; in add_to_rbuf()
51 spin_unlock_irqrestore(&chan->lock, flags); in add_to_rbuf()
61 int err = -EBUSY; in msg_submit()
63 spin_lock_irqsave(&chan->lock, flags); in msg_submit()
65 if (!chan->msg_count || chan->active_req) in msg_submit()
68 count = chan->msg_count; in msg_submit()
69 idx = chan->msg_free; in msg_submit()
71 idx -= count; in msg_submit()
73 idx += MBOX_TX_QUEUE_LEN - count; in msg_submit()
75 data = chan->msg_data[idx]; in msg_submit()
77 if (chan->cl->tx_prepare) in msg_submit()
78 chan->cl->tx_prepare(chan->cl, data); in msg_submit()
80 err = chan->mbox->ops->send_data(chan, data); in msg_submit()
82 chan->active_req = data; in msg_submit()
83 chan->msg_count--; in msg_submit()
86 spin_unlock_irqrestore(&chan->lock, flags); in msg_submit()
89 if (!err && (chan->txdone_method & TXDONE_BY_POLL)) { in msg_submit()
91 if (!hrtimer_active(&chan->mbox->poll_hrt)) in msg_submit()
92 hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); in msg_submit()
101 spin_lock_irqsave(&chan->lock, flags); in tx_tick()
102 mssg = chan->active_req; in tx_tick()
103 chan->active_req = NULL; in tx_tick()
104 spin_unlock_irqrestore(&chan->lock, flags); in tx_tick()
113 if (chan->cl->tx_done) in tx_tick()
114 chan->cl->tx_done(chan->cl, mssg, r); in tx_tick()
116 if (r != -ETIME && chan->cl->tx_block) in tx_tick()
117 complete(&chan->tx_complete); in tx_tick()
127 for (i = 0; i < mbox->num_chans; i++) { in txdone_hrtimer()
128 struct mbox_chan *chan = &mbox->chans[i]; in txdone_hrtimer()
130 if (chan->active_req && chan->cl) { in txdone_hrtimer()
132 txdone = chan->mbox->ops->last_tx_done(chan); in txdone_hrtimer()
139 hrtimer_forward_now(hrtimer, ms_to_ktime(mbox->txpoll_period)); in txdone_hrtimer()
146 * mbox_chan_received_data - A way for controller driver to push data
158 if (chan->cl->rx_callback) in mbox_chan_received_data()
159 chan->cl->rx_callback(chan->cl, mssg); in mbox_chan_received_data()
164 * mbox_chan_txdone - A way for controller driver to notify the
167 * @r: Status of last TX - OK or ERROR
175 if (unlikely(!(chan->txdone_method & TXDONE_BY_IRQ))) { in mbox_chan_txdone()
176 dev_err(chan->mbox->dev, in mbox_chan_txdone()
186 * mbox_client_txdone - The way for a client to run the TX state machine.
192 * if the controller can't sense TX-Done.
196 if (unlikely(!(chan->txdone_method & TXDONE_BY_ACK))) { in mbox_client_txdone()
197 dev_err(chan->mbox->dev, "Client can't run the TX ticker\n"); in mbox_client_txdone()
206 * mbox_client_peek_data - A way for client driver to pull data
222 if (chan->mbox->ops->peek_data) in mbox_client_peek_data()
223 return chan->mbox->ops->peek_data(chan); in mbox_client_peek_data()
230 * mbox_send_message - For client to submit a message to be
239 * In non-blocking mode, the requests are buffered by the API and a
240 * non-negative token is returned for each queued request. If the request
241 * is not queued, a negative token is returned. Upon failure or successful
249 * Return: Non-negative integer for successful submission (non-blocking mode)
251 * Negative value denotes failure.
257 if (!chan || !chan->cl) in mbox_send_message()
258 return -EINVAL; in mbox_send_message()
262 dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n"); in mbox_send_message()
268 if (chan->cl->tx_block) { in mbox_send_message()
272 if (!chan->cl->tx_tout) /* wait forever */ in mbox_send_message()
275 wait = msecs_to_jiffies(chan->cl->tx_tout); in mbox_send_message()
277 ret = wait_for_completion_timeout(&chan->tx_complete, wait); in mbox_send_message()
279 t = -ETIME; in mbox_send_message()
289 * mbox_request_channel - Request a mailbox channel.
307 struct device *dev = cl->dev; in mbox_request_channel()
314 if (!dev || !dev->of_node) { in mbox_request_channel()
316 return ERR_PTR(-ENODEV); in mbox_request_channel()
321 if (of_parse_phandle_with_args(dev->of_node, "mboxes", in mbox_request_channel()
322 "#mbox-cells", index, &spec)) { in mbox_request_channel()
325 return ERR_PTR(-ENODEV); in mbox_request_channel()
328 chan = ERR_PTR(-EPROBE_DEFER); in mbox_request_channel()
330 if (mbox->dev->of_node == spec.np) { in mbox_request_channel()
331 chan = mbox->of_xlate(mbox, &spec); in mbox_request_channel()
342 if (chan->cl || !try_module_get(mbox->dev->driver->owner)) { in mbox_request_channel()
345 return ERR_PTR(-EBUSY); in mbox_request_channel()
348 spin_lock_irqsave(&chan->lock, flags); in mbox_request_channel()
349 chan->msg_free = 0; in mbox_request_channel()
350 chan->msg_count = 0; in mbox_request_channel()
351 chan->active_req = NULL; in mbox_request_channel()
352 chan->cl = cl; in mbox_request_channel()
353 init_completion(&chan->tx_complete); in mbox_request_channel()
355 if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) in mbox_request_channel()
356 chan->txdone_method = TXDONE_BY_ACK; in mbox_request_channel()
358 spin_unlock_irqrestore(&chan->lock, flags); in mbox_request_channel()
360 if (chan->mbox->ops->startup) { in mbox_request_channel()
361 ret = chan->mbox->ops->startup(chan); in mbox_request_channel()
378 struct device_node *np = cl->dev->of_node; in mbox_request_channel_byname()
384 dev_err(cl->dev, "%s() currently only supports DT\n", __func__); in mbox_request_channel_byname()
385 return ERR_PTR(-EINVAL); in mbox_request_channel_byname()
388 if (!of_get_property(np, "mbox-names", NULL)) { in mbox_request_channel_byname()
389 dev_err(cl->dev, in mbox_request_channel_byname()
390 "%s() requires an \"mbox-names\" property\n", __func__); in mbox_request_channel_byname()
391 return ERR_PTR(-EINVAL); in mbox_request_channel_byname()
394 of_property_for_each_string(np, "mbox-names", prop, mbox_name) { in mbox_request_channel_byname()
400 dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n", in mbox_request_channel_byname()
402 return ERR_PTR(-EINVAL); in mbox_request_channel_byname()
407 * mbox_free_channel - The client relinquishes control of a mailbox
415 if (!chan || !chan->cl) in mbox_free_channel()
418 if (chan->mbox->ops->shutdown) in mbox_free_channel()
419 chan->mbox->ops->shutdown(chan); in mbox_free_channel()
422 spin_lock_irqsave(&chan->lock, flags); in mbox_free_channel()
423 chan->cl = NULL; in mbox_free_channel()
424 chan->active_req = NULL; in mbox_free_channel()
425 if (chan->txdone_method == TXDONE_BY_ACK) in mbox_free_channel()
426 chan->txdone_method = TXDONE_BY_POLL; in mbox_free_channel()
428 module_put(chan->mbox->dev->driver->owner); in mbox_free_channel()
429 spin_unlock_irqrestore(&chan->lock, flags); in mbox_free_channel()
437 int ind = sp->args[0]; in of_mbox_index_xlate()
439 if (ind >= mbox->num_chans) in of_mbox_index_xlate()
440 return ERR_PTR(-EINVAL); in of_mbox_index_xlate()
442 return &mbox->chans[ind]; in of_mbox_index_xlate()
446 * mbox_controller_register - Register the mailbox controller
456 if (!mbox || !mbox->dev || !mbox->ops || !mbox->num_chans) in mbox_controller_register()
457 return -EINVAL; in mbox_controller_register()
459 if (mbox->txdone_irq) in mbox_controller_register()
461 else if (mbox->txdone_poll) in mbox_controller_register()
468 if (!mbox->ops->last_tx_done) { in mbox_controller_register()
469 dev_err(mbox->dev, "last_tx_done method is absent\n"); in mbox_controller_register()
470 return -EINVAL; in mbox_controller_register()
473 hrtimer_init(&mbox->poll_hrt, CLOCK_MONOTONIC, in mbox_controller_register()
475 mbox->poll_hrt.function = txdone_hrtimer; in mbox_controller_register()
478 for (i = 0; i < mbox->num_chans; i++) { in mbox_controller_register()
479 struct mbox_chan *chan = &mbox->chans[i]; in mbox_controller_register()
481 chan->cl = NULL; in mbox_controller_register()
482 chan->mbox = mbox; in mbox_controller_register()
483 chan->txdone_method = txdone; in mbox_controller_register()
484 spin_lock_init(&chan->lock); in mbox_controller_register()
487 if (!mbox->of_xlate) in mbox_controller_register()
488 mbox->of_xlate = of_mbox_index_xlate; in mbox_controller_register()
491 list_add_tail(&mbox->node, &mbox_cons); in mbox_controller_register()
499 * mbox_controller_unregister - Unregister the mailbox controller
511 list_del(&mbox->node); in mbox_controller_unregister()
513 for (i = 0; i < mbox->num_chans; i++) in mbox_controller_unregister()
514 mbox_free_channel(&mbox->chans[i]); in mbox_controller_unregister()
516 if (mbox->txdone_poll) in mbox_controller_unregister()
517 hrtimer_cancel(&mbox->poll_hrt); in mbox_controller_unregister()