Re: [Intel-gfx] [RFC v4 12/25] drm/i915: Add drm_driver->initial_client_display callback

2019-03-01 Thread Daniel Vetter
On Fri, Mar 1, 2019 at 12:46 PM Noralf Trønnes  wrote:
>
>
>
> Den 16.04.2018 10.38, skrev Daniel Vetter:
> > On Sat, Apr 14, 2018 at 01:53:05PM +0200, Noralf Trønnes wrote:
> >> As part of moving the modesetting code out of drm_fb_helper and into
> >> drm_client, the drm_fb_helper_funcs->initial_config callback needs to go.
> >> Replace it with a drm_driver->initial_client_display callback that can
> >> work for all in-kernel clients.
> >>
> >> TODO:
> >> - Add a patch that moves the function out of intel_fbdev.c since it's not
> >>   fbdev specific anymore.
> >>
> >> Signed-off-by: Noralf Trønnes 
> >
> > So the reason we originally added this callback for i915 fast boot was
> > that there wasn't any atomic around yet. And it was all an experiment to
> > figure out how to best go about designing fastboot.
> >
> > But now we have fbdev, and fastboot design is also pretty clear:
> >
> > 1. driver loads
> > 2. driver reads out current hw state, reconstructs a full atomic state for
> > everything and stuffs it into connector/crtc/plane->state pointers.
> > 3. fbdev and any other client read out current state (with some caveats)
> > and just take it over.
> >
> > What non-fastboot drivers do:
> > 1. drivers load
> > 2. reset both hw and sw state to everything off.
> >
> > Now the intel_fb_initial_config is all generic code really, and it will
> > neatly fall back to the default config if everything is off. This means we
> > could:
> > 1. Move the intel_fb_initial_config into the fbdev helpers.
> > 2. Nuke the ->initial_config callback.
> >
> > And pronto! every driver which implements hw state readout will get fbdev
> > fastboot for free.
> >
>
> I'm back working on this now and there's one intel specific thing:
> num_pipes, in that function that I don't know how to handle when moving
> the code into the fbdev helper:

num_pipes == dev->mode_config.num_crtcs. Or should at least if we
managed to set up everything correctly. Not exactly sure why we've
used that intel-ism there, shouldn't have any effect when switching
over.
-Daniel

