intel_hotplug.c 20 KB

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