intel_hotplug.c 21 KB

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