Skip to contentSkip to conversation

drm/hyperv: Replace simple-KMS with regular atomic helpers

PATCH Superseded Ryosuke Yasuoka 2 participants 2 messages Apr 20, 2025 – Apr 22, 2025

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/hyperv: Replace simple-KMS with regular atomic helpers

Drop simple-KMS in favor of regular atomic helpers to make the code more modular. The simple-KMS helper mix up plane and CRTC state, so it is obsolete and should go away [1]. Since it just split the simple-pipe funtions into per-plane and per-CRTC, no functional changes is expected.

[1] https://lore.kernel.org/lkml/[email protected]/

---
 drivers/gpu/drm/hyperv/hyperv_drm.h         |   4 +-
 drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 168 ++++++++++++++++----
 2 files changed, 139 insertions(+), 33 deletions(-)
drivers/gpu/drm/hyperv/hyperv_drm.h +3 -1
index d2d8582b36df..9e776112c03e 100644
@@ -11,7 +11,9 @@
 struct hyperv_drm_device {
 	/* drm */
 	struct drm_device dev;
-	struct drm_simple_display_pipe pipe;
+	struct drm_plane plane;
+	struct drm_crtc crtc;
+	struct drm_encoder encoder;
 	struct drm_connector connector;
 
 	/* mode */
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +136 -32

224 lines not on this page · raw message

base-commit: b60301774a8fe6c30b14a95104ec099290a2e904

Signature · 1 line
2.49.0
#1 lore raw

Hi

Am 20.04.25 um 14:19 schrieb Ryosuke Yasuoka:

Quoted 8 lines

Drop simple-KMS in favor of regular atomic helpers to make the code more modular. The simple-KMS helper mix up plane and CRTC state, so it is obsolete and should go away [1]. Since it just split the simple-pipe funtions into per-plane and per-CRTC, no functional changes is expected.

[1] https://lore.kernel.org/lkml/[email protected]/

I cannot test, but thanks for doing this. Comments below.

Quoted 54 lines
---
  drivers/gpu/drm/hyperv/hyperv_drm.h         |   4 +-
  drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 168 ++++++++++++++++----
  2 files changed, 139 insertions(+), 33 deletions(-)
drivers/gpu/drm/hyperv/hyperv_drm.h +3 -1
index d2d8582b36df..9e776112c03e 100644
@@ -11,7 +11,9 @@
  struct hyperv_drm_device {
  	/* drm */
  	struct drm_device dev;
-	struct drm_simple_display_pipe pipe;
+	struct drm_plane plane;
+	struct drm_crtc crtc;
+	struct drm_encoder encoder;
  	struct drm_connector connector;
 
  	/* mode */
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +8 -4
index 6c6b57298797..c273c093b491 100644
@@ -5,6 +5,7 @@
 
  #include <linux/hyperv.h>
 
+#include <drm/drm_atomic.h>
  #include <drm/drm_damage_helper.h>
  #include <drm/drm_drv.h>
  #include <drm/drm_edid.h>
@@ -15,7 +16,7 @@
  #include <drm/drm_gem_framebuffer_helper.h>
  #include <drm/drm_gem_shmem_helper.h>
  #include <drm/drm_probe_helper.h>
-#include <drm/drm_simple_kms_helper.h>
+#include <drm/drm_plane.h>
 
  #include "hyperv_drm.h"
 
@@ -98,12 +99,47 @@ static int hyperv_check_size(struct hyperv_drm_device *hv, int w, int h,
  	return 0;
  }
 
-static void hyperv_pipe_enable(struct drm_simple_display_pipe *pipe,
-			       struct drm_crtc_state *crtc_state,
-			       struct drm_plane_state *plane_state)
+static const uint32_t hyperv_formats[] = {
+	DRM_FORMAT_XRGB8888,
+};
+
+static const uint64_t hyperv_modifiers[] = {
+	DRM_FORMAT_MOD_LINEAR,

drivers/gpu/drm/hyperv/hyperv_drm_modeset.c static int hyperv_check_size(struct hyperv_drm_device *hv, int w, int h, · line 117

Quoted 10 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +9 -0
+	DRM_FORMAT_MOD_INVALID
+};
+
 
+static enum drm_mode_status
+hyperv_crtc_helper_mode_valid(struct drm_crtc *crtc,
+			      const struct drm_display_mode *mode)
+{
+	return MODE_OK;
+}

This helper should not be necessary.

Quoted 8 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +6 -1
+
+static int hyperv_crtc_helper_atomic_check(struct drm_crtc *crtc,
+					   struct drm_atomic_state *state)
  {
-	struct hyperv_drm_device *hv = to_hv(pipe->crtc.dev);
+	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
+	int ret;
+

drivers/gpu/drm/hyperv/hyperv_drm_modeset.c static int hyperv_check_size(struct hyperv_drm_device *hv, int w, int h,

Quoted 10 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +9 -0
+	if (!crtc_state->enable)
+		goto out;
+
+	ret = drm_atomic_helper_check_crtc_primary_plane(crtc_state);
+	if (ret)
+		return ret;
+
+out:
 
+	return drm_atomic_add_affected_planes(state, crtc);

IIRC this function call was only required to work around an issue in the simple-kms helpers. It's not necessary if you use the regular interface and should be removed.

Quoted 13 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +9 -0
+}
+
+static void hyperv_crtc_helper_atomic_enable(struct drm_crtc *crtc,
+					     struct drm_atomic_state *state)
+{
+	struct hyperv_drm_device *hv = to_hv(crtc->dev);
+	struct drm_plane *plane = &hv->plane;
+	struct drm_plane_state *plane_state = plane->state;
  	struct drm_shadow_plane_state *shadow_plane_state = to_drm_shadow_plane_state(plane_state);
+	struct drm_crtc_state *crtc_state = crtc->state;
 
  	hyperv_hide_hw_ptr(hv->hdev);
Quoted 1 line

hyperv_update_situation(hv->hdev, 1, hv->screen_depth,

This looks more like something to do in the plane's atomic_enable, but it's OK for now.

drivers/gpu/drm/hyperv/hyperv_drm_modeset.c static void hyperv_pipe_enable(struct drm_simple_display_pipe *pipe, · line 149

Quoted 2 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +0 -0
@@ -113,12 +149,48 @@ static void hyperv_pipe_enable(struct drm_simple_display_pipe *pipe,
  	hyperv_blit_to_vram_fullscreen(plane_state->fb, &shadow_plane_state->data[0]);

I think this can be removed. Blit'ing is for planes and the plane already does it it's atomic_update. Doing this here as well is another artifact of the simple-kms helpers.

Quoted 51 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +40 -4
  }
 
-static int hyperv_pipe_check(struct drm_simple_display_pipe *pipe,
-			     struct drm_plane_state *plane_state,
-			     struct drm_crtc_state *crtc_state)
+static void hyperv_crtc_helper_atomic_disable(struct drm_crtc *crtc,
+					      struct drm_atomic_state *state)
+{ }
+
+static const struct drm_crtc_helper_funcs hyperv_crtc_helper_funcs = {
+	.mode_valid = hyperv_crtc_helper_mode_valid,
+	.atomic_check = hyperv_crtc_helper_atomic_check,
+	.atomic_enable = hyperv_crtc_helper_atomic_enable,
+	.atomic_disable = hyperv_crtc_helper_atomic_disable,
+};
+
+static const struct drm_crtc_funcs hyperv_crtc_funcs = {
+	.reset = drm_atomic_helper_crtc_reset,
+	.destroy = drm_crtc_cleanup,
+	.set_config = drm_atomic_helper_set_config,
+	.page_flip = drm_atomic_helper_page_flip,
+	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
+};
+
+static int hyperv_plane_atomic_check(struct drm_plane *plane,
+				     struct drm_atomic_state *state)
  {
-	struct hyperv_drm_device *hv = to_hv(pipe->crtc.dev);
+	struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(state, plane);
+	struct hyperv_drm_device *hv = to_hv(plane->dev);
  	struct drm_framebuffer *fb = plane_state->fb;
+	struct drm_crtc *crtc = plane_state->crtc;
+	struct drm_crtc_state *crtc_state = NULL;
+	int ret;
+
+	if (crtc)
+		crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
+
+	ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
+						  DRM_PLANE_NO_SCALING,
+						  DRM_PLANE_NO_SCALING,
+						  false, false);
+	if (ret)
+		return ret;
+
+	if (!plane_state->visible)
+		return 0;
 
 
  	if (fb->format->format != DRM_FORMAT_XRGB8888)
Quoted 1 line

return -EINVAL;

Our DRM core should have done this test already.

Quoted 25 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +6 -6
@@ -132,51 +204,83 @@ static int hyperv_pipe_check(struct drm_simple_display_pipe *pipe,
  	return 0;
  }
 
-static void hyperv_pipe_update(struct drm_simple_display_pipe *pipe,
-			       struct drm_plane_state *old_state)
+static void hyperv_plane_atomic_update(struct drm_plane *plane,
+						      struct drm_atomic_state *old_state)
  {
-	struct hyperv_drm_device *hv = to_hv(pipe->crtc.dev);
-	struct drm_plane_state *state = pipe->plane.state;
+	struct drm_plane_state *old_pstate = drm_atomic_get_old_plane_state(old_state, plane);
+	struct hyperv_drm_device *hv = to_hv(plane->dev);
+	struct drm_plane_state *state = plane->state;
  	struct drm_shadow_plane_state *shadow_plane_state = to_drm_shadow_plane_state(state);
  	struct drm_rect rect;
 
-	if (drm_atomic_helper_damage_merged(old_state, state, &rect)) {
+	if (drm_atomic_helper_damage_merged(old_pstate, state, &rect)) {
  		hyperv_blit_to_vram_rect(state->fb, &shadow_plane_state->data[0], &rect);
  		hyperv_update_dirt(hv->hdev, &rect);
  	}
  }
 
-static const struct drm_simple_display_pipe_funcs hyperv_pipe_funcs = {

drivers/gpu/drm/hyperv/hyperv_drm_modeset.c static int hyperv_pipe_check(struct drm_simple_display_pipe *pipe, · line 227

Quoted 10 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +5 -4
-	.enable	= hyperv_pipe_enable,
-	.check = hyperv_pipe_check,
-	.update	= hyperv_pipe_update,
-	DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS,
 
+static bool hyperv_format_mod_supported(struct drm_plane *plane,
+					uint32_t format, uint64_t modifier)
+{
+	return modifier == DRM_FORMAT_MOD_LINEAR;
+}

This helper is probably not necessary either.

Quoted 31 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +18 -5
+
+static const struct drm_plane_helper_funcs hyperv_plane_helper_funcs = {
+	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
+	.atomic_check = hyperv_plane_atomic_check,
+	.atomic_update = hyperv_plane_atomic_update,
  };
 
-static const uint32_t hyperv_formats[] = {
-	DRM_FORMAT_XRGB8888,
+static const struct drm_plane_funcs hyperv_plane_funcs = {
+	.update_plane		= drm_atomic_helper_update_plane,
+	.disable_plane		= drm_atomic_helper_disable_plane,
+	.destroy		= drm_plane_cleanup,
+	.format_mod_supported   = hyperv_format_mod_supported,
+	DRM_GEM_SHADOW_PLANE_FUNCS,
  };
 
-static const uint64_t hyperv_modifiers[] = {
-	DRM_FORMAT_MOD_LINEAR,
-	DRM_FORMAT_MOD_INVALID
+static const struct drm_encoder_funcs hyperv_drm_simple_encoder_funcs_cleanup = {
+	.destroy = drm_encoder_cleanup,
  };
 
  static inline int hyperv_pipe_init(struct hyperv_drm_device *hv)
  {
+	struct drm_device *dev = &hv->dev;
+	struct drm_encoder *encoder = &hv->encoder;
+	struct drm_plane *plane = &hv->plane;
+	struct drm_crtc *crtc = &hv->crtc;
+	struct drm_connector *connector = &hv->connector;

drivers/gpu/drm/hyperv/hyperv_drm_modeset.c static int hyperv_pipe_check(struct drm_simple_display_pipe *pipe, · line 255

Quoted 10 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +1 -7
  	int ret;
 
-	ret = drm_simple_display_pipe_init(&hv->dev,
-					   &hv->pipe,
-					   &hyperv_pipe_funcs,
-					   hyperv_formats,
-					   ARRAY_SIZE(hyperv_formats),
-					   hyperv_modifiers,
-					   &hv->connector);
+	drm_plane_helper_add(plane, &hyperv_plane_helper_funcs);

Rather call drm_universal_plane_init() first and then add the helper funcs.

drivers/gpu/drm/hyperv/hyperv_drm_modeset.c static int hyperv_pipe_check(struct drm_simple_display_pipe *pipe, · line 266

Quoted 11 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +11 -0
+	ret = drm_universal_plane_init(dev, plane, 0,
+				       &hyperv_plane_funcs,
+				       hyperv_formats, ARRAY_SIZE(hyperv_formats),
+				       hyperv_modifiers,
+				       DRM_PLANE_TYPE_PRIMARY, NULL);
+	if (ret)
+		return ret;
+
+	drm_crtc_helper_add(crtc, &hyperv_crtc_helper_funcs);
+	ret = drm_crtc_init_with_planes(dev, crtc, plane, NULL,
+					&hyperv_crtc_funcs, NULL);

Same ordering nit as with the plane.

drivers/gpu/drm/hyperv/hyperv_drm_modeset.c static int hyperv_pipe_check(struct drm_simple_display_pipe *pipe, · line 276

Quoted 10 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +10 -0
+	if (ret)
+		return ret;
+
+	encoder->possible_crtcs = drm_crtc_mask(crtc);
+	ret = drm_encoder_init(dev, encoder,
+			       &hyperv_drm_simple_encoder_funcs_cleanup,
+			       DRM_MODE_ENCODER_NONE, NULL);
+
+	if (ret || !connector)
+		return ret;

Connector init happens elsewhere, but you can inline hyperv_conn_init() right here.

drivers/gpu/drm/hyperv/hyperv_drm_modeset.c static int hyperv_pipe_check(struct drm_simple_display_pipe *pipe, · line 283

Quoted 8 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +4 -1
+
+	ret = drm_connector_attach_encoder(connector, encoder);
+
  	if (ret)
  		return ret;
 
-	drm_plane_enable_fb_damage_clips(&hv->pipe.plane);
+	drm_plane_enable_fb_damage_clips(&hv->plane);

This is a plane function you can move it close to the plane init.

Best regards
Thomas

Quoted 5 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +0 -0
  	return 0;
  }

base-commit: b60301774a8fe6c30b14a95104ec099290a2e904

Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)