Line data Source code
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 : */
28 : #include <dev/pci/drm/drmP.h>
29 : #include <dev/pci/drm/drm_crtc_helper.h>
30 : #include <dev/pci/drm/radeon_drm.h>
31 : #include "radeon_reg.h"
32 : #include "radeon.h"
33 : #include "atom.h"
34 :
35 :
36 : #define RADEON_WAIT_IDLE_TIMEOUT 200
37 :
38 : /**
39 : * radeon_driver_irq_handler_kms - irq handler for KMS
40 : *
41 : * @int irq, void *arg: args
42 : *
43 : * This is the irq handler for the radeon KMS driver (all asics).
44 : * radeon_irq_process is a macro that points to the per-asic
45 : * irq handler callback.
46 : */
47 0 : irqreturn_t radeon_driver_irq_handler_kms(void *arg)
48 : {
49 0 : struct drm_device *dev = (struct drm_device *) arg;
50 0 : struct radeon_device *rdev = dev->dev_private;
51 : irqreturn_t ret;
52 :
53 0 : if (!rdev->irq.installed)
54 0 : return 0;
55 :
56 0 : ret = radeon_irq_process(rdev);
57 : if (ret == IRQ_HANDLED)
58 : pm_runtime_mark_last_busy(dev->dev);
59 0 : return ret;
60 0 : }
61 :
62 : /*
63 : * Handle hotplug events outside the interrupt handler proper.
64 : */
65 : /**
66 : * radeon_hotplug_work_func - display hotplug work handler
67 : *
68 : * @work: work struct
69 : *
70 : * This is the hot plug event work handler (all asics).
71 : * The work gets scheduled from the irq handler if there
72 : * was a hot plug interrupt. It walks the connector table
73 : * and calls the hotplug handler for each one, then sends
74 : * a drm hotplug event to alert userspace.
75 : */
76 0 : static void radeon_hotplug_work_func(struct work_struct *work)
77 : {
78 0 : struct radeon_device *rdev = container_of(work, struct radeon_device,
79 : hotplug_work.work);
80 0 : struct drm_device *dev = rdev->ddev;
81 0 : struct drm_mode_config *mode_config = &dev->mode_config;
82 : struct drm_connector *connector;
83 :
84 : /* we can race here at startup, some boards seem to trigger
85 : * hotplug irqs when they shouldn't. */
86 0 : if (!rdev->mode_info.mode_config_initialized)
87 0 : return;
88 :
89 0 : mutex_lock(&mode_config->mutex);
90 0 : if (mode_config->num_connector) {
91 0 : list_for_each_entry(connector, &mode_config->connector_list, head)
92 0 : radeon_connector_hotplug(connector);
93 : }
94 0 : mutex_unlock(&mode_config->mutex);
95 : /* Just fire off a uevent and let userspace tell us what to do */
96 0 : drm_helper_hpd_irq_event(dev);
97 0 : }
98 :
99 0 : static void radeon_dp_work_func(struct work_struct *work)
100 : {
101 0 : struct radeon_device *rdev = container_of(work, struct radeon_device,
102 : dp_work);
103 0 : struct drm_device *dev = rdev->ddev;
104 0 : struct drm_mode_config *mode_config = &dev->mode_config;
105 : struct drm_connector *connector;
106 :
107 : /* this should take a mutex */
108 0 : if (mode_config->num_connector) {
109 0 : list_for_each_entry(connector, &mode_config->connector_list, head)
110 0 : radeon_connector_hotplug(connector);
111 : }
112 0 : }
113 : /**
114 : * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
115 : *
116 : * @dev: drm dev pointer
117 : *
118 : * Gets the hw ready to enable irqs (all asics).
119 : * This function disables all interrupt sources on the GPU.
120 : */
121 0 : void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
122 : {
123 0 : struct radeon_device *rdev = dev->dev_private;
124 : unsigned long irqflags;
125 : unsigned i;
126 :
127 0 : spin_lock_irqsave(&rdev->irq.lock, irqflags);
128 : /* Disable *all* interrupts */
129 0 : for (i = 0; i < RADEON_NUM_RINGS; i++)
130 0 : atomic_set(&rdev->irq.ring_int[i], 0);
131 0 : rdev->irq.dpm_thermal = false;
132 0 : for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
133 0 : rdev->irq.hpd[i] = false;
134 0 : for (i = 0; i < RADEON_MAX_CRTCS; i++) {
135 0 : rdev->irq.crtc_vblank_int[i] = false;
136 0 : atomic_set(&rdev->irq.pflip[i], 0);
137 0 : rdev->irq.afmt[i] = false;
138 : }
139 0 : radeon_irq_set(rdev);
140 0 : spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
141 : /* Clear bits */
142 0 : radeon_irq_process(rdev);
143 0 : }
144 :
145 : /**
146 : * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
147 : *
148 : * @dev: drm dev pointer
149 : *
150 : * Handles stuff to be done after enabling irqs (all asics).
151 : * Returns 0 on success.
152 : */
153 0 : int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
154 : {
155 0 : struct radeon_device *rdev = dev->dev_private;
156 :
157 0 : if (ASIC_IS_AVIVO(rdev))
158 0 : dev->max_vblank_count = 0x00ffffff;
159 : else
160 0 : dev->max_vblank_count = 0x001fffff;
161 :
162 0 : return 0;
163 : }
164 :
165 : /**
166 : * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
167 : *
168 : * @dev: drm dev pointer
169 : *
170 : * This function disables all interrupt sources on the GPU (all asics).
171 : */
172 0 : void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
173 : {
174 0 : struct radeon_device *rdev = dev->dev_private;
175 : unsigned long irqflags;
176 : unsigned i;
177 :
178 0 : if (rdev == NULL) {
179 0 : return;
180 : }
181 0 : spin_lock_irqsave(&rdev->irq.lock, irqflags);
182 : /* Disable *all* interrupts */
183 0 : for (i = 0; i < RADEON_NUM_RINGS; i++)
184 0 : atomic_set(&rdev->irq.ring_int[i], 0);
185 0 : rdev->irq.dpm_thermal = false;
186 0 : for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
187 0 : rdev->irq.hpd[i] = false;
188 0 : for (i = 0; i < RADEON_MAX_CRTCS; i++) {
189 0 : rdev->irq.crtc_vblank_int[i] = false;
190 0 : atomic_set(&rdev->irq.pflip[i], 0);
191 0 : rdev->irq.afmt[i] = false;
192 : }
193 0 : radeon_irq_set(rdev);
194 0 : spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
195 0 : }
196 :
197 : /**
198 : * radeon_msi_ok - asic specific msi checks
199 : *
200 : * @rdev: radeon device pointer
201 : *
202 : * Handles asic specific MSI checks to determine if
203 : * MSIs should be enabled on a particular chip (all asics).
204 : * Returns true if MSIs should be enabled, false if MSIs
205 : * should not be enabled.
206 : */
207 0 : bool radeon_msi_ok(struct radeon_device *rdev)
208 : {
209 : /* RV370/RV380 was first asic with MSI support */
210 0 : if (rdev->family < CHIP_RV380)
211 0 : return false;
212 :
213 : /* MSIs don't work on AGP */
214 0 : if (rdev->flags & RADEON_IS_AGP)
215 0 : return false;
216 :
217 : /*
218 : * Older chips have a HW limitation, they can only generate 40 bits
219 : * of address for "64-bit" MSIs which breaks on some platforms, notably
220 : * IBM POWER servers, so we limit them
221 : */
222 : #ifdef notyet
223 : if (rdev->family < CHIP_BONAIRE) {
224 : dev_info(rdev->dev, "radeon: MSI limited to 32-bit\n");
225 : rdev->pdev->no_64bit_msi = 1;
226 : }
227 : #endif
228 :
229 : /* force MSI on */
230 0 : if (radeon_msi == 1)
231 0 : return true;
232 0 : else if (radeon_msi == 0)
233 0 : return false;
234 :
235 : /* Quirks */
236 : /* HP RS690 only seems to work with MSIs. */
237 0 : if ((rdev->pdev->device == 0x791f) &&
238 0 : (rdev->pdev->subsystem_vendor == 0x103c) &&
239 0 : (rdev->pdev->subsystem_device == 0x30c2))
240 0 : return true;
241 :
242 : /* Dell RS690 only seems to work with MSIs. */
243 0 : if ((rdev->pdev->device == 0x791f) &&
244 0 : (rdev->pdev->subsystem_vendor == 0x1028) &&
245 0 : (rdev->pdev->subsystem_device == 0x01fc))
246 0 : return true;
247 :
248 : /* Dell RS690 only seems to work with MSIs. */
249 0 : if ((rdev->pdev->device == 0x791f) &&
250 0 : (rdev->pdev->subsystem_vendor == 0x1028) &&
251 0 : (rdev->pdev->subsystem_device == 0x01fd))
252 0 : return true;
253 :
254 : /* Gateway RS690 only seems to work with MSIs. */
255 0 : if ((rdev->pdev->device == 0x791f) &&
256 0 : (rdev->pdev->subsystem_vendor == 0x107b) &&
257 0 : (rdev->pdev->subsystem_device == 0x0185))
258 0 : return true;
259 :
260 : /* try and enable MSIs by default on all RS690s */
261 0 : if (rdev->family == CHIP_RS690)
262 0 : return true;
263 :
264 : /* RV515 seems to have MSI issues where it loses
265 : * MSI rearms occasionally. This leads to lockups and freezes.
266 : * disable it by default.
267 : */
268 0 : if (rdev->family == CHIP_RV515)
269 0 : return false;
270 0 : if (rdev->flags & RADEON_IS_IGP) {
271 : /* APUs work fine with MSIs */
272 0 : if (rdev->family >= CHIP_PALM)
273 0 : return true;
274 : /* lots of IGPs have problems with MSIs */
275 0 : return false;
276 : }
277 :
278 0 : return true;
279 0 : }
280 :
281 : /**
282 : * radeon_irq_kms_init - init driver interrupt info
283 : *
284 : * @rdev: radeon device pointer
285 : *
286 : * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
287 : * Returns 0 for success, error for failure.
288 : */
289 0 : int radeon_irq_kms_init(struct radeon_device *rdev)
290 : {
291 : int r = 0;
292 :
293 0 : mtx_init(&rdev->irq.lock, IPL_TTY);
294 0 : r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
295 0 : if (r) {
296 0 : return r;
297 : }
298 : #ifdef notyet
299 : /* enable msi */
300 : rdev->msi_enabled = 0;
301 :
302 : if (radeon_msi_ok(rdev)) {
303 : int ret = pci_enable_msi(rdev->pdev);
304 : if (!ret) {
305 : rdev->msi_enabled = 1;
306 : dev_info(rdev->dev, "radeon: using MSI.\n");
307 : }
308 : }
309 : #endif
310 :
311 0 : INIT_DELAYED_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
312 0 : INIT_WORK(&rdev->dp_work, radeon_dp_work_func);
313 0 : INIT_WORK(&rdev->audio_work, r600_audio_update_hdmi);
314 :
315 0 : rdev->irq.installed = true;
316 0 : r = drm_irq_install(rdev->ddev, rdev->ddev->pdev->irq);
317 0 : if (r) {
318 0 : rdev->irq.installed = false;
319 0 : flush_delayed_work(&rdev->hotplug_work);
320 0 : return r;
321 : }
322 :
323 : DRM_INFO("radeon: irq initialized.\n");
324 0 : return 0;
325 0 : }
326 :
327 : /**
328 : * radeon_irq_kms_fini - tear down driver interrupt info
329 : *
330 : * @rdev: radeon device pointer
331 : *
332 : * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
333 : */
334 0 : void radeon_irq_kms_fini(struct radeon_device *rdev)
335 : {
336 0 : drm_vblank_cleanup(rdev->ddev);
337 0 : if (rdev->irq.installed) {
338 0 : drm_irq_uninstall(rdev->ddev);
339 0 : rdev->irq.installed = false;
340 0 : if (rdev->msi_enabled)
341 : pci_disable_msi(rdev->pdev);
342 0 : flush_delayed_work(&rdev->hotplug_work);
343 0 : }
344 0 : }
345 :
346 : /**
347 : * radeon_irq_kms_sw_irq_get - enable software interrupt
348 : *
349 : * @rdev: radeon device pointer
350 : * @ring: ring whose interrupt you want to enable
351 : *
352 : * Enables the software interrupt for a specific ring (all asics).
353 : * The software interrupt is generally used to signal a fence on
354 : * a particular ring.
355 : */
356 0 : void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring)
357 : {
358 : unsigned long irqflags;
359 :
360 0 : if (!rdev->ddev->irq_enabled)
361 0 : return;
362 :
363 0 : if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) {
364 0 : spin_lock_irqsave(&rdev->irq.lock, irqflags);
365 0 : radeon_irq_set(rdev);
366 0 : spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
367 0 : }
368 0 : }
369 :
370 : /**
371 : * radeon_irq_kms_sw_irq_get_delayed - enable software interrupt
372 : *
373 : * @rdev: radeon device pointer
374 : * @ring: ring whose interrupt you want to enable
375 : *
376 : * Enables the software interrupt for a specific ring (all asics).
377 : * The software interrupt is generally used to signal a fence on
378 : * a particular ring.
379 : */
380 0 : bool radeon_irq_kms_sw_irq_get_delayed(struct radeon_device *rdev, int ring)
381 : {
382 0 : return atomic_inc_return(&rdev->irq.ring_int[ring]) == 1;
383 : }
384 :
385 : /**
386 : * radeon_irq_kms_sw_irq_put - disable software interrupt
387 : *
388 : * @rdev: radeon device pointer
389 : * @ring: ring whose interrupt you want to disable
390 : *
391 : * Disables the software interrupt for a specific ring (all asics).
392 : * The software interrupt is generally used to signal a fence on
393 : * a particular ring.
394 : */
395 0 : void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring)
396 : {
397 : unsigned long irqflags;
398 :
399 0 : if (!rdev->ddev->irq_enabled)
400 0 : return;
401 :
402 0 : if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) {
403 0 : spin_lock_irqsave(&rdev->irq.lock, irqflags);
404 0 : radeon_irq_set(rdev);
405 0 : spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
406 0 : }
407 0 : }
408 :
409 : /**
410 : * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
411 : *
412 : * @rdev: radeon device pointer
413 : * @crtc: crtc whose interrupt you want to enable
414 : *
415 : * Enables the pageflip interrupt for a specific crtc (all asics).
416 : * For pageflips we use the vblank interrupt source.
417 : */
418 0 : void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc)
419 : {
420 : unsigned long irqflags;
421 :
422 0 : if (crtc < 0 || crtc >= rdev->num_crtc)
423 0 : return;
424 :
425 0 : if (!rdev->ddev->irq_enabled)
426 0 : return;
427 :
428 0 : if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) {
429 0 : spin_lock_irqsave(&rdev->irq.lock, irqflags);
430 0 : radeon_irq_set(rdev);
431 0 : spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
432 0 : }
433 0 : }
434 :
435 : /**
436 : * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
437 : *
438 : * @rdev: radeon device pointer
439 : * @crtc: crtc whose interrupt you want to disable
440 : *
441 : * Disables the pageflip interrupt for a specific crtc (all asics).
442 : * For pageflips we use the vblank interrupt source.
443 : */
444 0 : void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc)
445 : {
446 : unsigned long irqflags;
447 :
448 0 : if (crtc < 0 || crtc >= rdev->num_crtc)
449 0 : return;
450 :
451 0 : if (!rdev->ddev->irq_enabled)
452 0 : return;
453 :
454 0 : if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) {
455 0 : spin_lock_irqsave(&rdev->irq.lock, irqflags);
456 0 : radeon_irq_set(rdev);
457 0 : spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
458 0 : }
459 0 : }
460 :
461 : /**
462 : * radeon_irq_kms_enable_afmt - enable audio format change interrupt
463 : *
464 : * @rdev: radeon device pointer
465 : * @block: afmt block whose interrupt you want to enable
466 : *
467 : * Enables the afmt change interrupt for a specific afmt block (all asics).
468 : */
469 0 : void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block)
470 : {
471 : unsigned long irqflags;
472 :
473 0 : if (!rdev->ddev->irq_enabled)
474 0 : return;
475 :
476 0 : spin_lock_irqsave(&rdev->irq.lock, irqflags);
477 0 : rdev->irq.afmt[block] = true;
478 0 : radeon_irq_set(rdev);
479 0 : spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
480 :
481 0 : }
482 :
483 : /**
484 : * radeon_irq_kms_disable_afmt - disable audio format change interrupt
485 : *
486 : * @rdev: radeon device pointer
487 : * @block: afmt block whose interrupt you want to disable
488 : *
489 : * Disables the afmt change interrupt for a specific afmt block (all asics).
490 : */
491 0 : void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block)
492 : {
493 : unsigned long irqflags;
494 :
495 0 : if (!rdev->ddev->irq_enabled)
496 0 : return;
497 :
498 0 : spin_lock_irqsave(&rdev->irq.lock, irqflags);
499 0 : rdev->irq.afmt[block] = false;
500 0 : radeon_irq_set(rdev);
501 0 : spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
502 0 : }
503 :
504 : /**
505 : * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
506 : *
507 : * @rdev: radeon device pointer
508 : * @hpd_mask: mask of hpd pins you want to enable.
509 : *
510 : * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
511 : */
512 0 : void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
513 : {
514 : unsigned long irqflags;
515 : int i;
516 :
517 0 : if (!rdev->ddev->irq_enabled)
518 0 : return;
519 :
520 0 : spin_lock_irqsave(&rdev->irq.lock, irqflags);
521 0 : for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
522 0 : rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
523 0 : radeon_irq_set(rdev);
524 0 : spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
525 0 : }
526 :
527 : /**
528 : * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
529 : *
530 : * @rdev: radeon device pointer
531 : * @hpd_mask: mask of hpd pins you want to disable.
532 : *
533 : * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
534 : */
535 0 : void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
536 : {
537 : unsigned long irqflags;
538 : int i;
539 :
540 0 : if (!rdev->ddev->irq_enabled)
541 0 : return;
542 :
543 0 : spin_lock_irqsave(&rdev->irq.lock, irqflags);
544 0 : for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
545 0 : rdev->irq.hpd[i] &= !(hpd_mask & (1 << i));
546 0 : radeon_irq_set(rdev);
547 0 : spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
548 0 : }
549 :
|