8326900a311e4094ff626d0e1d3a9c113c5592a9
[sfrench/cifs-2.6.git] / drivers / gpu / drm / i915 / intel_hotplug.c
1 /*
2  * Copyright © 2015 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23
24 #include <linux/kernel.h>
25
26 #include <drm/drmP.h>
27 #include <drm/i915_drm.h>
28
29 #include "i915_drv.h"
30 #include "intel_drv.h"
31
32 /**
33  * DOC: Hotplug
34  *
35  * Simply put, hotplug occurs when a display is connected to or disconnected
36  * from the system. However, there may be adapters and docking stations and
37  * Display Port short pulses and MST devices involved, complicating matters.
38  *
39  * Hotplug in i915 is handled in many different levels of abstraction.
40  *
41  * The platform dependent interrupt handling code in i915_irq.c enables,
42  * disables, and does preliminary handling of the interrupts. The interrupt
43  * handlers gather the hotplug detect (HPD) information from relevant registers
44  * into a platform independent mask of hotplug pins that have fired.
45  *
46  * The platform independent interrupt handler intel_hpd_irq_handler() in
47  * intel_hotplug.c does hotplug irq storm detection and mitigation, and passes
48  * further processing to appropriate bottom halves (Display Port specific and
49  * regular hotplug).
50  *
51  * The Display Port work function i915_digport_work_func() calls into
52  * intel_dp_hpd_pulse() via hooks, which handles DP short pulses and DP MST long
53  * pulses, with failures and non-MST long pulses triggering regular hotplug
54  * processing on the connector.
55  *
56  * The regular hotplug work function i915_hotplug_work_func() calls connector
57  * detect hooks, and, if connector status changes, triggers sending of hotplug
58  * uevent to userspace via drm_kms_helper_hotplug_event().
59  *
60  * Finally, the userspace is responsible for triggering a modeset upon receiving
61  * the hotplug uevent, disabling or enabling the crtc as needed.
62  *
63  * The hotplug interrupt storm detection and mitigation code keeps track of the
64  * number of interrupts per hotplug pin per a period of time, and if the number
65  * of interrupts exceeds a certain threshold, the interrupt is disabled for a
66  * while before being re-enabled. The intention is to mitigate issues raising
67  * from broken hardware triggering massive amounts of interrupts and grinding
68  * the system to a halt.
69  *
70  * Current implementation expects that hotplug interrupt storm will not be
71  * seen when display port sink is connected, hence on platforms whose DP
72  * callback is handled by i915_digport_work_func reenabling of hpd is not
73  * performed (it was never expected to be disabled in the first place ;) )
74  * this is specific to DP sinks handled by this routine and any other display
75  * such as HDMI or DVI enabled on the same port will have proper logic since
76  * it will use i915_hotplug_work_func where this logic is handled.
77  */
78
79 /**
80  * intel_hpd_pin_default - return default pin associated with certain port.
81  * @dev_priv: private driver data pointer
82  * @port: the hpd port to get associated pin
83  *
84  * It is only valid and used by digital port encoder.
85  *
86  * Return pin that is associatade with @port and HDP_NONE if no pin is
87  * hard associated with that @port.
88  */
89 enum hpd_pin intel_hpd_pin_default(struct drm_i915_private *dev_priv,
90                                    enum port port)
91 {
92         switch (port) {
93         case PORT_A:
94                 return HPD_PORT_A;
95         case PORT_B:
96                 return HPD_PORT_B;
97         case PORT_C:
98                 return HPD_PORT_C;
99         case PORT_D:
100                 return HPD_PORT_D;
101         case PORT_E:
102                 return HPD_PORT_E;
103         case PORT_F:
104                 if (IS_CNL_WITH_PORT_F(dev_priv))
105                         return HPD_PORT_E;
106                 return HPD_PORT_F;
107         default:
108                 MISSING_CASE(port);
109                 return HPD_NONE;
110         }
111 }
112
113 #define HPD_STORM_DETECT_PERIOD         1000
114 #define HPD_STORM_REENABLE_DELAY        (2 * 60 * 1000)
115
116 /**
117  * intel_hpd_irq_storm_detect - gather stats and detect HPD irq storm on a pin
118  * @dev_priv: private driver data pointer
119  * @pin: the pin to gather stats on
120  *
121  * Gather stats about HPD irqs from the specified @pin, and detect irq
122  * storms. Only the pin specific stats and state are changed, the caller is
123  * responsible for further action.
124  *
125  * The number of irqs that are allowed within @HPD_STORM_DETECT_PERIOD is
126  * stored in @dev_priv->hotplug.hpd_storm_threshold which defaults to
127  * @HPD_STORM_DEFAULT_THRESHOLD. If this threshold is exceeded, it's
128  * considered an irq storm and the irq state is set to @HPD_MARK_DISABLED.
129  *
130  * The HPD threshold can be controlled through i915_hpd_storm_ctl in debugfs,
131  * and should only be adjusted for automated hotplug testing.
132  *
133  * Return true if an irq storm was detected on @pin.
134  */
135 static bool intel_hpd_irq_storm_detect(struct drm_i915_private *dev_priv,
136                                        enum hpd_pin pin)
137 {
138         unsigned long start = dev_priv->hotplug.stats[pin].last_jiffies;
139         unsigned long end = start + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD);
140         const int threshold = dev_priv->hotplug.hpd_storm_threshold;
141         bool storm = false;
142
143         if (!time_in_range(jiffies, start, end)) {
144                 dev_priv->hotplug.stats[pin].last_jiffies = jiffies;
145                 dev_priv->hotplug.stats[pin].count = 0;
146                 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", pin);
147         } else if (dev_priv->hotplug.stats[pin].count > threshold &&
148                    threshold) {
149                 dev_priv->hotplug.stats[pin].state = HPD_MARK_DISABLED;
150                 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", pin);
151                 storm = true;
152         } else {
153                 dev_priv->hotplug.stats[pin].count++;
154                 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", pin,
155                               dev_priv->hotplug.stats[pin].count);
156         }
157
158         return storm;
159 }
160
161 static void intel_hpd_irq_storm_disable(struct drm_i915_private *dev_priv)
162 {
163         struct drm_device *dev = &dev_priv->drm;
164         struct intel_connector *intel_connector;
165         struct intel_encoder *intel_encoder;
166         struct drm_connector *connector;
167         struct drm_connector_list_iter conn_iter;
168         enum hpd_pin pin;
169         bool hpd_disabled = false;
170
171         lockdep_assert_held(&dev_priv->irq_lock);
172
173         drm_connector_list_iter_begin(dev, &conn_iter);
174         drm_for_each_connector_iter(connector, &conn_iter) {
175                 if (connector->polled != DRM_CONNECTOR_POLL_HPD)
176                         continue;
177
178                 intel_connector = to_intel_connector(connector);
179                 intel_encoder = intel_connector->encoder;
180                 if (!intel_encoder)
181                         continue;
182
183                 pin = intel_encoder->hpd_pin;
184                 if (pin == HPD_NONE ||
185                     dev_priv->hotplug.stats[pin].state != HPD_MARK_DISABLED)
186                         continue;
187
188                 DRM_INFO("HPD interrupt storm detected on connector %s: "
189                          "switching from hotplug detection to polling\n",
190                          connector->name);
191
192                 dev_priv->hotplug.stats[pin].state = HPD_DISABLED;
193                 connector->polled = DRM_CONNECTOR_POLL_CONNECT
194                         | DRM_CONNECTOR_POLL_DISCONNECT;
195                 hpd_disabled = true;
196         }
197         drm_connector_list_iter_end(&conn_iter);
198
199         /* Enable polling and queue hotplug re-enabling. */
200         if (hpd_disabled) {
201                 drm_kms_helper_poll_enable(dev);
202                 mod_delayed_work(system_wq, &dev_priv->hotplug.reenable_work,
203                                  msecs_to_jiffies(HPD_STORM_REENABLE_DELAY));
204         }
205 }
206
207 static void intel_hpd_irq_storm_reenable_work(struct work_struct *work)
208 {
209         struct drm_i915_private *dev_priv =
210                 container_of(work, typeof(*dev_priv),
211                              hotplug.reenable_work.work);
212         struct drm_device *dev = &dev_priv->drm;
213         enum hpd_pin pin;
214
215         intel_runtime_pm_get(dev_priv);
216
217         spin_lock_irq(&dev_priv->irq_lock);
218         for_each_hpd_pin(pin) {
219                 struct drm_connector *connector;
220                 struct drm_connector_list_iter conn_iter;
221
222                 if (dev_priv->hotplug.stats[pin].state != HPD_DISABLED)
223                         continue;
224
225                 dev_priv->hotplug.stats[pin].state = HPD_ENABLED;
226
227                 drm_connector_list_iter_begin(dev, &conn_iter);
228                 drm_for_each_connector_iter(connector, &conn_iter) {
229                         struct intel_connector *intel_connector = to_intel_connector(connector);
230
231                         /* Don't check MST ports, they don't have pins */
232                         if (!intel_connector->mst_port &&
233                             intel_connector->encoder->hpd_pin == pin) {
234                                 if (connector->polled != intel_connector->polled)
235                                         DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
236                                                          connector->name);
237                                 connector->polled = intel_connector->polled;
238                                 if (!connector->polled)
239                                         connector->polled = DRM_CONNECTOR_POLL_HPD;
240                         }
241                 }
242                 drm_connector_list_iter_end(&conn_iter);
243         }
244         if (dev_priv->display_irqs_enabled && dev_priv->display.hpd_irq_setup)
245                 dev_priv->display.hpd_irq_setup(dev_priv);
246         spin_unlock_irq(&dev_priv->irq_lock);
247
248         intel_runtime_pm_put(dev_priv);
249 }
250
251 bool intel_encoder_hotplug(struct intel_encoder *encoder,
252                            struct intel_connector *connector)
253 {
254         struct drm_device *dev = connector->base.dev;
255         enum drm_connector_status old_status;
256
257         WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
258         old_status = connector->base.status;
259
260         connector->base.status =
261                 drm_helper_probe_detect(&connector->base, NULL, false);
262
263         if (old_status == connector->base.status)
264                 return false;
265
266         DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
267                       connector->base.base.id,
268                       connector->base.name,
269                       drm_get_connector_status_name(old_status),
270                       drm_get_connector_status_name(connector->base.status));
271
272         return true;
273 }
274
275 static bool intel_encoder_has_hpd_pulse(struct intel_encoder *encoder)
276 {
277         return intel_encoder_is_dig_port(encoder) &&
278                 enc_to_dig_port(&encoder->base)->hpd_pulse != NULL;
279 }
280
281 static void i915_digport_work_func(struct work_struct *work)
282 {
283         struct drm_i915_private *dev_priv =
284                 container_of(work, struct drm_i915_private, hotplug.dig_port_work);
285         u32 long_port_mask, short_port_mask;
286         struct intel_encoder *encoder;
287         u32 old_bits = 0;
288
289         spin_lock_irq(&dev_priv->irq_lock);
290         long_port_mask = dev_priv->hotplug.long_port_mask;
291         dev_priv->hotplug.long_port_mask = 0;
292         short_port_mask = dev_priv->hotplug.short_port_mask;
293         dev_priv->hotplug.short_port_mask = 0;
294         spin_unlock_irq(&dev_priv->irq_lock);
295
296         for_each_intel_encoder(&dev_priv->drm, encoder) {
297                 struct intel_digital_port *dig_port;
298                 enum port port = encoder->port;
299                 bool long_hpd, short_hpd;
300                 enum irqreturn ret;
301
302                 if (!intel_encoder_has_hpd_pulse(encoder))
303                         continue;
304
305                 long_hpd = long_port_mask & BIT(port);
306                 short_hpd = short_port_mask & BIT(port);
307
308                 if (!long_hpd && !short_hpd)
309                         continue;
310
311                 dig_port = enc_to_dig_port(&encoder->base);
312
313                 ret = dig_port->hpd_pulse(dig_port, long_hpd);
314                 if (ret == IRQ_NONE) {
315                         /* fall back to old school hpd */
316                         old_bits |= BIT(encoder->hpd_pin);
317                 }
318         }
319
320         if (old_bits) {
321                 spin_lock_irq(&dev_priv->irq_lock);
322                 dev_priv->hotplug.event_bits |= old_bits;
323                 spin_unlock_irq(&dev_priv->irq_lock);
324                 schedule_work(&dev_priv->hotplug.hotplug_work);
325         }
326 }
327
328 /*
329  * Handle hotplug events outside the interrupt handler proper.
330  */
331 static void i915_hotplug_work_func(struct work_struct *work)
332 {
333         struct drm_i915_private *dev_priv =
334                 container_of(work, struct drm_i915_private, hotplug.hotplug_work);
335         struct drm_device *dev = &dev_priv->drm;
336         struct intel_connector *intel_connector;
337         struct intel_encoder *intel_encoder;
338         struct drm_connector *connector;
339         struct drm_connector_list_iter conn_iter;
340         bool changed = false;
341         u32 hpd_event_bits;
342
343         mutex_lock(&dev->mode_config.mutex);
344         DRM_DEBUG_KMS("running encoder hotplug functions\n");
345
346         spin_lock_irq(&dev_priv->irq_lock);
347
348         hpd_event_bits = dev_priv->hotplug.event_bits;
349         dev_priv->hotplug.event_bits = 0;
350
351         /* Disable hotplug on connectors that hit an irq storm. */
352         intel_hpd_irq_storm_disable(dev_priv);
353
354         spin_unlock_irq(&dev_priv->irq_lock);
355
356         drm_connector_list_iter_begin(dev, &conn_iter);
357         drm_for_each_connector_iter(connector, &conn_iter) {
358                 intel_connector = to_intel_connector(connector);
359                 if (!intel_connector->encoder)
360                         continue;
361                 intel_encoder = intel_connector->encoder;
362                 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
363                         DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
364                                       connector->name, intel_encoder->hpd_pin);
365
366                         changed |= intel_encoder->hotplug(intel_encoder,
367                                                           intel_connector);
368                 }
369         }
370         drm_connector_list_iter_end(&conn_iter);
371         mutex_unlock(&dev->mode_config.mutex);
372
373         if (changed)
374                 drm_kms_helper_hotplug_event(dev);
375 }
376
377
378 /**
379  * intel_hpd_irq_handler - main hotplug irq handler
380  * @dev_priv: drm_i915_private
381  * @pin_mask: a mask of hpd pins that have triggered the irq
382  * @long_mask: a mask of hpd pins that may be long hpd pulses
383  *
384  * This is the main hotplug irq handler for all platforms. The platform specific
385  * irq handlers call the platform specific hotplug irq handlers, which read and
386  * decode the appropriate registers into bitmasks about hpd pins that have
387  * triggered (@pin_mask), and which of those pins may be long pulses
388  * (@long_mask). The @long_mask is ignored if the port corresponding to the pin
389  * is not a digital port.
390  *
391  * Here, we do hotplug irq storm detection and mitigation, and pass further
392  * processing to appropriate bottom halves.
393  */
394 void intel_hpd_irq_handler(struct drm_i915_private *dev_priv,
395                            u32 pin_mask, u32 long_mask)
396 {
397         struct intel_encoder *encoder;
398         bool storm_detected = false;
399         bool queue_dig = false, queue_hp = false;
400
401         if (!pin_mask)
402                 return;
403
404         spin_lock(&dev_priv->irq_lock);
405         for_each_intel_encoder(&dev_priv->drm, encoder) {
406                 enum hpd_pin pin = encoder->hpd_pin;
407                 bool has_hpd_pulse = intel_encoder_has_hpd_pulse(encoder);
408
409                 if (!(BIT(pin) & pin_mask))
410                         continue;
411
412                 if (has_hpd_pulse) {
413                         bool long_hpd = long_mask & BIT(pin);
414                         enum port port = encoder->port;
415
416                         DRM_DEBUG_DRIVER("digital hpd port %c - %s\n", port_name(port),
417                                          long_hpd ? "long" : "short");
418                         /*
419                          * For long HPD pulses we want to have the digital queue happen,
420                          * but we still want HPD storm detection to function.
421                          */
422                         queue_dig = true;
423                         if (long_hpd) {
424                                 dev_priv->hotplug.long_port_mask |= (1 << port);
425                         } else {
426                                 /* for short HPD just trigger the digital queue */
427                                 dev_priv->hotplug.short_port_mask |= (1 << port);
428                                 continue;
429                         }
430                 }
431
432                 if (dev_priv->hotplug.stats[pin].state == HPD_DISABLED) {
433                         /*
434                          * On GMCH platforms the interrupt mask bits only
435                          * prevent irq generation, not the setting of the
436                          * hotplug bits itself. So only WARN about unexpected
437                          * interrupts on saner platforms.
438                          */
439                         WARN_ONCE(!HAS_GMCH_DISPLAY(dev_priv),
440                                   "Received HPD interrupt on pin %d although disabled\n", pin);
441                         continue;
442                 }
443
444                 if (dev_priv->hotplug.stats[pin].state != HPD_ENABLED)
445                         continue;
446
447                 if (!has_hpd_pulse) {
448                         dev_priv->hotplug.event_bits |= BIT(pin);
449                         queue_hp = true;
450                 }
451
452                 if (intel_hpd_irq_storm_detect(dev_priv, pin)) {
453                         dev_priv->hotplug.event_bits &= ~BIT(pin);
454                         storm_detected = true;
455                 }
456         }
457
458         if (storm_detected && dev_priv->display_irqs_enabled)
459                 dev_priv->display.hpd_irq_setup(dev_priv);
460         spin_unlock(&dev_priv->irq_lock);
461
462         /*
463          * Our hotplug handler can grab modeset locks (by calling down into the
464          * fb helpers). Hence it must not be run on our own dev-priv->wq work
465          * queue for otherwise the flush_work in the pageflip code will
466          * deadlock.
467          */
468         if (queue_dig)
469                 queue_work(dev_priv->hotplug.dp_wq, &dev_priv->hotplug.dig_port_work);
470         if (queue_hp)
471                 schedule_work(&dev_priv->hotplug.hotplug_work);
472 }
473
474 /**
475  * intel_hpd_init - initializes and enables hpd support
476  * @dev_priv: i915 device instance
477  *
478  * This function enables the hotplug support. It requires that interrupts have
479  * already been enabled with intel_irq_init_hw(). From this point on hotplug and
480  * poll request can run concurrently to other code, so locking rules must be
481  * obeyed.
482  *
483  * This is a separate step from interrupt enabling to simplify the locking rules
484  * in the driver load and resume code.
485  *
486  * Also see: intel_hpd_poll_init(), which enables connector polling
487  */
488 void intel_hpd_init(struct drm_i915_private *dev_priv)
489 {
490         int i;
491
492         for_each_hpd_pin(i) {
493                 dev_priv->hotplug.stats[i].count = 0;
494                 dev_priv->hotplug.stats[i].state = HPD_ENABLED;
495         }
496
497         WRITE_ONCE(dev_priv->hotplug.poll_enabled, false);
498         schedule_work(&dev_priv->hotplug.poll_init_work);
499
500         /*
501          * Interrupt setup is already guaranteed to be single-threaded, this is
502          * just to make the assert_spin_locked checks happy.
503          */
504         if (dev_priv->display_irqs_enabled && dev_priv->display.hpd_irq_setup) {
505                 spin_lock_irq(&dev_priv->irq_lock);
506                 if (dev_priv->display_irqs_enabled)
507                         dev_priv->display.hpd_irq_setup(dev_priv);
508                 spin_unlock_irq(&dev_priv->irq_lock);
509         }
510 }
511
512 static void i915_hpd_poll_init_work(struct work_struct *work)
513 {
514         struct drm_i915_private *dev_priv =
515                 container_of(work, struct drm_i915_private,
516                              hotplug.poll_init_work);
517         struct drm_device *dev = &dev_priv->drm;
518         struct drm_connector *connector;
519         struct drm_connector_list_iter conn_iter;
520         bool enabled;
521
522         mutex_lock(&dev->mode_config.mutex);
523
524         enabled = READ_ONCE(dev_priv->hotplug.poll_enabled);
525
526         drm_connector_list_iter_begin(dev, &conn_iter);
527         drm_for_each_connector_iter(connector, &conn_iter) {
528                 struct intel_connector *intel_connector =
529                         to_intel_connector(connector);
530                 connector->polled = intel_connector->polled;
531
532                 /* MST has a dynamic intel_connector->encoder and it's reprobing
533                  * is all handled by the MST helpers. */
534                 if (intel_connector->mst_port)
535                         continue;
536
537                 if (!connector->polled && I915_HAS_HOTPLUG(dev_priv) &&
538                     intel_connector->encoder->hpd_pin > HPD_NONE) {
539                         connector->polled = enabled ?
540                                 DRM_CONNECTOR_POLL_CONNECT |
541                                 DRM_CONNECTOR_POLL_DISCONNECT :
542                                 DRM_CONNECTOR_POLL_HPD;
543                 }
544         }
545         drm_connector_list_iter_end(&conn_iter);
546
547         if (enabled)
548                 drm_kms_helper_poll_enable(dev);
549
550         mutex_unlock(&dev->mode_config.mutex);
551
552         /*
553          * We might have missed any hotplugs that happened while we were
554          * in the middle of disabling polling
555          */
556         if (!enabled)
557                 drm_helper_hpd_irq_event(dev);
558 }
559
560 /**
561  * intel_hpd_poll_init - enables/disables polling for connectors with hpd
562  * @dev_priv: i915 device instance
563  *
564  * This function enables polling for all connectors, regardless of whether or
565  * not they support hotplug detection. Under certain conditions HPD may not be
566  * functional. On most Intel GPUs, this happens when we enter runtime suspend.
567  * On Valleyview and Cherryview systems, this also happens when we shut off all
568  * of the powerwells.
569  *
570  * Since this function can get called in contexts where we're already holding
571  * dev->mode_config.mutex, we do the actual hotplug enabling in a seperate
572  * worker.
573  *
574  * Also see: intel_hpd_init(), which restores hpd handling.
575  */
576 void intel_hpd_poll_init(struct drm_i915_private *dev_priv)
577 {
578         WRITE_ONCE(dev_priv->hotplug.poll_enabled, true);
579
580         /*
581          * We might already be holding dev->mode_config.mutex, so do this in a
582          * seperate worker
583          * As well, there's no issue if we race here since we always reschedule
584          * this worker anyway
585          */
586         schedule_work(&dev_priv->hotplug.poll_init_work);
587 }
588
589 void intel_hpd_init_work(struct drm_i915_private *dev_priv)
590 {
591         INIT_WORK(&dev_priv->hotplug.hotplug_work, i915_hotplug_work_func);
592         INIT_WORK(&dev_priv->hotplug.dig_port_work, i915_digport_work_func);
593         INIT_WORK(&dev_priv->hotplug.poll_init_work, i915_hpd_poll_init_work);
594         INIT_DELAYED_WORK(&dev_priv->hotplug.reenable_work,
595                           intel_hpd_irq_storm_reenable_work);
596 }
597
598 void intel_hpd_cancel_work(struct drm_i915_private *dev_priv)
599 {
600         spin_lock_irq(&dev_priv->irq_lock);
601
602         dev_priv->hotplug.long_port_mask = 0;
603         dev_priv->hotplug.short_port_mask = 0;
604         dev_priv->hotplug.event_bits = 0;
605
606         spin_unlock_irq(&dev_priv->irq_lock);
607
608         cancel_work_sync(&dev_priv->hotplug.dig_port_work);
609         cancel_work_sync(&dev_priv->hotplug.hotplug_work);
610         cancel_work_sync(&dev_priv->hotplug.poll_init_work);
611         cancel_delayed_work_sync(&dev_priv->hotplug.reenable_work);
612 }
613
614 bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
615 {
616         bool ret = false;
617
618         if (pin == HPD_NONE)
619                 return false;
620
621         spin_lock_irq(&dev_priv->irq_lock);
622         if (dev_priv->hotplug.stats[pin].state == HPD_ENABLED) {
623                 dev_priv->hotplug.stats[pin].state = HPD_DISABLED;
624                 ret = true;
625         }
626         spin_unlock_irq(&dev_priv->irq_lock);
627
628         return ret;
629 }
630
631 void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
632 {
633         if (pin == HPD_NONE)
634                 return;
635
636         spin_lock_irq(&dev_priv->irq_lock);
637         dev_priv->hotplug.stats[pin].state = HPD_ENABLED;
638         spin_unlock_irq(&dev_priv->irq_lock);
639 }