Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
radeon_irq_kms.c
Go to the documentation of this file.
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 <drm/drmP.h>
29 #include <drm/drm_crtc_helper.h>
30 #include <drm/radeon_drm.h>
31 #include "radeon_reg.h"
32 #include "radeon.h"
33 #include "atom.h"
34 
35 #define RADEON_WAIT_IDLE_TIMEOUT 200
36 
47 {
48  struct drm_device *dev = (struct drm_device *) arg;
49  struct radeon_device *rdev = dev->dev_private;
50 
51  return radeon_irq_process(rdev);
52 }
53 
54 /*
55  * Handle hotplug events outside the interrupt handler proper.
56  */
68 static void radeon_hotplug_work_func(struct work_struct *work)
69 {
70  struct radeon_device *rdev = container_of(work, struct radeon_device,
71  hotplug_work);
72  struct drm_device *dev = rdev->ddev;
73  struct drm_mode_config *mode_config = &dev->mode_config;
74  struct drm_connector *connector;
75 
76  if (mode_config->num_connector) {
77  list_for_each_entry(connector, &mode_config->connector_list, head)
78  radeon_connector_hotplug(connector);
79  }
80  /* Just fire off a uevent and let userspace tell us what to do */
82 }
83 
93 {
94  struct radeon_device *rdev = dev->dev_private;
95  unsigned long irqflags;
96  unsigned i;
97 
98  spin_lock_irqsave(&rdev->irq.lock, irqflags);
99  /* Disable *all* interrupts */
100  for (i = 0; i < RADEON_NUM_RINGS; i++)
101  atomic_set(&rdev->irq.ring_int[i], 0);
102  for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
103  rdev->irq.hpd[i] = false;
104  for (i = 0; i < RADEON_MAX_CRTCS; i++) {
105  rdev->irq.crtc_vblank_int[i] = false;
106  atomic_set(&rdev->irq.pflip[i], 0);
107  rdev->irq.afmt[i] = false;
108  }
109  radeon_irq_set(rdev);
110  spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
111  /* Clear bits */
112  radeon_irq_process(rdev);
113 }
114 
124 {
125  dev->max_vblank_count = 0x001fffff;
126  return 0;
127 }
128 
137 {
138  struct radeon_device *rdev = dev->dev_private;
139  unsigned long irqflags;
140  unsigned i;
141 
142  if (rdev == NULL) {
143  return;
144  }
145  spin_lock_irqsave(&rdev->irq.lock, irqflags);
146  /* Disable *all* interrupts */
147  for (i = 0; i < RADEON_NUM_RINGS; i++)
148  atomic_set(&rdev->irq.ring_int[i], 0);
149  for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
150  rdev->irq.hpd[i] = false;
151  for (i = 0; i < RADEON_MAX_CRTCS; i++) {
152  rdev->irq.crtc_vblank_int[i] = false;
153  atomic_set(&rdev->irq.pflip[i], 0);
154  rdev->irq.afmt[i] = false;
155  }
156  radeon_irq_set(rdev);
157  spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
158 }
159 
170 static bool radeon_msi_ok(struct radeon_device *rdev)
171 {
172  /* RV370/RV380 was first asic with MSI support */
173  if (rdev->family < CHIP_RV380)
174  return false;
175 
176  /* MSIs don't work on AGP */
177  if (rdev->flags & RADEON_IS_AGP)
178  return false;
179 
180  /* force MSI on */
181  if (radeon_msi == 1)
182  return true;
183  else if (radeon_msi == 0)
184  return false;
185 
186  /* Quirks */
187  /* HP RS690 only seems to work with MSIs. */
188  if ((rdev->pdev->device == 0x791f) &&
189  (rdev->pdev->subsystem_vendor == 0x103c) &&
190  (rdev->pdev->subsystem_device == 0x30c2))
191  return true;
192 
193  /* Dell RS690 only seems to work with MSIs. */
194  if ((rdev->pdev->device == 0x791f) &&
195  (rdev->pdev->subsystem_vendor == 0x1028) &&
196  (rdev->pdev->subsystem_device == 0x01fc))
197  return true;
198 
199  /* Dell RS690 only seems to work with MSIs. */
200  if ((rdev->pdev->device == 0x791f) &&
201  (rdev->pdev->subsystem_vendor == 0x1028) &&
202  (rdev->pdev->subsystem_device == 0x01fd))
203  return true;
204 
205  /* Gateway RS690 only seems to work with MSIs. */
206  if ((rdev->pdev->device == 0x791f) &&
207  (rdev->pdev->subsystem_vendor == 0x107b) &&
208  (rdev->pdev->subsystem_device == 0x0185))
209  return true;
210 
211  /* try and enable MSIs by default on all RS690s */
212  if (rdev->family == CHIP_RS690)
213  return true;
214 
215  /* RV515 seems to have MSI issues where it loses
216  * MSI rearms occasionally. This leads to lockups and freezes.
217  * disable it by default.
218  */
219  if (rdev->family == CHIP_RV515)
220  return false;
221  if (rdev->flags & RADEON_IS_IGP) {
222  /* APUs work fine with MSIs */
223  if (rdev->family >= CHIP_PALM)
224  return true;
225  /* lots of IGPs have problems with MSIs */
226  return false;
227  }
228 
229  return true;
230 }
231 
241 {
242  int r = 0;
243 
244  INIT_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
246 
247  spin_lock_init(&rdev->irq.lock);
248  r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
249  if (r) {
250  return r;
251  }
252  /* enable msi */
253  rdev->msi_enabled = 0;
254 
255  if (radeon_msi_ok(rdev)) {
256  int ret = pci_enable_msi(rdev->pdev);
257  if (!ret) {
258  rdev->msi_enabled = 1;
259  dev_info(rdev->dev, "radeon: using MSI.\n");
260  }
261  }
262  rdev->irq.installed = true;
263  r = drm_irq_install(rdev->ddev);
264  if (r) {
265  rdev->irq.installed = false;
266  return r;
267  }
268  DRM_INFO("radeon: irq initialized.\n");
269  return 0;
270 }
271 
280 {
281  drm_vblank_cleanup(rdev->ddev);
282  if (rdev->irq.installed) {
283  drm_irq_uninstall(rdev->ddev);
284  rdev->irq.installed = false;
285  if (rdev->msi_enabled)
286  pci_disable_msi(rdev->pdev);
287  }
288  flush_work(&rdev->hotplug_work);
289 }
290 
302 {
303  unsigned long irqflags;
304 
305  if (!rdev->ddev->irq_enabled)
306  return;
307 
308  if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) {
309  spin_lock_irqsave(&rdev->irq.lock, irqflags);
310  radeon_irq_set(rdev);
311  spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
312  }
313 }
314 
326 {
327  unsigned long irqflags;
328 
329  if (!rdev->ddev->irq_enabled)
330  return;
331 
332  if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) {
333  spin_lock_irqsave(&rdev->irq.lock, irqflags);
334  radeon_irq_set(rdev);
335  spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
336  }
337 }
338 
349 {
350  unsigned long irqflags;
351 
352  if (crtc < 0 || crtc >= rdev->num_crtc)
353  return;
354 
355  if (!rdev->ddev->irq_enabled)
356  return;
357 
358  if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) {
359  spin_lock_irqsave(&rdev->irq.lock, irqflags);
360  radeon_irq_set(rdev);
361  spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
362  }
363 }
364 
375 {
376  unsigned long irqflags;
377 
378  if (crtc < 0 || crtc >= rdev->num_crtc)
379  return;
380 
381  if (!rdev->ddev->irq_enabled)
382  return;
383 
384  if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) {
385  spin_lock_irqsave(&rdev->irq.lock, irqflags);
386  radeon_irq_set(rdev);
387  spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
388  }
389 }
390 
400 {
401  unsigned long irqflags;
402 
403  spin_lock_irqsave(&rdev->irq.lock, irqflags);
404  rdev->irq.afmt[block] = true;
405  radeon_irq_set(rdev);
406  spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
407 
408 }
409 
419 {
420  unsigned long irqflags;
421 
422  spin_lock_irqsave(&rdev->irq.lock, irqflags);
423  rdev->irq.afmt[block] = false;
424  radeon_irq_set(rdev);
425  spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
426 }
427 
436 void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
437 {
438  unsigned long irqflags;
439  int i;
440 
441  spin_lock_irqsave(&rdev->irq.lock, irqflags);
442  for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
443  rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
444  radeon_irq_set(rdev);
445  spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
446 }
447 
456 void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
457 {
458  unsigned long irqflags;
459  int i;
460 
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