Commit 83aefbb8 authored by Ville Syrjälä's avatar Ville Syrjälä

drm: Add drm_connector_for_each_possible_encoder()

Add a convenience macro for iterating connector->encoder_ids[].
Isolates the users from the implementation details.

Note that we don't seem to pass the file_priv down to drm_encoder_find()
because encoders apparently don't get leased. No idea why
drm_encoder_finc() even takes the file_priv actually.

Also use ARRAY_SIZE() when populating the array to avoid spreading
knowledge about the array size all over.

v2: Hide the drm_encoder_find() in the macro, and
    rename the macro appropriately (Daniel)
v3: Fix kernel docs (Daniel)

Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180628131315.14156-4-ville.syrjala@linux.intel.comReviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 20431c05
...@@ -321,7 +321,7 @@ int drm_mode_connector_attach_encoder(struct drm_connector *connector, ...@@ -321,7 +321,7 @@ int drm_mode_connector_attach_encoder(struct drm_connector *connector,
if (WARN_ON(connector->encoder)) if (WARN_ON(connector->encoder))
return -EINVAL; return -EINVAL;
for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { for (i = 0; i < ARRAY_SIZE(connector->encoder_ids); i++) {
if (connector->encoder_ids[i] == 0) { if (connector->encoder_ids[i] == 0) {
connector->encoder_ids[i] = encoder->base.id; connector->encoder_ids[i] = encoder->base.id;
return 0; return 0;
...@@ -1706,22 +1706,19 @@ int drm_mode_getconnector(struct drm_device *dev, void *data, ...@@ -1706,22 +1706,19 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
if (!connector) if (!connector)
return -ENOENT; return -ENOENT;
for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) drm_connector_for_each_possible_encoder(connector, encoder, i)
if (connector->encoder_ids[i] != 0) encoders_count++;
encoders_count++;
if ((out_resp->count_encoders >= encoders_count) && encoders_count) { if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
copied = 0; copied = 0;
encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
if (connector->encoder_ids[i] != 0) { drm_connector_for_each_possible_encoder(connector, encoder, i) {
if (put_user(connector->encoder_ids[i], if (put_user(encoder->base.id, encoder_ptr + copied)) {
encoder_ptr + copied)) { ret = -EFAULT;
ret = -EFAULT; goto out;
goto out;
}
copied++;
} }
copied++;
} }
} }
out_resp->count_encoders = encoders_count; out_resp->count_encoders = encoders_count;
......
...@@ -2326,17 +2326,10 @@ static bool drm_target_preferred(struct drm_fb_helper *fb_helper, ...@@ -2326,17 +2326,10 @@ static bool drm_target_preferred(struct drm_fb_helper *fb_helper,
static bool connector_has_possible_crtc(struct drm_connector *connector, static bool connector_has_possible_crtc(struct drm_connector *connector,
struct drm_crtc *crtc) struct drm_crtc *crtc)
{ {
struct drm_encoder *encoder;
int i; int i;
for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { drm_connector_for_each_possible_encoder(connector, encoder, i) {
struct drm_encoder *encoder;
if (connector->encoder_ids[i] == 0)
break;
encoder = drm_encoder_find(connector->dev, NULL,
connector->encoder_ids[i]);
if (encoder->possible_crtcs & drm_crtc_mask(crtc)) if (encoder->possible_crtcs & drm_crtc_mask(crtc))
return true; return true;
} }
......
...@@ -88,9 +88,9 @@ drm_mode_validate_pipeline(struct drm_display_mode *mode, ...@@ -88,9 +88,9 @@ drm_mode_validate_pipeline(struct drm_display_mode *mode,
struct drm_connector *connector) struct drm_connector *connector)
{ {
struct drm_device *dev = connector->dev; struct drm_device *dev = connector->dev;
uint32_t *ids = connector->encoder_ids;
enum drm_mode_status ret = MODE_OK; enum drm_mode_status ret = MODE_OK;
unsigned int i; struct drm_encoder *encoder;
int i;
/* Step 1: Validate against connector */ /* Step 1: Validate against connector */
ret = drm_connector_mode_valid(connector, mode); ret = drm_connector_mode_valid(connector, mode);
...@@ -98,13 +98,9 @@ drm_mode_validate_pipeline(struct drm_display_mode *mode, ...@@ -98,13 +98,9 @@ drm_mode_validate_pipeline(struct drm_display_mode *mode,
return ret; return ret;
/* Step 2: Validate against encoders and crtcs */ /* Step 2: Validate against encoders and crtcs */
for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { drm_connector_for_each_possible_encoder(connector, encoder, i) {
struct drm_encoder *encoder = drm_encoder_find(dev, NULL, ids[i]);
struct drm_crtc *crtc; struct drm_crtc *crtc;
if (!encoder)
continue;
ret = drm_encoder_mode_valid(encoder, mode); ret = drm_encoder_mode_valid(encoder, mode);
if (ret != MODE_OK) { if (ret != MODE_OK) {
/* No point in continuing for crtc check as this encoder /* No point in continuing for crtc check as this encoder
......
...@@ -1199,4 +1199,17 @@ void drm_connector_list_iter_end(struct drm_connector_list_iter *iter); ...@@ -1199,4 +1199,17 @@ void drm_connector_list_iter_end(struct drm_connector_list_iter *iter);
#define drm_for_each_connector_iter(connector, iter) \ #define drm_for_each_connector_iter(connector, iter) \
while ((connector = drm_connector_list_iter_next(iter))) while ((connector = drm_connector_list_iter_next(iter)))
/**
* drm_connector_for_each_possible_encoder - iterate connector's possible encoders
* @connector: &struct drm_connector pointer
* @encoder: &struct drm_encoder pointer used as cursor
* @__i: int iteration cursor, for macro-internal use
*/
#define drm_connector_for_each_possible_encoder(connector, encoder, __i) \
for ((__i) = 0; (__i) < ARRAY_SIZE((connector)->encoder_ids) && \
(connector)->encoder_ids[(__i)] != 0; (__i)++) \
for_each_if((encoder) = \
drm_encoder_find((connector)->dev, NULL, \
(connector)->encoder_ids[(__i)])) \
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment