Commit 7a48da0f authored by Maxime Ripard's avatar Maxime Ripard

drm/tests: Add helper to create mock plane

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, primary plane. By
default, it will create a linear XRGB8888 plane, using the default
helpers.
Reviewed-by: default avatarMaíra Canal <mcanal@igalia.com>
Signed-off-by: default avatarMaxime Ripard <mripard@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240222-kms-hdmi-connector-state-v7-3-8f4af575fce2@kernel.org
parent 66671944
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <drm/drm_atomic.h> #include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h> #include <drm/drm_atomic_helper.h>
#include <drm/drm_drv.h> #include <drm/drm_drv.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_kunit_helpers.h> #include <drm/drm_kunit_helpers.h>
#include <drm/drm_managed.h> #include <drm/drm_managed.h>
...@@ -164,5 +165,89 @@ drm_kunit_helper_atomic_state_alloc(struct kunit *test, ...@@ -164,5 +165,89 @@ drm_kunit_helper_atomic_state_alloc(struct kunit *test,
} }
EXPORT_SYMBOL_GPL(drm_kunit_helper_atomic_state_alloc); EXPORT_SYMBOL_GPL(drm_kunit_helper_atomic_state_alloc);
static const uint32_t default_plane_formats[] = {
DRM_FORMAT_XRGB8888,
};
static const uint64_t default_plane_modifiers[] = {
DRM_FORMAT_MOD_LINEAR,
DRM_FORMAT_MOD_INVALID
};
static const struct drm_plane_helper_funcs default_plane_helper_funcs = {
};
static const struct drm_plane_funcs default_plane_funcs = {
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
.reset = drm_atomic_helper_plane_reset,
};
/**
* drm_kunit_helper_create_primary_plane - Creates a mock primary plane for a KUnit test
* @test: The test context object
* @drm: The device to alloc the plane for
* @funcs: Callbacks for the new plane. Optional.
* @helper_funcs: Helpers callbacks for the new plane. Optional.
* @formats: array of supported formats (DRM_FORMAT\_\*). Optional.
* @num_formats: number of elements in @formats
* @modifiers: array of struct drm_format modifiers terminated by
* DRM_FORMAT_MOD_INVALID. Optional.
*
* This allocates and initializes a mock struct &drm_plane meant to be
* part of a mock device for a KUnit test.
*
* Resources will be cleaned up automatically.
*
* @funcs will default to the default helpers implementations.
* @helper_funcs will default to an empty implementation. @formats will
* default to XRGB8888 only. @modifiers will default to a linear
* modifier only.
*
* Returns:
* A pointer to the new plane, or an ERR_PTR() otherwise.
*/
struct drm_plane *
drm_kunit_helper_create_primary_plane(struct kunit *test,
struct drm_device *drm,
const struct drm_plane_funcs *funcs,
const struct drm_plane_helper_funcs *helper_funcs,
const uint32_t *formats,
unsigned int num_formats,
const uint64_t *modifiers)
{
struct drm_plane *plane;
if (!funcs)
funcs = &default_plane_funcs;
if (!helper_funcs)
helper_funcs = &default_plane_helper_funcs;
if (!formats || !num_formats) {
formats = default_plane_formats;
num_formats = ARRAY_SIZE(default_plane_formats);
}
if (!modifiers)
modifiers = default_plane_modifiers;
plane = __drmm_universal_plane_alloc(drm,
sizeof(struct drm_plane), 0,
0,
funcs,
formats,
num_formats,
default_plane_modifiers,
DRM_PLANE_TYPE_PRIMARY,
NULL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, plane);
drm_plane_helper_add(plane, helper_funcs);
return plane;
}
EXPORT_SYMBOL_GPL(drm_kunit_helper_create_primary_plane);
MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>"); MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include <kunit/test.h> #include <kunit/test.h>
struct drm_device; struct drm_device;
struct drm_plane_funcs;
struct drm_plane_helper_funcs;
struct kunit; struct kunit;
struct device *drm_kunit_helper_alloc_device(struct kunit *test); struct device *drm_kunit_helper_alloc_device(struct kunit *test);
...@@ -99,4 +101,13 @@ drm_kunit_helper_atomic_state_alloc(struct kunit *test, ...@@ -99,4 +101,13 @@ drm_kunit_helper_atomic_state_alloc(struct kunit *test,
struct drm_device *drm, struct drm_device *drm,
struct drm_modeset_acquire_ctx *ctx); struct drm_modeset_acquire_ctx *ctx);
struct drm_plane *
drm_kunit_helper_create_primary_plane(struct kunit *test,
struct drm_device *drm,
const struct drm_plane_funcs *funcs,
const struct drm_plane_helper_funcs *helper_funcs,
const uint32_t *formats,
unsigned int num_formats,
const uint64_t *modifiers);
#endif // DRM_KUNIT_HELPERS_H_ #endif // DRM_KUNIT_HELPERS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment