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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/static_stub.hkunit/test.hkunit/test-bug.hxe_device.hxe_ggtt.hxe_guc_ct.hxe_kunit_helpers.hxe_pci_test.h
Detected Declarations
function guc_buf_test_initfunction test_smallestfunction test_largestfunction test_granularfunction test_uniquefunction test_overlapfunction test_reusablefunction test_too_bigfunction test_flushfunction test_lookupfunction test_datafunction test_class
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
- Immediate include surface: `kunit/static_stub.h`, `kunit/test.h`, `kunit/test-bug.h`, `xe_device.h`, `xe_ggtt.h`, `xe_guc_ct.h`, `xe_kunit_helpers.h`, `xe_pci_test.h`.
- Detected declarations: `function guc_buf_test_init`, `function test_smallest`, `function test_largest`, `function test_granular`, `function test_unique`, `function test_overlap`, `function test_reusable`, `function test_too_big`, `function test_flush`, `function test_lookup`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.