dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [RFC v4 00/25] drm: Add generic fbdev emulation
@ 2018-04-14 11:52 Noralf Trønnes
  2018-04-14 11:52 ` [RFC v4 01/25] drm: provide management functions for drm_file Noralf Trønnes
                   ` (25 more replies)
  0 siblings, 26 replies; 46+ messages in thread
From: Noralf Trønnes @ 2018-04-14 11:52 UTC (permalink / raw)
  To: dri-devel; +Cc: intel-gfx, Noralf Trønnes

This patchset explores the possibility of having generic fbdev emulation
in DRM for drivers that supports dumb buffers which they can export. An
API is added to support in-kernel clients in general.

In this version I was able to reuse the modesetting code from
drm_fb_helper in the client API. This avoids code duplication, carries
over lessons learned and the modesetting code is bisectable. The
downside is that it takes +10 patches to rip drm_fb_helper in two, so
maybe it's not worth it wrt possible breakage and a challenging review.

Does the Intel CI test the fbdev emulation?

Daniel had this concern with the previous version:

    The register/unregister model needs more thought. Allowing both clients
    to register whenever they want to, and drm_device instances to come and
    go is what fbcon has done, and the resulting locking is a horror show.

    I think if we require that all in-kernel drm_clients are registers when
    loading drm.ko (and enabled/disabled only per module options and
    Kconfig), then we can throw out all the locking. That avoids a lot of
    the headaches.

