intel_hotplug.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. #include <linux/kernel.h>
  24. #include <drm/drmP.h>
  25. #include <drm/i915_drm.h>
  26. #include "i915_drv.h"
  27. #include "intel_drv.h"
  28. /**
  29. * DOC: Hotplug
  30. *
  31. * Simply put, hotplug occurs when a display is connected to or disconnected
  32. * from the system. However, there may be adapters and docking stations and
  33. * Display Port short pulses and MST devices involved, complicating matters.
  34. *
  35. * Hotplug in i915 is handled in many different levels of abstraction.
  36. *
  37. * The platform dependent interrupt handling code in i915_irq.c enables,
  38. * disables, and does preliminary handling of the interrupts. The interrupt
  39. * handlers gather the hotplug detect (HPD) information from relevant registers
  40. * into a platform independent mask of hotplug pins that have fired.
  41. *
  42. * The platform independent interrupt handler intel_hpd_irq_handler() in
  43. * intel_hotplug.c does hotplug irq storm detection and mitigation, and passes
  44. * further processing to appropriate bottom halves (Display Port specific and
  45. * regular hotplug).
  46. *
  47. * The Display Port work function i915_digport_work_func() calls into
  48. * intel_dp_hpd_pulse() via hooks, which handles DP short pulses and DP MST long
  49. * pulses, with failures and non-MST long pulses triggering regular hotplug
  50. * processing on the connector.
  51. *
  52. * The regular hotplug work function i915_hotplug_work_func() calls connector
  53. * detect hooks, and, if connector status changes, triggers sending of hotplug
  54. * uevent to userspace via drm_kms_helper_hotplug_event().
  55. *
  56. * Finally, the userspace is responsible for triggering a modeset upon receiving
  57. * the hotplug uevent, disabling or enabling the crtc as needed.
  58. *
  59. * The hotplug interrupt storm detection and mitigation code keeps track of the
  60. * number of interrupts per hotplug pin per a period of time, and if the number
  61. * of interrupts exceeds a certain threshold, the interrupt is disabled for a
  62. * while before being re-enabled. The intention is to mitigate issues raising
  63. * from broken hardware triggering massive amounts of interrupts and grinding
  64. * the system to a halt.
  65. *
  66. * Current implementation expects that hotplug interrupt storm will not be
  67. * seen when display port sink is connected, hence on platforms whose DP
  68. * callback is handled by i915_digport_work_func reenabling of hpd is not
  69. * performed (it was never expected to be disabled in the first place ;) )
  70. * this is specific to DP sinks handled by this routine and any other display
  71. * such as HDMI or DVI enabled on the same port will have proper logic since
  72. * it will use i915_hotplug_work_func where this logic is handled.
  73. */
  74. /**
  75. * intel_hpd_pin_default - return default pin associated with certain port.
  76. * @dev_priv: private driver data pointer
  77. * @port: the hpd port to get associated pin
  78. *
  79. * It is only valid and used by digital port encoder.
  80. *
  81. * Return pin that is associatade with @port and HDP_NONE if no pin is
  82. * hard associated with that @port.
  83. */
  84. enum hpd_pin intel_hpd_pin_default(struct drm_i915_private *dev_priv,
  85. enum port port)
  86. {
  87. switch (port) {
  88. case PORT_A:
  89. return HPD_PORT_A;
  90. case PORT_B:
  91. return HPD_PORT_B;
  92. case PORT_C:
  93. return HPD_PORT_C;
  94. case PORT_D:
  95. return HPD_PORT_D;
  96. case PORT_E:
  97. return HPD_PORT_E;
  98. case PORT_F:
  99. if (IS_CNL_WITH_PORT_F(dev_priv))
  100. return HPD_PORT_E;
  101. return HPD_PORT_F;
  102. default:
  103. MISSING_CASE(port);
  104. return HPD_NONE;
  105. }
  106. }
  107. #define HPD_STORM_DETECT_PERIOD 1000
  108. #define HPD_STORM_REENABLE_DELAY (2 * 60 * 1000)
  109. /**
  110. * intel_hpd_irq_storm_detect - gather stats and detect HPD irq storm on a pin
  111. * @dev_priv: private driver data pointer
  112. * @pin: the pin to gather stats on
  113. *
  114. * Gather stats about HPD irqs from the specified @pin, and detect irq
  115. * storms. Only the pin specific stats and state are changed, the caller is
  116. * responsible for further action.
  117. *
  118. * The number of irqs that are allowed within @HPD_STORM_DETECT_PERIOD is
  119. * stored in @dev_priv->hotplug.hpd_storm_threshold which defaults to
  120. * @HPD_STORM_DEFAULT_THRESHOLD. If this threshold is exceeded, it's
  121. * considered an irq storm and the irq state is set to @HPD_MARK_DISABLED.
  122. *
  123. * The HPD threshold can be controlled through i915_hpd_storm_ctl in debugfs,
  124. * and should only be adjusted for automated hotplug testing.
  125. *
  126. * Return true if an irq storm was detected on @pin.
  127. */
  128. static bool intel_hpd_irq_storm_detect(struct drm_i915_private *dev_priv,
  129. enum hpd_pin pin)
  130. {
  131. unsigned long start = dev_priv->hotplug.stats[pin].last_jiffies;
  132. unsigned long end = start + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD);
  133. const int threshold = dev_priv->hotplug.hpd_storm_threshold;
  134. bool storm = false;
  135. if (!time_in_range(jiffies, start, end)) {
  136. dev_priv->hotplug.stats[pin].last_jiffies = jiffies;
  137. dev_priv->hotplug.stats[pin].count = 0;
  138. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", pin);
  139. } else if (dev_priv->hotplug.stats[pin].count > threshold &&
  140. threshold) {
  141. dev_priv->hotplug.stats[pin].state = HPD_MARK_DISABLED;
  142. DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", pin);
  143. storm = true;
  144. } else {
  145. dev_priv->hotplug.stats[pin].count++;
  146. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", pin,
  147. dev_priv->hotplug.stats[pin].count);
  148. }
  149. return storm;
  150. }
  151. static void intel_hpd_irq_storm_disable(struct drm_i915_private *dev_priv)
  152. {
  153. struct drm_device *dev = &dev_priv->drm;
  154. struct intel_connector *intel_connector;
  155. struct intel_encoder *intel_encoder;
  156. struct drm_connector *connector;
  157. struct drm_connector_list_iter conn_iter;
  158. enum hpd_pin pin;
  159. bool hpd_disabled = false;
  160. lockdep_assert_held(&dev_priv->irq_lock);
  161. drm_connector_list_iter_begin(dev, &conn_iter);
  162. drm_for_each_connector_iter(connector, &conn_iter) {
  163. if (connector->polled != DRM_CONNECTOR_POLL_HPD)
  164. continue;
  165. intel_connector = to_intel_connector(connector);
  166. intel_encoder = intel_connector->encoder;
  167. if (!intel_encoder)
  168. continue;
  169. pin = intel_encoder->hpd_pin;
  170. if (pin == HPD_NONE ||
  171. dev_priv->hotplug.stats[pin].state != HPD_MARK_DISABLED)
  172. continue;
  173. DRM_INFO("HPD interrupt storm detected on connector %s: "
  174. "switching from hotplug detection to polling\n",
  175. connector->name);
  176. dev_priv->hotplug.stats[pin].state = HPD_DISABLED;
  177. connector->polled = DRM_CONNECTOR_POLL_CONNECT
  178. | DRM_CONNECTOR_POLL_DISCONNECT;
  179. hpd_disabled = true;
  180. }
  181. drm_connector_list_iter_end(&conn_iter);
  182. /* Enable polling and queue hotplug re-enabling. */
  183. if (hpd_disabled) {
  184. drm_kms_helper_poll_enable(dev);
  185. mod_delayed_work(system_wq, &dev_priv->hotplug.reenable_work,
  186. msecs_to_jiffies(HPD_STORM_REENABLE_DELAY));
  187. }
  188. }
  189. static void intel_hpd_irq_storm_reenable_work(struct work_struct *work)
  190. {
  191. struct drm_i915_private *dev_priv =
  192. container_of(work, typeof(*dev_priv),
  193. hotplug.reenable_work.work);
  194. struct drm_device *dev = &dev_priv->drm;
  195. enum hpd_pin pin;
  196. intel_runtime_pm_get(dev_priv);
  197. spin_lock_irq(&dev_priv->irq_lock);
  198. for_each_hpd_pin(pin) {
  199. struct drm_connector *connector;
  200. struct drm_connector_list_iter conn_iter;
  201. if (dev_priv->hotplug.stats[pin].state != HPD_DISABLED)
  202. continue;
  203. dev_priv->hotplug.stats[pin].state = HPD_ENABLED;
  204. drm_connector_list_iter_begin(dev, &conn_iter);
  205. drm_for_each_connector_iter(connector, &conn_iter) {
  206. struct intel_connector *intel_connector = to_intel_connector(connector);
  207. /* Don't check MST ports, they don't have pins */
  208. if (!intel_connector->mst_port &&
  209. intel_connector->encoder->hpd_pin == pin) {
  210. if (connector->polled != intel_connector->polled)
  211. DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
  212. connector->name);
  213. connector->polled = intel_connector->polled;
  214. if (!connector->polled)
  215. connector->polled = DRM_CONNECTOR_POLL_HPD;
  216. }
  217. }
  218. drm_connector_list_iter_end(&conn_iter);
  219. }
  220. if (dev_priv->display_irqs_enabled && dev_priv->display.hpd_irq_setup)
  221. dev_priv->display.hpd_irq_setup(dev_priv);
  222. spin_unlock_irq(&dev_priv->irq_lock);
  223. intel_runtime_pm_put(dev_priv);
  224. }
  225. bool intel_encoder_hotplug(struct intel_encoder *encoder,
  226. struct intel_connector *connector)
  227. {
  228. struct drm_device *dev = connector->base.dev;
  229. enum drm_connector_status old_status;
  230. WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
  231. old_status = connector->base.status;
  232. connector->base.status =
  233. drm_helper_probe_detect(&connector->base, NULL, false);
  234. if (old_status == connector->base.status)
  235. return false;
  236. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
  237. connector->base.base.id,
  238. connector->base.name,
  239. drm_get_connector_status_name(old_status),
  240. drm_get_connector_status_name(connector->base.status));
  241. return true;
  242. }
  243. static bool intel_encoder_has_hpd_pulse(struct intel_encoder *encoder)
  244. {
  245. return intel_encoder_is_dig_port(encoder) &&
  246. enc_to_dig_port(&encoder->base)->hpd_pulse != NULL;
  247. }
  248. static void i915_digport_work_func(struct work_struct *work)
  249. {
  250. struct drm_i915_private *dev_priv =
  251. container_of(work, struct drm_i915_private, hotplug.dig_port_work);
  252. u32 long_port_mask, short_port_mask;
  253. struct intel_encoder *encoder;
  254. u32 old_bits = 0;
  255. spin_lock_irq(&dev_priv->irq_lock);
  256. long_port_mask = dev_priv->hotplug.long_port_mask;
  257. dev_priv->hotplug.long_port_mask = 0;
  258. short_port_mask = dev_priv->hotplug.short_port_mask;
  259. dev_priv->hotplug.short_port_mask = 0;
  260. spin_unlock_irq(&dev_priv->irq_lock);
  261. for_each_intel_encoder(&dev_priv->drm, encoder) {
  262. struct intel_digital_port *dig_port;
  263. enum port port = encoder->port;
  264. bool long_hpd, short_hpd;
  265. enum irqreturn ret;
  266. if (!intel_encoder_has_hpd_pulse(encoder))
  267. continue;
  268. long_hpd = long_port_mask & BIT(port);
  269. short_hpd = short_port_mask & BIT(port);
  270. if (!long_hpd && !short_hpd)
  271. continue;
  272. dig_port = enc_to_dig_port(&encoder->base);
  273. ret = dig_port->hpd_pulse(dig_port, long_hpd);
  274. if (ret == IRQ_NONE) {
  275. /* fall back to old school hpd */
  276. old_bits |= BIT(encoder->hpd_pin);
  277. }
  278. }
  279. if (old_bits) {
  280. spin_lock_irq(&dev_priv->irq_lock);
  281. dev_priv->hotplug.event_bits |= old_bits;
  282. spin_unlock_irq(&dev_priv->irq_lock);
  283. schedule_work(&dev_priv->hotplug.hotplug_work);
  284. }
  285. }
  286. /*
  287. * Handle hotplug events outside the interrupt handler proper.
  288. */
  289. static void i915_hotplug_work_func(struct work_struct *work)
  290. {
  291. struct drm_i915_private *dev_priv =
  292. container_of(work, struct drm_i915_private, hotplug.hotplug_work);
  293. struct drm_device *dev = &dev_priv->drm;
  294. struct intel_connector *intel_connector;
  295. struct intel_encoder *intel_encoder;
  296. struct drm_connector *connector;
  297. struct drm_connector_list_iter conn_iter;
  298. bool changed = false;
  299. u32 hpd_event_bits;
  300. mutex_lock(&dev->mode_config.mutex);
  301. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  302. spin_lock_irq(&dev_priv->irq_lock);
  303. hpd_event_bits = dev_priv->hotplug.event_bits;
  304. dev_priv->hotplug.event_bits = 0;
  305. /* Disable hotplug on connectors that hit an irq storm. */
  306. intel_hpd_irq_storm_disable(dev_priv);
  307. spin_unlock_irq(&dev_priv->irq_lock);
  308. drm_connector_list_iter_begin(dev, &conn_iter);
  309. drm_for_each_connector_iter(connector, &conn_iter) {
  310. intel_connector = to_intel_connector(connector);
  311. if (!intel_connector->encoder)
  312. continue;
  313. intel_encoder = intel_connector->encoder;
  314. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  315. DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
  316. connector->name, intel_encoder->hpd_pin);
  317. changed |= intel_encoder->hotplug(intel_encoder,
  318. intel_connector);
  319. }
  320. }
  321. drm_connector_list_iter_end(&conn_iter);
  322. mutex_unlock(&dev->mode_config.mutex);
  323. if (changed)
  324. drm_kms_helper_hotplug_event(dev);
  325. }
  326. /**
  327. * intel_hpd_irq_handler - main hotplug irq handler
  328. * @dev_priv: drm_i915_private
  329. * @pin_mask: a mask of hpd pins that have triggered the irq
  330. * @long_mask: a mask of hpd pins that may be long hpd pulses
  331. *
  332. * This is the main hotplug irq handler for all platforms. The platform specific
  333. * irq handlers call the platform specific hotplug irq handlers, which read and
  334. * decode the appropriate registers into bitmasks about hpd pins that have
  335. * triggered (@pin_mask), and which of those pins may be long pulses
  336. * (@long_mask). The @long_mask is ignored if the port corresponding to the pin
  337. * is not a digital port.
  338. *
  339. * Here, we do hotplug irq storm detection and mitigation, and pass further
  340. * processing to appropriate bottom halves.
  341. */
  342. void intel_hpd_irq_handler(struct drm_i915_private *dev_priv,
  343. u32 pin_mask, u32 long_mask)
  344. {
  345. struct intel_encoder *encoder;
  346. bool storm_detected = false;
  347. bool queue_dig = false, queue_hp = false;
  348. u32 long_hpd_pulse_mask = 0;
  349. u32 short_hpd_pulse_mask = 0;
  350. enum hpd_pin pin;
  351. if (!pin_mask)
  352. return;
  353. spin_lock(&dev_priv->irq_lock);
  354. /*
  355. * Determine whether ->hpd_pulse() exists for each pin, and
  356. * whether we have a short or a long pulse. This is needed
  357. * as each pin may have up to two encoders (HDMI and DP) and
  358. * only the one of them (DP) will have ->hpd_pulse().
  359. */
  360. for_each_intel_encoder(&dev_priv->drm, encoder) {
  361. bool has_hpd_pulse = intel_encoder_has_hpd_pulse(encoder);
  362. enum port port = encoder->port;
  363. bool long_hpd;
  364. pin = encoder->hpd_pin;
  365. if (!(BIT(pin) & pin_mask))
  366. continue;
  367. if (!has_hpd_pulse)
  368. continue;
  369. long_hpd = long_mask & BIT(pin);
  370. DRM_DEBUG_DRIVER("digital hpd port %c - %s\n", port_name(port),
  371. long_hpd ? "long" : "short");
  372. queue_dig = true;
  373. if (long_hpd) {
  374. long_hpd_pulse_mask |= BIT(pin);
  375. dev_priv->hotplug.long_port_mask |= BIT(port);
  376. } else {
  377. short_hpd_pulse_mask |= BIT(pin);
  378. dev_priv->hotplug.short_port_mask |= BIT(port);
  379. }
  380. }
  381. /* Now process each pin just once */
  382. for_each_hpd_pin(pin) {
  383. bool long_hpd;
  384. if (!(BIT(pin) & pin_mask))
  385. continue;
  386. if (dev_priv->hotplug.stats[pin].state == HPD_DISABLED) {
  387. /*
  388. * On GMCH platforms the interrupt mask bits only
  389. * prevent irq generation, not the setting of the
  390. * hotplug bits itself. So only WARN about unexpected
  391. * interrupts on saner platforms.
  392. */
  393. WARN_ONCE(!HAS_GMCH_DISPLAY(dev_priv),
  394. "Received HPD interrupt on pin %d although disabled\n", pin);
  395. continue;
  396. }
  397. if (dev_priv->hotplug.stats[pin].state != HPD_ENABLED)
  398. continue;
  399. /*
  400. * Delegate to ->hpd_pulse() if one of the encoders for this
  401. * pin has it, otherwise let the hotplug_work deal with this
  402. * pin directly.
  403. */
  404. if (((short_hpd_pulse_mask | long_hpd_pulse_mask) & BIT(pin))) {
  405. long_hpd = long_hpd_pulse_mask & BIT(pin);
  406. } else {
  407. dev_priv->hotplug.event_bits |= BIT(pin);
  408. long_hpd = true;
  409. queue_hp = true;
  410. }
  411. if (!long_hpd)
  412. continue;
  413. if (intel_hpd_irq_storm_detect(dev_priv, pin)) {
  414. dev_priv->hotplug.event_bits &= ~BIT(pin);
  415. storm_detected = true;
  416. }
  417. }
  418. if (storm_detected && dev_priv->display_irqs_enabled)
  419. dev_priv->display.hpd_irq_setup(dev_priv);
  420. spin_unlock(&dev_priv->irq_lock);
  421. /*
  422. * Our hotplug handler can grab modeset locks (by calling down into the
  423. * fb helpers). Hence it must not be run on our own dev-priv->wq work
  424. * queue for otherwise the flush_work in the pageflip code will
  425. * deadlock.
  426. */
  427. if (queue_dig)
  428. queue_work(dev_priv->hotplug.dp_wq, &dev_priv->hotplug.dig_port_work);
  429. if (queue_hp)
  430. schedule_work(&dev_priv->hotplug.hotplug_work);
  431. }
  432. /**
  433. * intel_hpd_init - initializes and enables hpd support
  434. * @dev_priv: i915 device instance
  435. *
  436. * This function enables the hotplug support. It requires that interrupts have
  437. * already been enabled with intel_irq_init_hw(). From this point on hotplug and
  438. * poll request can run concurrently to other code, so locking rules must be
  439. * obeyed.
  440. *
  441. * This is a separate step from interrupt enabling to simplify the locking rules
  442. * in the driver load and resume code.
  443. *
  444. * Also see: intel_hpd_poll_init(), which enables connector polling
  445. */
  446. void intel_hpd_init(struct drm_i915_private *dev_priv)
  447. {
  448. int i;
  449. for_each_hpd_pin(i) {
  450. dev_priv->hotplug.stats[i].count = 0;
  451. dev_priv->hotplug.stats[i].state = HPD_ENABLED;
  452. }
  453. WRITE_ONCE(dev_priv->hotplug.poll_enabled, false);
  454. schedule_work(&dev_priv->hotplug.poll_init_work);
  455. /*
  456. * Interrupt setup is already guaranteed to be single-threaded, this is
  457. * just to make the assert_spin_locked checks happy.
  458. */
  459. if (dev_priv->display_irqs_enabled && dev_priv->display.hpd_irq_setup) {
  460. spin_lock_irq(&dev_priv->irq_lock);
  461. if (dev_priv->display_irqs_enabled)
  462. dev_priv->display.hpd_irq_setup(dev_priv);
  463. spin_unlock_irq(&dev_priv->irq_lock);
  464. }
  465. }
  466. static void i915_hpd_poll_init_work(struct work_struct *work)
  467. {
  468. struct drm_i915_private *dev_priv =
  469. container_of(work, struct drm_i915_private,
  470. hotplug.poll_init_work);
  471. struct drm_device *dev = &dev_priv->drm;
  472. struct drm_connector *connector;
  473. struct drm_connector_list_iter conn_iter;
  474. bool enabled;
  475. mutex_lock(&dev->mode_config.mutex);
  476. enabled = READ_ONCE(dev_priv->hotplug.poll_enabled);
  477. drm_connector_list_iter_begin(dev, &conn_iter);
  478. drm_for_each_connector_iter(connector, &conn_iter) {
  479. struct intel_connector *intel_connector =
  480. to_intel_connector(connector);
  481. connector->polled = intel_connector->polled;
  482. /* MST has a dynamic intel_connector->encoder and it's reprobing
  483. * is all handled by the MST helpers. */
  484. if (intel_connector->mst_port)
  485. continue;
  486. if (!connector->polled && I915_HAS_HOTPLUG(dev_priv) &&
  487. intel_connector->encoder->hpd_pin > HPD_NONE) {
  488. connector->polled = enabled ?
  489. DRM_CONNECTOR_POLL_CONNECT |
  490. DRM_CONNECTOR_POLL_DISCONNECT :
  491. DRM_CONNECTOR_POLL_HPD;
  492. }
  493. }
  494. drm_connector_list_iter_end(&conn_iter);
  495. if (enabled)
  496. drm_kms_helper_poll_enable(dev);
  497. mutex_unlock(&dev->mode_config.mutex);
  498. /*
  499. * We might have missed any hotplugs that happened while we were
  500. * in the middle of disabling polling
  501. */
  502. if (!enabled)
  503. drm_helper_hpd_irq_event(dev);
  504. }
  505. /**
  506. * intel_hpd_poll_init - enables/disables polling for connectors with hpd
  507. * @dev_priv: i915 device instance
  508. *
  509. * This function enables polling for all connectors, regardless of whether or
  510. * not they support hotplug detection. Under certain conditions HPD may not be
  511. * functional. On most Intel GPUs, this happens when we enter runtime suspend.
  512. * On Valleyview and Cherryview systems, this also happens when we shut off all
  513. * of the powerwells.
  514. *
  515. * Since this function can get called in contexts where we're already holding
  516. * dev->mode_config.mutex, we do the actual hotplug enabling in a seperate
  517. * worker.
  518. *
  519. * Also see: intel_hpd_init(), which restores hpd handling.
  520. */
  521. void intel_hpd_poll_init(struct drm_i915_private *dev_priv)
  522. {
  523. WRITE_ONCE(dev_priv->hotplug.poll_enabled, true);
  524. /*
  525. * We might already be holding dev->mode_config.mutex, so do this in a
  526. * seperate worker
  527. * As well, there's no issue if we race here since we always reschedule
  528. * this worker anyway
  529. */
  530. schedule_work(&dev_priv->hotplug.poll_init_work);
  531. }
  532. void intel_hpd_init_work(struct drm_i915_private *dev_priv)
  533. {
  534. INIT_WORK(&dev_priv->hotplug.hotplug_work, i915_hotplug_work_func);
  535. INIT_WORK(&dev_priv->hotplug.dig_port_work, i915_digport_work_func);
  536. INIT_WORK(&dev_priv->hotplug.poll_init_work, i915_hpd_poll_init_work);
  537. INIT_DELAYED_WORK(&dev_priv->hotplug.reenable_work,
  538. intel_hpd_irq_storm_reenable_work);
  539. }
  540. void intel_hpd_cancel_work(struct drm_i915_private *dev_priv)
  541. {
  542. spin_lock_irq(&dev_priv->irq_lock);
  543. dev_priv->hotplug.long_port_mask = 0;
  544. dev_priv->hotplug.short_port_mask = 0;
  545. dev_priv->hotplug.event_bits = 0;
  546. spin_unlock_irq(&dev_priv->irq_lock);
  547. cancel_work_sync(&dev_priv->hotplug.dig_port_work);
  548. cancel_work_sync(&dev_priv->hotplug.hotplug_work);
  549. cancel_work_sync(&dev_priv->hotplug.poll_init_work);
  550. cancel_delayed_work_sync(&dev_priv->hotplug.reenable_work);
  551. }
  552. bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
  553. {
  554. bool ret = false;
  555. if (pin == HPD_NONE)
  556. return false;
  557. spin_lock_irq(&dev_priv->irq_lock);
  558. if (dev_priv->hotplug.stats[pin].state == HPD_ENABLED) {
  559. dev_priv->hotplug.stats[pin].state = HPD_DISABLED;
  560. ret = true;
  561. }
  562. spin_unlock_irq(&dev_priv->irq_lock);
  563. return ret;
  564. }
  565. void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
  566. {
  567. if (pin == HPD_NONE)
  568. return;
  569. spin_lock_irq(&dev_priv->irq_lock);
  570. dev_priv->hotplug.stats[pin].state = HPD_ENABLED;
  571. spin_unlock_irq(&dev_priv->irq_lock);
  572. }