Skip to contentSkip to conversation

RFC: output polling + disconnected operation

PATCH New Dave Airlie 3 participants 8 messages May 5, 2010

Subsystems (5)
lore
Share & tools
lore

Dave Airlie

author maintainer
#0 lore raw

So one of the problems I want to solve for KMS it the what to do when nothing is plugged in at startup, I've fixed this for fbcon in the current tree, but when looking at X + randr clients I realised it needed a bit more work.

I've pulled the polling code back into the core, and it nows can send uevents to userspace when something changes. The drivers can specify flags for each output as to whether it is hotplug capable, needs connection polling and can handle disconnection polling. A lot of outputs can't handle disconnection polling due to DAC polling causing flicker on the current output. Also things like s-video shouldn't be polled for connect or disconnect esp if sharing a dac with a VGA output. So with patch one, we can boot, start X all without anything connected, however it runs into an issue which patch 2 is an attempt to fix.

So at startup X drivers genearlly seem to ask for a list of connectors and status for them, and if it can't find any connected, it goes to unknown, and if none of those they fall over and X exits. Idea 1 was to just pick a connector and claim it is connected when nothing else is, however this falls over, for DVI esp on a dual-DVI card. You pick a DVI connector, claim it is connected, you most likely end up turning on the analog portion of it, you hotplug a digital connector and the uevent gets sent, the client app repolls the connector status, sees the connector is still connected so doesn't do anything. Forcing a disconnect/connect is incredibly racy and hard. So Ben Skeggs suggested we just fake a disconnected connector for this case. It looks a bit messy in xrandr, but from what I can s
ee the gnome client ignores it as it should.

Anyways any other ideas on how this might be tackled or improvements that could be made?

Dave.

------------------------------------------------------------------------------
--

author maintainer
#1 lore raw

PATCH 1/2 drm/fbdev: rework output polling to be back in the core.

From: Dave Airlie <[email protected]>

After thinking it over a lot it made more sense for the core to deal with the output polling especially so it can notify X.

---
 drivers/gpu/drm/Kconfig                    |    2 +-
 drivers/gpu/drm/drm_crtc_helper.c          |   90 ++++++++++++++++++++
 drivers/gpu/drm/drm_fb_helper.c            |  123 ++++------------------------
 drivers/gpu/drm/i915/i915_irq.c            |    3 +-
 drivers/gpu/drm/i915/intel_display.c       |    1 +
 drivers/gpu/drm/i915/intel_drv.h           |    2 +-
 drivers/gpu/drm/i915/intel_fb.c            |   14 ++--
 drivers/gpu/drm/nouveau/nouveau_display.c  |    1 +
 drivers/gpu/drm/nouveau/nouveau_fbcon.c    |   14 +--
 drivers/gpu/drm/nouveau/nouveau_fbcon.h    |    2 +-
 drivers/gpu/drm/nouveau/nv50_display.c     |    2 +-
 drivers/gpu/drm/radeon/radeon_connectors.c |   13 +++
 drivers/gpu/drm/radeon/radeon_display.c    |    9 ++
 drivers/gpu/drm/radeon/radeon_fb.c         |   14 +---
 drivers/gpu/drm/radeon/radeon_irq_kms.c    |    5 +-
 drivers/gpu/drm/radeon/radeon_mode.h       |    3 +-
 include/drm/drm_crtc.h                     |   17 ++++
 include/drm/drm_crtc_helper.h              |    3 +
 include/drm/drm_fb_helper.h                |   13 +---
 19 files changed, 177 insertions(+), 154 deletions(-)
drivers/gpu/drm/Kconfig +1 -1
index be5aa7d..2583ddf 100644
@@ -9,6 +9,7 @@ menuconfig DRM
 	depends on (AGP || AGP=n) && PCI && !EMULATED_CMPXCHG && MMU
 	select I2C
 	select I2C_ALGOBIT
+	select SLOW_WORK
 	help
 	  Kernel-level support for the Direct Rendering Infrastructure (DRI)
 	  introduced in XFree86 4.0. If you say Y here, you need to select
@@ -23,7 +24,6 @@ config DRM_KMS_HELPER
 	depends on DRM
 	select FB
 	select FRAMEBUFFER_CONSOLE if !EMBEDDED
-	select SLOW_WORK
 	help
 	  FB and CRTC helpers for KMS drivers.
 
drivers/gpu/drm/drm_crtc_helper.c +90 -0

93 lines not on this page · raw message

drivers/gpu/drm/drm_fb_helper.c +18 -105

188 lines not on this page · raw message

drivers/gpu/drm/i915/i915_irq.c +1 -2
index ed26b7b..b034ea3 100644
@@ -271,8 +271,7 @@ static void i915_hotplug_work_func(struct work_struct *work)
 		}
 	}
 	/* Just fire off a uevent and let userspace tell us what to do */
