From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 3/9] drm: Add drm_connector_for_each_possible_encoder()
Date: Thu, 28 Jun 2018 20:24:53 +0300 [thread overview]
Message-ID: <20180628172453.GO20518@intel.com> (raw)
In-Reply-To: <20180628165640.GW13978@phenom.ffwll.local>
On Thu, Jun 28, 2018 at 06:56:40PM +0200, Daniel Vetter wrote:
> On Thu, Jun 28, 2018 at 04:13:09PM +0300, Ville Syrjala wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > 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)
> >
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Reviewed-by: Alex Deucher <alexander.deucher@amd.com> #v1
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> > drivers/gpu/drm/drm_connector.c | 21 +++++++++------------
> > drivers/gpu/drm/drm_fb_helper.c | 11 ++---------
> > drivers/gpu/drm/drm_probe_helper.c | 10 +++-------
> > include/drm/drm_connector.h | 13 +++++++++++++
> > 4 files changed, 27 insertions(+), 28 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
> > index 2f9ebddd178e..186febcf4e55 100644
> > --- a/drivers/gpu/drm/drm_connector.c
> > +++ b/drivers/gpu/drm/drm_connector.c
> > @@ -321,7 +321,7 @@ int drm_mode_connector_attach_encoder(struct drm_connector *connector,
> > if (WARN_ON(connector->encoder))
> > 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) {
> > connector->encoder_ids[i] = encoder->base.id;
> > return 0;
> > @@ -1708,22 +1708,19 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
> > if (!connector)
> > return -ENOENT;
> >
> > - for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++)
> > - if (connector->encoder_ids[i] != 0)
> > - encoders_count++;
> > + drm_connector_for_each_possible_encoder(connector, encoder, i)
> > + encoders_count++;
> >
> > if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
> > copied = 0;
> > 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) {
> > - if (put_user(connector->encoder_ids[i],
> > - encoder_ptr + copied)) {
> > - ret = -EFAULT;
> > - goto out;
> > - }
> > - copied++;
> > +
> > + drm_connector_for_each_possible_encoder(connector, encoder, i) {
> > + if (put_user(encoder->base.id, encoder_ptr + copied)) {
> > + ret = -EFAULT;
> > + goto out;
> > }
> > + copied++;
> > }
> > }
> > out_resp->count_encoders = encoders_count;
> > diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> > index b37f06317d51..d697c1c4a067 100644
> > --- a/drivers/gpu/drm/drm_fb_helper.c
> > +++ b/drivers/gpu/drm/drm_fb_helper.c
> > @@ -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,
> > struct drm_crtc *crtc)
> > {
> > + struct drm_encoder *encoder;
> > int i;
> >
> > - for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
> > - struct drm_encoder *encoder;
> > -
> > - if (connector->encoder_ids[i] == 0)
> > - break;
> > -
> > - encoder = drm_encoder_find(connector->dev, NULL,
> > - connector->encoder_ids[i]);
> > -
> > + drm_connector_for_each_possible_encoder(connector, encoder, i) {
> > if (encoder->possible_crtcs & drm_crtc_mask(crtc))
> > return true;
> > }
> > diff --git a/drivers/gpu/drm/drm_probe_helper.c b/drivers/gpu/drm/drm_probe_helper.c
> > index 527743394150..1a901fe9e23e 100644
> > --- a/drivers/gpu/drm/drm_probe_helper.c
> > +++ b/drivers/gpu/drm/drm_probe_helper.c
> > @@ -88,9 +88,9 @@ drm_mode_validate_pipeline(struct drm_display_mode *mode,
> > struct drm_connector *connector)
> > {
> > struct drm_device *dev = connector->dev;
> > - uint32_t *ids = connector->encoder_ids;
> > enum drm_mode_status ret = MODE_OK;
> > - unsigned int i;
> > + struct drm_encoder *encoder;
> > + int i;
> >
> > /* Step 1: Validate against connector */
> > ret = drm_connector_mode_valid(connector, mode);
> > @@ -98,13 +98,9 @@ drm_mode_validate_pipeline(struct drm_display_mode *mode,
> > return ret;
> >
> > /* Step 2: Validate against encoders and crtcs */
> > - for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
> > - struct drm_encoder *encoder = drm_encoder_find(dev, NULL, ids[i]);
> > + drm_connector_for_each_possible_encoder(connector, encoder, i) {
> > struct drm_crtc *crtc;
> >
> > - if (!encoder)
> > - continue;
> > -
> > ret = drm_encoder_mode_valid(encoder, mode);
> > if (ret != MODE_OK) {
> > /* No point in continuing for crtc check as this encoder
> > diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
> > index 14ab58ade87f..8de3a3aa516a 100644
> > --- a/include/drm/drm_connector.h
> > +++ b/include/drm/drm_connector.h
> > @@ -1193,4 +1193,17 @@ void drm_connector_list_iter_end(struct drm_connector_list_iter *iter);
> > #define drm_for_each_connector_iter(connector, 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 used as cursor
> > + * @encoder: the encoder
>
> Isn't this the other way round? encoder is the cursor, connector is _the_
> connector?
Yes indeed. Copy-paste fail on my part. Will fix.
>
> Otherwise Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> and ack from
> me on the entire series. Much prettier!
> -Daniel
>
> > + * @__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
> > --
> > 2.16.4
> >
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
--
Ville Syrjälä
Intel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2018-06-28 17:24 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-28 13:13 [PATCH v2 0/9] drm: Third attempt at fixing the fb-helper .best_encoder() mess Ville Syrjala
2018-06-28 13:13 ` [PATCH v2 1/9] drm/fb-helper: Eliminate the .best_encoder() usage Ville Syrjala
2018-06-28 15:27 ` Alex Deucher
2018-07-05 13:59 ` Ville Syrjälä
2018-06-28 13:13 ` [PATCH v2 2/9] drm/i915: Nuke intel_mst_best_encoder() Ville Syrjala
2018-06-28 13:13 ` [PATCH v2 3/9] drm: Add drm_connector_for_each_possible_encoder() Ville Syrjala
2018-06-28 16:56 ` Daniel Vetter
2018-06-28 17:24 ` Ville Syrjälä [this message]
2018-06-28 13:13 ` [PATCH v2 4/9] drm/amdgpu: Use drm_connector_for_each_possible_encoder() Ville Syrjala
[not found] ` <20180628131315.14156-1-ville.syrjala-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-06-28 13:13 ` [PATCH v2 5/9] drm/nouveau: " Ville Syrjala
2018-06-30 19:12 ` Dan Carpenter
2018-07-02 13:04 ` Ville Syrjälä
2018-07-02 14:05 ` Ville Syrjälä
[not found] ` <20180628131315.14156-6-ville.syrjala-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-07-02 15:29 ` [PATCH v3 " Ville Syrjala
2018-06-28 13:13 ` [PATCH v2 6/9] drm/radeon: " Ville Syrjala
2018-06-28 13:13 ` [PATCH v2 8/9] drm/msm: Use drm_connector_has_possible_encoder() Ville Syrjala
2018-06-28 13:13 ` [PATCH v2 7/9] drm: Add drm_connector_has_possible_encoder() Ville Syrjala
2018-06-28 13:13 ` [PATCH v2 9/9] drm/tilcdc: Use drm_connector_has_possible_encoder() Ville Syrjala
2018-06-28 13:45 ` Jyri Sarha
2018-06-28 17:52 ` Ville Syrjälä
2018-06-28 13:32 ` ✗ Fi.CI.CHECKPATCH: warning for drm: Third attempt at fixing the fb-helper .best_encoder() mess Patchwork
2018-06-28 13:47 ` [PATCH v2 0/9] " Ville Syrjälä
2018-06-28 13:50 ` ✓ Fi.CI.BAT: success for " Patchwork
2018-06-28 15:35 ` ✓ Fi.CI.IGT: " Patchwork
2018-07-02 15:47 ` ✗ Fi.CI.CHECKPATCH: warning for drm: Third attempt at fixing the fb-helper .best_encoder() mess (rev2) Patchwork
2018-07-02 16:06 ` ✓ Fi.CI.BAT: success " Patchwork
2018-07-02 18:28 ` ✓ Fi.CI.IGT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180628172453.GO20518@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).