diff mbox series

[v2,1/6] drm: Include the encoder itself in possible_clones

Message ID 20200207135950.6655-2-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm: Try to fix encoder possible_clones/crtc | expand

Commit Message

Ville Syrjala Feb. 7, 2020, 1:59 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

The docs say possible_clones should always include the encoder itself.
Since most drivers don't want to deal with the complexities of cloning
let's allow them to set possible_clones=0 and instead we'll fix that
up in the core.

We can't put this special case into drm_encoder_init() because drivers
will have to fill up possible_clones after adding all the relevant
encoders. Otherwise they wouldn't know the proper encoder indexes to
use. So we'll just do it just before registering the encoders.

TODO: Should we do something similar for possible_crtcs==0?

Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_encoder.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Thomas Zimmermann Feb. 7, 2020, 2:28 p.m. UTC | #1
Hi

Am 07.02.20 um 14:59 schrieb Ville Syrjala:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> The docs say possible_clones should always include the encoder itself.
> Since most drivers don't want to deal with the complexities of cloning
> let's allow them to set possible_clones=0 and instead we'll fix that
> up in the core.
> 
> We can't put this special case into drm_encoder_init() because drivers
> will have to fill up possible_clones after adding all the relevant
> encoders. Otherwise they wouldn't know the proper encoder indexes to
> use. So we'll just do it just before registering the encoders.
> 
> TODO: Should we do something similar for possible_crtcs==0?
> 
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

May this fixup function should warn iff possible_clones was set to non-0
by the driver, but the encoder itself is missing. In any case

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>

