Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/tests: Add helper to create mock crtc

We're going to need a full-blown, functional, KMS device to test more
components of the atomic modesetting infrastructure.

Let's add a new helper to create a dumb, mocked, CRTC. By default it
will create a CRTC relying only on the default helpers, but drivers are
free to deviate from that.

Reviewed-by: Maíra Canal <mcanal@igalia.com>
Signed-off-by: Maxime Ripard <mripard@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240222-kms-hdmi-connector-state-v7-4-8f4af575fce2@kernel.org

+72
+62
drivers/gpu/drm/tests/drm_kunit_helpers.c
··· 249 249 } 250 250 EXPORT_SYMBOL_GPL(drm_kunit_helper_create_primary_plane); 251 251 252 + static const struct drm_crtc_helper_funcs default_crtc_helper_funcs = { 253 + }; 254 + 255 + static const struct drm_crtc_funcs default_crtc_funcs = { 256 + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, 257 + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, 258 + .reset = drm_atomic_helper_crtc_reset, 259 + }; 260 + 261 + /** 262 + * drm_kunit_helper_create_crtc - Creates a mock CRTC for a KUnit test 263 + * @test: The test context object 264 + * @drm: The device to alloc the plane for 265 + * @primary: Primary plane for CRTC 266 + * @cursor: Cursor plane for CRTC. Optional. 267 + * @funcs: Callbacks for the new plane. Optional. 268 + * @helper_funcs: Helpers callbacks for the new plane. Optional. 269 + * 270 + * This allocates and initializes a mock struct &drm_crtc meant to be 271 + * part of a mock device for a KUnit test. 272 + * 273 + * Resources will be cleaned up automatically. 274 + * 275 + * @funcs will default to the default helpers implementations. 276 + * @helper_funcs will default to an empty implementation. 277 + * 278 + * Returns: 279 + * A pointer to the new CRTC, or an ERR_PTR() otherwise. 280 + */ 281 + struct drm_crtc * 282 + drm_kunit_helper_create_crtc(struct kunit *test, 283 + struct drm_device *drm, 284 + struct drm_plane *primary, 285 + struct drm_plane *cursor, 286 + const struct drm_crtc_funcs *funcs, 287 + const struct drm_crtc_helper_funcs *helper_funcs) 288 + { 289 + struct drm_crtc *crtc; 290 + int ret; 291 + 292 + if (!funcs) 293 + funcs = &default_crtc_funcs; 294 + 295 + if (!helper_funcs) 296 + helper_funcs = &default_crtc_helper_funcs; 297 + 298 + crtc = drmm_kzalloc(drm, sizeof(*crtc), GFP_KERNEL); 299 + KUNIT_ASSERT_NOT_NULL(test, crtc); 300 + 301 + ret = drmm_crtc_init_with_planes(drm, crtc, 302 + primary, 303 + cursor, 304 + funcs, 305 + NULL); 306 + KUNIT_ASSERT_EQ(test, ret, 0); 307 + 308 + drm_crtc_helper_add(crtc, helper_funcs); 309 + 310 + return crtc; 311 + } 312 + EXPORT_SYMBOL_GPL(drm_kunit_helper_create_crtc); 313 + 252 314 MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>"); 253 315 MODULE_LICENSE("GPL");
+10
include/drm/drm_kunit_helpers.h
··· 9 9 10 10 #include <kunit/test.h> 11 11 12 + struct drm_crtc_funcs; 13 + struct drm_crtc_helper_funcs; 12 14 struct drm_device; 13 15 struct drm_plane_funcs; 14 16 struct drm_plane_helper_funcs; ··· 111 109 const uint32_t *formats, 112 110 unsigned int num_formats, 113 111 const uint64_t *modifiers); 112 + 113 + struct drm_crtc * 114 + drm_kunit_helper_create_crtc(struct kunit *test, 115 + struct drm_device *drm, 116 + struct drm_plane *primary, 117 + struct drm_plane *cursor, 118 + const struct drm_crtc_funcs *funcs, 119 + const struct drm_crtc_helper_funcs *helper_funcs); 114 120 115 121 #endif // DRM_KUNIT_HELPERS_H_