drm/vkms: subclass CRTC state
authorHaneen Mohammed <hamohammed.sa@gmail.com>
Tue, 24 Jul 2018 16:31:05 +0000 (19:31 +0300)
committerSean Paul <seanpaul@chromium.org>
Mon, 30 Jul 2018 17:03:16 +0000 (13:03 -0400)
Subclass CRTC state struct to enable storing driver's private
state. This patch only adds the base drm_crtc_state struct and
the atomic functions that handle it.

Signed-off-by: Haneen Mohammed <hamohammed.sa@gmail.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/1f3564a5a0a6c4410c5d383c86a572ddda4818a8.1532446182.git.hamohammed.sa@gmail.com
drivers/gpu/drm/vkms/vkms_crtc.c
drivers/gpu/drm/vkms/vkms_drv.h

index 875fca662ac0c69c6dc56c0e0d4b1d48568140c4..26babb85ca775cd095aeb1f53aecbd7987e97fbe 100644 (file)
@@ -64,13 +64,60 @@ bool vkms_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
        return true;
 }
 
+static void vkms_atomic_crtc_reset(struct drm_crtc *crtc)
+{
+       struct vkms_crtc_state *vkms_state = NULL;
+
+       if (crtc->state) {
+               vkms_state = to_vkms_crtc_state(crtc->state);
+               __drm_atomic_helper_crtc_destroy_state(crtc->state);
+               kfree(vkms_state);
+               crtc->state = NULL;
+       }
+
+       vkms_state = kzalloc(sizeof(*vkms_state), GFP_KERNEL);
+       if (!vkms_state)
+               return;
+
+       crtc->state = &vkms_state->base;
+       crtc->state->crtc = crtc;
+}
+
+static struct drm_crtc_state *
+vkms_atomic_crtc_duplicate_state(struct drm_crtc *crtc)
+{
+       struct vkms_crtc_state *vkms_state;
+
+       if (WARN_ON(!crtc->state))
+               return NULL;
+
+       vkms_state = kzalloc(sizeof(*vkms_state), GFP_KERNEL);
+       if (!vkms_state)
+               return NULL;
+
+       __drm_atomic_helper_crtc_duplicate_state(crtc, &vkms_state->base);
+
+       return &vkms_state->base;
+}
+
+static void vkms_atomic_crtc_destroy_state(struct drm_crtc *crtc,
+                                          struct drm_crtc_state *state)
+{
+       struct vkms_crtc_state *vkms_state;
+
+       vkms_state = to_vkms_crtc_state(state);
+
+       __drm_atomic_helper_crtc_destroy_state(state);
+       kfree(vkms_state);
+}
+
 static const struct drm_crtc_funcs vkms_crtc_funcs = {
        .set_config             = drm_atomic_helper_set_config,
        .destroy                = drm_crtc_cleanup,
        .page_flip              = drm_atomic_helper_page_flip,
-       .reset                  = drm_atomic_helper_crtc_reset,
-       .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
-       .atomic_destroy_state   = drm_atomic_helper_crtc_destroy_state,
+       .reset                  = vkms_atomic_crtc_reset,
+       .atomic_duplicate_state = vkms_atomic_crtc_duplicate_state,
+       .atomic_destroy_state   = vkms_atomic_crtc_destroy_state,
        .enable_vblank          = vkms_enable_vblank,
        .disable_vblank         = vkms_disable_vblank,
 };
index 47048f7075668e1937b2c0c53a0412a29552a8e1..75e52d61e65d17fac369c20619752df061f56810 100644 (file)
@@ -20,6 +20,14 @@ static const u32 vkms_formats[] = {
        DRM_FORMAT_XRGB8888,
 };
 
+/**
+ * vkms_crtc_state - Driver specific CRTC state
+ * @base: base CRTC state
+ */
+struct vkms_crtc_state {
+       struct drm_crtc_state base;
+};
+
 struct vkms_output {
        struct drm_crtc crtc;
        struct drm_encoder encoder;
@@ -52,6 +60,9 @@ struct vkms_gem_object {
 #define drm_gem_to_vkms_gem(target)\
        container_of(target, struct vkms_gem_object, gem)
 
+#define to_vkms_crtc_state(target)\
+       container_of(target, struct vkms_crtc_state, base)
+
 /* CRTC */
 int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
                   struct drm_plane *primary, struct drm_plane *cursor);