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 #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 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
103 rdev->irq.hpd[i] = false;
104 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
105 rdev->irq.crtc_vblank_int[i] = false;
106 atomic_set(&rdev->irq.pflip[i], 0);
107 rdev->irq.afmt[i] = false;
109 radeon_irq_set(rdev);
110 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
112 radeon_irq_process(rdev);
116 * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
118 * @dev: drm dev pointer
120 * Handles stuff to be done after enabling irqs (all asics).
121 * Returns 0 on success.
123 int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
125 dev->max_vblank_count = 0x001fffff;
130 * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
132 * @dev: drm dev pointer
134 * This function disables all interrupt sources on the GPU (all asics).
136 void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
138 struct radeon_device *rdev = dev->dev_private;
139 unsigned long irqflags;
145 spin_lock_irqsave(&rdev->irq.lock, irqflags);
146 /* Disable *all* interrupts */
147 for (i = 0; i < RADEON_NUM_RINGS; i++)
148 atomic_set(&rdev->irq.ring_int[i], 0);
149 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
150 rdev->irq.hpd[i] = false;
151 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
152 rdev->irq.crtc_vblank_int[i] = false;
153 atomic_set(&rdev->irq.pflip[i], 0);
154 rdev->irq.afmt[i] = false;
156 radeon_irq_set(rdev);
157 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
161 * radeon_msi_ok - asic specific msi checks
163 * @rdev: radeon device pointer
165 * Handles asic specific MSI checks to determine if
166 * MSIs should be enabled on a particular chip (all asics).
167 * Returns true if MSIs should be enabled, false if MSIs
168 * should not be enabled.
170 static bool radeon_msi_ok(struct radeon_device *rdev)
172 /* RV370/RV380 was first asic with MSI support */
173 if (rdev->family < CHIP_RV380)
176 /* MSIs don't work on AGP */
177 if (rdev->flags & RADEON_IS_AGP)
183 else if (radeon_msi == 0)
187 /* HP RS690 only seems to work with MSIs. */
188 if ((rdev->pdev->device == 0x791f) &&
189 (rdev->pdev->subsystem_vendor == 0x103c) &&
190 (rdev->pdev->subsystem_device == 0x30c2))
193 /* Dell RS690 only seems to work with MSIs. */
194 if ((rdev->pdev->device == 0x791f) &&
195 (rdev->pdev->subsystem_vendor == 0x1028) &&
196 (rdev->pdev->subsystem_device == 0x01fc))
199 /* Dell RS690 only seems to work with MSIs. */
200 if ((rdev->pdev->device == 0x791f) &&
201 (rdev->pdev->subsystem_vendor == 0x1028) &&
202 (rdev->pdev->subsystem_device == 0x01fd))
205 /* Gateway RS690 only seems to work with MSIs. */
206 if ((rdev->pdev->device == 0x791f) &&
207 (rdev->pdev->subsystem_vendor == 0x107b) &&
208 (rdev->pdev->subsystem_device == 0x0185))
211 /* try and enable MSIs by default on all RS690s */
212 if (rdev->family == CHIP_RS690)
215 /* RV515 seems to have MSI issues where it loses
216 * MSI rearms occasionally. This leads to lockups and freezes.
217 * disable it by default.
219 if (rdev->family == CHIP_RV515)
221 if (rdev->flags & RADEON_IS_IGP) {
222 /* APUs work fine with MSIs */
223 if (rdev->family >= CHIP_PALM)
225 /* lots of IGPs have problems with MSIs */
233 * radeon_irq_kms_init - init driver interrupt info
235 * @rdev: radeon device pointer
237 * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
238 * Returns 0 for success, error for failure.
240 int radeon_irq_kms_init(struct radeon_device *rdev)
244 spin_lock_init(&rdev->irq.lock);
245 r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
250 rdev->msi_enabled = 0;
252 if (radeon_msi_ok(rdev)) {
253 int ret = pci_enable_msi(rdev->pdev);
255 rdev->msi_enabled = 1;
256 dev_info(rdev->dev, "radeon: using MSI.\n");
259 rdev->irq.installed = true;
260 r = drm_irq_install(rdev->ddev);
262 rdev->irq.installed = false;
266 INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
267 INIT_WORK(&rdev->audio_work, r600_audio_update_hdmi);
269 DRM_INFO("radeon: irq initialized.\n");
274 * radeon_irq_kms_fini - tear down driver interrupt info
276 * @rdev: radeon device pointer
278 * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
280 void radeon_irq_kms_fini(struct radeon_device *rdev)
282 drm_vblank_cleanup(rdev->ddev);
283 if (rdev->irq.installed) {
284 drm_irq_uninstall(rdev->ddev);
285 rdev->irq.installed = false;
286 if (rdev->msi_enabled)
287 pci_disable_msi(rdev->pdev);
288 flush_work(&rdev->hotplug_work);
293 * radeon_irq_kms_sw_irq_get - enable software interrupt
295 * @rdev: radeon device pointer
296 * @ring: ring whose interrupt you want to enable
298 * Enables the software interrupt for a specific ring (all asics).
299 * The software interrupt is generally used to signal a fence on
302 void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring)
304 unsigned long irqflags;
306 if (!rdev->ddev->irq_enabled)
309 if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) {
310 spin_lock_irqsave(&rdev->irq.lock, irqflags);
311 radeon_irq_set(rdev);
312 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
317 * radeon_irq_kms_sw_irq_put - disable software interrupt
319 * @rdev: radeon device pointer
320 * @ring: ring whose interrupt you want to disable
322 * Disables the software interrupt for a specific ring (all asics).
323 * The software interrupt is generally used to signal a fence on
326 void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring)
328 unsigned long irqflags;
330 if (!rdev->ddev->irq_enabled)
333 if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) {
334 spin_lock_irqsave(&rdev->irq.lock, irqflags);
335 radeon_irq_set(rdev);
336 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
341 * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
343 * @rdev: radeon device pointer
344 * @crtc: crtc whose interrupt you want to enable
346 * Enables the pageflip interrupt for a specific crtc (all asics).
347 * For pageflips we use the vblank interrupt source.
349 void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc)
351 unsigned long irqflags;
353 if (crtc < 0 || crtc >= rdev->num_crtc)
356 if (!rdev->ddev->irq_enabled)
359 if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) {
360 spin_lock_irqsave(&rdev->irq.lock, irqflags);
361 radeon_irq_set(rdev);
362 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
367 * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
369 * @rdev: radeon device pointer
370 * @crtc: crtc whose interrupt you want to disable
372 * Disables the pageflip interrupt for a specific crtc (all asics).
373 * For pageflips we use the vblank interrupt source.
375 void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc)
377 unsigned long irqflags;
379 if (crtc < 0 || crtc >= rdev->num_crtc)
382 if (!rdev->ddev->irq_enabled)
385 if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) {
386 spin_lock_irqsave(&rdev->irq.lock, irqflags);
387 radeon_irq_set(rdev);
388 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
393 * radeon_irq_kms_enable_afmt - enable audio format change interrupt
395 * @rdev: radeon device pointer
396 * @block: afmt block whose interrupt you want to enable
398 * Enables the afmt change interrupt for a specific afmt block (all asics).
400 void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block)
402 unsigned long irqflags;
404 if (!rdev->ddev->irq_enabled)
407 spin_lock_irqsave(&rdev->irq.lock, irqflags);
408 rdev->irq.afmt[block] = true;
409 radeon_irq_set(rdev);
410 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
415 * radeon_irq_kms_disable_afmt - disable audio format change interrupt
417 * @rdev: radeon device pointer
418 * @block: afmt block whose interrupt you want to disable
420 * Disables the afmt change interrupt for a specific afmt block (all asics).
422 void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block)
424 unsigned long irqflags;
426 if (!rdev->ddev->irq_enabled)
429 spin_lock_irqsave(&rdev->irq.lock, irqflags);
430 rdev->irq.afmt[block] = false;
431 radeon_irq_set(rdev);
432 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
436 * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
438 * @rdev: radeon device pointer
439 * @hpd_mask: mask of hpd pins you want to enable.
441 * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
443 void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
445 unsigned long irqflags;
448 if (!rdev->ddev->irq_enabled)
451 spin_lock_irqsave(&rdev->irq.lock, irqflags);
452 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
453 rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
454 radeon_irq_set(rdev);
455 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
459 * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
461 * @rdev: radeon device pointer
462 * @hpd_mask: mask of hpd pins you want to disable.
464 * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
466 void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
468 unsigned long irqflags;
471 if (!rdev->ddev->irq_enabled)
474 spin_lock_irqsave(&rdev->irq.lock, irqflags);
475 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
476 rdev->irq.hpd[i] &= !(hpd_mask & (1 << i));
477 radeon_irq_set(rdev);
478 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);