Bug 58405

Summary: [i965GM SDVO] Driver not emitting event when unplugging enabled HDMI output [i965]
Product: DRI Reporter: Alex Fiestas <afiestas>
Component: DRM/IntelAssignee: Daniel Vetter <daniel>
Status: CLOSED FIXED QA Contact: Intel GFX Bugs mailing list <intel-gfx-bugs>
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments:
Description Flags
Xorg.log
none
dmesg with debug 6
none
dmesg since HDMI is plugged
none
dmesg since HDMI is unplug
none
dmesg plugging HDMI and executing xrandr
none
dmesg since unplugging HDMI and executing xrandr
none
dmesg drm.debug=6 drm-intel-nightly commit: 4f9e7cfb09a
none
fix sdvo hotplug init sequence
none
dmesg with printk
none
use gen3 hotplug register definitions
none
Patch needed to make it work
none
dmesg since hdmi plug/unplug
none
fixup sdvo hpd bits on gen4.0 none

Description Alex Fiestas 2012-12-17 11:34:39 UTC
If the output connected to the HDMI port is enabled (set to a crtc) and it is unplugged, the event to announce that the output is no longer connected won't be emitted until XRRGetResourceScreen is called (you can execute the command xrandr to trigger it).

This behaviour doesn't seem to happen with VGA, and I could reproduce it in a i965GM (Dell xps1330) and a newer one integrated in an i7 cpu.

Linux MonsterBad 3.7.0-7-generic #15-Ubuntu SMP Sat Dec 15 16:34:25 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
Comment 1 Alex Fiestas 2012-12-17 11:36:17 UTC
Any more info you need, please ask for it.

I can recompile, apply patches or whatever is needed, and test the path in 3 different machines.

