Rev 3764 | Rev 5097 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3764 | Rev 5078 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright 2008 Advanced Micro Devices, Inc. |
2 | * Copyright 2008 Advanced Micro Devices, Inc. |
3 | * Copyright 2008 Red Hat Inc. |
3 | * Copyright 2008 Red Hat Inc. |
4 | * Copyright 2009 Jerome Glisse. |
4 | * Copyright 2009 Jerome Glisse. |
5 | * |
5 | * |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
7 | * copy of this software and associated documentation files (the "Software"), |
7 | * copy of this software and associated documentation files (the "Software"), |
8 | * to deal in the Software without restriction, including without limitation |
8 | * to deal in the Software without restriction, including without limitation |
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
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 |
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: |
11 | * Software is furnished to do so, subject to the following conditions: |
12 | * |
12 | * |
13 | * The above copyright notice and this permission notice shall be included in |
13 | * The above copyright notice and this permission notice shall be included in |
14 | * all copies or substantial portions of the Software. |
14 | * all copies or substantial portions of the Software. |
15 | * |
15 | * |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
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, |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
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 |
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, |
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 |
21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
22 | * OTHER DEALINGS IN THE SOFTWARE. |
22 | * OTHER DEALINGS IN THE SOFTWARE. |
23 | * |
23 | * |
24 | * Authors: Dave Airlie |
24 | * Authors: Dave Airlie |
25 | * Alex Deucher |
25 | * Alex Deucher |
26 | * Jerome Glisse |
26 | * Jerome Glisse |
27 | */ |
27 | */ |
28 | //#include |
28 | //#include |
29 | #include |
29 | #include |
30 | #include |
30 | #include |
31 | #include |
31 | #include |
32 | #include |
32 | #include |
33 | #include "radeon_reg.h" |
33 | #include "radeon_reg.h" |
34 | #include "radeon.h" |
34 | #include "radeon.h" |
35 | #include "atom.h" |
35 | #include "atom.h" |
36 | 36 | ||
37 | #include "bitmap.h" |
37 | #include "bitmap.h" |
38 | #include "display.h" |
38 | #include "display.h" |
39 | 39 | ||
40 | 40 | ||
41 | #include |
41 | #include |
- | 42 | ||
- | 43 | #define PCI_VENDOR_ID_ATI 0x1002 |
|
42 | 44 | #define PCI_VENDOR_ID_APPLE 0x106b |
|
43 | 45 | ||
44 | int radeon_no_wb = 1; |
46 | int radeon_no_wb; |
45 | int radeon_modeset = -1; |
47 | int radeon_modeset = -1; |
46 | int radeon_dynclks = -1; |
48 | int radeon_dynclks = -1; |
47 | int radeon_r4xx_atom = 0; |
49 | int radeon_r4xx_atom = 0; |
48 | int radeon_agpmode = 0; |
50 | int radeon_agpmode = 0; |
49 | int radeon_vram_limit = 0; |
51 | int radeon_vram_limit = 0; |
50 | int radeon_gart_size = 512; /* default gart size */ |
52 | int radeon_gart_size = -1; /* auto */ |
51 | int radeon_benchmarking = 0; |
53 | int radeon_benchmarking = 0; |
52 | int radeon_testing = 0; |
54 | int radeon_testing = 0; |
53 | int radeon_connector_table = 0; |
55 | int radeon_connector_table = 0; |
54 | int radeon_tv = 1; |
56 | int radeon_tv = 1; |
55 | int radeon_new_pll = -1; |
- | |
56 | int radeon_dynpm = -1; |
- | |
57 | int radeon_audio = 1; |
57 | int radeon_audio = -1; |
58 | int radeon_hw_i2c = 0; |
- | |
59 | int radeon_pcie_gen2 = 0; |
- | |
60 | int radeon_disp_priority = 0; |
58 | int radeon_disp_priority = 0; |
- | 59 | int radeon_hw_i2c = 0; |
|
- | 60 | int radeon_pcie_gen2 = -1; |
|
- | 61 | int radeon_msi = -1; |
|
61 | int radeon_lockup_timeout = 10000; |
62 | int radeon_lockup_timeout = 10000; |
62 | int radeon_fastfb = 0; |
63 | int radeon_fastfb = 0; |
- | 64 | int radeon_dpm = -1; |
|
- | 65 | int radeon_aspm = -1; |
|
- | 66 | int radeon_runtime_pm = -1; |
|
- | 67 | int radeon_hard_reset = 0; |
|
- | 68 | int radeon_vm_size = 8; |
|
- | 69 | int radeon_vm_block_size = -1; |
|
63 | - | ||
- | 70 | int radeon_deep_color = 0; |
|
- | 71 | int radeon_use_pflipirq = 2; |
|
64 | int irq_override = 0; |
72 | int irq_override = 0; |
- | 73 | int radeon_bapm = -1; |
|
65 | 74 | ||
66 | 75 | ||
- | 76 | extern display_t *os_display; |
|
67 | extern display_t *rdisplay; |
77 | extern struct drm_device *main_device; |
68 | struct drm_device *main_drm_device; |
78 | extern videomode_t usermode; |
69 | 79 | ||
70 | 80 | ||
71 | void parse_cmdline(char *cmdline, videomode_t *mode, char *log, int *kms); |
81 | void parse_cmdline(char *cmdline, videomode_t *mode, char *log, int *kms); |
72 | int init_display(struct radeon_device *rdev, videomode_t *mode); |
82 | int init_display(struct radeon_device *rdev, videomode_t *mode); |
73 | int init_display_kms(struct radeon_device *rdev, videomode_t *mode); |
83 | int init_display_kms(struct drm_device *dev, videomode_t *usermode); |
74 | 84 | ||
75 | int get_modes(videomode_t *mode, u32_t *count); |
85 | int get_modes(videomode_t *mode, u32_t *count); |
76 | int set_user_mode(videomode_t *mode); |
86 | int set_user_mode(videomode_t *mode); |
77 | int r100_2D_test(struct radeon_device *rdev); |
87 | int r100_2D_test(struct radeon_device *rdev); |
78 | 88 | ||
79 | 89 | ||
80 | /* Legacy VGA regions */ |
90 | /* Legacy VGA regions */ |
81 | #define VGA_RSRC_NONE 0x00 |
91 | #define VGA_RSRC_NONE 0x00 |
82 | #define VGA_RSRC_LEGACY_IO 0x01 |
92 | #define VGA_RSRC_LEGACY_IO 0x01 |
83 | #define VGA_RSRC_LEGACY_MEM 0x02 |
93 | #define VGA_RSRC_LEGACY_MEM 0x02 |
84 | #define VGA_RSRC_LEGACY_MASK (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM) |
94 | #define VGA_RSRC_LEGACY_MASK (VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM) |
85 | /* Non-legacy access */ |
95 | /* Non-legacy access */ |
86 | #define VGA_RSRC_NORMAL_IO 0x04 |
96 | #define VGA_RSRC_NORMAL_IO 0x04 |
87 | #define VGA_RSRC_NORMAL_MEM 0x08 |
97 | #define VGA_RSRC_NORMAL_MEM 0x08 |
88 | 98 | ||
89 | 99 | ||
90 | static const char radeon_family_name[][16] = { |
100 | static const char radeon_family_name[][16] = { |
91 | "R100", |
101 | "R100", |
92 | "RV100", |
102 | "RV100", |
93 | "RS100", |
103 | "RS100", |
94 | "RV200", |
104 | "RV200", |
95 | "RS200", |
105 | "RS200", |
96 | "R200", |
106 | "R200", |
97 | "RV250", |
107 | "RV250", |
98 | "RS300", |
108 | "RS300", |
99 | "RV280", |
109 | "RV280", |
100 | "R300", |
110 | "R300", |
101 | "R350", |
111 | "R350", |
102 | "RV350", |
112 | "RV350", |
103 | "RV380", |
113 | "RV380", |
104 | "R420", |
114 | "R420", |
105 | "R423", |
115 | "R423", |
106 | "RV410", |
116 | "RV410", |
107 | "RS400", |
117 | "RS400", |
108 | "RS480", |
118 | "RS480", |
109 | "RS600", |
119 | "RS600", |
110 | "RS690", |
120 | "RS690", |
111 | "RS740", |
121 | "RS740", |
112 | "RV515", |
122 | "RV515", |
113 | "R520", |
123 | "R520", |
114 | "RV530", |
124 | "RV530", |
115 | "RV560", |
125 | "RV560", |
116 | "RV570", |
126 | "RV570", |
117 | "R580", |
127 | "R580", |
118 | "R600", |
128 | "R600", |
119 | "RV610", |
129 | "RV610", |
120 | "RV630", |
130 | "RV630", |
121 | "RV670", |
131 | "RV670", |
122 | "RV620", |
132 | "RV620", |
123 | "RV635", |
133 | "RV635", |
124 | "RS780", |
134 | "RS780", |
125 | "RS880", |
135 | "RS880", |
126 | "RV770", |
136 | "RV770", |
127 | "RV730", |
137 | "RV730", |
128 | "RV710", |
138 | "RV710", |
129 | "RV740", |
139 | "RV740", |
130 | "CEDAR", |
140 | "CEDAR", |
131 | "REDWOOD", |
141 | "REDWOOD", |
132 | "JUNIPER", |
142 | "JUNIPER", |
133 | "CYPRESS", |
143 | "CYPRESS", |
134 | "HEMLOCK", |
144 | "HEMLOCK", |
135 | "PALM", |
145 | "PALM", |
136 | "SUMO", |
146 | "SUMO", |
137 | "SUMO2", |
147 | "SUMO2", |
138 | "BARTS", |
148 | "BARTS", |
139 | "TURKS", |
149 | "TURKS", |
140 | "CAICOS", |
150 | "CAICOS", |
141 | "CAYMAN", |
151 | "CAYMAN", |
142 | "ARUBA", |
152 | "ARUBA", |
143 | "TAHITI", |
153 | "TAHITI", |
144 | "PITCAIRN", |
154 | "PITCAIRN", |
145 | "VERDE", |
155 | "VERDE", |
146 | "OLAND", |
156 | "OLAND", |
147 | "HAINAN", |
157 | "HAINAN", |
- | 158 | "BONAIRE", |
|
- | 159 | "KAVERI", |
|
- | 160 | "KABINI", |
|
- | 161 | "HAWAII", |
|
- | 162 | "MULLINS", |
|
148 | "LAST", |
163 | "LAST", |
149 | }; |
164 | }; |
- | 165 | ||
- | 166 | #define RADEON_PX_QUIRK_DISABLE_PX (1 << 0) |
|
- | 167 | #define RADEON_PX_QUIRK_LONG_WAKEUP (1 << 1) |
|
- | 168 | ||
- | 169 | struct radeon_px_quirk { |
|
- | 170 | u32 chip_vendor; |
|
- | 171 | u32 chip_device; |
|
- | 172 | u32 subsys_vendor; |
|
- | 173 | u32 subsys_device; |
|
- | 174 | u32 px_quirk_flags; |
|
- | 175 | }; |
|
- | 176 | ||
- | 177 | static struct radeon_px_quirk radeon_px_quirk_list[] = { |
|
- | 178 | /* Acer aspire 5560g (CPU: AMD A4-3305M; GPU: AMD Radeon HD 6480g + 7470m) |
|
- | 179 | * https://bugzilla.kernel.org/show_bug.cgi?id=74551 |
|
- | 180 | */ |
|
- | 181 | { PCI_VENDOR_ID_ATI, 0x6760, 0x1025, 0x0672, RADEON_PX_QUIRK_DISABLE_PX }, |
|
- | 182 | /* Asus K73TA laptop with AMD A6-3400M APU and Radeon 6550 GPU |
|
- | 183 | * https://bugzilla.kernel.org/show_bug.cgi?id=51381 |
|
- | 184 | */ |
|
- | 185 | { PCI_VENDOR_ID_ATI, 0x6741, 0x1043, 0x108c, RADEON_PX_QUIRK_DISABLE_PX }, |
|
- | 186 | /* macbook pro 8.2 */ |
|
- | 187 | { PCI_VENDOR_ID_ATI, 0x6741, PCI_VENDOR_ID_APPLE, 0x00e2, RADEON_PX_QUIRK_LONG_WAKEUP }, |
|
- | 188 | { 0, 0, 0, 0, 0 }, |
|
- | 189 | }; |
|
- | 190 | ||
- | 191 | bool radeon_is_px(struct drm_device *dev) |
|
- | 192 | { |
|
- | 193 | struct radeon_device *rdev = dev->dev_private; |
|
- | 194 | ||
- | 195 | if (rdev->flags & RADEON_IS_PX) |
|
- | 196 | return true; |
|
- | 197 | return false; |
|
- | 198 | } |
|
- | 199 | ||
- | 200 | static void radeon_device_handle_px_quirks(struct radeon_device *rdev) |
|
- | 201 | { |
|
- | 202 | struct radeon_px_quirk *p = radeon_px_quirk_list; |
|
- | 203 | ||
- | 204 | /* Apply PX quirks */ |
|
- | 205 | while (p && p->chip_device != 0) { |
|
- | 206 | if (rdev->pdev->vendor == p->chip_vendor && |
|
- | 207 | rdev->pdev->device == p->chip_device && |
|
- | 208 | rdev->pdev->subsystem_vendor == p->subsys_vendor && |
|
- | 209 | rdev->pdev->subsystem_device == p->subsys_device) { |
|
- | 210 | rdev->px_quirk_flags = p->px_quirk_flags; |
|
- | 211 | break; |
|
- | 212 | } |
|
- | 213 | ++p; |
|
- | 214 | } |
|
- | 215 | ||
- | 216 | if (rdev->px_quirk_flags & RADEON_PX_QUIRK_DISABLE_PX) |
|
- | 217 | rdev->flags &= ~RADEON_IS_PX; |
|
- | 218 | } |
|
150 | 219 | ||
151 | /** |
220 | /** |
152 | * radeon_program_register_sequence - program an array of registers. |
221 | * radeon_program_register_sequence - program an array of registers. |
153 | * |
222 | * |
154 | * @rdev: radeon_device pointer |
223 | * @rdev: radeon_device pointer |
155 | * @registers: pointer to the register array |
224 | * @registers: pointer to the register array |
156 | * @array_size: size of the register array |
225 | * @array_size: size of the register array |
157 | * |
226 | * |
158 | * Programs an array or registers with and and or masks. |
227 | * Programs an array or registers with and and or masks. |
159 | * This is a helper for setting golden registers. |
228 | * This is a helper for setting golden registers. |
160 | */ |
229 | */ |
161 | void radeon_program_register_sequence(struct radeon_device *rdev, |
230 | void radeon_program_register_sequence(struct radeon_device *rdev, |
162 | const u32 *registers, |
231 | const u32 *registers, |
163 | const u32 array_size) |
232 | const u32 array_size) |
164 | { |
233 | { |
165 | u32 tmp, reg, and_mask, or_mask; |
234 | u32 tmp, reg, and_mask, or_mask; |
166 | int i; |
235 | int i; |
167 | 236 | ||
168 | if (array_size % 3) |
237 | if (array_size % 3) |
169 | return; |
238 | return; |
170 | 239 | ||
171 | for (i = 0; i < array_size; i +=3) { |
240 | for (i = 0; i < array_size; i +=3) { |
172 | reg = registers[i + 0]; |
241 | reg = registers[i + 0]; |
173 | and_mask = registers[i + 1]; |
242 | and_mask = registers[i + 1]; |
174 | or_mask = registers[i + 2]; |
243 | or_mask = registers[i + 2]; |
175 | 244 | ||
176 | if (and_mask == 0xffffffff) { |
245 | if (and_mask == 0xffffffff) { |
177 | tmp = or_mask; |
246 | tmp = or_mask; |
178 | } else { |
247 | } else { |
179 | tmp = RREG32(reg); |
248 | tmp = RREG32(reg); |
180 | tmp &= ~and_mask; |
249 | tmp &= ~and_mask; |
181 | tmp |= or_mask; |
250 | tmp |= or_mask; |
182 | } |
251 | } |
183 | WREG32(reg, tmp); |
252 | WREG32(reg, tmp); |
184 | } |
253 | } |
185 | } |
254 | } |
- | 255 | ||
- | 256 | void radeon_pci_config_reset(struct radeon_device *rdev) |
|
- | 257 | { |
|
- | 258 | pci_write_config_dword(rdev->pdev, 0x7c, RADEON_ASIC_RESET_DATA); |
|
- | 259 | } |
|
186 | 260 | ||
187 | /** |
261 | /** |
188 | * radeon_surface_init - Clear GPU surface registers. |
262 | * radeon_surface_init - Clear GPU surface registers. |
189 | * |
263 | * |
190 | * @rdev: radeon_device pointer |
264 | * @rdev: radeon_device pointer |
191 | * |
265 | * |
192 | * Clear GPU surface registers (r1xx-r5xx). |
266 | * Clear GPU surface registers (r1xx-r5xx). |
193 | */ |
267 | */ |
194 | void radeon_surface_init(struct radeon_device *rdev) |
268 | void radeon_surface_init(struct radeon_device *rdev) |
195 | { |
269 | { |
196 | /* FIXME: check this out */ |
270 | /* FIXME: check this out */ |
197 | if (rdev->family < CHIP_R600) { |
271 | if (rdev->family < CHIP_R600) { |
198 | int i; |
272 | int i; |
199 | 273 | ||
200 | for (i = 0; i < RADEON_GEM_MAX_SURFACES; i++) { |
274 | for (i = 0; i < RADEON_GEM_MAX_SURFACES; i++) { |
- | 275 | if (rdev->surface_regs[i].bo) |
|
- | 276 | radeon_bo_get_surface_reg(rdev->surface_regs[i].bo); |
|
- | 277 | else |
|
201 | radeon_clear_surface_reg(rdev, i); |
278 | radeon_clear_surface_reg(rdev, i); |
202 | } |
279 | } |
203 | /* enable surfaces */ |
280 | /* enable surfaces */ |
204 | WREG32(RADEON_SURFACE_CNTL, 0); |
281 | WREG32(RADEON_SURFACE_CNTL, 0); |
205 | } |
282 | } |
206 | } |
283 | } |
207 | 284 | ||
208 | /* |
285 | /* |
209 | * GPU scratch registers helpers function. |
286 | * GPU scratch registers helpers function. |
210 | */ |
287 | */ |
211 | /** |
288 | /** |
212 | * radeon_scratch_init - Init scratch register driver information. |
289 | * radeon_scratch_init - Init scratch register driver information. |
213 | * |
290 | * |
214 | * @rdev: radeon_device pointer |
291 | * @rdev: radeon_device pointer |
215 | * |
292 | * |
216 | * Init CP scratch register driver information (r1xx-r5xx) |
293 | * Init CP scratch register driver information (r1xx-r5xx) |
217 | */ |
294 | */ |
218 | void radeon_scratch_init(struct radeon_device *rdev) |
295 | void radeon_scratch_init(struct radeon_device *rdev) |
219 | { |
296 | { |
220 | int i; |
297 | int i; |
221 | 298 | ||
222 | /* FIXME: check this out */ |
299 | /* FIXME: check this out */ |
223 | if (rdev->family < CHIP_R300) { |
300 | if (rdev->family < CHIP_R300) { |
224 | rdev->scratch.num_reg = 5; |
301 | rdev->scratch.num_reg = 5; |
225 | } else { |
302 | } else { |
226 | rdev->scratch.num_reg = 7; |
303 | rdev->scratch.num_reg = 7; |
227 | } |
304 | } |
228 | rdev->scratch.reg_base = RADEON_SCRATCH_REG0; |
305 | rdev->scratch.reg_base = RADEON_SCRATCH_REG0; |
229 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
306 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
230 | rdev->scratch.free[i] = true; |
307 | rdev->scratch.free[i] = true; |
231 | rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4); |
308 | rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4); |
232 | } |
309 | } |
233 | } |
310 | } |
234 | 311 | ||
235 | /** |
312 | /** |
236 | * radeon_scratch_get - Allocate a scratch register |
313 | * radeon_scratch_get - Allocate a scratch register |
237 | * |
314 | * |
238 | * @rdev: radeon_device pointer |
315 | * @rdev: radeon_device pointer |
239 | * @reg: scratch register mmio offset |
316 | * @reg: scratch register mmio offset |
240 | * |
317 | * |
241 | * Allocate a CP scratch register for use by the driver (all asics). |
318 | * Allocate a CP scratch register for use by the driver (all asics). |
242 | * Returns 0 on success or -EINVAL on failure. |
319 | * Returns 0 on success or -EINVAL on failure. |
243 | */ |
320 | */ |
244 | int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg) |
321 | int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg) |
245 | { |
322 | { |
246 | int i; |
323 | int i; |
247 | 324 | ||
248 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
325 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
249 | if (rdev->scratch.free[i]) { |
326 | if (rdev->scratch.free[i]) { |
250 | rdev->scratch.free[i] = false; |
327 | rdev->scratch.free[i] = false; |
251 | *reg = rdev->scratch.reg[i]; |
328 | *reg = rdev->scratch.reg[i]; |
252 | return 0; |
329 | return 0; |
253 | } |
330 | } |
254 | } |
331 | } |
255 | return -EINVAL; |
332 | return -EINVAL; |
256 | } |
333 | } |
257 | 334 | ||
258 | /** |
335 | /** |
259 | * radeon_scratch_free - Free a scratch register |
336 | * radeon_scratch_free - Free a scratch register |
260 | * |
337 | * |
261 | * @rdev: radeon_device pointer |
338 | * @rdev: radeon_device pointer |
262 | * @reg: scratch register mmio offset |
339 | * @reg: scratch register mmio offset |
263 | * |
340 | * |
264 | * Free a CP scratch register allocated for use by the driver (all asics) |
341 | * Free a CP scratch register allocated for use by the driver (all asics) |
265 | */ |
342 | */ |
266 | void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg) |
343 | void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg) |
267 | { |
344 | { |
268 | int i; |
345 | int i; |
269 | 346 | ||
270 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
347 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
271 | if (rdev->scratch.reg[i] == reg) { |
348 | if (rdev->scratch.reg[i] == reg) { |
272 | rdev->scratch.free[i] = true; |
349 | rdev->scratch.free[i] = true; |
273 | return; |
350 | return; |
274 | } |
351 | } |
275 | } |
352 | } |
276 | } |
353 | } |
277 | 354 | ||
278 | /* |
355 | /* |
- | 356 | * GPU doorbell aperture helpers function. |
|
- | 357 | */ |
|
- | 358 | /** |
|
- | 359 | * radeon_doorbell_init - Init doorbell driver information. |
|
- | 360 | * |
|
- | 361 | * @rdev: radeon_device pointer |
|
- | 362 | * |
|
- | 363 | * Init doorbell driver information (CIK) |
|
- | 364 | * Returns 0 on success, error on failure. |
|
- | 365 | */ |
|
- | 366 | static int radeon_doorbell_init(struct radeon_device *rdev) |
|
- | 367 | { |
|
- | 368 | /* doorbell bar mapping */ |
|
- | 369 | rdev->doorbell.base = pci_resource_start(rdev->pdev, 2); |
|
- | 370 | rdev->doorbell.size = pci_resource_len(rdev->pdev, 2); |
|
- | 371 | ||
- | 372 | rdev->doorbell.num_doorbells = min_t(u32, rdev->doorbell.size / sizeof(u32), RADEON_MAX_DOORBELLS); |
|
- | 373 | if (rdev->doorbell.num_doorbells == 0) |
|
- | 374 | return -EINVAL; |
|
- | 375 | ||
- | 376 | rdev->doorbell.ptr = ioremap(rdev->doorbell.base, rdev->doorbell.num_doorbells * sizeof(u32)); |
|
- | 377 | if (rdev->doorbell.ptr == NULL) { |
|
- | 378 | return -ENOMEM; |
|
- | 379 | } |
|
- | 380 | DRM_INFO("doorbell mmio base: 0x%08X\n", (uint32_t)rdev->doorbell.base); |
|
- | 381 | DRM_INFO("doorbell mmio size: %u\n", (unsigned)rdev->doorbell.size); |
|
- | 382 | ||
- | 383 | memset(&rdev->doorbell.used, 0, sizeof(rdev->doorbell.used)); |
|
- | 384 | ||
- | 385 | return 0; |
|
- | 386 | } |
|
- | 387 | ||
- | 388 | /** |
|
- | 389 | * radeon_doorbell_fini - Tear down doorbell driver information. |
|
- | 390 | * |
|
- | 391 | * @rdev: radeon_device pointer |
|
- | 392 | * |
|
- | 393 | * Tear down doorbell driver information (CIK) |
|
- | 394 | */ |
|
- | 395 | static void radeon_doorbell_fini(struct radeon_device *rdev) |
|
- | 396 | { |
|
- | 397 | iounmap(rdev->doorbell.ptr); |
|
- | 398 | rdev->doorbell.ptr = NULL; |
|
- | 399 | } |
|
- | 400 | ||
- | 401 | /** |
|
- | 402 | * radeon_doorbell_get - Allocate a doorbell entry |
|
- | 403 | * |
|
- | 404 | * @rdev: radeon_device pointer |
|
- | 405 | * @doorbell: doorbell index |
|
- | 406 | * |
|
- | 407 | * Allocate a doorbell for use by the driver (all asics). |
|
- | 408 | * Returns 0 on success or -EINVAL on failure. |
|
- | 409 | */ |
|
- | 410 | int radeon_doorbell_get(struct radeon_device *rdev, u32 *doorbell) |
|
- | 411 | { |
|
- | 412 | unsigned long offset = find_first_zero_bit(rdev->doorbell.used, rdev->doorbell.num_doorbells); |
|
- | 413 | if (offset < rdev->doorbell.num_doorbells) { |
|
- | 414 | __set_bit(offset, rdev->doorbell.used); |
|
- | 415 | *doorbell = offset; |
|
- | 416 | return 0; |
|
- | 417 | } else { |
|
- | 418 | return -EINVAL; |
|
- | 419 | } |
|
- | 420 | } |
|
- | 421 | ||
- | 422 | /** |
|
- | 423 | * radeon_doorbell_free - Free a doorbell entry |
|
- | 424 | * |
|
- | 425 | * @rdev: radeon_device pointer |
|
- | 426 | * @doorbell: doorbell index |
|
- | 427 | * |
|
- | 428 | * Free a doorbell allocated for use by the driver (all asics) |
|
- | 429 | */ |
|
- | 430 | void radeon_doorbell_free(struct radeon_device *rdev, u32 doorbell) |
|
- | 431 | { |
|
- | 432 | if (doorbell < rdev->doorbell.num_doorbells) |
|
- | 433 | __clear_bit(doorbell, rdev->doorbell.used); |
|
- | 434 | } |
|
- | 435 | ||
- | 436 | /* |
|
279 | * radeon_wb_*() |
437 | * radeon_wb_*() |
280 | * Writeback is the the method by which the the GPU updates special pages |
438 | * Writeback is the the method by which the the GPU updates special pages |
281 | * in memory with the status of certain GPU events (fences, ring pointers, |
439 | * in memory with the status of certain GPU events (fences, ring pointers, |
282 | * etc.). |
440 | * etc.). |
283 | */ |
441 | */ |
284 | 442 | ||
285 | /** |
443 | /** |
286 | * radeon_wb_disable - Disable Writeback |
444 | * radeon_wb_disable - Disable Writeback |
287 | * |
445 | * |
288 | * @rdev: radeon_device pointer |
446 | * @rdev: radeon_device pointer |
289 | * |
447 | * |
290 | * Disables Writeback (all asics). Used for suspend. |
448 | * Disables Writeback (all asics). Used for suspend. |
291 | */ |
449 | */ |
292 | void radeon_wb_disable(struct radeon_device *rdev) |
450 | void radeon_wb_disable(struct radeon_device *rdev) |
293 | { |
451 | { |
294 | rdev->wb.enabled = false; |
452 | rdev->wb.enabled = false; |
295 | } |
453 | } |
296 | 454 | ||
297 | /** |
455 | /** |
298 | * radeon_wb_fini - Disable Writeback and free memory |
456 | * radeon_wb_fini - Disable Writeback and free memory |
299 | * |
457 | * |
300 | * @rdev: radeon_device pointer |
458 | * @rdev: radeon_device pointer |
301 | * |
459 | * |
302 | * Disables Writeback and frees the Writeback memory (all asics). |
460 | * Disables Writeback and frees the Writeback memory (all asics). |
303 | * Used at driver shutdown. |
461 | * Used at driver shutdown. |
304 | */ |
462 | */ |
305 | void radeon_wb_fini(struct radeon_device *rdev) |
463 | void radeon_wb_fini(struct radeon_device *rdev) |
306 | { |
464 | { |
307 | radeon_wb_disable(rdev); |
465 | radeon_wb_disable(rdev); |
308 | if (rdev->wb.wb_obj) { |
466 | if (rdev->wb.wb_obj) { |
- | 467 | if (!radeon_bo_reserve(rdev->wb.wb_obj, false)) { |
|
- | 468 | radeon_bo_kunmap(rdev->wb.wb_obj); |
|
- | 469 | radeon_bo_unpin(rdev->wb.wb_obj); |
|
- | 470 | radeon_bo_unreserve(rdev->wb.wb_obj); |
|
- | 471 | } |
|
309 | radeon_bo_unref(&rdev->wb.wb_obj); |
472 | radeon_bo_unref(&rdev->wb.wb_obj); |
310 | rdev->wb.wb = NULL; |
473 | rdev->wb.wb = NULL; |
311 | rdev->wb.wb_obj = NULL; |
474 | rdev->wb.wb_obj = NULL; |
312 | } |
475 | } |
313 | } |
476 | } |
314 | 477 | ||
315 | /** |
478 | /** |
316 | * radeon_wb_init- Init Writeback driver info and allocate memory |
479 | * radeon_wb_init- Init Writeback driver info and allocate memory |
317 | * |
480 | * |
318 | * @rdev: radeon_device pointer |
481 | * @rdev: radeon_device pointer |
319 | * |
482 | * |
320 | * Disables Writeback and frees the Writeback memory (all asics). |
483 | * Disables Writeback and frees the Writeback memory (all asics). |
321 | * Used at driver startup. |
484 | * Used at driver startup. |
322 | * Returns 0 on success or an -error on failure. |
485 | * Returns 0 on success or an -error on failure. |
323 | */ |
486 | */ |
324 | int radeon_wb_init(struct radeon_device *rdev) |
487 | int radeon_wb_init(struct radeon_device *rdev) |
325 | { |
488 | { |
326 | int r; |
489 | int r; |
327 | 490 | ||
328 | if (rdev->wb.wb_obj == NULL) { |
491 | if (rdev->wb.wb_obj == NULL) { |
329 | r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true, |
492 | r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true, |
330 | RADEON_GEM_DOMAIN_GTT, NULL, &rdev->wb.wb_obj); |
493 | RADEON_GEM_DOMAIN_GTT, 0, NULL, |
- | 494 | &rdev->wb.wb_obj); |
|
331 | if (r) { |
495 | if (r) { |
332 | dev_warn(rdev->dev, "(%d) create WB bo failed\n", r); |
496 | dev_warn(rdev->dev, "(%d) create WB bo failed\n", r); |
333 | return r; |
497 | return r; |
334 | } |
498 | } |
335 | r = radeon_bo_reserve(rdev->wb.wb_obj, false); |
499 | r = radeon_bo_reserve(rdev->wb.wb_obj, false); |
336 | if (unlikely(r != 0)) { |
500 | if (unlikely(r != 0)) { |
337 | radeon_wb_fini(rdev); |
501 | radeon_wb_fini(rdev); |
338 | return r; |
502 | return r; |
339 | } |
503 | } |
340 | r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT, |
504 | r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT, |
341 | &rdev->wb.gpu_addr); |
505 | &rdev->wb.gpu_addr); |
342 | if (r) { |
506 | if (r) { |
343 | radeon_bo_unreserve(rdev->wb.wb_obj); |
507 | radeon_bo_unreserve(rdev->wb.wb_obj); |
344 | dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r); |
508 | dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r); |
345 | radeon_wb_fini(rdev); |
509 | radeon_wb_fini(rdev); |
346 | return r; |
510 | return r; |
347 | } |
511 | } |
348 | r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb); |
512 | r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb); |
349 | radeon_bo_unreserve(rdev->wb.wb_obj); |
513 | radeon_bo_unreserve(rdev->wb.wb_obj); |
350 | if (r) { |
514 | if (r) { |
351 | dev_warn(rdev->dev, "(%d) map WB bo failed\n", r); |
515 | dev_warn(rdev->dev, "(%d) map WB bo failed\n", r); |
352 | radeon_wb_fini(rdev); |
516 | radeon_wb_fini(rdev); |
353 | return r; |
517 | return r; |
354 | } |
518 | } |
355 | } |
519 | } |
356 | 520 | ||
357 | /* clear wb memory */ |
521 | /* clear wb memory */ |
358 | memset((char *)rdev->wb.wb, 0, RADEON_GPU_PAGE_SIZE); |
522 | memset((char *)rdev->wb.wb, 0, RADEON_GPU_PAGE_SIZE); |
359 | /* disable event_write fences */ |
523 | /* disable event_write fences */ |
360 | rdev->wb.use_event = false; |
524 | rdev->wb.use_event = false; |
361 | /* disabled via module param */ |
525 | /* disabled via module param */ |
362 | if (radeon_no_wb == 1) { |
526 | if (radeon_no_wb == 1) { |
363 | rdev->wb.enabled = false; |
527 | rdev->wb.enabled = false; |
364 | } else { |
528 | } else { |
365 | if (rdev->flags & RADEON_IS_AGP) { |
529 | if (rdev->flags & RADEON_IS_AGP) { |
366 | /* often unreliable on AGP */ |
530 | /* often unreliable on AGP */ |
367 | rdev->wb.enabled = false; |
531 | rdev->wb.enabled = false; |
368 | } else if (rdev->family < CHIP_R300) { |
532 | } else if (rdev->family < CHIP_R300) { |
369 | /* often unreliable on pre-r300 */ |
533 | /* often unreliable on pre-r300 */ |
370 | rdev->wb.enabled = false; |
534 | rdev->wb.enabled = false; |
371 | } else { |
535 | } else { |
372 | rdev->wb.enabled = true; |
536 | rdev->wb.enabled = true; |
373 | /* event_write fences are only available on r600+ */ |
537 | /* event_write fences are only available on r600+ */ |
374 | if (rdev->family >= CHIP_R600) { |
538 | if (rdev->family >= CHIP_R600) { |
375 | rdev->wb.use_event = true; |
539 | rdev->wb.use_event = true; |
376 | } |
540 | } |
377 | } |
541 | } |
378 | } |
542 | } |
379 | /* always use writeback/events on NI, APUs */ |
543 | /* always use writeback/events on NI, APUs */ |
380 | if (rdev->family >= CHIP_PALM) { |
544 | if (rdev->family >= CHIP_PALM) { |
381 | rdev->wb.enabled = true; |
545 | rdev->wb.enabled = true; |
382 | rdev->wb.use_event = true; |
546 | rdev->wb.use_event = true; |
383 | } |
547 | } |
384 | 548 | ||
385 | dev_info(rdev->dev, "WB %sabled\n", rdev->wb.enabled ? "en" : "dis"); |
549 | dev_info(rdev->dev, "WB %sabled\n", rdev->wb.enabled ? "en" : "dis"); |
386 | 550 | ||
387 | return 0; |
551 | return 0; |
388 | } |
552 | } |
389 | 553 | ||
390 | /** |
554 | /** |
391 | * radeon_vram_location - try to find VRAM location |
555 | * radeon_vram_location - try to find VRAM location |
392 | * @rdev: radeon device structure holding all necessary informations |
556 | * @rdev: radeon device structure holding all necessary informations |
393 | * @mc: memory controller structure holding memory informations |
557 | * @mc: memory controller structure holding memory informations |
394 | * @base: base address at which to put VRAM |
558 | * @base: base address at which to put VRAM |
395 | * |
559 | * |
396 | * Function will place try to place VRAM at base address provided |
560 | * Function will place try to place VRAM at base address provided |
397 | * as parameter (which is so far either PCI aperture address or |
561 | * as parameter (which is so far either PCI aperture address or |
398 | * for IGP TOM base address). |
562 | * for IGP TOM base address). |
399 | * |
563 | * |
400 | * If there is not enough space to fit the unvisible VRAM in the 32bits |
564 | * If there is not enough space to fit the unvisible VRAM in the 32bits |
401 | * address space then we limit the VRAM size to the aperture. |
565 | * address space then we limit the VRAM size to the aperture. |
402 | * |
566 | * |
403 | * If we are using AGP and if the AGP aperture doesn't allow us to have |
567 | * If we are using AGP and if the AGP aperture doesn't allow us to have |
404 | * room for all the VRAM than we restrict the VRAM to the PCI aperture |
568 | * room for all the VRAM than we restrict the VRAM to the PCI aperture |
405 | * size and print a warning. |
569 | * size and print a warning. |
406 | * |
570 | * |
407 | * This function will never fails, worst case are limiting VRAM. |
571 | * This function will never fails, worst case are limiting VRAM. |
408 | * |
572 | * |
409 | * Note: GTT start, end, size should be initialized before calling this |
573 | * Note: GTT start, end, size should be initialized before calling this |
410 | * function on AGP platform. |
574 | * function on AGP platform. |
411 | * |
575 | * |
412 | * Note: We don't explicitly enforce VRAM start to be aligned on VRAM size, |
576 | * Note: We don't explicitly enforce VRAM start to be aligned on VRAM size, |
413 | * this shouldn't be a problem as we are using the PCI aperture as a reference. |
577 | * this shouldn't be a problem as we are using the PCI aperture as a reference. |
414 | * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but |
578 | * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but |
415 | * not IGP. |
579 | * not IGP. |
416 | * |
580 | * |
417 | * Note: we use mc_vram_size as on some board we need to program the mc to |
581 | * Note: we use mc_vram_size as on some board we need to program the mc to |
418 | * cover the whole aperture even if VRAM size is inferior to aperture size |
582 | * cover the whole aperture even if VRAM size is inferior to aperture size |
419 | * Novell bug 204882 + along with lots of ubuntu ones |
583 | * Novell bug 204882 + along with lots of ubuntu ones |
420 | * |
584 | * |
421 | * Note: when limiting vram it's safe to overwritte real_vram_size because |
585 | * Note: when limiting vram it's safe to overwritte real_vram_size because |
422 | * we are not in case where real_vram_size is inferior to mc_vram_size (ie |
586 | * we are not in case where real_vram_size is inferior to mc_vram_size (ie |
423 | * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu |
587 | * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu |
424 | * ones) |
588 | * ones) |
425 | * |
589 | * |
426 | * Note: IGP TOM addr should be the same as the aperture addr, we don't |
590 | * Note: IGP TOM addr should be the same as the aperture addr, we don't |
427 | * explicitly check for that thought. |
591 | * explicitly check for that thought. |
428 | * |
592 | * |
429 | * FIXME: when reducing VRAM size align new size on power of 2. |
593 | * FIXME: when reducing VRAM size align new size on power of 2. |
430 | */ |
594 | */ |
431 | void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base) |
595 | void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base) |
432 | { |
596 | { |
433 | uint64_t limit = (uint64_t)radeon_vram_limit << 20; |
597 | uint64_t limit = (uint64_t)radeon_vram_limit << 20; |
434 | 598 | ||
435 | mc->vram_start = base; |
599 | mc->vram_start = base; |
436 | if (mc->mc_vram_size > (rdev->mc.mc_mask - base + 1)) { |
600 | if (mc->mc_vram_size > (rdev->mc.mc_mask - base + 1)) { |
437 | dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n"); |
601 | dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n"); |
438 | mc->real_vram_size = mc->aper_size; |
602 | mc->real_vram_size = mc->aper_size; |
439 | mc->mc_vram_size = mc->aper_size; |
603 | mc->mc_vram_size = mc->aper_size; |
440 | } |
604 | } |
441 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
605 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
442 | if (rdev->flags & RADEON_IS_AGP && mc->vram_end > mc->gtt_start && mc->vram_start <= mc->gtt_end) { |
606 | if (rdev->flags & RADEON_IS_AGP && mc->vram_end > mc->gtt_start && mc->vram_start <= mc->gtt_end) { |
443 | dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n"); |
607 | dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n"); |
444 | mc->real_vram_size = mc->aper_size; |
608 | mc->real_vram_size = mc->aper_size; |
445 | mc->mc_vram_size = mc->aper_size; |
609 | mc->mc_vram_size = mc->aper_size; |
446 | } |
610 | } |
447 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
611 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
448 | if (limit && limit < mc->real_vram_size) |
612 | if (limit && limit < mc->real_vram_size) |
449 | mc->real_vram_size = limit; |
613 | mc->real_vram_size = limit; |
450 | dev_info(rdev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n", |
614 | dev_info(rdev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n", |
451 | mc->mc_vram_size >> 20, mc->vram_start, |
615 | mc->mc_vram_size >> 20, mc->vram_start, |
452 | mc->vram_end, mc->real_vram_size >> 20); |
616 | mc->vram_end, mc->real_vram_size >> 20); |
453 | } |
617 | } |
454 | 618 | ||
455 | /** |
619 | /** |
456 | * radeon_gtt_location - try to find GTT location |
620 | * radeon_gtt_location - try to find GTT location |
457 | * @rdev: radeon device structure holding all necessary informations |
621 | * @rdev: radeon device structure holding all necessary informations |
458 | * @mc: memory controller structure holding memory informations |
622 | * @mc: memory controller structure holding memory informations |
459 | * |
623 | * |
460 | * Function will place try to place GTT before or after VRAM. |
624 | * Function will place try to place GTT before or after VRAM. |
461 | * |
625 | * |
462 | * If GTT size is bigger than space left then we ajust GTT size. |
626 | * If GTT size is bigger than space left then we ajust GTT size. |
463 | * Thus function will never fails. |
627 | * Thus function will never fails. |
464 | * |
628 | * |
465 | * FIXME: when reducing GTT size align new size on power of 2. |
629 | * FIXME: when reducing GTT size align new size on power of 2. |
466 | */ |
630 | */ |
467 | void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc) |
631 | void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc) |
468 | { |
632 | { |
469 | u64 size_af, size_bf; |
633 | u64 size_af, size_bf; |
470 | 634 | ||
471 | size_af = ((rdev->mc.mc_mask - mc->vram_end) + mc->gtt_base_align) & ~mc->gtt_base_align; |
635 | size_af = ((rdev->mc.mc_mask - mc->vram_end) + mc->gtt_base_align) & ~mc->gtt_base_align; |
472 | size_bf = mc->vram_start & ~mc->gtt_base_align; |
636 | size_bf = mc->vram_start & ~mc->gtt_base_align; |
473 | if (size_bf > size_af) { |
637 | if (size_bf > size_af) { |
474 | if (mc->gtt_size > size_bf) { |
638 | if (mc->gtt_size > size_bf) { |
475 | dev_warn(rdev->dev, "limiting GTT\n"); |
639 | dev_warn(rdev->dev, "limiting GTT\n"); |
476 | mc->gtt_size = size_bf; |
640 | mc->gtt_size = size_bf; |
477 | } |
641 | } |
478 | mc->gtt_start = (mc->vram_start & ~mc->gtt_base_align) - mc->gtt_size; |
642 | mc->gtt_start = (mc->vram_start & ~mc->gtt_base_align) - mc->gtt_size; |
479 | } else { |
643 | } else { |
480 | if (mc->gtt_size > size_af) { |
644 | if (mc->gtt_size > size_af) { |
481 | dev_warn(rdev->dev, "limiting GTT\n"); |
645 | dev_warn(rdev->dev, "limiting GTT\n"); |
482 | mc->gtt_size = size_af; |
646 | mc->gtt_size = size_af; |
483 | } |
647 | } |
484 | mc->gtt_start = (mc->vram_end + 1 + mc->gtt_base_align) & ~mc->gtt_base_align; |
648 | mc->gtt_start = (mc->vram_end + 1 + mc->gtt_base_align) & ~mc->gtt_base_align; |
485 | } |
649 | } |
486 | mc->gtt_end = mc->gtt_start + mc->gtt_size - 1; |
650 | mc->gtt_end = mc->gtt_start + mc->gtt_size - 1; |
487 | dev_info(rdev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n", |
651 | dev_info(rdev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n", |
488 | mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end); |
652 | mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end); |
489 | } |
653 | } |
490 | 654 | ||
491 | /* |
655 | /* |
492 | * GPU helpers function. |
656 | * GPU helpers function. |
493 | */ |
657 | */ |
494 | /** |
658 | /** |
495 | * radeon_card_posted - check if the hw has already been initialized |
659 | * radeon_card_posted - check if the hw has already been initialized |
496 | * |
660 | * |
497 | * @rdev: radeon_device pointer |
661 | * @rdev: radeon_device pointer |
498 | * |
662 | * |
499 | * Check if the asic has been initialized (all asics). |
663 | * Check if the asic has been initialized (all asics). |
500 | * Used at driver startup. |
664 | * Used at driver startup. |
501 | * Returns true if initialized or false if not. |
665 | * Returns true if initialized or false if not. |
502 | */ |
666 | */ |
503 | bool radeon_card_posted(struct radeon_device *rdev) |
667 | bool radeon_card_posted(struct radeon_device *rdev) |
504 | { |
668 | { |
505 | uint32_t reg; |
669 | uint32_t reg; |
506 | 670 | ||
507 | if (ASIC_IS_NODCE(rdev)) |
671 | if (ASIC_IS_NODCE(rdev)) |
508 | goto check_memsize; |
672 | goto check_memsize; |
509 | 673 | ||
510 | /* first check CRTCs */ |
674 | /* first check CRTCs */ |
511 | if (ASIC_IS_DCE4(rdev)) { |
675 | if (ASIC_IS_DCE4(rdev)) { |
512 | reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) | |
676 | reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) | |
513 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET); |
677 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET); |
514 | if (rdev->num_crtc >= 4) { |
678 | if (rdev->num_crtc >= 4) { |
515 | reg |= RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) | |
679 | reg |= RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) | |
516 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET); |
680 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET); |
517 | } |
681 | } |
518 | if (rdev->num_crtc >= 6) { |
682 | if (rdev->num_crtc >= 6) { |
519 | reg |= RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) | |
683 | reg |= RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) | |
520 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET); |
684 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET); |
521 | } |
685 | } |
522 | if (reg & EVERGREEN_CRTC_MASTER_EN) |
686 | if (reg & EVERGREEN_CRTC_MASTER_EN) |
523 | return true; |
687 | return true; |
524 | } else if (ASIC_IS_AVIVO(rdev)) { |
688 | } else if (ASIC_IS_AVIVO(rdev)) { |
525 | reg = RREG32(AVIVO_D1CRTC_CONTROL) | |
689 | reg = RREG32(AVIVO_D1CRTC_CONTROL) | |
526 | RREG32(AVIVO_D2CRTC_CONTROL); |
690 | RREG32(AVIVO_D2CRTC_CONTROL); |
527 | if (reg & AVIVO_CRTC_EN) { |
691 | if (reg & AVIVO_CRTC_EN) { |
528 | return true; |
692 | return true; |
529 | } |
693 | } |
530 | } else { |
694 | } else { |
531 | reg = RREG32(RADEON_CRTC_GEN_CNTL) | |
695 | reg = RREG32(RADEON_CRTC_GEN_CNTL) | |
532 | RREG32(RADEON_CRTC2_GEN_CNTL); |
696 | RREG32(RADEON_CRTC2_GEN_CNTL); |
533 | if (reg & RADEON_CRTC_EN) { |
697 | if (reg & RADEON_CRTC_EN) { |
534 | return true; |
698 | return true; |
535 | } |
699 | } |
536 | } |
700 | } |
537 | 701 | ||
538 | check_memsize: |
702 | check_memsize: |
539 | /* then check MEM_SIZE, in case the crtcs are off */ |
703 | /* then check MEM_SIZE, in case the crtcs are off */ |
540 | if (rdev->family >= CHIP_R600) |
704 | if (rdev->family >= CHIP_R600) |
541 | reg = RREG32(R600_CONFIG_MEMSIZE); |
705 | reg = RREG32(R600_CONFIG_MEMSIZE); |
542 | else |
706 | else |
543 | reg = RREG32(RADEON_CONFIG_MEMSIZE); |
707 | reg = RREG32(RADEON_CONFIG_MEMSIZE); |
544 | 708 | ||
545 | if (reg) |
709 | if (reg) |
546 | return true; |
710 | return true; |
547 | 711 | ||
548 | return false; |
712 | return false; |
549 | 713 | ||
550 | } |
714 | } |
551 | 715 | ||
552 | /** |
716 | /** |
553 | * radeon_update_bandwidth_info - update display bandwidth params |
717 | * radeon_update_bandwidth_info - update display bandwidth params |
554 | * |
718 | * |
555 | * @rdev: radeon_device pointer |
719 | * @rdev: radeon_device pointer |
556 | * |
720 | * |
557 | * Used when sclk/mclk are switched or display modes are set. |
721 | * Used when sclk/mclk are switched or display modes are set. |
558 | * params are used to calculate display watermarks (all asics) |
722 | * params are used to calculate display watermarks (all asics) |
559 | */ |
723 | */ |
560 | void radeon_update_bandwidth_info(struct radeon_device *rdev) |
724 | void radeon_update_bandwidth_info(struct radeon_device *rdev) |
561 | { |
725 | { |
562 | fixed20_12 a; |
726 | fixed20_12 a; |
563 | u32 sclk = rdev->pm.current_sclk; |
727 | u32 sclk = rdev->pm.current_sclk; |
564 | u32 mclk = rdev->pm.current_mclk; |
728 | u32 mclk = rdev->pm.current_mclk; |
565 | 729 | ||
566 | /* sclk/mclk in Mhz */ |
730 | /* sclk/mclk in Mhz */ |
567 | a.full = dfixed_const(100); |
731 | a.full = dfixed_const(100); |
568 | rdev->pm.sclk.full = dfixed_const(sclk); |
732 | rdev->pm.sclk.full = dfixed_const(sclk); |
569 | rdev->pm.sclk.full = dfixed_div(rdev->pm.sclk, a); |
733 | rdev->pm.sclk.full = dfixed_div(rdev->pm.sclk, a); |
570 | rdev->pm.mclk.full = dfixed_const(mclk); |
734 | rdev->pm.mclk.full = dfixed_const(mclk); |
571 | rdev->pm.mclk.full = dfixed_div(rdev->pm.mclk, a); |
735 | rdev->pm.mclk.full = dfixed_div(rdev->pm.mclk, a); |
572 | 736 | ||
573 | if (rdev->flags & RADEON_IS_IGP) { |
737 | if (rdev->flags & RADEON_IS_IGP) { |
574 | a.full = dfixed_const(16); |
738 | a.full = dfixed_const(16); |
575 | /* core_bandwidth = sclk(Mhz) * 16 */ |
739 | /* core_bandwidth = sclk(Mhz) * 16 */ |
576 | rdev->pm.core_bandwidth.full = dfixed_div(rdev->pm.sclk, a); |
740 | rdev->pm.core_bandwidth.full = dfixed_div(rdev->pm.sclk, a); |
577 | } |
741 | } |
578 | } |
742 | } |
579 | 743 | ||
580 | /** |
744 | /** |
581 | * radeon_boot_test_post_card - check and possibly initialize the hw |
745 | * radeon_boot_test_post_card - check and possibly initialize the hw |
582 | * |
746 | * |
583 | * @rdev: radeon_device pointer |
747 | * @rdev: radeon_device pointer |
584 | * |
748 | * |
585 | * Check if the asic is initialized and if not, attempt to initialize |
749 | * Check if the asic is initialized and if not, attempt to initialize |
586 | * it (all asics). |
750 | * it (all asics). |
587 | * Returns true if initialized or false if not. |
751 | * Returns true if initialized or false if not. |
588 | */ |
752 | */ |
589 | bool radeon_boot_test_post_card(struct radeon_device *rdev) |
753 | bool radeon_boot_test_post_card(struct radeon_device *rdev) |
590 | { |
754 | { |
591 | if (radeon_card_posted(rdev)) |
755 | if (radeon_card_posted(rdev)) |
592 | return true; |
756 | return true; |
593 | 757 | ||
594 | if (rdev->bios) { |
758 | if (rdev->bios) { |
595 | DRM_INFO("GPU not posted. posting now...\n"); |
759 | DRM_INFO("GPU not posted. posting now...\n"); |
596 | if (rdev->is_atom_bios) |
760 | if (rdev->is_atom_bios) |
597 | atom_asic_init(rdev->mode_info.atom_context); |
761 | atom_asic_init(rdev->mode_info.atom_context); |
598 | else |
762 | else |
599 | radeon_combios_asic_init(rdev->ddev); |
763 | radeon_combios_asic_init(rdev->ddev); |
600 | return true; |
764 | return true; |
601 | } else { |
765 | } else { |
602 | dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); |
766 | dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); |
603 | return false; |
767 | return false; |
604 | } |
768 | } |
605 | } |
769 | } |
606 | 770 | ||
607 | /** |
771 | /** |
608 | * radeon_dummy_page_init - init dummy page used by the driver |
772 | * radeon_dummy_page_init - init dummy page used by the driver |
609 | * |
773 | * |
610 | * @rdev: radeon_device pointer |
774 | * @rdev: radeon_device pointer |
611 | * |
775 | * |
612 | * Allocate the dummy page used by the driver (all asics). |
776 | * Allocate the dummy page used by the driver (all asics). |
613 | * This dummy page is used by the driver as a filler for gart entries |
777 | * This dummy page is used by the driver as a filler for gart entries |
614 | * when pages are taken out of the GART |
778 | * when pages are taken out of the GART |
615 | * Returns 0 on sucess, -ENOMEM on failure. |
779 | * Returns 0 on sucess, -ENOMEM on failure. |
616 | */ |
780 | */ |
617 | int radeon_dummy_page_init(struct radeon_device *rdev) |
781 | int radeon_dummy_page_init(struct radeon_device *rdev) |
618 | { |
782 | { |
619 | if (rdev->dummy_page.page) |
783 | if (rdev->dummy_page.page) |
620 | return 0; |
784 | return 0; |
621 | rdev->dummy_page.page = (void*)AllocPage(); |
785 | rdev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO); |
622 | if (rdev->dummy_page.page == NULL) |
786 | if (rdev->dummy_page.page == NULL) |
623 | return -ENOMEM; |
787 | return -ENOMEM; |
624 | rdev->dummy_page.addr = MapIoMem((addr_t)rdev->dummy_page.page, 4096, 3); |
788 | rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page, |
625 | if (!rdev->dummy_page.addr) { |
- | |
626 | // __free_page(rdev->dummy_page.page); |
789 | 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
627 | rdev->dummy_page.page = NULL; |
- | |
628 | return -ENOMEM; |
- | |
629 | } |
- | |
630 | return 0; |
790 | return 0; |
631 | } |
791 | } |
632 | 792 | ||
633 | /** |
793 | /** |
634 | * radeon_dummy_page_fini - free dummy page used by the driver |
794 | * radeon_dummy_page_fini - free dummy page used by the driver |
635 | * |
795 | * |
636 | * @rdev: radeon_device pointer |
796 | * @rdev: radeon_device pointer |
637 | * |
797 | * |
638 | * Frees the dummy page used by the driver (all asics). |
798 | * Frees the dummy page used by the driver (all asics). |
639 | */ |
799 | */ |
640 | void radeon_dummy_page_fini(struct radeon_device *rdev) |
800 | void radeon_dummy_page_fini(struct radeon_device *rdev) |
641 | { |
801 | { |
642 | if (rdev->dummy_page.page == NULL) |
802 | if (rdev->dummy_page.page == NULL) |
643 | return; |
803 | return; |
644 | KernelFree((void*)rdev->dummy_page.addr); |
- | |
- | 804 | ||
645 | rdev->dummy_page.page = NULL; |
805 | rdev->dummy_page.page = NULL; |
646 | } |
806 | } |
647 | 807 | ||
648 | 808 | ||
649 | /* ATOM accessor methods */ |
809 | /* ATOM accessor methods */ |
650 | /* |
810 | /* |
651 | * ATOM is an interpreted byte code stored in tables in the vbios. The |
811 | * ATOM is an interpreted byte code stored in tables in the vbios. The |
652 | * driver registers callbacks to access registers and the interpreter |
812 | * driver registers callbacks to access registers and the interpreter |
653 | * in the driver parses the tables and executes then to program specific |
813 | * in the driver parses the tables and executes then to program specific |
654 | * actions (set display modes, asic init, etc.). See radeon_atombios.c, |
814 | * actions (set display modes, asic init, etc.). See radeon_atombios.c, |
655 | * atombios.h, and atom.c |
815 | * atombios.h, and atom.c |
656 | */ |
816 | */ |
657 | 817 | ||
658 | /** |
818 | /** |
659 | * cail_pll_read - read PLL register |
819 | * cail_pll_read - read PLL register |
660 | * |
820 | * |
661 | * @info: atom card_info pointer |
821 | * @info: atom card_info pointer |
662 | * @reg: PLL register offset |
822 | * @reg: PLL register offset |
663 | * |
823 | * |
664 | * Provides a PLL register accessor for the atom interpreter (r4xx+). |
824 | * Provides a PLL register accessor for the atom interpreter (r4xx+). |
665 | * Returns the value of the PLL register. |
825 | * Returns the value of the PLL register. |
666 | */ |
826 | */ |
667 | static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) |
827 | static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) |
668 | { |
828 | { |
669 | struct radeon_device *rdev = info->dev->dev_private; |
829 | struct radeon_device *rdev = info->dev->dev_private; |
670 | uint32_t r; |
830 | uint32_t r; |
671 | 831 | ||
672 | r = rdev->pll_rreg(rdev, reg); |
832 | r = rdev->pll_rreg(rdev, reg); |
673 | return r; |
833 | return r; |
674 | } |
834 | } |
675 | 835 | ||
676 | /** |
836 | /** |
677 | * cail_pll_write - write PLL register |
837 | * cail_pll_write - write PLL register |
678 | * |
838 | * |
679 | * @info: atom card_info pointer |
839 | * @info: atom card_info pointer |
680 | * @reg: PLL register offset |
840 | * @reg: PLL register offset |
681 | * @val: value to write to the pll register |
841 | * @val: value to write to the pll register |
682 | * |
842 | * |
683 | * Provides a PLL register accessor for the atom interpreter (r4xx+). |
843 | * Provides a PLL register accessor for the atom interpreter (r4xx+). |
684 | */ |
844 | */ |
685 | static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) |
845 | static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) |
686 | { |
846 | { |
687 | struct radeon_device *rdev = info->dev->dev_private; |
847 | struct radeon_device *rdev = info->dev->dev_private; |
688 | 848 | ||
689 | rdev->pll_wreg(rdev, reg, val); |
849 | rdev->pll_wreg(rdev, reg, val); |
690 | } |
850 | } |
691 | 851 | ||
692 | /** |
852 | /** |
693 | * cail_mc_read - read MC (Memory Controller) register |
853 | * cail_mc_read - read MC (Memory Controller) register |
694 | * |
854 | * |
695 | * @info: atom card_info pointer |
855 | * @info: atom card_info pointer |
696 | * @reg: MC register offset |
856 | * @reg: MC register offset |
697 | * |
857 | * |
698 | * Provides an MC register accessor for the atom interpreter (r4xx+). |
858 | * Provides an MC register accessor for the atom interpreter (r4xx+). |
699 | * Returns the value of the MC register. |
859 | * Returns the value of the MC register. |
700 | */ |
860 | */ |
701 | static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) |
861 | static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) |
702 | { |
862 | { |
703 | struct radeon_device *rdev = info->dev->dev_private; |
863 | struct radeon_device *rdev = info->dev->dev_private; |
704 | uint32_t r; |
864 | uint32_t r; |
705 | 865 | ||
706 | r = rdev->mc_rreg(rdev, reg); |
866 | r = rdev->mc_rreg(rdev, reg); |
707 | return r; |
867 | return r; |
708 | } |
868 | } |
709 | 869 | ||
710 | /** |
870 | /** |
711 | * cail_mc_write - write MC (Memory Controller) register |
871 | * cail_mc_write - write MC (Memory Controller) register |
712 | * |
872 | * |
713 | * @info: atom card_info pointer |
873 | * @info: atom card_info pointer |
714 | * @reg: MC register offset |
874 | * @reg: MC register offset |
715 | * @val: value to write to the pll register |
875 | * @val: value to write to the pll register |
716 | * |
876 | * |
717 | * Provides a MC register accessor for the atom interpreter (r4xx+). |
877 | * Provides a MC register accessor for the atom interpreter (r4xx+). |
718 | */ |
878 | */ |
719 | static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) |
879 | static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) |
720 | { |
880 | { |
721 | struct radeon_device *rdev = info->dev->dev_private; |
881 | struct radeon_device *rdev = info->dev->dev_private; |
722 | 882 | ||
723 | rdev->mc_wreg(rdev, reg, val); |
883 | rdev->mc_wreg(rdev, reg, val); |
724 | } |
884 | } |
725 | 885 | ||
726 | /** |
886 | /** |
727 | * cail_reg_write - write MMIO register |
887 | * cail_reg_write - write MMIO register |
728 | * |
888 | * |
729 | * @info: atom card_info pointer |
889 | * @info: atom card_info pointer |
730 | * @reg: MMIO register offset |
890 | * @reg: MMIO register offset |
731 | * @val: value to write to the pll register |
891 | * @val: value to write to the pll register |
732 | * |
892 | * |
733 | * Provides a MMIO register accessor for the atom interpreter (r4xx+). |
893 | * Provides a MMIO register accessor for the atom interpreter (r4xx+). |
734 | */ |
894 | */ |
735 | static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) |
895 | static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) |
736 | { |
896 | { |
737 | struct radeon_device *rdev = info->dev->dev_private; |
897 | struct radeon_device *rdev = info->dev->dev_private; |
738 | 898 | ||
739 | WREG32(reg*4, val); |
899 | WREG32(reg*4, val); |
740 | } |
900 | } |
741 | 901 | ||
742 | /** |
902 | /** |
743 | * cail_reg_read - read MMIO register |
903 | * cail_reg_read - read MMIO register |
744 | * |
904 | * |
745 | * @info: atom card_info pointer |
905 | * @info: atom card_info pointer |
746 | * @reg: MMIO register offset |
906 | * @reg: MMIO register offset |
747 | * |
907 | * |
748 | * Provides an MMIO register accessor for the atom interpreter (r4xx+). |
908 | * Provides an MMIO register accessor for the atom interpreter (r4xx+). |
749 | * Returns the value of the MMIO register. |
909 | * Returns the value of the MMIO register. |
750 | */ |
910 | */ |
751 | static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) |
911 | static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) |
752 | { |
912 | { |
753 | struct radeon_device *rdev = info->dev->dev_private; |
913 | struct radeon_device *rdev = info->dev->dev_private; |
754 | uint32_t r; |
914 | uint32_t r; |
755 | 915 | ||
756 | r = RREG32(reg*4); |
916 | r = RREG32(reg*4); |
757 | return r; |
917 | return r; |
758 | } |
918 | } |
759 | 919 | ||
760 | /** |
920 | /** |
761 | * cail_ioreg_write - write IO register |
921 | * cail_ioreg_write - write IO register |
762 | * |
922 | * |
763 | * @info: atom card_info pointer |
923 | * @info: atom card_info pointer |
764 | * @reg: IO register offset |
924 | * @reg: IO register offset |
765 | * @val: value to write to the pll register |
925 | * @val: value to write to the pll register |
766 | * |
926 | * |
767 | * Provides a IO register accessor for the atom interpreter (r4xx+). |
927 | * Provides a IO register accessor for the atom interpreter (r4xx+). |
768 | */ |
928 | */ |
769 | static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val) |
929 | static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val) |
770 | { |
930 | { |
771 | struct radeon_device *rdev = info->dev->dev_private; |
931 | struct radeon_device *rdev = info->dev->dev_private; |
772 | 932 | ||
773 | WREG32_IO(reg*4, val); |
933 | WREG32_IO(reg*4, val); |
774 | } |
934 | } |
775 | 935 | ||
776 | /** |
936 | /** |
777 | * cail_ioreg_read - read IO register |
937 | * cail_ioreg_read - read IO register |
778 | * |
938 | * |
779 | * @info: atom card_info pointer |
939 | * @info: atom card_info pointer |
780 | * @reg: IO register offset |
940 | * @reg: IO register offset |
781 | * |
941 | * |
782 | * Provides an IO register accessor for the atom interpreter (r4xx+). |
942 | * Provides an IO register accessor for the atom interpreter (r4xx+). |
783 | * Returns the value of the IO register. |
943 | * Returns the value of the IO register. |
784 | */ |
944 | */ |
785 | static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg) |
945 | static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg) |
786 | { |
946 | { |
787 | struct radeon_device *rdev = info->dev->dev_private; |
947 | struct radeon_device *rdev = info->dev->dev_private; |
788 | uint32_t r; |
948 | uint32_t r; |
789 | 949 | ||
790 | r = RREG32_IO(reg*4); |
950 | r = RREG32_IO(reg*4); |
791 | return r; |
951 | return r; |
792 | } |
952 | } |
793 | 953 | ||
794 | /** |
954 | /** |
795 | * radeon_atombios_init - init the driver info and callbacks for atombios |
955 | * radeon_atombios_init - init the driver info and callbacks for atombios |
796 | * |
956 | * |
797 | * @rdev: radeon_device pointer |
957 | * @rdev: radeon_device pointer |
798 | * |
958 | * |
799 | * Initializes the driver info and register access callbacks for the |
959 | * Initializes the driver info and register access callbacks for the |
800 | * ATOM interpreter (r4xx+). |
960 | * ATOM interpreter (r4xx+). |
801 | * Returns 0 on sucess, -ENOMEM on failure. |
961 | * Returns 0 on sucess, -ENOMEM on failure. |
802 | * Called at driver startup. |
962 | * Called at driver startup. |
803 | */ |
963 | */ |
804 | int radeon_atombios_init(struct radeon_device *rdev) |
964 | int radeon_atombios_init(struct radeon_device *rdev) |
805 | { |
965 | { |
806 | struct card_info *atom_card_info = |
966 | struct card_info *atom_card_info = |
807 | kzalloc(sizeof(struct card_info), GFP_KERNEL); |
967 | kzalloc(sizeof(struct card_info), GFP_KERNEL); |
808 | 968 | ||
809 | if (!atom_card_info) |
969 | if (!atom_card_info) |
810 | return -ENOMEM; |
970 | return -ENOMEM; |
811 | 971 | ||
812 | rdev->mode_info.atom_card_info = atom_card_info; |
972 | rdev->mode_info.atom_card_info = atom_card_info; |
813 | atom_card_info->dev = rdev->ddev; |
973 | atom_card_info->dev = rdev->ddev; |
814 | atom_card_info->reg_read = cail_reg_read; |
974 | atom_card_info->reg_read = cail_reg_read; |
815 | atom_card_info->reg_write = cail_reg_write; |
975 | atom_card_info->reg_write = cail_reg_write; |
816 | /* needed for iio ops */ |
976 | /* needed for iio ops */ |
817 | if (rdev->rio_mem) { |
977 | if (rdev->rio_mem) { |
818 | atom_card_info->ioreg_read = cail_ioreg_read; |
978 | atom_card_info->ioreg_read = cail_ioreg_read; |
819 | atom_card_info->ioreg_write = cail_ioreg_write; |
979 | atom_card_info->ioreg_write = cail_ioreg_write; |
820 | } else { |
980 | } else { |
821 | DRM_ERROR("Unable to find PCI I/O BAR; using MMIO for ATOM IIO\n"); |
981 | DRM_ERROR("Unable to find PCI I/O BAR; using MMIO for ATOM IIO\n"); |
822 | atom_card_info->ioreg_read = cail_reg_read; |
982 | atom_card_info->ioreg_read = cail_reg_read; |
823 | atom_card_info->ioreg_write = cail_reg_write; |
983 | atom_card_info->ioreg_write = cail_reg_write; |
824 | } |
984 | } |
825 | atom_card_info->mc_read = cail_mc_read; |
985 | atom_card_info->mc_read = cail_mc_read; |
826 | atom_card_info->mc_write = cail_mc_write; |
986 | atom_card_info->mc_write = cail_mc_write; |
827 | atom_card_info->pll_read = cail_pll_read; |
987 | atom_card_info->pll_read = cail_pll_read; |
828 | atom_card_info->pll_write = cail_pll_write; |
988 | atom_card_info->pll_write = cail_pll_write; |
829 | 989 | ||
830 | rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios); |
990 | rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios); |
831 | if (!rdev->mode_info.atom_context) { |
991 | if (!rdev->mode_info.atom_context) { |
832 | radeon_atombios_fini(rdev); |
992 | radeon_atombios_fini(rdev); |
833 | return -ENOMEM; |
993 | return -ENOMEM; |
834 | } |
994 | } |
835 | 995 | ||
836 | mutex_init(&rdev->mode_info.atom_context->mutex); |
996 | mutex_init(&rdev->mode_info.atom_context->mutex); |
837 | radeon_atom_initialize_bios_scratch_regs(rdev->ddev); |
997 | radeon_atom_initialize_bios_scratch_regs(rdev->ddev); |
838 | atom_allocate_fb_scratch(rdev->mode_info.atom_context); |
998 | atom_allocate_fb_scratch(rdev->mode_info.atom_context); |
839 | return 0; |
999 | return 0; |
840 | } |
1000 | } |
841 | 1001 | ||
842 | /** |
1002 | /** |
843 | * radeon_atombios_fini - free the driver info and callbacks for atombios |
1003 | * radeon_atombios_fini - free the driver info and callbacks for atombios |
844 | * |
1004 | * |
845 | * @rdev: radeon_device pointer |
1005 | * @rdev: radeon_device pointer |
846 | * |
1006 | * |
847 | * Frees the driver info and register access callbacks for the ATOM |
1007 | * Frees the driver info and register access callbacks for the ATOM |
848 | * interpreter (r4xx+). |
1008 | * interpreter (r4xx+). |
849 | * Called at driver shutdown. |
1009 | * Called at driver shutdown. |
850 | */ |
1010 | */ |
851 | void radeon_atombios_fini(struct radeon_device *rdev) |
1011 | void radeon_atombios_fini(struct radeon_device *rdev) |
852 | { |
1012 | { |
853 | if (rdev->mode_info.atom_context) { |
1013 | if (rdev->mode_info.atom_context) { |
854 | kfree(rdev->mode_info.atom_context->scratch); |
1014 | kfree(rdev->mode_info.atom_context->scratch); |
855 | } |
1015 | } |
856 | kfree(rdev->mode_info.atom_context); |
1016 | kfree(rdev->mode_info.atom_context); |
857 | rdev->mode_info.atom_context = NULL; |
1017 | rdev->mode_info.atom_context = NULL; |
858 | kfree(rdev->mode_info.atom_card_info); |
1018 | kfree(rdev->mode_info.atom_card_info); |
859 | rdev->mode_info.atom_card_info = NULL; |
1019 | rdev->mode_info.atom_card_info = NULL; |
860 | } |
1020 | } |
861 | 1021 | ||
862 | /* COMBIOS */ |
1022 | /* COMBIOS */ |
863 | /* |
1023 | /* |
864 | * COMBIOS is the bios format prior to ATOM. It provides |
1024 | * COMBIOS is the bios format prior to ATOM. It provides |
865 | * command tables similar to ATOM, but doesn't have a unified |
1025 | * command tables similar to ATOM, but doesn't have a unified |
866 | * parser. See radeon_combios.c |
1026 | * parser. See radeon_combios.c |
867 | */ |
1027 | */ |
868 | 1028 | ||
869 | /** |
1029 | /** |
870 | * radeon_combios_init - init the driver info for combios |
1030 | * radeon_combios_init - init the driver info for combios |
871 | * |
1031 | * |
872 | * @rdev: radeon_device pointer |
1032 | * @rdev: radeon_device pointer |
873 | * |
1033 | * |
874 | * Initializes the driver info for combios (r1xx-r3xx). |
1034 | * Initializes the driver info for combios (r1xx-r3xx). |
875 | * Returns 0 on sucess. |
1035 | * Returns 0 on sucess. |
876 | * Called at driver startup. |
1036 | * Called at driver startup. |
877 | */ |
1037 | */ |
878 | int radeon_combios_init(struct radeon_device *rdev) |
1038 | int radeon_combios_init(struct radeon_device *rdev) |
879 | { |
1039 | { |
880 | radeon_combios_initialize_bios_scratch_regs(rdev->ddev); |
1040 | radeon_combios_initialize_bios_scratch_regs(rdev->ddev); |
881 | return 0; |
1041 | return 0; |
882 | } |
1042 | } |
883 | 1043 | ||
884 | /** |
1044 | /** |
885 | * radeon_combios_fini - free the driver info for combios |
1045 | * radeon_combios_fini - free the driver info for combios |
886 | * |
1046 | * |
887 | * @rdev: radeon_device pointer |
1047 | * @rdev: radeon_device pointer |
888 | * |
1048 | * |
889 | * Frees the driver info for combios (r1xx-r3xx). |
1049 | * Frees the driver info for combios (r1xx-r3xx). |
890 | * Called at driver shutdown. |
1050 | * Called at driver shutdown. |
891 | */ |
1051 | */ |
892 | void radeon_combios_fini(struct radeon_device *rdev) |
1052 | void radeon_combios_fini(struct radeon_device *rdev) |
893 | { |
1053 | { |
894 | } |
1054 | } |
895 | 1055 | ||
896 | /* if we get transitioned to only one device, take VGA back */ |
1056 | /* if we get transitioned to only one device, take VGA back */ |
897 | /** |
1057 | /** |
898 | * radeon_vga_set_decode - enable/disable vga decode |
1058 | * radeon_vga_set_decode - enable/disable vga decode |
899 | * |
1059 | * |
900 | * @cookie: radeon_device pointer |
1060 | * @cookie: radeon_device pointer |
901 | * @state: enable/disable vga decode |
1061 | * @state: enable/disable vga decode |
902 | * |
1062 | * |
903 | * Enable/disable vga decode (all asics). |
1063 | * Enable/disable vga decode (all asics). |
904 | * Returns VGA resource flags. |
1064 | * Returns VGA resource flags. |
905 | */ |
1065 | */ |
906 | static unsigned int radeon_vga_set_decode(void *cookie, bool state) |
1066 | static unsigned int radeon_vga_set_decode(void *cookie, bool state) |
907 | { |
1067 | { |
908 | struct radeon_device *rdev = cookie; |
1068 | struct radeon_device *rdev = cookie; |
909 | radeon_vga_set_state(rdev, state); |
1069 | radeon_vga_set_state(rdev, state); |
910 | if (state) |
1070 | if (state) |
911 | return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | |
1071 | return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | |
912 | VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
1072 | VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
913 | else |
1073 | else |
914 | return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
1074 | return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
915 | } |
1075 | } |
916 | 1076 | ||
917 | /** |
1077 | /** |
918 | * radeon_check_pot_argument - check that argument is a power of two |
1078 | * radeon_check_pot_argument - check that argument is a power of two |
919 | * |
1079 | * |
920 | * @arg: value to check |
1080 | * @arg: value to check |
921 | * |
1081 | * |
922 | * Validates that a certain argument is a power of two (all asics). |
1082 | * Validates that a certain argument is a power of two (all asics). |
923 | * Returns true if argument is valid. |
1083 | * Returns true if argument is valid. |
924 | */ |
1084 | */ |
925 | static bool radeon_check_pot_argument(int arg) |
1085 | static bool radeon_check_pot_argument(int arg) |
926 | { |
1086 | { |
927 | return (arg & (arg - 1)) == 0; |
1087 | return (arg & (arg - 1)) == 0; |
928 | } |
1088 | } |
929 | 1089 | ||
930 | /** |
1090 | /** |
931 | * radeon_check_arguments - validate module params |
1091 | * radeon_check_arguments - validate module params |
932 | * |
1092 | * |
933 | * @rdev: radeon_device pointer |
1093 | * @rdev: radeon_device pointer |
934 | * |
1094 | * |
935 | * Validates certain module parameters and updates |
1095 | * Validates certain module parameters and updates |
936 | * the associated values used by the driver (all asics). |
1096 | * the associated values used by the driver (all asics). |
937 | */ |
1097 | */ |
938 | static void radeon_check_arguments(struct radeon_device *rdev) |
1098 | static void radeon_check_arguments(struct radeon_device *rdev) |
939 | { |
1099 | { |
940 | /* vramlimit must be a power of two */ |
1100 | /* vramlimit must be a power of two */ |
941 | if (!radeon_check_pot_argument(radeon_vram_limit)) { |
1101 | if (!radeon_check_pot_argument(radeon_vram_limit)) { |
942 | dev_warn(rdev->dev, "vram limit (%d) must be a power of 2\n", |
1102 | dev_warn(rdev->dev, "vram limit (%d) must be a power of 2\n", |
943 | radeon_vram_limit); |
1103 | radeon_vram_limit); |
944 | radeon_vram_limit = 0; |
1104 | radeon_vram_limit = 0; |
945 | } |
1105 | } |
- | 1106 | ||
- | 1107 | if (radeon_gart_size == -1) { |
|
- | 1108 | /* default to a larger gart size on newer asics */ |
|
- | 1109 | if (rdev->family >= CHIP_RV770) |
|
- | 1110 | radeon_gart_size = 1024; |
|
- | 1111 | else |
|
- | 1112 | radeon_gart_size = 512; |
|
946 | 1113 | } |
|
947 | /* gtt size must be power of two and greater or equal to 32M */ |
1114 | /* gtt size must be power of two and greater or equal to 32M */ |
948 | if (radeon_gart_size < 32) { |
1115 | if (radeon_gart_size < 32) { |
949 | dev_warn(rdev->dev, "gart size (%d) too small forcing to 512M\n", |
1116 | dev_warn(rdev->dev, "gart size (%d) too small\n", |
- | 1117 | radeon_gart_size); |
|
- | 1118 | if (rdev->family >= CHIP_RV770) |
|
- | 1119 | radeon_gart_size = 1024; |
|
950 | radeon_gart_size); |
1120 | else |
951 | radeon_gart_size = 512; |
- | |
952 | 1121 | radeon_gart_size = 512; |
|
953 | } else if (!radeon_check_pot_argument(radeon_gart_size)) { |
1122 | } else if (!radeon_check_pot_argument(radeon_gart_size)) { |
954 | dev_warn(rdev->dev, "gart size (%d) must be a power of 2\n", |
1123 | dev_warn(rdev->dev, "gart size (%d) must be a power of 2\n", |
955 | radeon_gart_size); |
1124 | radeon_gart_size); |
- | 1125 | if (rdev->family >= CHIP_RV770) |
|
- | 1126 | radeon_gart_size = 1024; |
|
- | 1127 | else |
|
956 | radeon_gart_size = 512; |
1128 | radeon_gart_size = 512; |
957 | } |
1129 | } |
958 | rdev->mc.gtt_size = (uint64_t)radeon_gart_size << 20; |
1130 | rdev->mc.gtt_size = (uint64_t)radeon_gart_size << 20; |
959 | 1131 | ||
960 | /* AGP mode can only be -1, 1, 2, 4, 8 */ |
1132 | /* AGP mode can only be -1, 1, 2, 4, 8 */ |
961 | switch (radeon_agpmode) { |
1133 | switch (radeon_agpmode) { |
962 | case -1: |
1134 | case -1: |
963 | case 0: |
1135 | case 0: |
964 | case 1: |
1136 | case 1: |
965 | case 2: |
1137 | case 2: |
966 | case 4: |
1138 | case 4: |
967 | case 8: |
1139 | case 8: |
968 | break; |
1140 | break; |
969 | default: |
1141 | default: |
970 | dev_warn(rdev->dev, "invalid AGP mode %d (valid mode: " |
1142 | dev_warn(rdev->dev, "invalid AGP mode %d (valid mode: " |
971 | "-1, 0, 1, 2, 4, 8)\n", radeon_agpmode); |
1143 | "-1, 0, 1, 2, 4, 8)\n", radeon_agpmode); |
972 | radeon_agpmode = 0; |
1144 | radeon_agpmode = 0; |
973 | break; |
1145 | break; |
974 | } |
1146 | } |
- | 1147 | ||
- | 1148 | if (!radeon_check_pot_argument(radeon_vm_size)) { |
|
- | 1149 | dev_warn(rdev->dev, "VM size (%d) must be a power of 2\n", |
|
- | 1150 | radeon_vm_size); |
|
- | 1151 | radeon_vm_size = 4; |
|
- | 1152 | } |
|
- | 1153 | ||
- | 1154 | if (radeon_vm_size < 1) { |
|
- | 1155 | dev_warn(rdev->dev, "VM size (%d) to small, min is 1GB\n", |
|
- | 1156 | radeon_vm_size); |
|
- | 1157 | radeon_vm_size = 4; |
|
- | 1158 | } |
|
- | 1159 | ||
- | 1160 | /* |
|
- | 1161 | * Max GPUVM size for Cayman, SI and CI are 40 bits. |
|
- | 1162 | */ |
|
- | 1163 | if (radeon_vm_size > 1024) { |
|
- | 1164 | dev_warn(rdev->dev, "VM size (%d) too large, max is 1TB\n", |
|
- | 1165 | radeon_vm_size); |
|
- | 1166 | radeon_vm_size = 4; |
|
- | 1167 | } |
|
- | 1168 | ||
- | 1169 | /* defines number of bits in page table versus page directory, |
|
- | 1170 | * a page is 4KB so we have 12 bits offset, minimum 9 bits in the |
|
- | 1171 | * page table and the remaining bits are in the page directory */ |
|
- | 1172 | if (radeon_vm_block_size == -1) { |
|
- | 1173 | ||
- | 1174 | /* Total bits covered by PD + PTs */ |
|
- | 1175 | unsigned bits = ilog2(radeon_vm_size) + 17; |
|
- | 1176 | ||
- | 1177 | /* Make sure the PD is 4K in size up to 8GB address space. |
|
- | 1178 | Above that split equal between PD and PTs */ |
|
- | 1179 | if (radeon_vm_size <= 8) |
|
- | 1180 | radeon_vm_block_size = bits - 9; |
|
- | 1181 | else |
|
- | 1182 | radeon_vm_block_size = (bits + 3) / 2; |
|
- | 1183 | ||
- | 1184 | } else if (radeon_vm_block_size < 9) { |
|
- | 1185 | dev_warn(rdev->dev, "VM page table size (%d) too small\n", |
|
- | 1186 | radeon_vm_block_size); |
|
- | 1187 | radeon_vm_block_size = 9; |
|
- | 1188 | } |
|
- | 1189 | ||
- | 1190 | if (radeon_vm_block_size > 24 || |
|
- | 1191 | (radeon_vm_size * 1024) < (1ull << radeon_vm_block_size)) { |
|
- | 1192 | dev_warn(rdev->dev, "VM page table size (%d) too large\n", |
|
- | 1193 | radeon_vm_block_size); |
|
- | 1194 | radeon_vm_block_size = 9; |
|
- | 1195 | } |
|
975 | } |
1196 | } |
- | 1197 | ||
- | 1198 | /** |
|
- | 1199 | * radeon_device_init - initialize the driver |
|
- | 1200 | * |
|
- | 1201 | * @rdev: radeon_device pointer |
|
- | 1202 | * @pdev: drm dev pointer |
|
- | 1203 | * @pdev: pci dev pointer |
|
- | 1204 | * @flags: driver flags |
|
- | 1205 | * |
|
- | 1206 | * Initializes the driver info and hw (all asics). |
|
- | 1207 | * Returns 0 for success or an error on failure. |
|
- | 1208 | * Called at driver startup. |
|
976 | 1209 | */ |
|
977 | int radeon_device_init(struct radeon_device *rdev, |
1210 | int radeon_device_init(struct radeon_device *rdev, |
978 | struct drm_device *ddev, |
1211 | struct drm_device *ddev, |
979 | struct pci_dev *pdev, |
1212 | struct pci_dev *pdev, |
980 | uint32_t flags) |
1213 | uint32_t flags) |
981 | { |
1214 | { |
982 | int r, i; |
1215 | int r, i; |
983 | int dma_bits; |
1216 | int dma_bits; |
- | 1217 | bool runtime = false; |
|
984 | 1218 | ||
- | 1219 | rdev->shutdown = false; |
|
985 | rdev->shutdown = false; |
1220 | rdev->dev = &pdev->dev; |
986 | rdev->ddev = ddev; |
1221 | rdev->ddev = ddev; |
987 | rdev->pdev = pdev; |
1222 | rdev->pdev = pdev; |
988 | rdev->flags = flags; |
1223 | rdev->flags = flags; |
989 | rdev->family = flags & RADEON_FAMILY_MASK; |
1224 | rdev->family = flags & RADEON_FAMILY_MASK; |
990 | rdev->is_atom_bios = false; |
1225 | rdev->is_atom_bios = false; |
991 | rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT; |
1226 | rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT; |
992 | rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; |
1227 | rdev->mc.gtt_size = 512 * 1024 * 1024; |
993 | rdev->accel_working = false; |
1228 | rdev->accel_working = false; |
994 | /* set up ring ids */ |
1229 | /* set up ring ids */ |
995 | for (i = 0; i < RADEON_NUM_RINGS; i++) { |
1230 | for (i = 0; i < RADEON_NUM_RINGS; i++) { |
996 | rdev->ring[i].idx = i; |
1231 | rdev->ring[i].idx = i; |
997 | } |
1232 | } |
998 | 1233 | ||
999 | DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X).\n", |
1234 | DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X).\n", |
1000 | radeon_family_name[rdev->family], pdev->vendor, pdev->device, |
1235 | radeon_family_name[rdev->family], pdev->vendor, pdev->device, |
1001 | pdev->subsystem_vendor, pdev->subsystem_device); |
1236 | pdev->subsystem_vendor, pdev->subsystem_device); |
1002 | 1237 | ||
1003 | /* mutex initialization are all done here so we |
1238 | /* mutex initialization are all done here so we |
1004 | * can recall function without having locking issues */ |
1239 | * can recall function without having locking issues */ |
1005 | mutex_init(&rdev->ring_lock); |
1240 | mutex_init(&rdev->ring_lock); |
1006 | mutex_init(&rdev->dc_hw_i2c_mutex); |
1241 | mutex_init(&rdev->dc_hw_i2c_mutex); |
1007 | atomic_set(&rdev->ih.lock, 0); |
1242 | atomic_set(&rdev->ih.lock, 0); |
1008 | mutex_init(&rdev->gem.mutex); |
1243 | mutex_init(&rdev->gem.mutex); |
1009 | mutex_init(&rdev->pm.mutex); |
1244 | mutex_init(&rdev->pm.mutex); |
1010 | mutex_init(&rdev->gpu_clock_mutex); |
1245 | mutex_init(&rdev->gpu_clock_mutex); |
- | 1246 | mutex_init(&rdev->srbm_mutex); |
|
1011 | // init_rwsem(&rdev->pm.mclk_lock); |
1247 | // init_rwsem(&rdev->pm.mclk_lock); |
1012 | // init_rwsem(&rdev->exclusive_lock); |
1248 | // init_rwsem(&rdev->exclusive_lock); |
1013 | init_waitqueue_head(&rdev->irq.vblank_queue); |
1249 | init_waitqueue_head(&rdev->irq.vblank_queue); |
1014 | r = radeon_gem_init(rdev); |
1250 | r = radeon_gem_init(rdev); |
1015 | if (r) |
1251 | if (r) |
1016 | return r; |
1252 | return r; |
1017 | /* initialize vm here */ |
- | |
- | 1253 | ||
1018 | mutex_init(&rdev->vm_manager.lock); |
1254 | radeon_check_arguments(rdev); |
1019 | /* Adjust VM size here. |
1255 | /* Adjust VM size here. |
1020 | * Currently set to 4GB ((1 << 20) 4k pages). |
- | |
1021 | * Max GPUVM size for cayman and SI is 40 bits. |
1256 | * Max GPUVM size for cayman+ is 40 bits. |
1022 | */ |
1257 | */ |
1023 | rdev->vm_manager.max_pfn = 1 << 20; |
1258 | rdev->vm_manager.max_pfn = radeon_vm_size << 18; |
1024 | INIT_LIST_HEAD(&rdev->vm_manager.lru_vm); |
- | |
1025 | 1259 | ||
1026 | /* Set asic functions */ |
1260 | /* Set asic functions */ |
1027 | r = radeon_asic_init(rdev); |
1261 | r = radeon_asic_init(rdev); |
1028 | if (r) |
1262 | if (r) |
1029 | return r; |
1263 | return r; |
1030 | radeon_check_arguments(rdev); |
- | |
1031 | 1264 | ||
1032 | /* all of the newer IGP chips have an internal gart |
1265 | /* all of the newer IGP chips have an internal gart |
1033 | * However some rs4xx report as AGP, so remove that here. |
1266 | * However some rs4xx report as AGP, so remove that here. |
1034 | */ |
1267 | */ |
1035 | if ((rdev->family >= CHIP_RS400) && |
1268 | if ((rdev->family >= CHIP_RS400) && |
1036 | (rdev->flags & RADEON_IS_IGP)) { |
1269 | (rdev->flags & RADEON_IS_IGP)) { |
1037 | rdev->flags &= ~RADEON_IS_AGP; |
1270 | rdev->flags &= ~RADEON_IS_AGP; |
1038 | } |
1271 | } |
1039 | 1272 | ||
1040 | if (rdev->flags & RADEON_IS_AGP && radeon_agpmode == -1) { |
1273 | if (rdev->flags & RADEON_IS_AGP && radeon_agpmode == -1) { |
1041 | radeon_agp_disable(rdev); |
1274 | radeon_agp_disable(rdev); |
1042 | } |
1275 | } |
1043 | 1276 | ||
1044 | /* Set the internal MC address mask |
1277 | /* Set the internal MC address mask |
1045 | * This is the max address of the GPU's |
1278 | * This is the max address of the GPU's |
1046 | * internal address space. |
1279 | * internal address space. |
1047 | */ |
1280 | */ |
1048 | if (rdev->family >= CHIP_CAYMAN) |
1281 | if (rdev->family >= CHIP_CAYMAN) |
1049 | rdev->mc.mc_mask = 0xffffffffffULL; /* 40 bit MC */ |
1282 | rdev->mc.mc_mask = 0xffffffffffULL; /* 40 bit MC */ |
1050 | else if (rdev->family >= CHIP_CEDAR) |
1283 | else if (rdev->family >= CHIP_CEDAR) |
1051 | rdev->mc.mc_mask = 0xfffffffffULL; /* 36 bit MC */ |
1284 | rdev->mc.mc_mask = 0xfffffffffULL; /* 36 bit MC */ |
1052 | else |
1285 | else |
1053 | rdev->mc.mc_mask = 0xffffffffULL; /* 32 bit MC */ |
1286 | rdev->mc.mc_mask = 0xffffffffULL; /* 32 bit MC */ |
1054 | 1287 | ||
1055 | /* set DMA mask + need_dma32 flags. |
1288 | /* set DMA mask + need_dma32 flags. |
1056 | * PCIE - can handle 40-bits. |
1289 | * PCIE - can handle 40-bits. |
1057 | * IGP - can handle 40-bits |
1290 | * IGP - can handle 40-bits |
1058 | * AGP - generally dma32 is safest |
1291 | * AGP - generally dma32 is safest |
1059 | * PCI - dma32 for legacy pci gart, 40 bits on newer asics |
1292 | * PCI - dma32 for legacy pci gart, 40 bits on newer asics |
1060 | */ |
1293 | */ |
1061 | rdev->need_dma32 = false; |
1294 | rdev->need_dma32 = false; |
1062 | if (rdev->flags & RADEON_IS_AGP) |
1295 | if (rdev->flags & RADEON_IS_AGP) |
1063 | rdev->need_dma32 = true; |
1296 | rdev->need_dma32 = true; |
1064 | if ((rdev->flags & RADEON_IS_PCI) && |
1297 | if ((rdev->flags & RADEON_IS_PCI) && |
1065 | (rdev->family <= CHIP_RS740)) |
1298 | (rdev->family <= CHIP_RS740)) |
1066 | rdev->need_dma32 = true; |
1299 | rdev->need_dma32 = true; |
1067 | 1300 | ||
1068 | dma_bits = rdev->need_dma32 ? 32 : 40; |
1301 | dma_bits = rdev->need_dma32 ? 32 : 40; |
1069 | r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits)); |
1302 | r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits)); |
1070 | if (r) { |
1303 | if (r) { |
1071 | rdev->need_dma32 = true; |
1304 | rdev->need_dma32 = true; |
1072 | dma_bits = 32; |
1305 | dma_bits = 32; |
1073 | printk(KERN_WARNING "radeon: No suitable DMA available.\n"); |
1306 | printk(KERN_WARNING "radeon: No suitable DMA available.\n"); |
1074 | } |
1307 | } |
1075 | 1308 | ||
1076 | /* Registers mapping */ |
1309 | /* Registers mapping */ |
1077 | /* TODO: block userspace mapping of io register */ |
1310 | /* TODO: block userspace mapping of io register */ |
1078 | spin_lock_init(&rdev->mmio_idx_lock); |
1311 | spin_lock_init(&rdev->mmio_idx_lock); |
- | 1312 | spin_lock_init(&rdev->smc_idx_lock); |
|
- | 1313 | spin_lock_init(&rdev->pll_idx_lock); |
|
- | 1314 | spin_lock_init(&rdev->mc_idx_lock); |
|
- | 1315 | spin_lock_init(&rdev->pcie_idx_lock); |
|
- | 1316 | spin_lock_init(&rdev->pciep_idx_lock); |
|
- | 1317 | spin_lock_init(&rdev->pif_idx_lock); |
|
- | 1318 | spin_lock_init(&rdev->cg_idx_lock); |
|
- | 1319 | spin_lock_init(&rdev->uvd_idx_lock); |
|
- | 1320 | spin_lock_init(&rdev->rcu_idx_lock); |
|
- | 1321 | spin_lock_init(&rdev->didt_idx_lock); |
|
- | 1322 | spin_lock_init(&rdev->end_idx_lock); |
|
- | 1323 | if (rdev->family >= CHIP_BONAIRE) { |
|
- | 1324 | rdev->rmmio_base = pci_resource_start(rdev->pdev, 5); |
|
- | 1325 | rdev->rmmio_size = pci_resource_len(rdev->pdev, 5); |
|
- | 1326 | } else { |
|
1079 | rdev->rmmio_base = pci_resource_start(rdev->pdev, 2); |
1327 | rdev->rmmio_base = pci_resource_start(rdev->pdev, 2); |
1080 | rdev->rmmio_size = pci_resource_len(rdev->pdev, 2); |
1328 | rdev->rmmio_size = pci_resource_len(rdev->pdev, 2); |
- | 1329 | } |
|
1081 | rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size); |
1330 | rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size); |
1082 | if (rdev->rmmio == NULL) { |
1331 | if (rdev->rmmio == NULL) { |
1083 | return -ENOMEM; |
1332 | return -ENOMEM; |
1084 | } |
1333 | } |
1085 | DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base); |
1334 | DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base); |
1086 | DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size); |
1335 | DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size); |
- | 1336 | ||
- | 1337 | /* doorbell bar mapping */ |
|
- | 1338 | if (rdev->family >= CHIP_BONAIRE) |
|
- | 1339 | radeon_doorbell_init(rdev); |
|
1087 | 1340 | ||
1088 | /* io port mapping */ |
1341 | /* io port mapping */ |
1089 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
1342 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
1090 | if (pci_resource_flags(rdev->pdev, i) & IORESOURCE_IO) { |
1343 | if (pci_resource_flags(rdev->pdev, i) & IORESOURCE_IO) { |
1091 | rdev->rio_mem_size = pci_resource_len(rdev->pdev, i); |
1344 | rdev->rio_mem_size = pci_resource_len(rdev->pdev, i); |
1092 | rdev->rio_mem = pci_iomap(rdev->pdev, i, rdev->rio_mem_size); |
1345 | rdev->rio_mem = pci_iomap(rdev->pdev, i, rdev->rio_mem_size); |
1093 | break; |
1346 | break; |
1094 | } |
1347 | } |
1095 | } |
1348 | } |
1096 | if (rdev->rio_mem == NULL) |
1349 | if (rdev->rio_mem == NULL) |
1097 | DRM_ERROR("Unable to find PCI I/O BAR\n"); |
1350 | DRM_ERROR("Unable to find PCI I/O BAR\n"); |
- | 1351 | ||
- | 1352 | if (rdev->flags & RADEON_IS_PX) |
|
- | 1353 | radeon_device_handle_px_quirks(rdev); |
|
- | 1354 | if (rdev->flags & RADEON_IS_PX) |
|
1098 | 1355 | runtime = true; |
|
1099 | 1356 | ||
1100 | r = radeon_init(rdev); |
1357 | r = radeon_init(rdev); |
1101 | if (r) |
1358 | if (r) |
1102 | return r; |
1359 | return r; |
1103 | 1360 | ||
1104 | // r = radeon_ib_ring_tests(rdev); |
1361 | r = radeon_ib_ring_tests(rdev); |
1105 | // if (r) |
1362 | if (r) |
- | 1363 | DRM_ERROR("ib ring test failed (%d).\n", r); |
|
1106 | // DRM_ERROR("ib ring test failed (%d).\n", r); |
1364 | |
1107 | 1365 | ||
1108 | if (rdev->flags & RADEON_IS_AGP && !rdev->accel_working) { |
1366 | if (rdev->flags & RADEON_IS_AGP && !rdev->accel_working) { |
1109 | /* Acceleration not working on AGP card try again |
1367 | /* Acceleration not working on AGP card try again |
1110 | * with fallback to PCI or PCIE GART |
1368 | * with fallback to PCI or PCIE GART |
1111 | */ |
1369 | */ |
1112 | radeon_asic_reset(rdev); |
1370 | radeon_asic_reset(rdev); |
1113 | radeon_fini(rdev); |
1371 | radeon_fini(rdev); |
1114 | radeon_agp_disable(rdev); |
1372 | radeon_agp_disable(rdev); |
1115 | r = radeon_init(rdev); |
1373 | r = radeon_init(rdev); |
1116 | if (r) |
1374 | if (r) |
1117 | return r; |
1375 | return r; |
1118 | } |
1376 | } |
- | 1377 | ||
1119 | // if (radeon_testing) { |
1378 | if ((radeon_testing & 1)) { |
- | 1379 | if (rdev->accel_working) |
|
1120 | // radeon_test_moves(rdev); |
1380 | radeon_test_moves(rdev); |
1121 | // } |
1381 | else |
- | 1382 | DRM_INFO("radeon: acceleration disabled, skipping move tests\n"); |
|
- | 1383 | } |
|
1122 | // if ((radeon_testing & 2)) { |
1384 | if ((radeon_testing & 2)) { |
- | 1385 | if (rdev->accel_working) |
|
1123 | // radeon_test_syncing(rdev); |
1386 | radeon_test_syncing(rdev); |
- | 1387 | else |
|
- | 1388 | DRM_INFO("radeon: acceleration disabled, skipping sync tests\n"); |
|
1124 | // } |
1389 | } |
1125 | if (radeon_benchmarking) { |
1390 | if (radeon_benchmarking) { |
- | 1391 | if (rdev->accel_working) |
|
1126 | radeon_benchmark(rdev, radeon_benchmarking); |
1392 | radeon_benchmark(rdev, radeon_benchmarking); |
- | 1393 | else |
|
- | 1394 | DRM_INFO("radeon: acceleration disabled, skipping benchmarks\n"); |
|
1127 | } |
1395 | } |
1128 | return 0; |
1396 | return 0; |
1129 | } |
1397 | } |
1130 | 1398 | ||
1131 | /** |
1399 | /** |
1132 | * radeon_gpu_reset - reset the asic |
1400 | * radeon_gpu_reset - reset the asic |
1133 | * |
1401 | * |
1134 | * @rdev: radeon device pointer |
1402 | * @rdev: radeon device pointer |
1135 | * |
1403 | * |
1136 | * Attempt the reset the GPU if it has hung (all asics). |
1404 | * Attempt the reset the GPU if it has hung (all asics). |
1137 | * Returns 0 for success or an error on failure. |
1405 | * Returns 0 for success or an error on failure. |
1138 | */ |
1406 | */ |
1139 | int radeon_gpu_reset(struct radeon_device *rdev) |
1407 | int radeon_gpu_reset(struct radeon_device *rdev) |
1140 | { |
1408 | { |
1141 | unsigned ring_sizes[RADEON_NUM_RINGS]; |
1409 | unsigned ring_sizes[RADEON_NUM_RINGS]; |
1142 | uint32_t *ring_data[RADEON_NUM_RINGS]; |
1410 | uint32_t *ring_data[RADEON_NUM_RINGS]; |
1143 | 1411 | ||
1144 | bool saved = false; |
1412 | bool saved = false; |
1145 | 1413 | ||
1146 | int i, r; |
1414 | int i, r; |
1147 | int resched; |
1415 | int resched; |
1148 | 1416 | ||
1149 | // down_write(&rdev->exclusive_lock); |
1417 | // down_write(&rdev->exclusive_lock); |
- | 1418 | rdev->needs_reset = false; |
|
- | 1419 | ||
1150 | radeon_save_bios_scratch_regs(rdev); |
1420 | radeon_save_bios_scratch_regs(rdev); |
1151 | /* block TTM */ |
1421 | /* block TTM */ |
1152 | // resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev); |
1422 | // resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev); |
1153 | radeon_suspend(rdev); |
1423 | radeon_suspend(rdev); |
1154 | 1424 | ||
1155 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { |
1425 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { |
1156 | ring_sizes[i] = radeon_ring_backup(rdev, &rdev->ring[i], |
1426 | ring_sizes[i] = radeon_ring_backup(rdev, &rdev->ring[i], |
1157 | &ring_data[i]); |
1427 | &ring_data[i]); |
1158 | if (ring_sizes[i]) { |
1428 | if (ring_sizes[i]) { |
1159 | saved = true; |
1429 | saved = true; |
1160 | dev_info(rdev->dev, "Saved %d dwords of commands " |
1430 | dev_info(rdev->dev, "Saved %d dwords of commands " |
1161 | "on ring %d.\n", ring_sizes[i], i); |
1431 | "on ring %d.\n", ring_sizes[i], i); |
1162 | } |
1432 | } |
1163 | } |
1433 | } |
1164 | 1434 | ||
1165 | retry: |
1435 | retry: |
1166 | r = radeon_asic_reset(rdev); |
1436 | r = radeon_asic_reset(rdev); |
1167 | if (!r) { |
1437 | if (!r) { |
1168 | dev_info(rdev->dev, "GPU reset succeeded, trying to resume\n"); |
1438 | dev_info(rdev->dev, "GPU reset succeeded, trying to resume\n"); |
1169 | radeon_resume(rdev); |
1439 | radeon_resume(rdev); |
1170 | } |
1440 | } |
1171 | 1441 | ||
1172 | radeon_restore_bios_scratch_regs(rdev); |
1442 | radeon_restore_bios_scratch_regs(rdev); |
1173 | 1443 | ||
1174 | if (!r) { |
1444 | if (!r) { |
1175 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { |
1445 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { |
1176 | radeon_ring_restore(rdev, &rdev->ring[i], |
1446 | radeon_ring_restore(rdev, &rdev->ring[i], |
1177 | ring_sizes[i], ring_data[i]); |
1447 | ring_sizes[i], ring_data[i]); |
1178 | ring_sizes[i] = 0; |
1448 | ring_sizes[i] = 0; |
1179 | ring_data[i] = NULL; |
1449 | ring_data[i] = NULL; |
1180 | } |
1450 | } |
1181 | 1451 | ||
1182 | // r = radeon_ib_ring_tests(rdev); |
1452 | // r = radeon_ib_ring_tests(rdev); |
1183 | // if (r) { |
1453 | // if (r) { |
1184 | // dev_err(rdev->dev, "ib ring test failed (%d).\n", r); |
1454 | // dev_err(rdev->dev, "ib ring test failed (%d).\n", r); |
1185 | // if (saved) { |
1455 | // if (saved) { |
1186 | // saved = false; |
1456 | // saved = false; |
1187 | // radeon_suspend(rdev); |
1457 | // radeon_suspend(rdev); |
1188 | // goto retry; |
1458 | // goto retry; |
1189 | // } |
1459 | // } |
1190 | // } |
1460 | // } |
1191 | } else { |
1461 | } else { |
1192 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { |
1462 | for (i = 0; i < RADEON_NUM_RINGS; ++i) { |
1193 | kfree(ring_data[i]); |
1463 | kfree(ring_data[i]); |
1194 | } |
1464 | } |
1195 | } |
1465 | } |
1196 | 1466 | ||
1197 | // ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched); |
1467 | // ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched); |
1198 | if (r) { |
1468 | if (r) { |
1199 | /* bad news, how to tell it to userspace ? */ |
1469 | /* bad news, how to tell it to userspace ? */ |
1200 | dev_info(rdev->dev, "GPU reset failed\n"); |
1470 | dev_info(rdev->dev, "GPU reset failed\n"); |
1201 | } |
1471 | } |
1202 | 1472 | ||
1203 | // up_write(&rdev->exclusive_lock); |
1473 | // up_write(&rdev->exclusive_lock); |
1204 | return r; |
1474 | return r; |
1205 | } |
1475 | } |
1206 | 1476 | ||
1207 | 1477 | ||
1208 | /* |
1478 | /* |
1209 | * Driver load/unload |
1479 | * Driver load/unload |
1210 | */ |
1480 | */ |
1211 | int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags) |
1481 | int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags) |
1212 | { |
1482 | { |
1213 | struct radeon_device *rdev; |
1483 | struct radeon_device *rdev; |
1214 | int r; |
1484 | int r; |
1215 | 1485 | ||
1216 | 1486 | ||
1217 | rdev = kzalloc(sizeof(struct radeon_device), GFP_KERNEL); |
1487 | rdev = kzalloc(sizeof(struct radeon_device), GFP_KERNEL); |
1218 | if (rdev == NULL) { |
1488 | if (rdev == NULL) { |
1219 | return -ENOMEM; |
1489 | return -ENOMEM; |
1220 | }; |
1490 | }; |
1221 | 1491 | ||
1222 | dev->dev_private = (void *)rdev; |
1492 | dev->dev_private = (void *)rdev; |
1223 | 1493 | ||
1224 | /* update BUS flag */ |
1494 | /* update BUS flag */ |
1225 | if (drm_device_is_agp(dev)) { |
1495 | if (drm_device_is_agp(dev)) { |
1226 | flags |= RADEON_IS_AGP; |
1496 | flags |= RADEON_IS_AGP; |
1227 | } else if (drm_device_is_pcie(dev)) { |
1497 | } else if (drm_device_is_pcie(dev)) { |
1228 | flags |= RADEON_IS_PCIE; |
1498 | flags |= RADEON_IS_PCIE; |
1229 | } else { |
1499 | } else { |
1230 | flags |= RADEON_IS_PCI; |
1500 | flags |= RADEON_IS_PCI; |
1231 | } |
1501 | } |
1232 | 1502 | ||
1233 | /* radeon_device_init should report only fatal error |
1503 | /* radeon_device_init should report only fatal error |
1234 | * like memory allocation failure or iomapping failure, |
1504 | * like memory allocation failure or iomapping failure, |
1235 | * or memory manager initialization failure, it must |
1505 | * or memory manager initialization failure, it must |
1236 | * properly initialize the GPU MC controller and permit |
1506 | * properly initialize the GPU MC controller and permit |
1237 | * VRAM allocation |
1507 | * VRAM allocation |
1238 | */ |
1508 | */ |
1239 | r = radeon_device_init(rdev, dev, dev->pdev, flags); |
1509 | r = radeon_device_init(rdev, dev, dev->pdev, flags); |
1240 | if (r) { |
1510 | if (r) { |
1241 | DRM_ERROR("Fatal error while trying to initialize radeon.\n"); |
1511 | DRM_ERROR("Fatal error while trying to initialize radeon.\n"); |
1242 | return r; |
1512 | return r; |
1243 | } |
1513 | } |
1244 | /* Again modeset_init should fail only on fatal error |
1514 | /* Again modeset_init should fail only on fatal error |
1245 | * otherwise it should provide enough functionalities |
1515 | * otherwise it should provide enough functionalities |
1246 | * for shadowfb to run |
1516 | * for shadowfb to run |
1247 | */ |
1517 | */ |
- | 1518 | main_device = dev; |
|
- | 1519 | ||
1248 | if( radeon_modeset ) |
1520 | if( radeon_modeset ) |
1249 | { |
1521 | { |
1250 | r = radeon_modeset_init(rdev); |
1522 | r = radeon_modeset_init(rdev); |
1251 | if (r) { |
1523 | if (r) { |
1252 | return r; |
1524 | return r; |
1253 | } |
1525 | } |
1254 | }; |
- | |
1255 | return 0; |
1526 | init_display_kms(dev, &usermode); |
1256 | } |
1527 | } |
1257 | - | ||
1258 | videomode_t usermode; |
- | |
1259 | - | ||
1260 | - | ||
1261 | int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent) |
- | |
1262 | { |
- | |
1263 | static struct drm_device *dev; |
- | |
1264 | int ret; |
- | |
1265 | - | ||
1266 | dev = kzalloc(sizeof(*dev), 0); |
- | |
1267 | if (!dev) |
- | |
1268 | return -ENOMEM; |
- | |
1269 | - | ||
1270 | // ret = pci_enable_device(pdev); |
- | |
1271 | // if (ret) |
- | |
1272 | // goto err_g1; |
- | |
1273 | - | ||
1274 | // pci_set_master(pdev); |
- | |
1275 | - | ||
1276 | // if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) { |
- | |
1277 | // printk(KERN_ERR "DRM: Fill_in_dev failed.\n"); |
- | |
1278 | // goto err_g2; |
- | |
1279 | // } |
- | |
1280 | - | ||
1281 | dev->pdev = pdev; |
- | |
1282 | dev->pci_device = pdev->device; |
- | |
1283 | dev->pci_vendor = pdev->vendor; |
- | |
1284 | - | ||
1285 | INIT_LIST_HEAD(&dev->filelist); |
- | |
1286 | INIT_LIST_HEAD(&dev->ctxlist); |
- | |
1287 | INIT_LIST_HEAD(&dev->vmalist); |
- | |
1288 | INIT_LIST_HEAD(&dev->maplist); |
- | |
1289 | - | ||
1290 | spin_lock_init(&dev->count_lock); |
- | |
1291 | mutex_init(&dev->struct_mutex); |
- | |
1292 | mutex_init(&dev->ctxlist_mutex); |
- | |
1293 | - | ||
1294 | - | ||
1295 | ret = radeon_driver_load_kms(dev, ent->driver_data ); |
- | |
1296 | if (ret) |
- | |
1297 | goto err_g4; |
- | |
1298 | - | ||
1299 | main_drm_device = dev; |
- | |
1300 | - | ||
1301 | if( radeon_modeset ) |
- | |
1302 | init_display_kms(dev->dev_private, &usermode); |
- | |
1303 | else |
1528 | else |
1304 | init_display(dev->dev_private, &usermode); |
1529 | init_display(rdev, &usermode); |
1305 | - | ||
1306 | 1530 | ||
- | 1531 | return 0; |
|
1307 | return 0; |
- | |
1308 | - | ||
1309 | err_g4: |
- | |
1310 | // drm_put_minor(&dev->primary); |
- | |
1311 | //err_g3: |
- | |
1312 | // if (drm_core_check_feature(dev, DRIVER_MODESET)) |
- | |
1313 | // drm_put_minor(&dev->control); |
- | |
1314 | //err_g2: |
- | |
1315 | // pci_disable_device(pdev); |
- | |
1316 | //err_g1: |
- | |
1317 | free(dev); |
- | |
1318 | - | ||
1319 | LEAVE(); |
- | |
1320 | 1532 | } |
|
1321 | return ret; |
1533 | |
1322 | } |
1534 | |
1323 | 1535 | ||
1324 | resource_size_t drm_get_resource_start(struct drm_device *dev, unsigned int resource) |
1536 | resource_size_t drm_get_resource_start(struct drm_device *dev, unsigned int resource) |
1325 | { |
1537 | { |
1326 | return pci_resource_start(dev->pdev, resource); |
1538 | return pci_resource_start(dev->pdev, resource); |
1327 | } |
1539 | } |
1328 | 1540 | ||
1329 | resource_size_t drm_get_resource_len(struct drm_device *dev, unsigned int resource) |
1541 | resource_size_t drm_get_resource_len(struct drm_device *dev, unsigned int resource) |
1330 | { |
1542 | { |
1331 | return pci_resource_len(dev->pdev, resource); |
1543 | return pci_resource_len(dev->pdev, resource); |
1332 | } |
1544 | } |
1333 | 1545 | ||
1334 | 1546 | ||
1335 | uint32_t __div64_32(uint64_t *n, uint32_t base) |
1547 | uint32_t __div64_32(uint64_t *n, uint32_t base) |
1336 | { |
1548 | { |
1337 | uint64_t rem = *n; |
1549 | uint64_t rem = *n; |
1338 | uint64_t b = base; |
1550 | uint64_t b = base; |
1339 | uint64_t res, d = 1; |
1551 | uint64_t res, d = 1; |
1340 | uint32_t high = rem >> 32; |
1552 | uint32_t high = rem >> 32; |
1341 | 1553 | ||
1342 | /* Reduce the thing a bit first */ |
1554 | /* Reduce the thing a bit first */ |
1343 | res = 0; |
1555 | res = 0; |
1344 | if (high >= base) { |
1556 | if (high >= base) { |
1345 | high /= base; |
1557 | high /= base; |
1346 | res = (uint64_t) high << 32; |
1558 | res = (uint64_t) high << 32; |
1347 | rem -= (uint64_t) (high*base) << 32; |
1559 | rem -= (uint64_t) (high*base) << 32; |
1348 | } |
1560 | } |
1349 | 1561 | ||
1350 | while ((int64_t)b > 0 && b < rem) { |
1562 | while ((int64_t)b > 0 && b < rem) { |
1351 | b = b+b; |
1563 | b = b+b; |
1352 | d = d+d; |
1564 | d = d+d; |
1353 | } |
1565 | } |
1354 | 1566 | ||
1355 | do { |
1567 | do { |
1356 | if (rem >= b) { |
1568 | if (rem >= b) { |
1357 | rem -= b; |
1569 | rem -= b; |
1358 | res += d; |
1570 | res += d; |
1359 | } |
1571 | } |
1360 | b >>= 1; |
1572 | b >>= 1; |
1361 | d >>= 1; |
1573 | d >>= 1; |
1362 | } while (d); |
1574 | } while (d); |
1363 | 1575 | ||
1364 | *n = res; |
1576 | *n = res; |
1365 | return rem; |
1577 | return rem; |
1366 | } |
1578 | } |
1367 | - | ||
1368 | 1579 | ||
1369 | static struct pci_device_id pciidlist[] = { |
1580 | static struct pci_device_id pciidlist[] = { |
1370 | radeon_PCI_IDS |
1581 | radeon_PCI_IDS |
1371 | }; |
1582 | }; |
- | 1583 | ||
- | 1584 | void radeon_driver_irq_preinstall_kms(struct drm_device *dev); |
|
- | 1585 | int radeon_driver_irq_postinstall_kms(struct drm_device *dev); |
|
- | 1586 | void radeon_driver_irq_uninstall_kms(struct drm_device *dev); |
|
- | 1587 | irqreturn_t radeon_driver_irq_handler_kms(int irq, void *arg); |
|
- | 1588 | ||
- | 1589 | ||
- | 1590 | static struct drm_driver kms_driver = { |
|
- | 1591 | .driver_features = |
|
- | 1592 | DRIVER_USE_AGP | |
|
- | 1593 | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | |
|
- | 1594 | DRIVER_PRIME | DRIVER_RENDER, |
|
- | 1595 | .load = radeon_driver_load_kms, |
|
- | 1596 | // .open = radeon_driver_open_kms, |
|
- | 1597 | // .preclose = radeon_driver_preclose_kms, |
|
- | 1598 | // .postclose = radeon_driver_postclose_kms, |
|
- | 1599 | // .lastclose = radeon_driver_lastclose_kms, |
|
- | 1600 | // .unload = radeon_driver_unload_kms, |
|
- | 1601 | // .get_vblank_counter = radeon_get_vblank_counter_kms, |
|
- | 1602 | // .enable_vblank = radeon_enable_vblank_kms, |
|
- | 1603 | // .disable_vblank = radeon_disable_vblank_kms, |
|
- | 1604 | // .get_vblank_timestamp = radeon_get_vblank_timestamp_kms, |
|
- | 1605 | // .get_scanout_position = radeon_get_crtc_scanoutpos, |
|
- | 1606 | #if defined(CONFIG_DEBUG_FS) |
|
- | 1607 | .debugfs_init = radeon_debugfs_init, |
|
- | 1608 | .debugfs_cleanup = radeon_debugfs_cleanup, |
|
- | 1609 | #endif |
|
- | 1610 | .irq_preinstall = radeon_driver_irq_preinstall_kms, |
|
- | 1611 | .irq_postinstall = radeon_driver_irq_postinstall_kms, |
|
- | 1612 | .irq_uninstall = radeon_driver_irq_uninstall_kms, |
|
- | 1613 | .irq_handler = radeon_driver_irq_handler_kms, |
|
- | 1614 | // .ioctls = radeon_ioctls_kms, |
|
- | 1615 | // .gem_free_object = radeon_gem_object_free, |
|
- | 1616 | // .gem_open_object = radeon_gem_object_open, |
|
- | 1617 | // .gem_close_object = radeon_gem_object_close, |
|
- | 1618 | // .dumb_create = radeon_mode_dumb_create, |
|
- | 1619 | // .dumb_map_offset = radeon_mode_dumb_mmap, |
|
- | 1620 | // .dumb_destroy = drm_gem_dumb_destroy, |
|
- | 1621 | // .fops = &radeon_driver_kms_fops, |
|
- | 1622 | ||
- | 1623 | // .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
|
- | 1624 | // .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
|
- | 1625 | // .gem_prime_export = drm_gem_prime_export, |
|
- | 1626 | // .gem_prime_import = drm_gem_prime_import, |
|
- | 1627 | // .gem_prime_pin = radeon_gem_prime_pin, |
|
- | 1628 | // .gem_prime_unpin = radeon_gem_prime_unpin, |
|
- | 1629 | // .gem_prime_get_sg_table = radeon_gem_prime_get_sg_table, |
|
- | 1630 | // .gem_prime_import_sg_table = radeon_gem_prime_import_sg_table, |
|
- | 1631 | // .gem_prime_vmap = radeon_gem_prime_vmap, |
|
1372 | - | ||
1373 | - | ||
1374 | #define CURRENT_API 0x0200 /* 2.00 */ |
- | |
1375 | #define COMPATIBLE_API 0x0100 /* 1.00 */ |
- | |
1376 | - | ||
1377 | #define API_VERSION (COMPATIBLE_API << 16) | CURRENT_API |
- | |
1378 | - | ||
1379 | #define SRV_GETVERSION 0 |
- | |
1380 | #define SRV_ENUM_MODES 1 |
- | |
1381 | #define SRV_SET_MODE 2 |
- | |
1382 | #define SRV_GET_CAPS 3 |
- | |
1383 | - | ||
1384 | #define SRV_CREATE_SURFACE 10 |
- | |
1385 | #define SRV_DESTROY_SURFACE 11 |
- | |
1386 | #define SRV_LOCK_SURFACE 12 |
- | |
1387 | #define SRV_UNLOCK_SURFACE 13 |
- | |
1388 | #define SRV_RESIZE_SURFACE 14 |
- | |
1389 | #define SRV_BLIT_BITMAP 15 |
- | |
1390 | #define SRV_BLIT_TEXTURE 16 |
- | |
1391 | #define SRV_BLIT_VIDEO 17 |
- | |
1392 | - | ||
1393 | - | ||
1394 | - | ||
1395 | int r600_video_blit(uint64_t src_offset, int x, int y, |
- | |
1396 | int w, int h, int pitch); |
- | |
1397 | - | ||
1398 | #define check_input(size) \ |
- | |
1399 | if( unlikely((inp==NULL)||(io->inp_size != (size))) ) \ |
- | |
1400 | break; |
- | |
1401 | - | ||
1402 | #define check_output(size) \ |
- | |
1403 | if( unlikely((outp==NULL)||(io->out_size != (size))) ) \ |
- | |
1404 | break; |
- | |
1405 | - | ||
1406 | int _stdcall display_handler(ioctl_t *io) |
- | |
1407 | { |
- | |
1408 | int retval = -1; |
- | |
1409 | u32_t *inp; |
- | |
1410 | u32_t *outp; |
- | |
1411 | - | ||
1412 | inp = io->input; |
- | |
1413 | outp = io->output; |
- | |
1414 | - | ||
1415 | switch(io->io_code) |
- | |
1416 | { |
- | |
1417 | case SRV_GETVERSION: |
- | |
1418 | check_output(4); |
- | |
1419 | *outp = API_VERSION; |
- | |
1420 | retval = 0; |
- | |
1421 | break; |
- | |
1422 | - | ||
1423 | case SRV_ENUM_MODES: |
- | |
1424 | dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n", |
- | |
1425 | inp, io->inp_size, io->out_size ); |
- | |
1426 | check_output(4); |
- | |
1427 | if( radeon_modeset) |
- | |
1428 | retval = get_modes((videomode_t*)inp, outp); |
- | |
1429 | break; |
- | |
1430 | - | ||
1431 | case SRV_SET_MODE: |
- | |
1432 | dbgprintf("SRV_SET_MODE inp %x inp_size %x\n", |
- | |
1433 | inp, io->inp_size); |
- | |
1434 | check_input(sizeof(videomode_t)); |
- | |
1435 | if( radeon_modeset ) |
- | |
1436 | retval = set_user_mode((videomode_t*)inp); |
- | |
1437 | break; |
- | |
1438 | /* |
- | |
1439 | case SRV_GET_CAPS: |
- | |
1440 | retval = get_driver_caps((hwcaps_t*)inp); |
- | |
1441 | break; |
- | |
1442 | - | ||
1443 | case SRV_CREATE_SURFACE: |
- | |
1444 | // check_input(8); |
- | |
1445 | retval = create_surface(main_drm_device, (struct io_call_10*)inp); |
- | |
1446 | break; |
- | |
1447 | - | ||
1448 | case SRV_LOCK_SURFACE: |
- | |
1449 | retval = lock_surface((struct io_call_12*)inp); |
- | |
1450 | break; |
- | |
1451 | - | ||
1452 | case SRV_BLIT_BITMAP: |
- | |
1453 | srv_blit_bitmap( inp[0], inp[1], inp[2], |
- | |
1454 | inp[3], inp[4], inp[5], inp[6]); |
1632 | // .gem_prime_vunmap = radeon_gem_prime_vunmap, |
1455 | */ |
- | |
1456 | }; |
- | |
1457 | - | ||
1458 | return retval; |
- | |
1459 | } |
1633 | |
1460 | - | ||
1461 | static char log[256]; |
- | |
1462 | static pci_dev_t device; |
1634 | }; |
1463 | 1635 | ||
1464 | u32_t drvEntry(int action, char *cmdline) |
- | |
1465 | { |
1636 | int ati_init(void) |
1466 | struct radeon_device *rdev = NULL; |
- | |
1467 | 1637 | { |
|
1468 | const struct pci_device_id *ent; |
- | |
1469 | - | ||
1470 | int err; |
- | |
1471 | u32_t retval = 0; |
- | |
1472 | - | ||
1473 | if(action != 1) |
- | |
1474 | return 0; |
- | |
1475 | - | ||
1476 | if( GetService("DISPLAY") != 0 ) |
- | |
1477 | return 0; |
- | |
1478 | - | ||
1479 | if( cmdline && *cmdline ) |
- | |
1480 | parse_cmdline(cmdline, &usermode, log, &radeon_modeset); |
- | |
1481 | - | ||
1482 | if(!dbg_open(log)) |
- | |
1483 | { |
- | |
1484 | strcpy(log, "/TMP1/1/ati.log"); |
- | |
1485 | - | ||
1486 | if(!dbg_open(log)) |
- | |
1487 | { |
- | |
1488 | printf("Can't open %s\nExit\n", log); |
- | |
1489 | return 0; |
- | |
1490 | }; |
- | |
1491 | } |
- | |
1492 | dbgprintf("Radeon v3.10 preview-1 cmdline %s\n", cmdline); |
- | |
1493 | - | ||
1494 | cpu_detect(); |
1638 | static pci_dev_t device; |
1495 | - | ||
1496 | enum_pci_devices(); |
1639 | const struct pci_device_id *ent; |
1497 | 1640 | int err; |
|
1498 | ent = find_pci_device(&device, pciidlist); |
1641 | |
1499 | 1642 | ent = find_pci_device(&device, pciidlist); |
|
1500 | if( unlikely(ent == NULL) ) |
1643 | if( unlikely(ent == NULL) ) |
1501 | { |
1644 | { |
1502 | dbgprintf("device not found\n"); |
1645 | dbgprintf("device not found\n"); |
1503 | return 0; |
1646 | return -ENODEV; |
1504 | }; |
1647 | }; |
1505 | - | ||
1506 | dbgprintf("device %x:%x\n", device.pci_dev.vendor, |
- | |
1507 | device.pci_dev.device); |
- | |
1508 | 1648 | ||
1509 | drm_global_init(); |
- | |
1510 | - | ||
1511 | err = drm_get_dev(&device.pci_dev, ent); |
1649 | drm_core_init(); |
- | 1650 | ||
1512 | 1651 | DRM_INFO("device %x:%x\n", device.pci_dev.vendor, |
|
1513 | rdev = rdisplay->ddev->dev_private; |
- | |
1514 | 1652 | device.pci_dev.device); |
|
1515 | err = RegService("DISPLAY", display_handler); |
1653 | |
1516 | - | ||
1517 | if( err != 0) |
- | |
1518 | dbgprintf("Set DISPLAY handler\n"); |
- | |
1519 | - | ||
1520 | return err; |
- | |
1521 | }; |
- | |
1522 | - | ||
1523 | #define PCI_CLASS_REVISION 0x08 |
- | |
1524 | #define PCI_CLASS_DISPLAY_VGA 0x0300 |
- | |
1525 | - | ||
1526 | int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn) |
- | |
1527 | { |
- | |
1528 | u16_t vendor, device; |
- | |
1529 | u32_t class; |
- | |
1530 | int ret = 0; |
- | |
1531 | - | ||
1532 | vendor = id & 0xffff; |
- | |
1533 | device = (id >> 16) & 0xffff; |
- | |
1534 | - | ||
1535 | if(vendor == 0x1002) |
- | |
1536 | { |
- | |
1537 | class = PciRead32(busnr, devfn, PCI_CLASS_REVISION); |
- | |
1538 | class >>= 16; |
- | |
1539 | 1654 | kms_driver.driver_features |= DRIVER_MODESET; |
|
- | 1655 | ||
1540 | if( class == PCI_CLASS_DISPLAY_VGA) |
1656 | err = drm_get_pci_dev(&device.pci_dev, ent, &kms_driver); |
1541 | ret = 1; |
1657 | |
1542 | } |
1658 | return err; |
1543 | return ret; |
1659 | }>><>><>>>>>=>><>>><>>>=>>><>>>=>><>>>>>>>>>>>><>><> |
1544 | }><>>><>><>>>>>=>><>><>>><>>>=>><>>>>>>>>> |
- |