-	intelfb_hotplug(dev, false);
-	drm_sysfs_hotplug_event(dev);
+	drm_helper_hpd_irq_event(dev);
 }
 
 static void i915_handle_rps_change(struct drm_device *dev)
drivers/gpu/drm/i915/intel_display.c +1 -0
index 3836f56..efc46ad 100644
@@ -4959,6 +4959,7 @@ intel_user_framebuffer_create(struct drm_device *dev,
 
 static const struct drm_mode_config_funcs intel_mode_funcs = {
 	.fb_create = intel_user_framebuffer_create,
+	.output_poll_changed = intel_fb_output_poll_changed,
 };
 
 static struct drm_gem_object *
drivers/gpu/drm/i915/intel_drv.h +1 -1
index 3230e8d..df931f7 100644
@@ -235,5 +235,5 @@ extern int intel_overlay_put_image(struct drm_device *dev, void *data,
 extern int intel_overlay_attrs(struct drm_device *dev, void *data,
 			       struct drm_file *file_priv);
 
-void intelfb_hotplug(struct drm_device *dev, bool polled);
+extern void intel_fb_output_poll_changed(struct drm_device *dev);
 #endif /* __INTEL_DRV_H__ */
drivers/gpu/drm/i915/intel_fb.c +7 -7
index b04e0a8..626aab7 100644
@@ -202,12 +202,6 @@ static int intel_fb_find_or_create_single(struct drm_fb_helper *helper,
 	return new_fb;
 }
 
-void intelfb_hotplug(struct drm_device *dev, bool polled)
-{
-	drm_i915_private_t *dev_priv = dev->dev_private;
-	drm_helper_fb_hpd_irq_event(&dev_priv->fbdev->helper);
-}
-
 static struct drm_fb_helper_funcs intel_fb_helper_funcs = {
 	.gamma_set = intel_crtc_fb_gamma_set,
 	.gamma_get = intel_crtc_fb_gamma_get,
@@ -251,7 +245,7 @@ int intel_fbdev_init(struct drm_device *dev)
 	ifbdev->helper.funcs = &intel_fb_helper_funcs;
 
 	drm_fb_helper_init(dev, &ifbdev->helper, 2,
-			   INTELFB_CONN_LIMIT, false);
+			   INTELFB_CONN_LIMIT);
 
 	drm_fb_helper_single_add_all_connectors(&ifbdev->helper);
 	drm_fb_helper_initial_config(&ifbdev->helper, 32);
@@ -269,3 +263,9 @@ void intel_fbdev_fini(struct drm_device *dev)
 	dev_priv->fbdev = NULL;
 }
 MODULE_LICENSE("GPL and additional rights");
+
+void intel_fb_output_poll_changed(struct drm_device *dev)
+{
+	drm_i915_private_t *dev_priv = dev->dev_private;
+	drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper);
+}
drivers/gpu/drm/nouveau/nouveau_display.c +1 -0
index 9d7928f..74e6b4e 100644
@@ -101,5 +101,6 @@ nouveau_user_framebuffer_create(struct drm_device *dev,
 
 const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
 	.fb_create = nouveau_user_framebuffer_create,
+	.output_poll_changed = nouveau_fbcon_output_poll_changed,
 };
 
drivers/gpu/drm/nouveau/nouveau_fbcon.c +4 -10
index f29fa8c..fa5abc2 100644
@@ -377,15 +377,11 @@ nouveau_fbcon_find_or_create_single(struct drm_fb_helper *helper,
 	return new_fb;
 }
 
-void nouveau_fbcon_hotplug(struct drm_device *dev)
+void
+nouveau_fbcon_output_poll_changed(struct drm_device *dev)
 {
 	struct drm_nouveau_private *dev_priv = dev->dev_private;
-	drm_helper_fb_hpd_irq_event(&dev_priv->nfbdev->helper);
-}
-
-static void nouveau_fbcon_output_status_changed(struct drm_fb_helper *fb_helper)
-{
-	drm_helper_fb_hotplug_event(fb_helper, true);
+	drm_fb_helper_hotplug_event(&dev_priv->nfbdev->helper);
 }
 
 int
@@ -425,7 +421,6 @@ static struct drm_fb_helper_funcs nouveau_fbcon_helper_funcs = {
 	.gamma_set = nouveau_fbcon_gamma_set,
 	.gamma_get = nouveau_fbcon_gamma_get,
 	.fb_probe = nouveau_fbcon_find_or_create_single,
-	.fb_output_status_changed = nouveau_fbcon_output_status_changed,
 };
 
 
