drivers/mailbox/ast2700-mailbox.c
Source file repositories/reference/linux-study-clean/drivers/mailbox/ast2700-mailbox.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mailbox/ast2700-mailbox.c- Extension
.c- Size
- 6029 bytes
- Lines
- 236
- Domain
- Driver Families
- Bucket
- drivers/mailbox
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/interrupt.hlinux/io.hlinux/iopoll.hlinux/kernel.hlinux/mailbox_controller.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/slab.h
Detected Declarations
struct ast2700_mbox_datastruct ast2700_mboxfunction ch_numfunction ast2700_mbox_tx_donefunction ast2700_mbox_irqfunction ast2700_mbox_send_datafunction ast2700_mbox_startupfunction ast2700_mbox_shutdownfunction ast2700_mbox_last_tx_donefunction ast2700_mbox_probe
Annotated Snippet
struct ast2700_mbox_data {
u8 num_chans;
u8 msg_size;
};
struct ast2700_mbox {
struct mbox_controller mbox;
u8 msg_size;
void __iomem *tx_regs;
void __iomem *rx_regs;
spinlock_t lock;
};
static inline int ch_num(struct mbox_chan *chan)
{
return chan - chan->mbox->chans;
}
static inline bool ast2700_mbox_tx_done(struct ast2700_mbox *mb, int idx)
{
return !(readl(mb->tx_regs + IPCR_STATUS) & BIT(idx));
}
static irqreturn_t ast2700_mbox_irq(int irq, void *p)
{
struct ast2700_mbox *mb = p;
void __iomem *data_reg;
int num_words = mb->msg_size / sizeof(u32);
u32 *word_data;
u32 status;
int n, i;
/* Only examine channels that are currently enabled. */
status = readl(mb->rx_regs + IPCR_ENABLE) &
readl(mb->rx_regs + IPCR_STATUS);
if (!(status & RX_IRQ_MASK))
return IRQ_NONE;
for (n = 0; n < mb->mbox.num_chans; ++n) {
struct mbox_chan *chan = &mb->mbox.chans[n];
if (!(status & RX_IRQ(n)))
continue;
data_reg = mb->rx_regs + IPCR_DATA + mb->msg_size * n;
word_data = chan->con_priv;
/* Read the message data */
for (i = 0; i < num_words; i++)
word_data[i] = readl(data_reg + i * sizeof(u32));
mbox_chan_received_data(chan, chan->con_priv);
/* The IRQ can be cleared only once the FIFO is empty. */
writel(RX_IRQ(n), mb->rx_regs + IPCR_STATUS);
}
return IRQ_HANDLED;
}
static int ast2700_mbox_send_data(struct mbox_chan *chan, void *data)
{
struct ast2700_mbox *mb = dev_get_drvdata(chan->mbox->dev);
int idx = ch_num(chan);
void __iomem *data_reg = mb->tx_regs + IPCR_DATA + mb->msg_size * idx;
u32 *word_data = data;
int num_words = mb->msg_size / sizeof(u32);
int i;
if (!(readl(mb->tx_regs + IPCR_ENABLE) & BIT(idx))) {
dev_warn(mb->mbox.dev, "%s: Ch-%d not enabled yet\n", __func__, idx);
return -ENODEV;
}
if (!(ast2700_mbox_tx_done(mb, idx))) {
dev_warn(mb->mbox.dev, "%s: Ch-%d last data has not finished\n", __func__, idx);
return -EBUSY;
}
/* Write the message data */
for (i = 0 ; i < num_words; i++)
writel(word_data[i], data_reg + i * sizeof(u32));
writel(BIT(idx), mb->tx_regs + IPCR_TX_TRIG);
dev_dbg(mb->mbox.dev, "%s: Ch-%d sent\n", __func__, idx);
return 0;
}
static int ast2700_mbox_startup(struct mbox_chan *chan)
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/io.h`, `linux/iopoll.h`, `linux/kernel.h`, `linux/mailbox_controller.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct ast2700_mbox_data`, `struct ast2700_mbox`, `function ch_num`, `function ast2700_mbox_tx_done`, `function ast2700_mbox_irq`, `function ast2700_mbox_send_data`, `function ast2700_mbox_startup`, `function ast2700_mbox_shutdown`, `function ast2700_mbox_last_tx_done`, `function ast2700_mbox_probe`.
- Atlas domain: Driver Families / drivers/mailbox.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.