/* * Copyright © 2015 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ #include <linux/kernel.h> #include "i915_drv.h" #include "i915_irq.h" #include "intel_display_power.h" #include "intel_display_types.h" #include "intel_hotplug.h" #include "intel_hotplug_irq.h" /** * 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. * @dev_priv: private driver data pointer * @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(struct drm_i915_private *dev_priv, enum port port) { … } /* Threshold == 5 for long IRQs, 50 for short */ #define HPD_STORM_DEFAULT_THRESHOLD … #define HPD_STORM_DETECT_PERIOD … #define HPD_STORM_REENABLE_DELAY … #define HPD_RETRY_DELAY … static enum hpd_pin intel_connector_hpd_pin(struct intel_connector *connector) { … } /** * intel_hpd_irq_storm_detect - gather stats and detect HPD IRQ storm on a pin * @dev_priv: private driver data pointer * @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 @dev_priv->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 * &dev_priv->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. */ static bool intel_hpd_irq_storm_detect(struct drm_i915_private *dev_priv, enum hpd_pin pin, bool long_hpd) { … } static bool detection_work_enabled(struct drm_i915_private *i915) { … } static bool mod_delayed_detection_work(struct drm_i915_private *i915, struct delayed_work *work, int delay) { … } static bool queue_delayed_detection_work(struct drm_i915_private *i915, struct delayed_work *work, int delay) { … } static bool queue_detection_work(struct drm_i915_private *i915, struct work_struct *work) { … } static void intel_hpd_irq_storm_switch_to_polling(struct drm_i915_private *dev_priv) { … } static void intel_hpd_irq_storm_reenable_work(struct work_struct *work) { … } static enum intel_hotplug_state intel_hotplug_detect_connector(struct intel_connector *connector) { … } enum intel_hotplug_state intel_encoder_hotplug(struct intel_encoder *encoder, struct intel_connector *connector) { … } static bool intel_encoder_has_hpd_pulse(struct intel_encoder *encoder) { … } static void i915_digport_work_func(struct work_struct *work) { … } /** * 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) { … } /* * Handle hotplug events outside the interrupt handler proper. */ static void i915_hotplug_work_func(struct work_struct *work) { … } /** * intel_hpd_irq_handler - main hotplug irq handler * @dev_priv: drm_i915_private * @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 drm_i915_private *dev_priv, u32 pin_mask, u32 long_mask) { … } /** * intel_hpd_init - initializes and enables hpd support * @dev_priv: i915 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 drm_i915_private *dev_priv) { … } static void i915_hpd_poll_detect_connectors(struct drm_i915_private *i915) { … } static void i915_hpd_poll_init_work(struct work_struct *work) { … } /** * intel_hpd_poll_enable - enable polling for connectors with hpd * @dev_priv: i915 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 seperate * worker. * * Also see: intel_hpd_init() and intel_hpd_poll_disable(). */ void intel_hpd_poll_enable(struct drm_i915_private *dev_priv) { … } /** * intel_hpd_poll_disable - disable polling for connectors with hpd * @dev_priv: i915 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 seperate * 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 drm_i915_private *dev_priv) { … } void intel_hpd_init_early(struct drm_i915_private *i915) { … } static bool cancel_all_detection_work(struct drm_i915_private *i915) { … } void intel_hpd_cancel_work(struct drm_i915_private *dev_priv) { … } bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin) { … } void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin) { … } static void queue_work_for_missed_irqs(struct drm_i915_private *i915) { … } void intel_hpd_enable_detection_work(struct drm_i915_private *i915) { … } void intel_hpd_disable_detection_work(struct drm_i915_private *i915) { … } bool intel_hpd_schedule_detection(struct drm_i915_private *i915) { … } static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data) { … } static ssize_t i915_hpd_storm_ctl_write(struct file *file, const char __user *ubuf, size_t len, loff_t *offp) { … } static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file) { … } static const struct file_operations i915_hpd_storm_ctl_fops = …; static int i915_hpd_short_storm_ctl_show(struct seq_file *m, void *data) { … } static int i915_hpd_short_storm_ctl_open(struct inode *inode, struct file *file) { … } static ssize_t i915_hpd_short_storm_ctl_write(struct file *file, const char __user *ubuf, size_t len, loff_t *offp) { … } static const struct file_operations i915_hpd_short_storm_ctl_fops = …; void intel_hpd_debugfs_register(struct drm_i915_private *i915) { … }