@@ -442,8 +437,7 @@ int nouveau_fbcon_init(struct drm_device *dev)
 	dev_priv->nfbdev = nfbdev;
 	nfbdev->helper.funcs = &nouveau_fbcon_helper_funcs;
 
-	drm_fb_helper_init(dev, &nfbdev->helper,
-			   2, 4, true);
+	drm_fb_helper_init(dev, &nfbdev->helper, 2, 4);
 	drm_fb_helper_single_add_all_connectors(&nfbdev->helper);
 	drm_fb_helper_initial_config(&nfbdev->helper, 32);
 	return 0;
drivers/gpu/drm/nouveau/nouveau_fbcon.h +1 -1
index bf8e00d..e7e1268 100644
@@ -58,6 +58,6 @@ void nouveau_fbcon_zfill_all(struct drm_device *dev);
 void nouveau_fbcon_save_disable_accel(struct drm_device *dev);
 void nouveau_fbcon_restore_accel(struct drm_device *dev);
 
-void nouveau_fbcon_hotplug(struct drm_device *dev);
+void nouveau_fbcon_output_poll_changed(struct drm_device *dev);
 #endif /* __NV50_FBCON_H__ */
 
drivers/gpu/drm/nouveau/nv50_display.c +1 -1
index f9b3048..34156b6 100644
@@ -947,7 +947,7 @@ nv50_display_irq_hotplug_bh(struct work_struct *work)
 	if (dev_priv->chipset >= 0x90)
 		nv_wr32(dev, 0xe074, nv_rd32(dev, 0xe074));
 
-	nouveau_fbcon_hotplug(dev);
+	drm_helper_hpd_irq_event(dev);
 }
 
 void
