/** * DOC: Hotplug * * Simply put, hotplug occurs when a display is connected to or disconnected * from the system. However, there may be adapters and docking stations and * Display Port short pulses and MST devices involved, complicating matters. * * Hotplug in i915 is handled in many different levels of abstraction. * * The platform dependent interrupt handling code in i915_irq.c enables, * disables, and does preliminary handling of the interrupts. The interrupt * handlers gather the hotplug detect (HPD) information from relevant registers * into a platform independent mask of hotplug pins that have fired. * * The platform independent interrupt handler intel_hpd_irq_handler() in * intel_hotplug.c does hotplug irq storm detection and mitigation, and passes * further processing to appropriate bottom halves (Display Port specific and * regular hotplug). * * The Display Port work function i915_digport_work_func() calls into * intel_dp_hpd_pulse() via hooks, which handles DP short pulses and DP MST long * pulses, with failures and non-MST long pulses triggering regular hotplug * processing on the connector. * * The regular hotplug work function i915_hotplug_work_func() calls connector * detect hooks, and, if connector status changes, triggers sending of hotplug * uevent to userspace via drm_kms_helper_hotplug_event(). * * Finally, the userspace is responsible for triggering a modeset upon receiving * the hotplug uevent, disabling or enabling the crtc as needed. * * The hotplug interrupt storm detection and mitigation code keeps track of the * number of interrupts per hotplug pin per a period of time, and if the number * of interrupts exceeds a certain threshold, the interrupt is disabled for a * while before being re-enabled. The intention is to mitigate issues raising * from broken hardware triggering massive amounts of interrupts and grinding * the system to a halt. * * Current implementation expects that hotplug interrupt storm will not be * seen when display port sink is connected, hence on platforms whose DP * callback is handled by i915_digport_work_func reenabling of hpd is not * performed (it was never expected to be disabled in the first place ;) ) * this is specific to DP sinks handled by this routine and any other display * such as HDMI or DVI enabled on the same port will have proper logic since * it will use i915_hotplug_work_func where this logic is handled.
*/
/** * intel_hpd_pin_default - return default pin associated with certain port. * @port: the hpd port to get associated pin * * It is only valid and used by digital port encoder. * * Return pin that is associatade with @port.
*/ enum hpd_pin intel_hpd_pin_default(enum port port)
{ return HPD_PORT_A + port - PORT_A;
}
/* Threshold == 5 for long IRQs, 50 for short */ #define HPD_STORM_DEFAULT_THRESHOLD 50
/* * MST connectors get their encoder attached dynamically * so need to make sure we have an encoder here. But since * MST encoders have their hpd_pin set to HPD_NONE we don't * have to special case them beyond that.
*/ return encoder ? encoder->hpd_pin : HPD_NONE;
}
/** * intel_hpd_irq_storm_detect - gather stats and detect HPD IRQ storm on a pin * @display: display device * @pin: the pin to gather stats on * @long_hpd: whether the HPD IRQ was long or short * * Gather stats about HPD IRQs from the specified @pin, and detect IRQ * storms. Only the pin specific stats and state are changed, the caller is * responsible for further action. * * The number of IRQs that are allowed within @HPD_STORM_DETECT_PERIOD is * stored in @display->hotplug.hpd_storm_threshold which defaults to * @HPD_STORM_DEFAULT_THRESHOLD. Long IRQs count as +10 to this threshold, and * short IRQs count as +1. If this threshold is exceeded, it's considered an * IRQ storm and the IRQ state is set to @HPD_MARK_DISABLED. * * By default, most systems will only count long IRQs towards * &display->hotplug.hpd_storm_threshold. However, some older systems also * suffer from short IRQ storms and must also track these. Because short IRQ * storms are naturally caused by sideband interactions with DP MST devices, * short IRQ detection is only enabled for systems without DP MST support. * Systems which are new enough to support DP MST are far less likely to * suffer from IRQ storms at all, so this is fine. * * The HPD threshold can be controlled through i915_hpd_storm_ctl in debugfs, * and should only be adjusted for automated hotplug testing. * * Return true if an IRQ storm was detected on @pin.
*/ staticbool intel_hpd_irq_storm_detect(struct intel_display *display, enum hpd_pin pin, bool long_hpd)
{ struct intel_hotplug *hpd = &display->hotplug; unsignedlong start = hpd->stats[pin].last_jiffies; unsignedlong end = start + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD); constint increment = long_hpd ? 10 : 1; constint threshold = hpd->hpd_storm_threshold; bool storm = false;
if (!threshold ||
(!long_hpd && !display->hotplug.hpd_short_storm_enabled)) returnfalse;
/** * intel_hpd_trigger_irq - trigger an hpd irq event for a port * @dig_port: digital port * * Trigger an HPD interrupt event for the given port, emulating a short pulse * generated by the sink, and schedule the dig port work to handle it.
*/ void intel_hpd_trigger_irq(struct intel_digital_port *dig_port)
{ struct intel_display *display = to_intel_display(dig_port); struct intel_hotplug *hotplug = &display->hotplug; struct intel_encoder *encoder = &dig_port->base;
spin_lock_irq(&display->irq.lock);
hotplug->short_hpd_pin_mask |= BIT(encoder->hpd_pin); if (!hpd_pin_is_blocked(display, encoder->hpd_pin))
queue_work(hotplug->dp_wq, &hotplug->dig_port_work);
/** * intel_hpd_irq_handler - main hotplug irq handler * @display: display device * @pin_mask: a mask of hpd pins that have triggered the irq * @long_mask: a mask of hpd pins that may be long hpd pulses * * This is the main hotplug irq handler for all platforms. The platform specific * irq handlers call the platform specific hotplug irq handlers, which read and * decode the appropriate registers into bitmasks about hpd pins that have * triggered (@pin_mask), and which of those pins may be long pulses * (@long_mask). The @long_mask is ignored if the port corresponding to the pin * is not a digital port. * * Here, we do hotplug irq storm detection and mitigation, and pass further * processing to appropriate bottom halves.
*/ void intel_hpd_irq_handler(struct intel_display *display,
u32 pin_mask, u32 long_mask)
{ struct intel_encoder *encoder; bool storm_detected = false; bool queue_dig = false, queue_hp = false;
u32 long_hpd_pulse_mask = 0;
u32 short_hpd_pulse_mask = 0; enum hpd_pin pin;
if (!pin_mask) return;
spin_lock(&display->irq.lock);
/* * Determine whether ->hpd_pulse() exists for each pin, and * whether we have a short or a long pulse. This is needed * as each pin may have up to two encoders (HDMI and DP) and * only the one of them (DP) will have ->hpd_pulse().
*/
for_each_intel_encoder(display->drm, encoder) { bool long_hpd;
pin = encoder->hpd_pin; if (!(BIT(pin) & pin_mask)) continue;
if (!intel_encoder_has_hpd_pulse(encoder)) continue;
/* Now process each pin just once */
for_each_hpd_pin(pin) { bool long_hpd;
if (!(BIT(pin) & pin_mask)) continue;
if (display->hotplug.stats[pin].state == HPD_DISABLED) { /* * On GMCH platforms the interrupt mask bits only * prevent irq generation, not the setting of the * hotplug bits itself. So only WARN about unexpected * interrupts on saner platforms.
*/
drm_WARN_ONCE(display->drm, !HAS_GMCH(display), "Received HPD interrupt on pin %d although disabled\n",
pin); continue;
}
if (display->hotplug.stats[pin].state != HPD_ENABLED) continue;
/* * Delegate to ->hpd_pulse() if one of the encoders for this * pin has it, otherwise let the hotplug_work deal with this * pin directly.
*/ if (((short_hpd_pulse_mask | long_hpd_pulse_mask) & BIT(pin))) {
long_hpd = long_hpd_pulse_mask & BIT(pin);
} else {
display->hotplug.event_bits |= BIT(pin);
long_hpd = true;
if (!hpd_pin_is_blocked(display, pin))
queue_hp = true;
}
/* * Disable any IRQs that storms were detected on. Polling enablement * happens later in our hotplug work.
*/ if (storm_detected)
intel_hpd_irq_setup(display);
/* * Our hotplug handler can grab modeset locks (by calling down into the * fb helpers). Hence it must not be run on our own dev-priv->wq work * queue for otherwise the flush_work in the pageflip code will * deadlock.
*/ if (queue_dig)
queue_work(display->hotplug.dp_wq, &display->hotplug.dig_port_work); if (queue_hp)
queue_delayed_detection_work(display,
&display->hotplug.hotplug_work, 0);
spin_unlock(&display->irq.lock);
}
/** * intel_hpd_init - initializes and enables hpd support * @display: display device instance * * This function enables the hotplug support. It requires that interrupts have * already been enabled with intel_irq_init_hw(). From this point on hotplug and * poll request can run concurrently to other code, so locking rules must be * obeyed. * * This is a separate step from interrupt enabling to simplify the locking rules * in the driver load and resume code. * * Also see: intel_hpd_poll_enable() and intel_hpd_poll_disable().
*/ void intel_hpd_init(struct intel_display *display)
{ int i;
/* * Interrupt setup is already guaranteed to be single-threaded, this is * just to make the assert_spin_locked checks happy.
*/
spin_lock_irq(&display->irq.lock);
intel_hpd_irq_setup(display);
spin_unlock_irq(&display->irq.lock);
}
enabled = READ_ONCE(display->hotplug.poll_enabled); /* * Prevent taking a power reference from this sequence of * i915_hpd_poll_init_work() -> drm_helper_hpd_irq_event() -> * connector detect which would requeue i915_hpd_poll_init_work() * and so risk an endless loop of this same sequence.
*/ if (!enabled) {
wakeref = intel_display_power_get(display,
POWER_DOMAIN_DISPLAY_CORE);
drm_WARN_ON(display->drm,
READ_ONCE(display->hotplug.poll_enabled));
cancel_work(&display->hotplug.poll_init_work);
}
if (enabled)
drm_kms_helper_poll_reschedule(display->drm);
mutex_unlock(&display->drm->mode_config.mutex);
/* * We might have missed any hotplugs that happened while we were * in the middle of disabling polling
*/ if (!enabled) {
i915_hpd_poll_detect_connectors(display);
/** * intel_hpd_poll_enable - enable polling for connectors with hpd * @display: display device instance * * This function enables polling for all connectors which support HPD. * Under certain conditions HPD may not be functional. On most Intel GPUs, * this happens when we enter runtime suspend. * On Valleyview and Cherryview systems, this also happens when we shut off all * of the powerwells. * * Since this function can get called in contexts where we're already holding * dev->mode_config.mutex, we do the actual hotplug enabling in a separate * worker. * * Also see: intel_hpd_init() and intel_hpd_poll_disable().
*/ void intel_hpd_poll_enable(struct intel_display *display)
{ if (!HAS_DISPLAY(display) || !intel_display_device_enabled(display)) return;
WRITE_ONCE(display->hotplug.poll_enabled, true);
/* * We might already be holding dev->mode_config.mutex, so do this in a * separate worker * As well, there's no issue if we race here since we always reschedule * this worker anyway
*/
spin_lock_irq(&display->irq.lock);
queue_detection_work(display,
&display->hotplug.poll_init_work);
spin_unlock_irq(&display->irq.lock);
}
/** * intel_hpd_poll_disable - disable polling for connectors with hpd * @display: display device instance * * This function disables polling for all connectors which support HPD. * Under certain conditions HPD may not be functional. On most Intel GPUs, * this happens when we enter runtime suspend. * On Valleyview and Cherryview systems, this also happens when we shut off all * of the powerwells. * * Since this function can get called in contexts where we're already holding * dev->mode_config.mutex, we do the actual hotplug enabling in a separate * worker. * * Also used during driver init to initialize connector->polled * appropriately for all connectors. * * Also see: intel_hpd_init() and intel_hpd_poll_enable().
*/ void intel_hpd_poll_disable(struct intel_display *display)
{ struct intel_encoder *encoder;
/* Kill all the work that may have been queued by hpd. */
drm_connector_list_iter_begin(display->drm, &conn_iter);
for_each_intel_connector_iter(connector, &conn_iter) {
intel_connector_cancel_modeset_retry_work(connector);
intel_hdcp_cancel_works(connector);
}
drm_connector_list_iter_end(&conn_iter);
}
display->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD; /* If we have MST support, we want to avoid doing short HPD IRQ storm * detection, as short HPD storms will occur as a natural part of * sideband messaging with MST. * On older platforms however, IRQ storms can occur with both long and * short pulses, as seen on some G4x systems.
*/
display->hotplug.hpd_short_storm_enabled = !HAS_DP_MST(display);
}
if (cancel_delayed_work_sync(&display->hotplug.hotplug_work))
was_pending = true; if (cancel_work_sync(&display->hotplug.poll_init_work))
was_pending = true; if (cancel_delayed_work_sync(&display->hotplug.reenable_work))
was_pending = true;
return was_pending;
}
void intel_hpd_cancel_work(struct intel_display *display)
{ if (!HAS_DISPLAY(display)) return;
/* * All other work triggered by hotplug events should be canceled by * now.
*/ if (cancel_all_detection_work(display))
drm_dbg_kms(display->drm, "Hotplug detection work still active\n");
}
if (drm_WARN_ON(display->drm, hotplug->stats[pin].blocked_count == 0)) returntrue;
hotplug->stats[pin].blocked_count--;
return hotplug->stats[pin].blocked_count == 0;
}
/** * intel_hpd_block - Block handling of HPD IRQs on an HPD pin * @encoder: Encoder to block the HPD handling for * * Blocks the handling of HPD IRQs on the HPD pin of @encoder. * * On return: * * - It's guaranteed that the blocked encoders' HPD pulse handler * (via intel_digital_port::hpd_pulse()) is not running. * - The hotplug event handling (via intel_encoder::hotplug()) of an * HPD IRQ pending at the time this function is called may be still * running. * - Detection on the encoder's connector (via * drm_connector_helper_funcs::detect_ctx(), * drm_connector_funcs::detect()) remains allowed, for instance as part of * userspace connector probing, or DRM core's connector polling. * * The call must be followed by calling intel_hpd_unblock(), or * intel_hpd_clear_and_unblock(). * * Note that the handling of HPD IRQs for another encoder using the same HPD * pin as that of @encoder will be also blocked.
*/ void intel_hpd_block(struct intel_encoder *encoder)
{ struct intel_display *display = to_intel_display(encoder); struct intel_hotplug *hotplug = &display->hotplug; bool do_flush = false;
if (encoder->hpd_pin == HPD_NONE) return;
spin_lock_irq(&display->irq.lock);
if (block_hpd_pin(display, encoder->hpd_pin))
do_flush = true;
spin_unlock_irq(&display->irq.lock);
if (do_flush && hpd_pin_has_pulse(display, encoder->hpd_pin))
flush_work(&hotplug->dig_port_work);
}
/** * intel_hpd_unblock - Unblock handling of HPD IRQs on an HPD pin * @encoder: Encoder to unblock the HPD handling for * * Unblock the handling of HPD IRQs on the HPD pin of @encoder, which was * previously blocked by intel_hpd_block(). Any HPD IRQ raised on the * HPD pin while it was blocked will be handled for @encoder and for any * other encoder sharing the same HPD pin.
*/ void intel_hpd_unblock(struct intel_encoder *encoder)
{ struct intel_display *display = to_intel_display(encoder);
if (encoder->hpd_pin == HPD_NONE) return;
spin_lock_irq(&display->irq.lock);
if (unblock_hpd_pin(display, encoder->hpd_pin))
queue_work_for_missed_irqs(display);
spin_unlock_irq(&display->irq.lock);
}
/** * intel_hpd_clear_and_unblock - Unblock handling of new HPD IRQs on an HPD pin * @encoder: Encoder to unblock the HPD handling for * * Unblock the handling of HPD IRQs on the HPD pin of @encoder, which was * previously blocked by intel_hpd_block(). Any HPD IRQ raised on the * HPD pin while it was blocked will be cleared, handling only new IRQs.
*/ void intel_hpd_clear_and_unblock(struct intel_encoder *encoder)
{ struct intel_display *display = to_intel_display(encoder); struct intel_hotplug *hotplug = &display->hotplug; enum hpd_pin pin = encoder->hpd_pin;
/* Synchronize with everything first in case there's been an HPD * storm, but we haven't finished handling it in the kernel yet
*/
intel_synchronize_irq(dev_priv);
flush_work(&display->hotplug.dig_port_work);
flush_delayed_work(&display->hotplug.hotplug_work);
if (copy_from_user(tmp, ubuf, len)) return -EFAULT;
tmp[len] = '\0';
/* Strip newline, if any */
newline = strchr(tmp, '\n'); if (newline)
*newline = '\0';
/* Reset to the "default" state for this system */ if (strcmp(tmp, "reset") == 0)
new_state = !HAS_DP_MST(display); elseif (kstrtobool(tmp, &new_state) != 0) return -EINVAL;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.