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 <drm/radeon_drm.h>
31 #include "radeon_reg.h"
35 #include <linux/pm_runtime.h>
37 #define RADEON_WAIT_IDLE_TIMEOUT 200
40 * radeon_driver_irq_handler_kms - irq handler for KMS
42 * @int irq, void *arg: args
44 * This is the irq handler for the radeon KMS driver (all asics).
45 * radeon_irq_process is a macro that points to the per-asic
46 * irq handler callback.
48 irqreturn_t radeon_driver_irq_handler_kms(int irq, void *arg)
50 struct drm_device *dev = (struct drm_device *) arg;
51 struct radeon_device *rdev = dev->dev_private;
54 ret = radeon_irq_process(rdev);
55 if (ret == IRQ_HANDLED)
56 pm_runtime_mark_last_busy(dev->dev);
61 * Handle hotplug events outside the interrupt handler proper.
64 * radeon_hotplug_work_func - display hotplug work handler
68 * This is the hot plug event work handler (all asics).
69 * The work gets scheduled from the irq handler if there
70 * was a hot plug interrupt. It walks the connector table
71 * and calls the hotplug handler for each one, then sends
72 * a drm hotplug event to alert userspace.
74 static void radeon_hotplug_work_func(struct work_struct *work)
76 struct radeon_device *rdev = container_of(work, struct radeon_device,
78 struct drm_device *dev = rdev->ddev;
79 struct drm_mode_config *mode_config = &dev->mode_config;
80 struct drm_connector *connector;
82 if (mode_config->num_connector) {
83 list_for_each_entry(connector, &mode_config->connector_list, head)
84 radeon_connector_hotplug(connector);
86 /* Just fire off a uevent and let userspace tell us what to do */
87 drm_helper_hpd_irq_event(dev);
91 * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
93 * @dev: drm dev pointer
95 * Gets the hw ready to enable irqs (all asics).
96 * This function disables all interrupt sources on the GPU.
98 void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
100 struct radeon_device *rdev = dev->dev_private;
101 unsigned long irqflags;
104 spin_lock_irqsave(&rdev->irq.lock, irqflags);
105 /* Disable *all* interrupts */
106 for (i = 0; i < RADEON_NUM_RINGS; i++)
107 atomic_set(&rdev->irq.ring_int[i], 0);
108 rdev->irq.dpm_thermal = false;
109 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
110 rdev->irq.hpd[i] = false;
111 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
112 rdev->irq.crtc_vblank_int[i] = false;
113 atomic_set(&rdev->irq.pflip[i], 0);
114 rdev->irq.afmt[i] = false;
116 radeon_irq_set(rdev);
117 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
119 radeon_irq_process(rdev);
123 * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
125 * @dev: drm dev pointer
127 * Handles stuff to be done after enabling irqs (all asics).
128 * Returns 0 on success.
130 int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
132 dev->max_vblank_count = 0x001fffff;
137 * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
139 * @dev: drm dev pointer
141 * This function disables all interrupt sources on the GPU (all asics).
143 void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
145 struct radeon_device *rdev = dev->dev_private;
146 unsigned long irqflags;
152 spin_lock_irqsave(&rdev->irq.lock, irqflags);
153 /* Disable *all* interrupts */
154 for (i = 0; i < RADEON_NUM_RINGS; i++)
155 atomic_set(&rdev->irq.ring_int[i], 0);
156 rdev->irq.dpm_thermal = false;
157 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
158 rdev->irq.hpd[i] = false;
159 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
160 rdev->irq.crtc_vblank_int[i] = false;
161 atomic_set(&rdev->irq.pflip[i], 0);
162 rdev->irq.afmt[i] = false;
164 radeon_irq_set(rdev);
165 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
169 * radeon_msi_ok - asic specific msi checks
171 * @rdev: radeon device pointer
173 * Handles asic specific MSI checks to determine if
174 * MSIs should be enabled on a particular chip (all asics).
175 * Returns true if MSIs should be enabled, false if MSIs
176 * should not be enabled.
178 static bool radeon_msi_ok(struct radeon_device *rdev)
180 /* RV370/RV380 was first asic with MSI support */
181 if (rdev->family < CHIP_RV380)
184 /* MSIs don't work on AGP */
185 if (rdev->flags & RADEON_IS_AGP)
191 else if (radeon_msi == 0)
195 /* HP RS690 only seems to work with MSIs. */
196 if ((rdev->pdev->device == 0x791f) &&
197 (rdev->pdev->subsystem_vendor == 0x103c) &&
198 (rdev->pdev->subsystem_device == 0x30c2))
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 == 0x01fc))
207 /* Dell RS690 only seems to work with MSIs. */
208 if ((rdev->pdev->device == 0x791f) &&
209 (rdev->pdev->subsystem_vendor == 0x1028) &&
210 (rdev->pdev->subsystem_device == 0x01fd))
213 /* Gateway RS690 only seems to work with MSIs. */
214 if ((rdev->pdev->device == 0x791f) &&
215 (rdev->pdev->subsystem_vendor == 0x107b) &&
216 (rdev->pdev->subsystem_device == 0x0185))
219 /* try and enable MSIs by default on all RS690s */
220 if (rdev->family == CHIP_RS690)
223 /* RV515 seems to have MSI issues where it loses
224 * MSI rearms occasionally. This leads to lockups and freezes.
225 * disable it by default.
227 if (rdev->family == CHIP_RV515)
229 if (rdev->flags & RADEON_IS_IGP) {
230 /* APUs work fine with MSIs */
231 if (rdev->family >= CHIP_PALM)
233 /* lots of IGPs have problems with MSIs */
241 * radeon_irq_kms_init - init driver interrupt info
243 * @rdev: radeon device pointer
245 * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
246 * Returns 0 for success, error for failure.
248 int radeon_irq_kms_init(struct radeon_device *rdev)
252 spin_lock_init(&rdev->irq.lock);
253 r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
258 rdev->msi_enabled = 0;
260 if (radeon_msi_ok(rdev)) {
261 int ret = pci_enable_msi(rdev->pdev);
263 rdev->msi_enabled = 1;
264 dev_info(rdev->dev, "radeon: using MSI.\n");
268 INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
269 INIT_WORK(&rdev->audio_work, r600_audio_update_hdmi);
271 rdev->irq.installed = true;
272 r = drm_irq_install(rdev->ddev, rdev->ddev->pdev->irq);
274 rdev->irq.installed = false;
275 flush_work(&rdev->hotplug_work);
279 DRM_INFO("radeon: irq initialized.\n");
284 * radeon_irq_kms_fini - tear down driver interrupt info
286 * @rdev: radeon device pointer
288 * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
290 void radeon_irq_kms_fini(struct radeon_device *rdev)
292 drm_vblank_cleanup(rdev->ddev);
293 if (rdev->irq.installed) {
294 drm_irq_uninstall(rdev->ddev);
295 rdev->irq.installed = false;
296 if (rdev->msi_enabled)
297 pci_disable_msi(rdev->pdev);
298 flush_work(&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 unsigned long irqflags;
316 if (!rdev->ddev->irq_enabled)
319 if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) {
320 spin_lock_irqsave(&rdev->irq.lock, irqflags);
321 radeon_irq_set(rdev);
322 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
327 * radeon_irq_kms_sw_irq_get_delayed - enable software interrupt
329 * @rdev: radeon device pointer
330 * @ring: ring whose interrupt you want to enable
332 * Enables the software interrupt for a specific ring (all asics).
333 * The software interrupt is generally used to signal a fence on
336 bool radeon_irq_kms_sw_irq_get_delayed(struct radeon_device *rdev, int ring)
338 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 unsigned long irqflags;
355 if (!rdev->ddev->irq_enabled)
358 if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) {
359 spin_lock_irqsave(&rdev->irq.lock, irqflags);
360 radeon_irq_set(rdev);
361 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
366 * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
368 * @rdev: radeon device pointer
369 * @crtc: crtc whose interrupt you want to enable
371 * Enables the pageflip interrupt for a specific crtc (all asics).
372 * For pageflips we use the vblank interrupt source.
374 void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc)
376 unsigned long irqflags;
378 if (crtc < 0 || crtc >= rdev->num_crtc)
381 if (!rdev->ddev->irq_enabled)
384 if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) {
385 spin_lock_irqsave(&rdev->irq.lock, irqflags);
386 radeon_irq_set(rdev);
387 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
392 * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
394 * @rdev: radeon device pointer
395 * @crtc: crtc whose interrupt you want to disable
397 * Disables the pageflip interrupt for a specific crtc (all asics).
398 * For pageflips we use the vblank interrupt source.
400 void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc)
402 unsigned long irqflags;
404 if (crtc < 0 || crtc >= rdev->num_crtc)
407 if (!rdev->ddev->irq_enabled)
410 if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) {
411 spin_lock_irqsave(&rdev->irq.lock, irqflags);
412 radeon_irq_set(rdev);
413 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
418 * radeon_irq_kms_enable_afmt - enable audio format change interrupt
420 * @rdev: radeon device pointer
421 * @block: afmt block whose interrupt you want to enable
423 * Enables the afmt change interrupt for a specific afmt block (all asics).
425 void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block)
427 unsigned long irqflags;
429 if (!rdev->ddev->irq_enabled)
432 spin_lock_irqsave(&rdev->irq.lock, irqflags);
433 rdev->irq.afmt[block] = true;
434 radeon_irq_set(rdev);
435 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
440 * radeon_irq_kms_disable_afmt - disable audio format change interrupt
442 * @rdev: radeon device pointer
443 * @block: afmt block whose interrupt you want to disable
445 * Disables the afmt change interrupt for a specific afmt block (all asics).
447 void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block)
449 unsigned long irqflags;
451 if (!rdev->ddev->irq_enabled)
454 spin_lock_irqsave(&rdev->irq.lock, irqflags);
455 rdev->irq.afmt[block] = false;
456 radeon_irq_set(rdev);
457 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
461 * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
463 * @rdev: radeon device pointer
464 * @hpd_mask: mask of hpd pins you want to enable.
466 * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
468 void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
470 unsigned long irqflags;
473 if (!rdev->ddev->irq_enabled)
476 spin_lock_irqsave(&rdev->irq.lock, irqflags);
477 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
478 rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
479 radeon_irq_set(rdev);
480 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
484 * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
486 * @rdev: radeon device pointer
487 * @hpd_mask: mask of hpd pins you want to disable.
489 * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
491 void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
493 unsigned long irqflags;
496 if (!rdev->ddev->irq_enabled)
499 spin_lock_irqsave(&rdev->irq.lock, irqflags);
500 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
501 rdev->irq.hpd[i] &= !(hpd_mask & (1 << i));
502 radeon_irq_set(rdev);
503 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);