intel_hotplug.c 20 KB

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