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 <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <dev/drm2/drmP.h>
33 #include <dev/drm2/drm_crtc_helper.h>
34 #include <dev/drm2/radeon/radeon_drm.h>
35 #include "radeon_reg.h"
36 #include "radeon_irq_kms.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(DRM_IRQ_ARGS)
53 struct drm_device *dev = (struct drm_device *) arg;
54 struct radeon_device *rdev = dev->dev_private;
56 return radeon_irq_process(rdev);
60 * Handle hotplug events outside the interrupt handler proper.
63 * radeon_hotplug_work_func - display hotplug work handler
67 * This is the hot plug event work handler (all asics).
68 * The work gets scheduled from the irq handler if there
69 * was a hot plug interrupt. It walks the connector table
70 * and calls the hotplug handler for each one, then sends
71 * a drm hotplug event to alert userspace.
73 static void radeon_hotplug_work_func(void *arg, int pending)
75 struct radeon_device *rdev = arg;
76 struct drm_device *dev = rdev->ddev;
77 struct drm_mode_config *mode_config = &dev->mode_config;
78 struct drm_connector *connector;
80 if (mode_config->num_connector) {
81 list_for_each_entry(connector, &mode_config->connector_list, head)
82 radeon_connector_hotplug(connector);
84 /* Just fire off a uevent and let userspace tell us what to do */
85 drm_helper_hpd_irq_event(dev);
89 * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
91 * @dev: drm dev pointer
93 * Gets the hw ready to enable irqs (all asics).
94 * This function disables all interrupt sources on the GPU.
96 void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
98 struct radeon_device *rdev = dev->dev_private;
99 unsigned long irqflags;
102 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
103 /* Disable *all* interrupts */
104 for (i = 0; i < RADEON_NUM_RINGS; i++)
105 atomic_set(&rdev->irq.ring_int[i], 0);
106 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
107 rdev->irq.hpd[i] = false;
108 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
109 rdev->irq.crtc_vblank_int[i] = false;
110 atomic_set(&rdev->irq.pflip[i], 0);
111 rdev->irq.afmt[i] = false;
113 radeon_irq_set(rdev);
114 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
116 radeon_irq_process(rdev);
120 * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
122 * @dev: drm dev pointer
124 * Handles stuff to be done after enabling irqs (all asics).
125 * Returns 0 on success.
127 int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
129 dev->max_vblank_count = 0x001fffff;
134 * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
136 * @dev: drm dev pointer
138 * This function disables all interrupt sources on the GPU (all asics).
140 void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
142 struct radeon_device *rdev = dev->dev_private;
143 unsigned long irqflags;
149 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
150 /* Disable *all* interrupts */
151 for (i = 0; i < RADEON_NUM_RINGS; i++)
152 atomic_set(&rdev->irq.ring_int[i], 0);
153 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
154 rdev->irq.hpd[i] = false;
155 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
156 rdev->irq.crtc_vblank_int[i] = false;
157 atomic_set(&rdev->irq.pflip[i], 0);
158 rdev->irq.afmt[i] = false;
160 radeon_irq_set(rdev);
161 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
165 * radeon_msi_ok - asic specific msi checks
167 * @rdev: radeon device pointer
169 * Handles asic specific MSI checks to determine if
170 * MSIs should be enabled on a particular chip (all asics).
171 * Returns true if MSIs should be enabled, false if MSIs
172 * should not be enabled.
174 int radeon_msi_ok(struct drm_device *dev, unsigned long flags)
178 family = flags & RADEON_FAMILY_MASK;
180 /* RV370/RV380 was first asic with MSI support */
181 if (family < CHIP_RV380)
184 /* MSIs don't work on AGP */
185 if (drm_device_is_agp(dev))
191 else if (radeon_msi == 0)
195 /* HP RS690 only seems to work with MSIs. */
196 if ((dev->pci_device == 0x791f) &&
197 (dev->pci_subvendor == 0x103c) &&
198 (dev->pci_subdevice == 0x30c2))
201 /* Dell RS690 only seems to work with MSIs. */
202 if ((dev->pci_device == 0x791f) &&
203 (dev->pci_subvendor == 0x1028) &&
204 (dev->pci_subdevice == 0x01fc))
207 /* Dell RS690 only seems to work with MSIs. */
208 if ((dev->pci_device == 0x791f) &&
209 (dev->pci_subvendor == 0x1028) &&
210 (dev->pci_subdevice == 0x01fd))
213 /* Gateway RS690 only seems to work with MSIs. */
214 if ((dev->pci_device == 0x791f) &&
215 (dev->pci_subvendor == 0x107b) &&
216 (dev->pci_subdevice == 0x0185))
219 /* try and enable MSIs by default on all RS690s */
220 if (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 (family == CHIP_RV515)
229 if (flags & RADEON_IS_IGP) {
230 /* APUs work fine with MSIs */
231 if (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 TASK_INIT(&rdev->hotplug_work, 0, radeon_hotplug_work_func, rdev);
253 TASK_INIT(&rdev->audio_work, 0, r600_audio_update_hdmi, rdev);
255 DRM_SPININIT(&rdev->irq.lock, "drm__radeon_device__irq__lock");
256 r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
261 rdev->msi_enabled = rdev->ddev->msi_enabled;
263 rdev->irq.installed = true;
264 DRM_UNLOCK(rdev->ddev);
265 r = drm_irq_install(rdev->ddev);
266 DRM_LOCK(rdev->ddev);
268 rdev->irq.installed = false;
271 DRM_INFO("radeon: irq initialized.\n");
276 * radeon_irq_kms_fini - tear down driver interrrupt info
278 * @rdev: radeon device pointer
280 * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
282 void radeon_irq_kms_fini(struct radeon_device *rdev)
284 drm_vblank_cleanup(rdev->ddev);
285 if (rdev->irq.installed) {
286 drm_irq_uninstall(rdev->ddev);
287 rdev->irq.installed = false;
289 taskqueue_drain(rdev->tq, &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 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
311 radeon_irq_set(rdev);
312 DRM_SPINUNLOCK_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 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
335 radeon_irq_set(rdev);
336 DRM_SPINUNLOCK_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 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
361 radeon_irq_set(rdev);
362 DRM_SPINUNLOCK_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 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
387 radeon_irq_set(rdev);
388 DRM_SPINUNLOCK_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 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
405 rdev->irq.afmt[block] = true;
406 radeon_irq_set(rdev);
407 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
412 * radeon_irq_kms_disable_afmt - disable audio format change interrupt
414 * @rdev: radeon device pointer
415 * @block: afmt block whose interrupt you want to disable
417 * Disables the afmt change interrupt for a specific afmt block (all asics).
419 void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block)
421 unsigned long irqflags;
423 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
424 rdev->irq.afmt[block] = false;
425 radeon_irq_set(rdev);
426 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
430 * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
432 * @rdev: radeon device pointer
433 * @hpd_mask: mask of hpd pins you want to enable.
435 * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
437 void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
439 unsigned long irqflags;
442 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
443 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
444 rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
445 radeon_irq_set(rdev);
446 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
450 * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
452 * @rdev: radeon device pointer
453 * @hpd_mask: mask of hpd pins you want to disable.
455 * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
457 void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
459 unsigned long irqflags;
462 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
463 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
464 rdev->irq.hpd[i] &= !(hpd_mask & (1 << i));
465 radeon_irq_set(rdev);
466 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);