drivers/accel/amdxdna/aie2_message.c

Source file repositories/reference/linux-study-clean/drivers/accel/amdxdna/aie2_message.c

File Facts

System
Linux kernel
Corpus path
drivers/accel/amdxdna/aie2_message.c
Extension
.c
Size
33931 bytes
Lines
1271
Domain
Driver Families
Bucket
drivers/accel
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

if (ret) {
			XDNA_ERR(xdna, "failed to enable force preempt %d", ret);
			goto del_ctx_req;
		}
	}

	cq_pair = &resp.cq_pair[0];
	x2i.mb_head_ptr_reg = AIE2_MBOX_OFF(ndev, cq_pair->x2i_q.head_addr);
	x2i.mb_tail_ptr_reg = AIE2_MBOX_OFF(ndev, cq_pair->x2i_q.tail_addr);
	x2i.rb_start_addr   = AIE2_SRAM_OFF(ndev, cq_pair->x2i_q.buf_addr);
	x2i.rb_size	    = cq_pair->x2i_q.buf_size;

	i2x.mb_head_ptr_reg = AIE2_MBOX_OFF(ndev, cq_pair->i2x_q.head_addr);
	i2x.mb_tail_ptr_reg = AIE2_MBOX_OFF(ndev, cq_pair->i2x_q.tail_addr);
	i2x.rb_start_addr   = AIE2_SRAM_OFF(ndev, cq_pair->i2x_q.buf_addr);
	i2x.rb_size	    = cq_pair->i2x_q.buf_size;

	ret = pci_irq_vector(to_pci_dev(xdna->ddev.dev), resp.msix_id);
	if (ret == -EINVAL) {
		XDNA_ERR(xdna, "Alloc IRQ failed %d", ret);
		goto del_ctx_req;
	}

	intr_reg = i2x.mb_head_ptr_reg + 4;
	hwctx->priv->mbox_chann = xdna_mailbox_alloc_channel(ndev->mbox);
	if (!hwctx->priv->mbox_chann) {
		XDNA_ERR(xdna, "Not able to create channel");
		ret = -EINVAL;
		goto del_ctx_req;
	}

	ret = xdna_mailbox_start_channel(hwctx->priv->mbox_chann, &x2i, &i2x,
					 intr_reg, ret);
	if (ret) {
		XDNA_ERR(xdna, "Not able to create channel");
		ret = -EINVAL;
		goto free_channel;
	}
	ndev->hwctx_num++;

	XDNA_DBG(xdna, "Mailbox channel irq: %d, msix_id: %d", ret, resp.msix_id);
	XDNA_DBG(xdna, "Created fw ctx %d pasid %d", hwctx->fw_ctx_id, hwctx->client->pasid);

	return 0;

free_channel:
	xdna_mailbox_free_channel(hwctx->priv->mbox_chann);
del_ctx_req:
	aie2_destroy_context_req(ndev, hwctx->fw_ctx_id);
	return ret;
}

int aie2_destroy_context(struct amdxdna_dev_hdl *ndev, struct amdxdna_hwctx *hwctx)
{
	struct amdxdna_dev *xdna = ndev->aie.xdna;
	int ret;

	if (!hwctx->priv->mbox_chann)
		return 0;

	xdna_mailbox_stop_channel(hwctx->priv->mbox_chann);
	ret = aie2_destroy_context_req(ndev, hwctx->fw_ctx_id);
	xdna_mailbox_free_channel(hwctx->priv->mbox_chann);
	XDNA_DBG(xdna, "Destroyed fw ctx %d", hwctx->fw_ctx_id);
	hwctx->priv->mbox_chann = NULL;
	hwctx->fw_ctx_id = -1;
	ndev->hwctx_num--;

	return ret;
}

static int aie2_send_host_buf_msgs(struct amdxdna_dev_hdl *ndev, u32 context_id,
				   u64 addr, u64 size, u32 initial_opcode)
{
	DECLARE_AIE_MSG(map_host_buffer, MSG_OP_MAP_HOST_BUFFER);
	struct amdxdna_dev *xdna = ndev->aie.xdna;
	size_t chunk_size;
	int ret;

	chunk_size = xdna->dev_info->dev_mem_size;
	if (!size || !IS_ALIGNED(size, chunk_size)) {
		XDNA_ERR(xdna, "Invalid size 0x%llx for chunk 0x%lx",
			 size, chunk_size);
		return -EINVAL;
	}

	msg.opcode = initial_opcode;
	do {
		req.context_id = context_id;
		req.buf_addr = addr;

Annotation

Implementation Notes