drivers/gpu/drm/radeon/radeon_connectors.c +13 -0
index c489346..765854e 100644
@@ -1085,6 +1085,7 @@ radeon_add_atom_connector(struct drm_device *dev,
 		drm_connector_attach_property(&radeon_connector->base,
 					      rdev->mode_info.load_detect_property,
 					      1);
+		connector->polled = DRM_CONNECTOR_POLL_CONNECT;
 		break;
 	case DRM_MODE_CONNECTOR_DVIA:
 		drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
@@ -1211,6 +1212,12 @@ radeon_add_atom_connector(struct drm_device *dev,
 		break;
 	}
 
+	if (hpd->hpd == RADEON_HPD_NONE) {
+		if (i2c_bus->valid)
+			connector->polled = DRM_CONNECTOR_POLL_CONNECT;
+	} else
+		connector->polled = DRM_CONNECTOR_POLL_HPD;
+
 	connector->display_info.subpixel_order = subpixel_order;
 	drm_sysfs_connector_add(connector);
 	return;
@@ -1272,6 +1279,7 @@ radeon_add_legacy_connector(struct drm_device *dev,
 		drm_connector_attach_property(&radeon_connector->base,
 					      rdev->mode_info.load_detect_property,
 					      1);
+		connector->polled = DRM_CONNECTOR_POLL_CONNECT;
 		break;
 	case DRM_MODE_CONNECTOR_DVIA:
 		drm_connector_init(dev, &radeon_connector->base, &radeon_vga_connector_funcs, connector_type);
@@ -1338,6 +1346,11 @@ radeon_add_legacy_connector(struct drm_device *dev,
 		break;
 	}
 
+	if (hpd->hpd == RADEON_HPD_NONE) {
+		if (i2c_bus->valid)
+			connector->polled = DRM_CONNECTOR_POLL_CONNECT;
+	} else
+		connector->polled = DRM_CONNECTOR_POLL_HPD;
 	connector->display_info.subpixel_order = subpixel_order;
 	drm_sysfs_connector_add(connector);
 	return;
drivers/gpu/drm/radeon/radeon_display.c +9 -0
index 243c1c4..8200551 100644
@@ -888,8 +888,15 @@ radeon_user_framebuffer_create(struct drm_device *dev,
 	return &radeon_fb->base;
 }
 
+static void radeon_output_poll_changed(struct drm_device *dev)
+{
+	struct radeon_device *rdev = dev->dev_private;
+	radeon_fb_output_poll_changed(rdev);
+}
+
 static const struct drm_mode_config_funcs radeon_mode_funcs = {
 	.fb_create = radeon_user_framebuffer_create,
+	.output_poll_changed = radeon_output_poll_changed
 };
 
 struct drm_prop_enum_list {
@@ -1030,6 +1037,7 @@ int radeon_modeset_init(struct radeon_device *rdev)
 	/* initialize hpd */
 	radeon_hpd_init(rdev);
 
+	drm_kms_helper_poll_init(rdev->ddev);
 	radeon_fbdev_init(rdev);
 	return 0;
 }
@@ -1040,6 +1048,7 @@ void radeon_modeset_fini(struct radeon_device *rdev)
 	kfree(rdev->mode_info.bios_hardcoded_edid);
 
 	if (rdev->mode_info.mode_config_initialized) {
+		drm_kms_helper_poll_fini(rdev->ddev);
 		radeon_hpd_fini(rdev);
 		drm_mode_config_cleanup(rdev->ddev);
 		rdev->mode_info.mode_config_initialized = false;
drivers/gpu/drm/radeon/radeon_fb.c +3 -11
index fcb5b52..0b15675 100644
@@ -311,16 +311,9 @@ int radeon_parse_options(char *options)
 	return 0;
 }
 
-void radeonfb_hotplug(struct drm_device *dev, bool polled)
+void radeon_fb_output_poll_changed(struct radeon_device *rdev)
 {
-	struct radeon_device *rdev = dev->dev_private;
-
-	drm_helper_fb_hpd_irq_event(&rdev->mode_info.rfbdev->helper);
-}
-
-static void radeon_fb_output_status_changed(struct drm_fb_helper *fb_helper)
-{
-	drm_helper_fb_hotplug_event(fb_helper, true);
+	drm_fb_helper_hotplug_event(&rdev->mode_info.rfbdev->helper);
 }
 
 static int radeon_fbdev_destroy(struct drm_device *dev, struct radeon_fbdev *rfbdev)
@@ -359,7 +352,6 @@ static struct drm_fb_helper_funcs radeon_fb_helper_funcs = {
 	.gamma_set = radeon_crtc_fb_gamma_set,
 	.gamma_get = radeon_crtc_fb_gamma_get,
 	.fb_probe = radeon_fb_find_or_create_single,
-	.fb_output_status_changed = radeon_fb_output_status_changed,
 };
 
 int radeon_fbdev_init(struct radeon_device *rdev)
@@ -381,7 +373,7 @@ int radeon_fbdev_init(struct radeon_device *rdev)
 
 	drm_fb_helper_init(rdev->ddev, &rfbdev->helper,
 			   rdev->num_crtc,
-			   RADEONFB_CONN_LIMIT, true);
+			   RADEONFB_CONN_LIMIT);
 	drm_fb_helper_single_add_all_connectors(&rfbdev->helper);
 	drm_fb_helper_initial_config(&rfbdev->helper, bpp_sel);
 	return 0;
drivers/gpu/drm/radeon/radeon_irq_kms.c +2 -3
index a95907a..8fa40ed 100644
@@ -26,6 +26,7 @@
  *          Jerome Glisse
  */
 #include "drmP.h"
+#include "drm_crtc_helper.h"
 #include "radeon_drm.h"
 #include "radeon_reg.h"
 #include "radeon.h"
@@ -55,9 +56,7 @@ static void radeon_hotplug_work_func(struct work_struct *work)
 			radeon_connector_hotplug(connector);
 	}
 	/* Just fire off a uevent and let userspace tell us what to do */
-	radeonfb_hotplug(dev, false);
-
-	drm_sysfs_hotplug_event(dev);
+	drm_helper_hpd_irq_event(dev);
 }
 
 void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
drivers/gpu/drm/radeon/radeon_mode.h +2 -1
index 4a086c0..e545a79 100644
@@ -585,5 +585,6 @@ void radeon_fbdev_fini(struct radeon_device *rdev);
 void radeon_fbdev_set_suspend(struct radeon_device *rdev, int state);
 int radeon_fbdev_total_size(struct radeon_device *rdev);
 bool radeon_fbdev_robj_is_fb(struct radeon_device *rdev, struct radeon_bo *robj);
-void radeonfb_hotplug(struct drm_device *dev, bool polled);
+
+void radeon_fb_output_poll_changed(struct radeon_device *rdev);
 #endif
include/drm/drm_crtc.h +17 -0
index c560364..2e4bf92 100644
@@ -31,6 +31,7 @@
 #include <linux/idr.h>
 
 #include <linux/fb.h>
+#include <linux/slow-work.h>
 
 struct drm_device;
 struct drm_mode_set;
@@ -460,6 +461,15 @@ enum drm_connector_force {
 	DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
 };
 
+/* should we poll this connector for connects and disconnects */
+/* hot plug detectable */
+#define DRM_CONNECTOR_POLL_HPD (1 << 0)
+/* poll for connections */
+#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
+/* can cleanly poll for disconnections without flickering the screen */
+/* DACs should rarely do this without a lot of testing */
+#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
+
 /**
  * drm_connector - central DRM connector control structure
  * @crtc: CRTC this connector is currently connected to, NULL if none
@@ -504,6 +514,8 @@ struct drm_connector {
 	u32 property_ids[DRM_CONNECTOR_MAX_PROPERTY];
 	uint64_t property_values[DRM_CONNECTOR_MAX_PROPERTY];
 
+	uint8_t polled; /* DRM_CONNECTOR_POLL_* */
+
 	/* requested DPMS state */
 	int dpms;
 