> ---
>  drivers/gpu/drm/drm_encoder.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
> index e555281f43d4..f761d9306028 100644
> --- a/drivers/gpu/drm/drm_encoder.c
> +++ b/drivers/gpu/drm/drm_encoder.c
> @@ -66,11 +66,26 @@ static const struct drm_prop_enum_list drm_encoder_enum_list[] = {
>  	{ DRM_MODE_ENCODER_DPI, "DPI" },
>  };
>  
> +/*
> + * For some reason we want the encoder itself included in
> + * possible_clones. Make life easy for drivers by allowing them
> + * to leave possible_clones unset if no cloning is possible.
> + */
> +static void fixup_possible_clones(struct drm_device *dev)
> +{
> +	struct drm_encoder *encoder;
> +
> +	drm_for_each_encoder(encoder, dev)
> +		encoder->possible_clones |= drm_encoder_mask(encoder);
> +}
> +
>  int drm_encoder_register_all(struct drm_device *dev)
>  {
>  	struct drm_encoder *encoder;
>  	int ret = 0;
>  
> +	fixup_possible_clones(dev);
> +
>  	drm_for_each_encoder(encoder, dev) {
>  		if (encoder->funcs->late_register)
>  			ret = encoder->funcs->late_register(encoder);
>
Ville Syrjala Feb. 7, 2020, 2:50 p.m. UTC | #2
On Fri, Feb 07, 2020 at 03:28:35PM +0100, Thomas Zimmermann wrote:
> Hi
> 
> Am 07.02.20 um 14:59 schrieb Ville Syrjala:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > The docs say possible_clones should always include the encoder itself.
> > Since most drivers don't want to deal with the complexities of cloning
> > let's allow them to set possible_clones=0 and instead we'll fix that
> > up in the core.
> > 
> > We can't put this special case into drm_encoder_init() because drivers
> > will have to fill up possible_clones after adding all the relevant
> > encoders. Otherwise they wouldn't know the proper encoder indexes to
> > use. So we'll just do it just before registering the encoders.
> > 
> > TODO: Should we do something similar for possible_crtcs==0?
> > 
> > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > Cc: Daniel Vetter <daniel@ffwll.ch>
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> May this fixup function should warn iff possible_clones was set to non-0
> by the driver, but the encoder itself is missing.

Yeah, I guess we could do that.

> In any case
> 
> Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
> 
> > ---
> >  drivers/gpu/drm/drm_encoder.c | 15 +++++++++++++++
> >  1 file changed, 15 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
> > index e555281f43d4..f761d9306028 100644
> > --- a/drivers/gpu/drm/drm_encoder.c
> > +++ b/drivers/gpu/drm/drm_encoder.c
> > @@ -66,11 +66,26 @@ static const struct drm_prop_enum_list drm_encoder_enum_list[] = {
> >  	{ DRM_MODE_ENCODER_DPI, "DPI" },
> >  };
> >  
> > +/*
> > + * For some reason we want the encoder itself included in
> > + * possible_clones. Make life easy for drivers by allowing them
> > + * to leave possible_clones unset if no cloning is possible.
> > + */
> > +static void fixup_possible_clones(struct drm_device *dev)
> > +{
> > +	struct drm_encoder *encoder;
> > +
> > +	drm_for_each_encoder(encoder, dev)
> > +		encoder->possible_clones |= drm_encoder_mask(encoder);
> > +}
> > +
> >  int drm_encoder_register_all(struct drm_device *dev)
> >  {
> >  	struct drm_encoder *encoder;
> >  	int ret = 0;
> >  
> > +	fixup_possible_clones(dev);
> > +
> >  	drm_for_each_encoder(encoder, dev) {
> >  		if (encoder->funcs->late_register)
> >  			ret = encoder->funcs->late_register(encoder);
> > 
> 
> -- 
> Thomas Zimmermann
> Graphics Driver Developer
> SUSE Software Solutions Germany GmbH
> Maxfeldstr. 5, 90409 Nürnberg, Germany
> (HRB 36809, AG Nürnberg)
> Geschäftsführer: Felix Imendörffer
>
Daniel Vetter Feb. 7, 2020, 4:27 p.m. UTC | #3
On Fri, Feb 07, 2020 at 04:50:01PM +0200, Ville Syrjälä wrote:
> On Fri, Feb 07, 2020 at 03:28:35PM +0100, Thomas Zimmermann wrote:
> > Hi
> > 
> > Am 07.02.20 um 14:59 schrieb Ville Syrjala:
> > > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > > 
> > > The docs say possible_clones should always include the encoder itself.
> > > Since most drivers don't want to deal with the complexities of cloning
> > > let's allow them to set possible_clones=0 and instead we'll fix that
> > > up in the core.
> > > 
> > > We can't put this special case into drm_encoder_init() because drivers
> > > will have to fill up possible_clones after adding all the relevant
> > > encoders. Otherwise they wouldn't know the proper encoder indexes to
> > > use. So we'll just do it just before registering the encoders.
> > > 
> > > TODO: Should we do something similar for possible_crtcs==0?
> > > 
> > > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > > Cc: Daniel Vetter <daniel@ffwll.ch>
> > > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > May this fixup function should warn iff possible_clones was set to non-0
> > by the driver, but the encoder itself is missing.
> 
> Yeah, I guess we could do that.

+1 on that, should catch some bugs at least.

Also can you pls fix up the kerneldoc for drm_encoder.possible_clones,
defacto this now means that 0 is a totally fine setting.
-Daniel

> 
> > In any case
> > 
> > Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
> > 
> > > ---
> > >  drivers/gpu/drm/drm_encoder.c | 15 +++++++++++++++
> > >  1 file changed, 15 insertions(+)
> > > 
> > > diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
> > > index e555281f43d4..f761d9306028 100644
> > > --- a/drivers/gpu/drm/drm_encoder.c
> > > +++ b/drivers/gpu/drm/drm_encoder.c
> > > @@ -66,11 +66,26 @@ static const struct drm_prop_enum_list drm_encoder_enum_list[] = {
> > >  	{ DRM_MODE_ENCODER_DPI, "DPI" },
> > >  };
> > >  
> > > +/*
> > > + * For some reason we want the encoder itself included in
> > > + * possible_clones. Make life easy for drivers by allowing them
> > > + * to leave possible_clones unset if no cloning is possible.
> > > + */
> > > +static void fixup_possible_clones(struct drm_device *dev)
> > > +{
> > > +	struct drm_encoder *encoder;
> > > +
> > > +	drm_for_each_encoder(encoder, dev)
> > > +		encoder->possible_clones |= drm_encoder_mask(encoder);
> > > +}
> > > +
> > >  int drm_encoder_register_all(struct drm_device *dev)
> > >  {
> > >  	struct drm_encoder *encoder;
> > >  	int ret = 0;
> > >  
> > > +	fixup_possible_clones(dev);
> > > +
> > >  	drm_for_each_encoder(encoder, dev) {
> > >  		if (encoder->funcs->late_register)
> > >  			ret = encoder->funcs->late_register(encoder);
> > > 
> > 
> > -- 
> > Thomas Zimmermann
> > Graphics Driver Developer
> > SUSE Software Solutions Germany GmbH
> > Maxfeldstr. 5, 90409 Nürnberg, Germany
> > (HRB 36809, AG Nürnberg)
> > Geschäftsführer: Felix Imendörffer
> > 
> 
> 
> 
> 
> -- 
> Ville Syrjälä
> Intel
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Ville Syrjala Feb. 7, 2020, 4:34 p.m. UTC | #4
On Fri, Feb 07, 2020 at 05:27:51PM +0100, Daniel Vetter wrote:
> On Fri, Feb 07, 2020 at 04:50:01PM +0200, Ville Syrjälä wrote:
> > On Fri, Feb 07, 2020 at 03:28:35PM +0100, Thomas Zimmermann wrote:
> > > Hi
> > > 
> > > Am 07.02.20 um 14:59 schrieb Ville Syrjala:
> > > > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > > > 
> > > > The docs say possible_clones should always include the encoder itself.
> > > > Since most drivers don't want to deal with the complexities of cloning
> > > > let's allow them to set possible_clones=0 and instead we'll fix that
> > > > up in the core.
> > > > 
> > > > We can't put this special case into drm_encoder_init() because drivers
> > > > will have to fill up possible_clones after adding all the relevant
> > > > encoders. Otherwise they wouldn't know the proper encoder indexes to
> > > > use. So we'll just do it just before registering the encoders.
> > > > 
> > > > TODO: Should we do something similar for possible_crtcs==0?
> > > > 
> > > > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > > > Cc: Daniel Vetter <daniel@ffwll.ch>
> > > > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > > 
> > > May this fixup function should warn iff possible_clones was set to non-0
> > > by the driver, but the encoder itself is missing.
> > 
> > Yeah, I guess we could do that.
> 
> +1 on that, should catch some bugs at least.
> 
> Also can you pls fix up the kerneldoc for drm_encoder.possible_clones,
> defacto this now means that 0 is a totally fine setting.

Sure.

And for possible_crtcs I was thinking similar concept:

for_each_encoder()
	if (possible_crtc == 0)
		possible_crtcs = all_crtc_mask;
Daniel Vetter Feb. 7, 2020, 4:36 p.m. UTC | #5
On Fri, Feb 07, 2020 at 03:59:45PM +0200, Ville Syrjala wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> The docs say possible_clones should always include the encoder itself.
> Since most drivers don't want to deal with the complexities of cloning
> let's allow them to set possible_clones=0 and instead we'll fix that
> up in the core.
> 
> We can't put this special case into drm_encoder_init() because drivers
> will have to fill up possible_clones after adding all the relevant
> encoders. Otherwise they wouldn't know the proper encoder indexes to
> use. So we'll just do it just before registering the encoders.
> 
> TODO: Should we do something similar for possible_crtcs==0?
> 
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  drivers/gpu/drm/drm_encoder.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
> index e555281f43d4..f761d9306028 100644
> --- a/drivers/gpu/drm/drm_encoder.c
> +++ b/drivers/gpu/drm/drm_encoder.c
> @@ -66,11 +66,26 @@ static const struct drm_prop_enum_list drm_encoder_enum_list[] = {
>  	{ DRM_MODE_ENCODER_DPI, "DPI" },
>  };
>  
> +/*
> + * For some reason we want the encoder itself included in
> + * possible_clones. Make life easy for drivers by allowing them
> + * to leave possible_clones unset if no cloning is possible.
> + */
> +static void fixup_possible_clones(struct drm_device *dev)
> +{
> +	struct drm_encoder *encoder;
> +
> +	drm_for_each_encoder(encoder, dev)
> +		encoder->possible_clones |= drm_encoder_mask(encoder);
> +}
> +
>  int drm_encoder_register_all(struct drm_device *dev)
>  {
>  	struct drm_encoder *encoder;
>  	int ret = 0;
>  
> +	fixup_possible_clones(dev);

This is way too late, we've already registered the chardev minors at this
point. I think we need a new drm_mode_config_validate() at the top of
drm_dev_register, but which does _not_ run when the driver has a ->load
callback (which soon will be no driver at all).

Cheers, Daniel


> +
>  	drm_for_each_encoder(encoder, dev) {
>  		if (encoder->funcs->late_register)
>  			ret = encoder->funcs->late_register(encoder);
> -- 
> 2.24.1
>
Daniel Vetter Feb. 7, 2020, 4:40 p.m. UTC | #6
On Fri, Feb 07, 2020 at 06:34:47PM +0200, Ville Syrjälä wrote:
> On Fri, Feb 07, 2020 at 05:27:51PM +0100, Daniel Vetter wrote:
> > On Fri, Feb 07, 2020 at 04:50:01PM +0200, Ville Syrjälä wrote:
> > > On Fri, Feb 07, 2020 at 03:28:35PM +0100, Thomas Zimmermann wrote:
> > > > Hi
> > > > 
> > > > Am 07.02.20 um 14:59 schrieb Ville Syrjala:
> > > > > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > > > > 
> > > > > The docs say possible_clones should always include the encoder itself.
> > > > > Since most drivers don't want to deal with the complexities of cloning
> > > > > let's allow them to set possible_clones=0 and instead we'll fix that
> > > > > up in the core.
> > > > > 
> > > > > We can't put this special case into drm_encoder_init() because drivers
> > > > > will have to fill up possible_clones after adding all the relevant
> > > > > encoders. Otherwise they wouldn't know the proper encoder indexes to
> > > > > use. So we'll just do it just before registering the encoders.
> > > > > 
> > > > > TODO: Should we do something similar for possible_crtcs==0?
> > > > > 
> > > > > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > > > > Cc: Daniel Vetter <daniel@ffwll.ch>
> > > > > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > > > 
> > > > May this fixup function should warn iff possible_clones was set to non-0
> > > > by the driver, but the encoder itself is missing.
> > > 
> > > Yeah, I guess we could do that.
> > 
> > +1 on that, should catch some bugs at least.
> > 
> > Also can you pls fix up the kerneldoc for drm_encoder.possible_clones,
> > defacto this now means that 0 is a totally fine setting.
> 
> Sure.
> 
> And for possible_crtcs I was thinking similar concept:
> 
> for_each_encoder()
> 	if (possible_crtc == 0)
> 		possible_crtcs = all_crtc_mask;

A quick grep shows that I think we can risk enforcing this. If that turns
out to be a misconception we can always go back to the fixup approach if
possible_crtcs is 0. But unlike possible_clones I think for possible_crtcs
the fixup-less approach looks possible at least.
-Daniel
Thomas Zimmermann Feb. 10, 2020, 8:16 a.m. UTC | #7
Hi

Am 07.02.20 um 17:27 schrieb Daniel Vetter:
> On Fri, Feb 07, 2020 at 04:50:01PM +0200, Ville Syrjälä wrote:
>> On Fri, Feb 07, 2020 at 03:28:35PM +0100, Thomas Zimmermann wrote:
>>> Hi
>>>
>>> Am 07.02.20 um 14:59 schrieb Ville Syrjala:
>>>> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>>>>
>>>> The docs say possible_clones should always include the encoder itself.
>>>> Since most drivers don't want to deal with the complexities of cloning
>>>> let's allow them to set possible_clones=0 and instead we'll fix that
>>>> up in the core.
>>>>
>>>> We can't put this special case into drm_encoder_init() because drivers
>>>> will have to fill up possible_clones after adding all the relevant
>>>> encoders. Otherwise they wouldn't know the proper encoder indexes to
>>>> use. So we'll just do it just before registering the encoders.
>>>>
>>>> TODO: Should we do something similar for possible_crtcs==0?
>>>>
>>>> Cc: Thomas Zimmermann <tzimmermann@suse.de>
>>>> Cc: Daniel Vetter <daniel@ffwll.ch>
>>>> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
>>>
>>> May this fixup function should warn iff possible_clones was set to non-0
>>> by the driver, but the encoder itself is missing.
>>
>> Yeah, I guess we could do that.
> 
> +1 on that, should catch some bugs at least.
> 
> Also can you pls fix up the kerneldoc for drm_encoder.possible_clones,
> defacto this now means that 0 is a totally fine setting.

Just a thought: we should encourage, or maybe even require, the use of
such defaults (i.e., 0); unless a driver has a good reason to override
them. So we don't have to fix drivers if the defaults ever change.

Best regards
Thomas

> -Daniel
> 
>>
>>> In any case
>>>
>>> Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
>>>
>>>> ---
>>>>  drivers/gpu/drm/drm_encoder.c | 15 +++++++++++++++
>>>>  1 file changed, 15 insertions(+)
>>>>
>>>> diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
>>>> index e555281f43d4..f761d9306028 100644
>>>> --- a/drivers/gpu/drm/drm_encoder.c
>>>> +++ b/drivers/gpu/drm/drm_encoder.c
>>>> @@ -66,11 +66,26 @@ static const struct drm_prop_enum_list drm_encoder_enum_list[] = {
>>>>  	{ DRM_MODE_ENCODER_DPI, "DPI" },
>>>>  };
>>>>  
>>>> +/*
>>>> + * For some reason we want the encoder itself included in
>>>> + * possible_clones. Make life easy for drivers by allowing them
>>>> + * to leave possible_clones unset if no cloning is possible.
>>>> + */
>>>> +static void fixup_possible_clones(struct drm_device *dev)
>>>> +{
>>>> +	struct drm_encoder *encoder;
>>>> +
>>>> +	drm_for_each_encoder(encoder, dev)
>>>> +		encoder->possible_clones |= drm_encoder_mask(encoder);
>>>> +}
>>>> +
>>>>  int drm_encoder_register_all(struct drm_device *dev)
>>>>  {
>>>>  	struct drm_encoder *encoder;
>>>>  	int ret = 0;
>>>>  
>>>> +	fixup_possible_clones(dev);
>>>> +
>>>>  	drm_for_each_encoder(encoder, dev) {
>>>>  		if (encoder->funcs->late_register)
>>>>  			ret = encoder->funcs->late_register(encoder);
>>>>
>>>
>>> -- 
>>> Thomas Zimmermann
>>> Graphics Driver Developer
>>> SUSE Software Solutions Germany GmbH
>>> Maxfeldstr. 5, 90409 Nürnberg, Germany
>>> (HRB 36809, AG Nürnberg)
>>> Geschäftsführer: Felix Imendörffer
>>>
>>
>>
>>
>>
>> -- 
>> Ville Syrjälä
>> Intel
>> _______________________________________________
>> Intel-gfx mailing list
>> Intel-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c
index e555281f43d4..f761d9306028 100644
--- a/drivers/gpu/drm/drm_encoder.c
+++ b/drivers/gpu/drm/drm_encoder.c
@@ -66,11 +66,26 @@  static const struct drm_prop_enum_list drm_encoder_enum_list[] = {
 	{ DRM_MODE_ENCODER_DPI, "DPI" },
 };
 
+/*
+ * For some reason we want the encoder itself included in
+ * possible_clones. Make life easy for drivers by allowing them
+ * to leave possible_clones unset if no cloning is possible.
+ */
+static void fixup_possible_clones(struct drm_device *dev)
+{
+	struct drm_encoder *encoder;
+
+	drm_for_each_encoder(encoder, dev)
+		encoder->possible_clones |= drm_encoder_mask(encoder);
+}
+
 int drm_encoder_register_all(struct drm_device *dev)
 {
 	struct drm_encoder *encoder;
 	int ret = 0;
 
+	fixup_possible_clones(dev);
+
 	drm_for_each_encoder(encoder, dev) {
 		if (encoder->funcs->late_register)
 			ret = encoder->funcs->late_register(encoder);