intel_hotplug.c 19 KB

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