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 | /** |
Alex Deucher | 8f61b34 | 2013-06-14 09:13:52 -0400 | [diff] [blame] | 85 | * radeon_irq_reset_work_func - execute gpu reset |
| 86 | * |
| 87 | * @work: work struct |
| 88 | * |
| 89 | * Execute scheduled gpu reset (cayman+). |
| 90 | * This function is called when the irq handler |
| 91 | * thinks we need a gpu reset. |
| 92 | */ |
| 93 | static void radeon_irq_reset_work_func(struct work_struct *work) |
| 94 | { |
| 95 | struct radeon_device *rdev = container_of(work, struct radeon_device, |
| 96 | reset_work); |
| 97 | |
| 98 | radeon_gpu_reset(rdev); |
| 99 | } |
| 100 | |
| 101 | /** |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 102 | * radeon_driver_irq_preinstall_kms - drm irq preinstall callback |
| 103 | * |
| 104 | * @dev: drm dev pointer |
| 105 | * |
| 106 | * Gets the hw ready to enable irqs (all asics). |
| 107 | * This function disables all interrupt sources on the GPU. |
| 108 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 109 | void radeon_driver_irq_preinstall_kms(struct drm_device *dev) |
| 110 | { |
| 111 | struct radeon_device *rdev = dev->dev_private; |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 112 | unsigned long irqflags; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 113 | unsigned i; |
| 114 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 115 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 116 | /* Disable *all* interrupts */ |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 117 | for (i = 0; i < RADEON_NUM_RINGS; i++) |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 118 | atomic_set(&rdev->irq.ring_int[i], 0); |
Alex Deucher | 4a6369e | 2013-04-12 14:04:10 -0400 | [diff] [blame^] | 119 | rdev->irq.dpm_thermal = false; |
Ilija Hadzic | 54bd520 | 2011-10-26 15:43:58 -0400 | [diff] [blame] | 120 | for (i = 0; i < RADEON_MAX_HPD_PINS; i++) |
Alex Deucher | 9e7b414 | 2010-03-16 17:08:06 -0400 | [diff] [blame] | 121 | rdev->irq.hpd[i] = false; |
Ilija Hadzic | 54bd520 | 2011-10-26 15:43:58 -0400 | [diff] [blame] | 122 | for (i = 0; i < RADEON_MAX_CRTCS; i++) { |
| 123 | rdev->irq.crtc_vblank_int[i] = false; |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 124 | atomic_set(&rdev->irq.pflip[i], 0); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 125 | rdev->irq.afmt[i] = false; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 126 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 127 | radeon_irq_set(rdev); |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 128 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 129 | /* Clear bits */ |
| 130 | radeon_irq_process(rdev); |
| 131 | } |
| 132 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 133 | /** |
| 134 | * radeon_driver_irq_postinstall_kms - drm irq preinstall callback |
| 135 | * |
| 136 | * @dev: drm dev pointer |
| 137 | * |
| 138 | * Handles stuff to be done after enabling irqs (all asics). |
| 139 | * Returns 0 on success. |
| 140 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 141 | int radeon_driver_irq_postinstall_kms(struct drm_device *dev) |
| 142 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 143 | dev->max_vblank_count = 0x001fffff; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 144 | return 0; |
| 145 | } |
| 146 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 147 | /** |
| 148 | * radeon_driver_irq_uninstall_kms - drm irq uninstall callback |
| 149 | * |
| 150 | * @dev: drm dev pointer |
| 151 | * |
| 152 | * This function disables all interrupt sources on the GPU (all asics). |
| 153 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 154 | void radeon_driver_irq_uninstall_kms(struct drm_device *dev) |
| 155 | { |
| 156 | struct radeon_device *rdev = dev->dev_private; |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 157 | unsigned long irqflags; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 158 | unsigned i; |
| 159 | |
| 160 | if (rdev == NULL) { |
| 161 | return; |
| 162 | } |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 163 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 164 | /* Disable *all* interrupts */ |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 165 | for (i = 0; i < RADEON_NUM_RINGS; i++) |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 166 | atomic_set(&rdev->irq.ring_int[i], 0); |
Alex Deucher | 4a6369e | 2013-04-12 14:04:10 -0400 | [diff] [blame^] | 167 | rdev->irq.dpm_thermal = false; |
Ilija Hadzic | 54bd520 | 2011-10-26 15:43:58 -0400 | [diff] [blame] | 168 | for (i = 0; i < RADEON_MAX_HPD_PINS; i++) |
Jerome Glisse | 003e69f | 2010-01-07 15:39:14 +0100 | [diff] [blame] | 169 | rdev->irq.hpd[i] = false; |
Ilija Hadzic | 54bd520 | 2011-10-26 15:43:58 -0400 | [diff] [blame] | 170 | for (i = 0; i < RADEON_MAX_CRTCS; i++) { |
| 171 | rdev->irq.crtc_vblank_int[i] = false; |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 172 | atomic_set(&rdev->irq.pflip[i], 0); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 173 | rdev->irq.afmt[i] = false; |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 174 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 175 | radeon_irq_set(rdev); |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 176 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 179 | /** |
| 180 | * radeon_msi_ok - asic specific msi checks |
| 181 | * |
| 182 | * @rdev: radeon device pointer |
| 183 | * |
| 184 | * Handles asic specific MSI checks to determine if |
| 185 | * MSIs should be enabled on a particular chip (all asics). |
| 186 | * Returns true if MSIs should be enabled, false if MSIs |
| 187 | * should not be enabled. |
| 188 | */ |
Alex Deucher | 8f6c25c | 2011-10-25 14:58:49 -0400 | [diff] [blame] | 189 | static bool radeon_msi_ok(struct radeon_device *rdev) |
| 190 | { |
| 191 | /* RV370/RV380 was first asic with MSI support */ |
| 192 | if (rdev->family < CHIP_RV380) |
| 193 | return false; |
| 194 | |
| 195 | /* MSIs don't work on AGP */ |
| 196 | if (rdev->flags & RADEON_IS_AGP) |
| 197 | return false; |
| 198 | |
Alex Deucher | a18cee1 | 2011-11-01 14:20:30 -0400 | [diff] [blame] | 199 | /* force MSI on */ |
| 200 | if (radeon_msi == 1) |
| 201 | return true; |
| 202 | else if (radeon_msi == 0) |
| 203 | return false; |
| 204 | |
Alex Deucher | b362105 | 2011-10-25 15:11:08 -0400 | [diff] [blame] | 205 | /* Quirks */ |
| 206 | /* HP RS690 only seems to work with MSIs. */ |
| 207 | if ((rdev->pdev->device == 0x791f) && |
| 208 | (rdev->pdev->subsystem_vendor == 0x103c) && |
| 209 | (rdev->pdev->subsystem_device == 0x30c2)) |
| 210 | return true; |
| 211 | |
Alex Deucher | 01e718e | 2011-11-01 14:14:18 -0400 | [diff] [blame] | 212 | /* Dell RS690 only seems to work with MSIs. */ |
| 213 | if ((rdev->pdev->device == 0x791f) && |
| 214 | (rdev->pdev->subsystem_vendor == 0x1028) && |
Alex Deucher | 44517c4 | 2012-01-15 08:51:12 -0500 | [diff] [blame] | 215 | (rdev->pdev->subsystem_device == 0x01fc)) |
| 216 | return true; |
| 217 | |
| 218 | /* Dell RS690 only seems to work with MSIs. */ |
| 219 | if ((rdev->pdev->device == 0x791f) && |
| 220 | (rdev->pdev->subsystem_vendor == 0x1028) && |
Alex Deucher | 01e718e | 2011-11-01 14:14:18 -0400 | [diff] [blame] | 221 | (rdev->pdev->subsystem_device == 0x01fd)) |
| 222 | return true; |
| 223 | |
Alex Deucher | 3a6d59d | 2012-09-26 12:31:45 -0400 | [diff] [blame] | 224 | /* Gateway RS690 only seems to work with MSIs. */ |
| 225 | if ((rdev->pdev->device == 0x791f) && |
| 226 | (rdev->pdev->subsystem_vendor == 0x107b) && |
| 227 | (rdev->pdev->subsystem_device == 0x0185)) |
| 228 | return true; |
| 229 | |
Alex Deucher | fb6ca6d | 2012-09-26 12:40:45 -0400 | [diff] [blame] | 230 | /* try and enable MSIs by default on all RS690s */ |
| 231 | if (rdev->family == CHIP_RS690) |
| 232 | return true; |
| 233 | |
Dave Airlie | 16a5e32 | 2012-04-13 11:14:50 +0100 | [diff] [blame] | 234 | /* RV515 seems to have MSI issues where it loses |
| 235 | * MSI rearms occasionally. This leads to lockups and freezes. |
| 236 | * disable it by default. |
| 237 | */ |
| 238 | if (rdev->family == CHIP_RV515) |
| 239 | return false; |
Alex Deucher | 8f6c25c | 2011-10-25 14:58:49 -0400 | [diff] [blame] | 240 | if (rdev->flags & RADEON_IS_IGP) { |
| 241 | /* APUs work fine with MSIs */ |
| 242 | if (rdev->family >= CHIP_PALM) |
| 243 | return true; |
| 244 | /* lots of IGPs have problems with MSIs */ |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | return true; |
| 249 | } |
| 250 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 251 | /** |
| 252 | * radeon_irq_kms_init - init driver interrupt info |
| 253 | * |
| 254 | * @rdev: radeon device pointer |
| 255 | * |
| 256 | * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics). |
| 257 | * Returns 0 for success, error for failure. |
| 258 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 259 | int radeon_irq_kms_init(struct radeon_device *rdev) |
| 260 | { |
| 261 | int r = 0; |
| 262 | |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 263 | INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func); |
Alex Deucher | f122c61 | 2012-03-30 08:59:57 -0400 | [diff] [blame] | 264 | INIT_WORK(&rdev->audio_work, r600_audio_update_hdmi); |
Alex Deucher | 8f61b34 | 2013-06-14 09:13:52 -0400 | [diff] [blame] | 265 | INIT_WORK(&rdev->reset_work, radeon_irq_reset_work_func); |
Tejun Heo | 32c87fc | 2011-01-03 14:49:32 +0100 | [diff] [blame] | 266 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 267 | spin_lock_init(&rdev->irq.lock); |
Alex Deucher | 9e7b414 | 2010-03-16 17:08:06 -0400 | [diff] [blame] | 268 | r = drm_vblank_init(rdev->ddev, rdev->num_crtc); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 269 | if (r) { |
| 270 | return r; |
| 271 | } |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 272 | /* enable msi */ |
| 273 | rdev->msi_enabled = 0; |
Alex Deucher | 8f6c25c | 2011-10-25 14:58:49 -0400 | [diff] [blame] | 274 | |
| 275 | if (radeon_msi_ok(rdev)) { |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 276 | int ret = pci_enable_msi(rdev->pdev); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 277 | if (!ret) { |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 278 | rdev->msi_enabled = 1; |
Alex Deucher | da7be68 | 2010-08-12 18:05:34 -0400 | [diff] [blame] | 279 | dev_info(rdev->dev, "radeon: using MSI.\n"); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 280 | } |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 281 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 282 | rdev->irq.installed = true; |
Jerome Glisse | 003e69f | 2010-01-07 15:39:14 +0100 | [diff] [blame] | 283 | r = drm_irq_install(rdev->ddev); |
| 284 | if (r) { |
| 285 | rdev->irq.installed = false; |
| 286 | return r; |
| 287 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 288 | DRM_INFO("radeon: irq initialized.\n"); |
| 289 | return 0; |
| 290 | } |
| 291 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 292 | /** |
Masanari Iida | cf2fbdd | 2013-03-16 20:53:05 +0900 | [diff] [blame] | 293 | * radeon_irq_kms_fini - tear down driver interrupt info |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 294 | * |
| 295 | * @rdev: radeon device pointer |
| 296 | * |
| 297 | * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics). |
| 298 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 299 | void radeon_irq_kms_fini(struct radeon_device *rdev) |
| 300 | { |
Jerome Glisse | 003e69f | 2010-01-07 15:39:14 +0100 | [diff] [blame] | 301 | drm_vblank_cleanup(rdev->ddev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 302 | if (rdev->irq.installed) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 303 | drm_irq_uninstall(rdev->ddev); |
Jerome Glisse | 003e69f | 2010-01-07 15:39:14 +0100 | [diff] [blame] | 304 | rdev->irq.installed = false; |
Alex Deucher | 3e5cb98 | 2009-10-16 12:21:24 -0400 | [diff] [blame] | 305 | if (rdev->msi_enabled) |
| 306 | pci_disable_msi(rdev->pdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 307 | } |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 308 | flush_work(&rdev->hotplug_work); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 309 | } |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 310 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 311 | /** |
| 312 | * radeon_irq_kms_sw_irq_get - enable software interrupt |
| 313 | * |
| 314 | * @rdev: radeon device pointer |
| 315 | * @ring: ring whose interrupt you want to enable |
| 316 | * |
| 317 | * Enables the software interrupt for a specific ring (all asics). |
| 318 | * The software interrupt is generally used to signal a fence on |
| 319 | * a particular ring. |
| 320 | */ |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 321 | 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] | 322 | { |
| 323 | unsigned long irqflags; |
| 324 | |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 325 | if (!rdev->ddev->irq_enabled) |
| 326 | return; |
| 327 | |
| 328 | if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) { |
| 329 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 330 | radeon_irq_set(rdev); |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 331 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 332 | } |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 333 | } |
| 334 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 335 | /** |
| 336 | * radeon_irq_kms_sw_irq_put - disable software interrupt |
| 337 | * |
| 338 | * @rdev: radeon device pointer |
| 339 | * @ring: ring whose interrupt you want to disable |
| 340 | * |
| 341 | * Disables the software interrupt for a specific ring (all asics). |
| 342 | * The software interrupt is generally used to signal a fence on |
| 343 | * a particular ring. |
| 344 | */ |
Alex Deucher | 1b37078 | 2011-11-17 20:13:28 -0500 | [diff] [blame] | 345 | 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] | 346 | { |
| 347 | unsigned long irqflags; |
| 348 | |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 349 | if (!rdev->ddev->irq_enabled) |
| 350 | return; |
| 351 | |
| 352 | if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) { |
| 353 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 354 | radeon_irq_set(rdev); |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 355 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 356 | } |
Dave Airlie | 1614f8b | 2009-12-01 16:04:56 +1000 | [diff] [blame] | 357 | } |
| 358 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 359 | /** |
| 360 | * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt |
| 361 | * |
| 362 | * @rdev: radeon device pointer |
| 363 | * @crtc: crtc whose interrupt you want to enable |
| 364 | * |
| 365 | * Enables the pageflip interrupt for a specific crtc (all asics). |
| 366 | * For pageflips we use the vblank interrupt source. |
| 367 | */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 368 | void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc) |
| 369 | { |
| 370 | unsigned long irqflags; |
| 371 | |
| 372 | if (crtc < 0 || crtc >= rdev->num_crtc) |
| 373 | return; |
| 374 | |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 375 | if (!rdev->ddev->irq_enabled) |
| 376 | return; |
| 377 | |
| 378 | if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) { |
| 379 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 380 | radeon_irq_set(rdev); |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 381 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 382 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 383 | } |
| 384 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 385 | /** |
| 386 | * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt |
| 387 | * |
| 388 | * @rdev: radeon device pointer |
| 389 | * @crtc: crtc whose interrupt you want to disable |
| 390 | * |
| 391 | * Disables the pageflip interrupt for a specific crtc (all asics). |
| 392 | * For pageflips we use the vblank interrupt source. |
| 393 | */ |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 394 | void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc) |
| 395 | { |
| 396 | unsigned long irqflags; |
| 397 | |
| 398 | if (crtc < 0 || crtc >= rdev->num_crtc) |
| 399 | return; |
| 400 | |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 401 | if (!rdev->ddev->irq_enabled) |
| 402 | return; |
| 403 | |
| 404 | if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) { |
| 405 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 406 | radeon_irq_set(rdev); |
Christian Koenig | 736fc37 | 2012-05-17 19:52:00 +0200 | [diff] [blame] | 407 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 408 | } |
Alex Deucher | 6f34be5 | 2010-11-21 10:59:01 -0500 | [diff] [blame] | 409 | } |
| 410 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 411 | /** |
| 412 | * radeon_irq_kms_enable_afmt - enable audio format change interrupt |
| 413 | * |
| 414 | * @rdev: radeon device pointer |
| 415 | * @block: afmt block whose interrupt you want to enable |
| 416 | * |
| 417 | * Enables the afmt change interrupt for a specific afmt block (all asics). |
| 418 | */ |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 419 | void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block) |
| 420 | { |
| 421 | unsigned long irqflags; |
| 422 | |
Alex Deucher | cc9945b | 2013-02-26 16:17:33 -0500 | [diff] [blame] | 423 | if (!rdev->ddev->irq_enabled) |
| 424 | return; |
| 425 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 426 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
| 427 | rdev->irq.afmt[block] = true; |
| 428 | radeon_irq_set(rdev); |
| 429 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
| 430 | |
| 431 | } |
| 432 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 433 | /** |
| 434 | * radeon_irq_kms_disable_afmt - disable audio format change interrupt |
| 435 | * |
| 436 | * @rdev: radeon device pointer |
| 437 | * @block: afmt block whose interrupt you want to disable |
| 438 | * |
| 439 | * Disables the afmt change interrupt for a specific afmt block (all asics). |
| 440 | */ |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 441 | void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block) |
| 442 | { |
| 443 | unsigned long irqflags; |
| 444 | |
Alex Deucher | cc9945b | 2013-02-26 16:17:33 -0500 | [diff] [blame] | 445 | if (!rdev->ddev->irq_enabled) |
| 446 | return; |
| 447 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 448 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
| 449 | rdev->irq.afmt[block] = false; |
| 450 | radeon_irq_set(rdev); |
| 451 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
| 452 | } |
| 453 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 454 | /** |
| 455 | * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt |
| 456 | * |
| 457 | * @rdev: radeon device pointer |
| 458 | * @hpd_mask: mask of hpd pins you want to enable. |
| 459 | * |
| 460 | * Enables the hotplug detect interrupt for a specific hpd pin (all asics). |
| 461 | */ |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 462 | void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask) |
| 463 | { |
| 464 | unsigned long irqflags; |
| 465 | int i; |
| 466 | |
Alex Deucher | cc9945b | 2013-02-26 16:17:33 -0500 | [diff] [blame] | 467 | if (!rdev->ddev->irq_enabled) |
| 468 | return; |
| 469 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 470 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
| 471 | for (i = 0; i < RADEON_MAX_HPD_PINS; ++i) |
| 472 | rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i)); |
| 473 | radeon_irq_set(rdev); |
| 474 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
| 475 | } |
| 476 | |
Alex Deucher | b73ba98 | 2012-07-17 14:02:35 -0400 | [diff] [blame] | 477 | /** |
| 478 | * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt |
| 479 | * |
| 480 | * @rdev: radeon device pointer |
| 481 | * @hpd_mask: mask of hpd pins you want to disable. |
| 482 | * |
| 483 | * Disables the hotplug detect interrupt for a specific hpd pin (all asics). |
| 484 | */ |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 485 | void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask) |
| 486 | { |
| 487 | unsigned long irqflags; |
| 488 | int i; |
| 489 | |
Alex Deucher | cc9945b | 2013-02-26 16:17:33 -0500 | [diff] [blame] | 490 | if (!rdev->ddev->irq_enabled) |
| 491 | return; |
| 492 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 493 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
| 494 | for (i = 0; i < RADEON_MAX_HPD_PINS; ++i) |
| 495 | rdev->irq.hpd[i] &= !(hpd_mask & (1 << i)); |
| 496 | radeon_irq_set(rdev); |
| 497 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
| 498 | } |
| 499 | |