drm: Add crtc->name and use it in debug messages
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Tue, 8 Dec 2015 16:41:53 +0000 (18:41 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Fri, 11 Dec 2015 08:13:48 +0000 (09:13 +0100)
Show a sensible name for the crtc in debug mesages. The driver may
supply its own name, otherwise the core genrates the name
("crtc-0", "crtc-1" etc.).

v2: kstrdup() the name passed by the caller (Jani)
v3: Generate a default name if the driver doesn't supply one

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1449592922-5545-6-git-send-email-ville.syrjala@linux.intel.com
drivers/gpu/drm/drm_atomic.c
drivers/gpu/drm/drm_atomic_helper.c
drivers/gpu/drm/drm_crtc.c
drivers/gpu/drm/drm_crtc_helper.c
include/drm/drm_crtc.h

index 07ab75e22b2b65e27cfe57eaffeea539b0c48dda..feb66895e48cf3dda1c7213668987ea29a7c5375 100644 (file)
@@ -288,8 +288,8 @@ drm_atomic_get_crtc_state(struct drm_atomic_state *state,
        state->crtcs[index] = crtc;
        crtc_state->state = state;
 
-       DRM_DEBUG_ATOMIC("Added [CRTC:%d] %p state to %p\n",
-                        crtc->base.id, crtc_state, state);
+       DRM_DEBUG_ATOMIC("Added [CRTC:%d:%s] %p state to %p\n",
+                        crtc->base.id, crtc->name, crtc_state, state);
 
        return crtc_state;
 }
@@ -486,8 +486,8 @@ static int drm_atomic_crtc_check(struct drm_crtc *crtc,
         */
 
        if (state->active && !state->enable) {
-               DRM_DEBUG_ATOMIC("[CRTC:%d] active without enabled\n",
-                                crtc->base.id);
+               DRM_DEBUG_ATOMIC("[CRTC:%d:%s] active without enabled\n",
+                                crtc->base.id, crtc->name);
                return -EINVAL;
        }
 
@@ -496,15 +496,15 @@ static int drm_atomic_crtc_check(struct drm_crtc *crtc,
         * be able to trigger. */
        if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
            WARN_ON(state->enable && !state->mode_blob)) {
-               DRM_DEBUG_ATOMIC("[CRTC:%d] enabled without mode blob\n",
-                                crtc->base.id);
+               DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enabled without mode blob\n",
+                                crtc->base.id, crtc->name);
                return -EINVAL;
        }
 
        if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
            WARN_ON(!state->enable && state->mode_blob)) {
-               DRM_DEBUG_ATOMIC("[CRTC:%d] disabled with mode blob\n",
-                                crtc->base.id);
+               DRM_DEBUG_ATOMIC("[CRTC:%d:%s] disabled with mode blob\n",
+                                crtc->base.id, crtc->name);
                return -EINVAL;
        }
 
@@ -1004,8 +1004,8 @@ drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
        }
 
        if (crtc)
-               DRM_DEBUG_ATOMIC("Link plane state %p to [CRTC:%d]\n",
-                                plane_state, crtc->base.id);
+               DRM_DEBUG_ATOMIC("Link plane state %p to [CRTC:%d:%s]\n",
+                                plane_state, crtc->base.id, crtc->name);
        else
                DRM_DEBUG_ATOMIC("Link plane state %p to [NOCRTC]\n",
                                 plane_state);
@@ -1072,8 +1072,8 @@ drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
        conn_state->crtc = crtc;
 
        if (crtc)
-               DRM_DEBUG_ATOMIC("Link connector state %p to [CRTC:%d]\n",
-                                conn_state, crtc->base.id);
+               DRM_DEBUG_ATOMIC("Link connector state %p to [CRTC:%d:%s]\n",
+                                conn_state, crtc->base.id, crtc->name);
        else
                DRM_DEBUG_ATOMIC("Link connector state %p to [NOCRTC]\n",
                                 conn_state);
@@ -1112,8 +1112,8 @@ drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
        if (ret)
                return ret;
 