Thanks :)
Comment 2 Chris Wilson 2012-12-17 11:59:50 UTC
Please attach your Xorg.0.log and dmesg.
Comment 3 Alex Fiestas 2012-12-17 16:13:15 UTC
Created attachment 71661 [details]
Xorg.log
Comment 4 Chris Wilson 2012-12-17 16:33:27 UTC
Thanks, that was useful to check everything that needed to be enabled was. So the likely cause is simply that the hotplug event is not being generated.
Comment 5 Chris Wilson 2012-12-17 16:34:14 UTC
What we will need now is a dmesg with drm.debug=6 (echo 6 > /sys/modules/drm/parameters/debug) over the course of you unplugging the HDMI.
Comment 6 Alex Fiestas 2012-12-17 16:44:30 UTC
Created attachment 71664 [details]
dmesg with debug 6
Comment 7 Alex Fiestas 2012-12-17 16:45:34 UTC
I added some comments (look for //) indicating where I had to execute xrandr to get the event, and a case where it worked (sent the event at the right time).
Comment 8 Alex Fiestas 2013-01-16 14:55:39 UTC
During the testing of our xrandr integration in KDE, at least 4 more users had this issue, one of them with a VGA1 port.

Is there any more debug information I can provide? maybe logs from other computers? or you have enough?

Thanks !
Comment 9 Daniel Vetter 2013-01-16 19:50:54 UTC
Kernel 3.8 fixes a bug in the hotplug handling where a userspace request for the current output status could inadvertently eat the respective hpd event. So retesting on a 3.8-rc kernel highly recommended.
Comment 10 Alex Fiestas 2013-01-19 19:34:03 UTC
Tested with 3.8-rc4, everything continues as described plus now no event is mitted when plugging the HDMI output (I have to execute xrandr to trigger it).

Will attach info running rc4 kernel.
Comment 11 Alex Fiestas 2013-01-19 19:56:28 UTC
Created attachment 73299 [details]
dmesg since HDMI is plugged
Comment 12 Alex Fiestas 2013-01-19 19:56:55 UTC
Created attachment 73300 [details]
dmesg since HDMI is unplug
Comment 13 Alex Fiestas 2013-01-19 19:57:22 UTC
Created attachment 73301 [details]
dmesg plugging  HDMI and executing xrandr
Comment 14 Alex Fiestas 2013-01-19 19:57:55 UTC
Created attachment 73302 [details]
dmesg since unplugging HDMI and executing xrandr
Comment 15 Alex Fiestas 2013-01-19 19:59:23 UTC
Added 4 dmesg logs with debug at 6 doing:

-Plugging HDMI output and waiting for a while
-Unplugging that HDMI output and waiting for a while
-Plugging HDMI and execute xrandr (this triggers the event)
-Unplugging HDMI and execute xrandr (triggers event as well)

If you need me to test anything more, please say so.
Comment 16 Chris Wilson 2013-05-01 15:24:58 UTC
Did this get fixed by

commit 202adf4b9f5957b26a1cb97267d78e0edb319c5e
Author: Daniel Vetter <daniel.vetter@ffwll.ch>
Date:   Fri Feb 22 00:53:04 2013 +0100

    drm/i915: Revert hdmi HDP pin checks
?
Comment 17 Daniel Vetter 2013-05-01 16:01:33 UTC
Unlikely, since nowadays the output poll work ignores connectors with the HPD poll flag set. I wonder whether we need to quirk something or whether we just get something wrong, since hpd looks pretty non-optional in the hdmi spec.
Comment 18 Alex Fiestas 2013-05-01 16:22:36 UTC
Just tested with Kernel 3.9 (the patch got into RC3, right?) and behavior is exactly the same.

Tomorrow I will be able to test it with 2 other systems, in the one I tried the GPU is 965GM
Comment 19 Alex Fiestas 2013-06-06 21:04:19 UTC
I have been doing some digging to try to figure out this bug. I have found something that perhaps will help you to find where the error is.

In i915_hpd_irq_setup when the encoder_list is iterated  none of the encoders has HPD_SDVO_B which apparently is where my HDMI port is hooked.

If I add:
hotplug_en |= SDVOB_HOTPLUG_INT_EN;

Then at least I can see some reaction from the drm driver in dmesg:
[drm:i965_irq_handler], hotplug event received, stat 0x00008040

Then, If in: i965_irq_handler I force hotplug_trigger
if (hotplug_trigger) {

I get this dmesg:
[drm:i965_irq_handler], not triggered
[drm:i915_hotplug_work_func], running encoder hotplug functions
[drm:intel_sdvo_debug_write], SDVOB: W: 0D 01 00                   (SDVO_CMD_SET_ACTIVE_HOT_PLUG)
[drm:intel_crt_detect], CRT not detected via hotplug
[drm:gmbus_xfer], GMBUS [i915 gmbus vga] NAK for addr: 0050 r(1)
[drm:drm_do_probe_ddc_edid], drm: skipping non-existent adapter i915 gmbus vga
[drm:intel_crt_get_edid], CRT GMBUS EDID read failed, retry using GPIO bit-banging
[drm:intel_gmbus_force_bit], enabling bit-banging on i915 gmbus vga. force bit now 1
[drm:drm_do_probe_ddc_edid], drm: skipping non-existent adapter i915 gmbus vga
[drm:intel_gmbus_force_bit], disabling bit-banging on i915 gmbus vga. force bit now 0
[drm:intel_crt_detect_ddc], CRT not detected via DDC:0x50 [no valid EDID found]
[drm:drm_helper_hpd_irq_event], [CONNECTOR:11:VGA-1] status updated from disconnected to disconnected.

Then in intel_setup_outputs I'm getting in:
if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
    DRM_DEBUG_KMS("probing SDVOB\n");
    found = intel_sdvo_init(dev, GEN3_SDVOB, true);
    found = false;
    if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
        DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
	intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
    }
}

If I force found to false, I'm getting an extra encoder with port HPD_PORT_B, but still it is not working.

Any pointers?

