内核mailbox

只罗列增加取走消息:

static int add_to_rbuf(struct mbox_chan *chan, void *mssg)
{
    int idx;
    unsigned long flags;

    spin_lock_irqsave(&chan->lock, flags);

    /* See if there is any space left */
    if (chan->msg_count == MBOX_TX_QUEUE_LEN) {
        spin_unlock_irqrestore(&chan->lock, flags);
        return -ENOBUFS;
    }

    idx = chan->msg_free;
    chan->msg_data[idx] = mssg;
    chan->msg_count++;

    if (idx == MBOX_TX_QUEUE_LEN - 1)
        chan->msg_free = 0;
    else
        chan->msg_free++;

    spin_unlock_irqrestore(&chan->lock, flags);

    return idx;
}

static void msg_submit(struct mbox_chan *chan)
{
    unsigned count, idx;
    unsigned long flags;
    void *data;
    int err;

    spin_lock_irqsave(&chan->lock, flags);

    if (!chan->msg_count || chan->active_req)
        goto exit;

    count = chan->msg_count;
    idx = chan->msg_free;
    if (idx >= count)
        idx -= count;
    else
        idx += MBOX_TX_QUEUE_LEN - count;

    data = chan->msg_data[idx];

    /* Try to submit a message to the MBOX controller */
    err = chan->mbox->ops->send_data(chan, data);
    if (!err) {
        chan->active_req = data;
        chan->msg_count--;
    }
exit:
    spin_unlock_irqrestore(&chan->lock, flags);
}

 

posted @ 2019-04-26 14:03  Vedic  阅读(496)  评论(0编辑  收藏  举报