@@ -543,6 +555,7 @@ struct drm_mode_set {
  */
 struct drm_mode_config_funcs {
 	struct drm_framebuffer *(*fb_create)(struct drm_device *dev, struct drm_file *file_priv, struct drm_mode_fb_cmd *mode_cmd);
+	void (*output_poll_changed)(struct drm_device *dev);
 };
 
 struct drm_mode_group {
@@ -580,6 +593,10 @@ struct drm_mode_config {
 	struct drm_mode_config_funcs *funcs;
 	resource_size_t fb_base;
 
+	/* output poll support */
+	bool poll_enabled;
+	struct delayed_slow_work output_poll_slow_work;
+
 	/* pointers to standard properties */
 	struct list_head property_blob_list;
 	struct drm_property *edid_property;
include/drm/drm_crtc_helper.h +3 -0
index b1fa0f8..dc5873c 100644
@@ -127,4 +127,7 @@ static inline void drm_connector_helper_add(struct drm_connector *connector,
 }
 
 extern int drm_helper_resume_force_mode(struct drm_device *dev);
+extern void drm_kms_helper_poll_init(struct drm_device *dev);
+extern void drm_kms_helper_poll_fini(struct drm_device *dev);
+extern void drm_helper_hpd_irq_event(struct drm_device *dev);
 #endif
include/drm/drm_fb_helper.h +2 -11
index 9b55a94..f0a6afc 100644
@@ -30,8 +30,6 @@
 #ifndef DRM_FB_HELPER_H
 #define DRM_FB_HELPER_H
 
-#include <linux/slow-work.h>
-
 struct drm_fb_helper;
 
 struct drm_fb_helper_crtc {
@@ -71,9 +69,6 @@ struct drm_fb_helper_funcs {
 
 	int (*fb_probe)(struct drm_fb_helper *helper,
 			struct drm_fb_helper_surface_size *sizes);
-
-	void (*fb_output_status_changed)(struct drm_fb_helper *helper);
-
 };
 
 struct drm_fb_helper_connector {
@@ -95,8 +90,6 @@ struct drm_fb_helper {
 	u32 pseudo_palette[17];
 	struct list_head kernel_fb_list;
 
-	struct delayed_slow_work output_status_change_slow_work;
-	bool poll_enabled;
 	/* we got a hotplug but fbdev wasn't running the console
 	   delay until next set_par */
 	bool delayed_hotplug;
@@ -107,7 +100,7 @@ int drm_fb_helper_single_fb_probe(struct drm_fb_helper *helper,
 
 int drm_fb_helper_init(struct drm_device *dev,
 		       struct drm_fb_helper *helper, int crtc_count,
-		       int max_conn, bool polled);
+		       int max_conn);
 void drm_fb_helper_fini(struct drm_fb_helper *helper);
 int drm_fb_helper_blank(int blank, struct fb_info *info);
 int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
@@ -130,10 +123,8 @@ void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
 
 int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info);
 
-bool drm_helper_fb_hotplug_event(struct drm_fb_helper *fb_helper,
-				 bool polled);
+bool drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper);
 bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel);
 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper);
 
-void drm_helper_fb_hpd_irq_event(struct drm_fb_helper *fb_helper);
 #endif
Signature · 5 lines
1.7.0.1


------------------------------------------------------------------------------
--
author maintainer
#2 lore raw

PATCH 2/2 drm: create fake disconnected connector for use when nothing is plugged in.

From: Dave Airlie <[email protected]>

The problem with using a real connector with a fake status is we have no way to tell userspace it got disconnected if something gets plugged into it, i.e. you use DVI-0 as the connector with an unknown or connected status, and it puts a 1024x768 mode on it. However when a monitor appears on that connector when we send the uevent and userspace repolls the modes it won't reset the mode on that output because the status hasn't changed sufficenetly. Unknown->connected status changes don't cause gnome to set the mode again.

Idea from Ben Skeggs to just create a fake disconnected connector, this seems to work well, xrandr gets a bit more info that needed, but gnome seems to work fine.

---
 drivers/gpu/drm/drm_crtc.c        |   40 +++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_crtc_helper.c |   25 ++++++++++++++++++++--
 drivers/gpu/drm/drm_fb_helper.c   |    2 +
 include/drm/drm_crtc.h            |    4 +++
 4 files changed, 68 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_crtc.c +40 -0
index 994d23b..3b880ca 100644
@@ -499,6 +499,7 @@ void drm_connector_cleanup(struct drm_connector *connector)
 	drm_mode_object_put(dev, &connector->base);
 	list_del(&connector->head);
 	mutex_unlock(&dev->mode_config.mutex);
+	connector->dev = NULL;
 }
 EXPORT_SYMBOL(drm_connector_cleanup);
 
@@ -1560,6 +1561,11 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
 				goto out;
 			}
 
