Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2015 Intel Corporation |
| 3 | * |
| 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: |
| 10 | * |
| 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 |
| 13 | * Software. |
| 14 | * |
| 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 |
| 21 | * IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | |
| 26 | #include <drm/drmP.h> |
| 27 | #include <drm/i915_drm.h> |
| 28 | |
| 29 | #include "i915_drv.h" |
| 30 | #include "intel_drv.h" |
| 31 | |
Jani Nikula | 856974a | 2015-07-02 16:05:28 +0300 | [diff] [blame] | 32 | /** |
| 33 | * DOC: Hotplug |
| 34 | * |
| 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. |
| 38 | * |
| 39 | * Hotplug in i915 is handled in many different levels of abstraction. |
| 40 | * |
| 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. |
| 45 | * |
| 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 |
| 49 | * regular hotplug). |
| 50 | * |
| 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. |
| 55 | * |
| 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(). |
| 59 | * |
| 60 | * Finally, the userspace is responsible for triggering a modeset upon receiving |
| 61 | * the hotplug uevent, disabling or enabling the crtc as needed. |
| 62 | * |
| 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. |
Thulasimani,Sivakumar | feecb69 | 2015-07-10 12:30:43 +0530 | [diff] [blame] | 69 | * |
| 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. |
Jani Nikula | 856974a | 2015-07-02 16:05:28 +0300 | [diff] [blame] | 77 | */ |
| 78 | |
Rodrigo Vivi | 256cfdde | 2017-08-11 11:26:49 -0700 | [diff] [blame] | 79 | /** |
| 80 | * intel_hpd_port - return port hard associated with certain pin. |
Rodrigo Vivi | cf53902 | 2018-01-29 15:22:21 -0800 | [diff] [blame] | 81 | * @dev_priv: private driver data pointer |
Rodrigo Vivi | 256cfdde | 2017-08-11 11:26:49 -0700 | [diff] [blame] | 82 | * @pin: the hpd pin to get associated port |
| 83 | * |
| 84 | * Return port that is associatade with @pin and PORT_NONE if no port is |
| 85 | * hard associated with that @pin. |
| 86 | */ |
Rodrigo Vivi | cf53902 | 2018-01-29 15:22:21 -0800 | [diff] [blame] | 87 | enum port intel_hpd_pin_to_port(struct drm_i915_private *dev_priv, |
| 88 | enum hpd_pin pin) |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 89 | { |
| 90 | switch (pin) { |
Imre Deak | cc24fcd | 2015-07-21 15:32:45 -0700 | [diff] [blame] | 91 | case HPD_PORT_A: |
Rodrigo Vivi | 256cfdde | 2017-08-11 11:26:49 -0700 | [diff] [blame] | 92 | return PORT_A; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 93 | case HPD_PORT_B: |
Rodrigo Vivi | 256cfdde | 2017-08-11 11:26:49 -0700 | [diff] [blame] | 94 | return PORT_B; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 95 | case HPD_PORT_C: |
Rodrigo Vivi | 256cfdde | 2017-08-11 11:26:49 -0700 | [diff] [blame] | 96 | return PORT_C; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 97 | case HPD_PORT_D: |
Rodrigo Vivi | 256cfdde | 2017-08-11 11:26:49 -0700 | [diff] [blame] | 98 | return PORT_D; |
Xiong Zhang | 26951ca | 2015-08-17 15:55:50 +0800 | [diff] [blame] | 99 | case HPD_PORT_E: |
Rodrigo Vivi | cf53902 | 2018-01-29 15:22:21 -0800 | [diff] [blame] | 100 | if (IS_CNL_WITH_PORT_F(dev_priv)) |
| 101 | return PORT_F; |
Rodrigo Vivi | 256cfdde | 2017-08-11 11:26:49 -0700 | [diff] [blame] | 102 | return PORT_E; |
Dhinakaran Pandiyan | 96ae483 | 2018-03-23 10:24:17 -0700 | [diff] [blame] | 103 | case HPD_PORT_F: |
| 104 | return PORT_F; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 105 | default: |
Rodrigo Vivi | 256cfdde | 2017-08-11 11:26:49 -0700 | [diff] [blame] | 106 | return PORT_NONE; /* no port for this pin */ |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
Rodrigo Vivi | f761bef2 | 2017-08-11 11:26:50 -0700 | [diff] [blame] | 110 | /** |
Rodrigo Vivi | cf53902 | 2018-01-29 15:22:21 -0800 | [diff] [blame] | 111 | * intel_hpd_pin_default - return default pin associated with certain port. |
| 112 | * @dev_priv: private driver data pointer |
Rodrigo Vivi | f761bef2 | 2017-08-11 11:26:50 -0700 | [diff] [blame] | 113 | * @port: the hpd port to get associated pin |
| 114 | * |
Rodrigo Vivi | cf53902 | 2018-01-29 15:22:21 -0800 | [diff] [blame] | 115 | * It is only valid and used by digital port encoder. |
| 116 | * |
Rodrigo Vivi | f761bef2 | 2017-08-11 11:26:50 -0700 | [diff] [blame] | 117 | * Return pin that is associatade with @port and HDP_NONE if no pin is |
| 118 | * hard associated with that @port. |
| 119 | */ |
Rodrigo Vivi | cf53902 | 2018-01-29 15:22:21 -0800 | [diff] [blame] | 120 | enum hpd_pin intel_hpd_pin_default(struct drm_i915_private *dev_priv, |
| 121 | enum port port) |
Rodrigo Vivi | f761bef2 | 2017-08-11 11:26:50 -0700 | [diff] [blame] | 122 | { |
| 123 | switch (port) { |
| 124 | case PORT_A: |
| 125 | return HPD_PORT_A; |
| 126 | case PORT_B: |
| 127 | return HPD_PORT_B; |
| 128 | case PORT_C: |
| 129 | return HPD_PORT_C; |
| 130 | case PORT_D: |
| 131 | return HPD_PORT_D; |
| 132 | case PORT_E: |
| 133 | return HPD_PORT_E; |
Rodrigo Vivi | cf53902 | 2018-01-29 15:22:21 -0800 | [diff] [blame] | 134 | case PORT_F: |
| 135 | if (IS_CNL_WITH_PORT_F(dev_priv)) |
| 136 | return HPD_PORT_E; |
Dhinakaran Pandiyan | 96ae483 | 2018-03-23 10:24:17 -0700 | [diff] [blame] | 137 | return HPD_PORT_F; |
Rodrigo Vivi | f761bef2 | 2017-08-11 11:26:50 -0700 | [diff] [blame] | 138 | default: |
| 139 | MISSING_CASE(port); |
| 140 | return HPD_NONE; |
| 141 | } |
| 142 | } |
| 143 | |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 144 | #define HPD_STORM_DETECT_PERIOD 1000 |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 145 | #define HPD_STORM_REENABLE_DELAY (2 * 60 * 1000) |
| 146 | |
| 147 | /** |
| 148 | * intel_hpd_irq_storm_detect - gather stats and detect HPD irq storm on a pin |
| 149 | * @dev_priv: private driver data pointer |
| 150 | * @pin: the pin to gather stats on |
| 151 | * |
| 152 | * Gather stats about HPD irqs from the specified @pin, and detect irq |
| 153 | * storms. Only the pin specific stats and state are changed, the caller is |
| 154 | * responsible for further action. |
| 155 | * |
Lyude | 317eaa9 | 2017-02-03 21:18:25 -0500 | [diff] [blame] | 156 | * The number of irqs that are allowed within @HPD_STORM_DETECT_PERIOD is |
| 157 | * stored in @dev_priv->hotplug.hpd_storm_threshold which defaults to |
| 158 | * @HPD_STORM_DEFAULT_THRESHOLD. If this threshold is exceeded, it's |
| 159 | * considered an irq storm and the irq state is set to @HPD_MARK_DISABLED. |
| 160 | * |
| 161 | * The HPD threshold can be controlled through i915_hpd_storm_ctl in debugfs, |
| 162 | * and should only be adjusted for automated hotplug testing. |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 163 | * |
| 164 | * Return true if an irq storm was detected on @pin. |
| 165 | */ |
| 166 | static bool intel_hpd_irq_storm_detect(struct drm_i915_private *dev_priv, |
| 167 | enum hpd_pin pin) |
| 168 | { |
| 169 | unsigned long start = dev_priv->hotplug.stats[pin].last_jiffies; |
| 170 | unsigned long end = start + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD); |
Lyude | 317eaa9 | 2017-02-03 21:18:25 -0500 | [diff] [blame] | 171 | const int threshold = dev_priv->hotplug.hpd_storm_threshold; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 172 | bool storm = false; |
| 173 | |
| 174 | if (!time_in_range(jiffies, start, end)) { |
| 175 | dev_priv->hotplug.stats[pin].last_jiffies = jiffies; |
| 176 | dev_priv->hotplug.stats[pin].count = 0; |
| 177 | DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", pin); |
Lyude | 317eaa9 | 2017-02-03 21:18:25 -0500 | [diff] [blame] | 178 | } else if (dev_priv->hotplug.stats[pin].count > threshold && |
| 179 | threshold) { |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 180 | dev_priv->hotplug.stats[pin].state = HPD_MARK_DISABLED; |
| 181 | DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", pin); |
| 182 | storm = true; |
| 183 | } else { |
| 184 | dev_priv->hotplug.stats[pin].count++; |
| 185 | DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", pin, |
| 186 | dev_priv->hotplug.stats[pin].count); |
| 187 | } |
| 188 | |
| 189 | return storm; |
| 190 | } |
| 191 | |
| 192 | static void intel_hpd_irq_storm_disable(struct drm_i915_private *dev_priv) |
| 193 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 194 | struct drm_device *dev = &dev_priv->drm; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 195 | struct intel_connector *intel_connector; |
| 196 | struct intel_encoder *intel_encoder; |
| 197 | struct drm_connector *connector; |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 198 | struct drm_connector_list_iter conn_iter; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 199 | enum hpd_pin pin; |
| 200 | bool hpd_disabled = false; |
| 201 | |
Chris Wilson | 6752041 | 2017-03-02 13:28:01 +0000 | [diff] [blame] | 202 | lockdep_assert_held(&dev_priv->irq_lock); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 203 | |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 204 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 205 | drm_for_each_connector_iter(connector, &conn_iter) { |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 206 | if (connector->polled != DRM_CONNECTOR_POLL_HPD) |
| 207 | continue; |
| 208 | |
| 209 | intel_connector = to_intel_connector(connector); |
| 210 | intel_encoder = intel_connector->encoder; |
| 211 | if (!intel_encoder) |
| 212 | continue; |
| 213 | |
| 214 | pin = intel_encoder->hpd_pin; |
| 215 | if (pin == HPD_NONE || |
| 216 | dev_priv->hotplug.stats[pin].state != HPD_MARK_DISABLED) |
| 217 | continue; |
| 218 | |
| 219 | DRM_INFO("HPD interrupt storm detected on connector %s: " |
| 220 | "switching from hotplug detection to polling\n", |
| 221 | connector->name); |
| 222 | |
| 223 | dev_priv->hotplug.stats[pin].state = HPD_DISABLED; |
| 224 | connector->polled = DRM_CONNECTOR_POLL_CONNECT |
| 225 | | DRM_CONNECTOR_POLL_DISCONNECT; |
| 226 | hpd_disabled = true; |
| 227 | } |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 228 | drm_connector_list_iter_end(&conn_iter); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 229 | |
| 230 | /* Enable polling and queue hotplug re-enabling. */ |
| 231 | if (hpd_disabled) { |
Dave Airlie | c4d79c2 | 2017-01-27 12:04:08 +1000 | [diff] [blame] | 232 | drm_kms_helper_poll_enable(dev); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 233 | mod_delayed_work(system_wq, &dev_priv->hotplug.reenable_work, |
| 234 | msecs_to_jiffies(HPD_STORM_REENABLE_DELAY)); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | static void intel_hpd_irq_storm_reenable_work(struct work_struct *work) |
| 239 | { |
| 240 | struct drm_i915_private *dev_priv = |
| 241 | container_of(work, typeof(*dev_priv), |
| 242 | hotplug.reenable_work.work); |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 243 | struct drm_device *dev = &dev_priv->drm; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 244 | int i; |
| 245 | |
| 246 | intel_runtime_pm_get(dev_priv); |
| 247 | |
| 248 | spin_lock_irq(&dev_priv->irq_lock); |
| 249 | for_each_hpd_pin(i) { |
| 250 | struct drm_connector *connector; |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 251 | struct drm_connector_list_iter conn_iter; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 252 | |
| 253 | if (dev_priv->hotplug.stats[i].state != HPD_DISABLED) |
| 254 | continue; |
| 255 | |
| 256 | dev_priv->hotplug.stats[i].state = HPD_ENABLED; |
| 257 | |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 258 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 259 | drm_for_each_connector_iter(connector, &conn_iter) { |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 260 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 261 | |
| 262 | if (intel_connector->encoder->hpd_pin == i) { |
| 263 | if (connector->polled != intel_connector->polled) |
| 264 | DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n", |
| 265 | connector->name); |
| 266 | connector->polled = intel_connector->polled; |
| 267 | if (!connector->polled) |
| 268 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
| 269 | } |
| 270 | } |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 271 | drm_connector_list_iter_end(&conn_iter); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 272 | } |
Chris Wilson | 262fd48 | 2017-02-15 13:15:47 +0000 | [diff] [blame] | 273 | if (dev_priv->display_irqs_enabled && dev_priv->display.hpd_irq_setup) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 274 | dev_priv->display.hpd_irq_setup(dev_priv); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 275 | spin_unlock_irq(&dev_priv->irq_lock); |
| 276 | |
| 277 | intel_runtime_pm_put(dev_priv); |
| 278 | } |
| 279 | |
Ville Syrjälä | dba14b2 | 2018-01-17 21:21:46 +0200 | [diff] [blame] | 280 | bool intel_encoder_hotplug(struct intel_encoder *encoder, |
| 281 | struct intel_connector *connector) |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 282 | { |
Ville Syrjälä | dba14b2 | 2018-01-17 21:21:46 +0200 | [diff] [blame] | 283 | struct drm_device *dev = connector->base.dev; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 284 | enum drm_connector_status old_status; |
| 285 | |
| 286 | WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); |
Ville Syrjälä | dba14b2 | 2018-01-17 21:21:46 +0200 | [diff] [blame] | 287 | old_status = connector->base.status; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 288 | |
Ville Syrjälä | dba14b2 | 2018-01-17 21:21:46 +0200 | [diff] [blame] | 289 | connector->base.status = |
| 290 | drm_helper_probe_detect(&connector->base, NULL, false); |
Maarten Lankhorst | 6c5ed5a | 2017-04-06 20:55:20 +0200 | [diff] [blame] | 291 | |
Ville Syrjälä | dba14b2 | 2018-01-17 21:21:46 +0200 | [diff] [blame] | 292 | if (old_status == connector->base.status) |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 293 | return false; |
| 294 | |
| 295 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n", |
Ville Syrjälä | dba14b2 | 2018-01-17 21:21:46 +0200 | [diff] [blame] | 296 | connector->base.base.id, |
| 297 | connector->base.name, |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 298 | drm_get_connector_status_name(old_status), |
Ville Syrjälä | dba14b2 | 2018-01-17 21:21:46 +0200 | [diff] [blame] | 299 | drm_get_connector_status_name(connector->base.status)); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 300 | |
| 301 | return true; |
| 302 | } |
| 303 | |
| 304 | static void i915_digport_work_func(struct work_struct *work) |
| 305 | { |
| 306 | struct drm_i915_private *dev_priv = |
| 307 | container_of(work, struct drm_i915_private, hotplug.dig_port_work); |
| 308 | u32 long_port_mask, short_port_mask; |
| 309 | struct intel_digital_port *intel_dig_port; |
| 310 | int i; |
| 311 | u32 old_bits = 0; |
| 312 | |
| 313 | spin_lock_irq(&dev_priv->irq_lock); |
| 314 | long_port_mask = dev_priv->hotplug.long_port_mask; |
| 315 | dev_priv->hotplug.long_port_mask = 0; |
| 316 | short_port_mask = dev_priv->hotplug.short_port_mask; |
| 317 | dev_priv->hotplug.short_port_mask = 0; |
| 318 | spin_unlock_irq(&dev_priv->irq_lock); |
| 319 | |
| 320 | for (i = 0; i < I915_MAX_PORTS; i++) { |
| 321 | bool valid = false; |
| 322 | bool long_hpd = false; |
| 323 | intel_dig_port = dev_priv->hotplug.irq_port[i]; |
| 324 | if (!intel_dig_port || !intel_dig_port->hpd_pulse) |
| 325 | continue; |
| 326 | |
| 327 | if (long_port_mask & (1 << i)) { |
| 328 | valid = true; |
| 329 | long_hpd = true; |
| 330 | } else if (short_port_mask & (1 << i)) |
| 331 | valid = true; |
| 332 | |
| 333 | if (valid) { |
| 334 | enum irqreturn ret; |
| 335 | |
| 336 | ret = intel_dig_port->hpd_pulse(intel_dig_port, long_hpd); |
| 337 | if (ret == IRQ_NONE) { |
| 338 | /* fall back to old school hpd */ |
| 339 | old_bits |= (1 << intel_dig_port->base.hpd_pin); |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | if (old_bits) { |
| 345 | spin_lock_irq(&dev_priv->irq_lock); |
| 346 | dev_priv->hotplug.event_bits |= old_bits; |
| 347 | spin_unlock_irq(&dev_priv->irq_lock); |
| 348 | schedule_work(&dev_priv->hotplug.hotplug_work); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | /* |
| 353 | * Handle hotplug events outside the interrupt handler proper. |
| 354 | */ |
| 355 | static void i915_hotplug_work_func(struct work_struct *work) |
| 356 | { |
| 357 | struct drm_i915_private *dev_priv = |
| 358 | container_of(work, struct drm_i915_private, hotplug.hotplug_work); |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 359 | struct drm_device *dev = &dev_priv->drm; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 360 | struct intel_connector *intel_connector; |
| 361 | struct intel_encoder *intel_encoder; |
| 362 | struct drm_connector *connector; |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 363 | struct drm_connector_list_iter conn_iter; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 364 | bool changed = false; |
| 365 | u32 hpd_event_bits; |
| 366 | |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 367 | mutex_lock(&dev->mode_config.mutex); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 368 | DRM_DEBUG_KMS("running encoder hotplug functions\n"); |
| 369 | |
| 370 | spin_lock_irq(&dev_priv->irq_lock); |
| 371 | |
| 372 | hpd_event_bits = dev_priv->hotplug.event_bits; |
| 373 | dev_priv->hotplug.event_bits = 0; |
| 374 | |
| 375 | /* Disable hotplug on connectors that hit an irq storm. */ |
| 376 | intel_hpd_irq_storm_disable(dev_priv); |
| 377 | |
| 378 | spin_unlock_irq(&dev_priv->irq_lock); |
| 379 | |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 380 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 381 | drm_for_each_connector_iter(connector, &conn_iter) { |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 382 | intel_connector = to_intel_connector(connector); |
| 383 | if (!intel_connector->encoder) |
| 384 | continue; |
| 385 | intel_encoder = intel_connector->encoder; |
| 386 | if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) { |
| 387 | DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n", |
| 388 | connector->name, intel_encoder->hpd_pin); |
Ville Syrjälä | dba14b2 | 2018-01-17 21:21:46 +0200 | [diff] [blame] | 389 | |
| 390 | changed |= intel_encoder->hotplug(intel_encoder, |
| 391 | intel_connector); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 392 | } |
| 393 | } |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 394 | drm_connector_list_iter_end(&conn_iter); |
| 395 | mutex_unlock(&dev->mode_config.mutex); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 396 | |
| 397 | if (changed) |
| 398 | drm_kms_helper_hotplug_event(dev); |
| 399 | } |
| 400 | |
| 401 | |
| 402 | /** |
| 403 | * intel_hpd_irq_handler - main hotplug irq handler |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 404 | * @dev_priv: drm_i915_private |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 405 | * @pin_mask: a mask of hpd pins that have triggered the irq |
| 406 | * @long_mask: a mask of hpd pins that may be long hpd pulses |
| 407 | * |
| 408 | * This is the main hotplug irq handler for all platforms. The platform specific |
| 409 | * irq handlers call the platform specific hotplug irq handlers, which read and |
| 410 | * decode the appropriate registers into bitmasks about hpd pins that have |
| 411 | * triggered (@pin_mask), and which of those pins may be long pulses |
| 412 | * (@long_mask). The @long_mask is ignored if the port corresponding to the pin |
| 413 | * is not a digital port. |
| 414 | * |
| 415 | * Here, we do hotplug irq storm detection and mitigation, and pass further |
| 416 | * processing to appropriate bottom halves. |
| 417 | */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 418 | void intel_hpd_irq_handler(struct drm_i915_private *dev_priv, |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 419 | u32 pin_mask, u32 long_mask) |
| 420 | { |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 421 | int i; |
| 422 | enum port port; |
| 423 | bool storm_detected = false; |
| 424 | bool queue_dig = false, queue_hp = false; |
| 425 | bool is_dig_port; |
| 426 | |
| 427 | if (!pin_mask) |
| 428 | return; |
| 429 | |
| 430 | spin_lock(&dev_priv->irq_lock); |
| 431 | for_each_hpd_pin(i) { |
| 432 | if (!(BIT(i) & pin_mask)) |
| 433 | continue; |
| 434 | |
Rodrigo Vivi | cf53902 | 2018-01-29 15:22:21 -0800 | [diff] [blame] | 435 | port = intel_hpd_pin_to_port(dev_priv, i); |
Rodrigo Vivi | 256cfdde | 2017-08-11 11:26:49 -0700 | [diff] [blame] | 436 | is_dig_port = port != PORT_NONE && |
| 437 | dev_priv->hotplug.irq_port[port]; |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 438 | |
| 439 | if (is_dig_port) { |
| 440 | bool long_hpd = long_mask & BIT(i); |
| 441 | |
| 442 | DRM_DEBUG_DRIVER("digital hpd port %c - %s\n", port_name(port), |
| 443 | long_hpd ? "long" : "short"); |
| 444 | /* |
| 445 | * For long HPD pulses we want to have the digital queue happen, |
| 446 | * but we still want HPD storm detection to function. |
| 447 | */ |
| 448 | queue_dig = true; |
| 449 | if (long_hpd) { |
| 450 | dev_priv->hotplug.long_port_mask |= (1 << port); |
| 451 | } else { |
| 452 | /* for short HPD just trigger the digital queue */ |
| 453 | dev_priv->hotplug.short_port_mask |= (1 << port); |
| 454 | continue; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | if (dev_priv->hotplug.stats[i].state == HPD_DISABLED) { |
| 459 | /* |
| 460 | * On GMCH platforms the interrupt mask bits only |
| 461 | * prevent irq generation, not the setting of the |
| 462 | * hotplug bits itself. So only WARN about unexpected |
| 463 | * interrupts on saner platforms. |
| 464 | */ |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 465 | WARN_ONCE(!HAS_GMCH_DISPLAY(dev_priv), |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 466 | "Received HPD interrupt on pin %d although disabled\n", i); |
| 467 | continue; |
| 468 | } |
| 469 | |
| 470 | if (dev_priv->hotplug.stats[i].state != HPD_ENABLED) |
| 471 | continue; |
| 472 | |
| 473 | if (!is_dig_port) { |
| 474 | dev_priv->hotplug.event_bits |= BIT(i); |
| 475 | queue_hp = true; |
| 476 | } |
| 477 | |
| 478 | if (intel_hpd_irq_storm_detect(dev_priv, i)) { |
| 479 | dev_priv->hotplug.event_bits &= ~BIT(i); |
| 480 | storm_detected = true; |
| 481 | } |
| 482 | } |
| 483 | |
Chris Wilson | 262fd48 | 2017-02-15 13:15:47 +0000 | [diff] [blame] | 484 | if (storm_detected && dev_priv->display_irqs_enabled) |
Tvrtko Ursulin | 91d1425 | 2016-05-06 14:48:28 +0100 | [diff] [blame] | 485 | dev_priv->display.hpd_irq_setup(dev_priv); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 486 | spin_unlock(&dev_priv->irq_lock); |
| 487 | |
| 488 | /* |
| 489 | * Our hotplug handler can grab modeset locks (by calling down into the |
| 490 | * fb helpers). Hence it must not be run on our own dev-priv->wq work |
| 491 | * queue for otherwise the flush_work in the pageflip code will |
| 492 | * deadlock. |
| 493 | */ |
| 494 | if (queue_dig) |
| 495 | queue_work(dev_priv->hotplug.dp_wq, &dev_priv->hotplug.dig_port_work); |
| 496 | if (queue_hp) |
| 497 | schedule_work(&dev_priv->hotplug.hotplug_work); |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * intel_hpd_init - initializes and enables hpd support |
| 502 | * @dev_priv: i915 device instance |
| 503 | * |
| 504 | * This function enables the hotplug support. It requires that interrupts have |
| 505 | * already been enabled with intel_irq_init_hw(). From this point on hotplug and |
| 506 | * poll request can run concurrently to other code, so locking rules must be |
| 507 | * obeyed. |
| 508 | * |
| 509 | * This is a separate step from interrupt enabling to simplify the locking rules |
| 510 | * in the driver load and resume code. |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 511 | * |
| 512 | * Also see: intel_hpd_poll_init(), which enables connector polling |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 513 | */ |
| 514 | void intel_hpd_init(struct drm_i915_private *dev_priv) |
| 515 | { |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 516 | int i; |
| 517 | |
| 518 | for_each_hpd_pin(i) { |
| 519 | dev_priv->hotplug.stats[i].count = 0; |
| 520 | dev_priv->hotplug.stats[i].state = HPD_ENABLED; |
| 521 | } |
Lyude | 07c5191 | 2016-01-07 10:43:28 -0500 | [diff] [blame] | 522 | |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 523 | WRITE_ONCE(dev_priv->hotplug.poll_enabled, false); |
| 524 | schedule_work(&dev_priv->hotplug.poll_init_work); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 525 | |
| 526 | /* |
| 527 | * Interrupt setup is already guaranteed to be single-threaded, this is |
| 528 | * just to make the assert_spin_locked checks happy. |
| 529 | */ |
Chris Wilson | 262fd48 | 2017-02-15 13:15:47 +0000 | [diff] [blame] | 530 | if (dev_priv->display_irqs_enabled && dev_priv->display.hpd_irq_setup) { |
| 531 | spin_lock_irq(&dev_priv->irq_lock); |
| 532 | if (dev_priv->display_irqs_enabled) |
| 533 | dev_priv->display.hpd_irq_setup(dev_priv); |
| 534 | spin_unlock_irq(&dev_priv->irq_lock); |
| 535 | } |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 536 | } |
| 537 | |
Chris Wilson | 24808e9 | 2016-08-17 12:09:06 +0100 | [diff] [blame] | 538 | static void i915_hpd_poll_init_work(struct work_struct *work) |
| 539 | { |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 540 | struct drm_i915_private *dev_priv = |
| 541 | container_of(work, struct drm_i915_private, |
| 542 | hotplug.poll_init_work); |
| 543 | struct drm_device *dev = &dev_priv->drm; |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 544 | struct drm_connector *connector; |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 545 | struct drm_connector_list_iter conn_iter; |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 546 | bool enabled; |
| 547 | |
| 548 | mutex_lock(&dev->mode_config.mutex); |
| 549 | |
| 550 | enabled = READ_ONCE(dev_priv->hotplug.poll_enabled); |
| 551 | |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 552 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 553 | drm_for_each_connector_iter(connector, &conn_iter) { |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 554 | struct intel_connector *intel_connector = |
| 555 | to_intel_connector(connector); |
| 556 | connector->polled = intel_connector->polled; |
| 557 | |
| 558 | /* MST has a dynamic intel_connector->encoder and it's reprobing |
| 559 | * is all handled by the MST helpers. */ |
| 560 | if (intel_connector->mst_port) |
| 561 | continue; |
| 562 | |
Tvrtko Ursulin | 56b857a | 2016-11-07 09:29:20 +0000 | [diff] [blame] | 563 | if (!connector->polled && I915_HAS_HOTPLUG(dev_priv) && |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 564 | intel_connector->encoder->hpd_pin > HPD_NONE) { |
| 565 | connector->polled = enabled ? |
| 566 | DRM_CONNECTOR_POLL_CONNECT | |
| 567 | DRM_CONNECTOR_POLL_DISCONNECT : |
| 568 | DRM_CONNECTOR_POLL_HPD; |
| 569 | } |
| 570 | } |
Daniel Vetter | cc3ca4f | 2017-03-01 10:52:22 +0100 | [diff] [blame] | 571 | drm_connector_list_iter_end(&conn_iter); |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 572 | |
| 573 | if (enabled) |
Dave Airlie | c4d79c2 | 2017-01-27 12:04:08 +1000 | [diff] [blame] | 574 | drm_kms_helper_poll_enable(dev); |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 575 | |
| 576 | mutex_unlock(&dev->mode_config.mutex); |
| 577 | |
| 578 | /* |
| 579 | * We might have missed any hotplugs that happened while we were |
| 580 | * in the middle of disabling polling |
| 581 | */ |
| 582 | if (!enabled) |
| 583 | drm_helper_hpd_irq_event(dev); |
| 584 | } |
| 585 | |
| 586 | /** |
| 587 | * intel_hpd_poll_init - enables/disables polling for connectors with hpd |
| 588 | * @dev_priv: i915 device instance |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 589 | * |
| 590 | * This function enables polling for all connectors, regardless of whether or |
| 591 | * not they support hotplug detection. Under certain conditions HPD may not be |
| 592 | * functional. On most Intel GPUs, this happens when we enter runtime suspend. |
| 593 | * On Valleyview and Cherryview systems, this also happens when we shut off all |
| 594 | * of the powerwells. |
| 595 | * |
| 596 | * Since this function can get called in contexts where we're already holding |
| 597 | * dev->mode_config.mutex, we do the actual hotplug enabling in a seperate |
| 598 | * worker. |
| 599 | * |
| 600 | * Also see: intel_hpd_init(), which restores hpd handling. |
| 601 | */ |
| 602 | void intel_hpd_poll_init(struct drm_i915_private *dev_priv) |
| 603 | { |
| 604 | WRITE_ONCE(dev_priv->hotplug.poll_enabled, true); |
| 605 | |
| 606 | /* |
| 607 | * We might already be holding dev->mode_config.mutex, so do this in a |
| 608 | * seperate worker |
| 609 | * As well, there's no issue if we race here since we always reschedule |
| 610 | * this worker anyway |
| 611 | */ |
| 612 | schedule_work(&dev_priv->hotplug.poll_init_work); |
| 613 | } |
| 614 | |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 615 | void intel_hpd_init_work(struct drm_i915_private *dev_priv) |
| 616 | { |
| 617 | INIT_WORK(&dev_priv->hotplug.hotplug_work, i915_hotplug_work_func); |
| 618 | INIT_WORK(&dev_priv->hotplug.dig_port_work, i915_digport_work_func); |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 619 | INIT_WORK(&dev_priv->hotplug.poll_init_work, i915_hpd_poll_init_work); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 620 | INIT_DELAYED_WORK(&dev_priv->hotplug.reenable_work, |
| 621 | intel_hpd_irq_storm_reenable_work); |
| 622 | } |
| 623 | |
| 624 | void intel_hpd_cancel_work(struct drm_i915_private *dev_priv) |
| 625 | { |
| 626 | spin_lock_irq(&dev_priv->irq_lock); |
| 627 | |
| 628 | dev_priv->hotplug.long_port_mask = 0; |
| 629 | dev_priv->hotplug.short_port_mask = 0; |
| 630 | dev_priv->hotplug.event_bits = 0; |
| 631 | |
| 632 | spin_unlock_irq(&dev_priv->irq_lock); |
| 633 | |
| 634 | cancel_work_sync(&dev_priv->hotplug.dig_port_work); |
| 635 | cancel_work_sync(&dev_priv->hotplug.hotplug_work); |
Lyude | 19625e8 | 2016-06-21 17:03:44 -0400 | [diff] [blame] | 636 | cancel_work_sync(&dev_priv->hotplug.poll_init_work); |
Jani Nikula | 77913b3 | 2015-06-18 13:06:16 +0300 | [diff] [blame] | 637 | cancel_delayed_work_sync(&dev_priv->hotplug.reenable_work); |
| 638 | } |
Lyude | b236d7c8 | 2016-06-21 17:03:43 -0400 | [diff] [blame] | 639 | |
| 640 | bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin) |
| 641 | { |
| 642 | bool ret = false; |
| 643 | |
| 644 | if (pin == HPD_NONE) |
| 645 | return false; |
| 646 | |
| 647 | spin_lock_irq(&dev_priv->irq_lock); |
| 648 | if (dev_priv->hotplug.stats[pin].state == HPD_ENABLED) { |
| 649 | dev_priv->hotplug.stats[pin].state = HPD_DISABLED; |
| 650 | ret = true; |
| 651 | } |
| 652 | spin_unlock_irq(&dev_priv->irq_lock); |
| 653 | |
| 654 | return ret; |
| 655 | } |
| 656 | |
| 657 | void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin) |
| 658 | { |
| 659 | if (pin == HPD_NONE) |
| 660 | return; |
| 661 | |
| 662 | spin_lock_irq(&dev_priv->irq_lock); |
| 663 | dev_priv->hotplug.stats[pin].state = HPD_ENABLED; |
| 664 | spin_unlock_irq(&dev_priv->irq_lock); |
| 665 | } |