Thanks.
Comment 20 Daniel Vetter 2013-06-06 21:29:12 UTC
Note that your i965gm and i7 are completely different wrt hotplug handling for hdmi. I'll restrict this bug here for your i965gm machine, please file a new one for the i7.

Now can you please retest with latest drm-intel-nightly git branch from

http://cgit.freedesktop.org/~danvet/drm-intel/

We've massively overhauled the hotplug handling, so any older testing isn't really valid any more.
Comment 21 Alex Fiestas 2013-06-07 17:44:04 UTC
Does not seem to help, but maybe I'm doing something wrong because at least the code of i915_hpd_irq_setup looks the same.

Is there something I can check to make completely sure I'm using the right branch?

This is the last commit I have: 4f9e7cfb
Comment 22 Daniel Vetter 2013-06-07 19:04:09 UTC
It's the right commit. And I've just rechecked the documentation and the hotplug bits /should/ be the right ones. So I'm confused.

Can you please check whether SDVOB_HOTPLUG_INT_EN is set for your system with the new fancy code? If you can indeed get an interrupt this way, then we have a bug somewhere in our code ... When testing please make sure that whatever dmesg dumps does indeed correlate with you plugging/unplugging the cable. Unfortunately it wouldn't be the first case where the hpd stuff simply isn't wired up though.

The second hack with the intel_hdmi_init is broken. i965GM does not have native HDMI ports, but only supports hdmi through the multi-purpose sdvo encoder.
Comment 23 Alex Fiestas 2013-06-08 02:03:58 UTC
SDVOB_HOTPLUG_INT_EN is NOT set in i915_hpd_irq_setup, if I add it then I get the following on dmesg every time I plug the HDMI (but not when I unplug):

hotplug event received, stat 0x00008040

As in the current kernel, HPD_SDVO_B does not seem to be within the encoders.
Comment 24 Chris Wilson 2013-06-08 06:53:57 UTC
Can you attach a drm.debug=6 dmesg from boot with the latest kernel?
Comment 25 Alex Fiestas 2013-06-08 13:45:48 UTC
Created attachment 80528 [details]
dmesg drm.debug=6 drm-intel-nightly commit: 4f9e7cfb09a
Comment 26 Chris Wilson 2013-06-09 01:07:51 UTC
Today's silly code:

  if (intel_sdvo->hotplug_active)
                intel_encoder->hpd_pin = HPD_SDVO_B ? HPD_SDVO_B : HPD_SDVO_C;

and the hotplug_mask is dead.
Comment 27 Chris Wilson 2013-06-09 01:11:36 UTC
Also note that test to enable hpd_pin is before we query the hw and initialize hotplug_active. Mystery solved.
Comment 28 Alex Fiestas 2013-06-09 10:20:57 UTC
Tried removing the conditional but I guess it will take more than that :p
Comment 29 Daniel Vetter 2013-06-09 11:54:04 UTC
Created attachment 80562 [details] [review]
fix sdvo hotplug init sequence

This should help. Patch totally untested though ;-)
Comment 30 Alex Fiestas 2013-06-09 14:53:46 UTC
With the patch applied I'm getting one hotplug event, but only once (instead of every time I plug/unplug the hdmi)

[drm:i965_irq_handler], hotplug event received, stat 0x00008040

It is progress though :p
Comment 31 Daniel Vetter 2013-06-09 15:48:14 UTC
Hm, that's strange. Can you please add a bit of printk debugging on top to figure out where the interrput might get killed, like this:

diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index 0aa2ef0..ca937e3 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -2874,6 +2874,7 @@ static void i915_hpd_irq_setup(struct drm_device *dev)
 
        if (I915_HAS_HOTPLUG(dev)) {
                hotplug_en = I915_READ(PORT_HOTPLUG_EN);
+               printk("hotplug_en old 0x%08x\n", hotplug_en);
                hotplug_en &= ~HOTPLUG_INT_EN_MASK;
                /* Note HDMI and DP share hotplug bits */
                /* enable bits are the same for all generations */
@@ -2891,6 +2892,7 @@ static void i915_hpd_irq_setup(struct drm_device *dev)
 
                /* Ignore TV since it's buggy */
                I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
+               printk("hotplug_en new 0x%08x\n", hotplug_en);
        }
 }
 
