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

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

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c
Extension
.c
Size
9326 bytes
Lines
330
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 © 2024 Intel Corporation
 */

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

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

#define DUT_GGTT_START		SZ_1M
#define DUT_GGTT_SIZE		SZ_2M

static struct xe_bo *replacement_xe_managed_bo_create_pin_map(struct xe_device *xe,
							      struct xe_tile *tile,
							      size_t size, u32 flags)
{
	struct kunit *test = kunit_get_current_test();
	struct xe_bo *bo;
	void *buf;

	bo = drmm_kzalloc(&xe->drm, sizeof(*bo), GFP_KERNEL);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bo);

	buf = drmm_kzalloc(&xe->drm, size, GFP_KERNEL);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);

	bo->tile = tile;
	bo->ttm.bdev = &xe->ttm;
	bo->ttm.base.size = size;
	iosys_map_set_vaddr(&bo->vmap, buf);

	if (flags & XE_BO_FLAG_GGTT) {
		struct xe_ggtt *ggtt = tile->mem.ggtt;

		bo->ggtt_node[tile->id] = xe_ggtt_insert_node(ggtt, xe_bo_size(bo), SZ_4K);
		KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bo->ggtt_node[tile->id]);
	}

	return bo;
}

static int guc_buf_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_ggtt *ggtt;
	struct xe_guc *guc;

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

	ggtt = xe_device_get_root_tile(test->priv)->mem.ggtt;
	guc = &xe_device_get_gt(test->priv, 0)->uc.guc;

	KUNIT_ASSERT_EQ(test, 0,
			xe_ggtt_init_kunit(ggtt, DUT_GGTT_START,
					   DUT_GGTT_SIZE));

	kunit_activate_static_stub(test, xe_managed_bo_create_pin_map,
				   replacement_xe_managed_bo_create_pin_map);

	KUNIT_ASSERT_EQ(test, 0, xe_guc_buf_cache_init(&guc->buf));

	test->priv = &guc->buf;
	return 0;
}

static void test_smallest(struct kunit *test)
{
	struct xe_guc_buf_cache *cache = test->priv;
	struct xe_guc_buf buf;

	buf = xe_guc_buf_reserve(cache, 1);
	KUNIT_ASSERT_TRUE(test, xe_guc_buf_is_valid(buf));
	KUNIT_EXPECT_NOT_NULL(test, xe_guc_buf_cpu_ptr(buf));
	KUNIT_EXPECT_NE(test, 0, xe_guc_buf_gpu_addr(buf));
	KUNIT_EXPECT_LE(test, DUT_GGTT_START, xe_guc_buf_gpu_addr(buf));
	KUNIT_EXPECT_GT(test, DUT_GGTT_START + DUT_GGTT_SIZE, xe_guc_buf_gpu_addr(buf));
	xe_guc_buf_release(buf);
}

Annotation

Implementation Notes