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