-       DRM_DEBUG_ATOMIC("Adding all current connectors for [CRTC:%d] to %p\n",
-                        crtc->base.id, state);
+       DRM_DEBUG_ATOMIC("Adding all current connectors for [CRTC:%d:%s] to %p\n",
+                        crtc->base.id, crtc->name, state);
 
        /*
         * Changed connectors are already in @state, so only need to look at the
@@ -1193,8 +1193,9 @@ drm_atomic_connectors_for_crtc(struct drm_atomic_state *state,
                        num_connected_connectors++;
        }
 
-       DRM_DEBUG_ATOMIC("State %p has %i connectors for [CRTC:%d]\n",
-                        state, num_connected_connectors, crtc->base.id);
+       DRM_DEBUG_ATOMIC("State %p has %i connectors for [CRTC:%d:%s]\n",
+                        state, num_connected_connectors,
+                        crtc->base.id, crtc->name);
 
        return num_connected_connectors;
 }
@@ -1256,8 +1257,8 @@ int drm_atomic_check_only(struct drm_atomic_state *state)
        for_each_crtc_in_state(state, crtc, crtc_state, i) {
                ret = drm_atomic_crtc_check(crtc, crtc_state);
                if (ret) {
-                       DRM_DEBUG_ATOMIC("[CRTC:%d] atomic core check failed\n",
-                                        crtc->base.id);
+                       DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic core check failed\n",
+                                        crtc->base.id, crtc->name);
                        return ret;
                }
        }
@@ -1268,8 +1269,8 @@ int drm_atomic_check_only(struct drm_atomic_state *state)
        if (!state->allow_modeset) {
                for_each_crtc_in_state(state, crtc, crtc_state, i) {
                        if (drm_atomic_crtc_needs_modeset(crtc_state)) {
-                               DRM_DEBUG_ATOMIC("[CRTC:%d] requires full modeset\n",
-                                                crtc->base.id);
+                               DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requires full modeset\n",
+                                                crtc->base.id, crtc->name);
                                return -EINVAL;
                        }
                }
index 110f3db8dd05b93673671eea4ebf620c04c13a96..6ba3fe5639e4c4f2a754c6733c328d08aad077f0 100644 (file)
@@ -143,9 +143,9 @@ steal_encoder(struct drm_atomic_state *state,
         */
        WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
 
-       DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d], stealing it\n",
+       DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s], stealing it\n",
                         encoder->base.id, encoder->name,
-                        encoder_crtc->base.id);
+                        encoder_crtc->base.id, encoder_crtc->name);
 
        crtc_state = drm_atomic_get_crtc_state(state, encoder_crtc);
        if (IS_ERR(crtc_state))
@@ -246,12 +246,13 @@ update_connector_routing(struct drm_atomic_state *state, int conn_idx)
        }
 
        if (new_encoder == connector_state->best_encoder) {
-               DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] keeps [ENCODER:%d:%s], now on [CRTC:%d]\n",
+               DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] keeps [ENCODER:%d:%s], now on [CRTC:%d:%s]\n",
                                 connector->base.id,
                                 connector->name,
                                 new_encoder->base.id,
                                 new_encoder->name,
-                                connector_state->crtc->base.id);
+                                connector_state->crtc->base.id,
+                                connector_state->crtc->name);
 
                return 0;
        }
@@ -285,12 +286,13 @@ update_connector_routing(struct drm_atomic_state *state, int conn_idx)
        crtc_state = state->crtc_states[idx];
        crtc_state->connectors_changed = true;
 
-       DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d]\n",
+       DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d:%s]\n",
                         connector->base.id,
                         connector->name,
                         new_encoder->base.id,
                         new_encoder->name,
-                        connector_state->crtc->base.id);
+                        connector_state->crtc->base.id,
+                        connector_state->crtc->name);
 
        return 0;
 }
@@ -374,8 +376,8 @@ mode_fixup(struct drm_atomic_state *state)
                ret = funcs->mode_fixup(crtc, &crtc_state->mode,
                                        &crtc_state->adjusted_mode);
                if (!ret) {
-                       DRM_DEBUG_ATOMIC("[CRTC:%d] fixup failed\n",
-                                        crtc->base.id);
+                       DRM_DEBUG_ATOMIC("[CRTC:%d:%s] fixup failed\n",
+                                        crtc->base.id, crtc->name);
                        return -EINVAL;
                }
        }
