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.

Dependency Surface

Detected Declarations

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

Implementation Notes