radeon_irq_kms.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include <drm/drmP.h>
  29. #include <drm/drm_crtc_helper.h>
  30. #include <drm/radeon_drm.h>
  31. #include "radeon_reg.h"
  32. #include "radeon.h"
  33. #include "atom.h"
  34. #include <linux/pm_runtime.h>
  35. #define RADEON_WAIT_IDLE_TIMEOUT 200
  36. /**
  37. * radeon_driver_irq_handler_kms - irq handler for KMS
  38. *
  39. * @int irq, void *arg: args
  40. *
  41. * This is the irq handler for the radeon KMS driver (all asics).
  42. * radeon_irq_process is a macro that points to the per-asic
  43. * irq handler callback.
  44. */
  45. irqreturn_t radeon_driver_irq_handler_kms(int irq, void *arg)
  46. {
  47. struct drm_device *dev = (struct drm_device *) arg;
  48. struct radeon_device *rdev = dev->dev_private;
  49. irqreturn_t ret;
  50. ret = radeon_irq_process(rdev);
  51. if (ret == IRQ_HANDLED)
  52. pm_runtime_mark_last_busy(dev->dev);
  53. return ret;
  54. }
  55. /*
  56. * Handle hotplug events outside the interrupt handler proper.
  57. */
  58. /**
  59. * radeon_hotplug_work_func - display hotplug work handler
  60. *
  61. * @work: work struct
  62. *
  63. * This is the hot plug event work handler (all asics).
  64. * The work gets scheduled from the irq handler if there
  65. * was a hot plug interrupt. It walks the connector table
  66. * and calls the hotplug handler for each one, then sends
  67. * a drm hotplug event to alert userspace.
  68. */
  69. static void radeon_hotplug_work_func(struct work_struct *work)
  70. {
  71. struct radeon_device *rdev = container_of(work, struct radeon_device,
  72. hotplug_work);
  73. struct drm_device *dev = rdev->ddev;
  74. struct drm_mode_config *mode_config = &dev->mode_config;
  75. struct drm_connector *connector;
  76. mutex_lock(&mode_config->mutex);
  77. if (mode_config->num_connector) {
  78. list_for_each_entry(connector, &mode_config->connector_list, head)
  79. radeon_connector_hotplug(connector);
  80. }
  81. mutex_unlock(&mode_config->mutex);
  82. /* Just fire off a uevent and let userspace tell us what to do */
  83. drm_helper_hpd_irq_event(dev);
  84. }
  85. /**
  86. * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
  87. *
  88. * @dev: drm dev pointer
  89. *
  90. * Gets the hw ready to enable irqs (all asics).
  91. * This function disables all interrupt sources on the GPU.
  92. */
  93. void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
  94. {
  95. struct radeon_device *rdev = dev->dev_private;
  96. unsigned long irqflags;
  97. unsigned i;
  98. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  99. /* Disable *all* interrupts */
  100. for (i = 0; i < RADEON_NUM_RINGS; i++)
  101. atomic_set(&rdev->irq.ring_int[i], 0);
  102. rdev->irq.dpm_thermal = false;
  103. for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
  104. rdev->irq.hpd[i] = false;
  105. for (i = 0; i < RADEON_MAX_CRTCS; i++) {
  106. rdev->irq.crtc_vblank_int[i] = false;
  107. atomic_set(&rdev->irq.pflip[i], 0);
  108. rdev->irq.afmt[i] = false;
  109. }
  110. radeon_irq_set(rdev);
  111. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  112. /* Clear bits */
  113. radeon_irq_process(rdev);
  114. }
  115. /**
  116. * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
  117. *
  118. * @dev: drm dev pointer
  119. *
  120. * Handles stuff to be done after enabling irqs (all asics).
  121. * Returns 0 on success.
  122. */
  123. int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
  124. {
  125. dev->max_vblank_count = 0x001fffff;
  126. return 0;
  127. }
  128. /**
  129. * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
  130. *
  131. * @dev: drm dev pointer
  132. *
  133. * This function disables all interrupt sources on the GPU (all asics).
  134. */
  135. void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
  136. {
  137. struct radeon_device *rdev = dev->dev_private;
  138. unsigned long irqflags;
  139. unsigned i;
  140. if (rdev == NULL) {
  141. return;
  142. }
  143. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  144. /* Disable *all* interrupts */
  145. for (i = 0; i < RADEON_NUM_RINGS; i++)
  146. atomic_set(&rdev->irq.ring_int[i], 0);
  147. rdev->irq.dpm_thermal = false;
  148. for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
  149. rdev->irq.hpd[i] = false;
  150. for (i = 0; i < RADEON_MAX_CRTCS; i++) {
  151. rdev->irq.crtc_vblank_int[i] = false;
  152. atomic_set(&rdev->irq.pflip[i], 0);
  153. rdev->irq.afmt[i] = false;
  154. }
  155. radeon_irq_set(rdev);
  156. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  157. }
  158. /**
  159. * radeon_msi_ok - asic specific msi checks
  160. *
  161. * @rdev: radeon device pointer
  162. *
  163. * Handles asic specific MSI checks to determine if
  164. * MSIs should be enabled on a particular chip (all asics).
  165. * Returns true if MSIs should be enabled, false if MSIs
  166. * should not be enabled.
  167. */
  168. static bool radeon_msi_ok(struct radeon_device *rdev)
  169. {
  170. /* RV370/RV380 was first asic with MSI support */
  171. if (rdev->family < CHIP_RV380)
  172. return false;
  173. /* MSIs don't work on AGP */
  174. if (rdev->flags & RADEON_IS_AGP)
  175. return false;
  176. /*
  177. * Older chips have a HW limitation, they can only generate 40 bits
  178. * of address for "64-bit" MSIs which breaks on some platforms, notably
  179. * IBM POWER servers, so we limit them
  180. */
  181. if (rdev->family < CHIP_BONAIRE) {
  182. dev_info(rdev->dev, "radeon: MSI limited to 32-bit\n");
  183. rdev->pdev->no_64bit_msi = 1;
  184. }
  185. /* force MSI on */
  186. if (radeon_msi == 1)
  187. return true;
  188. else if (radeon_msi == 0)
  189. return false;
  190. /* Quirks */
  191. /* HP RS690 only seems to work with MSIs. */
  192. if ((rdev->pdev->device == 0x791f) &&
  193. (rdev->pdev->subsystem_vendor == 0x103c) &&
  194. (rdev->pdev->subsystem_device == 0x30c2))
  195. return true;
  196. /* Dell RS690 only seems to work with MSIs. */
  197. if ((rdev->pdev->device == 0x791f) &&
  198. (rdev->pdev->subsystem_vendor == 0x1028) &&
  199. (rdev->pdev->subsystem_device == 0x01fc))
  200. return true;
  201. /* Dell RS690 only seems to work with MSIs. */
  202. if ((rdev->pdev->device == 0x791f) &&
  203. (rdev->pdev->subsystem_vendor == 0x1028) &&
  204. (rdev->pdev->subsystem_device == 0x01fd))
  205. return true;
  206. /* Gateway RS690 only seems to work with MSIs. */
  207. if ((rdev->pdev->device == 0x791f) &&
  208. (rdev->pdev->subsystem_vendor == 0x107b) &&
  209. (rdev->pdev->subsystem_device == 0x0185))
  210. return true;
  211. /* try and enable MSIs by default on all RS690s */
  212. if (rdev->family == CHIP_RS690)
  213. return true;
  214. /* RV515 seems to have MSI issues where it loses
  215. * MSI rearms occasionally. This leads to lockups and freezes.
  216. * disable it by default.
  217. */
  218. if (rdev->family == CHIP_RV515)
  219. return false;
  220. if (rdev->flags & RADEON_IS_IGP) {
  221. /* APUs work fine with MSIs */
  222. if (rdev->family >= CHIP_PALM)
  223. return true;
  224. /* lots of IGPs have problems with MSIs */
  225. return false;
  226. }
  227. return true;
  228. }
  229. /**
  230. * radeon_irq_kms_init - init driver interrupt info
  231. *
  232. * @rdev: radeon device pointer
  233. *
  234. * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
  235. * Returns 0 for success, error for failure.
  236. */
  237. int radeon_irq_kms_init(struct radeon_device *rdev)
  238. {
  239. int r = 0;
  240. spin_lock_init(&rdev->irq.lock);
  241. r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
  242. if (r) {
  243. return r;
  244. }
  245. /* enable msi */
  246. rdev->msi_enabled = 0;
  247. if (radeon_msi_ok(rdev)) {
  248. int ret = pci_enable_msi(rdev->pdev);
  249. if (!ret) {
  250. rdev->msi_enabled = 1;
  251. dev_info(rdev->dev, "radeon: using MSI.\n");
  252. }
  253. }
  254. INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
  255. INIT_WORK(&rdev->audio_work, r600_audio_update_hdmi);
  256. rdev->irq.installed = true;
  257. r = drm_irq_install(rdev->ddev, rdev->ddev->pdev->irq);
  258. if (r) {
  259. rdev->irq.installed = false;
  260. flush_work(&rdev->hotplug_work);
  261. return r;
  262. }
  263. DRM_INFO("radeon: irq initialized.\n");
  264. return 0;
  265. }
  266. /**
  267. * radeon_irq_kms_fini - tear down driver interrupt info
  268. *
  269. * @rdev: radeon device pointer
  270. *
  271. * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
  272. */
  273. void radeon_irq_kms_fini(struct radeon_device *rdev)
  274. {
  275. drm_vblank_cleanup(rdev->ddev);
  276. if (rdev->irq.installed) {
  277. drm_irq_uninstall(rdev->ddev);
  278. rdev->irq.installed = false;
  279. if (rdev->msi_enabled)
  280. pci_disable_msi(rdev->pdev);
  281. flush_work(&rdev->hotplug_work);
  282. }
  283. }
  284. /**
  285. * radeon_irq_kms_sw_irq_get - enable software interrupt
  286. *
  287. * @rdev: radeon device pointer
  288. * @ring: ring whose interrupt you want to enable
  289. *
  290. * Enables the software interrupt for a specific ring (all asics).
  291. * The software interrupt is generally used to signal a fence on
  292. * a particular ring.
  293. */
  294. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring)
  295. {
  296. unsigned long irqflags;
  297. if (!rdev->ddev->irq_enabled)
  298. return;
  299. if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) {
  300. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  301. radeon_irq_set(rdev);
  302. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  303. }
  304. }
  305. /**
  306. * radeon_irq_kms_sw_irq_get_delayed - enable software interrupt
  307. *
  308. * @rdev: radeon device pointer
  309. * @ring: ring whose interrupt you want to enable
  310. *
  311. * Enables the software interrupt for a specific ring (all asics).
  312. * The software interrupt is generally used to signal a fence on
  313. * a particular ring.
  314. */
  315. bool radeon_irq_kms_sw_irq_get_delayed(struct radeon_device *rdev, int ring)
  316. {
  317. return atomic_inc_return(&rdev->irq.ring_int[ring]) == 1;
  318. }
  319. /**
  320. * radeon_irq_kms_sw_irq_put - disable software interrupt
  321. *
  322. * @rdev: radeon device pointer
  323. * @ring: ring whose interrupt you want to disable
  324. *
  325. * Disables the software interrupt for a specific ring (all asics).
  326. * The software interrupt is generally used to signal a fence on
  327. * a particular ring.
  328. */
  329. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring)
  330. {
  331. unsigned long irqflags;
  332. if (!rdev->ddev->irq_enabled)
  333. return;
  334. if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) {
  335. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  336. radeon_irq_set(rdev);
  337. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  338. }
  339. }
  340. /**
  341. * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
  342. *
  343. * @rdev: radeon device pointer
  344. * @crtc: crtc whose interrupt you want to enable
  345. *
  346. * Enables the pageflip interrupt for a specific crtc (all asics).
  347. * For pageflips we use the vblank interrupt source.
  348. */
  349. void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc)
  350. {
  351. unsigned long irqflags;
  352. if (crtc < 0 || crtc >= rdev->num_crtc)
  353. return;
  354. if (!rdev->ddev->irq_enabled)
  355. return;
  356. if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) {
  357. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  358. radeon_irq_set(rdev);
  359. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  360. }
  361. }
  362. /**
  363. * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
  364. *
  365. * @rdev: radeon device pointer
  366. * @crtc: crtc whose interrupt you want to disable
  367. *
  368. * Disables the pageflip interrupt for a specific crtc (all asics).
  369. * For pageflips we use the vblank interrupt source.
  370. */
  371. void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc)
  372. {
  373. unsigned long irqflags;
  374. if (crtc < 0 || crtc >= rdev->num_crtc)
  375. return;
  376. if (!rdev->ddev->irq_enabled)
  377. return;
  378. if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) {
  379. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  380. radeon_irq_set(rdev);
  381. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  382. }
  383. }
  384. /**
  385. * radeon_irq_kms_enable_afmt - enable audio format change interrupt
  386. *
  387. * @rdev: radeon device pointer
  388. * @block: afmt block whose interrupt you want to enable
  389. *
  390. * Enables the afmt change interrupt for a specific afmt block (all asics).
  391. */
  392. void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block)
  393. {
  394. unsigned long irqflags;
  395. if (!rdev->ddev->irq_enabled)
  396. return;
  397. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  398. rdev->irq.afmt[block] = true;
  399. radeon_irq_set(rdev);
  400. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  401. }
  402. /**
  403. * radeon_irq_kms_disable_afmt - disable audio format change interrupt
  404. *
  405. * @rdev: radeon device pointer
  406. * @block: afmt block whose interrupt you want to disable
  407. *
  408. * Disables the afmt change interrupt for a specific afmt block (all asics).
  409. */
  410. void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block)
  411. {
  412. unsigned long irqflags;
  413. if (!rdev->ddev->irq_enabled)
  414. return;
  415. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  416. rdev->irq.afmt[block] = false;
  417. radeon_irq_set(rdev);
  418. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  419. }
  420. /**
  421. * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
  422. *
  423. * @rdev: radeon device pointer
  424. * @hpd_mask: mask of hpd pins you want to enable.
  425. *
  426. * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
  427. */
  428. void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
  429. {
  430. unsigned long irqflags;
  431. int i;
  432. if (!rdev->ddev->irq_enabled)
  433. return;
  434. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  435. for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
  436. rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
  437. radeon_irq_set(rdev);
  438. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  439. }
  440. /**
  441. * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
  442. *
  443. * @rdev: radeon device pointer
  444. * @hpd_mask: mask of hpd pins you want to disable.
  445. *
  446. * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
  447. */
  448. void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
  449. {
  450. unsigned long irqflags;
  451. int i;
  452. if (!rdev->ddev->irq_enabled)
  453. return;
  454. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  455. for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
  456. rdev->irq.hpd[i] &= !(hpd_mask & (1 << i));
  457. radeon_irq_set(rdev);
  458. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  459. }