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

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

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c
Extension
.c
Size
10097 bytes
Lines
320
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 © 2025 Intel Corporation
 */

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

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

#define TEST_MAX_VFS	63
#define TEST_VRAM	0x7a800000ull	/* random size that works on 32-bit */

static bool xe_device_is_admin_only_stub_enable(const struct xe_device *xe)
{
	return true;
}

static bool xe_device_is_admin_only_stub_disable(const struct xe_device *xe)
{
	return false;
}

static void pf_set_admin_mode(struct xe_device *xe, bool enable)
{
	typeof(xe_device_is_admin_only) *stub = enable ?
		xe_device_is_admin_only_stub_enable :
		xe_device_is_admin_only_stub_disable;

	kunit_activate_static_stub(kunit_get_current_test(),
				   xe_device_is_admin_only,
				   *stub);

	KUNIT_EXPECT_EQ(kunit_get_current_test(), enable, xe_sriov_pf_admin_only(xe));
	KUNIT_EXPECT_EQ(kunit_get_current_test(), enable, xe_device_is_admin_only(xe));
}

static void pf_set_usable_vram(struct xe_device *xe, u64 usable)
{
	struct xe_tile *tile = xe_device_get_root_tile(xe);
	struct kunit *test = kunit_get_current_test();

	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, tile);
	xe->mem.vram->usable_size = usable;
	tile->mem.vram->usable_size = usable;
	KUNIT_ASSERT_EQ(test, usable, xe_vram_region_usable_size(tile->mem.vram));
}

static const void *num_vfs_gen_param(struct kunit *test, const void *prev, char *desc)
{
	unsigned long next = 1 + (unsigned long)prev;

	if (next > TEST_MAX_VFS)
		return NULL;
	snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%lu VF%s",
		 next, str_plural(next));
	return (void *)next;
}

static int pf_gt_config_test_init(struct kunit *test)
{
	struct xe_pci_fake_data fake = {
		.sriov_mode = XE_SRIOV_MODE_PF,
		.platform = XE_BATTLEMAGE, /* any random DGFX platform with SR-IOV */
		.subplatform = XE_SUBPLATFORM_NONE,
		.graphics_verx100 = 2001,
	};
	struct xe_vram_region *vram;
	struct xe_device *xe;
	struct xe_gt *gt;

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

	xe = test->priv;
	KUNIT_ASSERT_TRUE(test, IS_SRIOV_PF(xe));

	gt = xe_root_mmio_gt(xe);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, gt);
	test->priv = gt;

	/* pretend it has some VRAM */
	KUNIT_ASSERT_TRUE(test, IS_DGFX(xe));
	vram = kunit_kzalloc(test, sizeof(*vram), GFP_KERNEL);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, vram);
	vram->usable_size = TEST_VRAM;
	xe->mem.vram = vram;
	xe->tiles[0].mem.vram = vram;

Annotation

Implementation Notes