drivers/mailbox/cix-mailbox.c
Source file repositories/reference/linux-study-clean/drivers/mailbox/cix-mailbox.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mailbox/cix-mailbox.c- Extension
.c- Size
- 17471 bytes
- Lines
- 644
- 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/err.hlinux/io.hlinux/interrupt.hlinux/kernel.hlinux/mailbox_controller.hlinux/module.hlinux/platform_device.h
Detected Declarations
struct cix_mbox_con_privstruct cix_mbox_privenum cix_mbox_chan_typefunction cix_mbox_writefunction cix_mbox_readfunction mbox_fifo_emptyfunction mbox_get_msg_sizefunction cix_mbox_send_data_dbfunction cix_mbox_send_data_regfunction cix_mbox_send_data_fifofunction cix_mbox_send_data_fastfunction cix_mbox_send_datafunction cix_mbox_isr_dbfunction cix_mbox_isr_regfunction cix_mbox_isr_fifofunction cix_mbox_isr_fastfunction cix_mbox_isrfunction cix_mbox_startupfunction cix_mbox_shutdownfunction cix_mbox_initfunction cix_mbox_probefunction cix_mailbox_init
Annotated Snippet
struct cix_mbox_con_priv {
enum cix_mbox_chan_type type;
struct mbox_chan *chan;
int index;
};
struct cix_mbox_priv {
struct device *dev;
int irq;
int dir;
void __iomem *base; /* region for mailbox */
struct cix_mbox_con_priv con_priv[CIX_MBOX_CHANS];
struct mbox_chan mbox_chans[CIX_MBOX_CHANS];
struct mbox_controller mbox;
bool use_shmem;
};
/*
* The CIX mailbox supports four types of transfers:
* CIX_MBOX_TYPE_DB, CIX_MBOX_TYPE_FAST, CIX_MBOX_TYPE_REG, and CIX_MBOX_TYPE_FIFO.
* For the REG and FIFO types of transfers, the message format is as follows:
*/
union cix_mbox_msg_reg_fifo {
u32 length; /* unit is byte */
u32 buf[CIX_MBOX_MSG_WORDS]; /* buf[0] must be the byte length of this array */
};
static struct cix_mbox_priv *to_cix_mbox_priv(struct mbox_controller *mbox)
{
return container_of(mbox, struct cix_mbox_priv, mbox);
}
static void cix_mbox_write(struct cix_mbox_priv *priv, u32 val, u32 offset)
{
if (priv->use_shmem)
iowrite32(val, priv->base + offset - CIX_SHMEM_OFFSET);
else
iowrite32(val, priv->base + offset);
}
static u32 cix_mbox_read(struct cix_mbox_priv *priv, u32 offset)
{
if (priv->use_shmem)
return ioread32(priv->base + offset - CIX_SHMEM_OFFSET);
else
return ioread32(priv->base + offset);
}
static bool mbox_fifo_empty(struct mbox_chan *chan)
{
struct cix_mbox_priv *priv = to_cix_mbox_priv(chan->mbox);
return ((cix_mbox_read(priv, CIX_FIFO_STAS) & CIX_FIFO_STAS_EMPTY) ? true : false);
}
/*
*The transmission unit of the CIX mailbox is word.
*The byte length should be converted into the word length.
*/
static inline u32 mbox_get_msg_size(void *msg)
{
u32 len;
len = ((u32 *)msg)[0] & CIX_MBOX_MSG_LEN_MASK;
return DIV_ROUND_UP(len, 4);
}
static int cix_mbox_send_data_db(struct mbox_chan *chan, void *data)
{
struct cix_mbox_priv *priv = to_cix_mbox_priv(chan->mbox);
/* trigger doorbell irq */
cix_mbox_write(priv, CIX_DB_INT_BIT, CIX_REG_DB_ACK);
return 0;
}
static int cix_mbox_send_data_reg(struct mbox_chan *chan, void *data)
{
struct cix_mbox_priv *priv = to_cix_mbox_priv(chan->mbox);
union cix_mbox_msg_reg_fifo *msg = data;
u32 len, i;
if (!data)
return -EINVAL;
len = mbox_get_msg_size(data);
for (i = 0; i < len; i++)
cix_mbox_write(priv, msg->buf[i], CIX_REG_MSG(i));
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/io.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/mailbox_controller.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct cix_mbox_con_priv`, `struct cix_mbox_priv`, `enum cix_mbox_chan_type`, `function cix_mbox_write`, `function cix_mbox_read`, `function mbox_fifo_empty`, `function mbox_get_msg_size`, `function cix_mbox_send_data_db`, `function cix_mbox_send_data_reg`, `function cix_mbox_send_data_fifo`.
- 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.