drm: Add drm_encoder_mask()
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Tue, 26 Jun 2018 19:47:09 +0000 (22:47 +0300)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Mon, 2 Jul 2018 15:45:55 +0000 (18:45 +0300)
Add drm_encoder_mask() which returns the 1<<index for the encoder.
We already have an identical drm_crtc_mask() for crtcs.

Mostly performed with coccinelle:
@@
@@
- (1<<drm_encoder_index(
+ drm_encoder_mask(
  ...)
-  )

@@
@@
- 1<<drm_encoder_index(
+ drm_encoder_mask(
  ...)

@@
@@
- BIT(drm_encoder_index(
+ drm_encoder_mask(
  ...)
- )

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180626194716.12522-3-ville.syrjala@linux.intel.com
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/drm_atomic_helper.c
include/drm/drm_encoder.h

index 4f487ceffe684cc4a5f1f29e4fc6d2bcba3f1597..8008a7de2e100a857c7fa144b73a8f60293791f2 100644 (file)
@@ -121,7 +121,7 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
                        new_encoder = drm_atomic_helper_best_encoder(connector);
 
                if (new_encoder) {
-                       if (encoder_mask & (1 << drm_encoder_index(new_encoder))) {
+                       if (encoder_mask & drm_encoder_mask(new_encoder)) {
                                DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] on [CONNECTOR:%d:%s] already assigned\n",
                                        new_encoder->base.id, new_encoder->name,
                                        connector->base.id, connector->name);
@@ -129,7 +129,7 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
                                return -EINVAL;
                        }
 
-                       encoder_mask |= 1 << drm_encoder_index(new_encoder);
+                       encoder_mask |= drm_encoder_mask(new_encoder);
                }
        }
 
@@ -155,7 +155,7 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
                        continue;
 
                encoder = connector->state->best_encoder;
-               if (!encoder || !(encoder_mask & (1 << drm_encoder_index(encoder))))
+               if (!encoder || !(encoder_mask & drm_encoder_mask(encoder)))
                        continue;
 
                if (!disable_conflicting_encoders) {
@@ -223,7 +223,7 @@ set_best_encoder(struct drm_atomic_state *state,
                        crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
 
                        crtc_state->encoder_mask &=
-                               ~(1 << drm_encoder_index(conn_state->best_encoder));
+                               ~drm_encoder_mask(conn_state->best_encoder);
                }
        }
 
@@ -234,7 +234,7 @@ set_best_encoder(struct drm_atomic_state *state,
                        crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
 
                        crtc_state->encoder_mask |=
-                               1 << drm_encoder_index(encoder);
+                               drm_encoder_mask(encoder);
                }
        }
 
index fb299696c7c417a24f953faaeb6cfd55b57833ed..4f597c0730b480a2db431616446c70d4a36b3306 100644 (file)
@@ -191,11 +191,23 @@ int drm_encoder_init(struct drm_device *dev,
  * Given a registered encoder, return the index of that encoder within a DRM
  * device's list of encoders.
  */
-static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
+static inline unsigned int drm_encoder_index(const struct drm_encoder *encoder)
 {
        return encoder->index;
 }
 
+/**
+ * drm_encoder_mask - find the mask of a registered ENCODER
+ * @encoder: encoder to find mask for
+ *
+ * Given a registered encoder, return the mask bit of that encoder for an
+ * encoder's possible_clones field.
+ */
+static inline u32 drm_encoder_mask(const struct drm_encoder *encoder)
+{
+       return 1 << drm_encoder_index(encoder);
+}
+
 /**
  * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
  * @encoder: encoder to test
@@ -241,7 +253,7 @@ void drm_encoder_cleanup(struct drm_encoder *encoder);
  */
 #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
        list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
-               for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
+               for_each_if ((encoder_mask) & drm_encoder_mask(encoder))
 
 /**
  * drm_for_each_encoder - iterate over all encoders