Commit | Line | Data |
---|---|---|
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 | */ | |
28 | #include "drmP.h" | |
29 | #include "radeon_drm.h" | |
30 | #include "radeon_reg.h" | |
771fe6b9 JG |
31 | #include "radeon.h" |
32 | #include "atom.h" | |
33 | ||
771fe6b9 JG |
34 | irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS) |
35 | { | |
36 | struct drm_device *dev = (struct drm_device *) arg; | |
37 | struct radeon_device *rdev = dev->dev_private; | |
38 | ||
39 | return radeon_irq_process(rdev); | |
40 | } | |
41 | ||
42 | void radeon_driver_irq_preinstall_kms(struct drm_device *dev) | |
43 | { | |
44 | struct radeon_device *rdev = dev->dev_private; | |
45 | unsigned i; | |
46 | ||
47 | /* Disable *all* interrupts */ | |
48 | rdev->irq.sw_int = false; | |
49 | for (i = 0; i < 2; i++) { | |
50 | rdev->irq.crtc_vblank_int[i] = false; | |
51 | } | |
52 | radeon_irq_set(rdev); | |
53 | /* Clear bits */ | |
54 | radeon_irq_process(rdev); | |
55 | } | |
56 | ||
57 | int radeon_driver_irq_postinstall_kms(struct drm_device *dev) | |
58 | { | |
59 | struct radeon_device *rdev = dev->dev_private; | |
60 | ||
61 | dev->max_vblank_count = 0x001fffff; | |
62 | rdev->irq.sw_int = true; | |
63 | radeon_irq_set(rdev); | |
64 | return 0; | |
65 | } | |
66 | ||
67 | void radeon_driver_irq_uninstall_kms(struct drm_device *dev) | |
68 | { | |
69 | struct radeon_device *rdev = dev->dev_private; | |
70 | unsigned i; | |
71 | ||
72 | if (rdev == NULL) { | |
73 | return; | |
74 | } | |
75 | /* Disable *all* interrupts */ | |
76 | rdev->irq.sw_int = false; | |
77 | for (i = 0; i < 2; i++) { | |
78 | rdev->irq.crtc_vblank_int[i] = false; | |
79 | } | |
80 | radeon_irq_set(rdev); | |
81 | } | |
82 | ||
83 | int radeon_irq_kms_init(struct radeon_device *rdev) | |
84 | { | |
85 | int r = 0; | |
dfee5614 | 86 | int num_crtc = 2; |
771fe6b9 | 87 | |
dfee5614 DA |
88 | if (rdev->flags & RADEON_SINGLE_CRTC) |
89 | num_crtc = 1; | |
1614f8b1 | 90 | spin_lock_init(&rdev->irq.sw_lock); |
dfee5614 | 91 | r = drm_vblank_init(rdev->ddev, num_crtc); |
771fe6b9 JG |
92 | if (r) { |
93 | return r; | |
94 | } | |
3e5cb98d AD |
95 | /* enable msi */ |
96 | rdev->msi_enabled = 0; | |
d8f60cfc AD |
97 | /* MSIs don't seem to work on my rs780; |
98 | * not sure about rs880 or other rs780s. | |
99 | * Needs more investigation. | |
100 | */ | |
101 | if ((rdev->family >= CHIP_RV380) && | |
102 | (rdev->family != CHIP_RS780) && | |
103 | (rdev->family != CHIP_RS880)) { | |
3e5cb98d | 104 | int ret = pci_enable_msi(rdev->pdev); |
d8f60cfc | 105 | if (!ret) { |
3e5cb98d | 106 | rdev->msi_enabled = 1; |
d8f60cfc AD |
107 | DRM_INFO("radeon: using MSI.\n"); |
108 | } | |
3e5cb98d | 109 | } |
771fe6b9 JG |
110 | drm_irq_install(rdev->ddev); |
111 | rdev->irq.installed = true; | |
112 | DRM_INFO("radeon: irq initialized.\n"); | |
113 | return 0; | |
114 | } | |
115 | ||
116 | void radeon_irq_kms_fini(struct radeon_device *rdev) | |
117 | { | |
118 | if (rdev->irq.installed) { | |
119 | rdev->irq.installed = false; | |
120 | drm_irq_uninstall(rdev->ddev); | |
3e5cb98d AD |
121 | if (rdev->msi_enabled) |
122 | pci_disable_msi(rdev->pdev); | |
771fe6b9 JG |
123 | } |
124 | } | |
1614f8b1 DA |
125 | |
126 | void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev) | |
127 | { | |
128 | unsigned long irqflags; | |
129 | ||
130 | spin_lock_irqsave(&rdev->irq.sw_lock, irqflags); | |
131 | if (rdev->ddev->irq_enabled && (++rdev->irq.sw_refcount == 1)) { | |
132 | rdev->irq.sw_int = true; | |
133 | radeon_irq_set(rdev); | |
134 | } | |
135 | spin_unlock_irqrestore(&rdev->irq.sw_lock, irqflags); | |
136 | } | |
137 | ||
138 | void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev) | |
139 | { | |
140 | unsigned long irqflags; | |
141 | ||
142 | spin_lock_irqsave(&rdev->irq.sw_lock, irqflags); | |
143 | BUG_ON(rdev->ddev->irq_enabled && rdev->irq.sw_refcount <= 0); | |
144 | if (rdev->ddev->irq_enabled && (--rdev->irq.sw_refcount == 0)) { | |
145 | rdev->irq.sw_int = false; | |
146 | radeon_irq_set(rdev); | |
147 | } | |
148 | spin_unlock_irqrestore(&rdev->irq.sw_lock, irqflags); | |
149 | } | |
150 |