]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/sysfb: Maintain CRTC state in struct drm_sysfb_crtc_state
authorThomas Zimmermann <tzimmermann@suse.de>
Tue, 1 Apr 2025 09:37:12 +0000 (11:37 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Mon, 7 Apr 2025 09:02:07 +0000 (11:02 +0200)
Move ofdrm's struct ofdrm_crtc_state plus functions to sysfb
helpers and rename everything to drm_sysfb_crtc_state.

The sysfb CRTC state is a regular CRTC state with information on
the primary plane's color format, as required for color management.
Helpers for sysfb planes will later set this up automatically.

In ofdrm and simpledrm, replace existing code with the new helpers.
Ofdrm continues to use the CRTC state for color management. This
has no effect on simpledrm.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://lore.kernel.org/r/20250401094056.32904-10-tzimmermann@suse.de
drivers/gpu/drm/sysfb/drm_sysfb_helper.c
drivers/gpu/drm/sysfb/drm_sysfb_helper.h
drivers/gpu/drm/sysfb/ofdrm.c
drivers/gpu/drm/sysfb/simpledrm.c

index 355e025c7c625ed9c337b2fb7107ff15d97d93be..368061b6f514689ce1602314a6bcc53f295b8c70 100644 (file)
@@ -1,7 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0-only
 
+#include <linux/export.h>
+#include <linux/slab.h>
 #include <linux/module.h>
 
+#include <drm/drm_atomic_state_helper.h>
+#include <drm/drm_print.h>
 #include <drm/drm_probe_helper.h>
 
 #include "drm_sysfb_helper.h"
@@ -33,6 +37,61 @@ struct drm_display_mode drm_sysfb_mode(unsigned int width,
 }
 EXPORT_SYMBOL(drm_sysfb_mode);
 
+/*
+ * CRTC
+ */
+
+static void drm_sysfb_crtc_state_destroy(struct drm_sysfb_crtc_state *sysfb_crtc_state)
+{
+       __drm_atomic_helper_crtc_destroy_state(&sysfb_crtc_state->base);
+
+       kfree(sysfb_crtc_state);
+}
+
+void drm_sysfb_crtc_reset(struct drm_crtc *crtc)
+{
+       struct drm_sysfb_crtc_state *sysfb_crtc_state;
+
+       if (crtc->state)
+               drm_sysfb_crtc_state_destroy(to_drm_sysfb_crtc_state(crtc->state));
+
+       sysfb_crtc_state = kzalloc(sizeof(*sysfb_crtc_state), GFP_KERNEL);
+       if (sysfb_crtc_state)
+               __drm_atomic_helper_crtc_reset(crtc, &sysfb_crtc_state->base);
+       else
+               __drm_atomic_helper_crtc_reset(crtc, NULL);
+}
+EXPORT_SYMBOL(drm_sysfb_crtc_reset);
+
+struct drm_crtc_state *drm_sysfb_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
+{
+       struct drm_device *dev = crtc->dev;
+       struct drm_crtc_state *crtc_state = crtc->state;
+       struct drm_sysfb_crtc_state *new_sysfb_crtc_state;
+       struct drm_sysfb_crtc_state *sysfb_crtc_state;
+
+       if (drm_WARN_ON(dev, !crtc_state))
+               return NULL;
+
+       new_sysfb_crtc_state = kzalloc(sizeof(*new_sysfb_crtc_state), GFP_KERNEL);
+       if (!new_sysfb_crtc_state)
+               return NULL;
+
+       sysfb_crtc_state = to_drm_sysfb_crtc_state(crtc_state);
+
+       __drm_atomic_helper_crtc_duplicate_state(crtc, &new_sysfb_crtc_state->base);
+       new_sysfb_crtc_state->format = sysfb_crtc_state->format;
+
+       return &new_sysfb_crtc_state->base;
+}
+EXPORT_SYMBOL(drm_sysfb_crtc_atomic_duplicate_state);
+
+void drm_sysfb_crtc_atomic_destroy_state(struct drm_crtc *crtc, struct drm_crtc_state *crtc_state)
+{
+       drm_sysfb_crtc_state_destroy(to_drm_sysfb_crtc_state(crtc_state));
+}
+EXPORT_SYMBOL(drm_sysfb_crtc_atomic_destroy_state);
+
 /*
  * Connector
  */
index 7e3fe9fa5cff93eb545aeb3bf29d2cdd25a226fa..91da27405a46d4b1378d70a4401ea5a0895c0a9b 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/container_of.h>
 #include <linux/iosys-map.h>
 
+#include <drm/drm_crtc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_modes.h>
 
@@ -37,6 +38,34 @@ static inline struct drm_sysfb_device *to_drm_sysfb_device(struct drm_device *de
        return container_of(dev, struct drm_sysfb_device, dev);
 }
 
+/*
+ * CRTC
+ */
+
+struct drm_sysfb_crtc_state {
+       struct drm_crtc_state base;
+
+       /* Primary-plane format; required for color mgmt. */
+       const struct drm_format_info *format;
+};
+
+static inline struct drm_sysfb_crtc_state *
+to_drm_sysfb_crtc_state(struct drm_crtc_state *base)
+{
+       return container_of(base, struct drm_sysfb_crtc_state, base);
+}
+
+void drm_sysfb_crtc_reset(struct drm_crtc *crtc);
+struct drm_crtc_state *drm_sysfb_crtc_atomic_duplicate_state(struct drm_crtc *crtc);
+void drm_sysfb_crtc_atomic_destroy_state(struct drm_crtc *crtc, struct drm_crtc_state *crtc_state);
+
+#define DRM_SYSFB_CRTC_FUNCS \
+       .reset = drm_sysfb_crtc_reset, \
+       .set_config = drm_atomic_helper_set_config, \
+       .page_flip = drm_atomic_helper_page_flip, \
+       .atomic_duplicate_state = drm_sysfb_crtc_atomic_duplicate_state, \
+       .atomic_destroy_state = drm_sysfb_crtc_atomic_destroy_state
+
 /*
  * Connector
  */
index 85db7441d1bf4f8a0727874fc43653b131f1c492..faaf35ba17f36699acdc27ab3a1b3279a30ed935 100644 (file)
@@ -725,24 +725,6 @@ static void ofdrm_device_set_gamma(struct ofdrm_device *odev,
  * Modesetting
  */
 
-struct ofdrm_crtc_state {
-       struct drm_crtc_state base;
-
-       /* Primary-plane format; required for color mgmt. */
-       const struct drm_format_info *format;
-};
-
-static struct ofdrm_crtc_state *to_ofdrm_crtc_state(struct drm_crtc_state *base)
-{
-       return container_of(base, struct ofdrm_crtc_state, base);
-}
-
-static void ofdrm_crtc_state_destroy(struct ofdrm_crtc_state *ofdrm_crtc_state)
-{
-       __drm_atomic_helper_crtc_destroy_state(&ofdrm_crtc_state->base);
-       kfree(ofdrm_crtc_state);
-}
-
 static const uint64_t ofdrm_primary_plane_format_modifiers[] = {
        DRM_FORMAT_MOD_LINEAR,
        DRM_FORMAT_MOD_INVALID
@@ -759,7 +741,7 @@ static int ofdrm_primary_plane_helper_atomic_check(struct drm_plane *plane,
        struct drm_framebuffer *new_fb = new_plane_state->fb;
        struct drm_crtc *new_crtc = new_plane_state->crtc;
        struct drm_crtc_state *new_crtc_state = NULL;
-       struct ofdrm_crtc_state *new_ofdrm_crtc_state;
+       struct drm_sysfb_crtc_state *new_sysfb_crtc_state;
        int ret;
 
        if (new_crtc)
@@ -786,8 +768,8 @@ static int ofdrm_primary_plane_helper_atomic_check(struct drm_plane *plane,
 
        new_crtc_state = drm_atomic_get_new_crtc_state(new_state, new_plane_state->crtc);
 
-       new_ofdrm_crtc_state = to_ofdrm_crtc_state(new_crtc_state);
-       new_ofdrm_crtc_state->format = new_fb->format;
+       new_sysfb_crtc_state = to_drm_sysfb_crtc_state(new_crtc_state);
+       new_sysfb_crtc_state->format = new_fb->format;
 
        return 0;
 }
@@ -920,10 +902,10 @@ static void ofdrm_crtc_helper_atomic_flush(struct drm_crtc *crtc, struct drm_ato
 {
        struct ofdrm_device *odev = ofdrm_device_of_dev(crtc->dev);
        struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
-       struct ofdrm_crtc_state *ofdrm_crtc_state = to_ofdrm_crtc_state(crtc_state);
+       struct drm_sysfb_crtc_state *sysfb_crtc_state = to_drm_sysfb_crtc_state(crtc_state);
 
        if (crtc_state->enable && crtc_state->color_mgmt_changed) {
-               const struct drm_format_info *format = ofdrm_crtc_state->format;
+               const struct drm_format_info *format = sysfb_crtc_state->format;
 
                if (crtc_state->gamma_lut)
                        ofdrm_device_set_gamma(odev, format, crtc_state->gamma_lut->data);
@@ -943,55 +925,9 @@ static const struct drm_crtc_helper_funcs ofdrm_crtc_helper_funcs = {
        .atomic_flush = ofdrm_crtc_helper_atomic_flush,
 };
 
-static void ofdrm_crtc_reset(struct drm_crtc *crtc)
-{
-       struct ofdrm_crtc_state *ofdrm_crtc_state =
-               kzalloc(sizeof(*ofdrm_crtc_state), GFP_KERNEL);
-
-       if (crtc->state)
-               ofdrm_crtc_state_destroy(to_ofdrm_crtc_state(crtc->state));
-
-       if (ofdrm_crtc_state)
-               __drm_atomic_helper_crtc_reset(crtc, &ofdrm_crtc_state->base);
-       else
-               __drm_atomic_helper_crtc_reset(crtc, NULL);
-}
-
-static struct drm_crtc_state *ofdrm_crtc_atomic_duplicate_state(struct drm_crtc *crtc)
-{
-       struct drm_device *dev = crtc->dev;
-       struct drm_crtc_state *crtc_state = crtc->state;
-       struct ofdrm_crtc_state *new_ofdrm_crtc_state;
-       struct ofdrm_crtc_state *ofdrm_crtc_state;
-
-       if (drm_WARN_ON(dev, !crtc_state))
-               return NULL;
-
-       new_ofdrm_crtc_state = kzalloc(sizeof(*new_ofdrm_crtc_state), GFP_KERNEL);
-       if (!new_ofdrm_crtc_state)
-               return NULL;
-
-       ofdrm_crtc_state = to_ofdrm_crtc_state(crtc_state);
-
-       __drm_atomic_helper_crtc_duplicate_state(crtc, &new_ofdrm_crtc_state->base);
-       new_ofdrm_crtc_state->format = ofdrm_crtc_state->format;
-
-       return &new_ofdrm_crtc_state->base;
-}
-
-static void ofdrm_crtc_atomic_destroy_state(struct drm_crtc *crtc,
-                                           struct drm_crtc_state *crtc_state)
-{
-       ofdrm_crtc_state_destroy(to_ofdrm_crtc_state(crtc_state));
-}
-
 static const struct drm_crtc_funcs ofdrm_crtc_funcs = {
-       .reset = ofdrm_crtc_reset,
+       DRM_SYSFB_CRTC_FUNCS,
        .destroy = drm_crtc_cleanup,
-       .set_config = drm_atomic_helper_set_config,
-       .page_flip = drm_atomic_helper_page_flip,
-       .atomic_duplicate_state = ofdrm_crtc_atomic_duplicate_state,
-       .atomic_destroy_state = ofdrm_crtc_atomic_destroy_state,
 };
 
 static const struct drm_encoder_funcs ofdrm_encoder_funcs = {
index 6d76d125d126a319e11dce311a598ee069fefc4e..986177e4a0f05f55d91dbb25c0f331b2f8f309c5 100644 (file)
@@ -715,12 +715,8 @@ static const struct drm_crtc_helper_funcs simpledrm_crtc_helper_funcs = {
 };
 
 static const struct drm_crtc_funcs simpledrm_crtc_funcs = {
-       .reset = drm_atomic_helper_crtc_reset,
+       DRM_SYSFB_CRTC_FUNCS,
        .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 const struct drm_encoder_funcs simpledrm_encoder_funcs = {