Then please attach debug dmesg.
Comment 32 Alex Fiestas 2013-06-09 16:35:47 UTC
Created attachment 80572 [details]
dmesg with printk

Output of the new printk:
[   10.631841] hotplug_en old 0x00000000
[   10.631843] hotplug_en new 0x04000220

Additionally, in i965_irq_handler this conditional is failing:
if (hotplug_trigger) {

So dev_priv->hotplug_work is NOT getting Queued.

hotplug_status is 0x00008040
after the &
hotplug_trigger is 0

If I comment the conditional, then the _work function is executed but still nothing works :p
Comment 33 Daniel Vetter 2013-06-09 18:32:23 UTC
Created attachment 80578 [details] [review]
use gen3 hotplug register definitions

Docs are consistently of a differen opinion, but this wouldn't be the first time around docs are full of lies. Please test.
Comment 34 Alex Fiestas 2013-06-09 19:00:35 UTC
Finally ! it is working like a charm now !
Comment 35 Alex Fiestas 2013-06-09 19:02:28 UTC
Created attachment 80579 [details]
Patch needed to make it work

Attaching combined patch with the changes needed to make it work.

Can this patch be backported? would be really nice to push this patches into current distributions.

Thanks for everything!
Comment 36 Daniel Vetter 2013-06-09 19:24:06 UTC
Can you please plug/unplug your hdmi output a few times and attach dmesg? I just want to check that no other relevant hotplug bits are set (so if you bored you could filter right away for that message ;-).
Comment 37 Alex Fiestas 2013-06-09 20:44:02 UTC
Created attachment 80586 [details]
dmesg since hdmi plug/unplug
Comment 38 Daniel Vetter 2013-06-16 12:05:19 UTC
Gentle poke for Chris to corroborate this story about Bspec being wrong for SDVO hpd bits on i965g/gm ...
Comment 39 Chris Wilson 2013-06-18 16:18:07 UTC
No hotplug event before patch; after patch every single connector was reprobed by the kernel. I'll take the no hotplug event thanks.
Comment 40 Chris Wilson 2013-06-18 16:18:31 UTC
(965gm with sDVO DVI)
Comment 41 Alex Fiestas 2013-06-18 16:58:53 UTC
I don't understand last two comments, anything more I can test? I can call for tests within the KDE community if needed.
Comment 42 Chris Wilson 2013-06-18 19:50:55 UTC
(In reply to comment #41)
> I don't understand last two comments, anything more I can test? I can call
> for tests within the KDE community if needed.

Just confirmation to Daniel that the patch also do the right thing on my 965gm (i.e. hotplug interrupts are being only generated after the patch). The rest is a dig that the current behaviour of then reprobing every output after the hotplug notification is broken by design.
Comment 43 Alex Fiestas 2013-06-19 09:54:22 UTC
Oooh ok :p 

So, do you think guys this can be backported somehow? I'd really like current distros to apply needed patch. If it can't, will it make it to 3.10?
Comment 44 Daniel Vetter 2013-06-24 19:03:37 UTC
Created attachment 81358 [details] [review]
fixup sdvo hpd bits on gen4.0

Final (hopefully) patch that I've submitted for merging. Please check whether it still works on latest drm-intel-nightly, thanks.
Comment 45 Chris Wilson 2013-06-25 14:18:11 UTC
commit a4ad7c1a468f99e23da0376fa6e883a38ee08070
Author: Daniel Vetter <daniel.vetter@ffwll.ch>
Date:   Mon Jun 24 21:33:28 2013 +0200

    drm/i915: Fix up sdvo hpd pins for i965g/gm
    
    Bspec seems to be full of lies, at least it disagress with reality:
    Two systems corrobated that SDVO hpd bits are the same as on gen3.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.