2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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.
24 * Authors: Dave Airlie
29 #include "drm_crtc_helper.h"
30 #include "radeon_drm.h"
31 #include "radeon_reg.h"
35 #define RADEON_WAIT_IDLE_TIMEOUT 200
38 * radeon_driver_irq_handler_kms - irq handler for KMS
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.
46 irqreturn_t
radeon_driver_irq_handler_kms(DRM_IRQ_ARGS
)
48 struct drm_device
*dev
= (struct drm_device
*) arg
;
49 struct radeon_device
*rdev
= dev
->dev_private
;
51 return radeon_irq_process(rdev
);
55 * Handle hotplug events outside the interrupt handler proper.
58 * radeon_hotplug_work_func - display hotplug work handler
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.
68 static void radeon_hotplug_work_func(struct work_struct
*work
)
70 struct radeon_device
*rdev
= container_of(work
, struct radeon_device
,
72 struct drm_device
*dev
= rdev
->ddev
;
73 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
74 struct drm_connector
*connector
;
76 if (mode_config
->num_connector
) {
77 list_for_each_entry(connector
, &mode_config
->connector_list
, head
)
78 radeon_connector_hotplug(connector
);
80 /* Just fire off a uevent and let userspace tell us what to do */
81 drm_helper_hpd_irq_event(dev
);
85 * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
87 * @dev: drm dev pointer
89 * Gets the hw ready to enable irqs (all asics).
90 * This function disables all interrupt sources on the GPU.
92 void radeon_driver_irq_preinstall_kms(struct drm_device
*dev
)
94 struct radeon_device
*rdev
= dev
->dev_private
;
95 unsigned long irqflags
;
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
.gui_idle
= 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;
110 radeon_irq_set(rdev
);
111 spin_unlock_irqrestore(&rdev
->irq
.lock
, irqflags
);
113 radeon_irq_process(rdev
);
117 * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
119 * @dev: drm dev pointer
121 * Handles stuff to be done after enabling irqs (all asics).
122 * Returns 0 on success.
124 int radeon_driver_irq_postinstall_kms(struct drm_device
*dev
)
126 dev
->max_vblank_count
= 0x001fffff;
131 * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
133 * @dev: drm dev pointer
135 * This function disables all interrupt sources on the GPU (all asics).
137 void radeon_driver_irq_uninstall_kms(struct drm_device
*dev
)
139 struct radeon_device
*rdev
= dev
->dev_private
;
140 unsigned long irqflags
;
146 spin_lock_irqsave(&rdev
->irq
.lock
, irqflags
);
147 /* Disable *all* interrupts */
148 for (i
= 0; i
< RADEON_NUM_RINGS
; i
++)
149 atomic_set(&rdev
->irq
.ring_int
[i
], 0);
150 rdev
->irq
.gui_idle
= false;
151 for (i
= 0; i
< RADEON_MAX_HPD_PINS
; i
++)
152 rdev
->irq
.hpd
[i
] = false;
153 for (i
= 0; i
< RADEON_MAX_CRTCS
; i
++) {
154 rdev
->irq
.crtc_vblank_int
[i
] = false;
155 atomic_set(&rdev
->irq
.pflip
[i
], 0);
156 rdev
->irq
.afmt
[i
] = false;
158 radeon_irq_set(rdev
);
159 spin_unlock_irqrestore(&rdev
->irq
.lock
, irqflags
);
163 * radeon_msi_ok - asic specific msi checks
165 * @rdev: radeon device pointer
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.
172 static bool radeon_msi_ok(struct radeon_device
*rdev
)
174 /* RV370/RV380 was first asic with MSI support */
175 if (rdev
->family
< CHIP_RV380
)
178 /* MSIs don't work on AGP */
179 if (rdev
->flags
& RADEON_IS_AGP
)
185 else if (radeon_msi
== 0)
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))
195 /* Dell RS690 only seems to work with MSIs. */
196 if ((rdev
->pdev
->device
== 0x791f) &&
197 (rdev
->pdev
->subsystem_vendor
== 0x1028) &&
198 (rdev
->pdev
->subsystem_device
== 0x01fc))
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))
207 /* Gateway RS690 only seems to work with MSIs. */
208 if ((rdev
->pdev
->device
== 0x791f) &&
209 (rdev
->pdev
->subsystem_vendor
== 0x107b) &&
210 (rdev
->pdev
->subsystem_device
== 0x0185))
213 /* try and enable MSIs by default on all RS690s */
214 if (rdev
->family
== CHIP_RS690
)
217 /* RV515 seems to have MSI issues where it loses
218 * MSI rearms occasionally. This leads to lockups and freezes.
219 * disable it by default.
221 if (rdev
->family
== CHIP_RV515
)
223 if (rdev
->flags
& RADEON_IS_IGP
) {
224 /* APUs work fine with MSIs */
225 if (rdev
->family
>= CHIP_PALM
)
227 /* lots of IGPs have problems with MSIs */
235 * radeon_irq_kms_init - init driver interrupt info
237 * @rdev: radeon device pointer
239 * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
240 * Returns 0 for success, error for failure.
242 int radeon_irq_kms_init(struct radeon_device
*rdev
)
246 INIT_WORK(&rdev
->hotplug_work
, radeon_hotplug_work_func
);
247 INIT_WORK(&rdev
->audio_work
, r600_audio_update_hdmi
);
249 spin_lock_init(&rdev
->irq
.lock
);
250 r
= drm_vblank_init(rdev
->ddev
, rdev
->num_crtc
);
255 rdev
->msi_enabled
= 0;
257 if (radeon_msi_ok(rdev
)) {
258 int ret
= pci_enable_msi(rdev
->pdev
);
260 rdev
->msi_enabled
= 1;
261 dev_info(rdev
->dev
, "radeon: using MSI.\n");
264 rdev
->irq
.installed
= true;
265 r
= drm_irq_install(rdev
->ddev
);
267 rdev
->irq
.installed
= false;
270 DRM_INFO("radeon: irq initialized.\n");
275 * radeon_irq_kms_fini - tear down driver interrrupt info
277 * @rdev: radeon device pointer
279 * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
281 void radeon_irq_kms_fini(struct radeon_device
*rdev
)
283 drm_vblank_cleanup(rdev
->ddev
);
284 if (rdev
->irq
.installed
) {
285 drm_irq_uninstall(rdev
->ddev
);
286 rdev
->irq
.installed
= false;
287 if (rdev
->msi_enabled
)
288 pci_disable_msi(rdev
->pdev
);
290 flush_work_sync(&rdev
->hotplug_work
);
294 * radeon_irq_kms_sw_irq_get - enable software interrupt
296 * @rdev: radeon device pointer
297 * @ring: ring whose interrupt you want to enable
299 * Enables the software interrupt for a specific ring (all asics).
300 * The software interrupt is generally used to signal a fence on
303 void radeon_irq_kms_sw_irq_get(struct radeon_device
*rdev
, int ring
)
305 unsigned long irqflags
;
307 if (!rdev
->ddev
->irq_enabled
)
310 if (atomic_inc_return(&rdev
->irq
.ring_int
[ring
]) == 1) {
311 spin_lock_irqsave(&rdev
->irq
.lock
, irqflags
);
312 radeon_irq_set(rdev
);
313 spin_unlock_irqrestore(&rdev
->irq
.lock
, irqflags
);
318 * radeon_irq_kms_sw_irq_put - disable software interrupt
320 * @rdev: radeon device pointer
321 * @ring: ring whose interrupt you want to disable
323 * Disables the software interrupt for a specific ring (all asics).
324 * The software interrupt is generally used to signal a fence on
327 void radeon_irq_kms_sw_irq_put(struct radeon_device
*rdev
, int ring
)
329 unsigned long irqflags
;
331 if (!rdev
->ddev
->irq_enabled
)
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
);
342 * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
344 * @rdev: radeon device pointer
345 * @crtc: crtc whose interrupt you want to enable
347 * Enables the pageflip interrupt for a specific crtc (all asics).
348 * For pageflips we use the vblank interrupt source.
350 void radeon_irq_kms_pflip_irq_get(struct radeon_device
*rdev
, int crtc
)
352 unsigned long irqflags
;
354 if (crtc
< 0 || crtc
>= rdev
->num_crtc
)
357 if (!rdev
->ddev
->irq_enabled
)
360 if (atomic_inc_return(&rdev
->irq
.pflip
[crtc
]) == 1) {
361 spin_lock_irqsave(&rdev
->irq
.lock
, irqflags
);
362 radeon_irq_set(rdev
);
363 spin_unlock_irqrestore(&rdev
->irq
.lock
, irqflags
);
368 * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
370 * @rdev: radeon device pointer
371 * @crtc: crtc whose interrupt you want to disable
373 * Disables the pageflip interrupt for a specific crtc (all asics).
374 * For pageflips we use the vblank interrupt source.
376 void radeon_irq_kms_pflip_irq_put(struct radeon_device
*rdev
, int crtc
)
378 unsigned long irqflags
;
380 if (crtc
< 0 || crtc
>= rdev
->num_crtc
)
383 if (!rdev
->ddev
->irq_enabled
)
386 if (atomic_dec_and_test(&rdev
->irq
.pflip
[crtc
])) {
387 spin_lock_irqsave(&rdev
->irq
.lock
, irqflags
);
388 radeon_irq_set(rdev
);
389 spin_unlock_irqrestore(&rdev
->irq
.lock
, irqflags
);
394 * radeon_irq_kms_enable_afmt - enable audio format change interrupt
396 * @rdev: radeon device pointer
397 * @block: afmt block whose interrupt you want to enable
399 * Enables the afmt change interrupt for a specific afmt block (all asics).
401 void radeon_irq_kms_enable_afmt(struct radeon_device
*rdev
, int block
)
403 unsigned long irqflags
;
405 spin_lock_irqsave(&rdev
->irq
.lock
, irqflags
);
406 rdev
->irq
.afmt
[block
] = true;
407 radeon_irq_set(rdev
);
408 spin_unlock_irqrestore(&rdev
->irq
.lock
, irqflags
);
413 * radeon_irq_kms_disable_afmt - disable audio format change interrupt
415 * @rdev: radeon device pointer
416 * @block: afmt block whose interrupt you want to disable
418 * Disables the afmt change interrupt for a specific afmt block (all asics).
420 void radeon_irq_kms_disable_afmt(struct radeon_device
*rdev
, int block
)
422 unsigned long irqflags
;
424 spin_lock_irqsave(&rdev
->irq
.lock
, irqflags
);
425 rdev
->irq
.afmt
[block
] = false;
426 radeon_irq_set(rdev
);
427 spin_unlock_irqrestore(&rdev
->irq
.lock
, irqflags
);
431 * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
433 * @rdev: radeon device pointer
434 * @hpd_mask: mask of hpd pins you want to enable.
436 * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
438 void radeon_irq_kms_enable_hpd(struct radeon_device
*rdev
, unsigned hpd_mask
)
440 unsigned long irqflags
;
443 spin_lock_irqsave(&rdev
->irq
.lock
, irqflags
);
444 for (i
= 0; i
< RADEON_MAX_HPD_PINS
; ++i
)
445 rdev
->irq
.hpd
[i
] |= !!(hpd_mask
& (1 << i
));
446 radeon_irq_set(rdev
);
447 spin_unlock_irqrestore(&rdev
->irq
.lock
, irqflags
);
451 * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
453 * @rdev: radeon device pointer
454 * @hpd_mask: mask of hpd pins you want to disable.
456 * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
458 void radeon_irq_kms_disable_hpd(struct radeon_device
*rdev
, unsigned hpd_mask
)
460 unsigned long irqflags
;
463 spin_lock_irqsave(&rdev
->irq
.lock
, irqflags
);
464 for (i
= 0; i
< RADEON_MAX_HPD_PINS
; ++i
)
465 rdev
->irq
.hpd
[i
] &= !(hpd_mask
& (1 << i
));
466 radeon_irq_set(rdev
);
467 spin_unlock_irqrestore(&rdev
->irq
.lock
, irqflags
);
471 * radeon_irq_kms_wait_gui_idle - waits for drawing engine to be idle
473 * @rdev: radeon device pointer
475 * Enabled the GUI idle interrupt and waits for it to fire (r6xx+).
476 * This is currently used to make sure the 3D engine is idle for power
477 * management, but should be replaces with proper fence waits.
478 * GUI idle interrupts don't work very well on pre-r6xx hw and it also
479 * does not take into account other aspects of the chip that may be busy.
480 * DO NOT USE GOING FORWARD.
482 int radeon_irq_kms_wait_gui_idle(struct radeon_device
*rdev
)
484 unsigned long irqflags
;
487 spin_lock_irqsave(&rdev
->irq
.lock
, irqflags
);
488 rdev
->irq
.gui_idle
= true;
489 radeon_irq_set(rdev
);
490 spin_unlock_irqrestore(&rdev
->irq
.lock
, irqflags
);
492 r
= wait_event_timeout(rdev
->irq
.idle_queue
, radeon_gui_idle(rdev
),
493 msecs_to_jiffies(RADEON_WAIT_IDLE_TIMEOUT
));
495 spin_lock_irqsave(&rdev
->irq
.lock
, irqflags
);
496 rdev
->irq
.gui_idle
= false;
497 radeon_irq_set(rdev
);
498 spin_unlock_irqrestore(&rdev
->irq
.lock
, irqflags
);