>
> static bool intel_fb_initial_config(...)
> {
> [...]
> /*
>  * If the BIOS didn't enable everything it could, fall back to have 
> the
>  * same user experiencing of lighting up as much as possible like the
>  * fbdev helper library.
>  */
> if (num_connectors_enabled != num_connectors_detected &&
> num_connectors_enabled < INTEL_INFO(dev_priv)->num_pipes) {
> DRM_DEBUG_KMS("fallback: Not all outputs enabled\n");
> DRM_DEBUG_KMS("Enabled: %i, detected: %i\n", 
> num_connectors_enabled,
>   num_connectors_detected);
> fallback = true;
> }
>
> Noralf.
>
> > And since you've already rewritting the intel code to use drm_client, it's
> > practically done already. Just need to s/intel_/drm_fbdev_helper_ or
> > something like that :-)
> > -Daniel
> >
> >> ---
> >>  drivers/gpu/drm/drm_fb_helper.c|  19 +--
> >>  drivers/gpu/drm/i915/i915_drv.c|   1 +
> >>  drivers/gpu/drm/i915/intel_drv.h   |  11 
> >>  drivers/gpu/drm/i915/intel_fbdev.c | 113 
> >> ++---
> >>  include/drm/drm_drv.h  |  21 +++
> >>  5 files changed, 104 insertions(+), 61 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/drm_fb_helper.c 
> >> b/drivers/gpu/drm/drm_fb_helper.c
> >> index b992f59dad30..5407bf6dc8c0 100644
> >> --- a/drivers/gpu/drm/drm_fb_helper.c
> >> +++ b/drivers/gpu/drm/drm_fb_helper.c
> >> @@ -2103,6 +2103,20 @@ static void drm_setup_crtcs(struct drm_fb_helper 
> >> *fb_helper,
> >>  /* prevent concurrent modification of connector_count by hotplug */
> >>  lockdep_assert_held(&fb_helper->lock);
> >>
> >> +mutex_lock(&dev->mode_config.mutex);
> >> +if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 
> >> 0)
> >> +DRM_DEBUG_KMS("No connectors reported connected with 
> >> modes\n");
> >> +
> >> +if (dev->driver->initial_client_display) {
> >> +display = dev->driver->initial_client_display(dev, width, 
> >> height);
> >> +if (display) {
> >> +drm_client_display_free(fb_helper->display);
> >> +fb_helper->display = display;
> >> +mutex_unlock(&dev->mode_config.mutex);
> >> +return;
> >> +}
> >> +}
> >> +
> >>  crtcs = kcalloc(fb_helper->connector_count,
> >>  sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
> >>  modes = kcalloc(fb_helper->connector_count,
> >> @@ -2120,9 +2134,6 @@ static void drm_setup_crtcs(struct drm_fb_helper 
> >> *fb_helper,
> >>  if (IS_ERR(display))
> >>  goto out;
> >>
> >> -mutex_lock(&fb_helper->dev->mode_config.mutex);
> >> -if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 
> >> 0)
> >> -DRM_DEBUG_KMS("No connectors repo

Re: [Intel-gfx] [RFC v4 12/25] drm/i915: Add drm_driver->initial_client_display callback

2019-03-01 Thread Noralf Trønnes


Den 16.04.2018 10.38, skrev Daniel Vetter:
> On Sat, Apr 14, 2018 at 01:53:05PM +0200, Noralf Trønnes wrote:
>> As part of moving the modesetting code out of drm_fb_helper and into
>> drm_client, the drm_fb_helper_funcs->initial_config callback needs to go.
>> Replace it with a drm_driver->initial_client_display callback that can
>> work for all in-kernel clients.
>>
>> TODO:
>> - Add a patch that moves the function out of intel_fbdev.c since it's not
>>   fbdev specific anymore.
>>
>> Signed-off-by: Noralf Trønnes 
> 
> So the reason we originally added this callback for i915 fast boot was
> that there wasn't any atomic around yet. And it was all an experiment to
> figure out how to best go about designing fastboot.
> 
> But now we have fbdev, and fastboot design is also pretty clear:
> 
> 1. driver loads
> 2. driver reads out current hw state, reconstructs a full atomic state for
> everything and stuffs it into connector/crtc/plane->state pointers.
> 3. fbdev and any other client read out current state (with some caveats)
> and just take it over.
> 
> What non-fastboot drivers do:
> 1. drivers load
> 2. reset both hw and sw state to everything off.
> 
> Now the intel_fb_initial_config is all generic code really, and it will
> neatly fall back to the default config if everything is off. This means we
> could:
> 1. Move the intel_fb_initial_config into the fbdev helpers.
> 2. Nuke the ->initial_config callback.
> 
> And pronto! every driver which implements hw state readout will get fbdev
> fastboot for free.
> 

I'm back working on this now and there's one intel specific thing:
num_pipes, in that function that I don't know how to handle when moving
the code into the fbdev helper:

static bool intel_fb_initial_config(...)
{
[...]
/*
 * If the BIOS didn't enable everything it could, fall back to have the
 * same user experiencing of lighting up as much as possible like the
 * fbdev helper library.
 */
if (num_connectors_enabled != num_connectors_detected &&
num_connectors_enabled < INTEL_INFO(dev_priv)->num_pipes) {
DRM_DEBUG_KMS("fallback: Not all outputs enabled\n");
DRM_DEBUG_KMS("Enabled: %i, detected: %i\n", 
num_connectors_enabled,
  num_connectors_detected);
fallback = true;
}

Noralf.

> And since you've already rewritting the intel code to use drm_client, it's
> practically done already. Just need to s/intel_/drm_fbdev_helper_ or
> something like that :-)
> -Daniel
> 
>> ---
>>  drivers/gpu/drm/drm_fb_helper.c|  19 +--
>>  drivers/gpu/drm/i915/i915_drv.c|   1 +
>>  drivers/gpu/drm/i915/intel_drv.h   |  11 
>>  drivers/gpu/drm/i915/intel_fbdev.c | 113 
>> ++---
>>  include/drm/drm_drv.h  |  21 +++
>>  5 files changed, 104 insertions(+), 61 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_fb_helper.c 
>> b/drivers/gpu/drm/drm_fb_helper.c
>> index b992f59dad30..5407bf6dc8c0 100644
>> --- a/drivers/gpu/drm/drm_fb_helper.c
>> +++ b/drivers/gpu/drm/drm_fb_helper.c
>> @@ -2103,6 +2103,20 @@ static void drm_setup_crtcs(struct drm_fb_helper 
>> *fb_helper,
>>  /* prevent concurrent modification of connector_count by hotplug */
>>  lockdep_assert_held(&fb_helper->lock);
>>  
>> +mutex_lock(&dev->mode_config.mutex);
>> +if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0)
>> +DRM_DEBUG_KMS("No connectors reported connected with modes\n");
>> +
>> +if (dev->driver->initial_client_display) {
>> +display = dev->driver->initial_client_display(dev, width, 
>> height);
>> +if (display) {
>> +drm_client_display_free(fb_helper->display);
>> +fb_helper->display = display;
>> +mutex_unlock(&dev->mode_config.mutex);
>> +return;
>> +}
>> +}
>> +
>>  crtcs = kcalloc(fb_helper->connector_count,
>>  sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
>>  modes = kcalloc(fb_helper->connector_count,
>> @@ -2120,9 +2134,6 @@ static void drm_setup_crtcs(struct drm_fb_helper 
>> *fb_helper,
>>  if (IS_ERR(display))
>>  goto out;
>>  
>> -mutex_lock(&fb_helper->dev->mode_config.mutex);
>> -if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0)
>> -DRM_DEBUG_KMS("No connectors reported connected with modes\n");
>>  drm_enable_connectors(fb_helper, enabled);
>>  
>>  if (!(fb_helper->funcs->initial_config &&
>> @@ -2144,7 +2155,6 @@ static void drm_setup_crtcs(struct drm_fb_helper 
>> *fb_helper,
>>  
>>  drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
>>  }
>> -mutex_unlock(&fb_helper->dev->mode_config.mutex);
>>  
>>  /* need to set the modesets up here for use later */
>>  /* fill out the connector<->crtc mappings into the modes

Re: [Intel-gfx] [RFC v4 12/25] drm/i915: Add drm_driver->initial_client_display callback

2018-04-16 Thread Daniel Vetter
On Sat, Apr 14, 2018 at 01:53:05PM +0200, Noralf Trønnes wrote:
> As part of moving the modesetting code out of drm_fb_helper and into
> drm_client, the drm_fb_helper_funcs->initial_config callback needs to go.
> Replace it with a drm_driver->initial_client_display callback that can
> work for all in-kernel clients.
> 
> TODO:
> - Add a patch that moves the function out of intel_fbdev.c since it's not
>   fbdev specific anymore.
> 
> Signed-off-by: Noralf Trønnes 

So the reason we originally added this callback for i915 fast boot was
that there wasn't any atomic around yet. And it was all an experiment to
figure out how to best go about designing fastboot.

But now we have fbdev, and fastboot design is also pretty clear:

1. driver loads
2. driver reads out current hw state, reconstructs a full atomic state for
everything and stuffs it into connector/crtc/plane->state pointers.
3. fbdev and any other client read out current state (with some caveats)
and just take it over.

What non-fastboot drivers do:
1. drivers load
2. reset both hw and sw state to everything off.

Now the intel_fb_initial_config is all generic code really, and it will
neatly fall back to the default config if everything is off. This means we
could:
1. Move the intel_fb_initial_config into the fbdev helpers.
2. Nuke the ->initial_config callback.

And pronto! every driver which implements hw state readout will get fbdev
fastboot for free.

And since you've already rewritting the intel code to use drm_client, it's
practically done already. Just need to s/intel_/drm_fbdev_helper_ or
something like that :-)
-Daniel

> ---
>  drivers/gpu/drm/drm_fb_helper.c|  19 +--
>  drivers/gpu/drm/i915/i915_drv.c|   1 +
>  drivers/gpu/drm/i915/intel_drv.h   |  11 
>  drivers/gpu/drm/i915/intel_fbdev.c | 113 
> ++---
>  include/drm/drm_drv.h  |  21 +++
>  5 files changed, 104 insertions(+), 61 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index b992f59dad30..5407bf6dc8c0 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -2103,6 +2103,20 @@ static void drm_setup_crtcs(struct drm_fb_helper 
> *fb_helper,
>   /* prevent concurrent modification of connector_count by hotplug */
>   lockdep_assert_held(&fb_helper->lock);
>  
> + mutex_lock(&dev->mode_config.mutex);
> + if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0)
> + DRM_DEBUG_KMS("No connectors reported connected with modes\n");
> +
> + if (dev->driver->initial_client_display) {
> + display = dev->driver->initial_client_display(dev, width, 
> height);
> + if (display) {
> + drm_client_display_free(fb_helper->display);
> + fb_helper->display = display;
> + mutex_unlock(&dev->mode_config.mutex);
> + return;
> + }
> + }
> +
>   crtcs = kcalloc(fb_helper->connector_count,
>   sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
>   modes = kcalloc(fb_helper->connector_count,
> @@ -2120,9 +2134,6 @@ static void drm_setup_crtcs(struct drm_fb_helper 
> *fb_helper,
>   if (IS_ERR(display))
>   goto out;
>  
> - mutex_lock(&fb_helper->dev->mode_config.mutex);
> - if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0)
> - DRM_DEBUG_KMS("No connectors reported connected with modes\n");
>   drm_enable_connectors(fb_helper, enabled);
>  
>   if (!(fb_helper->funcs->initial_config &&
> @@ -2144,7 +2155,6 @@ static void drm_setup_crtcs(struct drm_fb_helper 
> *fb_helper,
>  
>   drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
>   }
> - mutex_unlock(&fb_helper->dev->mode_config.mutex);
>  
>   /* need to set the modesets up here for use later */
>   /* fill out the connector<->crtc mappings into the modesets */
> @@ -2182,6 +2192,7 @@ static void drm_setup_crtcs(struct drm_fb_helper 
> *fb_helper,
>   drm_client_display_free(fb_helper->display);
>   fb_helper->display = display;
>  out:
> + mutex_unlock(&dev->mode_config.mutex);
>   kfree(crtcs);
>   kfree(modes);
>   kfree(offsets);
> diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
> index 07c07d55398b..b746c0cbaa4b 100644
> --- a/drivers/gpu/drm/i915/i915_drv.c
> +++ b/drivers/gpu/drm/i915/i915_drv.c
> @@ -2857,6 +2857,7 @@ static struct drm_driver driver = {
>  
>   .dumb_create = i915_gem_dumb_create,
>   .dumb_map_offset = i915_gem_mmap_gtt,
> + .initial_client_display = i915_initial_client_display,
>   .ioctls = i915_ioctls,
>   .num_ioctls = ARRAY_SIZE(i915_ioctls),
>   .fops = &i915_driver_fops,
> diff --git a/drivers/gpu/drm/i915/intel_drv.h 
> b/drivers/gpu/drm/i915/intel_drv.h
> index d4368589b355..f77f510617c5 100644
> --- a/driver

[RFC v4 12/25] drm/i915: Add drm_driver->initial_client_display callback

2018-04-14 Thread Noralf Trønnes
As part of moving the modesetting code out of drm_fb_helper and into
drm_client, the drm_fb_helper_funcs->initial_config callback needs to go.
Replace it with a drm_driver->initial_client_display callback that can
work for all in-kernel clients.

TODO:
- Add a patch that moves the function out of intel_fbdev.c since it's not
  fbdev specific anymore.

Signed-off-by: Noralf Trønnes 
---
 drivers/gpu/drm/drm_fb_helper.c|  19 +--
 drivers/gpu/drm/i915/i915_drv.c|   1 +
 drivers/gpu/drm/i915/intel_drv.h   |  11 
 drivers/gpu/drm/i915/intel_fbdev.c | 113 ++---
 include/drm/drm_drv.h  |  21 +++
 5 files changed, 104 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index b992f59dad30..5407bf6dc8c0 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -2103,6 +2103,20 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
/* prevent concurrent modification of connector_count by hotplug */
lockdep_assert_held(&fb_helper->lock);
 
+   mutex_lock(&dev->mode_config.mutex);
+   if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0)
+   DRM_DEBUG_KMS("No connectors reported connected with modes\n");
+
+   if (dev->driver->initial_client_display) {
+   display = dev->driver->initial_client_display(dev, width, 
height);
+   if (display) {
+   drm_client_display_free(fb_helper->display);
+   fb_helper->display = display;
+   mutex_unlock(&dev->mode_config.mutex);
+   return;
+   }
+   }
+
crtcs = kcalloc(fb_helper->connector_count,
sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
modes = kcalloc(fb_helper->connector_count,
@@ -2120,9 +2134,6 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
if (IS_ERR(display))
goto out;
 
-   mutex_lock(&fb_helper->dev->mode_config.mutex);
-   if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0)
-   DRM_DEBUG_KMS("No connectors reported connected with modes\n");
drm_enable_connectors(fb_helper, enabled);
 
if (!(fb_helper->funcs->initial_config &&
@@ -2144,7 +2155,6 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
 
drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
}
-   mutex_unlock(&fb_helper->dev->mode_config.mutex);
 
/* need to set the modesets up here for use later */
/* fill out the connector<->crtc mappings into the modesets */
@@ -2182,6 +2192,7 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
drm_client_display_free(fb_helper->display);
fb_helper->display = display;
 out:
+   mutex_unlock(&dev->mode_config.mutex);
kfree(crtcs);
kfree(modes);
kfree(offsets);
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 07c07d55398b..b746c0cbaa4b 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -2857,6 +2857,7 @@ static struct drm_driver driver = {
 
.dumb_create = i915_gem_dumb_create,
.dumb_map_offset = i915_gem_mmap_gtt,
+   .initial_client_display = i915_initial_client_display,
.ioctls = i915_ioctls,
.num_ioctls = ARRAY_SIZE(i915_ioctls),
.fops = &i915_driver_fops,
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index d4368589b355..f77f510617c5 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1720,6 +1720,9 @@ extern void intel_fbdev_fini(struct drm_i915_private 
*dev_priv);
 extern void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool 
synchronous);
 extern void intel_fbdev_output_poll_changed(struct drm_device *dev);
 extern void intel_fbdev_restore_mode(struct drm_device *dev);
+struct drm_client_display *
+i915_initial_client_display(struct drm_device *dev, unsigned int width,
+   unsigned int height);
 #else
 static inline int intel_fbdev_init(struct drm_device *dev)
 {
@@ -1749,6 +1752,14 @@ static inline void 
intel_fbdev_output_poll_changed(struct drm_device *dev)
 static inline void intel_fbdev_restore_mode(struct drm_device *dev)
 {
 }
+
+static inline struct drm_client_display *
+i915_initial_client_display(struct drm_device *dev, unsigned int width,
+   unsigned int height)
+{
+   return NULL;
+}
+
 #endif
 
 /* intel_fbc.c */
diff --git a/drivers/gpu/drm/i915/intel_fbdev.c 
b/drivers/gpu/drm/i915/intel_fbdev.c
index a4ab8575a72e..b7f44c9475a8 100644
--- a/drivers/gpu/drm/i915/intel_fbdev.c
+++ b/drivers/gpu/drm/i915/intel_fbdev.c
@@ -38,6 +38,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include "intel_drv.h"

[RFC v4 12/25] drm/i915: Add drm_driver->initial_client_display callback

2018-04-13 Thread Noralf Trønnes
As part of moving the modesetting code out of drm_fb_helper and into
drm_client, the drm_fb_helper_funcs->initial_config callback needs to go.
Replace it with a drm_driver->initial_client_display callback that can
work for all in-kernel clients.

TODO:
- Add a patch that moves the function out of intel_fbdev.c since it's not
  fbdev specific anymore.

Signed-off-by: Noralf Trønnes 
---
 drivers/gpu/drm/drm_fb_helper.c|  19 +--
 drivers/gpu/drm/i915/i915_drv.c|   1 +
 drivers/gpu/drm/i915/intel_drv.h   |  11 
 drivers/gpu/drm/i915/intel_fbdev.c | 113 ++---
 include/drm/drm_drv.h  |  21 +++
 5 files changed, 104 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index b992f59dad30..5407bf6dc8c0 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -2103,6 +2103,20 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
/* prevent concurrent modification of connector_count by hotplug */
lockdep_assert_held(&fb_helper->lock);
 
+   mutex_lock(&dev->mode_config.mutex);
+   if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0)
+   DRM_DEBUG_KMS("No connectors reported connected with modes\n");
+
+   if (dev->driver->initial_client_display) {
+   display = dev->driver->initial_client_display(dev, width, 
height);
+   if (display) {
+   drm_client_display_free(fb_helper->display);
+   fb_helper->display = display;
+   mutex_unlock(&dev->mode_config.mutex);
+   return;
+   }
+   }
+
crtcs = kcalloc(fb_helper->connector_count,
sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
modes = kcalloc(fb_helper->connector_count,
@@ -2120,9 +2134,6 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
if (IS_ERR(display))
goto out;
 
-   mutex_lock(&fb_helper->dev->mode_config.mutex);
-   if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0)
-   DRM_DEBUG_KMS("No connectors reported connected with modes\n");
drm_enable_connectors(fb_helper, enabled);
 
if (!(fb_helper->funcs->initial_config &&
@@ -2144,7 +2155,6 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
 
drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
}
-   mutex_unlock(&fb_helper->dev->mode_config.mutex);
 
/* need to set the modesets up here for use later */
/* fill out the connector<->crtc mappings into the modesets */
@@ -2182,6 +2192,7 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
drm_client_display_free(fb_helper->display);
fb_helper->display = display;
 out:
+   mutex_unlock(&dev->mode_config.mutex);
kfree(crtcs);
kfree(modes);
kfree(offsets);
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 07c07d55398b..b746c0cbaa4b 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -2857,6 +2857,7 @@ static struct drm_driver driver = {
 
.dumb_create = i915_gem_dumb_create,
.dumb_map_offset = i915_gem_mmap_gtt,
+   .initial_client_display = i915_initial_client_display,
.ioctls = i915_ioctls,
.num_ioctls = ARRAY_SIZE(i915_ioctls),
.fops = &i915_driver_fops,
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index d4368589b355..f77f510617c5 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1720,6 +1720,9 @@ extern void intel_fbdev_fini(struct drm_i915_private 
*dev_priv);
 extern void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool 
synchronous);
 extern void intel_fbdev_output_poll_changed(struct drm_device *dev);
 extern void intel_fbdev_restore_mode(struct drm_device *dev);
+struct drm_client_display *
+i915_initial_client_display(struct drm_device *dev, unsigned int width,
+   unsigned int height);
 #else
 static inline int intel_fbdev_init(struct drm_device *dev)
 {
@@ -1749,6 +1752,14 @@ static inline void 
intel_fbdev_output_poll_changed(struct drm_device *dev)
 static inline void intel_fbdev_restore_mode(struct drm_device *dev)
 {
 }
+
+static inline struct drm_client_display *
+i915_initial_client_display(struct drm_device *dev, unsigned int width,
+   unsigned int height)
+{
+   return NULL;
+}
+
 #endif
 
 /* intel_fbc.c */
diff --git a/drivers/gpu/drm/i915/intel_fbdev.c 
b/drivers/gpu/drm/i915/intel_fbdev.c
index a4ab8575a72e..b7f44c9475a8 100644
--- a/drivers/gpu/drm/i915/intel_fbdev.c
+++ b/drivers/gpu/drm/i915/intel_fbdev.c
@@ -38,6 +38,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include "intel_drv.h"

[RFC v4 12/25] drm/i915: Add drm_driver->initial_client_display callback

2018-04-12 Thread Noralf Trønnes
As part of moving the modesetting code out of drm_fb_helper and into
drm_client, the drm_fb_helper_funcs->initial_config callback needs to go.
Replace it with a drm_driver->initial_client_display callback that can
work for all in-kernel clients.

TODO:
- Add a patch that moves the function out of intel_fbdev.c since it's not
  fbdev specific anymore.

Signed-off-by: Noralf Trønnes 
---
 drivers/gpu/drm/drm_fb_helper.c|  19 +--
 drivers/gpu/drm/i915/i915_drv.c|   1 +
 drivers/gpu/drm/i915/intel_drv.h   |  11 
 drivers/gpu/drm/i915/intel_fbdev.c | 113 ++---
 include/drm/drm_drv.h  |  21 +++
 5 files changed, 104 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index b992f59dad30..5407bf6dc8c0 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -2103,6 +2103,20 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
/* prevent concurrent modification of connector_count by hotplug */
lockdep_assert_held(&fb_helper->lock);
 
+   mutex_lock(&dev->mode_config.mutex);
+   if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0)
+   DRM_DEBUG_KMS("No connectors reported connected with modes\n");
+
+   if (dev->driver->initial_client_display) {
+   display = dev->driver->initial_client_display(dev, width, 
height);
+   if (display) {
+   drm_client_display_free(fb_helper->display);
+   fb_helper->display = display;
+   mutex_unlock(&dev->mode_config.mutex);
+   return;
+   }
+   }
+
crtcs = kcalloc(fb_helper->connector_count,
sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
modes = kcalloc(fb_helper->connector_count,
@@ -2120,9 +2134,6 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
if (IS_ERR(display))
goto out;
 
-   mutex_lock(&fb_helper->dev->mode_config.mutex);
-   if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0)
-   DRM_DEBUG_KMS("No connectors reported connected with modes\n");
drm_enable_connectors(fb_helper, enabled);
 
if (!(fb_helper->funcs->initial_config &&
@@ -2144,7 +2155,6 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
 
drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
}
-   mutex_unlock(&fb_helper->dev->mode_config.mutex);
 
/* need to set the modesets up here for use later */
/* fill out the connector<->crtc mappings into the modesets */
@@ -2182,6 +2192,7 @@ static void drm_setup_crtcs(struct drm_fb_helper 
*fb_helper,
drm_client_display_free(fb_helper->display);
fb_helper->display = display;
 out:
+   mutex_unlock(&dev->mode_config.mutex);
kfree(crtcs);
kfree(modes);
kfree(offsets);
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 07c07d55398b..b746c0cbaa4b 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -2857,6 +2857,7 @@ static struct drm_driver driver = {
 
.dumb_create = i915_gem_dumb_create,
.dumb_map_offset = i915_gem_mmap_gtt,
+   .initial_client_display = i915_initial_client_display,
.ioctls = i915_ioctls,
.num_ioctls = ARRAY_SIZE(i915_ioctls),
.fops = &i915_driver_fops,
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index d4368589b355..f77f510617c5 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1720,6 +1720,9 @@ extern void intel_fbdev_fini(struct drm_i915_private 
*dev_priv);
 extern void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool 
synchronous);
 extern void intel_fbdev_output_poll_changed(struct drm_device *dev);
 extern void intel_fbdev_restore_mode(struct drm_device *dev);
+struct drm_client_display *
+i915_initial_client_display(struct drm_device *dev, unsigned int width,
+   unsigned int height);
 #else
 static inline int intel_fbdev_init(struct drm_device *dev)
 {
@@ -1749,6 +1752,14 @@ static inline void 
intel_fbdev_output_poll_changed(struct drm_device *dev)
 static inline void intel_fbdev_restore_mode(struct drm_device *dev)
 {
 }
+
+static inline struct drm_client_display *
+i915_initial_client_display(struct drm_device *dev, unsigned int width,
+   unsigned int height)
+{
+   return NULL;
+}
+
 #endif
 
 /* intel_fbc.c */
diff --git a/drivers/gpu/drm/i915/intel_fbdev.c 
b/drivers/gpu/drm/i915/intel_fbdev.c
index a4ab8575a72e..b7f44c9475a8 100644
--- a/drivers/gpu/drm/i915/intel_fbdev.c
+++ b/drivers/gpu/drm/i915/intel_fbdev.c
@@ -38,6 +38,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include "intel_drv.h"