drm/ttm: kill off some members to ttm_validate_buffer
[deliverable/linux.git] / drivers / gpu / drm / radeon / radeon_irq_kms.c
CommitLineData
771fe6b9
JG
1/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
760285e7
DH
28#include <drm/drmP.h>
29#include <drm/drm_crtc_helper.h>
30#include <drm/radeon_drm.h>
771fe6b9 31#include "radeon_reg.h"
771fe6b9
JG
32#include "radeon.h"
33#include "atom.h"
34
10ebc0bc
DA
35#include <linux/pm_runtime.h>
36
fb98257a
CK
37#define RADEON_WAIT_IDLE_TIMEOUT 200
38
b73ba98d
AD
39/**
40 * radeon_driver_irq_handler_kms - irq handler for KMS
41 *
e9f0d76f 42 * @int irq, void *arg: args
b73ba98d
AD
43 *
44 * This is the irq handler for the radeon KMS driver (all asics).
45 * radeon_irq_process is a macro that points to the per-asic
46 * irq handler callback.
47 */
e9f0d76f 48irqreturn_t radeon_driver_irq_handler_kms(int irq, void *arg)
771fe6b9
JG
49{
50 struct drm_device *dev = (struct drm_device *) arg;
51 struct radeon_device *rdev = dev->dev_private;
10ebc0bc 52 irqreturn_t ret;
771fe6b9 53
10ebc0bc
DA
54 ret = radeon_irq_process(rdev);
55 if (ret == IRQ_HANDLED)
56 pm_runtime_mark_last_busy(dev->dev);
57 return ret;
771fe6b9
JG
58}
59
d4877cf2
AD
60/*
61 * Handle hotplug events outside the interrupt handler proper.
62 */
b73ba98d
AD
63/**
64 * radeon_hotplug_work_func - display hotplug work handler
65 *
66 * @work: work struct
67 *
68 * This is the hot plug event work handler (all asics).
69 * The work gets scheduled from the irq handler if there
70 * was a hot plug interrupt. It walks the connector table
71 * and calls the hotplug handler for each one, then sends
72 * a drm hotplug event to alert userspace.
73 */
d4877cf2
AD
74static void radeon_hotplug_work_func(struct work_struct *work)
75{
76 struct radeon_device *rdev = container_of(work, struct radeon_device,
77 hotplug_work);
78 struct drm_device *dev = rdev->ddev;
79 struct drm_mode_config *mode_config = &dev->mode_config;
80 struct drm_connector *connector;
81
82 if (mode_config->num_connector) {
83 list_for_each_entry(connector, &mode_config->connector_list, head)
84 radeon_connector_hotplug(connector);
85 }
86 /* Just fire off a uevent and let userspace tell us what to do */
eb1f8e4f 87 drm_helper_hpd_irq_event(dev);
d4877cf2
AD
88}
89
b73ba98d
AD
90/**
91 * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
92 *
93 * @dev: drm dev pointer
94 *
95 * Gets the hw ready to enable irqs (all asics).
96 * This function disables all interrupt sources on the GPU.
97 */
771fe6b9
JG
98void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
99{
100 struct radeon_device *rdev = dev->dev_private;
fb98257a 101 unsigned long irqflags;
771fe6b9
JG
102 unsigned i;
103
fb98257a 104 spin_lock_irqsave(&rdev->irq.lock, irqflags);
771fe6b9 105 /* Disable *all* interrupts */
1b37078b 106 for (i = 0; i < RADEON_NUM_RINGS; i++)
736fc37f 107 atomic_set(&rdev->irq.ring_int[i], 0);
4a6369e9 108 rdev->irq.dpm_thermal = false;
54bd5206 109 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
9e7b414e 110 rdev->irq.hpd[i] = false;
54bd5206
IH
111 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
112 rdev->irq.crtc_vblank_int[i] = false;
736fc37f 113 atomic_set(&rdev->irq.pflip[i], 0);
f122c610 114 rdev->irq.afmt[i] = false;
6f34be50 115 }
771fe6b9 116 radeon_irq_set(rdev);
fb98257a 117 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
771fe6b9
JG
118 /* Clear bits */
119 radeon_irq_process(rdev);
120}
121
b73ba98d
AD
122/**
123 * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
124 *
125 * @dev: drm dev pointer
126 *
127 * Handles stuff to be done after enabling irqs (all asics).
128 * Returns 0 on success.
129 */
771fe6b9
JG
130int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
131{
771fe6b9 132 dev->max_vblank_count = 0x001fffff;
771fe6b9
JG
133 return 0;
134}
135
b73ba98d
AD
136/**
137 * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
138 *
139 * @dev: drm dev pointer
140 *
141 * This function disables all interrupt sources on the GPU (all asics).
142 */
771fe6b9
JG
143void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
144{
145 struct radeon_device *rdev = dev->dev_private;
fb98257a 146 unsigned long irqflags;
771fe6b9
JG
147 unsigned i;
148
149 if (rdev == NULL) {
150 return;
151 }
fb98257a 152 spin_lock_irqsave(&rdev->irq.lock, irqflags);
771fe6b9 153 /* Disable *all* interrupts */
1b37078b 154 for (i = 0; i < RADEON_NUM_RINGS; i++)
736fc37f 155 atomic_set(&rdev->irq.ring_int[i], 0);
4a6369e9 156 rdev->irq.dpm_thermal = false;
54bd5206 157 for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
003e69f9 158 rdev->irq.hpd[i] = false;
54bd5206
IH
159 for (i = 0; i < RADEON_MAX_CRTCS; i++) {
160 rdev->irq.crtc_vblank_int[i] = false;
736fc37f 161 atomic_set(&rdev->irq.pflip[i], 0);
f122c610 162 rdev->irq.afmt[i] = false;
6f34be50 163 }
771fe6b9 164 radeon_irq_set(rdev);
fb98257a 165 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
771fe6b9
JG
166}
167
b73ba98d
AD
168/**
169 * radeon_msi_ok - asic specific msi checks
170 *
171 * @rdev: radeon device pointer
172 *
173 * Handles asic specific MSI checks to determine if
174 * MSIs should be enabled on a particular chip (all asics).
175 * Returns true if MSIs should be enabled, false if MSIs
176 * should not be enabled.
177 */
8f6c25c5
AD
178static bool radeon_msi_ok(struct radeon_device *rdev)
179{
180 /* RV370/RV380 was first asic with MSI support */
181 if (rdev->family < CHIP_RV380)
182 return false;
183
184 /* MSIs don't work on AGP */
185 if (rdev->flags & RADEON_IS_AGP)
186 return false;
187
a18cee15
AD
188 /* force MSI on */
189 if (radeon_msi == 1)
190 return true;
191 else if (radeon_msi == 0)
192 return false;
193
b362105f
AD
194 /* Quirks */
195 /* HP RS690 only seems to work with MSIs. */
196 if ((rdev->pdev->device == 0x791f) &&
197 (rdev->pdev->subsystem_vendor == 0x103c) &&
198 (rdev->pdev->subsystem_device == 0x30c2))
199 return true;
200
44517c44
AD
201 /* Dell RS690 only seems to work with MSIs. */
202 if ((rdev->pdev->device == 0x791f) &&
203 (rdev->pdev->subsystem_vendor == 0x1028) &&
204 (rdev->pdev->subsystem_device == 0x01fc))
205 return true;
206
01e718ec
AD
207 /* Dell RS690 only seems to work with MSIs. */
208 if ((rdev->pdev->device == 0x791f) &&
209 (rdev->pdev->subsystem_vendor == 0x1028) &&
210 (rdev->pdev->subsystem_device == 0x01fd))
211 return true;
212
3a6d59df
AD
213 /* Gateway RS690 only seems to work with MSIs. */
214 if ((rdev->pdev->device == 0x791f) &&
215 (rdev->pdev->subsystem_vendor == 0x107b) &&
216 (rdev->pdev->subsystem_device == 0x0185))
217 return true;
218
fb6ca6d1
AD
219 /* try and enable MSIs by default on all RS690s */
220 if (rdev->family == CHIP_RS690)
221 return true;
222
16a5e32b
DA
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.
226 */
227 if (rdev->family == CHIP_RV515)
228 return false;
8f6c25c5
AD
229 if (rdev->flags & RADEON_IS_IGP) {
230 /* APUs work fine with MSIs */
231 if (rdev->family >= CHIP_PALM)
232 return true;
233 /* lots of IGPs have problems with MSIs */
234 return false;
235 }
236
237 return true;
238}
239
b73ba98d
AD
240/**
241 * radeon_irq_kms_init - init driver interrupt info
242 *
243 * @rdev: radeon device pointer
244 *
245 * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
246 * Returns 0 for success, error for failure.
247 */
771fe6b9
JG
248int radeon_irq_kms_init(struct radeon_device *rdev)
249{
250 int r = 0;
251
fb98257a 252 spin_lock_init(&rdev->irq.lock);
9e7b414e 253 r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
771fe6b9
JG
254 if (r) {
255 return r;
256 }
3e5cb98d
AD
257 /* enable msi */
258 rdev->msi_enabled = 0;
8f6c25c5
AD
259
260 if (radeon_msi_ok(rdev)) {
3e5cb98d 261 int ret = pci_enable_msi(rdev->pdev);
d8f60cfc 262 if (!ret) {
3e5cb98d 263 rdev->msi_enabled = 1;
da7be684 264 dev_info(rdev->dev, "radeon: using MSI.\n");
d8f60cfc 265 }
3e5cb98d 266 }
27c505ca
SS
267
268 INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
269 INIT_WORK(&rdev->audio_work, r600_audio_update_hdmi);
27c505ca 270
771fe6b9 271 rdev->irq.installed = true;
bb0f1b5c 272 r = drm_irq_install(rdev->ddev, rdev->ddev->pdev->irq);
003e69f9
JG
273 if (r) {
274 rdev->irq.installed = false;
27c505ca 275 flush_work(&rdev->hotplug_work);
003e69f9
JG
276 return r;
277 }
a01c34f7 278
771fe6b9
JG
279 DRM_INFO("radeon: irq initialized.\n");
280 return 0;
281}
282
b73ba98d 283/**
cf2fbdd2 284 * radeon_irq_kms_fini - tear down driver interrupt info
b73ba98d
AD
285 *
286 * @rdev: radeon device pointer
287 *
288 * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
289 */
771fe6b9
JG
290void radeon_irq_kms_fini(struct radeon_device *rdev)
291{
003e69f9 292 drm_vblank_cleanup(rdev->ddev);
771fe6b9 293 if (rdev->irq.installed) {
771fe6b9 294 drm_irq_uninstall(rdev->ddev);
003e69f9 295 rdev->irq.installed = false;
3e5cb98d
AD
296 if (rdev->msi_enabled)
297 pci_disable_msi(rdev->pdev);
a01c34f7 298 flush_work(&rdev->hotplug_work);
771fe6b9
JG
299 }
300}
1614f8b1 301
b73ba98d
AD
302/**
303 * radeon_irq_kms_sw_irq_get - enable software interrupt
304 *
305 * @rdev: radeon device pointer
306 * @ring: ring whose interrupt you want to enable
307 *
308 * Enables the software interrupt for a specific ring (all asics).
309 * The software interrupt is generally used to signal a fence on
310 * a particular ring.
311 */
1b37078b 312void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring)
1614f8b1
DA
313{
314 unsigned long irqflags;
315
736fc37f
CK
316 if (!rdev->ddev->irq_enabled)
317 return;
318
319 if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) {
320 spin_lock_irqsave(&rdev->irq.lock, irqflags);
1614f8b1 321 radeon_irq_set(rdev);
736fc37f 322 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
1614f8b1 323 }
1614f8b1
DA
324}
325
b73ba98d
AD
326/**
327 * radeon_irq_kms_sw_irq_put - disable software interrupt
328 *
329 * @rdev: radeon device pointer
330 * @ring: ring whose interrupt you want to disable
331 *
332 * Disables the software interrupt for a specific ring (all asics).
333 * The software interrupt is generally used to signal a fence on
334 * a particular ring.
335 */
1b37078b 336void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring)
1614f8b1
DA
337{
338 unsigned long irqflags;
339
736fc37f
CK
340 if (!rdev->ddev->irq_enabled)
341 return;
342
343 if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) {
344 spin_lock_irqsave(&rdev->irq.lock, irqflags);
1614f8b1 345 radeon_irq_set(rdev);
736fc37f 346 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
1614f8b1 347 }
1614f8b1
DA
348}
349
b73ba98d
AD
350/**
351 * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
352 *
353 * @rdev: radeon device pointer
354 * @crtc: crtc whose interrupt you want to enable
355 *
356 * Enables the pageflip interrupt for a specific crtc (all asics).
357 * For pageflips we use the vblank interrupt source.
358 */
6f34be50
AD
359void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc)
360{
361 unsigned long irqflags;
362
363 if (crtc < 0 || crtc >= rdev->num_crtc)
364 return;
365
736fc37f
CK
366 if (!rdev->ddev->irq_enabled)
367 return;
368
369 if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) {
370 spin_lock_irqsave(&rdev->irq.lock, irqflags);
6f34be50 371 radeon_irq_set(rdev);
736fc37f 372 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
6f34be50 373 }
6f34be50
AD
374}
375
b73ba98d
AD
376/**
377 * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
378 *
379 * @rdev: radeon device pointer
380 * @crtc: crtc whose interrupt you want to disable
381 *
382 * Disables the pageflip interrupt for a specific crtc (all asics).
383 * For pageflips we use the vblank interrupt source.
384 */
6f34be50
AD
385void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc)
386{
387 unsigned long irqflags;
388
389 if (crtc < 0 || crtc >= rdev->num_crtc)
390 return;
391
736fc37f
CK
392 if (!rdev->ddev->irq_enabled)
393 return;
394
395 if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) {
396 spin_lock_irqsave(&rdev->irq.lock, irqflags);
6f34be50 397 radeon_irq_set(rdev);
736fc37f 398 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
6f34be50 399 }
6f34be50
AD
400}
401
b73ba98d
AD
402/**
403 * radeon_irq_kms_enable_afmt - enable audio format change interrupt
404 *
405 * @rdev: radeon device pointer
406 * @block: afmt block whose interrupt you want to enable
407 *
408 * Enables the afmt change interrupt for a specific afmt block (all asics).
409 */
fb98257a
CK
410void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block)
411{
412 unsigned long irqflags;
413
cc9945bf
AD
414 if (!rdev->ddev->irq_enabled)
415 return;
416
fb98257a
CK
417 spin_lock_irqsave(&rdev->irq.lock, irqflags);
418 rdev->irq.afmt[block] = true;
419 radeon_irq_set(rdev);
420 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
421
422}
423
b73ba98d
AD
424/**
425 * radeon_irq_kms_disable_afmt - disable audio format change interrupt
426 *
427 * @rdev: radeon device pointer
428 * @block: afmt block whose interrupt you want to disable
429 *
430 * Disables the afmt change interrupt for a specific afmt block (all asics).
431 */
fb98257a
CK
432void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block)
433{
434 unsigned long irqflags;
435
cc9945bf
AD
436 if (!rdev->ddev->irq_enabled)
437 return;
438
fb98257a
CK
439 spin_lock_irqsave(&rdev->irq.lock, irqflags);
440 rdev->irq.afmt[block] = false;
441 radeon_irq_set(rdev);
442 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
443}
444
b73ba98d
AD
445/**
446 * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
447 *
448 * @rdev: radeon device pointer
449 * @hpd_mask: mask of hpd pins you want to enable.
450 *
451 * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
452 */
fb98257a
CK
453void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
454{
455 unsigned long irqflags;
456 int i;
457
cc9945bf
AD
458 if (!rdev->ddev->irq_enabled)
459 return;
460
fb98257a
CK
461 spin_lock_irqsave(&rdev->irq.lock, irqflags);
462 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
463 rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
464 radeon_irq_set(rdev);
465 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
466}
467
b73ba98d
AD
468/**
469 * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
470 *
471 * @rdev: radeon device pointer
472 * @hpd_mask: mask of hpd pins you want to disable.
473 *
474 * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
475 */
fb98257a
CK
476void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
477{
478 unsigned long irqflags;
479 int i;
480
cc9945bf
AD
481 if (!rdev->ddev->irq_enabled)
482 return;
483
fb98257a
CK
484 spin_lock_irqsave(&rdev->irq.lock, irqflags);
485 for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
486 rdev->irq.hpd[i] &= !(hpd_mask & (1 << i));
487 radeon_irq_set(rdev);
488 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
489}
490
This page took 0.308679 seconds and 5 git commands to generate.