drivers/gpu/drm/tests/drm_atomic_test.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/tests/drm_atomic_test.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/tests/drm_atomic_test.c
Extension
.c
Size
4002 bytes
Lines
154
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct drm_atomic_test_priv {
	struct drm_device drm;
	struct drm_plane *plane;
	struct drm_crtc *crtc;
	struct drm_encoder encoder;
	struct drm_connector connector;
};

static const struct drm_connector_helper_funcs drm_atomic_init_connector_helper_funcs = {
};

static const struct drm_connector_funcs drm_atomic_init_connector_funcs = {
	.atomic_destroy_state	= drm_atomic_helper_connector_destroy_state,
	.atomic_duplicate_state	= drm_atomic_helper_connector_duplicate_state,
	.reset			= drm_atomic_helper_connector_reset,
};

static struct drm_atomic_test_priv *create_device(struct kunit *test)
{
	struct drm_atomic_test_priv *priv;
	struct drm_connector *connector;
	struct drm_encoder *enc;
	struct drm_device *drm;
	struct drm_plane *plane;
	struct drm_crtc *crtc;
	struct device *dev;
	int ret;

	dev = drm_kunit_helper_alloc_device(test);
	if (IS_ERR(dev))
		return ERR_CAST(dev);

	priv = drm_kunit_helper_alloc_drm_device(test, dev,
						 struct drm_atomic_test_priv, drm,
						 DRIVER_MODESET | DRIVER_ATOMIC);
	if (IS_ERR(priv))
		return ERR_CAST(priv);

	drm = &priv->drm;
	plane = drm_kunit_helper_create_primary_plane(test, drm,
						      NULL,
						      NULL,
						      NULL, 0,
						      NULL);
	if (IS_ERR(plane))
		return ERR_CAST(plane);
	priv->plane = plane;

	crtc = drm_kunit_helper_create_crtc(test, drm,
					    plane, NULL,
					    NULL,
					    NULL);
	if (IS_ERR(crtc))
		return ERR_CAST(crtc);
	priv->crtc = crtc;

	enc = &priv->encoder;
	ret = drmm_encoder_init(drm, enc, NULL, DRM_MODE_ENCODER_TMDS, NULL);
	if (ret)
		return ERR_PTR(ret);

	enc->possible_crtcs = drm_crtc_mask(crtc);

	connector = &priv->connector;
	ret = drmm_connector_init(drm, connector,
				  &drm_atomic_init_connector_funcs,
				  DRM_MODE_CONNECTOR_VIRTUAL,
				  NULL);
	if (ret)
		return ERR_PTR(ret);

	drm_connector_helper_add(connector, &drm_atomic_init_connector_helper_funcs);

	drm_connector_attach_encoder(connector, enc);

	drm_mode_config_reset(drm);

	return priv;
}

static void drm_test_drm_atomic_get_connector_for_encoder(struct kunit *test)
{
	struct drm_modeset_acquire_ctx ctx;
	struct drm_atomic_test_priv *priv;
	struct drm_display_mode *mode;
	struct drm_connector *curr_connector;
	int ret;

	priv = create_device(test);
	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv);

Annotation

Implementation Notes