Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 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 | */ |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame^] | 28 | #include <drm/drmP.h> |
| 29 | #include <drm/drm_crtc_helper.h> |
| 30 | #include <drm/radeon_drm.h> |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 31 | #include "radeon_reg.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 32 | #include "radeon.h" |
| 33 | #include "atom.h" |
| 34 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 35 | #define RADEON_WAIT_IDLE_TIMEOUT 200 |
| 36 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 37 | /** |
| 38 | * radeon_driver_irq_handler_kms - irq handler for KMS |
| 39 | * |
| 40 | * @DRM_IRQ_ARGS: args |
| 41 | * |
| 42 | * This is the irq handler for the radeon KMS driver (all asics). |
| 43 | * radeon_irq_process is a macro that points to the per-asic |
| 44 | * irq handler callback. |
| 45 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 46 | irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS) |
| 47 | { |
| 48 | struct drm_device *dev = (struct drm_device *) arg; |
| 49 | struct radeon_device *rdev = dev->dev_private; |
| 50 | |
| 51 | return radeon_irq_process(rdev); |
| 52 | } |
| 53 | |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 54 | /* |
| 55 | * Handle hotplug events outside the interrupt handler proper. |
| 56 | */ |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 57 | /** |
| 58 | * radeon_hotplug_work_func - display hotplug work handler |
| 59 | * |
| 60 | * @work: work struct |
| 61 | * |
| 62 | * This is the hot plug event work handler (all asics). |
| 63 | * The work gets scheduled from the irq handler if there |
| 64 | * was a hot plug interrupt. It walks the connector table |
| 65 | * and calls the hotplug handler for each one, then sends |
| 66 | * a drm hotplug event to alert userspace. |
| 67 | */ |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 68 | static void radeon_hotplug_work_func(struct work_struct *work) |
| 69 | { |
| 70 | struct radeon_device *rdev = container_of(work, struct radeon_device, |
| 71 | hotplug_work); |
| 72 | struct drm_device *dev = rdev->ddev; |
| 73 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 74 | struct drm_connector *connector; |
| 75 | |
| 76 | if (mode_config->num_connector) { |
| 77 | list_for_each_entry(connector, &mode_config->connector_list, head) |
| 78 | radeon_connector_hotplug(connector); |
| 79 | } |
| 80 | /* Just fire off a uevent and let userspace tell us what to do */ |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 81 | drm_helper_hpd_irq_event(dev); |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 82 | } |
| 83 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 84 | /** |
| 85 | * radeon_driver_irq_preinstall_kms - drm irq preinstall callback |
| 86 | * |
| 87 | * @dev: drm dev pointer |
| 88 | * |
| 89 | * Gets the hw ready to enable irqs (all asics). |
| 90 | * This function disables all interrupt sources on the GPU. |
| 91 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 92 | void radeon_driver_irq_preinstall_kms(struct drm_device *dev) |
| 93 | { |
| 94 | struct radeon_device *rdev = dev->dev_private; |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 95 | unsigned long irqflags; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 96 | unsigned i; |
| 97 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 98 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 99 | /* Disable *all* interrupts */ |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 100 | for (i = 0; i < RADEON_NUM_RINGS; i++) |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 101 | atomic_set(&rdev->irq.ring_int[i], 0); |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 102 | rdev->irq.gui_idle = false; |
Ilija Hadzic | 54bd520 | 2011-10-26 15:43:58 -0400 | [diff] [blame] | 103 | for (i = 0; i < RADEON_MAX_HPD_PINS; i++) |
Alex Deucher | 9e7b414 | 2010-03-16 17:08:06 -0400 | [diff] [blame] | 104 | rdev->irq.hpd[i] = false; |
Ilija Hadzic | 54bd520 | 2011-10-26 15:43:58 -0400 | [diff] [blame] | 105 | for (i = 0; i < RADEON_MAX_CRTCS; i++) { |
| 106 | rdev->irq.crtc_vblank_int[i] = false; |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 107 | atomic_set(&rdev->irq.pflip[i], 0); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 108 | rdev->irq.afmt[i] = false; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 109 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 110 | radeon_irq_set(rdev); |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 111 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 112 | /* Clear bits */ |
| 113 | radeon_irq_process(rdev); |
| 114 | } |
| 115 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 116 | /** |
| 117 | * radeon_driver_irq_postinstall_kms - drm irq preinstall callback |
| 118 | * |
| 119 | * @dev: drm dev pointer |
| 120 | * |
| 121 | * Handles stuff to be done after enabling irqs (all asics). |
| 122 | * Returns 0 on success. |
| 123 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 124 | int radeon_driver_irq_postinstall_kms(struct drm_device *dev) |
| 125 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 126 | dev->max_vblank_count = 0x001fffff; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 130 | /** |
| 131 | * radeon_driver_irq_uninstall_kms - drm irq uninstall callback |
| 132 | * |
| 133 | * @dev: drm dev pointer |
| 134 | * |
| 135 | * This function disables all interrupt sources on the GPU (all asics). |
| 136 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 137 | void radeon_driver_irq_uninstall_kms(struct drm_device *dev) |
| 138 | { |
| 139 | struct radeon_device *rdev = dev->dev_private; |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 140 | unsigned long irqflags; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 141 | unsigned i; |
| 142 | |
| 143 | if (rdev == NULL) { |
| 144 | return; |
| 145 | } |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 146 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 147 | /* Disable *all* interrupts */ |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 148 | for (i = 0; i < RADEON_NUM_RINGS; i++) |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 149 | atomic_set(&rdev->irq.ring_int[i], 0); |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 150 | rdev->irq.gui_idle = false; |
Ilija Hadzic | 54bd520 | 2011-10-26 15:43:58 -0400 | [diff] [blame] | 151 | for (i = 0; i < RADEON_MAX_HPD_PINS; i++) |
Jerome Glisse | 003e69f | 2010-01-07 15:39:14 +0100 | [diff] [blame] | 152 | rdev->irq.hpd[i] = false; |
Ilija Hadzic | 54bd520 | 2011-10-26 15:43:58 -0400 | [diff] [blame] | 153 | for (i = 0; i < RADEON_MAX_CRTCS; i++) { |
| 154 | rdev->irq.crtc_vblank_int[i] = false; |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 155 | atomic_set(&rdev->irq.pflip[i], 0); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 156 | rdev->irq.afmt[i] = false; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 157 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 158 | radeon_irq_set(rdev); |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 159 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 160 | } |
| 161 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 162 | /** |
| 163 | * radeon_msi_ok - asic specific msi checks |
| 164 | * |
| 165 | * @rdev: radeon device pointer |
| 166 | * |
| 167 | * Handles asic specific MSI checks to determine if |
| 168 | * MSIs should be enabled on a particular chip (all asics). |
| 169 | * Returns true if MSIs should be enabled, false if MSIs |
| 170 | * should not be enabled. |
| 171 | */ |
Alex Deucher | 8f6c25c | 2011-10-25 14:58:49 -0400 | [diff] [blame] | 172 | static bool radeon_msi_ok(struct radeon_device *rdev) |
| 173 | { |
| 174 | /* RV370/RV380 was first asic with MSI support */ |
| 175 | if (rdev->family < CHIP_RV380) |
| 176 | return false; |
| 177 | |
| 178 | /* MSIs don't work on AGP */ |
| 179 | if (rdev->flags & RADEON_IS_AGP) |
| 180 | return false; |
| 181 | |
Alex Deucher | a18cee1 | 2011-11-01 14:20:30 -0400 | [diff] [blame] | 182 | /* force MSI on */ |
| 183 | if (radeon_msi == 1) |
| 184 | return true; |
| 185 | else if (radeon_msi == 0) |
| 186 | return false; |
| 187 | |
Alex Deucher | b362105 | 2011-10-25 15:11:08 -0400 | [diff] [blame] | 188 | /* Quirks */ |
| 189 | /* HP RS690 only seems to work with MSIs. */ |
| 190 | if ((rdev->pdev->device == 0x791f) && |
| 191 | (rdev->pdev->subsystem_vendor == 0x103c) && |
| 192 | (rdev->pdev->subsystem_device == 0x30c2)) |
| 193 | return true; |
| 194 | |
Alex Deucher | 01e718e | 2011-11-01 14:14:18 -0400 | [diff] [blame] | 195 | /* Dell RS690 only seems to work with MSIs. */ |
| 196 | if ((rdev->pdev->device == 0x791f) && |
| 197 | (rdev->pdev->subsystem_vendor == 0x1028) && |
Alex Deucher | 44517c4 | 2012-01-15 08:51:12 -0500 | [diff] [blame] | 198 | (rdev->pdev->subsystem_device == 0x01fc)) |
| 199 | return true; |
| 200 | |
| 201 | /* Dell RS690 only seems to work with MSIs. */ |
| 202 | if ((rdev->pdev->device == 0x791f) && |
| 203 | (rdev->pdev->subsystem_vendor == 0x1028) && |
Alex Deucher | 01e718e | 2011-11-01 14:14:18 -0400 | [diff] [blame] | 204 | (rdev->pdev->subsystem_device == 0x01fd)) |
| 205 | return true; |
| 206 | |
Dave Airlie | 16a5e32 | 2012-04-13 11:14:50 +0100 | [diff] [blame] | 207 | /* RV515 seems to have MSI issues where it loses |
| 208 | * MSI rearms occasionally. This leads to lockups and freezes. |
| 209 | * disable it by default. |
| 210 | */ |
| 211 | if (rdev->family == CHIP_RV515) |
| 212 | return false; |
Alex Deucher | 8f6c25c | 2011-10-25 14:58:49 -0400 | [diff] [blame] | 213 | if (rdev->flags & RADEON_IS_IGP) { |
| 214 | /* APUs work fine with MSIs */ |
| 215 | if (rdev->family >= CHIP_PALM) |
| 216 | return true; |
| 217 | /* lots of IGPs have problems with MSIs */ |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | return true; |
| 222 | } |
| 223 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 224 | /** |
| 225 | * radeon_irq_kms_init - init driver interrupt info |
| 226 | * |
| 227 | * @rdev: radeon device pointer |
| 228 | * |
| 229 | * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics). |
| 230 | * Returns 0 for success, error for failure. |
| 231 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 232 | int radeon_irq_kms_init(struct radeon_device *rdev) |
| 233 | { |
| 234 | int r = 0; |
| 235 | |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 236 | INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 237 | INIT_WORK(&rdev->audio_work, r600_audio_update_hdmi); |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 238 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 239 | spin_lock_init(&rdev->irq.lock); |
Alex Deucher | 9e7b414 | 2010-03-16 17:08:06 -0400 | [diff] [blame] | 240 | r = drm_vblank_init(rdev->ddev, rdev->num_crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 241 | if (r) { |
| 242 | return r; |
| 243 | } |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 244 | /* enable msi */ |
| 245 | rdev->msi_enabled = 0; |
Alex Deucher | 8f6c25c | 2011-10-25 14:58:49 -0400 | [diff] [blame] | 246 | |
| 247 | if (radeon_msi_ok(rdev)) { |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 248 | int ret = pci_enable_msi(rdev->pdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 249 | if (!ret) { |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 250 | rdev->msi_enabled = 1; |
Alex Deucher | da7be68 | 2010-08-12 18:05:34 -0400 | [diff] [blame] | 251 | dev_info(rdev->dev, "radeon: using MSI.\n"); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 252 | } |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 253 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 254 | rdev->irq.installed = true; |
Jerome Glisse | 003e69f | 2010-01-07 15:39:14 +0100 | [diff] [blame] | 255 | r = drm_irq_install(rdev->ddev); |
| 256 | if (r) { |
| 257 | rdev->irq.installed = false; |
| 258 | return r; |
| 259 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 260 | DRM_INFO("radeon: irq initialized.\n"); |
| 261 | return 0; |
| 262 | } |
| 263 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 264 | /** |
| 265 | * radeon_irq_kms_fini - tear down driver interrrupt info |
| 266 | * |
| 267 | * @rdev: radeon device pointer |
| 268 | * |
| 269 | * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics). |
| 270 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 271 | void radeon_irq_kms_fini(struct radeon_device *rdev) |
| 272 | { |
Jerome Glisse | 003e69f | 2010-01-07 15:39:14 +0100 | [diff] [blame] | 273 | drm_vblank_cleanup(rdev->ddev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 274 | if (rdev->irq.installed) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 275 | drm_irq_uninstall(rdev->ddev); |
Jerome Glisse | 003e69f | 2010-01-07 15:39:14 +0100 | [diff] [blame] | 276 | rdev->irq.installed = false; |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 277 | if (rdev->msi_enabled) |
| 278 | pci_disable_msi(rdev->pdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 279 | } |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 280 | flush_work_sync(&rdev->hotplug_work); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 281 | } |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 282 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 283 | /** |
| 284 | * radeon_irq_kms_sw_irq_get - enable software interrupt |
| 285 | * |
| 286 | * @rdev: radeon device pointer |
| 287 | * @ring: ring whose interrupt you want to enable |
| 288 | * |
| 289 | * Enables the software interrupt for a specific ring (all asics). |
| 290 | * The software interrupt is generally used to signal a fence on |
| 291 | * a particular ring. |
| 292 | */ |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 293 | void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring) |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 294 | { |
| 295 | unsigned long irqflags; |
| 296 | |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 297 | if (!rdev->ddev->irq_enabled) |
| 298 | return; |
| 299 | |
| 300 | if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) { |
| 301 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 302 | radeon_irq_set(rdev); |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 303 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 304 | } |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 305 | } |
| 306 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 307 | /** |
| 308 | * radeon_irq_kms_sw_irq_put - disable software interrupt |
| 309 | * |
| 310 | * @rdev: radeon device pointer |
| 311 | * @ring: ring whose interrupt you want to disable |
| 312 | * |
| 313 | * Disables the software interrupt for a specific ring (all asics). |
| 314 | * The software interrupt is generally used to signal a fence on |
| 315 | * a particular ring. |
| 316 | */ |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 317 | void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring) |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 318 | { |
| 319 | unsigned long irqflags; |
| 320 | |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 321 | if (!rdev->ddev->irq_enabled) |
| 322 | return; |
| 323 | |
| 324 | if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) { |
| 325 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 326 | radeon_irq_set(rdev); |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 327 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 328 | } |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 329 | } |
| 330 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 331 | /** |
| 332 | * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt |
| 333 | * |
| 334 | * @rdev: radeon device pointer |
| 335 | * @crtc: crtc whose interrupt you want to enable |
| 336 | * |
| 337 | * Enables the pageflip interrupt for a specific crtc (all asics). |
| 338 | * For pageflips we use the vblank interrupt source. |
| 339 | */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 340 | void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc) |
| 341 | { |
| 342 | unsigned long irqflags; |
| 343 | |
| 344 | if (crtc < 0 || crtc >= rdev->num_crtc) |
| 345 | return; |
| 346 | |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 347 | if (!rdev->ddev->irq_enabled) |
| 348 | return; |
| 349 | |
| 350 | if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) { |
| 351 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 352 | radeon_irq_set(rdev); |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 353 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 354 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 355 | } |
| 356 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 357 | /** |
| 358 | * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt |
| 359 | * |
| 360 | * @rdev: radeon device pointer |
| 361 | * @crtc: crtc whose interrupt you want to disable |
| 362 | * |
| 363 | * Disables the pageflip interrupt for a specific crtc (all asics). |
| 364 | * For pageflips we use the vblank interrupt source. |
| 365 | */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 366 | void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc) |
| 367 | { |
| 368 | unsigned long irqflags; |
| 369 | |
| 370 | if (crtc < 0 || crtc >= rdev->num_crtc) |
| 371 | return; |
| 372 | |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 373 | if (!rdev->ddev->irq_enabled) |
| 374 | return; |
| 375 | |
| 376 | if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) { |
| 377 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 378 | radeon_irq_set(rdev); |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 379 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 380 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 381 | } |
| 382 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 383 | /** |
| 384 | * radeon_irq_kms_enable_afmt - enable audio format change interrupt |
| 385 | * |
| 386 | * @rdev: radeon device pointer |
| 387 | * @block: afmt block whose interrupt you want to enable |
| 388 | * |
| 389 | * Enables the afmt change interrupt for a specific afmt block (all asics). |
| 390 | */ |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 391 | void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block) |
| 392 | { |
| 393 | unsigned long irqflags; |
| 394 | |
| 395 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
| 396 | rdev->irq.afmt[block] = true; |
| 397 | radeon_irq_set(rdev); |
| 398 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
| 399 | |
| 400 | } |
| 401 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 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 | */ |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 410 | void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block) |
| 411 | { |
| 412 | unsigned long irqflags; |
| 413 | |
| 414 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
| 415 | rdev->irq.afmt[block] = false; |
| 416 | radeon_irq_set(rdev); |
| 417 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
| 418 | } |
| 419 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 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 | */ |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 428 | void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask) |
| 429 | { |
| 430 | unsigned long irqflags; |
| 431 | int i; |
| 432 | |
| 433 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
| 434 | for (i = 0; i < RADEON_MAX_HPD_PINS; ++i) |
| 435 | rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i)); |
| 436 | radeon_irq_set(rdev); |
| 437 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
| 438 | } |
| 439 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 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 | */ |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 448 | void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask) |
| 449 | { |
| 450 | unsigned long irqflags; |
| 451 | int i; |
| 452 | |
| 453 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
| 454 | for (i = 0; i < RADEON_MAX_HPD_PINS; ++i) |
| 455 | rdev->irq.hpd[i] &= !(hpd_mask & (1 << i)); |
| 456 | radeon_irq_set(rdev); |
| 457 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
| 458 | } |
| 459 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 460 | /** |
| 461 | * radeon_irq_kms_wait_gui_idle - waits for drawing engine to be idle |
| 462 | * |
| 463 | * @rdev: radeon device pointer |
| 464 | * |
| 465 | * Enabled the GUI idle interrupt and waits for it to fire (r6xx+). |
| 466 | * This is currently used to make sure the 3D engine is idle for power |
| 467 | * management, but should be replaces with proper fence waits. |
| 468 | * GUI idle interrupts don't work very well on pre-r6xx hw and it also |
| 469 | * does not take into account other aspects of the chip that may be busy. |
| 470 | * DO NOT USE GOING FORWARD. |
| 471 | */ |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 472 | int radeon_irq_kms_wait_gui_idle(struct radeon_device *rdev) |
| 473 | { |
| 474 | unsigned long irqflags; |
| 475 | int r; |
| 476 | |
| 477 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
| 478 | rdev->irq.gui_idle = true; |
| 479 | radeon_irq_set(rdev); |
| 480 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
| 481 | |
| 482 | r = wait_event_timeout(rdev->irq.idle_queue, radeon_gui_idle(rdev), |
| 483 | msecs_to_jiffies(RADEON_WAIT_IDLE_TIMEOUT)); |
| 484 | |
| 485 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
| 486 | rdev->irq.gui_idle = false; |
| 487 | radeon_irq_set(rdev); |
| 488 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
| 489 | return r; |
| 490 | } |