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>
28 #include "intel_display_types.h"
29 #include "intel_hotplug.h"
30 #include "intel_hotplug_irq.h"
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.
39 * Hotplug in i915 is handled in many different levels of abstraction.
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.
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
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.
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().
60 * Finally, the userspace is responsible for triggering a modeset upon receiving
61 * the hotplug uevent, disabling or enabling the crtc as needed.
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.
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.
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
84 * It is only valid and used by digital port encoder.
86 * Return pin that is associatade with @port.
88 enum hpd_pin intel_hpd_pin_default(struct drm_i915_private *dev_priv,
91 return HPD_PORT_A + port - PORT_A;
94 /* Threshold == 5 for long IRQs, 50 for short */
95 #define HPD_STORM_DEFAULT_THRESHOLD 50
97 #define HPD_STORM_DETECT_PERIOD 1000
98 #define HPD_STORM_REENABLE_DELAY (2 * 60 * 1000)
99 #define HPD_RETRY_DELAY 1000
102 intel_connector_hpd_pin(struct intel_connector *connector)
104 struct intel_encoder *encoder = intel_attached_encoder(connector);
107 * MST connectors get their encoder attached dynamically
108 * so need to make sure we have an encoder here. But since
109 * MST encoders have their hpd_pin set to HPD_NONE we don't
110 * have to special case them beyond that.
112 return encoder ? encoder->hpd_pin : HPD_NONE;
116 * intel_hpd_irq_storm_detect - gather stats and detect HPD IRQ storm on a pin
117 * @dev_priv: private driver data pointer
118 * @pin: the pin to gather stats on
119 * @long_hpd: whether the HPD IRQ was long or short
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.
125 * The number of IRQs that are allowed within @HPD_STORM_DETECT_PERIOD is
126 * stored in @dev_priv->display.hotplug.hpd_storm_threshold which defaults to
127 * @HPD_STORM_DEFAULT_THRESHOLD. Long IRQs count as +10 to this threshold, and
128 * short IRQs count as +1. If this threshold is exceeded, it's considered an
129 * IRQ storm and the IRQ state is set to @HPD_MARK_DISABLED.
131 * By default, most systems will only count long IRQs towards
132 * &dev_priv->display.hotplug.hpd_storm_threshold. However, some older systems also
133 * suffer from short IRQ storms and must also track these. Because short IRQ
134 * storms are naturally caused by sideband interactions with DP MST devices,
135 * short IRQ detection is only enabled for systems without DP MST support.
136 * Systems which are new enough to support DP MST are far less likely to
137 * suffer from IRQ storms at all, so this is fine.
139 * The HPD threshold can be controlled through i915_hpd_storm_ctl in debugfs,
140 * and should only be adjusted for automated hotplug testing.
142 * Return true if an IRQ storm was detected on @pin.
144 static bool intel_hpd_irq_storm_detect(struct drm_i915_private *dev_priv,
145 enum hpd_pin pin, bool long_hpd)
147 struct intel_hotplug *hpd = &dev_priv->display.hotplug;
148 unsigned long start = hpd->stats[pin].last_jiffies;
149 unsigned long end = start + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD);
150 const int increment = long_hpd ? 10 : 1;
151 const int threshold = hpd->hpd_storm_threshold;
155 (!long_hpd && !dev_priv->display.hotplug.hpd_short_storm_enabled))
158 if (!time_in_range(jiffies, start, end)) {
159 hpd->stats[pin].last_jiffies = jiffies;
160 hpd->stats[pin].count = 0;
163 hpd->stats[pin].count += increment;
164 if (hpd->stats[pin].count > threshold) {
165 hpd->stats[pin].state = HPD_MARK_DISABLED;
166 drm_dbg_kms(&dev_priv->drm,
167 "HPD interrupt storm detected on PIN %d\n", pin);
170 drm_dbg_kms(&dev_priv->drm,
171 "Received HPD interrupt on PIN %d - cnt: %d\n",
173 hpd->stats[pin].count);
180 intel_hpd_irq_storm_switch_to_polling(struct drm_i915_private *dev_priv)
182 struct drm_connector_list_iter conn_iter;
183 struct intel_connector *connector;
184 bool hpd_disabled = false;
186 lockdep_assert_held(&dev_priv->irq_lock);
188 drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
189 for_each_intel_connector_iter(connector, &conn_iter) {
192 if (connector->base.polled != DRM_CONNECTOR_POLL_HPD)
195 pin = intel_connector_hpd_pin(connector);
196 if (pin == HPD_NONE ||
197 dev_priv->display.hotplug.stats[pin].state != HPD_MARK_DISABLED)
200 drm_info(&dev_priv->drm,
201 "HPD interrupt storm detected on connector %s: "
202 "switching from hotplug detection to polling\n",
203 connector->base.name);
205 dev_priv->display.hotplug.stats[pin].state = HPD_DISABLED;
206 connector->base.polled = DRM_CONNECTOR_POLL_CONNECT |
207 DRM_CONNECTOR_POLL_DISCONNECT;
210 drm_connector_list_iter_end(&conn_iter);
212 /* Enable polling and queue hotplug re-enabling. */
214 drm_kms_helper_poll_reschedule(&dev_priv->drm);
215 mod_delayed_work(dev_priv->unordered_wq,
216 &dev_priv->display.hotplug.reenable_work,
217 msecs_to_jiffies(HPD_STORM_REENABLE_DELAY));
221 static void intel_hpd_irq_storm_reenable_work(struct work_struct *work)
223 struct drm_i915_private *dev_priv =
224 container_of(work, typeof(*dev_priv),
225 display.hotplug.reenable_work.work);
226 struct drm_connector_list_iter conn_iter;
227 struct intel_connector *connector;
228 intel_wakeref_t wakeref;
231 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
233 spin_lock_irq(&dev_priv->irq_lock);
235 drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
236 for_each_intel_connector_iter(connector, &conn_iter) {
237 pin = intel_connector_hpd_pin(connector);
238 if (pin == HPD_NONE ||
239 dev_priv->display.hotplug.stats[pin].state != HPD_DISABLED)
242 if (connector->base.polled != connector->polled)
243 drm_dbg(&dev_priv->drm,
244 "Reenabling HPD on connector %s\n",
245 connector->base.name);
246 connector->base.polled = connector->polled;
248 drm_connector_list_iter_end(&conn_iter);
250 for_each_hpd_pin(pin) {
251 if (dev_priv->display.hotplug.stats[pin].state == HPD_DISABLED)
252 dev_priv->display.hotplug.stats[pin].state = HPD_ENABLED;
255 intel_hpd_irq_setup(dev_priv);
257 spin_unlock_irq(&dev_priv->irq_lock);
259 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
262 enum intel_hotplug_state
263 intel_encoder_hotplug(struct intel_encoder *encoder,
264 struct intel_connector *connector)
266 struct drm_device *dev = connector->base.dev;
267 enum drm_connector_status old_status;
268 u64 old_epoch_counter;
271 drm_WARN_ON(dev, !mutex_is_locked(&dev->mode_config.mutex));
272 old_status = connector->base.status;
273 old_epoch_counter = connector->base.epoch_counter;
275 connector->base.status =
276 drm_helper_probe_detect(&connector->base, NULL, false);
278 if (old_epoch_counter != connector->base.epoch_counter)
282 drm_dbg_kms(dev, "[CONNECTOR:%d:%s] status updated from %s to %s (epoch counter %llu->%llu)\n",
283 connector->base.base.id,
284 connector->base.name,
285 drm_get_connector_status_name(old_status),
286 drm_get_connector_status_name(connector->base.status),
288 connector->base.epoch_counter);
289 return INTEL_HOTPLUG_CHANGED;
291 return INTEL_HOTPLUG_UNCHANGED;
294 static bool intel_encoder_has_hpd_pulse(struct intel_encoder *encoder)
296 return intel_encoder_is_dig_port(encoder) &&
297 enc_to_dig_port(encoder)->hpd_pulse != NULL;
300 static void i915_digport_work_func(struct work_struct *work)
302 struct drm_i915_private *dev_priv =
303 container_of(work, struct drm_i915_private, display.hotplug.dig_port_work);
304 u32 long_port_mask, short_port_mask;
305 struct intel_encoder *encoder;
308 spin_lock_irq(&dev_priv->irq_lock);
309 long_port_mask = dev_priv->display.hotplug.long_port_mask;
310 dev_priv->display.hotplug.long_port_mask = 0;
311 short_port_mask = dev_priv->display.hotplug.short_port_mask;
312 dev_priv->display.hotplug.short_port_mask = 0;
313 spin_unlock_irq(&dev_priv->irq_lock);
315 for_each_intel_encoder(&dev_priv->drm, encoder) {
316 struct intel_digital_port *dig_port;
317 enum port port = encoder->port;
318 bool long_hpd, short_hpd;
321 if (!intel_encoder_has_hpd_pulse(encoder))
324 long_hpd = long_port_mask & BIT(port);
325 short_hpd = short_port_mask & BIT(port);
327 if (!long_hpd && !short_hpd)
330 dig_port = enc_to_dig_port(encoder);
332 ret = dig_port->hpd_pulse(dig_port, long_hpd);
333 if (ret == IRQ_NONE) {
334 /* fall back to old school hpd */
335 old_bits |= BIT(encoder->hpd_pin);
340 spin_lock_irq(&dev_priv->irq_lock);
341 dev_priv->display.hotplug.event_bits |= old_bits;
342 spin_unlock_irq(&dev_priv->irq_lock);
343 queue_delayed_work(dev_priv->unordered_wq,
344 &dev_priv->display.hotplug.hotplug_work, 0);
349 * intel_hpd_trigger_irq - trigger an hpd irq event for a port
350 * @dig_port: digital port
352 * Trigger an HPD interrupt event for the given port, emulating a short pulse
353 * generated by the sink, and schedule the dig port work to handle it.
355 void intel_hpd_trigger_irq(struct intel_digital_port *dig_port)
357 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
359 spin_lock_irq(&i915->irq_lock);
360 i915->display.hotplug.short_port_mask |= BIT(dig_port->base.port);
361 spin_unlock_irq(&i915->irq_lock);
363 queue_work(i915->display.hotplug.dp_wq, &i915->display.hotplug.dig_port_work);
367 * Handle hotplug events outside the interrupt handler proper.
369 static void i915_hotplug_work_func(struct work_struct *work)
371 struct drm_i915_private *dev_priv =
372 container_of(work, struct drm_i915_private,
373 display.hotplug.hotplug_work.work);
374 struct drm_connector_list_iter conn_iter;
375 struct intel_connector *connector;
376 u32 changed = 0, retry = 0;
379 struct drm_connector *first_changed_connector = NULL;
380 int changed_connectors = 0;
382 mutex_lock(&dev_priv->drm.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->display.hotplug.event_bits;
388 dev_priv->display.hotplug.event_bits = 0;
389 hpd_retry_bits = dev_priv->display.hotplug.retry_bits;
390 dev_priv->display.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 /* Skip calling encode hotplug handlers if ignore long HPD set*/
398 if (dev_priv->display.hotplug.ignore_long_hpd) {
399 drm_dbg_kms(&dev_priv->drm, "Ignore HPD flag on - skip encoder hotplug handlers\n");
400 mutex_unlock(&dev_priv->drm.mode_config.mutex);
404 drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
405 for_each_intel_connector_iter(connector, &conn_iter) {
409 pin = intel_connector_hpd_pin(connector);
414 if ((hpd_event_bits | hpd_retry_bits) & hpd_bit) {
415 struct intel_encoder *encoder =
416 intel_attached_encoder(connector);
418 if (hpd_event_bits & hpd_bit)
419 connector->hotplug_retries = 0;
421 connector->hotplug_retries++;
423 drm_dbg_kms(&dev_priv->drm,
424 "Connector %s (pin %i) received hotplug event. (retry %d)\n",
425 connector->base.name, pin,
426 connector->hotplug_retries);
428 switch (encoder->hotplug(encoder, connector)) {
429 case INTEL_HOTPLUG_UNCHANGED:
431 case INTEL_HOTPLUG_CHANGED:
433 changed_connectors++;
434 if (!first_changed_connector) {
435 drm_connector_get(&connector->base);
436 first_changed_connector = &connector->base;
439 case INTEL_HOTPLUG_RETRY:
445 drm_connector_list_iter_end(&conn_iter);
446 mutex_unlock(&dev_priv->drm.mode_config.mutex);
448 if (changed_connectors == 1)
449 drm_kms_helper_connector_hotplug_event(first_changed_connector);
450 else if (changed_connectors > 0)
451 drm_kms_helper_hotplug_event(&dev_priv->drm);
453 if (first_changed_connector)
454 drm_connector_put(first_changed_connector);
456 /* Remove shared HPD pins that have changed */
459 spin_lock_irq(&dev_priv->irq_lock);
460 dev_priv->display.hotplug.retry_bits |= retry;
461 spin_unlock_irq(&dev_priv->irq_lock);
463 mod_delayed_work(dev_priv->unordered_wq,
464 &dev_priv->display.hotplug.hotplug_work,
465 msecs_to_jiffies(HPD_RETRY_DELAY));
471 * intel_hpd_irq_handler - main hotplug irq handler
472 * @dev_priv: drm_i915_private
473 * @pin_mask: a mask of hpd pins that have triggered the irq
474 * @long_mask: a mask of hpd pins that may be long hpd pulses
476 * This is the main hotplug irq handler for all platforms. The platform specific
477 * irq handlers call the platform specific hotplug irq handlers, which read and
478 * decode the appropriate registers into bitmasks about hpd pins that have
479 * triggered (@pin_mask), and which of those pins may be long pulses
480 * (@long_mask). The @long_mask is ignored if the port corresponding to the pin
481 * is not a digital port.
483 * Here, we do hotplug irq storm detection and mitigation, and pass further
484 * processing to appropriate bottom halves.
486 void intel_hpd_irq_handler(struct drm_i915_private *dev_priv,
487 u32 pin_mask, u32 long_mask)
489 struct intel_encoder *encoder;
490 bool storm_detected = false;
491 bool queue_dig = false, queue_hp = false;
492 u32 long_hpd_pulse_mask = 0;
493 u32 short_hpd_pulse_mask = 0;
499 spin_lock(&dev_priv->irq_lock);
502 * Determine whether ->hpd_pulse() exists for each pin, and
503 * whether we have a short or a long pulse. This is needed
504 * as each pin may have up to two encoders (HDMI and DP) and
505 * only the one of them (DP) will have ->hpd_pulse().
507 for_each_intel_encoder(&dev_priv->drm, encoder) {
508 enum port port = encoder->port;
511 pin = encoder->hpd_pin;
512 if (!(BIT(pin) & pin_mask))
515 if (!intel_encoder_has_hpd_pulse(encoder))
518 long_hpd = long_mask & BIT(pin);
520 drm_dbg(&dev_priv->drm,
521 "digital hpd on [ENCODER:%d:%s] - %s\n",
522 encoder->base.base.id, encoder->base.name,
523 long_hpd ? "long" : "short");
527 long_hpd_pulse_mask |= BIT(pin);
528 dev_priv->display.hotplug.long_port_mask |= BIT(port);
530 short_hpd_pulse_mask |= BIT(pin);
531 dev_priv->display.hotplug.short_port_mask |= BIT(port);
535 /* Now process each pin just once */
536 for_each_hpd_pin(pin) {
539 if (!(BIT(pin) & pin_mask))
542 if (dev_priv->display.hotplug.stats[pin].state == HPD_DISABLED) {
544 * On GMCH platforms the interrupt mask bits only
545 * prevent irq generation, not the setting of the
546 * hotplug bits itself. So only WARN about unexpected
547 * interrupts on saner platforms.
549 drm_WARN_ONCE(&dev_priv->drm, !HAS_GMCH(dev_priv),
550 "Received HPD interrupt on pin %d although disabled\n",
555 if (dev_priv->display.hotplug.stats[pin].state != HPD_ENABLED)
559 * Delegate to ->hpd_pulse() if one of the encoders for this
560 * pin has it, otherwise let the hotplug_work deal with this
563 if (((short_hpd_pulse_mask | long_hpd_pulse_mask) & BIT(pin))) {
564 long_hpd = long_hpd_pulse_mask & BIT(pin);
566 dev_priv->display.hotplug.event_bits |= BIT(pin);
571 if (intel_hpd_irq_storm_detect(dev_priv, pin, long_hpd)) {
572 dev_priv->display.hotplug.event_bits &= ~BIT(pin);
573 storm_detected = true;
579 * Disable any IRQs that storms were detected on. Polling enablement
580 * happens later in our hotplug work.
583 intel_hpd_irq_setup(dev_priv);
584 spin_unlock(&dev_priv->irq_lock);
587 * Our hotplug handler can grab modeset locks (by calling down into the
588 * fb helpers). Hence it must not be run on our own dev-priv->wq work
589 * queue for otherwise the flush_work in the pageflip code will
593 queue_work(dev_priv->display.hotplug.dp_wq, &dev_priv->display.hotplug.dig_port_work);
595 queue_delayed_work(dev_priv->unordered_wq,
596 &dev_priv->display.hotplug.hotplug_work, 0);
600 * intel_hpd_init - initializes and enables hpd support
601 * @dev_priv: i915 device instance
603 * This function enables the hotplug support. It requires that interrupts have
604 * already been enabled with intel_irq_init_hw(). From this point on hotplug and
605 * poll request can run concurrently to other code, so locking rules must be
608 * This is a separate step from interrupt enabling to simplify the locking rules
609 * in the driver load and resume code.
611 * Also see: intel_hpd_poll_enable() and intel_hpd_poll_disable().
613 void intel_hpd_init(struct drm_i915_private *dev_priv)
617 if (!HAS_DISPLAY(dev_priv))
620 for_each_hpd_pin(i) {
621 dev_priv->display.hotplug.stats[i].count = 0;
622 dev_priv->display.hotplug.stats[i].state = HPD_ENABLED;
626 * Interrupt setup is already guaranteed to be single-threaded, this is
627 * just to make the assert_spin_locked checks happy.
629 spin_lock_irq(&dev_priv->irq_lock);
630 intel_hpd_irq_setup(dev_priv);
631 spin_unlock_irq(&dev_priv->irq_lock);
634 static void i915_hpd_poll_init_work(struct work_struct *work)
636 struct drm_i915_private *dev_priv =
637 container_of(work, struct drm_i915_private,
638 display.hotplug.poll_init_work);
639 struct drm_connector_list_iter conn_iter;
640 struct intel_connector *connector;
643 mutex_lock(&dev_priv->drm.mode_config.mutex);
645 enabled = READ_ONCE(dev_priv->display.hotplug.poll_enabled);
647 drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
648 for_each_intel_connector_iter(connector, &conn_iter) {
651 pin = intel_connector_hpd_pin(connector);
655 connector->base.polled = connector->polled;
657 if (enabled && connector->base.polled == DRM_CONNECTOR_POLL_HPD)
658 connector->base.polled = DRM_CONNECTOR_POLL_CONNECT |
659 DRM_CONNECTOR_POLL_DISCONNECT;
661 drm_connector_list_iter_end(&conn_iter);
664 drm_kms_helper_poll_reschedule(&dev_priv->drm);
666 mutex_unlock(&dev_priv->drm.mode_config.mutex);
669 * We might have missed any hotplugs that happened while we were
670 * in the middle of disabling polling
673 drm_helper_hpd_irq_event(&dev_priv->drm);
677 * intel_hpd_poll_enable - enable polling for connectors with hpd
678 * @dev_priv: i915 device instance
680 * This function enables polling for all connectors which support HPD.
681 * Under certain conditions HPD may not be functional. On most Intel GPUs,
682 * this happens when we enter runtime suspend.
683 * On Valleyview and Cherryview systems, this also happens when we shut off all
686 * Since this function can get called in contexts where we're already holding
687 * dev->mode_config.mutex, we do the actual hotplug enabling in a seperate
690 * Also see: intel_hpd_init() and intel_hpd_poll_disable().
692 void intel_hpd_poll_enable(struct drm_i915_private *dev_priv)
694 if (!HAS_DISPLAY(dev_priv) ||
695 !INTEL_DISPLAY_ENABLED(dev_priv))
698 WRITE_ONCE(dev_priv->display.hotplug.poll_enabled, true);
701 * We might already be holding dev->mode_config.mutex, so do this in a
703 * As well, there's no issue if we race here since we always reschedule
706 queue_work(dev_priv->unordered_wq,
707 &dev_priv->display.hotplug.poll_init_work);
711 * intel_hpd_poll_disable - disable polling for connectors with hpd
712 * @dev_priv: i915 device instance
714 * This function disables polling for all connectors which support HPD.
715 * Under certain conditions HPD may not be functional. On most Intel GPUs,
716 * this happens when we enter runtime suspend.
717 * On Valleyview and Cherryview systems, this also happens when we shut off all
720 * Since this function can get called in contexts where we're already holding
721 * dev->mode_config.mutex, we do the actual hotplug enabling in a seperate
724 * Also used during driver init to initialize connector->polled
725 * appropriately for all connectors.
727 * Also see: intel_hpd_init() and intel_hpd_poll_enable().
729 void intel_hpd_poll_disable(struct drm_i915_private *dev_priv)
731 if (!HAS_DISPLAY(dev_priv))
734 WRITE_ONCE(dev_priv->display.hotplug.poll_enabled, false);
735 queue_work(dev_priv->unordered_wq,
736 &dev_priv->display.hotplug.poll_init_work);
739 void intel_hpd_init_early(struct drm_i915_private *i915)
741 INIT_DELAYED_WORK(&i915->display.hotplug.hotplug_work,
742 i915_hotplug_work_func);
743 INIT_WORK(&i915->display.hotplug.dig_port_work, i915_digport_work_func);
744 INIT_WORK(&i915->display.hotplug.poll_init_work, i915_hpd_poll_init_work);
745 INIT_DELAYED_WORK(&i915->display.hotplug.reenable_work,
746 intel_hpd_irq_storm_reenable_work);
748 i915->display.hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
749 /* If we have MST support, we want to avoid doing short HPD IRQ storm
750 * detection, as short HPD storms will occur as a natural part of
751 * sideband messaging with MST.
752 * On older platforms however, IRQ storms can occur with both long and
753 * short pulses, as seen on some G4x systems.
755 i915->display.hotplug.hpd_short_storm_enabled = !HAS_DP_MST(i915);
758 void intel_hpd_cancel_work(struct drm_i915_private *dev_priv)
760 if (!HAS_DISPLAY(dev_priv))
763 spin_lock_irq(&dev_priv->irq_lock);
765 dev_priv->display.hotplug.long_port_mask = 0;
766 dev_priv->display.hotplug.short_port_mask = 0;
767 dev_priv->display.hotplug.event_bits = 0;
768 dev_priv->display.hotplug.retry_bits = 0;
770 spin_unlock_irq(&dev_priv->irq_lock);
772 cancel_work_sync(&dev_priv->display.hotplug.dig_port_work);
773 cancel_delayed_work_sync(&dev_priv->display.hotplug.hotplug_work);
774 cancel_work_sync(&dev_priv->display.hotplug.poll_init_work);
775 cancel_delayed_work_sync(&dev_priv->display.hotplug.reenable_work);
778 bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
785 spin_lock_irq(&dev_priv->irq_lock);
786 if (dev_priv->display.hotplug.stats[pin].state == HPD_ENABLED) {
787 dev_priv->display.hotplug.stats[pin].state = HPD_DISABLED;
790 spin_unlock_irq(&dev_priv->irq_lock);
795 void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
800 spin_lock_irq(&dev_priv->irq_lock);
801 dev_priv->display.hotplug.stats[pin].state = HPD_ENABLED;
802 spin_unlock_irq(&dev_priv->irq_lock);
805 static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
807 struct drm_i915_private *dev_priv = m->private;
808 struct intel_hotplug *hotplug = &dev_priv->display.hotplug;
810 /* Synchronize with everything first in case there's been an HPD
811 * storm, but we haven't finished handling it in the kernel yet
813 intel_synchronize_irq(dev_priv);
814 flush_work(&dev_priv->display.hotplug.dig_port_work);
815 flush_delayed_work(&dev_priv->display.hotplug.hotplug_work);
817 seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
818 seq_printf(m, "Detected: %s\n",
819 str_yes_no(delayed_work_pending(&hotplug->reenable_work)));
824 static ssize_t i915_hpd_storm_ctl_write(struct file *file,
825 const char __user *ubuf, size_t len,
828 struct seq_file *m = file->private_data;
829 struct drm_i915_private *dev_priv = m->private;
830 struct intel_hotplug *hotplug = &dev_priv->display.hotplug;
831 unsigned int new_threshold;
836 if (len >= sizeof(tmp))
839 if (copy_from_user(tmp, ubuf, len))
844 /* Strip newline, if any */
845 newline = strchr(tmp, '\n');
849 if (strcmp(tmp, "reset") == 0)
850 new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
851 else if (kstrtouint(tmp, 10, &new_threshold) != 0)
854 if (new_threshold > 0)
855 drm_dbg_kms(&dev_priv->drm,
856 "Setting HPD storm detection threshold to %d\n",
859 drm_dbg_kms(&dev_priv->drm, "Disabling HPD storm detection\n");
861 spin_lock_irq(&dev_priv->irq_lock);
862 hotplug->hpd_storm_threshold = new_threshold;
863 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
865 hotplug->stats[i].count = 0;
866 spin_unlock_irq(&dev_priv->irq_lock);
868 /* Re-enable hpd immediately if we were in an irq storm */
869 flush_delayed_work(&dev_priv->display.hotplug.reenable_work);
874 static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
876 return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
879 static const struct file_operations i915_hpd_storm_ctl_fops = {
880 .owner = THIS_MODULE,
881 .open = i915_hpd_storm_ctl_open,
884 .release = single_release,
885 .write = i915_hpd_storm_ctl_write
888 static int i915_hpd_short_storm_ctl_show(struct seq_file *m, void *data)
890 struct drm_i915_private *dev_priv = m->private;
892 seq_printf(m, "Enabled: %s\n",
893 str_yes_no(dev_priv->display.hotplug.hpd_short_storm_enabled));
899 i915_hpd_short_storm_ctl_open(struct inode *inode, struct file *file)
901 return single_open(file, i915_hpd_short_storm_ctl_show,
905 static ssize_t i915_hpd_short_storm_ctl_write(struct file *file,
906 const char __user *ubuf,
907 size_t len, loff_t *offp)
909 struct seq_file *m = file->private_data;
910 struct drm_i915_private *dev_priv = m->private;
911 struct intel_hotplug *hotplug = &dev_priv->display.hotplug;
917 if (len >= sizeof(tmp))
920 if (copy_from_user(tmp, ubuf, len))
925 /* Strip newline, if any */
926 newline = strchr(tmp, '\n');
930 /* Reset to the "default" state for this system */
931 if (strcmp(tmp, "reset") == 0)
932 new_state = !HAS_DP_MST(dev_priv);
933 else if (kstrtobool(tmp, &new_state) != 0)
936 drm_dbg_kms(&dev_priv->drm, "%sabling HPD short storm detection\n",
937 new_state ? "En" : "Dis");
939 spin_lock_irq(&dev_priv->irq_lock);
940 hotplug->hpd_short_storm_enabled = new_state;
941 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
943 hotplug->stats[i].count = 0;
944 spin_unlock_irq(&dev_priv->irq_lock);
946 /* Re-enable hpd immediately if we were in an irq storm */
947 flush_delayed_work(&dev_priv->display.hotplug.reenable_work);
952 static const struct file_operations i915_hpd_short_storm_ctl_fops = {
953 .owner = THIS_MODULE,
954 .open = i915_hpd_short_storm_ctl_open,
957 .release = single_release,
958 .write = i915_hpd_short_storm_ctl_write,
961 void intel_hpd_debugfs_register(struct drm_i915_private *i915)
963 struct drm_minor *minor = i915->drm.primary;
965 debugfs_create_file("i915_hpd_storm_ctl", 0644, minor->debugfs_root,
966 i915, &i915_hpd_storm_ctl_fops);
967 debugfs_create_file("i915_hpd_short_storm_ctl", 0644, minor->debugfs_root,
968 i915, &i915_hpd_short_storm_ctl_fops);
969 debugfs_create_bool("i915_ignore_long_hpd", 0644, minor->debugfs_root,
970 &i915->display.hotplug.ignore_long_hpd);