I have solved this by adding a notifier that fires when a new DRM device
is registered (I've removed the new() callback). Currently only
bootsplash uses this. The fbdev client needs to be setup from the driver
since it can't know on device registration if the driver will setup it's
own fbdev emulation later and the vtcon client hooks up to a user
provided device id.

Since fbcon can't handle fb_open failing, the buffer has to be
pre-allocated. Exporting a GEM buffer pins the driver module making it
impossible to unload it.
I have included 2 solutions to the problem:
- sysfs file to remove/close clients: remove_internal_clients
- Change drm_gem_prime_export() so it doesn't pin on client buffers

If a dumb buffer is exported from a kernel thread (worker) context, the
file descriptor isn't closed and I leak a reference so the buffer isn't
freed. Please look at drm_client_buffer_create() in patch
'drm/client: Finish the in-kernel client API'.
This is a blocker that needs a solution.


Noralf.

Changes since version 3:
Client API changes:
- Drop drm_client_register_funcs() which attached clients indirectly.
  Let clients attach directly using drm_client_new{_from_id}(). Clients
  that wants to attach to all devices must be linked into drm.ko and use
  the DRM device notifier. This is done to avoid the lock/race
  register/unregister hell we have with fbcon. (Daniel Vetter)
- drm_client_display_restore() checks if there is a master and if so
  returns -EBUSY. (Daniel Vetter)
- Allocate drm_file up front instead of on-demand. Since fbdev can't do
  on demand buffer allocation because of fbcon, there's no need for this.
- Add sysfs file to remove clients
- Don't pin driver module when exporting gem client buffers
- Dropped page flip support since drm_fb_helper is now used for fbdev
  emulation.

- The bootsplash client now switches over to fbdev on keypress.

Changes since version 2:
- Don't set drm master for in-kernel clients. (Daniel Vetter)
- Add in-kernel client API

Changes since version 1:
- Don't add drm_fb_helper_fb_open() and drm_fb_helper_fb_release() to
  DRM_FB_HELPER_DEFAULT_OPS(). (Fi.CI.STATIC)
  The following uses that macro and sets fb_open/close: udlfb_ops,
  amdgpufb_ops, drm_fb_helper_generic_fbdev_ops, nouveau_fbcon_ops,
  nouveau_fbcon_sw_ops, radeonfb_ops.
  This results in: warning: Initializer entry defined twice
- Support CONFIG_DRM_KMS_HELPER=m (kbuild test robot)
  ERROR: <function> [drivers/gpu/drm/drm_kms_helper.ko] undefined!
- Drop buggy patch: (Chris Wilson)
  drm/prime: Clear drm_gem_object->dma_buf on release
- Defer buffer creation until fb_open.


David Herrmann (1):
  drm: provide management functions for drm_file

Noralf Trønnes (24):
  drm/file: Don't set master on in-kernel clients
  drm/fb-helper: No need to cache rotation and sw_rotations
  drm/fb-helper: Remove drm_fb_helper_debug_enter/leave()
  drm/fb-helper: dpms_legacy(): Only set on connectors in use
  drm/atomic: Move __drm_atomic_helper_disable_plane/set_config()
  drm: Begin an API for in-kernel clients
  drm/fb-helper: Use struct drm_client_display
  drm/fb-helper: Move modeset commit code to drm_client
  drm/connector: Add
    drm_connector_has_preferred_mode/pick_cmdline_mode()
  drm/connector: Add connector array functions
  drm/i915: Add drm_driver->initial_client_display callback
  drm/fb-helper: Remove struct drm_fb_helper_crtc
  drm/fb-helper: Remove struct drm_fb_helper_connector
  drm/fb-helper: Move modeset config code to drm_client
  drm: Make ioctls available for in-kernel clients
  drm/client: Bail out if there's a DRM master
  drm/client: Make the display modes available to clients
  drm/client: Finish the in-kernel client API
  drm/prime: Don't pin module on export for in-kernel clients
  drm/fb-helper: Add drm_fb_helper_fb_open/release()
  drm/fb-helper: Add generic fbdev emulation
  drm: Add DRM device registered notifier
  drm/client: Hack: Add bootsplash
  drm/client: Hack: Add DRM VT console client

 drivers/gpu/drm/Kconfig                 |    2 +
 drivers/gpu/drm/Makefile                |    4 +-
 drivers/gpu/drm/client/Kconfig          |   14 +
 drivers/gpu/drm/client/Makefile         |    3 +
 drivers/gpu/drm/client/drm_bootsplash.c |  248 ++++++
 drivers/gpu/drm/client/drm_vtcon.c      |  785 +++++++++++++++++
 drivers/gpu/drm/client/internal.h       |   19 +
 drivers/gpu/drm/drm_atomic.c            |  168 ++++
 drivers/gpu/drm/drm_atomic_helper.c     |  168 +---
 drivers/gpu/drm/drm_auth.c              |   33 +
 drivers/gpu/drm/drm_client.c            | 1448 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_connector.c         |  199 +++++
 drivers/gpu/drm/drm_crtc_internal.h     |   18 +-
 drivers/gpu/drm/drm_debugfs.c           |    7 +
 drivers/gpu/drm/drm_drv.c               |   43 +
 drivers/gpu/drm/drm_dumb_buffers.c      |   33 +-
 drivers/gpu/drm/drm_fb_helper.c         | 1420 ++++++++----------------------
 drivers/gpu/drm/drm_file.c              |  304 ++++---
 drivers/gpu/drm/drm_framebuffer.c       |   50 +-
 drivers/gpu/drm/drm_internal.h          |    7 +
 drivers/gpu/drm/drm_ioc32.c             |    2 +-
 drivers/gpu/drm/drm_ioctl.c             |    4 +-
 drivers/gpu/drm/drm_prime.c             |   37 +-
 drivers/gpu/drm/drm_probe_helper.c      |    3 +
 drivers/gpu/drm/drm_sysfs.c             |   20 +
 drivers/gpu/drm/i915/i915_drv.c         |    1 +
 drivers/gpu/drm/i915/intel_drv.h        |   11 +
 drivers/gpu/drm/i915/intel_fbdev.c      |  112 +--
 include/drm/drm_atomic.h                |    5 +
 include/drm/drm_atomic_helper.h         |    4 -
 include/drm/drm_client.h                |  182 ++++
 include/drm/drm_connector.h             |   11 +
 include/drm/drm_device.h                |    4 +
 include/drm/drm_drv.h                   |   25 +
 include/drm/drm_fb_helper.h             |  126 ++-
 35 files changed, 4007 insertions(+), 1513 deletions(-)
 create mode 100644 drivers/gpu/drm/client/Kconfig
 create mode 100644 drivers/gpu/drm/client/Makefile
 create mode 100644 drivers/gpu/drm/client/drm_bootsplash.c
 create mode 100644 drivers/gpu/drm/client/drm_vtcon.c
 create mode 100644 drivers/gpu/drm/client/internal.h
 create mode 100644 drivers/gpu/drm/drm_client.c
 create mode 100644 include/drm/drm_client.h

--
2.15.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 46+ messages in thread
* [RFC v4 00/25] drm: Add generic fbdev emulation
@ 2018-04-13 16:53 Noralf Trønnes
  2018-04-13 16:53 ` [RFC v4 16/25] drm: Make ioctls available for in-kernel clients Noralf Trønnes
  0 siblings, 1 reply; 46+ messages in thread
From: Noralf Trønnes @ 2018-04-13 16:53 UTC (permalink / raw)
  To: dri-devel; +Cc: daniel.vetter, intel-gfx, laurent.pinchart, mstaudt

This patchset explores the possibility of having generic fbdev emulation
in DRM for drivers that supports dumb buffers which they can export. An
API is added to support in-kernel clients in general.

In this version I was able to reuse the modesetting code from
drm_fb_helper in the client API. This avoids code duplication, carries
over lessons learned and the modesetting code is bisectable. The
downside is that it takes +10 patches to rip drm_fb_helper in two, so
maybe it's not worth it wrt possible breakage and a challenging review.

Does the Intel CI test the fbdev emulation?

Daniel had this concern with the previous version:

    The register/unregister model needs more thought. Allowing both clients
    to register whenever they want to, and drm_device instances to come and
    go is what fbcon has done, and the resulting locking is a horror show.

    I think if we require that all in-kernel drm_clients are registers when
    loading drm.ko (and enabled/disabled only per module options and
    Kconfig), then we can throw out all the locking. That avoids a lot of
    the headaches.

I have solved this by adding a notifier that fires when a new DRM device
is registered (I've removed the new() callback). Currently only
bootsplash uses this. The fbdev client needs to be setup from the driver
since it can't know on device registration if the driver will setup it's
own fbdev emulation later and the vtcon client hooks up to a user
provided device id.

Since fbcon can't handle fb_open failing, the buffer has to be
pre-allocated. Exporting a GEM buffer pins the driver module making it
impossible to unload it.
I have included 2 solutions to the problem:
- sysfs file to remove/close clients: remove_internal_clients
- Change drm_gem_prime_export() so it doesn't pin on client buffers

If a dumb buffer is exported from a kernel thread (worker) context, the
file descriptor isn't closed and I leak a reference so the buffer isn't
freed. Please look at drm_client_buffer_create() in patch
'drm/client: Finish the in-kernel client API'.
This is a blocker that needs a solution.


Noralf.

Changes since version 3:
Client API changes:
- Drop drm_client_register_funcs() which attached clients indirectly.
  Let clients attach directly using drm_client_new{_from_id}(). Clients
  that wants to attach to all devices must be linked into drm.ko and use
  the DRM device notifier. This is done to avoid the lock/race
  register/unregister hell we have with fbcon. (Daniel Vetter)
- drm_client_display_restore() checks if there is a master and if so
  returns -EBUSY. (Daniel Vetter)
- Allocate drm_file up front instead of on-demand. Since fbdev can't do
  on demand buffer allocation because of fbcon, there's no need for this.
- Add sysfs file to remove clients
- Don't pin driver module when exporting gem client buffers
- Dropped page flip support since drm_fb_helper is now used for fbdev
  emulation.

- The bootsplash client now switches over to fbdev on keypress.

Changes since version 2:
- Don't set drm master for in-kernel clients. (Daniel Vetter)
- Add in-kernel client API

Changes since version 1:
- Don't add drm_fb_helper_fb_open() and drm_fb_helper_fb_release() to
  DRM_FB_HELPER_DEFAULT_OPS(). (Fi.CI.STATIC)
  The following uses that macro and sets fb_open/close: udlfb_ops,
  amdgpufb_ops, drm_fb_helper_generic_fbdev_ops, nouveau_fbcon_ops,
  nouveau_fbcon_sw_ops, radeonfb_ops.
  This results in: warning: Initializer entry defined twice
- Support CONFIG_DRM_KMS_HELPER=m (kbuild test robot)
  ERROR: <function> [drivers/gpu/drm/drm_kms_helper.ko] undefined!
- Drop buggy patch: (Chris Wilson)
  drm/prime: Clear drm_gem_object->dma_buf on release
- Defer buffer creation until fb_open.


David Herrmann (1):
  drm: provide management functions for drm_file

Noralf Trønnes (24):
  drm/file: Don't set master on in-kernel clients
  drm/fb-helper: No need to cache rotation and sw_rotations
  drm/fb-helper: Remove drm_fb_helper_debug_enter/leave()
  drm/fb-helper: dpms_legacy(): Only set on connectors in use
  drm/atomic: Move __drm_atomic_helper_disable_plane/set_config()
  drm: Begin an API for in-kernel clients
  drm/fb-helper: Use struct drm_client_display
  drm/fb-helper: Move modeset commit code to drm_client
  drm/connector: Add
    drm_connector_has_preferred_mode/pick_cmdline_mode()
  drm/connector: Add connector array functions
  drm/i915: Add drm_driver->initial_client_display callback
  drm/fb-helper: Remove struct drm_fb_helper_crtc
  drm/fb-helper: Remove struct drm_fb_helper_connector
  drm/fb-helper: Move modeset config code to drm_client
  drm: Make ioctls available for in-kernel clients
  drm/client: Bail out if there's a DRM master
  drm/client: Make the display modes available to clients
  drm/client: Finish the in-kernel client API
  drm/prime: Don't pin module on export for in-kernel clients
  drm/fb-helper: Add drm_fb_helper_fb_open/release()
  drm/fb-helper: Add generic fbdev emulation
  drm: Add DRM device registered notifier
  drm/client: Hack: Add bootsplash
  drm/client: Hack: Add DRM VT console client

 drivers/gpu/drm/Kconfig                 |    2 +
 drivers/gpu/drm/Makefile                |    4 +-
 drivers/gpu/drm/client/Kconfig          |   14 +
 drivers/gpu/drm/client/Makefile         |    3 +
 drivers/gpu/drm/client/drm_bootsplash.c |  248 ++++++
 drivers/gpu/drm/client/drm_vtcon.c      |  785 +++++++++++++++++
 drivers/gpu/drm/client/internal.h       |   19 +
 drivers/gpu/drm/drm_atomic.c            |  168 ++++
 drivers/gpu/drm/drm_atomic_helper.c     |  168 +---
 drivers/gpu/drm/drm_auth.c              |   33 +
 drivers/gpu/drm/drm_client.c            | 1448 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_connector.c         |  199 +++++
 drivers/gpu/drm/drm_crtc_internal.h     |   18 +-
 drivers/gpu/drm/drm_debugfs.c           |    7 +
 drivers/gpu/drm/drm_drv.c               |   43 +
 drivers/gpu/drm/drm_dumb_buffers.c      |   33 +-
 drivers/gpu/drm/drm_fb_helper.c         | 1420 ++++++++----------------------
 drivers/gpu/drm/drm_file.c              |  304 ++++---
 drivers/gpu/drm/drm_framebuffer.c       |   50 +-
 drivers/gpu/drm/drm_internal.h          |    7 +
 drivers/gpu/drm/drm_ioc32.c             |    2 +-
 drivers/gpu/drm/drm_ioctl.c             |    4 +-
 drivers/gpu/drm/drm_prime.c             |   37 +-
 drivers/gpu/drm/drm_probe_helper.c      |    3 +
 drivers/gpu/drm/drm_sysfs.c             |   20 +
 drivers/gpu/drm/i915/i915_drv.c         |    1 +
 drivers/gpu/drm/i915/intel_drv.h        |   11 +
 drivers/gpu/drm/i915/intel_fbdev.c      |  112 +--
 include/drm/drm_atomic.h                |    5 +
 include/drm/drm_atomic_helper.h         |    4 -
 include/drm/drm_client.h                |  182 ++++
 include/drm/drm_connector.h             |   11 +
 include/drm/drm_device.h                |    4 +
 include/drm/drm_drv.h                   |   25 +
 include/drm/drm_fb_helper.h             |  126 ++-
 35 files changed, 4007 insertions(+), 1513 deletions(-)
 create mode 100644 drivers/gpu/drm/client/Kconfig
 create mode 100644 drivers/gpu/drm/client/Makefile
 create mode 100644 drivers/gpu/drm/client/drm_bootsplash.c
 create mode 100644 drivers/gpu/drm/client/drm_vtcon.c
 create mode 100644 drivers/gpu/drm/client/internal.h
 create mode 100644 drivers/gpu/drm/drm_client.c
 create mode 100644 include/drm/drm_client.h

--
2.15.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 46+ messages in thread
* [RFC v4 12/25] drm/i915: Add drm_driver->initial_client_display callback
@ 2018-04-12 16:12 Noralf Trønnes
  2018-04-12 16:12 ` [RFC v4 16/25] drm: Make ioctls available for in-kernel clients Noralf Trønnes
  0 siblings, 1 reply; 46+ messages in thread
From: Noralf Trønnes @ 2018-04-12 16:12 UTC (permalink / raw)
  To: dri-devel; +Cc: daniel.vetter, intel-gfx, laurent.pinchart, mstaudt

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 <noralf@tronnes.org>
---
 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 <linux/vga_switcheroo.h>
 
 #include <drm/drmP.h>
+#include <drm/drm_client.h>
 #include <drm/drm_crtc.h>
 #include <drm/drm_fb_helper.h>
 #include "intel_drv.h"
@@ -287,18 +288,6 @@ static int intelfb_create(struct drm_fb_helper *helper,
 	return ret;
 }
 
-static struct drm_fb_helper_crtc *
-intel_fb_helper_crtc(struct drm_fb_helper *fb_helper, struct drm_crtc *crtc)
-{
-	int i;
-
-	for (i = 0; i < fb_helper->crtc_count; i++)
-		if (fb_helper->crtc_info[i].mode_set.crtc == crtc)
-			return &fb_helper->crtc_info[i];
-
-	return NULL;
-}
-
 /*
  * Try to read the BIOS display configuration and use it for the initial
  * fb configuration.
@@ -326,44 +315,48 @@ intel_fb_helper_crtc(struct drm_fb_helper *fb_helper, struct drm_crtc *crtc)
  * is in VGA mode we need to recalculate watermarks and set a new high-res
  * framebuffer anyway.
  */
-static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper,
-				    struct drm_fb_helper_crtc **crtcs,
-				    struct drm_display_mode **modes,
-				    struct drm_fb_offset *offsets,
-				    bool *enabled, int width, int height)
+struct drm_client_display *
+i915_initial_client_display(struct drm_device *dev, unsigned int width,
+			    unsigned int height)
 {
-	struct drm_i915_private *dev_priv = to_i915(fb_helper->dev);
+	struct drm_i915_private *dev_priv = to_i915(dev);
 	unsigned long conn_configured, conn_seq, mask;
-	unsigned int count = min(fb_helper->connector_count, BITS_PER_LONG);
-	int i, j;
-	bool *save_enabled;
-	bool fallback = true, ret = true;
+	bool fallback = true, *enabled = NULL;
+	struct drm_client_display *display;
+	struct drm_connector **connectors;
+	int i, connector_count;
+	unsigned int count;
 	int num_connectors_enabled = 0;
 	int num_connectors_detected = 0;
 	struct drm_modeset_acquire_ctx ctx;
 
-	save_enabled = kcalloc(count, sizeof(bool), GFP_KERNEL);
-	if (!save_enabled)
-		return false;
+	display = drm_client_display_create(dev);
+	if (IS_ERR(display))
+		return NULL;
 
 	drm_modeset_acquire_init(&ctx, 0);
 
-	while (drm_modeset_lock_all_ctx(fb_helper->dev, &ctx) != 0)
+	while (drm_modeset_lock_all_ctx(dev, &ctx) != 0)
 		drm_modeset_backoff(&ctx);
 
-	memcpy(save_enabled, enabled, count);
+	connector_count = drm_connector_get_all(dev, &connectors);
+	if (connector_count < 1)
+		goto bail;
+
+	enabled = drm_connector_get_enabled_status(connectors, connector_count);
+	if (!enabled)
+		goto bail;
+
+	count = min(connector_count, BITS_PER_LONG);
 	mask = GENMASK(count - 1, 0);
 	conn_configured = 0;
 retry:
 	conn_seq = conn_configured;
 	for (i = 0; i < count; i++) {
-		struct drm_fb_helper_connector *fb_conn;
-		struct drm_connector *connector;
+		struct drm_connector *connector = connectors[i];
+		struct drm_display_mode *mode;
+		struct drm_mode_set *modeset;
 		struct drm_encoder *encoder;
-		struct drm_fb_helper_crtc *new_crtc;
-
-		fb_conn = fb_helper->connector_info[i];
-		connector = fb_conn->connector;
 
 		if (conn_configured & BIT(i))
 			continue;
@@ -402,16 +395,13 @@ static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper,
 
 		num_connectors_enabled++;
 
-		new_crtc = intel_fb_helper_crtc(fb_helper,
-						connector->state->crtc);
-
 		/*
 		 * Make sure we're not trying to drive multiple connectors
 		 * with a single CRTC, since our cloning support may not
 		 * match the BIOS.
 		 */
-		for (j = 0; j < count; j++) {
-			if (crtcs[j] == new_crtc) {
+		drm_client_display_for_each_modeset(modeset, display) {
+			if (modeset->connectors[0] == connector) {
 				DRM_DEBUG_KMS("fallback: cloned configuration\n");
 				goto bail;
 			}
@@ -421,28 +411,26 @@ static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper,
 			      connector->name);
 
 		/* go for command line mode first */
-		modes[i] = drm_connector_pick_cmdline_mode(connector);
+		mode = drm_connector_pick_cmdline_mode(connector);
 
 		/* try for preferred next */
-		if (!modes[i]) {
+		if (!mode) {
 			DRM_DEBUG_KMS("looking for preferred mode on connector %s %d\n",
 				      connector->name, connector->has_tile);
-			modes[i] = drm_connector_has_preferred_mode(connector,
-								    width,
-								    height);
+			mode = drm_connector_has_preferred_mode(connector,
+								width, height);
 		}
 
 		/* No preferred mode marked by the EDID? Are there any modes? */
-		if (!modes[i] && !list_empty(&connector->modes)) {
+		if (!mode && !list_empty(&connector->modes)) {
 			DRM_DEBUG_KMS("using first mode listed on connector %s\n",
 				      connector->name);
-			modes[i] = list_first_entry(&connector->modes,
-						    struct drm_display_mode,
-						    head);
+			mode = list_first_entry(&connector->modes,
+						struct drm_display_mode, head);
 		}
 
 		/* last resort: use current mode */
-		if (!modes[i]) {
+		if (!mode) {
 			/*
 			 * IMPORTANT: We want to use the adjusted mode (i.e.
 			 * after the panel fitter upscaling) as the initial
@@ -458,16 +446,26 @@ static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper,
 			 */
 			DRM_DEBUG_KMS("looking for current mode on connector %s\n",
 				      connector->name);
-			modes[i] = &connector->state->crtc->mode;
+			mode = &connector->state->crtc->mode;
 		}
-		crtcs[i] = new_crtc;
+
+		modeset = drm_client_display_find_modeset(display, connector->state->crtc);
+		if (WARN_ON(!modeset))
+			goto bail;
+
+		modeset->mode = drm_mode_duplicate(dev, mode);
+		drm_connector_get(connector);
+		modeset->connectors[0] = connector;
+		modeset->num_connectors = 1;
+		modeset->x = 0;
+		modeset->y = 0;
 
 		DRM_DEBUG_KMS("connector %s on [CRTC:%d:%s]: %dx%d%s\n",
 			      connector->name,
 			      connector->state->crtc->base.id,
 			      connector->state->crtc->name,
-			      modes[i]->hdisplay, modes[i]->vdisplay,
-			      modes[i]->flags & DRM_MODE_FLAG_INTERLACE ? "i" :"");
+			      mode->hdisplay, mode->vdisplay,
+			      mode->flags & DRM_MODE_FLAG_INTERLACE ? "i" : "");
 
 		fallback = false;
 		conn_configured |= BIT(i);
@@ -492,19 +490,20 @@ static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper,
 	if (fallback) {
 bail:
 		DRM_DEBUG_KMS("Not using firmware configuration\n");
-		memcpy(enabled, save_enabled, count);
-		ret = false;
+		drm_client_display_free(display);
+		display = NULL;
 	}
 
 	drm_modeset_drop_locks(&ctx);
 	drm_modeset_acquire_fini(&ctx);
 
-	kfree(save_enabled);
-	return ret;
+	drm_connector_put_all(connectors, connector_count);
+	kfree(enabled);
+
+	return display;
 }
 
 static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
-	.initial_config = intel_fb_initial_config,
 	.fb_probe = intelfb_create,
 };
 
diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h
index 7e545f5f94d3..13356e6fd40c 100644
--- a/include/drm/drm_drv.h
+++ b/include/drm/drm_drv.h
@@ -32,6 +32,7 @@
 
 #include <drm/drm_device.h>
 
+struct drm_client_display;
 struct drm_file;
 struct drm_gem_object;
 struct drm_master;
@@ -553,6 +554,26 @@ struct drm_driver {
 			    struct drm_device *dev,
 			    uint32_t handle);
 
+	/**
+	 * @initial_client_config:
+	 *
+	 * Driver callback to setup an initial fbdev display configuration.
+	 * Drivers can use this callback to tell the fbdev emulation what the
+	 * preferred initial configuration is. This is useful to implement
+	 * smooth booting where the fbdev (and subsequently all userspace) never
+	 * changes the mode, but always inherits the existing configuration.
+	 *
+	 * This callback is optional.
+	 *
+	 * RETURNS:
+	 *
+	 * The driver should return true if a suitable initial configuration has
+	 * been filled out and false when the fbdev helper should fall back to
+	 * the default probing logic.
+	 */
+	struct drm_client_display *(*initial_client_display)(struct drm_device *dev,
+					unsigned int width, unsigned int height);
+
 	/**
 	 * @gem_vm_ops: Driver private ops for this object
 	 */
-- 
2.15.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 46+ messages in thread

end of thread, other threads:[~2019-03-01 11:51 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-14 11:52 [RFC v4 00/25] drm: Add generic fbdev emulation Noralf Trønnes
2018-04-14 11:52 ` [RFC v4 01/25] drm: provide management functions for drm_file Noralf Trønnes
2018-04-14 11:52 ` [RFC v4 02/25] drm/file: Don't set master on in-kernel clients Noralf Trønnes
2018-04-14 11:52 ` [RFC v4 03/25] drm/fb-helper: No need to cache rotation and sw_rotations Noralf Trønnes
2018-04-14 11:52 ` [RFC v4 04/25] drm/fb-helper: Remove drm_fb_helper_debug_enter/leave() Noralf Trønnes
2018-04-14 11:52 ` [RFC v4 05/25] drm/fb-helper: dpms_legacy(): Only set on connectors in use Noralf Trønnes
2018-04-14 11:52 ` [RFC v4 06/25] drm/atomic: Move __drm_atomic_helper_disable_plane/set_config() Noralf Trønnes
2018-04-16  8:30   ` Daniel Vetter
2018-04-14 11:53 ` [RFC v4 07/25] drm: Begin an API for in-kernel clients Noralf Trønnes
2018-04-14 11:53 ` [RFC v4 08/25] drm/fb-helper: Use struct drm_client_display Noralf Trønnes
2018-04-14 11:53 ` [RFC v4 09/25] drm/fb-helper: Move modeset commit code to drm_client Noralf Trønnes
2018-04-14 11:53 ` [RFC v4 10/25] drm/connector: Add drm_connector_has_preferred_mode/pick_cmdline_mode() Noralf Trønnes
2018-04-14 11:53 ` [RFC v4 11/25] drm/connector: Add connector array functions Noralf Trønnes
2018-04-16  8:33   ` Daniel Vetter
2018-04-14 11:53 ` [RFC v4 12/25] drm/i915: Add drm_driver->initial_client_display callback Noralf Trønnes
2018-04-16  8:38   ` Daniel Vetter
2019-03-01 11:46     ` [Intel-gfx] " Noralf Trønnes
2019-03-01 11:51       ` Daniel Vetter
2018-04-14 11:53 ` [RFC v4 13/25] drm/fb-helper: Remove struct drm_fb_helper_crtc Noralf Trønnes
2018-04-14 11:53 ` [RFC v4 14/25] drm/fb-helper: Remove struct drm_fb_helper_connector Noralf Trønnes
2018-04-14 11:53 ` [RFC v4 15/25] drm/fb-helper: Move modeset config code to drm_client Noralf Trønnes
2018-04-14 11:53 ` [RFC v4 16/25] drm: Make ioctls available for in-kernel clients Noralf Trønnes
2018-04-16  9:04   ` Daniel Vetter
2018-04-14 11:53 ` [RFC v4 17/25] drm/client: Bail out if there's a DRM master Noralf Trønnes
2018-04-16  8:45   ` Daniel Vetter
2018-04-14 11:53 ` [RFC v4 18/25] drm/client: Make the display modes available to clients Noralf Trønnes
2018-04-14 11:53 ` [RFC v4 19/25] drm/client: Finish the in-kernel client API Noralf Trønnes
2018-04-16  8:27   ` [Intel-gfx] " Daniel Vetter
2018-04-16 15:58     ` Noralf Trønnes
2018-04-17  8:08       ` Daniel Vetter
2018-04-14 11:53 ` [RFC v4 20/25] drm/prime: Don't pin module on export for in-kernel clients Noralf Trønnes
2018-04-14 11:53 ` [RFC v4 21/25] drm/fb-helper: Add drm_fb_helper_fb_open/release() Noralf Trønnes
2018-04-16  8:46   ` Daniel Vetter
2018-04-16 16:10     ` Noralf Trønnes
2018-04-17  8:14       ` [Intel-gfx] " Daniel Vetter
2018-04-14 11:53 ` [RFC v4 22/25] drm/fb-helper: Add generic fbdev emulation Noralf Trønnes
2018-04-16  8:52   ` Daniel Vetter
2018-04-14 11:53 ` [RFC v4 23/25] drm: Add DRM device registered notifier Noralf Trønnes
2018-04-17 10:16   ` Daniel Vetter
2018-04-14 11:53 ` [RFC v4 24/25] drm/client: Hack: Add bootsplash Noralf Trønnes
2018-04-14 11:53 ` [RFC v4 25/25] drm/client: Hack: Add DRM VT console client Noralf Trønnes
2018-04-16  8:21 ` [RFC v4 00/25] drm: Add generic fbdev emulation Daniel Vetter
2018-04-16 18:49   ` Noralf Trønnes
2018-04-17  8:10     ` [Intel-gfx] " Daniel Vetter
  -- strict thread matches above, loose matches on Subject: below --
2018-04-13 16:53 Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 16/25] drm: Make ioctls available for in-kernel clients Noralf Trønnes
2018-04-12 16:12 [RFC v4 12/25] drm/i915: Add drm_driver->initial_client_display callback Noralf Trønnes
2018-04-12 16:12 ` [RFC v4 16/25] drm: Make ioctls available for in-kernel clients Noralf Trønnes

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).