intel_hotplug.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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_port - return port hard associated with certain pin.
  76. * @dev_priv: private driver data pointer
  77. * @pin: the hpd pin to get associated port
  78. *
  79. * Return port that is associatade with @pin and PORT_NONE if no port is
  80. * hard associated with that @pin.
  81. */
  82. enum port intel_hpd_pin_to_port(struct drm_i915_private *dev_priv,
  83. enum hpd_pin pin)
  84. {
  85. switch (pin) {
  86. case HPD_PORT_A:
  87. return PORT_A;
  88. case HPD_PORT_B:
  89. return PORT_B;
  90. case HPD_PORT_C:
  91. return PORT_C;
  92. case HPD_PORT_D:
  93. return PORT_D;
  94. case HPD_PORT_E:
  95. if (IS_CNL_WITH_PORT_F(dev_priv))
  96. return PORT_F;
  97. return PORT_E;
  98. case HPD_PORT_F:
  99. return PORT_F;
  100. default:
  101. return PORT_NONE; /* no port for this pin */
  102. }
  103. }
  104. /**
  105. * intel_hpd_pin_default - return default pin associated with certain port.
  106. * @dev_priv: private driver data pointer
  107. * @port: the hpd port to get associated pin
  108. *
  109. * It is only valid and used by digital port encoder.
  110. *
  111. * Return pin that is associatade with @port and HDP_NONE if no pin is
  112. * hard associated with that @port.
  113. */
  114. enum hpd_pin intel_hpd_pin_default(struct drm_i915_private *dev_priv,
  115. enum port port)
  116. {
  117. switch (port) {
  118. case PORT_A:
  119. return HPD_PORT_A;
  120. case PORT_B:
  121. return HPD_PORT_B;
  122. case PORT_C:
  123. return HPD_PORT_C;
  124. case PORT_D:
  125. return HPD_PORT_D;
  126. case PORT_E:
  127. return HPD_PORT_E;
  128. case PORT_F:
  129. if (IS_CNL_WITH_PORT_F(dev_priv))
  130. return HPD_PORT_E;
  131. return HPD_PORT_F;
  132. default:
  133. MISSING_CASE(port);
  134. return HPD_NONE;
  135. }
  136. }
  137. #define HPD_STORM_DETECT_PERIOD 1000
  138. #define HPD_STORM_REENABLE_DELAY (2 * 60 * 1000)
  139. /**
  140. * intel_hpd_irq_storm_detect - gather stats and detect HPD irq storm on a pin
  141. * @dev_priv: private driver data pointer
  142. * @pin: the pin to gather stats on
  143. *
  144. * Gather stats about HPD irqs from the specified @pin, and detect irq
  145. * storms. Only the pin specific stats and state are changed, the caller is
  146. * responsible for further action.
  147. *
  148. * The number of irqs that are allowed within @HPD_STORM_DETECT_PERIOD is
  149. * stored in @dev_priv->hotplug.hpd_storm_threshold which defaults to
  150. * @HPD_STORM_DEFAULT_THRESHOLD. If this threshold is exceeded, it's
  151. * considered an irq storm and the irq state is set to @HPD_MARK_DISABLED.
  152. *
  153. * The HPD threshold can be controlled through i915_hpd_storm_ctl in debugfs,
  154. * and should only be adjusted for automated hotplug testing.
  155. *
  156. * Return true if an irq storm was detected on @pin.
  157. */
  158. static bool intel_hpd_irq_storm_detect(struct drm_i915_private *dev_priv,
  159. enum hpd_pin pin)
  160. {
  161. unsigned long start = dev_priv->hotplug.stats[pin].last_jiffies;
  162. unsigned long end = start + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD);
  163. const int threshold = dev_priv->hotplug.hpd_storm_threshold;
  164. bool storm = false;
  165. if (!time_in_range(jiffies, start, end)) {
  166. dev_priv->hotplug.stats[pin].last_jiffies = jiffies;
  167. dev_priv->hotplug.stats[pin].count = 0;
  168. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", pin);
  169. } else if (dev_priv->hotplug.stats[pin].count > threshold &&
  170. threshold) {
  171. dev_priv->hotplug.stats[pin].state = HPD_MARK_DISABLED;
  172. DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", pin);
  173. storm = true;
  174. } else {
  175. dev_priv->hotplug.stats[pin].count++;
  176. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", pin,
  177. dev_priv->hotplug.stats[pin].count);
  178. }
  179. return storm;
  180. }
  181. static void intel_hpd_irq_storm_disable(struct drm_i915_private *dev_priv)
  182. {
  183. struct drm_device *dev = &dev_priv->drm;
  184. struct intel_connector *intel_connector;
  185. struct intel_encoder *intel_encoder;
  186. struct drm_connector *connector;
  187. struct drm_connector_list_iter conn_iter;
  188. enum hpd_pin pin;
  189. bool hpd_disabled = false;
  190. lockdep_assert_held(&dev_priv->irq_lock);
  191. drm_connector_list_iter_begin(dev, &conn_iter);
  192. drm_for_each_connector_iter(connector, &conn_iter) {
  193. if (connector->polled != DRM_CONNECTOR_POLL_HPD)
  194. continue;
  195. intel_connector = to_intel_connector(connector);
  196. intel_encoder = intel_connector->encoder;
  197. if (!intel_encoder)
  198. continue;
  199. pin = intel_encoder->hpd_pin;
  200. if (pin == HPD_NONE ||
  201. dev_priv->hotplug.stats[pin].state != HPD_MARK_DISABLED)
  202. continue;
  203. DRM_INFO("HPD interrupt storm detected on connector %s: "
  204. "switching from hotplug detection to polling\n",
  205. connector->name);
  206. dev_priv->hotplug.stats[pin].state = HPD_DISABLED;
  207. connector->polled = DRM_CONNECTOR_POLL_CONNECT
  208. | DRM_CONNECTOR_POLL_DISCONNECT;
  209. hpd_disabled = true;
  210. }
  211. drm_connector_list_iter_end(&conn_iter);
  212. /* Enable polling and queue hotplug re-enabling. */
  213. if (hpd_disabled) {
  214. drm_kms_helper_poll_enable(dev);
  215. mod_delayed_work(system_wq, &dev_priv->hotplug.reenable_work,
  216. msecs_to_jiffies(HPD_STORM_REENABLE_DELAY));
  217. }
  218. }
  219. static void intel_hpd_irq_storm_reenable_work(struct work_struct *work)
  220. {
  221. struct drm_i915_private *dev_priv =
  222. container_of(work, typeof(*dev_priv),
  223. hotplug.reenable_work.work);
  224. struct drm_device *dev = &dev_priv->drm;
  225. int i;
  226. intel_runtime_pm_get(dev_priv);
  227. spin_lock_irq(&dev_priv->irq_lock);
  228. for_each_hpd_pin(i) {
  229. struct drm_connector *connector;
  230. struct drm_connector_list_iter conn_iter;
  231. if (dev_priv->hotplug.stats[i].state != HPD_DISABLED)
  232. continue;
  233. dev_priv->hotplug.stats[i].state = HPD_ENABLED;
  234. drm_connector_list_iter_begin(dev, &conn_iter);
  235. drm_for_each_connector_iter(connector, &conn_iter) {
  236. struct intel_connector *intel_connector = to_intel_connector(connector);
  237. if (intel_connector->encoder->hpd_pin == i) {
  238. if (connector->polled != intel_connector->polled)
  239. DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
  240. connector->name);
  241. connector->polled = intel_connector->polled;
  242. if (!connector->polled)
  243. connector->polled = DRM_CONNECTOR_POLL_HPD;
  244. }
  245. }
  246. drm_connector_list_iter_end(&conn_iter);
  247. }
  248. if (dev_priv->display_irqs_enabled && dev_priv->display.hpd_irq_setup)
  249. dev_priv->display.hpd_irq_setup(dev_priv);
  250. spin_unlock_irq(&dev_priv->irq_lock);
  251. intel_runtime_pm_put(dev_priv);
  252. }
  253. bool intel_encoder_hotplug(struct intel_encoder *encoder,
  254. struct intel_connector *connector)
  255. {
  256. struct drm_device *dev = connector->base.dev;
  257. enum drm_connector_status old_status;
  258. WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
  259. old_status = connector->base.status;
  260. connector->base.status =
  261. drm_helper_probe_detect(&connector->base, NULL, false);
  262. if (old_status == connector->base.status)
  263. return false;
  264. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
  265. connector->base.base.id,
  266. connector->base.name,
  267. drm_get_connector_status_name(old_status),
  268. drm_get_connector_status_name(connector->base.status));
  269. return true;
  270. }
  271. static void i915_digport_work_func(struct work_struct *work)
  272. {
  273. struct drm_i915_private *dev_priv =
  274. container_of(work, struct drm_i915_private, hotplug.dig_port_work);
  275. u32 long_port_mask, short_port_mask;
  276. struct intel_digital_port *intel_dig_port;
  277. int i;
  278. u32 old_bits = 0;
  279. spin_lock_irq(&dev_priv->irq_lock);
  280. long_port_mask = dev_priv->hotplug.long_port_mask;
  281. dev_priv->hotplug.long_port_mask = 0;
  282. short_port_mask = dev_priv->hotplug.short_port_mask;
  283. dev_priv->hotplug.short_port_mask = 0;
  284. spin_unlock_irq(&dev_priv->irq_lock);
  285. for (i = 0; i < I915_MAX_PORTS; i++) {
  286. bool valid = false;
  287. bool long_hpd = false;
  288. intel_dig_port = dev_priv->hotplug.irq_port[i];
  289. if (!intel_dig_port || !intel_dig_port->hpd_pulse)
  290. continue;
  291. if (long_port_mask & (1 << i)) {
  292. valid = true;
  293. long_hpd = true;
  294. } else if (short_port_mask & (1 << i))
  295. valid = true;
  296. if (valid) {
  297. enum irqreturn ret;
  298. ret = intel_dig_port->hpd_pulse(intel_dig_port, long_hpd);
  299. if (ret == IRQ_NONE) {
  300. /* fall back to old school hpd */
  301. old_bits |= (1 << intel_dig_port->base.hpd_pin);
  302. }
  303. }
  304. }
  305. if (old_bits) {
  306. spin_lock_irq(&dev_priv->irq_lock);
  307. dev_priv->hotplug.event_bits |= old_bits;
  308. spin_unlock_irq(&dev_priv->irq_lock);
  309. schedule_work(&dev_priv->hotplug.hotplug_work);
  310. }
  311. }
  312. /*
  313. * Handle hotplug events outside the interrupt handler proper.
  314. */
  315. static void i915_hotplug_work_func(struct work_struct *work)
  316. {
  317. struct drm_i915_private *dev_priv =
  318. container_of(work, struct drm_i915_private, hotplug.hotplug_work);
  319. struct drm_device *dev = &dev_priv->drm;
  320. struct intel_connector *intel_connector;
  321. struct intel_encoder *intel_encoder;
  322. struct drm_connector *connector;
  323. struct drm_connector_list_iter conn_iter;
  324. bool changed = false;
  325. u32 hpd_event_bits;
  326. mutex_lock(&dev->mode_config.mutex);
  327. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  328. spin_lock_irq(&dev_priv->irq_lock);
  329. hpd_event_bits = dev_priv->hotplug.event_bits;
  330. dev_priv->hotplug.event_bits = 0;
  331. /* Disable hotplug on connectors that hit an irq storm. */
  332. intel_hpd_irq_storm_disable(dev_priv);
  333. spin_unlock_irq(&dev_priv->irq_lock);
  334. drm_connector_list_iter_begin(dev, &conn_iter);
  335. drm_for_each_connector_iter(connector, &conn_iter) {
  336. intel_connector = to_intel_connector(connector);
  337. if (!intel_connector->encoder)
  338. continue;
  339. intel_encoder = intel_connector->encoder;
  340. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  341. DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
  342. connector->name, intel_encoder->hpd_pin);
  343. changed |= intel_encoder->hotplug(intel_encoder,
  344. intel_connector);
  345. }
  346. }
  347. drm_connector_list_iter_end(&conn_iter);
  348. mutex_unlock(&dev->mode_config.mutex);
  349. if (changed)
  350. drm_kms_helper_hotplug_event(dev);
  351. }
  352. /**
  353. * intel_hpd_irq_handler - main hotplug irq handler
  354. * @dev_priv: drm_i915_private
  355. * @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. */
  368. void intel_hpd_irq_handler(struct drm_i915_private *dev_priv,
  369. u32 pin_mask, u32 long_mask)
  370. {
  371. 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. if (!pin_mask)
  377. return;
  378. spin_lock(&dev_priv->irq_lock);
  379. for_each_hpd_pin(i) {
  380. if (!(BIT(i) & pin_mask))
  381. continue;
  382. port = intel_hpd_pin_to_port(dev_priv, i);
  383. is_dig_port = port != PORT_NONE &&
  384. dev_priv->hotplug.irq_port[port];
  385. if (is_dig_port) {
  386. bool long_hpd = long_mask & BIT(i);
  387. DRM_DEBUG_DRIVER("digital hpd port %c - %s\n", port_name(port),
  388. long_hpd ? "long" : "short");
  389. /*
  390. * For long HPD pulses we want to have the digital queue happen,
  391. * but we still want HPD storm detection to function.
  392. */
  393. queue_dig = true;
  394. if (long_hpd) {
  395. dev_priv->hotplug.long_port_mask |= (1 << port);
  396. } else {
  397. /* for short HPD just trigger the digital queue */
  398. dev_priv->hotplug.short_port_mask |= (1 << port);
  399. continue;
  400. }
  401. }
  402. if (dev_priv->hotplug.stats[i].state == HPD_DISABLED) {
  403. /*
  404. * On GMCH platforms the interrupt mask bits only
  405. * prevent irq generation, not the setting of the
  406. * hotplug bits itself. So only WARN about unexpected
  407. * interrupts on saner platforms.
  408. */
  409. WARN_ONCE(!HAS_GMCH_DISPLAY(dev_priv),
  410. "Received HPD interrupt on pin %d although disabled\n", i);
  411. continue;
  412. }
  413. if (dev_priv->hotplug.stats[i].state != HPD_ENABLED)
  414. continue;
  415. if (!is_dig_port) {
  416. dev_priv->hotplug.event_bits |= BIT(i);
  417. queue_hp = true;
  418. }
  419. if (intel_hpd_irq_storm_detect(dev_priv, i)) {
  420. dev_priv->hotplug.event_bits &= ~BIT(i);
  421. storm_detected = true;
  422. }
  423. }
  424. if (storm_detected && dev_priv->display_irqs_enabled)
  425. dev_priv->display.hpd_irq_setup(dev_priv);
  426. spin_unlock(&dev_priv->irq_lock);
  427. /*
  428. * Our hotplug handler can grab modeset locks (by calling down into the
  429. * fb helpers). Hence it must not be run on our own dev-priv->wq work
  430. * queue for otherwise the flush_work in the pageflip code will
  431. * deadlock.
  432. */
  433. if (queue_dig)
  434. queue_work(dev_priv->hotplug.dp_wq, &dev_priv->hotplug.dig_port_work);
  435. if (queue_hp)
  436. schedule_work(&dev_priv->hotplug.hotplug_work);
  437. }
  438. /**
  439. * intel_hpd_init - initializes and enables hpd support
  440. * @dev_priv: i915 device instance
  441. *
  442. * This function enables the hotplug support. It requires that interrupts have
  443. * already been enabled with intel_irq_init_hw(). From this point on hotplug and
  444. * poll request can run concurrently to other code, so locking rules must be
  445. * obeyed.
  446. *
  447. * This is a separate step from interrupt enabling to simplify the locking rules
  448. * in the driver load and resume code.
  449. *
  450. * Also see: intel_hpd_poll_init(), which enables connector polling
  451. */
  452. void intel_hpd_init(struct drm_i915_private *dev_priv)
  453. {
  454. int i;
  455. for_each_hpd_pin(i) {
  456. dev_priv->hotplug.stats[i].count = 0;
  457. dev_priv->hotplug.stats[i].state = HPD_ENABLED;
  458. }
  459. WRITE_ONCE(dev_priv->hotplug.poll_enabled, false);
  460. schedule_work(&dev_priv->hotplug.poll_init_work);
  461. /*
  462. * Interrupt setup is already guaranteed to be single-threaded, this is
  463. * just to make the assert_spin_locked checks happy.
  464. */
  465. if (dev_priv->display_irqs_enabled && dev_priv->display.hpd_irq_setup) {
  466. spin_lock_irq(&dev_priv->irq_lock);
  467. if (dev_priv->display_irqs_enabled)
  468. dev_priv->display.hpd_irq_setup(dev_priv);
  469. spin_unlock_irq(&dev_priv->irq_lock);
  470. }
  471. }
  472. static void i915_hpd_poll_init_work(struct work_struct *work)
  473. {
  474. struct drm_i915_private *dev_priv =
  475. container_of(work, struct drm_i915_private,
  476. hotplug.poll_init_work);
  477. struct drm_device *dev = &dev_priv->drm;
  478. struct drm_connector *connector;
  479. struct drm_connector_list_iter conn_iter;
  480. bool enabled;
  481. mutex_lock(&dev->mode_config.mutex);
  482. enabled = READ_ONCE(dev_priv->hotplug.poll_enabled);
  483. drm_connector_list_iter_begin(dev, &conn_iter);
  484. drm_for_each_connector_iter(connector, &conn_iter) {
  485. struct intel_connector *intel_connector =
  486. to_intel_connector(connector);
  487. connector->polled = intel_connector->polled;
  488. /* MST has a dynamic intel_connector->encoder and it's reprobing
  489. * is all handled by the MST helpers. */
  490. if (intel_connector->mst_port)
  491. continue;
  492. if (!connector->polled && I915_HAS_HOTPLUG(dev_priv) &&
  493. intel_connector->encoder->hpd_pin > HPD_NONE) {
  494. connector->polled = enabled ?
  495. DRM_CONNECTOR_POLL_CONNECT |
  496. DRM_CONNECTOR_POLL_DISCONNECT :
  497. DRM_CONNECTOR_POLL_HPD;
  498. }
  499. }
  500. drm_connector_list_iter_end(&conn_iter);
  501. if (enabled)
  502. drm_kms_helper_poll_enable(dev);
  503. mutex_unlock(&dev->mode_config.mutex);
  504. /*
  505. * We might have missed any hotplugs that happened while we were
  506. * in the middle of disabling polling
  507. */
  508. if (!enabled)
  509. drm_helper_hpd_irq_event(dev);
  510. }
  511. /**
  512. * intel_hpd_poll_init - enables/disables polling for connectors with hpd
  513. * @dev_priv: i915 device instance
  514. *
  515. * This function enables polling for all connectors, regardless of whether or
  516. * not they support hotplug detection. Under certain conditions HPD may not be
  517. * functional. On most Intel GPUs, this happens when we enter runtime suspend.
  518. * On Valleyview and Cherryview systems, this also happens when we shut off all
  519. * of the powerwells.
  520. *
  521. * Since this function can get called in contexts where we're already holding
  522. * dev->mode_config.mutex, we do the actual hotplug enabling in a seperate
  523. * worker.
  524. *
  525. * Also see: intel_hpd_init(), which restores hpd handling.
  526. */
  527. void intel_hpd_poll_init(struct drm_i915_private *dev_priv)
  528. {
  529. WRITE_ONCE(dev_priv->hotplug.poll_enabled, true);
  530. /*
  531. * We might already be holding dev->mode_config.mutex, so do this in a
  532. * seperate worker
  533. * As well, there's no issue if we race here since we always reschedule
  534. * this worker anyway
  535. */
  536. schedule_work(&dev_priv->hotplug.poll_init_work);
  537. }
  538. void intel_hpd_init_work(struct drm_i915_private *dev_priv)
  539. {
  540. INIT_WORK(&dev_priv->hotplug.hotplug_work, i915_hotplug_work_func);
  541. INIT_WORK(&dev_priv->hotplug.dig_port_work, i915_digport_work_func);
  542. INIT_WORK(&dev_priv->hotplug.poll_init_work, i915_hpd_poll_init_work);
  543. INIT_DELAYED_WORK(&dev_priv->hotplug.reenable_work,
  544. intel_hpd_irq_storm_reenable_work);
  545. }
  546. void intel_hpd_cancel_work(struct drm_i915_private *dev_priv)
  547. {
  548. spin_lock_irq(&dev_priv->irq_lock);
  549. dev_priv->hotplug.long_port_mask = 0;
  550. dev_priv->hotplug.short_port_mask = 0;
  551. dev_priv->hotplug.event_bits = 0;
  552. spin_unlock_irq(&dev_priv->irq_lock);
  553. cancel_work_sync(&dev_priv->hotplug.dig_port_work);
  554. cancel_work_sync(&dev_priv->hotplug.hotplug_work);
  555. cancel_work_sync(&dev_priv->hotplug.poll_init_work);
  556. cancel_delayed_work_sync(&dev_priv->hotplug.reenable_work);
  557. }
  558. bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
  559. {
  560. bool ret = false;
  561. if (pin == HPD_NONE)
  562. return false;
  563. spin_lock_irq(&dev_priv->irq_lock);
  564. if (dev_priv->hotplug.stats[pin].state == HPD_ENABLED) {
  565. dev_priv->hotplug.stats[pin].state = HPD_DISABLED;
  566. ret = true;
  567. }
  568. spin_unlock_irq(&dev_priv->irq_lock);
  569. return ret;
  570. }
  571. void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin)
  572. {
  573. if (pin == HPD_NONE)
  574. return;
  575. spin_lock_irq(&dev_priv->irq_lock);
  576. dev_priv->hotplug.stats[pin].state = HPD_ENABLED;
  577. spin_unlock_irq(&dev_priv->irq_lock);
  578. }