radeon_irq_kms.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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 "drmP.h"
  29. #include "drm_crtc_helper.h"
  30. #include "radeon_drm.h"
  31. #include "radeon_reg.h"
  32. #include "radeon.h"
  33. #include "atom.h"
  34. #define RADEON_WAIT_IDLE_TIMEOUT 200
  35. /**
  36. * radeon_driver_irq_handler_kms - irq handler for KMS
  37. *
  38. * @DRM_IRQ_ARGS: args
  39. *
  40. * This is the irq handler for the radeon KMS driver (all asics).
  41. * radeon_irq_process is a macro that points to the per-asic
  42. * irq handler callback.
  43. */
  44. irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS)
  45. {
  46. struct drm_device *dev = (struct drm_device *) arg;
  47. struct radeon_device *rdev = dev->dev_private;
  48. return radeon_irq_process(rdev);
  49. }
  50. /*
  51. * Handle hotplug events outside the interrupt handler proper.
  52. */
  53. /**
  54. * radeon_hotplug_work_func - display hotplug work handler
  55. *
  56. * @work: work struct
  57. *
  58. * This is the hot plug event work handler (all asics).
  59. * The work gets scheduled from the irq handler if there
  60. * was a hot plug interrupt. It walks the connector table
  61. * and calls the hotplug handler for each one, then sends
  62. * a drm hotplug event to alert userspace.
  63. */
  64. static void radeon_hotplug_work_func(struct work_struct *work)
  65. {
  66. struct radeon_device *rdev = container_of(work, struct radeon_device,
  67. hotplug_work);
  68. struct drm_device *dev = rdev->ddev;
  69. struct drm_mode_config *mode_config = &dev->mode_config;
  70. struct drm_connector *connector;
  71. if (mode_config->num_connector) {
  72. list_for_each_entry(connector, &mode_config->connector_list, head)
  73. radeon_connector_hotplug(connector);
  74. }
  75. /* Just fire off a uevent and let userspace tell us what to do */
  76. drm_helper_hpd_irq_event(dev);
  77. }
  78. /**
  79. * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
  80. *
  81. * @dev: drm dev pointer
  82. *
  83. * Gets the hw ready to enable irqs (all asics).
  84. * This function disables all interrupt sources on the GPU.
  85. */
  86. void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
  87. {
  88. struct radeon_device *rdev = dev->dev_private;
  89. unsigned long irqflags;
  90. unsigned i;
  91. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  92. /* Disable *all* interrupts */
  93. for (i = 0; i < RADEON_NUM_RINGS; i++)
  94. atomic_set(&rdev->irq.ring_int[i], 0);
  95. for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
  96. rdev->irq.hpd[i] = false;
  97. for (i = 0; i < RADEON_MAX_CRTCS; i++) {
  98. rdev->irq.crtc_vblank_int[i] = false;
  99. atomic_set(&rdev->irq.pflip[i], 0);
  100. rdev->irq.afmt[i] = false;
  101. }
  102. radeon_irq_set(rdev);
  103. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  104. /* Clear bits */
  105. radeon_irq_process(rdev);
  106. }
  107. /**
  108. * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
  109. *
  110. * @dev: drm dev pointer
  111. *
  112. * Handles stuff to be done after enabling irqs (all asics).
  113. * Returns 0 on success.
  114. */
  115. int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
  116. {
  117. dev->max_vblank_count = 0x001fffff;
  118. return 0;
  119. }
  120. /**
  121. * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
  122. *
  123. * @dev: drm dev pointer
  124. *
  125. * This function disables all interrupt sources on the GPU (all asics).
  126. */
  127. void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
  128. {
  129. struct radeon_device *rdev = dev->dev_private;
  130. unsigned long irqflags;
  131. unsigned i;
  132. if (rdev == NULL) {
  133. return;
  134. }
  135. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  136. /* Disable *all* interrupts */
  137. for (i = 0; i < RADEON_NUM_RINGS; i++)
  138. atomic_set(&rdev->irq.ring_int[i], 0);
  139. for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
  140. rdev->irq.hpd[i] = false;
  141. for (i = 0; i < RADEON_MAX_CRTCS; i++) {
  142. rdev->irq.crtc_vblank_int[i] = false;
  143. atomic_set(&rdev->irq.pflip[i], 0);
  144. rdev->irq.afmt[i] = false;
  145. }
  146. radeon_irq_set(rdev);
  147. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  148. }
  149. /**
  150. * radeon_msi_ok - asic specific msi checks
  151. *
  152. * @rdev: radeon device pointer
  153. *
  154. * Handles asic specific MSI checks to determine if
  155. * MSIs should be enabled on a particular chip (all asics).
  156. * Returns true if MSIs should be enabled, false if MSIs
  157. * should not be enabled.
  158. */
  159. static bool radeon_msi_ok(struct radeon_device *rdev)
  160. {
  161. /* RV370/RV380 was first asic with MSI support */
  162. if (rdev->family < CHIP_RV380)
  163. return false;
  164. /* MSIs don't work on AGP */
  165. if (rdev->flags & RADEON_IS_AGP)
  166. return false;
  167. /* force MSI on */
  168. if (radeon_msi == 1)
  169. return true;
  170. else if (radeon_msi == 0)
  171. return false;
  172. /* Quirks */
  173. /* HP RS690 only seems to work with MSIs. */
  174. if ((rdev->pdev->device == 0x791f) &&
  175. (rdev->pdev->subsystem_vendor == 0x103c) &&
  176. (rdev->pdev->subsystem_device == 0x30c2))
  177. return true;
  178. /* Dell RS690 only seems to work with MSIs. */
  179. if ((rdev->pdev->device == 0x791f) &&
  180. (rdev->pdev->subsystem_vendor == 0x1028) &&
  181. (rdev->pdev->subsystem_device == 0x01fc))
  182. return true;
  183. /* Dell RS690 only seems to work with MSIs. */
  184. if ((rdev->pdev->device == 0x791f) &&
  185. (rdev->pdev->subsystem_vendor == 0x1028) &&
  186. (rdev->pdev->subsystem_device == 0x01fd))
  187. return true;
  188. /* RV515 seems to have MSI issues where it loses
  189. * MSI rearms occasionally. This leads to lockups and freezes.
  190. * disable it by default.
  191. */
  192. if (rdev->family == CHIP_RV515)
  193. return false;
  194. if (rdev->flags & RADEON_IS_IGP) {
  195. /* APUs work fine with MSIs */
  196. if (rdev->family >= CHIP_PALM)
  197. return true;
  198. /* lots of IGPs have problems with MSIs */
  199. return false;
  200. }
  201. return true;
  202. }
  203. /**
  204. * radeon_irq_kms_init - init driver interrupt info
  205. *
  206. * @rdev: radeon device pointer
  207. *
  208. * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
  209. * Returns 0 for success, error for failure.
  210. */
  211. int radeon_irq_kms_init(struct radeon_device *rdev)
  212. {
  213. int r = 0;
  214. INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
  215. INIT_WORK(&rdev->audio_work, r600_audio_update_hdmi);
  216. spin_lock_init(&rdev->irq.lock);
  217. r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
  218. if (r) {
  219. return r;
  220. }
  221. /* enable msi */
  222. rdev->msi_enabled = 0;
  223. if (radeon_msi_ok(rdev)) {
  224. int ret = pci_enable_msi(rdev->pdev);
  225. if (!ret) {
  226. rdev->msi_enabled = 1;
  227. dev_info(rdev->dev, "radeon: using MSI.\n");
  228. }
  229. }
  230. rdev->irq.installed = true;
  231. r = drm_irq_install(rdev->ddev);
  232. if (r) {
  233. rdev->irq.installed = false;
  234. return r;
  235. }
  236. DRM_INFO("radeon: irq initialized.\n");
  237. return 0;
  238. }
  239. /**
  240. * radeon_irq_kms_fini - tear down driver interrrupt info
  241. *
  242. * @rdev: radeon device pointer
  243. *
  244. * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
  245. */
  246. void radeon_irq_kms_fini(struct radeon_device *rdev)
  247. {
  248. drm_vblank_cleanup(rdev->ddev);
  249. if (rdev->irq.installed) {
  250. drm_irq_uninstall(rdev->ddev);
  251. rdev->irq.installed = false;
  252. if (rdev->msi_enabled)
  253. pci_disable_msi(rdev->pdev);
  254. }
  255. flush_work_sync(&rdev->hotplug_work);
  256. }
  257. /**
  258. * radeon_irq_kms_sw_irq_get - enable software interrupt
  259. *
  260. * @rdev: radeon device pointer
  261. * @ring: ring whose interrupt you want to enable
  262. *
  263. * Enables the software interrupt for a specific ring (all asics).
  264. * The software interrupt is generally used to signal a fence on
  265. * a particular ring.
  266. */
  267. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring)
  268. {
  269. unsigned long irqflags;
  270. if (!rdev->ddev->irq_enabled)
  271. return;
  272. if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) {
  273. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  274. radeon_irq_set(rdev);
  275. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  276. }
  277. }
  278. /**
  279. * radeon_irq_kms_sw_irq_put - disable software interrupt
  280. *
  281. * @rdev: radeon device pointer
  282. * @ring: ring whose interrupt you want to disable
  283. *
  284. * Disables the software interrupt for a specific ring (all asics).
  285. * The software interrupt is generally used to signal a fence on
  286. * a particular ring.
  287. */
  288. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring)
  289. {
  290. unsigned long irqflags;
  291. if (!rdev->ddev->irq_enabled)
  292. return;
  293. if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) {
  294. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  295. radeon_irq_set(rdev);
  296. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  297. }
  298. }
  299. /**
  300. * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
  301. *
  302. * @rdev: radeon device pointer
  303. * @crtc: crtc whose interrupt you want to enable
  304. *
  305. * Enables the pageflip interrupt for a specific crtc (all asics).
  306. * For pageflips we use the vblank interrupt source.
  307. */
  308. void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc)
  309. {
  310. unsigned long irqflags;
  311. if (crtc < 0 || crtc >= rdev->num_crtc)
  312. return;
  313. if (!rdev->ddev->irq_enabled)
  314. return;
  315. if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) {
  316. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  317. radeon_irq_set(rdev);
  318. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  319. }
  320. }
  321. /**
  322. * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
  323. *
  324. * @rdev: radeon device pointer
  325. * @crtc: crtc whose interrupt you want to disable
  326. *
  327. * Disables the pageflip interrupt for a specific crtc (all asics).
  328. * For pageflips we use the vblank interrupt source.
  329. */
  330. void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc)
  331. {
  332. unsigned long irqflags;
  333. if (crtc < 0 || crtc >= rdev->num_crtc)
  334. return;
  335. if (!rdev->ddev->irq_enabled)
  336. return;
  337. if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) {
  338. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  339. radeon_irq_set(rdev);
  340. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  341. }
  342. }
  343. /**
  344. * radeon_irq_kms_enable_afmt - enable audio format change interrupt
  345. *
  346. * @rdev: radeon device pointer
  347. * @block: afmt block whose interrupt you want to enable
  348. *
  349. * Enables the afmt change interrupt for a specific afmt block (all asics).
  350. */
  351. void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block)
  352. {
  353. unsigned long irqflags;
  354. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  355. rdev->irq.afmt[block] = true;
  356. radeon_irq_set(rdev);
  357. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  358. }
  359. /**
  360. * radeon_irq_kms_disable_afmt - disable audio format change interrupt
  361. *
  362. * @rdev: radeon device pointer
  363. * @block: afmt block whose interrupt you want to disable
  364. *
  365. * Disables the afmt change interrupt for a specific afmt block (all asics).
  366. */
  367. void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block)
  368. {
  369. unsigned long irqflags;
  370. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  371. rdev->irq.afmt[block] = false;
  372. radeon_irq_set(rdev);
  373. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  374. }
  375. /**
  376. * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
  377. *
  378. * @rdev: radeon device pointer
  379. * @hpd_mask: mask of hpd pins you want to enable.
  380. *
  381. * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
  382. */
  383. void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
  384. {
  385. unsigned long irqflags;
  386. int i;
  387. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  388. for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
  389. rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
  390. radeon_irq_set(rdev);
  391. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  392. }
  393. /**
  394. * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
  395. *
  396. * @rdev: radeon device pointer
  397. * @hpd_mask: mask of hpd pins you want to disable.
  398. *
  399. * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
  400. */
  401. void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
  402. {
  403. unsigned long irqflags;
  404. int i;
  405. spin_lock_irqsave(&rdev->irq.lock, irqflags);
  406. for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
  407. rdev->irq.hpd[i] &= !(hpd_mask & (1 << i));
  408. radeon_irq_set(rdev);
  409. spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
  410. }