drivers/mailbox/mailbox.c
Source file repositories/reference/linux-study-clean/drivers/mailbox/mailbox.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mailbox/mailbox.c- Extension
.c- Size
- 17261 bytes
- Lines
- 635
- Domain
- Driver Families
- Bucket
- drivers/mailbox
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cleanup.hlinux/delay.hlinux/device.hlinux/err.hlinux/mailbox_client.hlinux/mailbox_controller.hlinux/module.hlinux/mutex.hlinux/of.hlinux/property.hlinux/spinlock.h
Detected Declarations
function add_to_rbuffunction msg_submitfunction scoped_guardfunction tx_tickfunction scoped_guardfunction txdone_hrtimerfunction mbox_chan_received_datafunction mbox_chan_txdonefunction mbox_client_txdonefunction mbox_chan_received_datafunction mbox_send_messagefunction chanfunction mbox_chan_txdonefunction __mbox_bind_clientfunction scoped_guardfunction mbox_bind_clientfunction scoped_guardfunction list_for_each_entryfunction mbox_free_channelfunction mbox_controller_registerfunction mbox_controller_unregisterfunction scoped_guardfunction __devm_mbox_controller_unregisterfunction devm_mbox_controller_registerexport mbox_chan_received_dataexport mbox_chan_txdoneexport mbox_client_txdoneexport mbox_client_peek_dataexport mbox_chan_tx_slots_availableexport mbox_send_messageexport mbox_flushexport mbox_bind_clientexport mbox_request_channelexport mbox_request_channel_bynameexport mbox_free_channelexport mbox_controller_registerexport mbox_controller_unregisterexport devm_mbox_controller_register
Annotated Snippet
if (!err) {
chan->active_req = data;
chan->msg_count--;
}
}
if (!err && (chan->txdone_method & MBOX_TXDONE_BY_POLL)) {
/* kick start the timer immediately to avoid delays */
scoped_guard(spinlock_irqsave, &chan->mbox->poll_hrt_lock)
hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL);
}
}
static void tx_tick(struct mbox_chan *chan, int r)
{
void *mssg;
scoped_guard(spinlock_irqsave, &chan->lock) {
mssg = chan->active_req;
chan->active_req = MBOX_NO_MSG;
}
/* Submit next message */
msg_submit(chan);
if (mssg == MBOX_NO_MSG)
return;
/* Notify the client */
if (chan->cl->tx_done)
chan->cl->tx_done(chan->cl, mssg, r);
if (r != -ETIME && chan->cl->tx_block)
complete(&chan->tx_complete);
}
static enum hrtimer_restart txdone_hrtimer(struct hrtimer *hrtimer)
{
struct mbox_controller *mbox =
container_of(hrtimer, struct mbox_controller, poll_hrt);
bool txdone, resched = false;
int i;
for (i = 0; i < mbox->num_chans; i++) {
struct mbox_chan *chan = &mbox->chans[i];
if (chan->active_req != MBOX_NO_MSG && chan->cl) {
txdone = chan->mbox->ops->last_tx_done(chan);
if (txdone)
tx_tick(chan, 0);
else
resched = true;
}
}
if (resched) {
scoped_guard(spinlock_irqsave, &mbox->poll_hrt_lock) {
if (!hrtimer_is_queued(hrtimer))
hrtimer_forward_now(hrtimer, ms_to_ktime(mbox->txpoll_period));
}
return HRTIMER_RESTART;
}
return HRTIMER_NORESTART;
}
/**
* mbox_chan_received_data - A way for controller driver to push data
* received from remote to the upper layer.
* @chan: Pointer to the mailbox channel on which RX happened.
* @mssg: Client specific message typecasted as void *
*
* After startup and before shutdown any data received on the chan
* is passed on to the API via atomic mbox_chan_received_data().
* The controller should ACK the RX only after this call returns.
*/
void mbox_chan_received_data(struct mbox_chan *chan, void *mssg)
{
/* No buffering the received data */
if (chan->cl->rx_callback)
chan->cl->rx_callback(chan->cl, mssg);
}
EXPORT_SYMBOL_GPL(mbox_chan_received_data);
/**
* mbox_chan_txdone - A way for controller driver to notify the
* framework that the last TX has completed.
* @chan: Pointer to the mailbox chan on which TX happened.
* @r: Status of last TX - OK or ERROR
*
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/delay.h`, `linux/device.h`, `linux/err.h`, `linux/mailbox_client.h`, `linux/mailbox_controller.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `function add_to_rbuf`, `function msg_submit`, `function scoped_guard`, `function tx_tick`, `function scoped_guard`, `function txdone_hrtimer`, `function mbox_chan_received_data`, `function mbox_chan_txdone`, `function mbox_client_txdone`, `function mbox_chan_received_data`.
- Atlas domain: Driver Families / drivers/mailbox.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.