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_irq_reset_work_func - execute gpu reset
92 * Execute scheduled gpu reset (cayman+).
93 * This function is called when the irq handler
94 * thinks we need a gpu reset.
96 static void radeon_irq_reset_work_func(void *arg
, int pending
)
98 struct radeon_device
*rdev
= arg
;
100 radeon_gpu_reset(rdev
);
104 * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
106 * @dev: drm dev pointer
108 * Gets the hw ready to enable irqs (all asics).
109 * This function disables all interrupt sources on the GPU.
111 void radeon_driver_irq_preinstall_kms(struct drm_device
*dev
)
113 struct radeon_device
*rdev
= dev
->dev_private
;
116 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
117 /* Disable *all* interrupts */
118 for (i
= 0; i
< RADEON_NUM_RINGS
; i
++)
119 atomic_set(&rdev
->irq
.ring_int
[i
], 0);
120 rdev
->irq
.dpm_thermal
= false;
121 for (i
= 0; i
< RADEON_MAX_HPD_PINS
; i
++)
122 rdev
->irq
.hpd
[i
] = false;
123 for (i
= 0; i
< RADEON_MAX_CRTCS
; i
++) {
124 rdev
->irq
.crtc_vblank_int
[i
] = false;
125 atomic_set(&rdev
->irq
.pflip
[i
], 0);
126 rdev
->irq
.afmt
[i
] = false;
128 radeon_irq_set(rdev
);
129 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
131 radeon_irq_process(rdev
);
135 * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
137 * @dev: drm dev pointer
139 * Handles stuff to be done after enabling irqs (all asics).
140 * Returns 0 on success.
142 int radeon_driver_irq_postinstall_kms(struct drm_device
*dev
)
144 dev
->max_vblank_count
= 0x001fffff;
149 * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
151 * @dev: drm dev pointer
153 * This function disables all interrupt sources on the GPU (all asics).
155 void radeon_driver_irq_uninstall_kms(struct drm_device
*dev
)
157 struct radeon_device
*rdev
= dev
->dev_private
;
163 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
164 /* Disable *all* interrupts */
165 for (i
= 0; i
< RADEON_NUM_RINGS
; i
++)
166 atomic_set(&rdev
->irq
.ring_int
[i
], 0);
167 rdev
->irq
.dpm_thermal
= false;
168 for (i
= 0; i
< RADEON_MAX_HPD_PINS
; i
++)
169 rdev
->irq
.hpd
[i
] = false;
170 for (i
= 0; i
< RADEON_MAX_CRTCS
; i
++) {
171 rdev
->irq
.crtc_vblank_int
[i
] = false;
172 atomic_set(&rdev
->irq
.pflip
[i
], 0);
173 rdev
->irq
.afmt
[i
] = false;
175 radeon_irq_set(rdev
);
176 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
180 * radeon_msi_ok - asic specific msi checks
182 * @rdev: radeon device pointer
184 * Handles asic specific MSI checks to determine if
185 * MSIs should be enabled on a particular chip (all asics).
186 * Returns true if MSIs should be enabled, false if MSIs
187 * should not be enabled.
189 int radeon_msi_ok(struct drm_device
*dev
, unsigned long flags
)
193 family
= flags
& RADEON_FAMILY_MASK
;
195 /* RV370/RV380 was first asic with MSI support */
196 if (family
< CHIP_RV380
)
199 /* MSIs don't work on AGP */
200 if (drm_device_is_agp(dev
))
206 else if (radeon_msi
== 0)
210 /* HP RS690 only seems to work with MSIs. */
211 if ((dev
->pci_device
== 0x791f) &&
212 (dev
->pci_subvendor
== 0x103c) &&
213 (dev
->pci_subdevice
== 0x30c2))
216 /* Dell RS690 only seems to work with MSIs. */
217 if ((dev
->pci_device
== 0x791f) &&
218 (dev
->pci_subvendor
== 0x1028) &&
219 (dev
->pci_subdevice
== 0x01fc))
222 /* Dell RS690 only seems to work with MSIs. */
223 if ((dev
->pci_device
== 0x791f) &&
224 (dev
->pci_subvendor
== 0x1028) &&
225 (dev
->pci_subdevice
== 0x01fd))
228 /* Gateway RS690 only seems to work with MSIs. */
229 if ((dev
->pci_device
== 0x791f) &&
230 (dev
->pci_subvendor
== 0x107b) &&
231 (dev
->pci_subdevice
== 0x0185))
234 /* try and enable MSIs by default on all RS690s */
235 if (family
== CHIP_RS690
)
238 /* RV515 seems to have MSI issues where it loses
239 * MSI rearms occasionally. This leads to lockups and freezes.
240 * disable it by default.
242 if (family
== CHIP_RV515
)
244 if (flags
& RADEON_IS_IGP
) {
245 /* APUs work fine with MSIs */
246 if (family
>= CHIP_PALM
)
248 /* lots of IGPs have problems with MSIs */
256 * radeon_irq_kms_init - init driver interrupt info
258 * @rdev: radeon device pointer
260 * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
261 * Returns 0 for success, error for failure.
263 int radeon_irq_kms_init(struct radeon_device
*rdev
)
268 lockinit(&rdev
->irq
.lock
, "drm__radeon_device__irq__lock", 0, LK_CANRECURSE
);
269 r
= drm_vblank_init(rdev
->ddev
, rdev
->num_crtc
);
274 rdev
->msi_enabled
= (rdev
->ddev
->irq_type
== PCI_INTR_TYPE_MSI
);
276 rdev
->irq
.installed
= true;
277 DRM_UNLOCK(rdev
->ddev
);
278 r
= drm_irq_install(rdev
->ddev
, rdev
->ddev
->irq
);
279 DRM_LOCK(rdev
->ddev
);
281 rdev
->irq
.installed
= false;
285 TASK_INIT(&rdev
->hotplug_work
, 0, radeon_hotplug_work_func
, rdev
);
286 TASK_INIT(&rdev
->audio_work
, 0, r600_audio_update_hdmi
, rdev
);
287 TASK_INIT(&rdev
->reset_work
, 0, radeon_irq_reset_work_func
, rdev
);
289 DRM_INFO("radeon: irq initialized.\n");
294 * radeon_irq_kms_fini - tear down driver interrupt info
296 * @rdev: radeon device pointer
298 * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
300 void radeon_irq_kms_fini(struct radeon_device
*rdev
)
302 drm_vblank_cleanup(rdev
->ddev
);
303 if (rdev
->irq
.installed
) {
304 drm_irq_uninstall(rdev
->ddev
);
305 rdev
->irq
.installed
= false;
307 taskqueue_drain(rdev
->tq
, &rdev
->hotplug_work
);
311 * radeon_irq_kms_sw_irq_get - enable software interrupt
313 * @rdev: radeon device pointer
314 * @ring: ring whose interrupt you want to enable
316 * Enables the software interrupt for a specific ring (all asics).
317 * The software interrupt is generally used to signal a fence on
320 void radeon_irq_kms_sw_irq_get(struct radeon_device
*rdev
, int ring
)
322 if (!rdev
->ddev
->irq_enabled
)
325 if (atomic_inc_return(&rdev
->irq
.ring_int
[ring
]) == 1) {
326 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
327 radeon_irq_set(rdev
);
328 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
333 * radeon_irq_kms_sw_irq_put - disable software interrupt
335 * @rdev: radeon device pointer
336 * @ring: ring whose interrupt you want to disable
338 * Disables the software interrupt for a specific ring (all asics).
339 * The software interrupt is generally used to signal a fence on
342 void radeon_irq_kms_sw_irq_put(struct radeon_device
*rdev
, int ring
)
344 if (!rdev
->ddev
->irq_enabled
)
347 if (atomic_dec_and_test(&rdev
->irq
.ring_int
[ring
])) {
348 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
349 radeon_irq_set(rdev
);
350 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
355 * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
357 * @rdev: radeon device pointer
358 * @crtc: crtc whose interrupt you want to enable
360 * Enables the pageflip interrupt for a specific crtc (all asics).
361 * For pageflips we use the vblank interrupt source.
363 void radeon_irq_kms_pflip_irq_get(struct radeon_device
*rdev
, int crtc
)
365 if (crtc
< 0 || crtc
>= rdev
->num_crtc
)
368 if (!rdev
->ddev
->irq_enabled
)
371 if (atomic_inc_return(&rdev
->irq
.pflip
[crtc
]) == 1) {
372 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
373 radeon_irq_set(rdev
);
374 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
379 * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
381 * @rdev: radeon device pointer
382 * @crtc: crtc whose interrupt you want to disable
384 * Disables the pageflip interrupt for a specific crtc (all asics).
385 * For pageflips we use the vblank interrupt source.
387 void radeon_irq_kms_pflip_irq_put(struct radeon_device
*rdev
, int crtc
)
389 if (crtc
< 0 || crtc
>= rdev
->num_crtc
)
392 if (!rdev
->ddev
->irq_enabled
)
395 if (atomic_dec_and_test(&rdev
->irq
.pflip
[crtc
])) {
396 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
397 radeon_irq_set(rdev
);
398 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
403 * radeon_irq_kms_enable_afmt - enable audio format change interrupt
405 * @rdev: radeon device pointer
406 * @block: afmt block whose interrupt you want to enable
408 * Enables the afmt change interrupt for a specific afmt block (all asics).
410 void radeon_irq_kms_enable_afmt(struct radeon_device
*rdev
, int block
)
412 if (!rdev
->ddev
->irq_enabled
)
415 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
416 rdev
->irq
.afmt
[block
] = true;
417 radeon_irq_set(rdev
);
418 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
422 * radeon_irq_kms_disable_afmt - disable audio format change interrupt
424 * @rdev: radeon device pointer
425 * @block: afmt block whose interrupt you want to disable
427 * Disables the afmt change interrupt for a specific afmt block (all asics).
429 void radeon_irq_kms_disable_afmt(struct radeon_device
*rdev
, int block
)
431 if (!rdev
->ddev
->irq_enabled
)
434 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
435 rdev
->irq
.afmt
[block
] = false;
436 radeon_irq_set(rdev
);
437 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
441 * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
443 * @rdev: radeon device pointer
444 * @hpd_mask: mask of hpd pins you want to enable.
446 * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
448 void radeon_irq_kms_enable_hpd(struct radeon_device
*rdev
, unsigned hpd_mask
)
452 if (!rdev
->ddev
->irq_enabled
)
455 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
456 for (i
= 0; i
< RADEON_MAX_HPD_PINS
; ++i
)
457 rdev
->irq
.hpd
[i
] |= !!(hpd_mask
& (1 << i
));
458 radeon_irq_set(rdev
);
459 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);
463 * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
465 * @rdev: radeon device pointer
466 * @hpd_mask: mask of hpd pins you want to disable.
468 * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
470 void radeon_irq_kms_disable_hpd(struct radeon_device
*rdev
, unsigned hpd_mask
)
474 if (!rdev
->ddev
->irq_enabled
)
477 lockmgr(&rdev
->irq
.lock
, LK_EXCLUSIVE
);
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 lockmgr(&rdev
->irq
.lock
, LK_RELEASE
);