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_enable(&dev_priv->drm);
215 mod_delayed_work(system_wq, &dev_priv->display.hotplug.reenable_work,
216 msecs_to_jiffies(HPD_STORM_REENABLE_DELAY));
220 static void intel_hpd_irq_storm_reenable_work(struct work_struct *work)
222 struct drm_i915_private *dev_priv =
223 container_of(work, typeof(*dev_priv),
224 display.hotplug.reenable_work.work);
225 struct drm_connector_list_iter conn_iter;
226 struct intel_connector *connector;
227 intel_wakeref_t wakeref;
230 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
232 spin_lock_irq(&dev_priv->irq_lock);
234 drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
235 for_each_intel_connector_iter(connector, &conn_iter) {
236 pin = intel_connector_hpd_pin(connector);
237 if (pin == HPD_NONE ||
238 dev_priv->display.hotplug.stats[pin].state != HPD_DISABLED)
241 if (connector->base.polled != connector->polled)
242 drm_dbg(&dev_priv->drm,
243 "Reenabling HPD on connector %s\n",
244 connector->base.name);
245 connector->base.polled = connector->polled;
247 drm_connector_list_iter_end(&conn_iter);
249 for_each_hpd_pin(pin) {
250 if (dev_priv->display.hotplug.stats[pin].state == HPD_DISABLED)
251 dev_priv->display.hotplug.stats[pin].state = HPD_ENABLED;
254 intel_hpd_irq_setup(dev_priv);
256 spin_unlock_irq(&dev_priv->irq_lock);
258 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
261 enum intel_hotplug_state
262 intel_encoder_hotplug(struct intel_encoder *encoder,
263 struct intel_connector *connector)
265 struct drm_device *dev = connector->base.dev;
266 enum drm_connector_status old_status;
267 u64 old_epoch_counter;
270 drm_WARN_ON(dev, !mutex_is_locked(&dev->mode_config.mutex));
271 old_status = connector->base.status;
272 old_epoch_counter = connector->base.epoch_counter;
274 connector->base.status =
275 drm_helper_probe_detect(&connector->base, NULL, false);
277 if (old_epoch_counter != connector->base.epoch_counter)
281 drm_dbg_kms(dev, "[CONNECTOR:%d:%s] status updated from %s to %s (epoch counter %llu->%llu)\n",
282 connector->base.base.id,
283 connector->base.name,
284 drm_get_connector_status_name(old_status),
285 drm_get_connector_status_name(connector->base.status),
287 connector->base.epoch_counter);
288 return INTEL_HOTPLUG_CHANGED;
290 return INTEL_HOTPLUG_UNCHANGED;
293 static bool intel_encoder_has_hpd_pulse(struct intel_encoder *encoder)
295 return intel_encoder_is_dig_port(encoder) &&
296 enc_to_dig_port(encoder)->hpd_pulse != NULL;
299 static void i915_digport_work_func(struct work_struct *work)
301 struct drm_i915_private *dev_priv =
302 container_of(work, struct drm_i915_private, display.hotplug.dig_port_work);
303 u32 long_port_mask, short_port_mask;
304 struct intel_encoder *encoder;
307 spin_lock_irq(&dev_priv->irq_lock);
308 long_port_mask = dev_priv->display.hotplug.long_port_mask;
309 dev_priv->display.hotplug.long_port_mask = 0;
310 short_port_mask = dev_priv->display.hotplug.short_port_mask;
311 dev_priv->display.hotplug.short_port_mask = 0;
312 spin_unlock_irq(&dev_priv->irq_lock);
314 for_each_intel_encoder(&dev_priv->drm, encoder) {
315 struct intel_digital_port *dig_port;
316 enum port port = encoder->port;
317 bool long_hpd, short_hpd;
320 if (!intel_encoder_has_hpd_pulse(encoder))
323 long_hpd = long_port_mask & BIT(port);
324 short_hpd = short_port_mask & BIT(port);
326 if (!long_hpd && !short_hpd)
329 dig_port = enc_to_dig_port(encoder);
331 ret = dig_port->hpd_pulse(dig_port, long_hpd);
332 if (ret == IRQ_NONE) {
333 /* fall back to old school hpd */
334 old_bits |= BIT(encoder->hpd_pin);
339 spin_lock_irq(&dev_priv->irq_lock);
340 dev_priv->display.hotplug.event_bits |= old_bits;
341 spin_unlock_irq(&dev_priv->irq_lock);
342 queue_delayed_work(system_wq, &dev_priv->display.hotplug.hotplug_work, 0);
347 * intel_hpd_trigger_irq - trigger an hpd irq event for a port
348 * @dig_port: digital port
350 * Trigger an HPD interrupt event for the given port, emulating a short pulse
351 * generated by the sink, and schedule the dig port work to handle it.
353 void intel_hpd_trigger_irq(struct intel_digital_port *dig_port)
355 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
357 spin_lock_irq(&i915->irq_lock);
358 i915->display.hotplug.short_port_mask |= BIT(dig_port->base.port);
359 spin_unlock_irq(&i915->irq_lock);
361 queue_work(i915->display.hotplug.dp_wq, &i915->display.hotplug.dig_port_work);
365 * Handle hotplug events outside the interrupt handler proper.
367 static void i915_hotplug_work_func(struct work_struct *work)
369 struct drm_i915_private *dev_priv =
370 container_of(work, struct drm_i915_private,
371 display.hotplug.hotplug_work.work);
372 struct drm_connector_list_iter conn_iter;
373 struct intel_connector *connector;
374 u32 changed = 0, retry = 0;
378 mutex_lock(&dev_priv->drm.mode_config.mutex);
379 drm_dbg_kms(&dev_priv->drm, "running encoder hotplug functions\n");
381 spin_lock_irq(&dev_priv->irq_lock);
383 hpd_event_bits = dev_priv->display.hotplug.event_bits;
384 dev_priv->display.hotplug.event_bits = 0;
385 hpd_retry_bits = dev_priv->display.hotplug.retry_bits;
386 dev_priv->display.hotplug.retry_bits = 0;
388 /* Enable polling for connectors which had HPD IRQ storms */
389 intel_hpd_irq_storm_switch_to_polling(dev_priv);
391 spin_unlock_irq(&dev_priv->irq_lock);
393 /* Skip calling encode hotplug handlers if ignore long HPD set*/
394 if (dev_priv->display.hotplug.ignore_long_hpd) {
395 drm_dbg_kms(&dev_priv->drm, "Ignore HPD flag on - skip encoder hotplug handlers\n");
396 mutex_unlock(&dev_priv->drm.mode_config.mutex);
400 drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
401 for_each_intel_connector_iter(connector, &conn_iter) {
405 pin = intel_connector_hpd_pin(connector);
410 if ((hpd_event_bits | hpd_retry_bits) & hpd_bit) {
411 struct intel_encoder *encoder =
412 intel_attached_encoder(connector);
414 if (hpd_event_bits & hpd_bit)
415 connector->hotplug_retries = 0;
417 connector->hotplug_retries++;
419 drm_dbg_kms(&dev_priv->drm,
420 "Connector %s (pin %i) received hotplug event. (retry %d)\n",
421 connector->base.name, pin,
422 connector->hotplug_retries);
424 switch (encoder->hotplug(encoder, connector)) {
425 case INTEL_HOTPLUG_UNCHANGED:
427 case INTEL_HOTPLUG_CHANGED:
430 case INTEL_HOTPLUG_RETRY:
436 drm_connector_list_iter_end(&conn_iter);
437 mutex_unlock(&dev_priv->drm.mode_config.mutex);
440 drm_kms_helper_hotplug_event(&dev_priv->drm);
442 /* Remove shared HPD pins that have changed */
445 spin_lock_irq(&dev_priv->irq_lock);
446 dev_priv->display.hotplug.retry_bits |= retry;
447 spin_unlock_irq(&dev_priv->irq_lock);
449 mod_delayed_work(system_wq, &dev_priv->display.hotplug.hotplug_work,
450 msecs_to_jiffies(HPD_RETRY_DELAY));
456 * intel_hpd_irq_handler - main hotplug irq handler
457 * @dev_priv: drm_i915_private
458 * @pin_mask: a mask of hpd pins that have triggered the irq
459 * @long_mask: a mask of hpd pins that may be long hpd pulses
461 * This is the main hotplug irq handler for all platforms. The platform specific
462 * irq handlers call the platform specific hotplug irq handlers, which read and
463 * decode the appropriate registers into bitmasks about hpd pins that have
464 * triggered (@pin_mask), and which of those pins may be long pulses
465 * (@long_mask). The @long_mask is ignored if the port corresponding to the pin
466 * is not a digital port.
468 * Here, we do hotplug irq storm detection and mitigation, and pass further
469 * processing to appropriate bottom halves.
471 void intel_hpd_irq_handler(struct drm_i915_private *dev_priv,
472 u32 pin_mask, u32 long_mask)
474 struct intel_encoder *encoder;
475 bool storm_detected = false;
476 bool queue_dig = false, queue_hp = false;
477 u32 long_hpd_pulse_mask = 0;
478 u32 short_hpd_pulse_mask = 0;
484 spin_lock(&dev_priv->irq_lock);
487 * Determine whether ->hpd_pulse() exists for each pin, and
488 * whether we have a short or a long pulse. This is needed
489 * as each pin may have up to two encoders (HDMI and DP) and
490 * only the one of them (DP) will have ->hpd_pulse().
492 for_each_intel_encoder(&dev_priv->drm, encoder) {
493 enum port port = encoder->port;
496 pin = encoder->hpd_pin;
497 if (!(BIT(pin) & pin_mask))
500 if (!intel_encoder_has_hpd_pulse(encoder))
503 long_hpd = long_mask & BIT(pin);
505 drm_dbg(&dev_priv->drm,
506 "digital hpd on [ENCODER:%d:%s] - %s\n",
507 encoder->base.base.id, encoder->base.name,
508 long_hpd ? "long" : "short");
512 long_hpd_pulse_mask |= BIT(pin);
513 dev_priv->display.hotplug.long_port_mask |= BIT(port);
515 short_hpd_pulse_mask |= BIT(pin);
516 dev_priv->display.hotplug.short_port_mask |= BIT(port);
520 /* Now process each pin just once */
521 for_each_hpd_pin(pin) {
524 if (!(BIT(pin) & pin_mask))
527 if (dev_priv->display.hotplug.stats[pin].state == HPD_DISABLED) {
529 * On GMCH platforms the interrupt mask bits only
530 * prevent irq generation, not the setting of the
531 * hotplug bits itself. So only WARN about unexpected
532 * interrupts on saner platforms.
534 drm_WARN_ONCE(&dev_priv->drm, !HAS_GMCH(dev_priv),
535 "Received HPD interrupt on pin %d although disabled\n",
540 if (dev_priv->display.hotplug.stats[pin].state != HPD_ENABLED)
544 * Delegate to ->hpd_pulse() if one of the encoders for this
545 * pin has it, otherwise let the hotplug_work deal with this
548 if (((short_hpd_pulse_mask | long_hpd_pulse_mask) & BIT(pin))) {
549 long_hpd = long_hpd_pulse_mask & BIT(pin);
551 dev_priv->display.hotplug.event_bits |= BIT(pin);
556 if (intel_hpd_irq_storm_detect(dev_priv, pin, long_hpd)) {
557 dev_priv->display.hotplug.event_bits &= ~BIT(pin);
558 storm_detected = true;
564 * Disable any IRQs that storms were detected on. Polling enablement
565 * happens later in our hotplug work.
568 intel_hpd_irq_setup(dev_priv);
569 spin_unlock(&dev_priv->irq_lock);
572 * Our hotplug handler can grab modeset locks (by calling down into the
573 * fb helpers). Hence it must not be run on our own dev-priv->wq work
574 * queue for otherwise the flush_work in the pageflip code will
578 queue_work(dev_priv->display.hotplug.dp_wq, &dev_priv->display.hotplug.dig_port_work);
580 queue_delayed_work(system_wq, &dev_priv->display.hotplug.hotplug_work, 0);
584 * intel_hpd_init - initializes and enables hpd support
585 * @dev_priv: i915 device instance
587 * This function enables the hotplug support. It requires that interrupts have
588 * already been enabled with intel_irq_init_hw(). From this point on hotplug and
589 * poll request can run concurrently to other code, so locking rules must be
592 * This is a separate step from interrupt enabling to simplify the locking rules
593 * in the driver load and resume code.
595 * Also see: intel_hpd_poll_enable() and intel_hpd_poll_disable().
597 void intel_hpd_init(struct drm_i915_private *dev_priv)
601 if (!HAS_DISPLAY(dev_priv))
604 for_each_hpd_pin(i) {
605 dev_priv->display.hotplug.stats[i].count = 0;
606 dev_priv->display.hotplug.stats[i].state = HPD_ENABLED;
610 * Interrupt setup is already guaranteed to be single-threaded, this is
611 * just to make the assert_spin_locked checks happy.
613 spin_lock_irq(&dev_priv->irq_lock);
614 intel_hpd_irq_setup(dev_priv);
615 spin_unlock_irq(&dev_priv->irq_lock);
618 static void i915_hpd_poll_init_work(struct work_struct *work)
620 struct drm_i915_private *dev_priv =
621 container_of(work, struct drm_i915_private,
622 display.hotplug.poll_init_work);
623 struct drm_connector_list_iter conn_iter;
624 struct intel_connector *connector;
627 mutex_lock(&dev_priv->drm.mode_config.mutex);
629 enabled = READ_ONCE(dev_priv->display.hotplug.poll_enabled);
631 drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
632 for_each_intel_connector_iter(connector, &conn_iter) {
635 pin = intel_connector_hpd_pin(connector);
639 connector->base.polled = connector->polled;
641 if (enabled && connector->base.polled == DRM_CONNECTOR_POLL_HPD)
642 connector->base.polled = DRM_CONNECTOR_POLL_CONNECT |
643 DRM_CONNECTOR_POLL_DISCONNECT;
645 drm_connector_list_iter_end(&conn_iter);
648 drm_kms_helper_poll_enable(&dev_priv->drm);
650 mutex_unlock(&dev_priv->drm.mode_config.mutex);
653 * We might have missed any hotplugs that happened while we were
654 * in the middle of disabling polling
657 drm_helper_hpd_irq_event(&dev_priv->drm);
661 * intel_hpd_poll_enable - enable polling for connectors with hpd
662 * @dev_priv: i915 device instance
664 * This function enables polling for all connectors which support HPD.
665 * Under certain conditions HPD may not be functional. On most Intel GPUs,
666 * this happens when we enter runtime suspend.
667 * On Valleyview and Cherryview systems, this also happens when we shut off all
670 * Since this function can get called in contexts where we're already holding
671 * dev->mode_config.mutex, we do the actual hotplug enabling in a seperate
674 * Also see: intel_hpd_init() and intel_hpd_poll_disable().
676 void intel_hpd_poll_enable(struct drm_i915_private *dev_priv)
678 if (!HAS_DISPLAY(dev_priv) ||
679 !INTEL_DISPLAY_ENABLED(dev_priv))
682 WRITE_ONCE(dev_priv->display.hotplug.poll_enabled, true);
685 * We might already be holding dev->mode_config.mutex, so do this in a
687 * As well, there's no issue if we race here since we always reschedule
690 schedule_work(&dev_priv->display.hotplug.poll_init_work);
694 * intel_hpd_poll_disable - disable polling for connectors with hpd
695 * @dev_priv: i915 device instance
697 * This function disables polling for all connectors which support HPD.
698 * Under certain conditions HPD may not be functional. On most Intel GPUs,
699 * this happens when we enter runtime suspend.
700 * On Valleyview and Cherryview systems, this also happens when we shut off all
703 * Since this function can get called in contexts where we're already holding
704 * dev->mode_config.mutex, we do the actual hotplug enabling in a seperate
707 * Also used during driver init to initialize connector->polled
708 * appropriately for all connectors.
710 * Also see: intel_hpd_init() and intel_hpd_poll_enable().
712 void intel_hpd_poll_disable(struct drm_i915_private *dev_priv)
714 if (!HAS_DISPLAY(dev_priv))
717 WRITE_ONCE(dev_priv->display.hotplug.poll_enabled, false);
718 schedule_work(&dev_priv->display.hotplug.poll_init_work);
721 void intel_hpd_init_early(struct drm_i915_private *i915)
723 INIT_DELAYED_WORK(&i915->display.hotplug.hotplug_work,
724 i915_hotplug_work_func);
725 INIT_WORK(&i915->display.hotplug.dig_port_work, i915_digport_work_func);
726 INIT_WORK(&i915->display.hotplug.poll_init_work, i915_hpd_poll_init_work);
727 INIT_DELAYED_WORK(&i915->display.hotplug.reenable_work,
728 intel_hpd_irq_storm_reenable_work);
730 i915->display.hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
731 /* If we have MST support, we want to avoid doing short HPD IRQ storm
732 * detection, as short HPD storms will occur as a natural part of
733 * sideband messaging with MST.
734 * On older platforms however, IRQ storms can occur with both long and
735 * short pulses, as seen on some G4x systems.
737 i915->display.hotplug.hpd_short_storm_enabled = !HAS_DP_MST(i915);
740 void intel_hpd_cancel_work(struct drm_i915_private *dev_priv)
742 if (!HAS_DISPLAY(dev_priv))
745 spin_lock_irq(&dev_priv->irq_lock);
747 dev_priv->display.hotplug.long_port_mask = 0;
748 dev_priv->display.hotplug.short_port_mask = 0;
749 dev_priv->display.hotplug.event_bits = 0;
750 dev_priv->display.hotplug.retry_bits = 0;
752 spin_unlock_irq(&dev_priv->irq_lock);
754 cancel_work_sync(&dev_priv->display.hotplug.dig_port_work);
755 cancel_delayed_work_sync(&dev_priv->display.hotplug.hotplug_work);
756 cancel_work_sync(&dev_priv->display.hotplug.poll_init_work);
757 cancel_delayed_work_sync(&dev_priv->display.hotplug.reenable_work);
760 bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
767 spin_lock_irq(&dev_priv->irq_lock);
768 if (dev_priv->display.hotplug.stats[pin].state == HPD_ENABLED) {
769 dev_priv->display.hotplug.stats[pin].state = HPD_DISABLED;
772 spin_unlock_irq(&dev_priv->irq_lock);
777 void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
782 spin_lock_irq(&dev_priv->irq_lock);
783 dev_priv->display.hotplug.stats[pin].state = HPD_ENABLED;
784 spin_unlock_irq(&dev_priv->irq_lock);
787 static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
789 struct drm_i915_private *dev_priv = m->private;
790 struct intel_hotplug *hotplug = &dev_priv->display.hotplug;
792 /* Synchronize with everything first in case there's been an HPD
793 * storm, but we haven't finished handling it in the kernel yet
795 intel_synchronize_irq(dev_priv);
796 flush_work(&dev_priv->display.hotplug.dig_port_work);
797 flush_delayed_work(&dev_priv->display.hotplug.hotplug_work);
799 seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
800 seq_printf(m, "Detected: %s\n",
801 str_yes_no(delayed_work_pending(&hotplug->reenable_work)));
806 static ssize_t i915_hpd_storm_ctl_write(struct file *file,
807 const char __user *ubuf, size_t len,
810 struct seq_file *m = file->private_data;
811 struct drm_i915_private *dev_priv = m->private;
812 struct intel_hotplug *hotplug = &dev_priv->display.hotplug;
813 unsigned int new_threshold;
818 if (len >= sizeof(tmp))
821 if (copy_from_user(tmp, ubuf, len))
826 /* Strip newline, if any */
827 newline = strchr(tmp, '\n');
831 if (strcmp(tmp, "reset") == 0)
832 new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
833 else if (kstrtouint(tmp, 10, &new_threshold) != 0)
836 if (new_threshold > 0)
837 drm_dbg_kms(&dev_priv->drm,
838 "Setting HPD storm detection threshold to %d\n",
841 drm_dbg_kms(&dev_priv->drm, "Disabling HPD storm detection\n");
843 spin_lock_irq(&dev_priv->irq_lock);
844 hotplug->hpd_storm_threshold = new_threshold;
845 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
847 hotplug->stats[i].count = 0;
848 spin_unlock_irq(&dev_priv->irq_lock);
850 /* Re-enable hpd immediately if we were in an irq storm */
851 flush_delayed_work(&dev_priv->display.hotplug.reenable_work);
856 static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
858 return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
861 static const struct file_operations i915_hpd_storm_ctl_fops = {
862 .owner = THIS_MODULE,
863 .open = i915_hpd_storm_ctl_open,
866 .release = single_release,
867 .write = i915_hpd_storm_ctl_write
870 static int i915_hpd_short_storm_ctl_show(struct seq_file *m, void *data)
872 struct drm_i915_private *dev_priv = m->private;
874 seq_printf(m, "Enabled: %s\n",
875 str_yes_no(dev_priv->display.hotplug.hpd_short_storm_enabled));
881 i915_hpd_short_storm_ctl_open(struct inode *inode, struct file *file)
883 return single_open(file, i915_hpd_short_storm_ctl_show,
887 static ssize_t i915_hpd_short_storm_ctl_write(struct file *file,
888 const char __user *ubuf,
889 size_t len, loff_t *offp)
891 struct seq_file *m = file->private_data;
892 struct drm_i915_private *dev_priv = m->private;
893 struct intel_hotplug *hotplug = &dev_priv->display.hotplug;
899 if (len >= sizeof(tmp))
902 if (copy_from_user(tmp, ubuf, len))
907 /* Strip newline, if any */
908 newline = strchr(tmp, '\n');
912 /* Reset to the "default" state for this system */
913 if (strcmp(tmp, "reset") == 0)
914 new_state = !HAS_DP_MST(dev_priv);
915 else if (kstrtobool(tmp, &new_state) != 0)
918 drm_dbg_kms(&dev_priv->drm, "%sabling HPD short storm detection\n",
919 new_state ? "En" : "Dis");
921 spin_lock_irq(&dev_priv->irq_lock);
922 hotplug->hpd_short_storm_enabled = new_state;
923 /* Reset the HPD storm stats so we don't accidentally trigger a storm */
925 hotplug->stats[i].count = 0;
926 spin_unlock_irq(&dev_priv->irq_lock);
928 /* Re-enable hpd immediately if we were in an irq storm */
929 flush_delayed_work(&dev_priv->display.hotplug.reenable_work);
934 static const struct file_operations i915_hpd_short_storm_ctl_fops = {
935 .owner = THIS_MODULE,
936 .open = i915_hpd_short_storm_ctl_open,
939 .release = single_release,
940 .write = i915_hpd_short_storm_ctl_write,
943 void intel_hpd_debugfs_register(struct drm_i915_private *i915)
945 struct drm_minor *minor = i915->drm.primary;
947 debugfs_create_file("i915_hpd_storm_ctl", 0644, minor->debugfs_root,
948 i915, &i915_hpd_storm_ctl_fops);
949 debugfs_create_file("i915_hpd_short_storm_ctl", 0644, minor->debugfs_root,
950 i915, &i915_hpd_short_storm_ctl_fops);
951 debugfs_create_bool("i915_ignore_long_hpd", 0644, minor->debugfs_root,
952 &i915->display.hotplug.ignore_long_hpd);