+			if (out_id == dev->mode_config.disconnected_connector.base.id) {
+				ret = 0;
+				goto out;
+			}
+
 			obj = drm_mode_object_find(dev, out_id,
 						   DRM_MODE_OBJECT_CONNECTOR);
 			if (!obj) {
@@ -2655,3 +2661,37 @@ out:
 	mutex_unlock(&dev->mode_config.mutex);
 	return ret;
 }
+
+static void drm_connector_disconnected_dpms(struct drm_connector *connector, int mode)
+{
+	return;
+}
+
+static enum drm_connector_status drm_connector_disconnected_detect(struct drm_connector *connector)
+{
+	return connector_status_disconnected;
+}
+
+static int drm_connector_disconnected_fill_modes(struct drm_connector *connector, u32 max_width, u32 max_height)
+{
+	return 0;
+}
+
+static struct drm_connector_funcs drm_disconnected_funcs = {
+	.dpms = drm_connector_disconnected_dpms,
+	.detect = drm_connector_disconnected_detect,
+	.fill_modes = drm_connector_disconnected_fill_modes,
+	.destroy = drm_connector_cleanup,
+};
+
+int drm_mode_add_disconnected_connector(struct drm_device *dev)
+{
+	if (dev->mode_config.disconnected_connector.dev == NULL) {
+		drm_connector_init(dev, &dev->mode_config.disconnected_connector,
+				   &drm_disconnected_funcs,
+				   DRM_MODE_CONNECTOR_Unknown);
+		dev->mode_config.disconnected_connector.status = connector_status_disconnected;
+	}
+	return 0;
+}
+EXPORT_SYMBOL(drm_mode_add_disconnected_connector);
drivers/gpu/drm/drm_crtc_helper.c +22 -3
index ebb7a0c..665febb 100644
@@ -819,11 +819,20 @@ static void output_poll_execute(struct slow_work *work)
 	enum drm_connector_status old_status, status;
 	bool repoll = false, changed = false;
 	int ret;
+	bool connected = false;
 
 	list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
-		/* if this is HPD or polled don't check it - TV out for instance */
-		if (!connector->polled)
+
+		/* skip the special disconnected connector */
+		if (&dev->mode_config.disconnected_connector == connector)
+			continue;
+		/* if this is HPD or polled don't check it -
+		   TV out for instance */
+		if (!connector->polled) {
+			if (connector->status == connector_status_connected)
+				connected = true;
 			continue;
+		}
 		else if (connector->polled & (DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT))
 			repoll = true;
 
@@ -832,8 +841,10 @@ static void output_poll_execute(struct slow_work *work)
 		   skip it */
 		if (old_status == connector_status_connected &&
 		    !(connector->polled & DRM_CONNECTOR_POLL_DISCONNECT) &&
-		    !(connector->polled & DRM_CONNECTOR_POLL_HPD))
+		    !(connector->polled & DRM_CONNECTOR_POLL_HPD)) {
+			connected = true;
 			continue;
+		}
 
 		status = connector->funcs->detect(connector);
 		if (old_status != status)
@@ -843,6 +854,14 @@ static void output_poll_execute(struct slow_work *work)
 			connected = true;
 	}
 
