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 static bool radeon_msi_ok(struct radeon_device *rdev)
176 /* RV370/RV380 was first asic with MSI support */
177 if (rdev->family < CHIP_RV380)
180 /* MSIs don't work on AGP */
181 if (rdev->flags & RADEON_IS_AGP)
187 else if (radeon_msi == 0)
191 /* HP RS690 only seems to work with MSIs. */
192 if ((rdev->ddev->pci_device == 0x791f) &&
193 (rdev->ddev->pci_subvendor == 0x103c) &&
194 (rdev->ddev->pci_subdevice == 0x30c2))
197 /* Dell RS690 only seems to work with MSIs. */
198 if ((rdev->ddev->pci_device == 0x791f) &&
199 (rdev->ddev->pci_subvendor == 0x1028) &&
200 (rdev->ddev->pci_subdevice == 0x01fc))
203 /* Dell RS690 only seems to work with MSIs. */
204 if ((rdev->ddev->pci_device == 0x791f) &&
205 (rdev->ddev->pci_subvendor == 0x1028) &&
206 (rdev->ddev->pci_subdevice == 0x01fd))
209 /* Gateway RS690 only seems to work with MSIs. */
210 if ((rdev->ddev->pci_device == 0x791f) &&
211 (rdev->ddev->pci_subvendor == 0x107b) &&
212 (rdev->ddev->pci_subdevice == 0x0185))
215 /* try and enable MSIs by default on all RS690s */
216 if (rdev->family == CHIP_RS690)
219 /* RV515 seems to have MSI issues where it loses
220 * MSI rearms occasionally. This leads to lockups and freezes.
221 * disable it by default.
223 if (rdev->family == CHIP_RV515)
225 if (rdev->flags & RADEON_IS_IGP) {
226 /* APUs work fine with MSIs */
227 if (rdev->family >= CHIP_PALM)
229 /* lots of IGPs have problems with MSIs */
237 * radeon_irq_kms_init - init driver interrupt info
239 * @rdev: radeon device pointer
241 * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
242 * Returns 0 for success, error for failure.
244 int radeon_irq_kms_init(struct radeon_device *rdev)
248 TASK_INIT(&rdev->hotplug_work, 0, radeon_hotplug_work_func, rdev);
249 TASK_INIT(&rdev->audio_work, 0, r600_audio_update_hdmi, rdev);
251 DRM_SPININIT(&rdev->irq.lock, "drm__radeon_device__irq__lock");
252 r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
257 rdev->msi_enabled = 0;
259 if (radeon_msi_ok(rdev)) {
260 int ret = drm_pci_enable_msi(rdev->ddev);
262 rdev->msi_enabled = 1;
263 dev_info(rdev->dev, "radeon: using MSI.\n");
266 rdev->irq.installed = true;
267 r = drm_irq_install(rdev->ddev);
269 rdev->irq.installed = false;
272 DRM_INFO("radeon: irq initialized.\n");
277 * radeon_irq_kms_fini - tear down driver interrrupt info
279 * @rdev: radeon device pointer
281 * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
283 void radeon_irq_kms_fini(struct radeon_device *rdev)
285 drm_vblank_cleanup(rdev->ddev);
286 if (rdev->irq.installed) {
287 drm_irq_uninstall(rdev->ddev);
288 rdev->irq.installed = false;
289 if (rdev->msi_enabled)
290 drm_pci_disable_msi(rdev->ddev);
292 taskqueue_drain(rdev->tq, &rdev->hotplug_work);
296 * radeon_irq_kms_sw_irq_get - enable software interrupt
298 * @rdev: radeon device pointer
299 * @ring: ring whose interrupt you want to enable
301 * Enables the software interrupt for a specific ring (all asics).
302 * The software interrupt is generally used to signal a fence on
305 void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring)
307 unsigned long irqflags;
309 if (!rdev->ddev->irq_enabled)
312 if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) {
313 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
314 radeon_irq_set(rdev);
315 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
320 * radeon_irq_kms_sw_irq_put - disable software interrupt
322 * @rdev: radeon device pointer
323 * @ring: ring whose interrupt you want to disable
325 * Disables the software interrupt for a specific ring (all asics).
326 * The software interrupt is generally used to signal a fence on
329 void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring)
331 unsigned long irqflags;
333 if (!rdev->ddev->irq_enabled)
336 if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) {
337 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
338 radeon_irq_set(rdev);
339 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
344 * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
346 * @rdev: radeon device pointer
347 * @crtc: crtc whose interrupt you want to enable
349 * Enables the pageflip interrupt for a specific crtc (all asics).
350 * For pageflips we use the vblank interrupt source.
352 void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc)
354 unsigned long irqflags;
356 if (crtc < 0 || crtc >= rdev->num_crtc)
359 if (!rdev->ddev->irq_enabled)
362 if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) {
363 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
364 radeon_irq_set(rdev);
365 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
370 * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
372 * @rdev: radeon device pointer
373 * @crtc: crtc whose interrupt you want to disable
375 * Disables the pageflip interrupt for a specific crtc (all asics).
376 * For pageflips we use the vblank interrupt source.
378 void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc)
380 unsigned long irqflags;
382 if (crtc < 0 || crtc >= rdev->num_crtc)
385 if (!rdev->ddev->irq_enabled)
388 if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) {
389 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
390 radeon_irq_set(rdev);
391 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
396 * radeon_irq_kms_enable_afmt - enable audio format change interrupt
398 * @rdev: radeon device pointer
399 * @block: afmt block whose interrupt you want to enable
401 * Enables the afmt change interrupt for a specific afmt block (all asics).
403 void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block)
405 unsigned long irqflags;
407 if (!rdev->ddev->irq_enabled)
410 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
411 rdev->irq.afmt[block] = true;
412 radeon_irq_set(rdev);
413 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
418 * radeon_irq_kms_disable_afmt - disable audio format change interrupt
420 * @rdev: radeon device pointer
421 * @block: afmt block whose interrupt you want to disable
423 * Disables the afmt change interrupt for a specific afmt block (all asics).
425 void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block)
427 unsigned long irqflags;
429 if (!rdev->ddev->irq_enabled)
432 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
433 rdev->irq.afmt[block] = false;
434 radeon_irq_set(rdev);
435 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
439 * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
441 * @rdev: radeon device pointer
442 * @hpd_mask: mask of hpd pins you want to enable.
444 * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
446 void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
448 unsigned long irqflags;
451 if (!rdev->ddev->irq_enabled)
454 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
455 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
456 rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
457 radeon_irq_set(rdev);
458 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);
462 * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
464 * @rdev: radeon device pointer
465 * @hpd_mask: mask of hpd pins you want to disable.
467 * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
469 void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
471 unsigned long irqflags;
474 if (!rdev->ddev->irq_enabled)
477 DRM_SPINLOCK_IRQSAVE(&rdev->irq.lock, irqflags);
478 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
479 rdev->irq.hpd[i] &= !(hpd_mask & (1 << i));
480 radeon_irq_set(rdev);
481 DRM_SPINUNLOCK_IRQRESTORE(&rdev->irq.lock, irqflags);