drivers/gpu/drm/xe/xe_guc_ct.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_guc_ct.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/xe/xe_guc_ct.c
Extension
.c
Size
65061 bytes
Lines
2286
Domain
Driver Families
Bucket
drivers/gpu
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 g2h_fence {
	u32 *response_buffer;
	u32 seqno;
	/* fields below this point are setup based on the response */
	u32 response_data;
	u16 response_len;
	u16 error;
	u16 hint;
	u16 reason;
	u32 counter;
	bool cancel;
	bool retry;
	bool wait;
	bool fail;
	bool done;
};

static void g2h_fence_init(struct g2h_fence *g2h_fence, u32 *response_buffer)
{
	memset(g2h_fence, 0, sizeof(*g2h_fence));
	g2h_fence->response_buffer = response_buffer;
	g2h_fence->seqno = ~0x0;
}

static void g2h_fence_reinit(struct g2h_fence *g2h_fence)
{
	memset_after(g2h_fence, 0, seqno);
}

static void g2h_fence_cancel(struct g2h_fence *g2h_fence)
{
	g2h_fence->cancel = true;
	g2h_fence->fail = true;

	/* WRITE_ONCE pairs with READ_ONCEs in guc_ct_send_recv. */
	WRITE_ONCE(g2h_fence->done, true);
}

static bool g2h_fence_needs_alloc(struct g2h_fence *g2h_fence)
{
	return g2h_fence->seqno == ~0x0;
}

/**
 * DOC: GuC CTB Blob
 *
 * We allocate single blob to hold both CTB descriptors and buffers:
 *
 *      +--------+-----------------------------------------------+------+
 *      | offset | contents                                      | size |
 *      +========+===============================================+======+
 *      | 0x0000 | H2G CTB Descriptor (send)                     |      |
 *      +--------+-----------------------------------------------+  4K  |
 *      | 0x0800 | G2H CTB Descriptor (g2h)                      |      |
 *      +--------+-----------------------------------------------+------+
 *      | 0x1000 | H2G CT Buffer (send)                          | n*4K |
 *      |        |                                               |      |
 *      +--------+-----------------------------------------------+------+
 *      | 0x1000 | G2H CT Buffer (g2h)                           | m*4K |
 *      | + n*4K |                                               |      |
 *      +--------+-----------------------------------------------+------+
 *
 * Size of each ``CT Buffer`` must be multiple of 4K.
 * We don't expect too many messages in flight at any time, unless we are
 * using the GuC submission. In that case each request requires a minimum
 * 2 dwords which gives us a maximum 256 queue'd requests. Hopefully this
 * enough space to avoid backpressure on the driver. We increase the size
 * of the receive buffer (relative to the send) to ensure a G2H response
 * CTB has a landing spot.
 *
 * In addition to submissions, the G2H buffer needs to be able to hold
 * enough space for recoverable page fault notifications. The number of
 * page faults is interrupt driven and can be as much as the number of
 * compute resources available. However, most of the actual work for these
 * is in a separate page fault worker thread. Therefore we only need to
 * make sure the queue has enough space to handle all of the submissions
 * and responses and an extra buffer for incoming page faults.
 */

#define CTB_DESC_SIZE		ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K)
#define CTB_H2G_BUFFER_OFFSET	(CTB_DESC_SIZE * 2)
#define CTB_G2H_BUFFER_OFFSET	(CTB_DESC_SIZE * 2)
#define CTB_H2G_BUFFER_SIZE	(SZ_4K)
#define CTB_H2G_BUFFER_DWORDS	(CTB_H2G_BUFFER_SIZE / sizeof(u32))
#define CTB_G2H_BUFFER_SIZE	(SZ_128K)
#define CTB_G2H_BUFFER_DWORDS	(CTB_G2H_BUFFER_SIZE / sizeof(u32))
#define G2H_ROOM_BUFFER_SIZE	(CTB_G2H_BUFFER_SIZE / 2)
#define G2H_ROOM_BUFFER_DWORDS	(CTB_G2H_BUFFER_DWORDS / 2)

/**

Annotation

Implementation Notes