2 * Copyright © 2015 Intel Corporation
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:
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
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
24 #include <linux/kernel.h>
27 #include "intel_display_types.h"
28 #include "intel_hotplug.h"
33 * Simply put, hotplug occurs when a display is connected to or disconnected
34 * from the system. However, there may be adapters and docking stations and
35 * Display Port short pulses and MST devices involved, complicating matters.
37 * Hotplug in i915 is handled in many different levels of abstraction.
39 * The platform dependent interrupt handling code in i915_irq.c enables,
40 * disables, and does preliminary handling of the interrupts. The interrupt
41 * handlers gather the hotplug detect (HPD) information from relevant registers
42 * into a platform independent mask of hotplug pins that have fired.
44 * The platform independent interrupt handler intel_hpd_irq_handler() in
45 * intel_hotplug.c does hotplug irq storm detection and mitigation, and passes
46 * further processing to appropriate bottom halves (Display Port specific and
49 * The Display Port work function i915_digport_work_func() calls into
50 * intel_dp_hpd_pulse() via hooks, which handles DP short pulses and DP MST long
51 * pulses, with failures and non-MST long pulses triggering regular hotplug
52 * processing on the connector.
54 * The regular hotplug work function i915_hotplug_work_func() calls connector
55 * detect hooks, and, if connector status changes, triggers sending of hotplug
56 * uevent to userspace via drm_kms_helper_hotplug_event().
58 * Finally, the userspace is responsible for triggering a modeset upon receiving
59 * the hotplug uevent, disabling or enabling the crtc as needed.
61 * The hotplug interrupt storm detection and mitigation code keeps track of the
62 * number of interrupts per hotplug pin per a period of time, and if the number
63 * of interrupts exceeds a certain threshold, the interrupt is disabled for a
64 * while before being re-enabled. The intention is to mitigate issues raising
65 * from broken hardware triggering massive amounts of interrupts and grinding
66 * the system to a halt.
68 * Current implementation expects that hotplug interrupt storm will not be
69 * seen when display port sink is connected, hence on platforms whose DP
70 * callback is handled by i915_digport_work_func reenabling of hpd is not
71 * performed (it was never expected to be disabled in the first place ;) )
72 * this is specific to DP sinks handled by this routine and any other display
73 * such as HDMI or DVI enabled on the same port will have proper logic since
74 * it will use i915_hotplug_work_func where this logic is handled.
78 * intel_hpd_pin_default - return default pin associated with certain port.
79 * @dev_priv: private driver data pointer
80 * @port: the hpd port to get associated pin
82 * It is only valid and used by digital port encoder.
84 * Return pin that is associatade with @port.
86 enum hpd_pin
intel_hpd_pin_default(struct drm_i915_private
*dev_priv
,
89 return HPD_PORT_A
+ port
- PORT_A
;
92 #define HPD_STORM_DETECT_PERIOD 1000
93 #define HPD_STORM_REENABLE_DELAY (2 * 60 * 1000)
94 #define HPD_RETRY_DELAY 1000
97 intel_connector_hpd_pin(struct intel_connector
*connector
)
99 struct intel_encoder
*encoder
= intel_attached_encoder(connector
);
102 * MST connectors get their encoder attached dynamically
103 * so need to make sure we have an encoder here. But since
104 * MST encoders have their hpd_pin set to HPD_NONE we don't
105 * have to special case them beyond that.
107 return encoder
? encoder
->hpd_pin
: HPD_NONE
;
111 * intel_hpd_irq_storm_detect - gather stats and detect HPD IRQ storm on a pin
112 * @dev_priv: private driver data pointer
113 * @pin: the pin to gather stats on
114 * @long_hpd: whether the HPD IRQ was long or short
116 * Gather stats about HPD IRQs from the specified @pin, and detect IRQ
117 * storms. Only the pin specific stats and state are changed, the caller is
118 * responsible for further action.
120 * The number of IRQs that are allowed within @HPD_STORM_DETECT_PERIOD is
121 * stored in @dev_priv->hotplug.hpd_storm_threshold which defaults to
122 * @HPD_STORM_DEFAULT_THRESHOLD. Long IRQs count as +10 to this threshold, and
123 * short IRQs count as +1. If this threshold is exceeded, it's considered an
124 * IRQ storm and the IRQ state is set to @HPD_MARK_DISABLED.
126 * By default, most systems will only count long IRQs towards
127 * &dev_priv->hotplug.hpd_storm_threshold. However, some older systems also
128 * suffer from short IRQ storms and must also track these. Because short IRQ
129 * storms are naturally caused by sideband interactions with DP MST devices,
130 * short IRQ detection is only enabled for systems without DP MST support.
131 * Systems which are new enough to support DP MST are far less likely to
132 * suffer from IRQ storms at all, so this is fine.
134 * The HPD threshold can be controlled through i915_hpd_storm_ctl in debugfs,
135 * and should only be adjusted for automated hotplug testing.
137 * Return true if an IRQ storm was detected on @pin.
139 static bool intel_hpd_irq_storm_detect(struct drm_i915_private
*dev_priv
,
140 enum hpd_pin pin
, bool long_hpd
)
142 struct i915_hotplug
*hpd
= &dev_priv
->hotplug
;
143 unsigned long start
= hpd
->stats
[pin
].last_jiffies
;
144 unsigned long end
= start
+ msecs_to_jiffies(HPD_STORM_DETECT_PERIOD
);
145 const int increment
= long_hpd
? 10 : 1;
146 const int threshold
= hpd
->hpd_storm_threshold
;
150 (!long_hpd
&& !dev_priv
->hotplug
.hpd_short_storm_enabled
))
153 if (!time_in_range(jiffies
, start
, end
)) {
154 hpd
->stats
[pin
].last_jiffies
= jiffies
;
155 hpd
->stats
[pin
].count
= 0;
158 hpd
->stats
[pin
].count
+= increment
;
159 if (hpd
->stats
[pin
].count
> threshold
) {
160 hpd
->stats
[pin
].state
= HPD_MARK_DISABLED
;
161 drm_dbg_kms(&dev_priv
->drm
,
162 "HPD interrupt storm detected on PIN %d\n", pin
);
165 drm_dbg_kms(&dev_priv
->drm
,
166 "Received HPD interrupt on PIN %d - cnt: %d\n",
168 hpd
->stats
[pin
].count
);
175 intel_hpd_irq_storm_switch_to_polling(struct drm_i915_private
*dev_priv
)
177 struct drm_device
*dev
= &dev_priv
->drm
;
178 struct drm_connector_list_iter conn_iter
;
179 struct intel_connector
*connector
;
180 bool hpd_disabled
= false;
182 lockdep_assert_held(&dev_priv
->irq_lock
);
184 drm_connector_list_iter_begin(dev
, &conn_iter
);
185 for_each_intel_connector_iter(connector
, &conn_iter
) {
188 if (connector
->base
.polled
!= DRM_CONNECTOR_POLL_HPD
)
191 pin
= intel_connector_hpd_pin(connector
);
192 if (pin
== HPD_NONE
||
193 dev_priv
->hotplug
.stats
[pin
].state
!= HPD_MARK_DISABLED
)
196 drm_info(&dev_priv
->drm
,
197 "HPD interrupt storm detected on connector %s: "
198 "switching from hotplug detection to polling\n",
199 connector
->base
.name
);
201 dev_priv
->hotplug
.stats
[pin
].state
= HPD_DISABLED
;
202 connector
->base
.polled
= DRM_CONNECTOR_POLL_CONNECT
|
203 DRM_CONNECTOR_POLL_DISCONNECT
;
206 drm_connector_list_iter_end(&conn_iter
);
208 /* Enable polling and queue hotplug re-enabling. */
210 drm_kms_helper_poll_enable(dev
);
211 mod_delayed_work(system_wq
, &dev_priv
->hotplug
.reenable_work
,
212 msecs_to_jiffies(HPD_STORM_REENABLE_DELAY
));
216 static void intel_hpd_irq_setup(struct drm_i915_private
*i915
)
218 if (i915
->display_irqs_enabled
&& i915
->display
.hpd_irq_setup
)
219 i915
->display
.hpd_irq_setup(i915
);
222 static void intel_hpd_irq_storm_reenable_work(struct work_struct
*work
)
224 struct drm_i915_private
*dev_priv
=
225 container_of(work
, typeof(*dev_priv
),
226 hotplug
.reenable_work
.work
);
227 struct drm_device
*dev
= &dev_priv
->drm
;
228 struct drm_connector_list_iter conn_iter
;
229 struct intel_connector
*connector
;
230 intel_wakeref_t wakeref
;
233 wakeref
= intel_runtime_pm_get(&dev_priv
->runtime_pm
);
235 spin_lock_irq(&dev_priv
->irq_lock
);
237 drm_connector_list_iter_begin(dev
, &conn_iter
);
238 for_each_intel_connector_iter(connector
, &conn_iter
) {
239 pin
= intel_connector_hpd_pin(connector
);
240 if (pin
== HPD_NONE
||
241 dev_priv
->hotplug
.stats
[pin
].state
!= HPD_DISABLED
)
244 if (connector
->base
.polled
!= connector
->polled
)
245 drm_dbg(&dev_priv
->drm
,
246 "Reenabling HPD on connector %s\n",
247 connector
->base
.name
);
248 connector
->base
.polled
= connector
->polled
;
250 drm_connector_list_iter_end(&conn_iter
);
252 for_each_hpd_pin(pin
) {
253 if (dev_priv
->hotplug
.stats
[pin
].state
== HPD_DISABLED
)
254 dev_priv
->hotplug
.stats
[pin
].state
= HPD_ENABLED
;
257 intel_hpd_irq_setup(dev_priv
);
259 spin_unlock_irq(&dev_priv
->irq_lock
);
261 intel_runtime_pm_put(&dev_priv
->runtime_pm
, wakeref
);
264 enum intel_hotplug_state
265 intel_encoder_hotplug(struct intel_encoder
*encoder
,
266 struct intel_connector
*connector
)
268 struct drm_device
*dev
= connector
->base
.dev
;
269 enum drm_connector_status old_status
;
270 u64 old_epoch_counter
;
273 drm_WARN_ON(dev
, !mutex_is_locked(&dev
->mode_config
.mutex
));
274 old_status
= connector
->base
.status
;
275 old_epoch_counter
= connector
->base
.epoch_counter
;
277 connector
->base
.status
=
278 drm_helper_probe_detect(&connector
->base
, NULL
, false);
280 if (old_epoch_counter
!= connector
->base
.epoch_counter
)
284 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s (epoch counter %llu->%llu)\n",
285 connector
->base
.base
.id
,
286 connector
->base
.name
,
287 drm_get_connector_status_name(old_status
),
288 drm_get_connector_status_name(connector
->base
.status
),
290 connector
->base
.epoch_counter
);
291 return INTEL_HOTPLUG_CHANGED
;
293 return INTEL_HOTPLUG_UNCHANGED
;
296 static bool intel_encoder_has_hpd_pulse(struct intel_encoder
*encoder
)
298 return intel_encoder_is_dig_port(encoder
) &&
299 enc_to_dig_port(encoder
)->hpd_pulse
!= NULL
;
302 static void i915_digport_work_func(struct work_struct
*work
)
304 struct drm_i915_private
*dev_priv
=
305 container_of(work
, struct drm_i915_private
, hotplug
.dig_port_work
);
306 u32 long_port_mask
, short_port_mask
;
307 struct intel_encoder
*encoder
;
310 spin_lock_irq(&dev_priv
->irq_lock
);
311 long_port_mask
= dev_priv
->hotplug
.long_port_mask
;
312 dev_priv
->hotplug
.long_port_mask
= 0;
313 short_port_mask
= dev_priv
->hotplug
.short_port_mask
;
314 dev_priv
->hotplug
.short_port_mask
= 0;
315 spin_unlock_irq(&dev_priv
->irq_lock
);
317 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
318 struct intel_digital_port
*dig_port
;
319 enum port port
= encoder
->port
;
320 bool long_hpd
, short_hpd
;
323 if (!intel_encoder_has_hpd_pulse(encoder
))
326 long_hpd
= long_port_mask
& BIT(port
);
327 short_hpd
= short_port_mask
& BIT(port
);
329 if (!long_hpd
&& !short_hpd
)
332 dig_port
= enc_to_dig_port(encoder
);
334 ret
= dig_port
->hpd_pulse(dig_port
, long_hpd
);
335 if (ret
== IRQ_NONE
) {
336 /* fall back to old school hpd */
337 old_bits
|= BIT(encoder
->hpd_pin
);
342 spin_lock_irq(&dev_priv
->irq_lock
);
343 dev_priv
->hotplug
.event_bits
|= old_bits
;
344 spin_unlock_irq(&dev_priv
->irq_lock
);
345 queue_delayed_work(system_wq
, &dev_priv
->hotplug
.hotplug_work
, 0);
350 * intel_hpd_trigger_irq - trigger an hpd irq event for a port
351 * @dig_port: digital port
353 * Trigger an HPD interrupt event for the given port, emulating a short pulse
354 * generated by the sink, and schedule the dig port work to handle it.
356 void intel_hpd_trigger_irq(struct intel_digital_port
*dig_port
)
358 struct drm_i915_private
*i915
= to_i915(dig_port
->base
.base
.dev
);
360 spin_lock_irq(&i915
->irq_lock
);
361 i915
->hotplug
.short_port_mask
|= BIT(dig_port
->base
.port
);
362 spin_unlock_irq(&i915
->irq_lock
);
364 queue_work(i915
->hotplug
.dp_wq
, &i915
->hotplug
.dig_port_work
);
368 * Handle hotplug events outside the interrupt handler proper.
370 static void i915_hotplug_work_func(struct work_struct
*work
)
372 struct drm_i915_private
*dev_priv
=
373 container_of(work
, struct drm_i915_private
,
374 hotplug
.hotplug_work
.work
);
375 struct drm_device
*dev
= &dev_priv
->drm
;
376 struct drm_connector_list_iter conn_iter
;
377 struct intel_connector
*connector
;
378 u32 changed
= 0, retry
= 0;
382 mutex_lock(&dev
->mode_config
.mutex
);
383 drm_dbg_kms(&dev_priv
->drm
, "running encoder hotplug functions\n");
385 spin_lock_irq(&dev_priv
->irq_lock
);
387 hpd_event_bits
= dev_priv
->hotplug
.event_bits
;
388 dev_priv
->hotplug
.event_bits
= 0;
389 hpd_retry_bits
= dev_priv
->hotplug
.retry_bits
;
390 dev_priv
->hotplug
.retry_bits
= 0;
392 /* Enable polling for connectors which had HPD IRQ storms */
393 intel_hpd_irq_storm_switch_to_polling(dev_priv
);
395 spin_unlock_irq(&dev_priv
->irq_lock
);
397 drm_connector_list_iter_begin(dev
, &conn_iter
);
398 for_each_intel_connector_iter(connector
, &conn_iter
) {
402 pin
= intel_connector_hpd_pin(connector
);
407 if ((hpd_event_bits
| hpd_retry_bits
) & hpd_bit
) {
408 struct intel_encoder
*encoder
=
409 intel_attached_encoder(connector
);
411 if (hpd_event_bits
& hpd_bit
)
412 connector
->hotplug_retries
= 0;
414 connector
->hotplug_retries
++;
416 drm_dbg_kms(&dev_priv
->drm
,
417 "Connector %s (pin %i) received hotplug event. (retry %d)\n",
418 connector
->base
.name
, pin
,
419 connector
->hotplug_retries
);
421 switch (encoder
->hotplug(encoder
, connector
)) {
422 case INTEL_HOTPLUG_UNCHANGED
:
424 case INTEL_HOTPLUG_CHANGED
:
427 case INTEL_HOTPLUG_RETRY
:
433 drm_connector_list_iter_end(&conn_iter
);
434 mutex_unlock(&dev
->mode_config
.mutex
);
437 drm_kms_helper_hotplug_event(dev
);
439 /* Remove shared HPD pins that have changed */
442 spin_lock_irq(&dev_priv
->irq_lock
);
443 dev_priv
->hotplug
.retry_bits
|= retry
;
444 spin_unlock_irq(&dev_priv
->irq_lock
);
446 mod_delayed_work(system_wq
, &dev_priv
->hotplug
.hotplug_work
,
447 msecs_to_jiffies(HPD_RETRY_DELAY
));
453 * intel_hpd_irq_handler - main hotplug irq handler
454 * @dev_priv: drm_i915_private
455 * @pin_mask: a mask of hpd pins that have triggered the irq
456 * @long_mask: a mask of hpd pins that may be long hpd pulses
458 * This is the main hotplug irq handler for all platforms. The platform specific
459 * irq handlers call the platform specific hotplug irq handlers, which read and
460 * decode the appropriate registers into bitmasks about hpd pins that have
461 * triggered (@pin_mask), and which of those pins may be long pulses
462 * (@long_mask). The @long_mask is ignored if the port corresponding to the pin
463 * is not a digital port.
465 * Here, we do hotplug irq storm detection and mitigation, and pass further
466 * processing to appropriate bottom halves.
468 void intel_hpd_irq_handler(struct drm_i915_private
*dev_priv
,
469 u32 pin_mask
, u32 long_mask
)
471 struct intel_encoder
*encoder
;
472 bool storm_detected
= false;
473 bool queue_dig
= false, queue_hp
= false;
474 u32 long_hpd_pulse_mask
= 0;
475 u32 short_hpd_pulse_mask
= 0;
481 spin_lock(&dev_priv
->irq_lock
);
484 * Determine whether ->hpd_pulse() exists for each pin, and
485 * whether we have a short or a long pulse. This is needed
486 * as each pin may have up to two encoders (HDMI and DP) and
487 * only the one of them (DP) will have ->hpd_pulse().
489 for_each_intel_encoder(&dev_priv
->drm
, encoder
) {
490 enum port port
= encoder
->port
;
493 pin
= encoder
->hpd_pin
;
494 if (!(BIT(pin
) & pin_mask
))
497 if (!intel_encoder_has_hpd_pulse(encoder
))
500 long_hpd
= long_mask
& BIT(pin
);
502 drm_dbg(&dev_priv
->drm
,
503 "digital hpd on [ENCODER:%d:%s] - %s\n",
504 encoder
->base
.base
.id
, encoder
->base
.name
,
505 long_hpd
? "long" : "short");
509 long_hpd_pulse_mask
|= BIT(pin
);
510 dev_priv
->hotplug
.long_port_mask
|= BIT(port
);
512 short_hpd_pulse_mask
|= BIT(pin
);
513 dev_priv
->hotplug
.short_port_mask
|= BIT(port
);
517 /* Now process each pin just once */
518 for_each_hpd_pin(pin
) {
521 if (!(BIT(pin
) & pin_mask
))
524 if (dev_priv
->hotplug
.stats
[pin
].state
== HPD_DISABLED
) {
526 * On GMCH platforms the interrupt mask bits only
527 * prevent irq generation, not the setting of the
528 * hotplug bits itself. So only WARN about unexpected
529 * interrupts on saner platforms.
531 drm_WARN_ONCE(&dev_priv
->drm
, !HAS_GMCH(dev_priv
),
532 "Received HPD interrupt on pin %d although disabled\n",
537 if (dev_priv
->hotplug
.stats
[pin
].state
!= HPD_ENABLED
)
541 * Delegate to ->hpd_pulse() if one of the encoders for this
542 * pin has it, otherwise let the hotplug_work deal with this
545 if (((short_hpd_pulse_mask
| long_hpd_pulse_mask
) & BIT(pin
))) {
546 long_hpd
= long_hpd_pulse_mask
& BIT(pin
);
548 dev_priv
->hotplug
.event_bits
|= BIT(pin
);
553 if (intel_hpd_irq_storm_detect(dev_priv
, pin
, long_hpd
)) {
554 dev_priv
->hotplug
.event_bits
&= ~BIT(pin
);
555 storm_detected
= true;
561 * Disable any IRQs that storms were detected on. Polling enablement
562 * happens later in our hotplug work.
565 intel_hpd_irq_setup(dev_priv
);
566 spin_unlock(&dev_priv
->irq_lock
);
569 * Our hotplug handler can grab modeset locks (by calling down into the
570 * fb helpers). Hence it must not be run on our own dev-priv->wq work
571 * queue for otherwise the flush_work in the pageflip code will
575 queue_work(dev_priv
->hotplug
.dp_wq
, &dev_priv
->hotplug
.dig_port_work
);
577 queue_delayed_work(system_wq
, &dev_priv
->hotplug
.hotplug_work
, 0);
581 * intel_hpd_init - initializes and enables hpd support
582 * @dev_priv: i915 device instance
584 * This function enables the hotplug support. It requires that interrupts have
585 * already been enabled with intel_irq_init_hw(). From this point on hotplug and
586 * poll request can run concurrently to other code, so locking rules must be
589 * This is a separate step from interrupt enabling to simplify the locking rules
590 * in the driver load and resume code.
592 * Also see: intel_hpd_poll_enable() and intel_hpd_poll_disable().
594 void intel_hpd_init(struct drm_i915_private
*dev_priv
)
598 for_each_hpd_pin(i
) {
599 dev_priv
->hotplug
.stats
[i
].count
= 0;
600 dev_priv
->hotplug
.stats
[i
].state
= HPD_ENABLED
;
604 * Interrupt setup is already guaranteed to be single-threaded, this is
605 * just to make the assert_spin_locked checks happy.
607 spin_lock_irq(&dev_priv
->irq_lock
);
608 intel_hpd_irq_setup(dev_priv
);
609 spin_unlock_irq(&dev_priv
->irq_lock
);
612 static void i915_hpd_poll_init_work(struct work_struct
*work
)
614 struct drm_i915_private
*dev_priv
=
615 container_of(work
, struct drm_i915_private
,
616 hotplug
.poll_init_work
);
617 struct drm_device
*dev
= &dev_priv
->drm
;
618 struct drm_connector_list_iter conn_iter
;
619 struct intel_connector
*connector
;
622 mutex_lock(&dev
->mode_config
.mutex
);
624 enabled
= READ_ONCE(dev_priv
->hotplug
.poll_enabled
);
626 drm_connector_list_iter_begin(dev
, &conn_iter
);
627 for_each_intel_connector_iter(connector
, &conn_iter
) {
630 pin
= intel_connector_hpd_pin(connector
);
634 connector
->base
.polled
= connector
->polled
;
636 if (enabled
&& connector
->base
.polled
== DRM_CONNECTOR_POLL_HPD
)
637 connector
->base
.polled
= DRM_CONNECTOR_POLL_CONNECT
|
638 DRM_CONNECTOR_POLL_DISCONNECT
;
640 drm_connector_list_iter_end(&conn_iter
);
643 drm_kms_helper_poll_enable(dev
);
645 mutex_unlock(&dev
->mode_config
.mutex
);
648 * We might have missed any hotplugs that happened while we were
649 * in the middle of disabling polling
652 drm_helper_hpd_irq_event(dev
);
656 * intel_hpd_poll_enable - enable polling for connectors with hpd
657 * @dev_priv: i915 device instance
659 * This function enables polling for all connectors which support HPD.
660 * Under certain conditions HPD may not be functional. On most Intel GPUs,
661 * this happens when we enter runtime suspend.
662 * On Valleyview and Cherryview systems, this also happens when we shut off all
665 * Since this function can get called in contexts where we're already holding
666 * dev->mode_config.mutex, we do the actual hotplug enabling in a seperate
669 * Also see: intel_hpd_init() and intel_hpd_poll_disable().
671 void intel_hpd_poll_enable(struct drm_i915_private
*dev_priv
)
673 WRITE_ONCE(dev_priv
->hotplug
.poll_enabled
, true);
676 * We might already be holding dev->mode_config.mutex, so do this in a
678 * As well, there's no issue if we race here since we always reschedule
681 schedule_work(&dev_priv
->hotplug
.poll_init_work
);
685 * intel_hpd_poll_disable - disable polling for connectors with hpd
686 * @dev_priv: i915 device instance
688 * This function disables polling for all connectors which support HPD.
689 * Under certain conditions HPD may not be functional. On most Intel GPUs,
690 * this happens when we enter runtime suspend.
691 * On Valleyview and Cherryview systems, this also happens when we shut off all
694 * Since this function can get called in contexts where we're already holding
695 * dev->mode_config.mutex, we do the actual hotplug enabling in a seperate
698 * Also used during driver init to initialize connector->polled
699 * appropriately for all connectors.
701 * Also see: intel_hpd_init() and intel_hpd_poll_enable().
703 void intel_hpd_poll_disable(struct drm_i915_private
*dev_priv
)
705 WRITE_ONCE(dev_priv
->hotplug
.poll_enabled
, false);
706 schedule_work(&dev_priv
->hotplug
.poll_init_work
);
709 void intel_hpd_init_work(struct drm_i915_private
*dev_priv
)
711 INIT_DELAYED_WORK(&dev_priv
->hotplug
.hotplug_work
,
712 i915_hotplug_work_func
);
713 INIT_WORK(&dev_priv
->hotplug
.dig_port_work
, i915_digport_work_func
);
714 INIT_WORK(&dev_priv
->hotplug
.poll_init_work
, i915_hpd_poll_init_work
);
715 INIT_DELAYED_WORK(&dev_priv
->hotplug
.reenable_work
,
716 intel_hpd_irq_storm_reenable_work
);
719 void intel_hpd_cancel_work(struct drm_i915_private
*dev_priv
)
721 spin_lock_irq(&dev_priv
->irq_lock
);
723 dev_priv
->hotplug
.long_port_mask
= 0;
724 dev_priv
->hotplug
.short_port_mask
= 0;
725 dev_priv
->hotplug
.event_bits
= 0;
726 dev_priv
->hotplug
.retry_bits
= 0;
728 spin_unlock_irq(&dev_priv
->irq_lock
);
730 cancel_work_sync(&dev_priv
->hotplug
.dig_port_work
);
731 cancel_delayed_work_sync(&dev_priv
->hotplug
.hotplug_work
);
732 cancel_work_sync(&dev_priv
->hotplug
.poll_init_work
);
733 cancel_delayed_work_sync(&dev_priv
->hotplug
.reenable_work
);
736 bool intel_hpd_disable(struct drm_i915_private
*dev_priv
, enum hpd_pin pin
)
743 spin_lock_irq(&dev_priv
->irq_lock
);
744 if (dev_priv
->hotplug
.stats
[pin
].state
== HPD_ENABLED
) {
745 dev_priv
->hotplug
.stats
[pin
].state
= HPD_DISABLED
;
748 spin_unlock_irq(&dev_priv
->irq_lock
);
753 void intel_hpd_enable(struct drm_i915_private
*dev_priv
, enum hpd_pin pin
)
758 spin_lock_irq(&dev_priv
->irq_lock
);
759 dev_priv
->hotplug
.stats
[pin
].state
= HPD_ENABLED
;
760 spin_unlock_irq(&dev_priv
->irq_lock
);