@@ -422,14 +424,14 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,
 
        for_each_crtc_in_state(state, crtc, crtc_state, i) {
                if (!drm_mode_equal(&crtc->state->mode, &crtc_state->mode)) {
-                       DRM_DEBUG_ATOMIC("[CRTC:%d] mode changed\n",
-                                        crtc->base.id);
+                       DRM_DEBUG_ATOMIC("[CRTC:%d:%s] mode changed\n",
+                                        crtc->base.id, crtc->name);
                        crtc_state->mode_changed = true;
                }
 
                if (crtc->state->enable != crtc_state->enable) {
-                       DRM_DEBUG_ATOMIC("[CRTC:%d] enable changed\n",
-                                        crtc->base.id);
+                       DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enable changed\n",
+                                        crtc->base.id, crtc->name);
 
                        /*
                         * For clarity this assignment is done here, but
@@ -470,18 +472,18 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,
                 * a full modeset because update_connector_routing force that.
                 */
                if (crtc->state->active != crtc_state->active) {
-                       DRM_DEBUG_ATOMIC("[CRTC:%d] active changed\n",
-                                        crtc->base.id);
+                       DRM_DEBUG_ATOMIC("[CRTC:%d:%s] active changed\n",
+                                        crtc->base.id, crtc->name);
                        crtc_state->active_changed = true;
                }
 
                if (!drm_atomic_crtc_needs_modeset(crtc_state))
                        continue;
 
-               DRM_DEBUG_ATOMIC("[CRTC:%d] needs all connectors, enable: %c, active: %c\n",
-                                crtc->base.id,
+               DRM_DEBUG_ATOMIC("[CRTC:%d:%s] needs all connectors, enable: %c, active: %c\n",
+                                crtc->base.id, crtc->name,
                                 crtc_state->enable ? 'y' : 'n',
-                             crtc_state->active ? 'y' : 'n');
+                                crtc_state->active ? 'y' : 'n');
 
                ret = drm_atomic_add_affected_connectors(state, crtc);
                if (ret != 0)
@@ -495,8 +497,8 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,
                                                                crtc);
 
                if (crtc_state->enable != !!num_connectors) {
-                       DRM_DEBUG_ATOMIC("[CRTC:%d] enabled/connectors mismatch\n",
-                                        crtc->base.id);
+                       DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enabled/connectors mismatch\n",
+                                        crtc->base.id, crtc->name);
 
                        return -EINVAL;
                }
@@ -559,8 +561,8 @@ drm_atomic_helper_check_planes(struct drm_device *dev,
 
                ret = funcs->atomic_check(crtc, state->crtc_states[i]);
                if (ret) {
-                       DRM_DEBUG_ATOMIC("[CRTC:%d] atomic driver check failed\n",
-                                        crtc->base.id);
+                       DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic driver check failed\n",
+                                        crtc->base.id, crtc->name);
                        return ret;
                }
        }
@@ -673,8 +675,8 @@ disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
 
                funcs = crtc->helper_private;
 
-               DRM_DEBUG_ATOMIC("disabling [CRTC:%d]\n",
-                                crtc->base.id);
+               DRM_DEBUG_ATOMIC("disabling [CRTC:%d:%s]\n",
+                                crtc->base.id, crtc->name);
 
 
                /* Right function depends upon target state. */
@@ -785,8 +787,8 @@ crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state)
                funcs = crtc->helper_private;
 
                if (crtc->state->enable && funcs->mode_set_nofb) {
-                       DRM_DEBUG_ATOMIC("modeset on [CRTC:%d]\n",
-                                        crtc->base.id);
+                       DRM_DEBUG_ATOMIC("modeset on [CRTC:%d:%s]\n",
+                                        crtc->base.id, crtc->name);
 
                        funcs->mode_set_nofb(crtc);
                }
