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
28 * $FreeBSD: head/sys/dev/drm2/radeon/radeon_irq_kms.c 254885 2013-08-25 19:37:15Z dumbbell $
32 #include <drm/drm_crtc_helper.h>
33 #include <uapi_drm/radeon_drm.h>
34 #include "radeon_reg.h"
35 #include "radeon_irq_kms.h"
39 #define RADEON_WAIT_IDLE_TIMEOUT 200
42 * radeon_driver_irq_handler_kms - irq handler for KMS
46 * This is the irq handler for the radeon KMS driver (all asics).
47 * radeon_irq_process is a macro that points to the per-asic
48 * irq handler callback.
50 irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS)
52 struct drm_device *dev = (struct drm_device *) arg;
53 struct radeon_device *rdev = dev->dev_private;
55 return radeon_irq_process(rdev);
59 * Handle hotplug events outside the interrupt handler proper.
62 * radeon_hotplug_work_func - display hotplug work handler
66 * This is the hot plug event work handler (all asics).
67 * The work gets scheduled from the irq handler if there
68 * was a hot plug interrupt. It walks the connector table
69 * and calls the hotplug handler for each one, then sends
70 * a drm hotplug event to alert userspace.
72 static void radeon_hotplug_work_func(void *arg, int pending)
74 struct radeon_device *rdev = arg;
75 struct drm_device *dev = rdev->ddev;
76 struct drm_mode_config *mode_config = &dev->mode_config;
77 struct drm_connector *connector;
79 if (mode_config->num_connector) {
80 list_for_each_entry(connector, &mode_config->connector_list, head)
81 radeon_connector_hotplug(connector);
83 /* Just fire off a uevent and let userspace tell us what to do */
84 drm_helper_hpd_irq_event(dev);
88 * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
90 * @dev: drm dev pointer
92 * Gets the hw ready to enable irqs (all asics).
93 * This function disables all interrupt sources on the GPU.
95 void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
97 struct radeon_device *rdev = dev->dev_private;
100 lockmgr(&rdev->irq.lock, LK_EXCLUSIVE);
101 /* Disable *all* interrupts */
102 for (i = 0; i < RADEON_NUM_RINGS; i++)
103 atomic_set(&rdev->irq.ring_int[i], 0);
104 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
105 rdev->irq.hpd[i] = false;
106 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
107 rdev->irq.crtc_vblank_int[i] = false;
108 atomic_set(&rdev->irq.pflip[i], 0);
109 rdev->irq.afmt[i] = false;
111 radeon_irq_set(rdev);
112 lockmgr(&rdev->irq.lock, LK_RELEASE);
114 radeon_irq_process(rdev);
118 * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
120 * @dev: drm dev pointer
122 * Handles stuff to be done after enabling irqs (all asics).
123 * Returns 0 on success.
125 int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
127 dev->max_vblank_count = 0x001fffff;
132 * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
134 * @dev: drm dev pointer
136 * This function disables all interrupt sources on the GPU (all asics).
138 void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
140 struct radeon_device *rdev = dev->dev_private;
146 lockmgr(&rdev->irq.lock, LK_EXCLUSIVE);
147 /* Disable *all* interrupts */
148 for (i = 0; i < RADEON_NUM_RINGS; i++)
149 atomic_set(&rdev->irq.ring_int[i], 0);
150 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
151 rdev->irq.hpd[i] = false;
152 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
153 rdev->irq.crtc_vblank_int[i] = false;
154 atomic_set(&rdev->irq.pflip[i], 0);
155 rdev->irq.afmt[i] = false;
157 radeon_irq_set(rdev);
158 lockmgr(&rdev->irq.lock, LK_RELEASE);
162 * radeon_msi_ok - asic specific msi checks
164 * @rdev: radeon device pointer
166 * Handles asic specific MSI checks to determine if
167 * MSIs should be enabled on a particular chip (all asics).
168 * Returns true if MSIs should be enabled, false if MSIs
169 * should not be enabled.
171 int radeon_msi_ok(struct drm_device *dev, unsigned long flags)
175 family = flags & RADEON_FAMILY_MASK;
177 /* RV370/RV380 was first asic with MSI support */
178 if (family < CHIP_RV380)
181 /* MSIs don't work on AGP */
182 if (drm_device_is_agp(dev))
188 else if (radeon_msi == 0)
192 /* HP RS690 only seems to work with MSIs. */
193 if ((dev->pci_device == 0x791f) &&
194 (dev->pci_subvendor == 0x103c) &&
195 (dev->pci_subdevice == 0x30c2))
198 /* Dell RS690 only seems to work with MSIs. */
199 if ((dev->pci_device == 0x791f) &&
200 (dev->pci_subvendor == 0x1028) &&
201 (dev->pci_subdevice == 0x01fc))
204 /* Dell RS690 only seems to work with MSIs. */
205 if ((dev->pci_device == 0x791f) &&
206 (dev->pci_subvendor == 0x1028) &&
207 (dev->pci_subdevice == 0x01fd))
210 /* Gateway RS690 only seems to work with MSIs. */
211 if ((dev->pci_device == 0x791f) &&
212 (dev->pci_subvendor == 0x107b) &&
213 (dev->pci_subdevice == 0x0185))
216 /* try and enable MSIs by default on all RS690s */
217 if (family == CHIP_RS690)
220 /* RV515 seems to have MSI issues where it loses
221 * MSI rearms occasionally. This leads to lockups and freezes.
222 * disable it by default.
224 if (family == CHIP_RV515)
226 if (flags & RADEON_IS_IGP) {
227 /* APUs work fine with MSIs */
228 if (family >= CHIP_PALM)
230 /* lots of IGPs have problems with MSIs */
238 * radeon_irq_kms_init - init driver interrupt info
240 * @rdev: radeon device pointer
242 * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
243 * Returns 0 for success, error for failure.
245 int radeon_irq_kms_init(struct radeon_device *rdev)
249 TASK_INIT(&rdev->hotplug_work, 0, radeon_hotplug_work_func, rdev);
250 TASK_INIT(&rdev->audio_work, 0, r600_audio_update_hdmi, rdev);
252 lockinit(&rdev->irq.lock, "drm__radeon_device__irq__lock", 0, LK_CANRECURSE);
253 r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
258 rdev->msi_enabled = rdev->ddev->msi_enabled;
260 rdev->irq.installed = true;
261 DRM_UNLOCK(rdev->ddev);
262 r = drm_irq_install(rdev->ddev);
263 DRM_LOCK(rdev->ddev);
265 rdev->irq.installed = false;
268 DRM_INFO("radeon: irq initialized.\n");
273 * radeon_irq_kms_fini - tear down driver interrrupt info
275 * @rdev: radeon device pointer
277 * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
279 void radeon_irq_kms_fini(struct radeon_device *rdev)
281 drm_vblank_cleanup(rdev->ddev);
282 if (rdev->irq.installed) {
283 drm_irq_uninstall(rdev->ddev);
284 rdev->irq.installed = false;
286 taskqueue_drain(rdev->tq, &rdev->hotplug_work);
290 * radeon_irq_kms_sw_irq_get - enable software interrupt
292 * @rdev: radeon device pointer
293 * @ring: ring whose interrupt you want to enable
295 * Enables the software interrupt for a specific ring (all asics).
296 * The software interrupt is generally used to signal a fence on
299 void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring)
301 if (!rdev->ddev->irq_enabled)
304 if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) {
305 lockmgr(&rdev->irq.lock, LK_EXCLUSIVE);
306 radeon_irq_set(rdev);
307 lockmgr(&rdev->irq.lock, LK_RELEASE);
312 * radeon_irq_kms_sw_irq_put - disable software interrupt
314 * @rdev: radeon device pointer
315 * @ring: ring whose interrupt you want to disable
317 * Disables the software interrupt for a specific ring (all asics).
318 * The software interrupt is generally used to signal a fence on
321 void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring)
323 if (!rdev->ddev->irq_enabled)
326 if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) {
327 lockmgr(&rdev->irq.lock, LK_EXCLUSIVE);
328 radeon_irq_set(rdev);
329 lockmgr(&rdev->irq.lock, LK_RELEASE);
334 * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
336 * @rdev: radeon device pointer
337 * @crtc: crtc whose interrupt you want to enable
339 * Enables the pageflip interrupt for a specific crtc (all asics).
340 * For pageflips we use the vblank interrupt source.
342 void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc)
344 if (crtc < 0 || crtc >= rdev->num_crtc)
347 if (!rdev->ddev->irq_enabled)
350 if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) {
351 lockmgr(&rdev->irq.lock, LK_EXCLUSIVE);
352 radeon_irq_set(rdev);
353 lockmgr(&rdev->irq.lock, LK_RELEASE);
358 * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
360 * @rdev: radeon device pointer
361 * @crtc: crtc whose interrupt you want to disable
363 * Disables the pageflip interrupt for a specific crtc (all asics).
364 * For pageflips we use the vblank interrupt source.
366 void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc)
368 if (crtc < 0 || crtc >= rdev->num_crtc)
371 if (!rdev->ddev->irq_enabled)
374 if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) {
375 lockmgr(&rdev->irq.lock, LK_EXCLUSIVE);
376 radeon_irq_set(rdev);
377 lockmgr(&rdev->irq.lock, LK_RELEASE);
382 * radeon_irq_kms_enable_afmt - enable audio format change interrupt
384 * @rdev: radeon device pointer
385 * @block: afmt block whose interrupt you want to enable
387 * Enables the afmt change interrupt for a specific afmt block (all asics).
389 void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block)
391 lockmgr(&rdev->irq.lock, LK_EXCLUSIVE);
392 rdev->irq.afmt[block] = true;
393 radeon_irq_set(rdev);
394 lockmgr(&rdev->irq.lock, LK_RELEASE);
399 * radeon_irq_kms_disable_afmt - disable audio format change interrupt
401 * @rdev: radeon device pointer
402 * @block: afmt block whose interrupt you want to disable
404 * Disables the afmt change interrupt for a specific afmt block (all asics).
406 void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block)
408 lockmgr(&rdev->irq.lock, LK_EXCLUSIVE);
409 rdev->irq.afmt[block] = false;
410 radeon_irq_set(rdev);
411 lockmgr(&rdev->irq.lock, LK_RELEASE);
415 * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
417 * @rdev: radeon device pointer
418 * @hpd_mask: mask of hpd pins you want to enable.
420 * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
422 void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
426 lockmgr(&rdev->irq.lock, LK_EXCLUSIVE);
427 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
428 rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
429 radeon_irq_set(rdev);
430 lockmgr(&rdev->irq.lock, LK_RELEASE);
434 * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
436 * @rdev: radeon device pointer
437 * @hpd_mask: mask of hpd pins you want to disable.
439 * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
441 void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
445 lockmgr(&rdev->irq.lock, LK_EXCLUSIVE);
446 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
447 rdev->irq.hpd[i] &= !(hpd_mask & (1 << i));
448 radeon_irq_set(rdev);
449 lockmgr(&rdev->irq.lock, LK_RELEASE);