blob: ba763e7d7dcfdede1c708af9da0f205c84a7fdc5 [file] [log] [blame]
Jani Nikula77913b32015-06-18 13:06:16 +03001/*
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 Nikula856974a2015-07-02 16:05:28 +030032/**
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,Sivakumarfeecb692015-07-10 12:30:43 +053069 *
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 Nikula856974a2015-07-02 16:05:28 +030077 */
78
Imre Deakcc24fcd2015-07-21 15:32:45 -070079bool intel_hpd_pin_to_port(enum hpd_pin pin, enum port *port)
Jani Nikula77913b32015-06-18 13:06:16 +030080{
81 switch (pin) {
Imre Deakcc24fcd2015-07-21 15:32:45 -070082 case HPD_PORT_A:
83 *port = PORT_A;
84 return true;
Jani Nikula77913b32015-06-18 13:06:16 +030085 case HPD_PORT_B:
Imre Deakcc24fcd2015-07-21 15:32:45 -070086 *port = PORT_B;
87 return true;
Jani Nikula77913b32015-06-18 13:06:16 +030088 case HPD_PORT_C:
Imre Deakcc24fcd2015-07-21 15:32:45 -070089 *port = PORT_C;
90 return true;
Jani Nikula77913b32015-06-18 13:06:16 +030091 case HPD_PORT_D:
Imre Deakcc24fcd2015-07-21 15:32:45 -070092 *port = PORT_D;
93 return true;
Xiong Zhang26951ca2015-08-17 15:55:50 +080094 case HPD_PORT_E:
95 *port = PORT_E;
96 return true;
Jani Nikula77913b32015-06-18 13:06:16 +030097 default:
Imre Deakcc24fcd2015-07-21 15:32:45 -070098 return false; /* no hpd */
Jani Nikula77913b32015-06-18 13:06:16 +030099 }
100}
101
102#define HPD_STORM_DETECT_PERIOD 1000
Jani Nikula77913b32015-06-18 13:06:16 +0300103#define HPD_STORM_REENABLE_DELAY (2 * 60 * 1000)
104
105/**
106 * intel_hpd_irq_storm_detect - gather stats and detect HPD irq storm on a pin
107 * @dev_priv: private driver data pointer
108 * @pin: the pin to gather stats on
109 *
110 * Gather stats about HPD irqs from the specified @pin, and detect irq
111 * storms. Only the pin specific stats and state are changed, the caller is
112 * responsible for further action.
113 *
Lyude317eaa92017-02-03 21:18:25 -0500114 * The number of irqs that are allowed within @HPD_STORM_DETECT_PERIOD is
115 * stored in @dev_priv->hotplug.hpd_storm_threshold which defaults to
116 * @HPD_STORM_DEFAULT_THRESHOLD. If this threshold is exceeded, it's
117 * considered an irq storm and the irq state is set to @HPD_MARK_DISABLED.
118 *
119 * The HPD threshold can be controlled through i915_hpd_storm_ctl in debugfs,
120 * and should only be adjusted for automated hotplug testing.
Jani Nikula77913b32015-06-18 13:06:16 +0300121 *
122 * Return true if an irq storm was detected on @pin.
123 */
124static bool intel_hpd_irq_storm_detect(struct drm_i915_private *dev_priv,
125 enum hpd_pin pin)
126{
127 unsigned long start = dev_priv->hotplug.stats[pin].last_jiffies;
128 unsigned long end = start + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD);
Lyude317eaa92017-02-03 21:18:25 -0500129 const int threshold = dev_priv->hotplug.hpd_storm_threshold;
Jani Nikula77913b32015-06-18 13:06:16 +0300130 bool storm = false;
131
132 if (!time_in_range(jiffies, start, end)) {
133 dev_priv->hotplug.stats[pin].last_jiffies = jiffies;
134 dev_priv->hotplug.stats[pin].count = 0;
135 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", pin);
Lyude317eaa92017-02-03 21:18:25 -0500136 } else if (dev_priv->hotplug.stats[pin].count > threshold &&
137 threshold) {
Jani Nikula77913b32015-06-18 13:06:16 +0300138 dev_priv->hotplug.stats[pin].state = HPD_MARK_DISABLED;
139 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", pin);
140 storm = true;
141 } else {
142 dev_priv->hotplug.stats[pin].count++;
143 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", pin,
144 dev_priv->hotplug.stats[pin].count);
145 }
146
147 return storm;
148}
149
150static void intel_hpd_irq_storm_disable(struct drm_i915_private *dev_priv)
151{
Chris Wilson91c8a322016-07-05 10:40:23 +0100152 struct drm_device *dev = &dev_priv->drm;
Jani Nikula77913b32015-06-18 13:06:16 +0300153 struct drm_mode_config *mode_config = &dev->mode_config;
154 struct intel_connector *intel_connector;
155 struct intel_encoder *intel_encoder;
156 struct drm_connector *connector;
157 enum hpd_pin pin;
158 bool hpd_disabled = false;
159
Chris Wilson67520412017-03-02 13:28:01 +0000160 lockdep_assert_held(&dev_priv->irq_lock);
Jani Nikula77913b32015-06-18 13:06:16 +0300161
162 list_for_each_entry(connector, &mode_config->connector_list, head) {
163 if (connector->polled != DRM_CONNECTOR_POLL_HPD)
164 continue;
165
166 intel_connector = to_intel_connector(connector);
167 intel_encoder = intel_connector->encoder;
168 if (!intel_encoder)
169 continue;
170
171 pin = intel_encoder->hpd_pin;
172 if (pin == HPD_NONE ||
173 dev_priv->hotplug.stats[pin].state != HPD_MARK_DISABLED)
174 continue;
175
176 DRM_INFO("HPD interrupt storm detected on connector %s: "
177 "switching from hotplug detection to polling\n",
178 connector->name);
179
180 dev_priv->hotplug.stats[pin].state = HPD_DISABLED;
181 connector->polled = DRM_CONNECTOR_POLL_CONNECT
182 | DRM_CONNECTOR_POLL_DISCONNECT;
183 hpd_disabled = true;
184 }
185
186 /* Enable polling and queue hotplug re-enabling. */
187 if (hpd_disabled) {
Dave Airliec4d79c22017-01-27 12:04:08 +1000188 drm_kms_helper_poll_enable(dev);
Jani Nikula77913b32015-06-18 13:06:16 +0300189 mod_delayed_work(system_wq, &dev_priv->hotplug.reenable_work,
190 msecs_to_jiffies(HPD_STORM_REENABLE_DELAY));
191 }
192}
193
194static void intel_hpd_irq_storm_reenable_work(struct work_struct *work)
195{
196 struct drm_i915_private *dev_priv =
197 container_of(work, typeof(*dev_priv),
198 hotplug.reenable_work.work);
Chris Wilson91c8a322016-07-05 10:40:23 +0100199 struct drm_device *dev = &dev_priv->drm;
Jani Nikula77913b32015-06-18 13:06:16 +0300200 struct drm_mode_config *mode_config = &dev->mode_config;
201 int i;
202
203 intel_runtime_pm_get(dev_priv);
204
205 spin_lock_irq(&dev_priv->irq_lock);
206 for_each_hpd_pin(i) {
207 struct drm_connector *connector;
208
209 if (dev_priv->hotplug.stats[i].state != HPD_DISABLED)
210 continue;
211
212 dev_priv->hotplug.stats[i].state = HPD_ENABLED;
213
214 list_for_each_entry(connector, &mode_config->connector_list, head) {
215 struct intel_connector *intel_connector = to_intel_connector(connector);
216
217 if (intel_connector->encoder->hpd_pin == i) {
218 if (connector->polled != intel_connector->polled)
219 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
220 connector->name);
221 connector->polled = intel_connector->polled;
222 if (!connector->polled)
223 connector->polled = DRM_CONNECTOR_POLL_HPD;
224 }
225 }
226 }
Chris Wilson262fd482017-02-15 13:15:47 +0000227 if (dev_priv->display_irqs_enabled && dev_priv->display.hpd_irq_setup)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100228 dev_priv->display.hpd_irq_setup(dev_priv);
Jani Nikula77913b32015-06-18 13:06:16 +0300229 spin_unlock_irq(&dev_priv->irq_lock);
230
231 intel_runtime_pm_put(dev_priv);
232}
233
234static bool intel_hpd_irq_event(struct drm_device *dev,
235 struct drm_connector *connector)
236{
237 enum drm_connector_status old_status;
238
239 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
240 old_status = connector->status;
241
242 connector->status = connector->funcs->detect(connector, false);
243 if (old_status == connector->status)
244 return false;
245
246 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
247 connector->base.id,
248 connector->name,
249 drm_get_connector_status_name(old_status),
250 drm_get_connector_status_name(connector->status));
251
252 return true;
253}
254
255static void i915_digport_work_func(struct work_struct *work)
256{
257 struct drm_i915_private *dev_priv =
258 container_of(work, struct drm_i915_private, hotplug.dig_port_work);
259 u32 long_port_mask, short_port_mask;
260 struct intel_digital_port *intel_dig_port;
261 int i;
262 u32 old_bits = 0;
263
264 spin_lock_irq(&dev_priv->irq_lock);
265 long_port_mask = dev_priv->hotplug.long_port_mask;
266 dev_priv->hotplug.long_port_mask = 0;
267 short_port_mask = dev_priv->hotplug.short_port_mask;
268 dev_priv->hotplug.short_port_mask = 0;
269 spin_unlock_irq(&dev_priv->irq_lock);
270
271 for (i = 0; i < I915_MAX_PORTS; i++) {
272 bool valid = false;
273 bool long_hpd = false;
274 intel_dig_port = dev_priv->hotplug.irq_port[i];
275 if (!intel_dig_port || !intel_dig_port->hpd_pulse)
276 continue;
277
278 if (long_port_mask & (1 << i)) {
279 valid = true;
280 long_hpd = true;
281 } else if (short_port_mask & (1 << i))
282 valid = true;
283
284 if (valid) {
285 enum irqreturn ret;
286
287 ret = intel_dig_port->hpd_pulse(intel_dig_port, long_hpd);
288 if (ret == IRQ_NONE) {
289 /* fall back to old school hpd */
290 old_bits |= (1 << intel_dig_port->base.hpd_pin);
291 }
292 }
293 }
294
295 if (old_bits) {
296 spin_lock_irq(&dev_priv->irq_lock);
297 dev_priv->hotplug.event_bits |= old_bits;
298 spin_unlock_irq(&dev_priv->irq_lock);
299 schedule_work(&dev_priv->hotplug.hotplug_work);
300 }
301}
302
303/*
304 * Handle hotplug events outside the interrupt handler proper.
305 */
306static void i915_hotplug_work_func(struct work_struct *work)
307{
308 struct drm_i915_private *dev_priv =
309 container_of(work, struct drm_i915_private, hotplug.hotplug_work);
Chris Wilson91c8a322016-07-05 10:40:23 +0100310 struct drm_device *dev = &dev_priv->drm;
Jani Nikula77913b32015-06-18 13:06:16 +0300311 struct drm_mode_config *mode_config = &dev->mode_config;
312 struct intel_connector *intel_connector;
313 struct intel_encoder *intel_encoder;
314 struct drm_connector *connector;
315 bool changed = false;
316 u32 hpd_event_bits;
317
318 mutex_lock(&mode_config->mutex);
319 DRM_DEBUG_KMS("running encoder hotplug functions\n");
320
321 spin_lock_irq(&dev_priv->irq_lock);
322
323 hpd_event_bits = dev_priv->hotplug.event_bits;
324 dev_priv->hotplug.event_bits = 0;
325
326 /* Disable hotplug on connectors that hit an irq storm. */
327 intel_hpd_irq_storm_disable(dev_priv);
328
329 spin_unlock_irq(&dev_priv->irq_lock);
330
331 list_for_each_entry(connector, &mode_config->connector_list, head) {
332 intel_connector = to_intel_connector(connector);
333 if (!intel_connector->encoder)
334 continue;
335 intel_encoder = intel_connector->encoder;
336 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
337 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
338 connector->name, intel_encoder->hpd_pin);
339 if (intel_encoder->hot_plug)
340 intel_encoder->hot_plug(intel_encoder);
341 if (intel_hpd_irq_event(dev, connector))
342 changed = true;
343 }
344 }
345 mutex_unlock(&mode_config->mutex);
346
347 if (changed)
348 drm_kms_helper_hotplug_event(dev);
349}
350
351
352/**
353 * intel_hpd_irq_handler - main hotplug irq handler
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100354 * @dev_priv: drm_i915_private
Jani Nikula77913b32015-06-18 13:06:16 +0300355 * @pin_mask: a mask of hpd pins that have triggered the irq
356 * @long_mask: a mask of hpd pins that may be long hpd pulses
357 *
358 * This is the main hotplug irq handler for all platforms. The platform specific
359 * irq handlers call the platform specific hotplug irq handlers, which read and
360 * decode the appropriate registers into bitmasks about hpd pins that have
361 * triggered (@pin_mask), and which of those pins may be long pulses
362 * (@long_mask). The @long_mask is ignored if the port corresponding to the pin
363 * is not a digital port.
364 *
365 * Here, we do hotplug irq storm detection and mitigation, and pass further
366 * processing to appropriate bottom halves.
367 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100368void intel_hpd_irq_handler(struct drm_i915_private *dev_priv,
Jani Nikula77913b32015-06-18 13:06:16 +0300369 u32 pin_mask, u32 long_mask)
370{
Jani Nikula77913b32015-06-18 13:06:16 +0300371 int i;
372 enum port port;
373 bool storm_detected = false;
374 bool queue_dig = false, queue_hp = false;
375 bool is_dig_port;
376
377 if (!pin_mask)
378 return;
379
380 spin_lock(&dev_priv->irq_lock);
381 for_each_hpd_pin(i) {
382 if (!(BIT(i) & pin_mask))
383 continue;
384
Imre Deakcc24fcd2015-07-21 15:32:45 -0700385 is_dig_port = intel_hpd_pin_to_port(i, &port) &&
386 dev_priv->hotplug.irq_port[port];
Jani Nikula77913b32015-06-18 13:06:16 +0300387
388 if (is_dig_port) {
389 bool long_hpd = long_mask & BIT(i);
390
391 DRM_DEBUG_DRIVER("digital hpd port %c - %s\n", port_name(port),
392 long_hpd ? "long" : "short");
393 /*
394 * For long HPD pulses we want to have the digital queue happen,
395 * but we still want HPD storm detection to function.
396 */
397 queue_dig = true;
398 if (long_hpd) {
399 dev_priv->hotplug.long_port_mask |= (1 << port);
400 } else {
401 /* for short HPD just trigger the digital queue */
402 dev_priv->hotplug.short_port_mask |= (1 << port);
403 continue;
404 }
405 }
406
407 if (dev_priv->hotplug.stats[i].state == HPD_DISABLED) {
408 /*
409 * On GMCH platforms the interrupt mask bits only
410 * prevent irq generation, not the setting of the
411 * hotplug bits itself. So only WARN about unexpected
412 * interrupts on saner platforms.
413 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100414 WARN_ONCE(!HAS_GMCH_DISPLAY(dev_priv),
Jani Nikula77913b32015-06-18 13:06:16 +0300415 "Received HPD interrupt on pin %d although disabled\n", i);
416 continue;
417 }
418
419 if (dev_priv->hotplug.stats[i].state != HPD_ENABLED)
420 continue;
421
422 if (!is_dig_port) {
423 dev_priv->hotplug.event_bits |= BIT(i);
424 queue_hp = true;
425 }
426
427 if (intel_hpd_irq_storm_detect(dev_priv, i)) {
428 dev_priv->hotplug.event_bits &= ~BIT(i);
429 storm_detected = true;
430 }
431 }
432
Chris Wilson262fd482017-02-15 13:15:47 +0000433 if (storm_detected && dev_priv->display_irqs_enabled)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100434 dev_priv->display.hpd_irq_setup(dev_priv);
Jani Nikula77913b32015-06-18 13:06:16 +0300435 spin_unlock(&dev_priv->irq_lock);
436
437 /*
438 * Our hotplug handler can grab modeset locks (by calling down into the
439 * fb helpers). Hence it must not be run on our own dev-priv->wq work
440 * queue for otherwise the flush_work in the pageflip code will
441 * deadlock.
442 */
443 if (queue_dig)
444 queue_work(dev_priv->hotplug.dp_wq, &dev_priv->hotplug.dig_port_work);
445 if (queue_hp)
446 schedule_work(&dev_priv->hotplug.hotplug_work);
447}
448
449/**
450 * intel_hpd_init - initializes and enables hpd support
451 * @dev_priv: i915 device instance
452 *
453 * This function enables the hotplug support. It requires that interrupts have
454 * already been enabled with intel_irq_init_hw(). From this point on hotplug and
455 * poll request can run concurrently to other code, so locking rules must be
456 * obeyed.
457 *
458 * This is a separate step from interrupt enabling to simplify the locking rules
459 * in the driver load and resume code.
Lyude19625e82016-06-21 17:03:44 -0400460 *
461 * Also see: intel_hpd_poll_init(), which enables connector polling
Jani Nikula77913b32015-06-18 13:06:16 +0300462 */
463void intel_hpd_init(struct drm_i915_private *dev_priv)
464{
Jani Nikula77913b32015-06-18 13:06:16 +0300465 int i;
466
467 for_each_hpd_pin(i) {
468 dev_priv->hotplug.stats[i].count = 0;
469 dev_priv->hotplug.stats[i].state = HPD_ENABLED;
470 }
Lyude07c51912016-01-07 10:43:28 -0500471
Lyude19625e82016-06-21 17:03:44 -0400472 WRITE_ONCE(dev_priv->hotplug.poll_enabled, false);
473 schedule_work(&dev_priv->hotplug.poll_init_work);
Jani Nikula77913b32015-06-18 13:06:16 +0300474
475 /*
476 * Interrupt setup is already guaranteed to be single-threaded, this is
477 * just to make the assert_spin_locked checks happy.
478 */
Chris Wilson262fd482017-02-15 13:15:47 +0000479 if (dev_priv->display_irqs_enabled && dev_priv->display.hpd_irq_setup) {
480 spin_lock_irq(&dev_priv->irq_lock);
481 if (dev_priv->display_irqs_enabled)
482 dev_priv->display.hpd_irq_setup(dev_priv);
483 spin_unlock_irq(&dev_priv->irq_lock);
484 }
Jani Nikula77913b32015-06-18 13:06:16 +0300485}
486
Chris Wilson24808e92016-08-17 12:09:06 +0100487static void i915_hpd_poll_init_work(struct work_struct *work)
488{
Lyude19625e82016-06-21 17:03:44 -0400489 struct drm_i915_private *dev_priv =
490 container_of(work, struct drm_i915_private,
491 hotplug.poll_init_work);
492 struct drm_device *dev = &dev_priv->drm;
493 struct drm_mode_config *mode_config = &dev->mode_config;
494 struct drm_connector *connector;
495 bool enabled;
496
497 mutex_lock(&dev->mode_config.mutex);
498
499 enabled = READ_ONCE(dev_priv->hotplug.poll_enabled);
500
501 list_for_each_entry(connector, &mode_config->connector_list, head) {
502 struct intel_connector *intel_connector =
503 to_intel_connector(connector);
504 connector->polled = intel_connector->polled;
505
506 /* MST has a dynamic intel_connector->encoder and it's reprobing
507 * is all handled by the MST helpers. */
508 if (intel_connector->mst_port)
509 continue;
510
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +0000511 if (!connector->polled && I915_HAS_HOTPLUG(dev_priv) &&
Lyude19625e82016-06-21 17:03:44 -0400512 intel_connector->encoder->hpd_pin > HPD_NONE) {
513 connector->polled = enabled ?
514 DRM_CONNECTOR_POLL_CONNECT |
515 DRM_CONNECTOR_POLL_DISCONNECT :
516 DRM_CONNECTOR_POLL_HPD;
517 }
518 }
519
520 if (enabled)
Dave Airliec4d79c22017-01-27 12:04:08 +1000521 drm_kms_helper_poll_enable(dev);
Lyude19625e82016-06-21 17:03:44 -0400522
523 mutex_unlock(&dev->mode_config.mutex);
524
525 /*
526 * We might have missed any hotplugs that happened while we were
527 * in the middle of disabling polling
528 */
529 if (!enabled)
530 drm_helper_hpd_irq_event(dev);
531}
532
533/**
534 * intel_hpd_poll_init - enables/disables polling for connectors with hpd
535 * @dev_priv: i915 device instance
Lyude19625e82016-06-21 17:03:44 -0400536 *
537 * This function enables polling for all connectors, regardless of whether or
538 * not they support hotplug detection. Under certain conditions HPD may not be
539 * functional. On most Intel GPUs, this happens when we enter runtime suspend.
540 * On Valleyview and Cherryview systems, this also happens when we shut off all
541 * of the powerwells.
542 *
543 * Since this function can get called in contexts where we're already holding
544 * dev->mode_config.mutex, we do the actual hotplug enabling in a seperate
545 * worker.
546 *
547 * Also see: intel_hpd_init(), which restores hpd handling.
548 */
549void intel_hpd_poll_init(struct drm_i915_private *dev_priv)
550{
551 WRITE_ONCE(dev_priv->hotplug.poll_enabled, true);
552
553 /*
554 * We might already be holding dev->mode_config.mutex, so do this in a
555 * seperate worker
556 * As well, there's no issue if we race here since we always reschedule
557 * this worker anyway
558 */
559 schedule_work(&dev_priv->hotplug.poll_init_work);
560}
561
Jani Nikula77913b32015-06-18 13:06:16 +0300562void intel_hpd_init_work(struct drm_i915_private *dev_priv)
563{
564 INIT_WORK(&dev_priv->hotplug.hotplug_work, i915_hotplug_work_func);
565 INIT_WORK(&dev_priv->hotplug.dig_port_work, i915_digport_work_func);
Lyude19625e82016-06-21 17:03:44 -0400566 INIT_WORK(&dev_priv->hotplug.poll_init_work, i915_hpd_poll_init_work);
Jani Nikula77913b32015-06-18 13:06:16 +0300567 INIT_DELAYED_WORK(&dev_priv->hotplug.reenable_work,
568 intel_hpd_irq_storm_reenable_work);
569}
570
571void intel_hpd_cancel_work(struct drm_i915_private *dev_priv)
572{
573 spin_lock_irq(&dev_priv->irq_lock);
574
575 dev_priv->hotplug.long_port_mask = 0;
576 dev_priv->hotplug.short_port_mask = 0;
577 dev_priv->hotplug.event_bits = 0;
578
579 spin_unlock_irq(&dev_priv->irq_lock);
580
581 cancel_work_sync(&dev_priv->hotplug.dig_port_work);
582 cancel_work_sync(&dev_priv->hotplug.hotplug_work);
Lyude19625e82016-06-21 17:03:44 -0400583 cancel_work_sync(&dev_priv->hotplug.poll_init_work);
Jani Nikula77913b32015-06-18 13:06:16 +0300584 cancel_delayed_work_sync(&dev_priv->hotplug.reenable_work);
585}
Lyudeb236d7c82016-06-21 17:03:43 -0400586
587bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
588{
589 bool ret = false;
590
591 if (pin == HPD_NONE)
592 return false;
593
594 spin_lock_irq(&dev_priv->irq_lock);
595 if (dev_priv->hotplug.stats[pin].state == HPD_ENABLED) {
596 dev_priv->hotplug.stats[pin].state = HPD_DISABLED;
597 ret = true;
598 }
599 spin_unlock_irq(&dev_priv->irq_lock);
600
601 return ret;
602}
603
604void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
605{
606 if (pin == HPD_NONE)
607 return;
608
609 spin_lock_irq(&dev_priv->irq_lock);
610 dev_priv->hotplug.stats[pin].state = HPD_ENABLED;
611 spin_unlock_irq(&dev_priv->irq_lock);
612}