+	/* if we have the disconnected connector */
+	if (dev->mode_config.disconnected_connector.dev != NULL) {
+		/* if nothing connected at all we need to force disconnected connector to connected */
+		if (!connected)
+			dev->mode_config.disconnected_connector.status = connector_status_connected;
+		else
+			dev->mode_config.disconnected_connector.status = connector_status_disconnected;
+	}
 	if (changed) {
 		/* send a uevent + call fbdev */
 		drm_sysfs_hotplug_event(dev);
drivers/gpu/drm/drm_fb_helper.c +2 -0
index d198b82..f7eb3f0 100644
@@ -1283,6 +1283,8 @@ bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
 	 */
 	if (count == 0) {
 		printk(KERN_INFO "No connectors reported connected with modes\n");
+		/* create fake connector to hang disconnected X operation off */
+		drm_mode_add_disconnected_connector(dev);
 	}
 	drm_setup_crtcs(fb_helper);
 
include/drm/drm_crtc.h +4 -0
index 2e4bf92..5dd3aad 100644
@@ -625,6 +625,8 @@ struct drm_mode_config {
 	struct drm_property *scaling_mode_property;
 	struct drm_property *dithering_mode_property;
 	struct drm_property *dirty_info_property;
+
+	struct drm_connector disconnected_connector;
 };
 
 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
@@ -804,4 +806,6 @@ extern int drm_add_modes_noedid(struct drm_connector *connector,
 				int hdisplay, int vdisplay);
 
 extern bool drm_edid_is_valid(struct edid *edid);
+
+extern int drm_mode_add_disconnected_connector(struct drm_device *dev);
 #endif /* __DRM_CRTC_H__ */
Signature · 5 lines
1.7.0.1


------------------------------------------------------------------------------
--
#3 lore raw
In reply to Dave Airlie
Quoted 5 lines · On Wed, 5 May 2010 11:12:13 +1000 Dave Airlie <[email protected]> wrote:

So at startup X drivers genearlly seem to ask for a list of connectors and status for them, and if it can't find any connected, it goes to unknown, and if none of those they fall over and X exits. Idea 1 was to just pick a connector and claim it is connected when nothing else is, however this falls over, for DVI esp on a dual-DVI

Quoted 8 lines

card. You pick a DVI connector, claim it is connected, you most likely end up turning on the analog portion of it, you hotplug a digital connector and the uevent gets sent, the client app repolls the connector status, sees the connector is still connected so doesn't do anything. Forcing a disconnect/connect is incredibly racy and hard. So Ben Skeggs suggested we just fake a disconnected connector for this case. It looks a bit messy in xrandr, but from what I can see the gnome client ignores it as it should.

It's an ugly problem... When the hotplug event is received, wouldn't you re-probe and find a digital monitor attached? If so, that would mean a mode set sent in by the X server should end up being a full one since the current config is incompatible. Which means X just has to know it forced a mode, so when any event comes in it should re-set the mode unconditionally...

Jesse

------------------------------------------------------------------------------
--

author maintainer
#4 lore raw
Quoted 16 lines · Jesse Barnes
Quoted 5 lines · On Wed,  5 May 2010 11:12:13 +1000 Dave Airlie <[email protected]> wrote:

So at startup X drivers genearlly seem to ask for a list of connectors and status for them, and if it can't find any connected, it goes to unknown, and if none of those they fall over and X exits. Idea 1 was to just pick a connector and claim it is connected when nothing else is, however this falls over, for DVI esp on a dual-DVI

Quoted 8 lines

card. You pick a DVI connector, claim it is connected, you most likely end up turning on the analog portion of it, you hotplug a digital connector and the uevent gets sent, the client app repolls the connector status, sees the connector is still connected so doesn't do anything. Forcing a disconnect/connect is incredibly racy and hard. So Ben Skeggs suggested we just fake a disconnected connector for this case. It looks a bit messy in xrandr, but from what I can see the gnome client ignores it as it should.

Quoted 6 lines

It's an ugly problem... When the hotplug event is received, wouldn't you re-probe and find a digital monitor attached?  If so, that would mean a mode set sent in by the X server should end up being a full one since the current config is incompatible.  Which means X just has to know it forced a mode, so when any event comes in it should re-set the mode unconditionally...

Userspace (as in gnome/kde/xrandr) doesn't know what is attached, digital or analog, it just sees a connected status, notices it was connected before, it still connected and doesn't do anything.

Dave.

------------------------------------------------------------------------------
--

#5 lore raw
In reply to Dave Airlie
Quoted 15 lines · Dave Airlie

So at startup X drivers genearlly seem to ask for a list of connectors and status for them, and if it can't find any connected, it goes to unknown, and if none of those they fall over and X exits. Idea 1 was to just pick a connector and claim it is connected when nothing else is, however this falls over, for DVI esp on a dual-DVI card. You pick a DVI connector, claim it is connected, you most likely end up turning on the analog portion of it, you hotplug a digital connector and the uevent gets sent, the client app repolls the connector status, sees the connector is still connected so doesn't do anything. Forcing a disconnect/connect is incredibly racy and hard. So Ben Skeggs suggested we just fake a disconnected connector for this case. It looks a bit messy in xrandr, but from what I can see the gnome client ignores it as it should.

Quoted 2 lines

Anyways any other ideas on how this might be tackled or improvements that could be made?

If I understand correctly, this tries to address userspace issues (X refusing to start up with nothing connected, GNOME doing nothing when an output changes from unknown to connected) by making the kernel fake information. Wouldn't it be better to address these in userspace? Otherwise if more similar issues turn up, we might end up in a twisty maze of fake information, possibly with conflicting requirements.

Signature · 9 lines
Earthling Michel Dänzer           |                http://www.vmware.com
Libre software enthusiast         |          Debian, X and DRI developer

------------------------------------------------------------------------------
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel
author maintainer
#6 lore raw

2010/5/5 Michel Dänzer <[email protected]>:

Quoted 19 lines · Dave Airlie
Quoted 15 lines

So at startup X drivers genearlly seem to ask for a list of connectors and status for them, and if it can't find any connected, it goes to unknown, and if none of those they fall over and X exits. Idea 1 was to just pick a connector and claim it is connected when nothing else is, however this falls over, for DVI esp on a dual-DVI card. You pick a DVI connector, claim it is connected, you most likely end up turning on the analog portion of it, you hotplug a digital connector and the uevent gets sent, the client app repolls the connector status, sees the connector is still connected so doesn't do anything. Forcing a disconnect/connect is incredibly racy and hard. So Ben Skeggs suggested we just fake a disconnected connector for this case. It looks a bit messy in xrandr, but from what I can see the gnome client ignores it as it should.

Quoted 2 lines

Anyways any other ideas on how this might be tackled or improvements that could be made?

Quoted 6 lines

If I understand correctly, this tries to address userspace issues (X refusing to start up with nothing connected, GNOME doing nothing when an output changes from unknown to connected) by making the kernel fake information. Wouldn't it be better to address these in userspace? Otherwise if more similar issues turn up, we might end up in a twisty maze of fake information, possibly with conflicting requirements.

The thing is current UMS drivers already do bad faking of stuff,

have a look at the info->first_load_no_devices flags in -ati.

So if nobody ever thought this was worth doing properly in the first place or anytime since, I'd like that KMS drivers can just follow what UMS drivers have done.

Granted I could probably do the faking in the KMS X.org drivers, but since UMS drivers never had hotplug or any useful uevent mechanism they'd never see the problem, so I've fixed the drivers to work.

My worry with changing X/GNOME is that it'll break some random corner case assumptions somewhere else in userspace, there are many randr clients and I don't want to hunt them all down, I'd like to advertise the protocol we have now if I can.

Dave.

------------------------------------------------------------------------------
--

#7 lore raw
Quoted 31 lines · Dave Airlie

2010/5/5 Michel Dänzer <[email protected]>:

Quoted 19 lines · Dave Airlie
Quoted 15 lines

So at startup X drivers genearlly seem to ask for a list of connectors and status for them, and if it can't find any connected, it goes to unknown, and if none of those they fall over and X exits. Idea 1 was to just pick a connector and claim it is connected when nothing else is, however this falls over, for DVI esp on a dual-DVI card. You pick a DVI connector, claim it is connected, you most likely end up turning on the analog portion of it, you hotplug a digital connector and the uevent gets sent, the client app repolls the connector status, sees the connector is still connected so doesn't do anything. Forcing a disconnect/connect is incredibly racy and hard. So Ben Skeggs suggested we just fake a disconnected connector for this case. It looks a bit messy in xrandr, but from what I can see the gnome client ignores it as it should.

Quoted 2 lines

Anyways any other ideas on how this might be tackled or improvements that could be made?

Quoted 6 lines

If I understand correctly, this tries to address userspace issues (X refusing to start up with nothing connected, GNOME doing nothing when an output changes from unknown to connected) by making the kernel fake information. Wouldn't it be better to address these in userspace? Otherwise if more similar issues turn up, we might end up in a twisty maze of fake information, possibly with conflicting requirements.

The thing is current UMS drivers already do bad faking of stuff,

have a look at the info->first_load_no_devices flags in -ati.

Quoted 7 lines

So if nobody ever thought this was worth doing properly in the first place or anytime since, I'd like that KMS drivers can just follow what UMS drivers have done.

Granted I could probably do the faking in the KMS X.org drivers, but since UMS drivers never had hotplug or any useful uevent mechanism they'd never see the problem, so I've fixed the drivers to work.

Doing it in the X drivers would be less ugly IMO, at least the workaround would be in / next to the same component as one of the underlying problems.

Quoted 3 lines

My worry with changing X/GNOME is that it'll break some random corner case assumptions somewhere else in userspace, there are many randr clients and I don't want to hunt them all down,

Then how do you know none of them will trip over this change?

Quoted 1 line

I'd like to advertise the protocol we have now if I can.

What protocol are you referring to?

To me it would make more sense to address the underlying problems rather than piling up more workarounds. The KMS API should provide as accurate information as possible, not second-guess what its users might expect.

Signature · 10 lines
Earthling Michel Dänzer           |                http://www.vmware.com
Libre software enthusiast         |          Debian, X and DRI developer


------------------------------------------------------------------------------
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel