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/drm_crtc_helper.h>
30 #include <uapi_drm/radeon_drm.h>
31 #include "radeon_reg.h"
32 #include "radeon_irq_kms.h"
37 #include <linux/pm_runtime.h>
40 #define RADEON_WAIT_IDLE_TIMEOUT 200
43 * radeon_driver_irq_handler_kms - irq handler for KMS
47 * This is the irq handler for the radeon KMS driver (all asics).
48 * radeon_irq_process is a macro that points to the per-asic
49 * irq handler callback.
51 irqreturn_t
radeon_driver_irq_handler_kms(void *arg
)
53 struct drm_device
*dev
= (struct drm_device
*) arg
;
54 struct radeon_device
*rdev
= dev
->dev_private
;
58 ret
= radeon_irq_process(rdev
);
59 if (ret
== IRQ_HANDLED
)
60 pm_runtime_mark_last_busy(dev
->dev
);
63 return radeon_irq_process(rdev
);
68 * Handle hotplug events outside the interrupt handler proper.
71 * radeon_hotplug_work_func - display hotplug work handler
75 * This is the hot plug event work handler (all asics).
76 * The work gets scheduled from the irq handler if there
77 * was a hot plug interrupt. It walks the connector table
78 * and calls the hotplug handler for each one, then sends
79 * a drm hotplug event to alert userspace.
81 static void radeon_hotplug_work_func(void *arg
, int pending
)
83 struct radeon_device
*rdev
= arg
;
84 struct drm_device
*dev
= rdev
->ddev
;
85 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
86 struct drm_connector
*connector
;
88 if (mode_config
->num_connector
) {
89 list_for_each_entry(connector
, &mode_config
->connector_list
, head
)
90 radeon_connector_hotplug(connector
);
92 /* Just fire off a uevent and let userspace tell us what to do */
93 drm_helper_hpd_irq_event(dev
);
97 * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
99 * @dev: drm dev pointer
101 * Gets the hw ready to enable irqs (all asics).
102 * This function disables all interrupt sources on the GPU.
104 void radeon_driver_irq_preinstall_kms(struct drm_device
*dev
)
106 struct radeon_device
*rdev
= dev
->dev_private
;
109 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
110 /* Disable *all* interrupts */
111 for (i
= 0; i
< RADEON_NUM_RINGS
; i
++)
112 atomic_set(&rdev
->irq
.ring_int
[i
], 0);
113 rdev
->irq
.dpm_thermal
= false;
114 for (i
= 0; i
< RADEON_MAX_HPD_PINS
; i
++)
115 rdev
->irq
.hpd
[i
] = false;
116 for (i
= 0; i
< RADEON_MAX_CRTCS
; i
++) {
117 rdev
->irq
.crtc_vblank_int
[i
] = false;
118 atomic_set(&rdev
->irq
.pflip
[i
], 0);
119 rdev
->irq
.afmt
[i
] = false;
121 radeon_irq_set(rdev
);
122 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
124 radeon_irq_process(rdev
);
128 * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
130 * @dev: drm dev pointer
132 * Handles stuff to be done after enabling irqs (all asics).
133 * Returns 0 on success.
135 int radeon_driver_irq_postinstall_kms(struct drm_device
*dev
)
137 dev
->max_vblank_count
= 0x001fffff;
142 * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
144 * @dev: drm dev pointer
146 * This function disables all interrupt sources on the GPU (all asics).
148 void radeon_driver_irq_uninstall_kms(struct drm_device
*dev
)
150 struct radeon_device
*rdev
= dev
->dev_private
;
156 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
157 /* Disable *all* interrupts */
158 for (i
= 0; i
< RADEON_NUM_RINGS
; i
++)
159 atomic_set(&rdev
->irq
.ring_int
[i
], 0);
160 rdev
->irq
.dpm_thermal
= false;
161 for (i
= 0; i
< RADEON_MAX_HPD_PINS
; i
++)
162 rdev
->irq
.hpd
[i
] = false;
163 for (i
= 0; i
< RADEON_MAX_CRTCS
; i
++) {
164 rdev
->irq
.crtc_vblank_int
[i
] = false;
165 atomic_set(&rdev
->irq
.pflip
[i
], 0);
166 rdev
->irq
.afmt
[i
] = false;
168 radeon_irq_set(rdev
);
169 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
173 * radeon_msi_ok - asic specific msi checks
175 * @rdev: radeon device pointer
177 * Handles asic specific MSI checks to determine if
178 * MSIs should be enabled on a particular chip (all asics).
179 * Returns true if MSIs should be enabled, false if MSIs
180 * should not be enabled.
182 int radeon_msi_ok(struct drm_device
*rdev
, unsigned long flags
)
186 family
= flags
& RADEON_FAMILY_MASK
;
188 /* RV370/RV380 was first asic with MSI support */
189 if (family
< CHIP_RV380
)
192 /* MSIs don't work on AGP */
193 if (drm_pci_device_is_agp(rdev
))
199 else if (radeon_msi
== 0)
203 /* HP RS690 only seems to work with MSIs. */
204 if ((rdev
->pdev
->device
== 0x791f) &&
205 (rdev
->pdev
->subsystem_vendor
== 0x103c) &&
206 (rdev
->pdev
->subsystem_device
== 0x30c2))
209 /* Dell RS690 only seems to work with MSIs. */
210 if ((rdev
->pdev
->device
== 0x791f) &&
211 (rdev
->pdev
->subsystem_vendor
== 0x1028) &&
212 (rdev
->pdev
->subsystem_device
== 0x01fc))
215 /* Dell RS690 only seems to work with MSIs. */
216 if ((rdev
->pdev
->device
== 0x791f) &&
217 (rdev
->pdev
->subsystem_vendor
== 0x1028) &&
218 (rdev
->pdev
->subsystem_device
== 0x01fd))
221 /* Gateway RS690 only seems to work with MSIs. */
222 if ((rdev
->pdev
->device
== 0x791f) &&
223 (rdev
->pdev
->subsystem_vendor
== 0x107b) &&
224 (rdev
->pdev
->subsystem_device
== 0x0185))
227 /* try and enable MSIs by default on all RS690s */
228 if (family
== CHIP_RS690
)
231 /* RV515 seems to have MSI issues where it loses
232 * MSI rearms occasionally. This leads to lockups and freezes.
233 * disable it by default.
235 if (family
== CHIP_RV515
)
237 if (flags
& RADEON_IS_IGP
) {
238 /* APUs work fine with MSIs */
239 if (family
>= CHIP_PALM
)
241 /* lots of IGPs have problems with MSIs */
249 * radeon_irq_kms_init - init driver interrupt info
251 * @rdev: radeon device pointer
253 * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
254 * Returns 0 for success, error for failure.
256 int radeon_irq_kms_init(struct radeon_device
*rdev
)
260 lockinit(&rdev
->irq
.lock
, "drm__radeon_device__irq__lock", 0, LK_CANRECURSE
);
261 r
= drm_vblank_init(rdev
->ddev
, rdev
->num_crtc
);
266 rdev
->msi_enabled
= (rdev
->ddev
->irq_type
== PCI_INTR_TYPE_MSI
);
268 TASK_INIT(&rdev
->hotplug_work
, 0, radeon_hotplug_work_func
, rdev
);
269 TASK_INIT(&rdev
->audio_work
, 0, r600_audio_update_hdmi
, rdev
);
271 rdev
->irq
.installed
= true;
272 DRM_UNLOCK(rdev
->ddev
);
273 r
= drm_irq_install(rdev
->ddev
, rdev
->ddev
->irq
);
274 DRM_LOCK(rdev
->ddev
);
276 rdev
->irq
.installed
= false;
277 taskqueue_drain(rdev
->tq
, &rdev
->hotplug_work
);
281 DRM_INFO("radeon: irq initialized.\n");
286 * radeon_irq_kms_fini - tear down driver interrupt info
288 * @rdev: radeon device pointer
290 * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
292 void radeon_irq_kms_fini(struct radeon_device
*rdev
)
294 drm_vblank_cleanup(rdev
->ddev
);
295 if (rdev
->irq
.installed
) {
296 drm_irq_uninstall(rdev
->ddev
);
297 rdev
->irq
.installed
= false;
298 taskqueue_drain(rdev
->tq
, &rdev
->hotplug_work
);
303 * radeon_irq_kms_sw_irq_get - enable software interrupt
305 * @rdev: radeon device pointer
306 * @ring: ring whose interrupt you want to enable
308 * Enables the software interrupt for a specific ring (all asics).
309 * The software interrupt is generally used to signal a fence on
312 void radeon_irq_kms_sw_irq_get(struct radeon_device
*rdev
, int ring
)
314 if (!rdev
->ddev
->irq_enabled
)
317 if (atomic_inc_return(&rdev
->irq
.ring_int
[ring
]) == 1) {
318 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
319 radeon_irq_set(rdev
);
320 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
325 * radeon_irq_kms_sw_irq_get_delayed - enable software interrupt
327 * @rdev: radeon device pointer
328 * @ring: ring whose interrupt you want to enable
330 * Enables the software interrupt for a specific ring (all asics).
331 * The software interrupt is generally used to signal a fence on
335 bool radeon_irq_kms_sw_irq_get_delayed(struct radeon_device
*rdev
, int ring
)
337 return atomic_inc_return(&rdev
->irq
.ring_int
[ring
]) == 1;
342 * radeon_irq_kms_sw_irq_put - disable software interrupt
344 * @rdev: radeon device pointer
345 * @ring: ring whose interrupt you want to disable
347 * Disables the software interrupt for a specific ring (all asics).
348 * The software interrupt is generally used to signal a fence on
351 void radeon_irq_kms_sw_irq_put(struct radeon_device
*rdev
, int ring
)
353 if (!rdev
->ddev
->irq_enabled
)
356 if (atomic_dec_and_test(&rdev
->irq
.ring_int
[ring
])) {
357 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
358 radeon_irq_set(rdev
);
359 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
364 * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
366 * @rdev: radeon device pointer
367 * @crtc: crtc whose interrupt you want to enable
369 * Enables the pageflip interrupt for a specific crtc (all asics).
370 * For pageflips we use the vblank interrupt source.
372 void radeon_irq_kms_pflip_irq_get(struct radeon_device
*rdev
, int crtc
)
374 if (crtc
< 0 || crtc
>= rdev
->num_crtc
)
377 if (!rdev
->ddev
->irq_enabled
)
380 if (atomic_inc_return(&rdev
->irq
.pflip
[crtc
]) == 1) {
381 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
382 radeon_irq_set(rdev
);
383 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
388 * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
390 * @rdev: radeon device pointer
391 * @crtc: crtc whose interrupt you want to disable
393 * Disables the pageflip interrupt for a specific crtc (all asics).
394 * For pageflips we use the vblank interrupt source.
396 void radeon_irq_kms_pflip_irq_put(struct radeon_device
*rdev
, int crtc
)
398 if (crtc
< 0 || crtc
>= rdev
->num_crtc
)
401 if (!rdev
->ddev
->irq_enabled
)
404 if (atomic_dec_and_test(&rdev
->irq
.pflip
[crtc
])) {
405 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
406 radeon_irq_set(rdev
);
407 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
412 * radeon_irq_kms_enable_afmt - enable audio format change interrupt
414 * @rdev: radeon device pointer
415 * @block: afmt block whose interrupt you want to enable
417 * Enables the afmt change interrupt for a specific afmt block (all asics).
419 void radeon_irq_kms_enable_afmt(struct radeon_device
*rdev
, int block
)
421 if (!rdev
->ddev
->irq_enabled
)
424 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
425 rdev
->irq
.afmt
[block
] = true;
426 radeon_irq_set(rdev
);
427 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
431 * radeon_irq_kms_disable_afmt - disable audio format change interrupt
433 * @rdev: radeon device pointer
434 * @block: afmt block whose interrupt you want to disable
436 * Disables the afmt change interrupt for a specific afmt block (all asics).
438 void radeon_irq_kms_disable_afmt(struct radeon_device
*rdev
, int block
)
440 if (!rdev
->ddev
->irq_enabled
)
443 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
444 rdev
->irq
.afmt
[block
] = false;
445 radeon_irq_set(rdev
);
446 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
450 * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
452 * @rdev: radeon device pointer
453 * @hpd_mask: mask of hpd pins you want to enable.
455 * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
457 void radeon_irq_kms_enable_hpd(struct radeon_device
*rdev
, unsigned hpd_mask
)
461 if (!rdev
->ddev
->irq_enabled
)
464 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
465 for (i
= 0; i
< RADEON_MAX_HPD_PINS
; ++i
)
466 rdev
->irq
.hpd
[i
] |= !!(hpd_mask
& (1 << i
));
467 radeon_irq_set(rdev
);
468 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
472 * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
474 * @rdev: radeon device pointer
475 * @hpd_mask: mask of hpd pins you want to disable.
477 * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
479 void radeon_irq_kms_disable_hpd(struct radeon_device
*rdev
, unsigned hpd_mask
)
483 if (!rdev
->ddev
->irq_enabled
)
486 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
487 for (i
= 0; i
< RADEON_MAX_HPD_PINS
; ++i
)
488 rdev
->irq
.hpd
[i
] &= !(hpd_mask
& (1 << i
));
489 radeon_irq_set(rdev
);
490 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);