@@ -885,8 +887,8 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
                funcs = crtc->helper_private;
 
                if (crtc->state->enable) {
-                       DRM_DEBUG_ATOMIC("enabling [CRTC:%d]\n",
-                                        crtc->base.id);
+                       DRM_DEBUG_ATOMIC("enabling [CRTC:%d:%s]\n",
+                                        crtc->base.id, crtc->name);
 
                        if (funcs->enable)
                                funcs->enable(crtc);
index aade4640fa6dccdc580dc146a107c40c3c88a060..efa57e8a99b5bf535fc8a6b1c3b1f3ab7160172a 100644 (file)
@@ -649,6 +649,18 @@ EXPORT_SYMBOL(drm_framebuffer_remove);
 
 DEFINE_WW_CLASS(crtc_ww_class);
 
+static unsigned int drm_num_crtcs(struct drm_device *dev)
+{
+       unsigned int num = 0;
+       struct drm_crtc *tmp;
+
+       drm_for_each_crtc(tmp, dev) {
+               num++;
+       }
+
+       return num;
+}
+
 /**
  * drm_crtc_init_with_planes - Initialise a new CRTC object with
  *    specified primary and cursor planes.
@@ -684,6 +696,21 @@ int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
        if (ret)
                return ret;
 
+       if (name) {
+               va_list ap;
+
+               va_start(ap, name);
+               crtc->name = kvasprintf(GFP_KERNEL, name, ap);
+               va_end(ap);
+       } else {
+               crtc->name = kasprintf(GFP_KERNEL, "crtc-%d",
+                                      drm_num_crtcs(dev));
+       }
+       if (!crtc->name) {
+               drm_mode_object_put(dev, &crtc->base);
+               return -ENOMEM;
+       }
+
        crtc->base.properties = &crtc->properties;
 
        list_add_tail(&crtc->head, &config->crtc_list);
@@ -730,6 +757,8 @@ void drm_crtc_cleanup(struct drm_crtc *crtc)
        if (crtc->state && crtc->funcs->atomic_destroy_state)
                crtc->funcs->atomic_destroy_state(crtc, crtc->state);
 
+       kfree(crtc->name);
+
        memset(crtc, 0, sizeof(*crtc));
 }
 EXPORT_SYMBOL(drm_crtc_cleanup);
@@ -1814,7 +1843,8 @@ int drm_mode_getresources(struct drm_device *dev, void *data,
                copied = 0;
                crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr;
                drm_for_each_crtc(crtc, dev) {
-                       DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
+                       DRM_DEBUG_KMS("[CRTC:%d:%s]\n",
+                                     crtc->base.id, crtc->name);
                        if (put_user(crtc->base.id, crtc_id + copied)) {
                                ret = -EFAULT;
                                goto out;
@@ -2659,7 +2689,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
                ret = -ENOENT;
                goto out;
        }
-       DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
+       DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
 
        if (crtc_req->mode_valid) {
                /* If we have a mode we need a framebuffer. */
index fadbdb33bdccdfe68bbf44b2addc905ec58db7c7..a02a7f9a6a9d872cbf5be0fdf521f8e9512ebe0b 100644 (file)
@@ -339,7 +339,7 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
                DRM_DEBUG_KMS("CRTC fixup failed\n");
                goto done;
        }
-       DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
+       DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
 
        crtc->hwmode = *adjusted_mode;
 
@@ -519,11 +519,13 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
                set->fb = NULL;
 
        if (set->fb) {
-               DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
-                               set->crtc->base.id, set->fb->base.id,
-                               (int)set->num_connectors, set->x, set->y);
+               DRM_DEBUG_KMS("[CRTC:%d:%s] [FB:%d] #connectors=%d (x y) (%i %i)\n",
+                             set->crtc->base.id, set->crtc->name,
+                             set->fb->base.id,
+                             (int)set->num_connectors, set->x, set->y);
        } else {
-               DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
+               DRM_DEBUG_KMS("[CRTC:%d:%s] [NOFB]\n",
+                             set->crtc->base.id, set->crtc->name);
                drm_crtc_helper_disable(set->crtc);
                return 0;
        }
@@ -663,12 +665,12 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
                        connector->encoder->crtc = new_crtc;
                }
                if (new_crtc) {
-                       DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
-                               connector->base.id, connector->name,
-                               new_crtc->base.id);
+                       DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d:%s]\n",
+                                     connector->base.id, connector->name,
+                                     new_crtc->base.id, new_crtc->name);
                } else {
                        DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
-                               connector->base.id, connector->name);
+                                     connector->base.id, connector->name);
                }
        }
 
@@ -685,8 +687,8 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
                        if (!drm_crtc_helper_set_mode(set->crtc, set->mode,
                                                      set->x, set->y,
                                                      save_set.fb)) {
-                               DRM_ERROR("failed to set mode on [CRTC:%d]\n",
-                                         set->crtc->base.id);
+                               DRM_ERROR("failed to set mode on [CRTC:%d:%s]\n",
+                                         set->crtc->base.id, set->crtc->name);
                                set->crtc->primary->fb = save_set.fb;
                                ret = -EINVAL;
                                goto fail;
index 5b5e6b650c115cc19bc39c990327dad9c43eec11..4bea0a1151bc01009fe2a8682f27adf7f4696d09 100644 (file)
@@ -712,6 +712,8 @@ struct drm_crtc {
        struct device_node *port;
        struct list_head head;
 
+       char *name;
+
        /*
         * crtc mutex
         *