drivers/gpu/drm/xe/tests/xe_guc_relay_test.c

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

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/xe/tests/xe_guc_relay_test.c
Extension
.c
Size
17643 bytes
Lines
523
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

// SPDX-License-Identifier: GPL-2.0 AND MIT
/*
 * Copyright © 2023 Intel Corporation
 */

#include <kunit/static_stub.h>
#include <kunit/test.h>
#include <kunit/test-bug.h>

#include "xe_device.h"
#include "xe_kunit_helpers.h"
#include "xe_pci_test.h"

#define TEST_RID	1234
#define TEST_VFID	5
#define TEST_LEN	6
#define TEST_ACTION	0xa
#define TEST_DATA(n)	(0xd0 + (n))

static int replacement_relay_get_totalvfs(struct xe_guc_relay *relay)
{
	return TEST_VFID;
}

static int relay_test_init(struct kunit *test)
{
	struct xe_pci_fake_data fake = {
		.sriov_mode = XE_SRIOV_MODE_PF,
		.platform = XE_TIGERLAKE, /* some random platform */
		.subplatform = XE_SUBPLATFORM_NONE,
	};
	struct xe_guc_relay *relay;
	struct xe_device *xe;

	test->priv = &fake;
	xe_kunit_helper_xe_device_test_init(test);

	xe = test->priv;
	KUNIT_ASSERT_EQ(test, xe_sriov_init(xe), 0);

	relay = &xe_device_get_gt(xe, 0)->uc.guc.relay;
	kunit_activate_static_stub(test, relay_get_totalvfs,
				   replacement_relay_get_totalvfs);

	KUNIT_ASSERT_EQ(test, xe_guc_relay_init(relay), 0);
	KUNIT_EXPECT_TRUE(test, relay_is_ready(relay));
	relay->last_rid = TEST_RID - 1;

	test->priv = relay;
	return 0;
}

static const u32 TEST_MSG[TEST_LEN] = {
	FIELD_PREP_CONST(GUC_HXG_MSG_0_ORIGIN, GUC_HXG_ORIGIN_HOST) |
	FIELD_PREP_CONST(GUC_HXG_MSG_0_TYPE, GUC_HXG_TYPE_EVENT) |
	FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_ACTION, TEST_ACTION) |
	FIELD_PREP_CONST(GUC_HXG_EVENT_MSG_0_DATA0, TEST_DATA(0)),
	TEST_DATA(1), TEST_DATA(2), TEST_DATA(3), TEST_DATA(4),
};

static int replacement_xe_guc_ct_send_recv_always_fails(struct xe_guc_ct *ct,
							const u32 *msg, u32 len,
							u32 *response_buffer)
{
	struct kunit *test = kunit_get_current_test();

	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ct);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, msg);
	KUNIT_ASSERT_GE(test, len, GUC_HXG_MSG_MIN_LEN);

	return -ECOMM;
}

static int replacement_xe_guc_ct_send_recv_expects_pf2guc_relay(struct xe_guc_ct *ct,
								const u32 *msg, u32 len,
								u32 *response_buffer)
{
	struct kunit *test = kunit_get_current_test();

	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ct);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, msg);
	KUNIT_ASSERT_GE(test, len, PF2GUC_RELAY_TO_VF_REQUEST_MSG_MIN_LEN);
	KUNIT_ASSERT_EQ(test, len, PF2GUC_RELAY_TO_VF_REQUEST_MSG_MIN_LEN + TEST_LEN);
	KUNIT_EXPECT_EQ(test, GUC_HXG_ORIGIN_HOST, FIELD_GET(GUC_HXG_MSG_0_ORIGIN, msg[0]));
	KUNIT_EXPECT_EQ(test, GUC_HXG_TYPE_REQUEST, FIELD_GET(GUC_HXG_MSG_0_TYPE, msg[0]));
	KUNIT_EXPECT_EQ(test, XE_GUC_ACTION_PF2GUC_RELAY_TO_VF,
			FIELD_GET(GUC_HXG_REQUEST_MSG_0_ACTION, msg[0]));
	KUNIT_EXPECT_EQ(test, TEST_VFID,
			FIELD_GET(PF2GUC_RELAY_TO_VF_REQUEST_MSG_1_VFID, msg[1]));
	KUNIT_EXPECT_EQ(test, TEST_RID,

Annotation

Implementation Notes