drivers/mailbox/mailbox-altera.c
Source file repositories/reference/linux-study-clean/drivers/mailbox/mailbox-altera.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mailbox/mailbox-altera.c- Extension
.c- Size
- 8596 bytes
- Lines
- 362
- 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.
- 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/device.hlinux/interrupt.hlinux/io.hlinux/kernel.hlinux/mailbox_controller.hlinux/module.hlinux/of.hlinux/platform_device.h
Detected Declarations
struct altera_mboxenum altera_mbox_msgfunction altera_mbox_fullfunction altera_mbox_pendingfunction altera_mbox_rx_intmaskfunction altera_mbox_tx_intmaskfunction altera_mbox_is_senderfunction altera_mbox_rx_datafunction altera_mbox_poll_rxfunction altera_mbox_tx_interruptfunction altera_mbox_rx_interruptfunction altera_mbox_startup_senderfunction altera_mbox_startup_receiverfunction altera_mbox_send_datafunction altera_mbox_last_tx_donefunction altera_mbox_peek_datafunction altera_mbox_startupfunction altera_mbox_shutdownfunction altera_mbox_probe
Annotated Snippet
struct altera_mbox {
bool is_sender; /* 1-sender, 0-receiver */
bool intr_mode;
int irq;
void __iomem *mbox_base;
struct device *dev;
struct mbox_controller controller;
/* If the controller supports only RX polling mode */
struct timer_list rxpoll_timer;
struct mbox_chan *chan;
};
static struct altera_mbox *mbox_chan_to_altera_mbox(struct mbox_chan *chan)
{
if (!chan || !chan->con_priv)
return NULL;
return (struct altera_mbox *)chan->con_priv;
}
static inline int altera_mbox_full(struct altera_mbox *mbox)
{
u32 status;
status = readl_relaxed(mbox->mbox_base + MAILBOX_STS_REG);
return MBOX_FULL(status);
}
static inline int altera_mbox_pending(struct altera_mbox *mbox)
{
u32 status;
status = readl_relaxed(mbox->mbox_base + MAILBOX_STS_REG);
return MBOX_PENDING(status);
}
static void altera_mbox_rx_intmask(struct altera_mbox *mbox, bool enable)
{
u32 mask;
mask = readl_relaxed(mbox->mbox_base + MAILBOX_INTMASK_REG);
if (enable)
mask |= INT_PENDING_MSK;
else
mask &= ~INT_PENDING_MSK;
writel_relaxed(mask, mbox->mbox_base + MAILBOX_INTMASK_REG);
}
static void altera_mbox_tx_intmask(struct altera_mbox *mbox, bool enable)
{
u32 mask;
mask = readl_relaxed(mbox->mbox_base + MAILBOX_INTMASK_REG);
if (enable)
mask |= INT_SPACE_MSK;
else
mask &= ~INT_SPACE_MSK;
writel_relaxed(mask, mbox->mbox_base + MAILBOX_INTMASK_REG);
}
static bool altera_mbox_is_sender(struct altera_mbox *mbox)
{
u32 reg;
/* Write a magic number to PTR register and read back this register.
* This register is read-write if it is a sender.
*/
#define MBOX_MAGIC 0xA5A5AA55
writel_relaxed(MBOX_MAGIC, mbox->mbox_base + MAILBOX_PTR_REG);
reg = readl_relaxed(mbox->mbox_base + MAILBOX_PTR_REG);
if (reg == MBOX_MAGIC) {
/* Clear to 0 */
writel_relaxed(0, mbox->mbox_base + MAILBOX_PTR_REG);
return true;
}
return false;
}
static void altera_mbox_rx_data(struct mbox_chan *chan)
{
struct altera_mbox *mbox = mbox_chan_to_altera_mbox(chan);
u32 data[2];
if (altera_mbox_pending(mbox)) {
data[MBOX_PTR] =
readl_relaxed(mbox->mbox_base + MAILBOX_PTR_REG);
data[MBOX_CMD] =
readl_relaxed(mbox->mbox_base + MAILBOX_CMD_REG);
mbox_chan_received_data(chan, (void *)data);
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/interrupt.h`, `linux/io.h`, `linux/kernel.h`, `linux/mailbox_controller.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct altera_mbox`, `enum altera_mbox_msg`, `function altera_mbox_full`, `function altera_mbox_pending`, `function altera_mbox_rx_intmask`, `function altera_mbox_tx_intmask`, `function altera_mbox_is_sender`, `function altera_mbox_rx_data`, `function altera_mbox_poll_rx`, `function altera_mbox_tx_interrupt`.
- Atlas domain: Driver Families / drivers/mailbox.
- Implementation status: source implementation candidate.
- 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.