drivers/gpu/drm/ttm/tests/ttm_resource_test.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/ttm/tests/ttm_resource_test.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/ttm/tests/ttm_resource_test.c- Extension
.c- Size
- 9307 bytes
- Lines
- 338
- 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
drm/ttm/ttm_resource.httm_kunit_helpers.h
Detected Declarations
struct ttm_resource_test_casestruct ttm_resource_test_privfunction ttm_resource_test_initfunction ttm_resource_test_finifunction ttm_init_test_mocksfunction ttm_init_test_managerfunction ttm_resource_case_descfunction ttm_resource_init_basicfunction ttm_resource_init_pinnedfunction ttm_resource_fini_basicfunction ttm_resource_manager_init_basicfunction ttm_resource_manager_usage_basicfunction ttm_resource_manager_set_used_basicfunction ttm_sys_man_alloc_basicfunction ttm_sys_man_free_basic
Annotated Snippet
struct ttm_resource_test_case {
const char *description;
u32 mem_type;
u32 flags;
};
struct ttm_resource_test_priv {
struct ttm_test_devices *devs;
struct ttm_buffer_object *bo;
struct ttm_place *place;
};
static const struct ttm_resource_manager_func ttm_resource_manager_mock_funcs = { };
static int ttm_resource_test_init(struct kunit *test)
{
struct ttm_resource_test_priv *priv;
priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, priv);
priv->devs = ttm_test_devices_all(test);
KUNIT_ASSERT_NOT_NULL(test, priv->devs);
test->priv = priv;
return 0;
}
static void ttm_resource_test_fini(struct kunit *test)
{
struct ttm_resource_test_priv *priv = test->priv;
ttm_test_devices_put(test, priv->devs);
}
static void ttm_init_test_mocks(struct kunit *test,
struct ttm_resource_test_priv *priv,
u32 mem_type, u32 flags)
{
size_t size = RES_SIZE;
/* Make sure we have what we need for a good BO mock */
KUNIT_ASSERT_NOT_NULL(test, priv->devs->ttm_dev);
priv->bo = ttm_bo_kunit_init(test, priv->devs, size, NULL);
priv->place = ttm_place_kunit_init(test, mem_type, flags);
}
static void ttm_init_test_manager(struct kunit *test,
struct ttm_resource_test_priv *priv,
u32 mem_type)
{
struct ttm_device *ttm_dev = priv->devs->ttm_dev;
struct ttm_resource_manager *man;
size_t size = SZ_16K;
man = kunit_kzalloc(test, sizeof(*man), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, man);
man->use_tt = false;
man->func = &ttm_resource_manager_mock_funcs;
ttm_resource_manager_init(man, ttm_dev, size);
ttm_set_driver_manager(ttm_dev, mem_type, man);
ttm_resource_manager_set_used(man, true);
}
static const struct ttm_resource_test_case ttm_resource_cases[] = {
{
.description = "Init resource in TTM_PL_SYSTEM",
.mem_type = TTM_PL_SYSTEM,
},
{
.description = "Init resource in TTM_PL_VRAM",
.mem_type = TTM_PL_VRAM,
},
{
.description = "Init resource in a private placement",
.mem_type = TTM_PRIV_DUMMY_REG,
},
{
.description = "Init resource in TTM_PL_SYSTEM, set placement flags",
.mem_type = TTM_PL_SYSTEM,
.flags = TTM_PL_FLAG_TOPDOWN,
},
};
static void ttm_resource_case_desc(const struct ttm_resource_test_case *t, char *desc)
{
Annotation
- Immediate include surface: `drm/ttm/ttm_resource.h`, `ttm_kunit_helpers.h`.
- Detected declarations: `struct ttm_resource_test_case`, `struct ttm_resource_test_priv`, `function ttm_resource_test_init`, `function ttm_resource_test_fini`, `function ttm_init_test_mocks`, `function ttm_init_test_manager`, `function ttm_resource_case_desc`, `function ttm_resource_init_basic`, `function ttm_resource_init_pinned`, `function ttm_resource_fini_basic`.
- 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.