1/* SPDX-License-Identifier: GPL-2.0 AND MIT */
2/*
3 * Copyright © 2023 Intel Corporation
4 */
5#ifndef TTM_KUNIT_HELPERS_H
6#define TTM_KUNIT_HELPERS_H
7
8#include <drm/drm_drv.h>
9#include <drm/ttm/ttm_device.h>
10#include <drm/ttm/ttm_bo.h>
11#include <drm/ttm/ttm_placement.h>
12
13#include <drm/drm_kunit_helpers.h>
14#include <kunit/test.h>
15
16#define TTM_PL_MOCK1 (TTM_PL_PRIV + 1)
17#define TTM_PL_MOCK2 (TTM_PL_PRIV + 2)
18
19extern struct ttm_device_funcs ttm_dev_funcs;
20extern struct ttm_device_funcs ttm_dev_funcs_bad_evict;
21
22struct ttm_test_devices {
23 struct drm_device *drm;
24 struct device *dev;
25 struct ttm_device *ttm_dev;
26};
27
28/* Building blocks for test-specific init functions */
29int ttm_device_kunit_init(struct ttm_test_devices *priv,
30 struct ttm_device *ttm,
31 unsigned int alloc_flags);
32int ttm_device_kunit_init_bad_evict(struct ttm_test_devices *priv,
33 struct ttm_device *ttm);
34struct ttm_buffer_object *ttm_bo_kunit_init(struct kunit *test,
35 struct ttm_test_devices *devs,
36 size_t size,
37 struct dma_resv *obj);
38struct ttm_place *ttm_place_kunit_init(struct kunit *test, u32 mem_type,
39 u32 flags);
40void dummy_ttm_bo_destroy(struct ttm_buffer_object *bo);
41
42struct ttm_test_devices *ttm_test_devices_basic(struct kunit *test);
43struct ttm_test_devices *ttm_test_devices_all(struct kunit *test);
44
45void ttm_test_devices_put(struct kunit *test, struct ttm_test_devices *devs);
46
47/* Generic init/fini for tests that only need DRM/TTM devices */
48int ttm_test_devices_init(struct kunit *test);
49int ttm_test_devices_all_init(struct kunit *test);
50void ttm_test_devices_fini(struct kunit *test);
51
52#endif // TTM_KUNIT_HELPERS_H
53

source code of linux/drivers/gpu/drm/ttm/tests/ttm_kunit_helpers.h