blob: 4ee0c53b28a78b380642dc7d3d1f79afe62ef981 [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
28#include <linux/console.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020030#include <drm/drmP.h>
31#include <drm/drm_crtc_helper.h>
32#include <drm/radeon_drm.h>
Dave Airlie28d52042009-09-21 14:33:58 +100033#include <linux/vgaarb.h>
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100034#include <linux/vga_switcheroo.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020035#include "radeon_reg.h"
36#include "radeon.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020037#include "atom.h"
38
Jerome Glisse1b5331d2010-04-12 20:21:53 +000039static const char radeon_family_name[][16] = {
40 "R100",
41 "RV100",
42 "RS100",
43 "RV200",
44 "RS200",
45 "R200",
46 "RV250",
47 "RS300",
48 "RV280",
49 "R300",
50 "R350",
51 "RV350",
52 "RV380",
53 "R420",
54 "R423",
55 "RV410",
56 "RS400",
57 "RS480",
58 "RS600",
59 "RS690",
60 "RS740",
61 "RV515",
62 "R520",
63 "RV530",
64 "RV560",
65 "RV570",
66 "R580",
67 "R600",
68 "RV610",
69 "RV630",
70 "RV670",
71 "RV620",
72 "RV635",
73 "RS780",
74 "RS880",
75 "RV770",
76 "RV730",
77 "RV710",
78 "RV740",
79 "CEDAR",
80 "REDWOOD",
81 "JUNIPER",
82 "CYPRESS",
83 "HEMLOCK",
Alex Deucherb08ebe7e2010-12-03 15:34:16 -050084 "PALM",
Jerome Glisse1b5331d2010-04-12 20:21:53 +000085 "LAST",
86};
87
Jerome Glisse771fe6b2009-06-05 14:42:42 +020088/*
Michel Dänzerb1e3a6d2009-06-23 16:12:54 +020089 * Clear GPU surface registers.
90 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +100091void radeon_surface_init(struct radeon_device *rdev)
Michel Dänzerb1e3a6d2009-06-23 16:12:54 +020092{
93 /* FIXME: check this out */
94 if (rdev->family < CHIP_R600) {
95 int i;
96
Dave Airlie550e2d92009-12-09 14:15:38 +100097 for (i = 0; i < RADEON_GEM_MAX_SURFACES; i++) {
98 if (rdev->surface_regs[i].bo)
99 radeon_bo_get_surface_reg(rdev->surface_regs[i].bo);
100 else
101 radeon_clear_surface_reg(rdev, i);
Michel Dänzerb1e3a6d2009-06-23 16:12:54 +0200102 }
Dave Airliee024e112009-06-24 09:48:08 +1000103 /* enable surfaces */
104 WREG32(RADEON_SURFACE_CNTL, 0);
Michel Dänzerb1e3a6d2009-06-23 16:12:54 +0200105 }
106}
107
108/*
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200109 * GPU scratch registers helpers function.
110 */
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000111void radeon_scratch_init(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200112{
113 int i;
114
115 /* FIXME: check this out */
116 if (rdev->family < CHIP_R300) {
117 rdev->scratch.num_reg = 5;
118 } else {
119 rdev->scratch.num_reg = 7;
120 }
Alex Deucher724c80e2010-08-27 18:25:25 -0400121 rdev->scratch.reg_base = RADEON_SCRATCH_REG0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200122 for (i = 0; i < rdev->scratch.num_reg; i++) {
123 rdev->scratch.free[i] = true;
Alex Deucher724c80e2010-08-27 18:25:25 -0400124 rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200125 }
126}
127
128int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg)
129{
130 int i;
131
132 for (i = 0; i < rdev->scratch.num_reg; i++) {
133 if (rdev->scratch.free[i]) {
134 rdev->scratch.free[i] = false;
135 *reg = rdev->scratch.reg[i];
136 return 0;
137 }
138 }
139 return -EINVAL;
140}
141
142void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg)
143{
144 int i;
145
146 for (i = 0; i < rdev->scratch.num_reg; i++) {
147 if (rdev->scratch.reg[i] == reg) {
148 rdev->scratch.free[i] = true;
149 return;
150 }
151 }
152}
153
Alex Deucher724c80e2010-08-27 18:25:25 -0400154void radeon_wb_disable(struct radeon_device *rdev)
155{
156 int r;
157
158 if (rdev->wb.wb_obj) {
159 r = radeon_bo_reserve(rdev->wb.wb_obj, false);
160 if (unlikely(r != 0))
161 return;
162 radeon_bo_kunmap(rdev->wb.wb_obj);
163 radeon_bo_unpin(rdev->wb.wb_obj);
164 radeon_bo_unreserve(rdev->wb.wb_obj);
165 }
166 rdev->wb.enabled = false;
167}
168
169void radeon_wb_fini(struct radeon_device *rdev)
170{
171 radeon_wb_disable(rdev);
172 if (rdev->wb.wb_obj) {
173 radeon_bo_unref(&rdev->wb.wb_obj);
174 rdev->wb.wb = NULL;
175 rdev->wb.wb_obj = NULL;
176 }
177}
178
179int radeon_wb_init(struct radeon_device *rdev)
180{
181 int r;
182
183 if (rdev->wb.wb_obj == NULL) {
Alex Deucher268b2512010-11-17 19:00:26 -0500184 r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
Alex Deucher724c80e2010-08-27 18:25:25 -0400185 RADEON_GEM_DOMAIN_GTT, &rdev->wb.wb_obj);
186 if (r) {
187 dev_warn(rdev->dev, "(%d) create WB bo failed\n", r);
188 return r;
189 }
190 }
191 r = radeon_bo_reserve(rdev->wb.wb_obj, false);
192 if (unlikely(r != 0)) {
193 radeon_wb_fini(rdev);
194 return r;
195 }
196 r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT,
197 &rdev->wb.gpu_addr);
198 if (r) {
199 radeon_bo_unreserve(rdev->wb.wb_obj);
200 dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r);
201 radeon_wb_fini(rdev);
202 return r;
203 }
204 r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb);
205 radeon_bo_unreserve(rdev->wb.wb_obj);
206 if (r) {
207 dev_warn(rdev->dev, "(%d) map WB bo failed\n", r);
208 radeon_wb_fini(rdev);
209 return r;
210 }
211
Alex Deucherd0f8a852010-09-04 05:04:34 -0400212 /* disable event_write fences */
213 rdev->wb.use_event = false;
Alex Deucher724c80e2010-08-27 18:25:25 -0400214 /* disabled via module param */
215 if (radeon_no_wb == 1)
216 rdev->wb.enabled = false;
217 else {
218 /* often unreliable on AGP */
219 if (rdev->flags & RADEON_IS_AGP) {
220 rdev->wb.enabled = false;
Alex Deucherd0f8a852010-09-04 05:04:34 -0400221 } else {
Alex Deucher724c80e2010-08-27 18:25:25 -0400222 rdev->wb.enabled = true;
Alex Deucherd0f8a852010-09-04 05:04:34 -0400223 /* event_write fences are only available on r600+ */
224 if (rdev->family >= CHIP_R600)
225 rdev->wb.use_event = true;
226 }
Alex Deucher724c80e2010-08-27 18:25:25 -0400227 }
228
229 dev_info(rdev->dev, "WB %sabled\n", rdev->wb.enabled ? "en" : "dis");
230
231 return 0;
232}
233
Jerome Glissed594e462010-02-17 21:54:29 +0000234/**
235 * radeon_vram_location - try to find VRAM location
236 * @rdev: radeon device structure holding all necessary informations
237 * @mc: memory controller structure holding memory informations
238 * @base: base address at which to put VRAM
239 *
240 * Function will place try to place VRAM at base address provided
241 * as parameter (which is so far either PCI aperture address or
242 * for IGP TOM base address).
243 *
244 * If there is not enough space to fit the unvisible VRAM in the 32bits
245 * address space then we limit the VRAM size to the aperture.
246 *
247 * If we are using AGP and if the AGP aperture doesn't allow us to have
248 * room for all the VRAM than we restrict the VRAM to the PCI aperture
249 * size and print a warning.
250 *
251 * This function will never fails, worst case are limiting VRAM.
252 *
253 * Note: GTT start, end, size should be initialized before calling this
254 * function on AGP platform.
255 *
256 * Note: We don't explictly enforce VRAM start to be aligned on VRAM size,
257 * this shouldn't be a problem as we are using the PCI aperture as a reference.
258 * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but
259 * not IGP.
260 *
261 * Note: we use mc_vram_size as on some board we need to program the mc to
262 * cover the whole aperture even if VRAM size is inferior to aperture size
263 * Novell bug 204882 + along with lots of ubuntu ones
264 *
265 * Note: when limiting vram it's safe to overwritte real_vram_size because
266 * we are not in case where real_vram_size is inferior to mc_vram_size (ie
267 * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu
268 * ones)
269 *
270 * Note: IGP TOM addr should be the same as the aperture addr, we don't
271 * explicitly check for that thought.
272 *
273 * FIXME: when reducing VRAM size align new size on power of 2.
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200274 */
Jerome Glissed594e462010-02-17 21:54:29 +0000275void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200276{
Jerome Glissed594e462010-02-17 21:54:29 +0000277 mc->vram_start = base;
278 if (mc->mc_vram_size > (0xFFFFFFFF - base + 1)) {
279 dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n");
280 mc->real_vram_size = mc->aper_size;
281 mc->mc_vram_size = mc->aper_size;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200282 }
Jerome Glissed594e462010-02-17 21:54:29 +0000283 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
Jerome Glisse2cbeb4e2010-08-16 11:54:36 -0400284 if (rdev->flags & RADEON_IS_AGP && mc->vram_end > mc->gtt_start && mc->vram_start <= mc->gtt_end) {
Jerome Glissed594e462010-02-17 21:54:29 +0000285 dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n");
286 mc->real_vram_size = mc->aper_size;
287 mc->mc_vram_size = mc->aper_size;
288 }
289 mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
Alex Deucherdd7cc552010-12-03 14:37:21 -0500290 dev_info(rdev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n",
Jerome Glissed594e462010-02-17 21:54:29 +0000291 mc->mc_vram_size >> 20, mc->vram_start,
292 mc->vram_end, mc->real_vram_size >> 20);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200293}
294
Jerome Glissed594e462010-02-17 21:54:29 +0000295/**
296 * radeon_gtt_location - try to find GTT location
297 * @rdev: radeon device structure holding all necessary informations
298 * @mc: memory controller structure holding memory informations
299 *
300 * Function will place try to place GTT before or after VRAM.
301 *
302 * If GTT size is bigger than space left then we ajust GTT size.
303 * Thus function will never fails.
304 *
305 * FIXME: when reducing GTT size align new size on power of 2.
306 */
307void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
308{
309 u64 size_af, size_bf;
310
Alex Deucher8d369bb2010-07-15 10:51:10 -0400311 size_af = ((0xFFFFFFFF - mc->vram_end) + mc->gtt_base_align) & ~mc->gtt_base_align;
312 size_bf = mc->vram_start & ~mc->gtt_base_align;
Jerome Glissed594e462010-02-17 21:54:29 +0000313 if (size_bf > size_af) {
314 if (mc->gtt_size > size_bf) {
315 dev_warn(rdev->dev, "limiting GTT\n");
316 mc->gtt_size = size_bf;
317 }
Alex Deucher8d369bb2010-07-15 10:51:10 -0400318 mc->gtt_start = (mc->vram_start & ~mc->gtt_base_align) - mc->gtt_size;
Jerome Glissed594e462010-02-17 21:54:29 +0000319 } else {
320 if (mc->gtt_size > size_af) {
321 dev_warn(rdev->dev, "limiting GTT\n");
322 mc->gtt_size = size_af;
323 }
Alex Deucher8d369bb2010-07-15 10:51:10 -0400324 mc->gtt_start = (mc->vram_end + 1 + mc->gtt_base_align) & ~mc->gtt_base_align;
Jerome Glissed594e462010-02-17 21:54:29 +0000325 }
326 mc->gtt_end = mc->gtt_start + mc->gtt_size - 1;
Alex Deucherdd7cc552010-12-03 14:37:21 -0500327 dev_info(rdev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n",
Jerome Glissed594e462010-02-17 21:54:29 +0000328 mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end);
329}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200330
331/*
332 * GPU helpers function.
333 */
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200334bool radeon_card_posted(struct radeon_device *rdev)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200335{
336 uint32_t reg;
337
338 /* first check CRTCs */
Alex Deucher18007402010-11-22 17:56:28 -0500339 if (ASIC_IS_DCE41(rdev)) {
340 reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) |
341 RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET);
342 if (reg & EVERGREEN_CRTC_MASTER_EN)
343 return true;
344 } else if (ASIC_IS_DCE4(rdev)) {
Alex Deucherbcc1c2a2010-01-12 17:54:34 -0500345 reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) |
346 RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) |
347 RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) |
348 RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) |
349 RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) |
350 RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET);
351 if (reg & EVERGREEN_CRTC_MASTER_EN)
352 return true;
353 } else if (ASIC_IS_AVIVO(rdev)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200354 reg = RREG32(AVIVO_D1CRTC_CONTROL) |
355 RREG32(AVIVO_D2CRTC_CONTROL);
356 if (reg & AVIVO_CRTC_EN) {
357 return true;
358 }
359 } else {
360 reg = RREG32(RADEON_CRTC_GEN_CNTL) |
361 RREG32(RADEON_CRTC2_GEN_CNTL);
362 if (reg & RADEON_CRTC_EN) {
363 return true;
364 }
365 }
366
367 /* then check MEM_SIZE, in case the crtcs are off */
368 if (rdev->family >= CHIP_R600)
369 reg = RREG32(R600_CONFIG_MEMSIZE);
370 else
371 reg = RREG32(RADEON_CONFIG_MEMSIZE);
372
373 if (reg)
374 return true;
375
376 return false;
377
378}
379
Alex Deucherf47299c2010-03-16 20:54:38 -0400380void radeon_update_bandwidth_info(struct radeon_device *rdev)
381{
382 fixed20_12 a;
Alex Deucher88072862010-08-10 12:33:20 -0400383 u32 sclk = rdev->pm.current_sclk;
384 u32 mclk = rdev->pm.current_mclk;
385
386 /* sclk/mclk in Mhz */
387 a.full = dfixed_const(100);
388 rdev->pm.sclk.full = dfixed_const(sclk);
389 rdev->pm.sclk.full = dfixed_div(rdev->pm.sclk, a);
390 rdev->pm.mclk.full = dfixed_const(mclk);
391 rdev->pm.mclk.full = dfixed_div(rdev->pm.mclk, a);
Alex Deucherf47299c2010-03-16 20:54:38 -0400392
393 if (rdev->flags & RADEON_IS_IGP) {
Ben Skeggs68adac52010-04-28 11:46:42 +1000394 a.full = dfixed_const(16);
Alex Deucherf47299c2010-03-16 20:54:38 -0400395 /* core_bandwidth = sclk(Mhz) * 16 */
Ben Skeggs68adac52010-04-28 11:46:42 +1000396 rdev->pm.core_bandwidth.full = dfixed_div(rdev->pm.sclk, a);
Alex Deucherf47299c2010-03-16 20:54:38 -0400397 }
398}
399
Dave Airlie72542d72009-12-01 14:06:31 +1000400bool radeon_boot_test_post_card(struct radeon_device *rdev)
401{
402 if (radeon_card_posted(rdev))
403 return true;
404
405 if (rdev->bios) {
406 DRM_INFO("GPU not posted. posting now...\n");
407 if (rdev->is_atom_bios)
408 atom_asic_init(rdev->mode_info.atom_context);
409 else
410 radeon_combios_asic_init(rdev->ddev);
411 return true;
412 } else {
413 dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
414 return false;
415 }
416}
417
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000418int radeon_dummy_page_init(struct radeon_device *rdev)
419{
Dave Airlie82568562010-02-05 16:00:07 +1000420 if (rdev->dummy_page.page)
421 return 0;
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000422 rdev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO);
423 if (rdev->dummy_page.page == NULL)
424 return -ENOMEM;
425 rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page,
426 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
Benjamin Herrenschmidta30f6fb72010-08-10 14:48:58 +1000427 if (pci_dma_mapping_error(rdev->pdev, rdev->dummy_page.addr)) {
428 dev_err(&rdev->pdev->dev, "Failed to DMA MAP the dummy page\n");
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000429 __free_page(rdev->dummy_page.page);
430 rdev->dummy_page.page = NULL;
431 return -ENOMEM;
432 }
433 return 0;
434}
435
436void radeon_dummy_page_fini(struct radeon_device *rdev)
437{
438 if (rdev->dummy_page.page == NULL)
439 return;
440 pci_unmap_page(rdev->pdev, rdev->dummy_page.addr,
441 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
442 __free_page(rdev->dummy_page.page);
443 rdev->dummy_page.page = NULL;
444}
445
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200446
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200447/* ATOM accessor methods */
448static uint32_t cail_pll_read(struct card_info *info, uint32_t reg)
449{
450 struct radeon_device *rdev = info->dev->dev_private;
451 uint32_t r;
452
453 r = rdev->pll_rreg(rdev, reg);
454 return r;
455}
456
457static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val)
458{
459 struct radeon_device *rdev = info->dev->dev_private;
460
461 rdev->pll_wreg(rdev, reg, val);
462}
463
464static uint32_t cail_mc_read(struct card_info *info, uint32_t reg)
465{
466 struct radeon_device *rdev = info->dev->dev_private;
467 uint32_t r;
468
469 r = rdev->mc_rreg(rdev, reg);
470 return r;
471}
472
473static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val)
474{
475 struct radeon_device *rdev = info->dev->dev_private;
476
477 rdev->mc_wreg(rdev, reg, val);
478}
479
480static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val)
481{
482 struct radeon_device *rdev = info->dev->dev_private;
483
484 WREG32(reg*4, val);
485}
486
487static uint32_t cail_reg_read(struct card_info *info, uint32_t reg)
488{
489 struct radeon_device *rdev = info->dev->dev_private;
490 uint32_t r;
491
492 r = RREG32(reg*4);
493 return r;
494}
495
Alex Deucher351a52a2010-06-30 11:52:50 -0400496static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val)
497{
498 struct radeon_device *rdev = info->dev->dev_private;
499
500 WREG32_IO(reg*4, val);
501}
502
503static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg)
504{
505 struct radeon_device *rdev = info->dev->dev_private;
506 uint32_t r;
507
508 r = RREG32_IO(reg*4);
509 return r;
510}
511
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200512int radeon_atombios_init(struct radeon_device *rdev)
513{
Mathias Fröhlich61c4b242009-10-27 15:08:01 -0400514 struct card_info *atom_card_info =
515 kzalloc(sizeof(struct card_info), GFP_KERNEL);
516
517 if (!atom_card_info)
518 return -ENOMEM;
519
520 rdev->mode_info.atom_card_info = atom_card_info;
521 atom_card_info->dev = rdev->ddev;
522 atom_card_info->reg_read = cail_reg_read;
523 atom_card_info->reg_write = cail_reg_write;
Alex Deucher351a52a2010-06-30 11:52:50 -0400524 /* needed for iio ops */
525 if (rdev->rio_mem) {
526 atom_card_info->ioreg_read = cail_ioreg_read;
527 atom_card_info->ioreg_write = cail_ioreg_write;
528 } else {
529 DRM_ERROR("Unable to find PCI I/O BAR; using MMIO for ATOM IIO\n");
530 atom_card_info->ioreg_read = cail_reg_read;
531 atom_card_info->ioreg_write = cail_reg_write;
532 }
Mathias Fröhlich61c4b242009-10-27 15:08:01 -0400533 atom_card_info->mc_read = cail_mc_read;
534 atom_card_info->mc_write = cail_mc_write;
535 atom_card_info->pll_read = cail_pll_read;
536 atom_card_info->pll_write = cail_pll_write;
537
538 rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios);
Rafał Miłeckic31ad972009-12-17 00:00:46 +0100539 mutex_init(&rdev->mode_info.atom_context->mutex);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200540 radeon_atom_initialize_bios_scratch_regs(rdev->ddev);
Dave Airlied904ef92009-11-17 06:29:46 +1000541 atom_allocate_fb_scratch(rdev->mode_info.atom_context);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200542 return 0;
543}
544
545void radeon_atombios_fini(struct radeon_device *rdev)
546{
Jerome Glisse4a04a842009-12-09 17:39:16 +0100547 if (rdev->mode_info.atom_context) {
548 kfree(rdev->mode_info.atom_context->scratch);
549 kfree(rdev->mode_info.atom_context);
550 }
Mathias Fröhlich61c4b242009-10-27 15:08:01 -0400551 kfree(rdev->mode_info.atom_card_info);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200552}
553
554int radeon_combios_init(struct radeon_device *rdev)
555{
556 radeon_combios_initialize_bios_scratch_regs(rdev->ddev);
557 return 0;
558}
559
560void radeon_combios_fini(struct radeon_device *rdev)
561{
562}
563
Dave Airlie28d52042009-09-21 14:33:58 +1000564/* if we get transitioned to only one device, tak VGA back */
565static unsigned int radeon_vga_set_decode(void *cookie, bool state)
566{
567 struct radeon_device *rdev = cookie;
Dave Airlie28d52042009-09-21 14:33:58 +1000568 radeon_vga_set_state(rdev, state);
569 if (state)
570 return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
571 VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
572 else
573 return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
574}
Dave Airliec1176d62009-10-08 14:03:05 +1000575
Jerome Glisse36421332009-12-11 21:18:34 +0100576void radeon_check_arguments(struct radeon_device *rdev)
577{
578 /* vramlimit must be a power of two */
579 switch (radeon_vram_limit) {
580 case 0:
581 case 4:
582 case 8:
583 case 16:
584 case 32:
585 case 64:
586 case 128:
587 case 256:
588 case 512:
589 case 1024:
590 case 2048:
591 case 4096:
592 break;
593 default:
594 dev_warn(rdev->dev, "vram limit (%d) must be a power of 2\n",
595 radeon_vram_limit);
596 radeon_vram_limit = 0;
597 break;
598 }
599 radeon_vram_limit = radeon_vram_limit << 20;
600 /* gtt size must be power of two and greater or equal to 32M */
601 switch (radeon_gart_size) {
602 case 4:
603 case 8:
604 case 16:
605 dev_warn(rdev->dev, "gart size (%d) too small forcing to 512M\n",
606 radeon_gart_size);
607 radeon_gart_size = 512;
608 break;
609 case 32:
610 case 64:
611 case 128:
612 case 256:
613 case 512:
614 case 1024:
615 case 2048:
616 case 4096:
617 break;
618 default:
619 dev_warn(rdev->dev, "gart size (%d) must be a power of 2\n",
620 radeon_gart_size);
621 radeon_gart_size = 512;
622 break;
623 }
624 rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024;
625 /* AGP mode can only be -1, 1, 2, 4, 8 */
626 switch (radeon_agpmode) {
627 case -1:
628 case 0:
629 case 1:
630 case 2:
631 case 4:
632 case 8:
633 break;
634 default:
635 dev_warn(rdev->dev, "invalid AGP mode %d (valid mode: "
636 "-1, 0, 1, 2, 4, 8)\n", radeon_agpmode);
637 radeon_agpmode = 0;
638 break;
639 }
640}
641
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000642static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
643{
644 struct drm_device *dev = pci_get_drvdata(pdev);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000645 pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
646 if (state == VGA_SWITCHEROO_ON) {
647 printk(KERN_INFO "radeon: switched on\n");
648 /* don't suspend or resume card normally */
Dave Airlie5bcf7192010-12-07 09:20:40 +1000649 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000650 radeon_resume_kms(dev);
Dave Airlie5bcf7192010-12-07 09:20:40 +1000651 dev->switch_power_state = DRM_SWITCH_POWER_ON;
Dave Airliefbf81762010-06-01 09:09:06 +1000652 drm_kms_helper_poll_enable(dev);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000653 } else {
654 printk(KERN_INFO "radeon: switched off\n");
Dave Airliefbf81762010-06-01 09:09:06 +1000655 drm_kms_helper_poll_disable(dev);
Dave Airlie5bcf7192010-12-07 09:20:40 +1000656 dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000657 radeon_suspend_kms(dev, pmm);
Dave Airlie5bcf7192010-12-07 09:20:40 +1000658 dev->switch_power_state = DRM_SWITCH_POWER_OFF;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000659 }
660}
661
662static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
663{
664 struct drm_device *dev = pci_get_drvdata(pdev);
665 bool can_switch;
666
667 spin_lock(&dev->count_lock);
668 can_switch = (dev->open_count == 0);
669 spin_unlock(&dev->count_lock);
670 return can_switch;
671}
672
673
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200674int radeon_device_init(struct radeon_device *rdev,
675 struct drm_device *ddev,
676 struct pci_dev *pdev,
677 uint32_t flags)
678{
Alex Deucher351a52a2010-06-30 11:52:50 -0400679 int r, i;
Dave Airliead49f502009-07-10 22:36:26 +1000680 int dma_bits;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200681
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200682 rdev->shutdown = false;
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200683 rdev->dev = &pdev->dev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200684 rdev->ddev = ddev;
685 rdev->pdev = pdev;
686 rdev->flags = flags;
687 rdev->family = flags & RADEON_FAMILY_MASK;
688 rdev->is_atom_bios = false;
689 rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT;
690 rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024;
691 rdev->gpu_lockup = false;
Jerome Glisse733289c2009-09-16 15:24:21 +0200692 rdev->accel_working = false;
Jerome Glisse1b5331d2010-04-12 20:21:53 +0000693
694 DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X).\n",
695 radeon_family_name[rdev->family], pdev->vendor, pdev->device);
696
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200697 /* mutex initialization are all done here so we
698 * can recall function without having locking issues */
699 mutex_init(&rdev->cs_mutex);
700 mutex_init(&rdev->ib_pool.mutex);
701 mutex_init(&rdev->cp.mutex);
Alex Deucher40bacf12009-12-23 03:23:21 -0500702 mutex_init(&rdev->dc_hw_i2c_mutex);
Alex Deucherd8f60cf2009-12-01 13:43:46 -0500703 if (rdev->family >= CHIP_R600)
704 spin_lock_init(&rdev->ih.lock);
Jerome Glisse4c788672009-11-20 14:29:23 +0100705 mutex_init(&rdev->gem.mutex);
Rafał Miłeckic913e232009-12-22 23:02:16 +0100706 mutex_init(&rdev->pm.mutex);
Matthew Garrett5876dd22010-04-26 15:52:20 -0400707 mutex_init(&rdev->vram_mutex);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200708 rwlock_init(&rdev->fence_drv.lock);
Jerome Glisse9f022dd2009-09-11 15:35:22 +0200709 INIT_LIST_HEAD(&rdev->gem.objects);
Rafał Miłecki73a6d3f2010-01-08 00:22:47 +0100710 init_waitqueue_head(&rdev->irq.vblank_queue);
Alex Deucher2031f772010-04-22 12:52:11 -0400711 init_waitqueue_head(&rdev->irq.idle_queue);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200712
Alex Deucherd4877cf2009-12-04 16:56:37 -0500713 /* setup workqueue */
714 rdev->wq = create_workqueue("radeon");
715 if (rdev->wq == NULL)
716 return -ENOMEM;
717
Jerome Glisse4aac0472009-09-14 18:29:49 +0200718 /* Set asic functions */
719 r = radeon_asic_init(rdev);
Jerome Glisse36421332009-12-11 21:18:34 +0100720 if (r)
Jerome Glisse4aac0472009-09-14 18:29:49 +0200721 return r;
Jerome Glisse36421332009-12-11 21:18:34 +0100722 radeon_check_arguments(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200723
Alex Deucherf95df9c2010-03-21 14:02:25 -0400724 /* all of the newer IGP chips have an internal gart
725 * However some rs4xx report as AGP, so remove that here.
726 */
727 if ((rdev->family >= CHIP_RS400) &&
728 (rdev->flags & RADEON_IS_IGP)) {
729 rdev->flags &= ~RADEON_IS_AGP;
730 }
731
Jerome Glisse30256a32009-11-30 17:47:59 +0100732 if (rdev->flags & RADEON_IS_AGP && radeon_agpmode == -1) {
Jerome Glisseb574f252009-10-06 19:04:29 +0200733 radeon_agp_disable(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200734 }
735
Dave Airliead49f502009-07-10 22:36:26 +1000736 /* set DMA mask + need_dma32 flags.
737 * PCIE - can handle 40-bits.
738 * IGP - can handle 40-bits (in theory)
739 * AGP - generally dma32 is safest
740 * PCI - only dma32
741 */
742 rdev->need_dma32 = false;
743 if (rdev->flags & RADEON_IS_AGP)
744 rdev->need_dma32 = true;
745 if (rdev->flags & RADEON_IS_PCI)
746 rdev->need_dma32 = true;
747
748 dma_bits = rdev->need_dma32 ? 32 : 40;
749 r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits));
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200750 if (r) {
751 printk(KERN_WARNING "radeon: No suitable DMA available.\n");
752 }
753
754 /* Registers mapping */
755 /* TODO: block userspace mapping of io register */
Jordan Crouse01d73a62010-05-27 13:40:24 -0600756 rdev->rmmio_base = pci_resource_start(rdev->pdev, 2);
757 rdev->rmmio_size = pci_resource_len(rdev->pdev, 2);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200758 rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size);
759 if (rdev->rmmio == NULL) {
760 return -ENOMEM;
761 }
762 DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base);
763 DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size);
764
Alex Deucher351a52a2010-06-30 11:52:50 -0400765 /* io port mapping */
766 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
767 if (pci_resource_flags(rdev->pdev, i) & IORESOURCE_IO) {
768 rdev->rio_mem_size = pci_resource_len(rdev->pdev, i);
769 rdev->rio_mem = pci_iomap(rdev->pdev, i, rdev->rio_mem_size);
770 break;
771 }
772 }
773 if (rdev->rio_mem == NULL)
774 DRM_ERROR("Unable to find PCI I/O BAR\n");
775
Dave Airlie28d52042009-09-21 14:33:58 +1000776 /* if we have > 1 VGA cards, then disable the radeon VGA resources */
Dave Airlie93239ea2009-10-28 11:09:58 +1000777 /* this will fail for cards that aren't VGA class devices, just
778 * ignore it */
779 vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000780 vga_switcheroo_register_client(rdev->pdev,
781 radeon_switcheroo_set_state,
Dave Airlie8d608aa2010-12-07 08:57:57 +1000782 NULL,
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000783 radeon_switcheroo_can_switch);
Dave Airlie28d52042009-09-21 14:33:58 +1000784
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000785 r = radeon_init(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +0200786 if (r)
Jerome Glisse3ce0a232009-09-08 10:10:24 +1000787 return r;
Michel Dänzerb1e3a6d2009-06-23 16:12:54 +0200788
Jerome Glisseb574f252009-10-06 19:04:29 +0200789 if (rdev->flags & RADEON_IS_AGP && !rdev->accel_working) {
790 /* Acceleration not working on AGP card try again
791 * with fallback to PCI or PCIE GART
792 */
Jerome Glissea2d07b72010-03-09 14:45:11 +0000793 radeon_asic_reset(rdev);
Jerome Glisseb574f252009-10-06 19:04:29 +0200794 radeon_fini(rdev);
795 radeon_agp_disable(rdev);
796 r = radeon_init(rdev);
Jerome Glisse4aac0472009-09-14 18:29:49 +0200797 if (r)
798 return r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200799 }
Michel Dänzerecc0b322009-07-21 11:23:57 +0200800 if (radeon_testing) {
801 radeon_test_moves(rdev);
802 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200803 if (radeon_benchmarking) {
804 radeon_benchmark(rdev);
805 }
Jerome Glisse6cf8a3f52009-09-10 21:46:48 +0200806 return 0;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200807}
808
809void radeon_device_fini(struct radeon_device *rdev)
810{
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200811 DRM_INFO("radeon: finishing device.\n");
812 rdev->shutdown = true;
Jerome Glisse90aca4d2010-03-09 14:45:12 +0000813 /* evict vram memory */
814 radeon_bo_evict_vram(rdev);
Jerome Glisse62a8ea32009-10-01 18:02:11 +0200815 radeon_fini(rdev);
Alex Deucherd4877cf2009-12-04 16:56:37 -0500816 destroy_workqueue(rdev->wq);
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000817 vga_switcheroo_unregister_client(rdev->pdev);
Dave Airliec1176d62009-10-08 14:03:05 +1000818 vga_client_register(rdev->pdev, NULL, NULL, NULL);
Alex Deuchere0a2ca72010-07-08 12:24:52 -0400819 if (rdev->rio_mem)
820 pci_iounmap(rdev->pdev, rdev->rio_mem);
Alex Deucher351a52a2010-06-30 11:52:50 -0400821 rdev->rio_mem = NULL;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200822 iounmap(rdev->rmmio);
823 rdev->rmmio = NULL;
824}
825
826
827/*
828 * Suspend & resume.
829 */
830int radeon_suspend_kms(struct drm_device *dev, pm_message_t state)
831{
Darren Jenkins875c1862009-12-30 12:18:30 +1100832 struct radeon_device *rdev;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200833 struct drm_crtc *crtc;
Alex Deucherd8dcaa12010-06-02 12:08:41 -0400834 struct drm_connector *connector;
Jerome Glisse4c788672009-11-20 14:29:23 +0100835 int r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200836
Darren Jenkins875c1862009-12-30 12:18:30 +1100837 if (dev == NULL || dev->dev_private == NULL) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200838 return -ENODEV;
839 }
840 if (state.event == PM_EVENT_PRETHAW) {
841 return 0;
842 }
Darren Jenkins875c1862009-12-30 12:18:30 +1100843 rdev = dev->dev_private;
844
Dave Airlie5bcf7192010-12-07 09:20:40 +1000845 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000846 return 0;
Alex Deucherd8dcaa12010-06-02 12:08:41 -0400847
848 /* turn off display hw */
849 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
850 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
851 }
852
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200853 /* unpin the front buffers */
854 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
855 struct radeon_framebuffer *rfb = to_radeon_framebuffer(crtc->fb);
Jerome Glisse4c788672009-11-20 14:29:23 +0100856 struct radeon_bo *robj;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200857
858 if (rfb == NULL || rfb->obj == NULL) {
859 continue;
860 }
861 robj = rfb->obj->driver_private;
Dave Airlie38651672010-03-30 05:34:13 +0000862 /* don't unpin kernel fb objects */
863 if (!radeon_fbdev_robj_is_fb(rdev, robj)) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100864 r = radeon_bo_reserve(robj, false);
Dave Airlie38651672010-03-30 05:34:13 +0000865 if (r == 0) {
Jerome Glisse4c788672009-11-20 14:29:23 +0100866 radeon_bo_unpin(robj);
867 radeon_bo_unreserve(robj);
868 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200869 }
870 }
871 /* evict vram memory */
Jerome Glisse4c788672009-11-20 14:29:23 +0100872 radeon_bo_evict_vram(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200873 /* wait for gpu to finish processing current batch */
874 radeon_fence_wait_last(rdev);
875
Yang Zhaof657c2a2009-09-15 12:21:01 +1000876 radeon_save_bios_scratch_regs(rdev);
877
Alex Deucherce8f5372010-05-07 15:10:16 -0400878 radeon_pm_suspend(rdev);
Jerome Glisse62a8ea32009-10-01 18:02:11 +0200879 radeon_suspend(rdev);
Alex Deucherd4877cf2009-12-04 16:56:37 -0500880 radeon_hpd_fini(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200881 /* evict remaining vram memory */
Jerome Glisse4c788672009-11-20 14:29:23 +0100882 radeon_bo_evict_vram(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200883
Jerome Glisse10b06122010-05-21 18:48:54 +0200884 radeon_agp_suspend(rdev);
885
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200886 pci_save_state(dev->pdev);
887 if (state.event == PM_EVENT_SUSPEND) {
888 /* Shut down the device */
889 pci_disable_device(dev->pdev);
890 pci_set_power_state(dev->pdev, PCI_D3hot);
891 }
892 acquire_console_sem();
Dave Airlie38651672010-03-30 05:34:13 +0000893 radeon_fbdev_set_suspend(rdev, 1);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200894 release_console_sem();
895 return 0;
896}
897
898int radeon_resume_kms(struct drm_device *dev)
899{
Cedric Godin09bdf592010-06-11 14:40:56 -0400900 struct drm_connector *connector;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200901 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200902
Dave Airlie5bcf7192010-12-07 09:20:40 +1000903 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000904 return 0;
905
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200906 acquire_console_sem();
907 pci_set_power_state(dev->pdev, PCI_D0);
908 pci_restore_state(dev->pdev);
909 if (pci_enable_device(dev->pdev)) {
910 release_console_sem();
911 return -1;
912 }
913 pci_set_master(dev->pdev);
Dave Airlie0ebf1712009-11-05 15:39:10 +1000914 /* resume AGP if in use */
915 radeon_agp_resume(rdev);
Jerome Glisse62a8ea32009-10-01 18:02:11 +0200916 radeon_resume(rdev);
Alex Deucherce8f5372010-05-07 15:10:16 -0400917 radeon_pm_resume(rdev);
Yang Zhaof657c2a2009-09-15 12:21:01 +1000918 radeon_restore_bios_scratch_regs(rdev);
Cedric Godin09bdf592010-06-11 14:40:56 -0400919
Dave Airlie38651672010-03-30 05:34:13 +0000920 radeon_fbdev_set_suspend(rdev, 0);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200921 release_console_sem();
922
Alex Deucherd4877cf2009-12-04 16:56:37 -0500923 /* reset hpd state */
924 radeon_hpd_init(rdev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200925 /* blat the mode back in */
926 drm_helper_resume_force_mode(dev);
Alex Deuchera93f3442010-12-20 11:22:29 -0500927 /* turn on display hw */
928 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
929 drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
930 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200931 return 0;
932}
933
Jerome Glisse90aca4d2010-03-09 14:45:12 +0000934int radeon_gpu_reset(struct radeon_device *rdev)
935{
936 int r;
937
938 radeon_save_bios_scratch_regs(rdev);
939 radeon_suspend(rdev);
940
941 r = radeon_asic_reset(rdev);
942 if (!r) {
943 dev_info(rdev->dev, "GPU reset succeed\n");
944 radeon_resume(rdev);
945 radeon_restore_bios_scratch_regs(rdev);
946 drm_helper_resume_force_mode(rdev->ddev);
947 return 0;
948 }
949 /* bad news, how to tell it to userspace ? */
950 dev_info(rdev->dev, "GPU reset failed\n");
951 return r;
952}
953
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200954
955/*
956 * Debugfs
957 */
958struct radeon_debugfs {
959 struct drm_info_list *files;
960 unsigned num_files;
961};
962static struct radeon_debugfs _radeon_debugfs[RADEON_DEBUGFS_MAX_NUM_FILES];
963static unsigned _radeon_debugfs_count = 0;
964
965int radeon_debugfs_add_files(struct radeon_device *rdev,
966 struct drm_info_list *files,
967 unsigned nfiles)
968{
969 unsigned i;
970
971 for (i = 0; i < _radeon_debugfs_count; i++) {
972 if (_radeon_debugfs[i].files == files) {
973 /* Already registered */
974 return 0;
975 }
976 }
977 if ((_radeon_debugfs_count + nfiles) > RADEON_DEBUGFS_MAX_NUM_FILES) {
978 DRM_ERROR("Reached maximum number of debugfs files.\n");
979 DRM_ERROR("Report so we increase RADEON_DEBUGFS_MAX_NUM_FILES.\n");
980 return -EINVAL;
981 }
982 _radeon_debugfs[_radeon_debugfs_count].files = files;
983 _radeon_debugfs[_radeon_debugfs_count].num_files = nfiles;
984 _radeon_debugfs_count++;
985#if defined(CONFIG_DEBUG_FS)
986 drm_debugfs_create_files(files, nfiles,
987 rdev->ddev->control->debugfs_root,
988 rdev->ddev->control);
989 drm_debugfs_create_files(files, nfiles,
990 rdev->ddev->primary->debugfs_root,
991 rdev->ddev->primary);
992#endif
993 return 0;
994}
995
996#if defined(CONFIG_DEBUG_FS)
997int radeon_debugfs_init(struct drm_minor *minor)
998{
999 return 0;
1000}
1001
1002void radeon_debugfs_cleanup(struct drm_minor *minor)
1003{
1004 unsigned i;
1005
1006 for (i = 0; i < _radeon_debugfs_count; i++) {
1007 drm_debugfs_remove_files(_radeon_debugfs[i].files,
1008 _radeon_debugfs[i].num_files, minor);
1009 }
1010}
1011#endif