Message ID | 1459943641-12179-2-git-send-email-durgadoss.r@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, 2016-04-06 at 17:23 +0530, Durgadoss R wrote: > Looping over the crtc list and finding an unused crtc > has other users like upfront link training. Hence move it to > a common function to re-use the logic. > > v3: > * Added kernel Doc and removed an invalid comment (Ander) > * Rebased on top of latest code which includes locking > for state->enable usage. > v2: > * Made this as a separate function instead of having it > inside upfront link train code. > > Signed-off-by: Durgadoss R <durgadoss.r@intel.com> > --- > drivers/gpu/drm/i915/intel_display.c | 74 +++++++++++++++++++++-------------- > - > drivers/gpu/drm/i915/intel_drv.h | 2 + > 2 files changed, 45 insertions(+), 31 deletions(-) > > diff --git a/drivers/gpu/drm/i915/intel_display.c > b/drivers/gpu/drm/i915/intel_display.c > index e6b5ee5..3c1fbcd 100644 > --- a/drivers/gpu/drm/i915/intel_display.c > +++ b/drivers/gpu/drm/i915/intel_display.c > @@ -10366,6 +10366,43 @@ static int intel_modeset_setup_plane_state(struct > drm_atomic_state *state, > return 0; > } > > +/** > + * intel_get_unused_crtc - Find an unused crtc for the given encoder > + * @encoder: drm_encoder structure > + * @ctx: ctx pointer to use with locking > + * > + * This function tries to find an unused crtc that can drive > + * the given encoder. Returns NULL on failure. This doesn't match the code below, since it now returns an unused crtc or an ERR_PTR. It never returns NULL. Ander > + */ > +struct drm_crtc *intel_get_unused_crtc(struct drm_encoder *encoder, > + struct drm_modeset_acquire_ctx *ctx) > +{ > + struct drm_crtc *possible_crtc; > + struct drm_crtc *crtc = NULL; > + struct drm_device *dev = encoder->dev; > + int ret, i = -1; > + > + for_each_crtc(dev, possible_crtc) { > + i++; > + if (!(encoder->possible_crtcs & (1 << i))) > + continue; > + > + ret = drm_modeset_lock(&possible_crtc->mutex, ctx); > + if (ret) > + return ERR_PTR(ret); > + > + if (possible_crtc->state->enable) { > + drm_modeset_unlock(&possible_crtc->mutex); > + continue; > + } > + > + crtc = possible_crtc; > + break; > + } > + > + return crtc; > +} > + > bool intel_get_load_detect_pipe(struct drm_connector *connector, > struct drm_display_mode *mode, > struct intel_load_detect_pipe *old, > @@ -10374,7 +10411,6 @@ bool intel_get_load_detect_pipe(struct drm_connector > *connector, > struct intel_crtc *intel_crtc; > struct intel_encoder *intel_encoder = > intel_attached_encoder(connector); > - struct drm_crtc *possible_crtc; > struct drm_encoder *encoder = &intel_encoder->base; > struct drm_crtc *crtc = NULL; > struct drm_device *dev = encoder->dev; > @@ -10383,7 +10419,7 @@ bool intel_get_load_detect_pipe(struct drm_connector > *connector, > struct drm_atomic_state *state = NULL, *restore_state = NULL; > struct drm_connector_state *connector_state; > struct intel_crtc_state *crtc_state; > - int ret, i = -1; > + int ret; > > DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", > connector->base.id, connector->name, > @@ -10413,39 +10449,15 @@ retry: > ret = drm_modeset_lock(&crtc->mutex, ctx); > if (ret) > goto fail; > - > - /* Make sure the crtc and connector are running */ > - goto found; > - } > - > - /* Find an unused one (if possible) */ > - for_each_crtc(dev, possible_crtc) { > - i++; > - if (!(encoder->possible_crtcs & (1 << i))) > - continue; > - > - ret = drm_modeset_lock(&possible_crtc->mutex, ctx); > - if (ret) > + } else { > + crtc = intel_get_unused_crtc(encoder, ctx); > + if (IS_ERR_OR_NULL(crtc)) { > + ret = PTR_ERR_OR_ZERO(crtc); > + DRM_DEBUG_KMS("no pipe available for load-detect\n"); > goto fail; > - > - if (possible_crtc->state->enable) { > - drm_modeset_unlock(&possible_crtc->mutex); > - continue; > } > - > - crtc = possible_crtc; > - break; > - } > - > - /* > - * If we didn't find an unused CRTC, don't use any. > - */ > - if (!crtc) { > - DRM_DEBUG_KMS("no pipe available for load-detect\n"); > - goto fail; > } > > -found: > intel_crtc = to_intel_crtc(crtc); > > ret = drm_modeset_lock(&crtc->primary->mutex, ctx); > diff --git a/drivers/gpu/drm/i915/intel_drv.h > b/drivers/gpu/drm/i915/intel_drv.h > index 9255b56..3873af5 100644 > --- a/drivers/gpu/drm/i915/intel_drv.h > +++ b/drivers/gpu/drm/i915/intel_drv.h > @@ -1152,6 +1152,8 @@ bool intel_get_load_detect_pipe(struct drm_connector > *connector, > void intel_release_load_detect_pipe(struct drm_connector *connector, > struct intel_load_detect_pipe *old, > struct drm_modeset_acquire_ctx *ctx); > +struct drm_crtc *intel_get_unused_crtc(struct drm_encoder *encoder, > + struct drm_modeset_acquire_ctx *ctx); > int intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, > unsigned int rotation); > struct drm_framebuffer *
>-----Original Message----- >From: Ander Conselvan De Oliveira [mailto:conselvan2@gmail.com] >Sent: Monday, April 11, 2016 6:06 PM >To: R, Durgadoss <durgadoss.r@intel.com>; intel-gfx@lists.freedesktop.org >Cc: ville.syrjala@linux.intel.com >Subject: Re: [PATCHv3 1/4] drm/i915: Make finding unused crtc as a generic function > >On Wed, 2016-04-06 at 17:23 +0530, Durgadoss R wrote: >> Looping over the crtc list and finding an unused crtc >> has other users like upfront link training. Hence move it to >> a common function to re-use the logic. >> >> v3: >> * Added kernel Doc and removed an invalid comment (Ander) >> * Rebased on top of latest code which includes locking >> for state->enable usage. >> v2: >> * Made this as a separate function instead of having it >> inside upfront link train code. >> >> Signed-off-by: Durgadoss R <durgadoss.r@intel.com> >> --- >> drivers/gpu/drm/i915/intel_display.c | 74 +++++++++++++++++++++-------------- >> - >> drivers/gpu/drm/i915/intel_drv.h | 2 + >> 2 files changed, 45 insertions(+), 31 deletions(-) >> >> diff --git a/drivers/gpu/drm/i915/intel_display.c >> b/drivers/gpu/drm/i915/intel_display.c >> index e6b5ee5..3c1fbcd 100644 >> --- a/drivers/gpu/drm/i915/intel_display.c >> +++ b/drivers/gpu/drm/i915/intel_display.c >> @@ -10366,6 +10366,43 @@ static int intel_modeset_setup_plane_state(struct >> drm_atomic_state *state, >> return 0; >> } >> >> +/** >> + * intel_get_unused_crtc - Find an unused crtc for the given encoder >> + * @encoder: drm_encoder structure >> + * @ctx: ctx pointer to use with locking >> + * >> + * This function tries to find an unused crtc that can drive >> + * the given encoder. Returns NULL on failure. > >This doesn't match the code below, since it now returns an unused crtc or an >ERR_PTR. It never returns NULL. If the 'state->enable' is set for all crtcs, then I think it can return a NULL. Anyway, will fix the comment so say "Null or an error pointer" on failure. Thanks, Durga > >Ander > >> + */ >> +struct drm_crtc *intel_get_unused_crtc(struct drm_encoder *encoder, >> + struct drm_modeset_acquire_ctx *ctx) >> +{ >> + struct drm_crtc *possible_crtc; >> + struct drm_crtc *crtc = NULL; >> + struct drm_device *dev = encoder->dev; >> + int ret, i = -1; >> + >> + for_each_crtc(dev, possible_crtc) { >> + i++; >> + if (!(encoder->possible_crtcs & (1 << i))) >> + continue; >> + >> + ret = drm_modeset_lock(&possible_crtc->mutex, ctx); >> + if (ret) >> + return ERR_PTR(ret); >> + >> + if (possible_crtc->state->enable) { >> + drm_modeset_unlock(&possible_crtc->mutex); >> + continue; >> + } >> + >> + crtc = possible_crtc; >> + break; >> + } >> + >> + return crtc; >> +} >> + >> bool intel_get_load_detect_pipe(struct drm_connector *connector, >> struct drm_display_mode *mode, >> struct intel_load_detect_pipe *old, >> @@ -10374,7 +10411,6 @@ bool intel_get_load_detect_pipe(struct drm_connector >> *connector, >> struct intel_crtc *intel_crtc; >> struct intel_encoder *intel_encoder = >> intel_attached_encoder(connector); >> - struct drm_crtc *possible_crtc; >> struct drm_encoder *encoder = &intel_encoder->base; >> struct drm_crtc *crtc = NULL; >> struct drm_device *dev = encoder->dev; >> @@ -10383,7 +10419,7 @@ bool intel_get_load_detect_pipe(struct drm_connector >> *connector, >> struct drm_atomic_state *state = NULL, *restore_state = NULL; >> struct drm_connector_state *connector_state; >> struct intel_crtc_state *crtc_state; >> - int ret, i = -1; >> + int ret; >> >> DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", >> connector->base.id, connector->name, >> @@ -10413,39 +10449,15 @@ retry: >> ret = drm_modeset_lock(&crtc->mutex, ctx); >> if (ret) >> goto fail; >> - >> - /* Make sure the crtc and connector are running */ >> - goto found; >> - } >> - >> - /* Find an unused one (if possible) */ >> - for_each_crtc(dev, possible_crtc) { >> - i++; >> - if (!(encoder->possible_crtcs & (1 << i))) >> - continue; >> - >> - ret = drm_modeset_lock(&possible_crtc->mutex, ctx); >> - if (ret) >> + } else { >> + crtc = intel_get_unused_crtc(encoder, ctx); >> + if (IS_ERR_OR_NULL(crtc)) { >> + ret = PTR_ERR_OR_ZERO(crtc); >> + DRM_DEBUG_KMS("no pipe available for load-detect\n"); >> goto fail; >> - >> - if (possible_crtc->state->enable) { >> - drm_modeset_unlock(&possible_crtc->mutex); >> - continue; >> } >> - >> - crtc = possible_crtc; >> - break; >> - } >> - >> - /* >> - * If we didn't find an unused CRTC, don't use any. >> - */ >> - if (!crtc) { >> - DRM_DEBUG_KMS("no pipe available for load-detect\n"); >> - goto fail; >> } >> >> -found: >> intel_crtc = to_intel_crtc(crtc); >> >> ret = drm_modeset_lock(&crtc->primary->mutex, ctx); >> diff --git a/drivers/gpu/drm/i915/intel_drv.h >> b/drivers/gpu/drm/i915/intel_drv.h >> index 9255b56..3873af5 100644 >> --- a/drivers/gpu/drm/i915/intel_drv.h >> +++ b/drivers/gpu/drm/i915/intel_drv.h >> @@ -1152,6 +1152,8 @@ bool intel_get_load_detect_pipe(struct drm_connector >> *connector, >> void intel_release_load_detect_pipe(struct drm_connector *connector, >> struct intel_load_detect_pipe *old, >> struct drm_modeset_acquire_ctx *ctx); >> +struct drm_crtc *intel_get_unused_crtc(struct drm_encoder *encoder, >> + struct drm_modeset_acquire_ctx *ctx); >> int intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, >> unsigned int rotation); >> struct drm_framebuffer *
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index e6b5ee5..3c1fbcd 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -10366,6 +10366,43 @@ static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, return 0; } +/** + * intel_get_unused_crtc - Find an unused crtc for the given encoder + * @encoder: drm_encoder structure + * @ctx: ctx pointer to use with locking + * + * This function tries to find an unused crtc that can drive + * the given encoder. Returns NULL on failure. + */ +struct drm_crtc *intel_get_unused_crtc(struct drm_encoder *encoder, + struct drm_modeset_acquire_ctx *ctx) +{ + struct drm_crtc *possible_crtc; + struct drm_crtc *crtc = NULL; + struct drm_device *dev = encoder->dev; + int ret, i = -1; + + for_each_crtc(dev, possible_crtc) { + i++; + if (!(encoder->possible_crtcs & (1 << i))) + continue; + + ret = drm_modeset_lock(&possible_crtc->mutex, ctx); + if (ret) + return ERR_PTR(ret); + + if (possible_crtc->state->enable) { + drm_modeset_unlock(&possible_crtc->mutex); + continue; + } + + crtc = possible_crtc; + break; + } + + return crtc; +} + bool intel_get_load_detect_pipe(struct drm_connector *connector, struct drm_display_mode *mode, struct intel_load_detect_pipe *old, @@ -10374,7 +10411,6 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector, struct intel_crtc *intel_crtc; struct intel_encoder *intel_encoder = intel_attached_encoder(connector); - struct drm_crtc *possible_crtc; struct drm_encoder *encoder = &intel_encoder->base; struct drm_crtc *crtc = NULL; struct drm_device *dev = encoder->dev; @@ -10383,7 +10419,7 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector, struct drm_atomic_state *state = NULL, *restore_state = NULL; struct drm_connector_state *connector_state; struct intel_crtc_state *crtc_state; - int ret, i = -1; + int ret; DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", connector->base.id, connector->name, @@ -10413,39 +10449,15 @@ retry: ret = drm_modeset_lock(&crtc->mutex, ctx); if (ret) goto fail; - - /* Make sure the crtc and connector are running */ - goto found; - } - - /* Find an unused one (if possible) */ - for_each_crtc(dev, possible_crtc) { - i++; - if (!(encoder->possible_crtcs & (1 << i))) - continue; - - ret = drm_modeset_lock(&possible_crtc->mutex, ctx); - if (ret) + } else { + crtc = intel_get_unused_crtc(encoder, ctx); + if (IS_ERR_OR_NULL(crtc)) { + ret = PTR_ERR_OR_ZERO(crtc); + DRM_DEBUG_KMS("no pipe available for load-detect\n"); goto fail; - - if (possible_crtc->state->enable) { - drm_modeset_unlock(&possible_crtc->mutex); - continue; } - - crtc = possible_crtc; - break; - } - - /* - * If we didn't find an unused CRTC, don't use any. - */ - if (!crtc) { - DRM_DEBUG_KMS("no pipe available for load-detect\n"); - goto fail; } -found: intel_crtc = to_intel_crtc(crtc); ret = drm_modeset_lock(&crtc->primary->mutex, ctx); diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h index 9255b56..3873af5 100644 --- a/drivers/gpu/drm/i915/intel_drv.h +++ b/drivers/gpu/drm/i915/intel_drv.h @@ -1152,6 +1152,8 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector, void intel_release_load_detect_pipe(struct drm_connector *connector, struct intel_load_detect_pipe *old, struct drm_modeset_acquire_ctx *ctx); +struct drm_crtc *intel_get_unused_crtc(struct drm_encoder *encoder, + struct drm_modeset_acquire_ctx *ctx); int intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, unsigned int rotation); struct drm_framebuffer *
Looping over the crtc list and finding an unused crtc has other users like upfront link training. Hence move it to a common function to re-use the logic. v3: * Added kernel Doc and removed an invalid comment (Ander) * Rebased on top of latest code which includes locking for state->enable usage. v2: * Made this as a separate function instead of having it inside upfront link train code. Signed-off-by: Durgadoss R <durgadoss.r@intel.com> --- drivers/gpu/drm/i915/intel_display.c | 74 +++++++++++++++++++++--------------- drivers/gpu/drm/i915/intel_drv.h | 2 + 2 files changed, 45 insertions(+), 31 deletions(-)