blob: 50b596ec7b7eec8bb2704d9455355ebbf22dd32e [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
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"
Dave Airlieeb1f8e42010-05-07 06:42:51 +000029#include "drm_crtc_helper.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020030#include "radeon_drm.h"
31#include "radeon_reg.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020032#include "radeon.h"
33#include "atom.h"
34
Christian Koenigfb982572012-05-17 01:33:30 +020035#define RADEON_WAIT_IDLE_TIMEOUT 200
36
Alex Deucherb73ba982012-07-17 14:02:35 -040037/**
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 Glisse771fe6b2009-06-05 14:42:42 +020046irqreturn_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 Deucherd4877cf2009-12-04 16:56:37 -050054/*
55 * Handle hotplug events outside the interrupt handler proper.
56 */
Alex Deucherb73ba982012-07-17 14:02:35 -040057/**
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 Deucherd4877cf2009-12-04 16:56:37 -050068static 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 Airlieeb1f8e42010-05-07 06:42:51 +000081 drm_helper_hpd_irq_event(dev);
Alex Deucherd4877cf2009-12-04 16:56:37 -050082}
83
Alex Deucherb73ba982012-07-17 14:02:35 -040084/**
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 Glisse771fe6b2009-06-05 14:42:42 +020092void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
93{
94 struct radeon_device *rdev = dev->dev_private;
Christian Koenigfb982572012-05-17 01:33:30 +020095 unsigned long irqflags;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020096 unsigned i;
97
Christian Koenigfb982572012-05-17 01:33:30 +020098 spin_lock_irqsave(&rdev->irq.lock, irqflags);
Jerome Glisse771fe6b2009-06-05 14:42:42 +020099 /* Disable *all* interrupts */
Alex Deucher1b370782011-11-17 20:13:28 -0500100 for (i = 0; i < RADEON_NUM_RINGS; i++)
Christian Koenig736fc372012-05-17 19:52:00 +0200101 atomic_set(&rdev->irq.ring_int[i], 0);
Alex Deucher2031f772010-04-22 12:52:11 -0400102 rdev->irq.gui_idle = false;
Ilija Hadzic54bd52062011-10-26 15:43:58 -0400103 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
Alex Deucher9e7b4142010-03-16 17:08:06 -0400104 rdev->irq.hpd[i] = false;
Ilija Hadzic54bd52062011-10-26 15:43:58 -0400105 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
106 rdev->irq.crtc_vblank_int[i] = false;
Christian Koenig736fc372012-05-17 19:52:00 +0200107 atomic_set(&rdev->irq.pflip[i], 0);
Alex Deucherf122c612012-03-30 08:59:57 -0400108 rdev->irq.afmt[i] = false;
Alex Deucher6f34be52010-11-21 10:59:01 -0500109 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200110 radeon_irq_set(rdev);
Christian Koenigfb982572012-05-17 01:33:30 +0200111 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200112 /* Clear bits */
113 radeon_irq_process(rdev);
114}
115
Alex Deucherb73ba982012-07-17 14:02:35 -0400116/**
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 Glisse771fe6b2009-06-05 14:42:42 +0200124int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
125{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200126 dev->max_vblank_count = 0x001fffff;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200127 return 0;
128}
129
Alex Deucherb73ba982012-07-17 14:02:35 -0400130/**
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 Glisse771fe6b2009-06-05 14:42:42 +0200137void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
138{
139 struct radeon_device *rdev = dev->dev_private;
Christian Koenigfb982572012-05-17 01:33:30 +0200140 unsigned long irqflags;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200141 unsigned i;
142
143 if (rdev == NULL) {
144 return;
145 }
Christian Koenigfb982572012-05-17 01:33:30 +0200146 spin_lock_irqsave(&rdev->irq.lock, irqflags);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200147 /* Disable *all* interrupts */
Alex Deucher1b370782011-11-17 20:13:28 -0500148 for (i = 0; i < RADEON_NUM_RINGS; i++)
Christian Koenig736fc372012-05-17 19:52:00 +0200149 atomic_set(&rdev->irq.ring_int[i], 0);
Alex Deucher2031f772010-04-22 12:52:11 -0400150 rdev->irq.gui_idle = false;
Ilija Hadzic54bd52062011-10-26 15:43:58 -0400151 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
Jerome Glisse003e69f2010-01-07 15:39:14 +0100152 rdev->irq.hpd[i] = false;
Ilija Hadzic54bd52062011-10-26 15:43:58 -0400153 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
154 rdev->irq.crtc_vblank_int[i] = false;
Christian Koenig736fc372012-05-17 19:52:00 +0200155 atomic_set(&rdev->irq.pflip[i], 0);
Alex Deucherf122c612012-03-30 08:59:57 -0400156 rdev->irq.afmt[i] = false;
Alex Deucher6f34be52010-11-21 10:59:01 -0500157 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200158 radeon_irq_set(rdev);
Christian Koenigfb982572012-05-17 01:33:30 +0200159 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200160}
161
Alex Deucherb73ba982012-07-17 14:02:35 -0400162/**
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 Deucher8f6c25c2011-10-25 14:58:49 -0400172static 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 Deuchera18cee12011-11-01 14:20:30 -0400182 /* force MSI on */
183 if (radeon_msi == 1)
184 return true;
185 else if (radeon_msi == 0)
186 return false;
187
Alex Deucherb3621052011-10-25 15:11:08 -0400188 /* 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 Deucher01e718e2011-11-01 14:14:18 -0400195 /* Dell RS690 only seems to work with MSIs. */
196 if ((rdev->pdev->device == 0x791f) &&
197 (rdev->pdev->subsystem_vendor == 0x1028) &&
Alex Deucher44517c42012-01-15 08:51:12 -0500198 (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 Deucher01e718e2011-11-01 14:14:18 -0400204 (rdev->pdev->subsystem_device == 0x01fd))
205 return true;
206
Dave Airlie16a5e322012-04-13 11:14:50 +0100207 /* 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 Deucher8f6c25c2011-10-25 14:58:49 -0400213 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 Deucherb73ba982012-07-17 14:02:35 -0400224/**
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 Glisse771fe6b2009-06-05 14:42:42 +0200232int radeon_irq_kms_init(struct radeon_device *rdev)
233{
234 int r = 0;
235
Tejun Heo32c87fc2011-01-03 14:49:32 +0100236 INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
Alex Deucherf122c612012-03-30 08:59:57 -0400237 INIT_WORK(&rdev->audio_work, r600_audio_update_hdmi);
Tejun Heo32c87fc2011-01-03 14:49:32 +0100238
Christian Koenigfb982572012-05-17 01:33:30 +0200239 spin_lock_init(&rdev->irq.lock);
Alex Deucher9e7b4142010-03-16 17:08:06 -0400240 r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200241 if (r) {
242 return r;
243 }
Alex Deucher3e5cb982009-10-16 12:21:24 -0400244 /* enable msi */
245 rdev->msi_enabled = 0;
Alex Deucher8f6c25c2011-10-25 14:58:49 -0400246
247 if (radeon_msi_ok(rdev)) {
Alex Deucher3e5cb982009-10-16 12:21:24 -0400248 int ret = pci_enable_msi(rdev->pdev);
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500249 if (!ret) {
Alex Deucher3e5cb982009-10-16 12:21:24 -0400250 rdev->msi_enabled = 1;
Alex Deucherda7be682010-08-12 18:05:34 -0400251 dev_info(rdev->dev, "radeon: using MSI.\n");
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500252 }
Alex Deucher3e5cb982009-10-16 12:21:24 -0400253 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200254 rdev->irq.installed = true;
Jerome Glisse003e69f2010-01-07 15:39:14 +0100255 r = drm_irq_install(rdev->ddev);
256 if (r) {
257 rdev->irq.installed = false;
258 return r;
259 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200260 DRM_INFO("radeon: irq initialized.\n");
261 return 0;
262}
263
Alex Deucherb73ba982012-07-17 14:02:35 -0400264/**
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 Glisse771fe6b2009-06-05 14:42:42 +0200271void radeon_irq_kms_fini(struct radeon_device *rdev)
272{
Jerome Glisse003e69f2010-01-07 15:39:14 +0100273 drm_vblank_cleanup(rdev->ddev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200274 if (rdev->irq.installed) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200275 drm_irq_uninstall(rdev->ddev);
Jerome Glisse003e69f2010-01-07 15:39:14 +0100276 rdev->irq.installed = false;
Alex Deucher3e5cb982009-10-16 12:21:24 -0400277 if (rdev->msi_enabled)
278 pci_disable_msi(rdev->pdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200279 }
Tejun Heo43829732012-08-20 14:51:24 -0700280 flush_work(&rdev->hotplug_work);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200281}
Dave Airlie1614f8b2009-12-01 16:04:56 +1000282
Alex Deucherb73ba982012-07-17 14:02:35 -0400283/**
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 Deucher1b370782011-11-17 20:13:28 -0500293void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring)
Dave Airlie1614f8b2009-12-01 16:04:56 +1000294{
295 unsigned long irqflags;
296
Christian Koenig736fc372012-05-17 19:52:00 +0200297 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 Airlie1614f8b2009-12-01 16:04:56 +1000302 radeon_irq_set(rdev);
Christian Koenig736fc372012-05-17 19:52:00 +0200303 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
Dave Airlie1614f8b2009-12-01 16:04:56 +1000304 }
Dave Airlie1614f8b2009-12-01 16:04:56 +1000305}
306
Alex Deucherb73ba982012-07-17 14:02:35 -0400307/**
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 Deucher1b370782011-11-17 20:13:28 -0500317void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring)
Dave Airlie1614f8b2009-12-01 16:04:56 +1000318{
319 unsigned long irqflags;
320
Christian Koenig736fc372012-05-17 19:52:00 +0200321 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 Airlie1614f8b2009-12-01 16:04:56 +1000326 radeon_irq_set(rdev);
Christian Koenig736fc372012-05-17 19:52:00 +0200327 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
Dave Airlie1614f8b2009-12-01 16:04:56 +1000328 }
Dave Airlie1614f8b2009-12-01 16:04:56 +1000329}
330
Alex Deucherb73ba982012-07-17 14:02:35 -0400331/**
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 Deucher6f34be52010-11-21 10:59:01 -0500340void 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 Koenig736fc372012-05-17 19:52:00 +0200347 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 Deucher6f34be52010-11-21 10:59:01 -0500352 radeon_irq_set(rdev);
Christian Koenig736fc372012-05-17 19:52:00 +0200353 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
Alex Deucher6f34be52010-11-21 10:59:01 -0500354 }
Alex Deucher6f34be52010-11-21 10:59:01 -0500355}
356
Alex Deucherb73ba982012-07-17 14:02:35 -0400357/**
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 Deucher6f34be52010-11-21 10:59:01 -0500366void 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 Koenig736fc372012-05-17 19:52:00 +0200373 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 Deucher6f34be52010-11-21 10:59:01 -0500378 radeon_irq_set(rdev);
Christian Koenig736fc372012-05-17 19:52:00 +0200379 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
Alex Deucher6f34be52010-11-21 10:59:01 -0500380 }
Alex Deucher6f34be52010-11-21 10:59:01 -0500381}
382
Alex Deucherb73ba982012-07-17 14:02:35 -0400383/**
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 Koenigfb982572012-05-17 01:33:30 +0200391void 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 Deucherb73ba982012-07-17 14:02:35 -0400402/**
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 Koenigfb982572012-05-17 01:33:30 +0200410void 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 Deucherb73ba982012-07-17 14:02:35 -0400420/**
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 Koenigfb982572012-05-17 01:33:30 +0200428void 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 Deucherb73ba982012-07-17 14:02:35 -0400440/**
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 Koenigfb982572012-05-17 01:33:30 +0200448void 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 Deucherb73ba982012-07-17 14:02:35 -0400460/**
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 Koenigfb982572012-05-17 01:33:30 +0200472int 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}