|
| 1 | +// SPDX-License-Identifier: GPL-2.0 AND MIT |
| 2 | +/* |
| 3 | + * Copyright © 2023 Intel Corporation |
| 4 | + */ |
| 5 | +#include "ttm_kunit_helpers.h" |
| 6 | + |
| 7 | +struct ttm_device_funcs ttm_dev_funcs = { |
| 8 | +}; |
| 9 | +EXPORT_SYMBOL_GPL(ttm_dev_funcs); |
| 10 | + |
| 11 | +int ttm_device_kunit_init(struct ttm_test_devices *priv, |
| 12 | + struct ttm_device *ttm, |
| 13 | + bool use_dma_alloc, |
| 14 | + bool use_dma32) |
| 15 | +{ |
| 16 | + struct drm_device *drm = priv->drm; |
| 17 | + int err; |
| 18 | + |
| 19 | + err = ttm_device_init(ttm, &ttm_dev_funcs, drm->dev, |
| 20 | + drm->anon_inode->i_mapping, |
| 21 | + drm->vma_offset_manager, |
| 22 | + use_dma_alloc, use_dma32); |
| 23 | + |
| 24 | + return err; |
| 25 | +} |
| 26 | +EXPORT_SYMBOL_GPL(ttm_device_kunit_init); |
| 27 | + |
| 28 | +struct ttm_test_devices *ttm_test_devices_basic(struct kunit *test) |
| 29 | +{ |
| 30 | + struct ttm_test_devices *devs; |
| 31 | + |
| 32 | + devs = kunit_kzalloc(test, sizeof(*devs), GFP_KERNEL); |
| 33 | + KUNIT_ASSERT_NOT_NULL(test, devs); |
| 34 | + |
| 35 | + devs->dev = drm_kunit_helper_alloc_device(test); |
| 36 | + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, devs->dev); |
| 37 | + |
| 38 | + devs->drm = __drm_kunit_helper_alloc_drm_device(test, devs->dev, |
| 39 | + sizeof(*devs->drm), 0, |
| 40 | + DRIVER_GEM); |
| 41 | + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, devs->drm); |
| 42 | + |
| 43 | + return devs; |
| 44 | +} |
| 45 | +EXPORT_SYMBOL_GPL(ttm_test_devices_basic); |
| 46 | + |
| 47 | +struct ttm_test_devices *ttm_test_devices_all(struct kunit *test) |
| 48 | +{ |
| 49 | + struct ttm_test_devices *devs; |
| 50 | + struct ttm_device *ttm_dev; |
| 51 | + int err; |
| 52 | + |
| 53 | + devs = ttm_test_devices_basic(test); |
| 54 | + |
| 55 | + ttm_dev = kunit_kzalloc(test, sizeof(*ttm_dev), GFP_KERNEL); |
| 56 | + KUNIT_ASSERT_NOT_NULL(test, ttm_dev); |
| 57 | + |
| 58 | + err = ttm_device_kunit_init(devs, ttm_dev, false, false); |
| 59 | + KUNIT_ASSERT_EQ(test, err, 0); |
| 60 | + |
| 61 | + devs->ttm_dev = ttm_dev; |
| 62 | + |
| 63 | + return devs; |
| 64 | +} |
| 65 | +EXPORT_SYMBOL_GPL(ttm_test_devices_all); |
| 66 | + |
| 67 | +void ttm_test_devices_put(struct kunit *test, struct ttm_test_devices *devs) |
| 68 | +{ |
| 69 | + if (devs->ttm_dev) |
| 70 | + ttm_device_fini(devs->ttm_dev); |
| 71 | + |
| 72 | + drm_kunit_helper_free_device(test, devs->dev); |
| 73 | +} |
| 74 | +EXPORT_SYMBOL_GPL(ttm_test_devices_put); |
| 75 | + |
| 76 | +int ttm_test_devices_init(struct kunit *test) |
| 77 | +{ |
| 78 | + struct ttm_test_devices *priv; |
| 79 | + |
| 80 | + priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); |
| 81 | + KUNIT_ASSERT_NOT_NULL(test, priv); |
| 82 | + |
| 83 | + priv = ttm_test_devices_basic(test); |
| 84 | + test->priv = priv; |
| 85 | + |
| 86 | + return 0; |
| 87 | +} |
| 88 | +EXPORT_SYMBOL_GPL(ttm_test_devices_init); |
| 89 | + |
| 90 | +void ttm_test_devices_fini(struct kunit *test) |
| 91 | +{ |
| 92 | + ttm_test_devices_put(test, test->priv); |
| 93 | +} |
| 94 | +EXPORT_SYMBOL_GPL(ttm_test_devices_fini); |
| 95 | + |
| 96 | +MODULE_LICENSE("GPL"); |
0 commit comments