Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Advanced Micro Devices, Inc. |
| 3 | * Copyright 2008 Red Hat Inc. |
| 4 | * Copyright 2009 Jerome Glisse. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Dave Airlie |
| 25 | * Alex Deucher |
| 26 | * Jerome Glisse |
| 27 | */ |
| 28 | #include <linux/console.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 30 | #include <drm/drmP.h> |
| 31 | #include <drm/drm_crtc_helper.h> |
| 32 | #include <drm/radeon_drm.h> |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 33 | #include <linux/vgaarb.h> |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 34 | #include <linux/vga_switcheroo.h> |
Matthew Garrett | bcc65fd | 2011-08-08 16:21:16 +0000 | [diff] [blame] | 35 | #include <linux/efi.h> |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 36 | #include "radeon_reg.h" |
| 37 | #include "radeon.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 38 | #include "atom.h" |
| 39 | |
Jerome Glisse | 1b5331d | 2010-04-12 20:21:53 +0000 | [diff] [blame] | 40 | static const char radeon_family_name[][16] = { |
| 41 | "R100", |
| 42 | "RV100", |
| 43 | "RS100", |
| 44 | "RV200", |
| 45 | "RS200", |
| 46 | "R200", |
| 47 | "RV250", |
| 48 | "RS300", |
| 49 | "RV280", |
| 50 | "R300", |
| 51 | "R350", |
| 52 | "RV350", |
| 53 | "RV380", |
| 54 | "R420", |
| 55 | "R423", |
| 56 | "RV410", |
| 57 | "RS400", |
| 58 | "RS480", |
| 59 | "RS600", |
| 60 | "RS690", |
| 61 | "RS740", |
| 62 | "RV515", |
| 63 | "R520", |
| 64 | "RV530", |
| 65 | "RV560", |
| 66 | "RV570", |
| 67 | "R580", |
| 68 | "R600", |
| 69 | "RV610", |
| 70 | "RV630", |
| 71 | "RV670", |
| 72 | "RV620", |
| 73 | "RV635", |
| 74 | "RS780", |
| 75 | "RS880", |
| 76 | "RV770", |
| 77 | "RV730", |
| 78 | "RV710", |
| 79 | "RV740", |
| 80 | "CEDAR", |
| 81 | "REDWOOD", |
| 82 | "JUNIPER", |
| 83 | "CYPRESS", |
| 84 | "HEMLOCK", |
Alex Deucher | b08ebe7 | 2010-12-03 15:34:16 -0500 | [diff] [blame] | 85 | "PALM", |
Alex Deucher | 4df64e6 | 2011-05-31 15:42:46 -0400 | [diff] [blame] | 86 | "SUMO", |
| 87 | "SUMO2", |
Alex Deucher | 1fe1830 | 2011-01-06 21:19:12 -0500 | [diff] [blame] | 88 | "BARTS", |
| 89 | "TURKS", |
| 90 | "CAICOS", |
Alex Deucher | b7cfc9f | 2011-03-02 20:07:27 -0500 | [diff] [blame] | 91 | "CAYMAN", |
Alex Deucher | 8848f75 | 2012-03-20 17:18:28 -0400 | [diff] [blame] | 92 | "ARUBA", |
Alex Deucher | cb28bb3 | 2012-03-20 17:17:59 -0400 | [diff] [blame] | 93 | "TAHITI", |
| 94 | "PITCAIRN", |
| 95 | "VERDE", |
Jerome Glisse | 1b5331d | 2010-04-12 20:21:53 +0000 | [diff] [blame] | 96 | "LAST", |
| 97 | }; |
| 98 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 99 | /* |
Michel Dänzer | b1e3a6d | 2009-06-23 16:12:54 +0200 | [diff] [blame] | 100 | * Clear GPU surface registers. |
| 101 | */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 102 | void radeon_surface_init(struct radeon_device *rdev) |
Michel Dänzer | b1e3a6d | 2009-06-23 16:12:54 +0200 | [diff] [blame] | 103 | { |
| 104 | /* FIXME: check this out */ |
| 105 | if (rdev->family < CHIP_R600) { |
| 106 | int i; |
| 107 | |
Dave Airlie | 550e2d9 | 2009-12-09 14:15:38 +1000 | [diff] [blame] | 108 | for (i = 0; i < RADEON_GEM_MAX_SURFACES; i++) { |
| 109 | if (rdev->surface_regs[i].bo) |
| 110 | radeon_bo_get_surface_reg(rdev->surface_regs[i].bo); |
| 111 | else |
| 112 | radeon_clear_surface_reg(rdev, i); |
Michel Dänzer | b1e3a6d | 2009-06-23 16:12:54 +0200 | [diff] [blame] | 113 | } |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 114 | /* enable surfaces */ |
| 115 | WREG32(RADEON_SURFACE_CNTL, 0); |
Michel Dänzer | b1e3a6d | 2009-06-23 16:12:54 +0200 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
| 119 | /* |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 120 | * GPU scratch registers helpers function. |
| 121 | */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 122 | void radeon_scratch_init(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 123 | { |
| 124 | int i; |
| 125 | |
| 126 | /* FIXME: check this out */ |
| 127 | if (rdev->family < CHIP_R300) { |
| 128 | rdev->scratch.num_reg = 5; |
| 129 | } else { |
| 130 | rdev->scratch.num_reg = 7; |
| 131 | } |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 132 | rdev->scratch.reg_base = RADEON_SCRATCH_REG0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 133 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
| 134 | rdev->scratch.free[i] = true; |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 135 | rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg) |
| 140 | { |
| 141 | int i; |
| 142 | |
| 143 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
| 144 | if (rdev->scratch.free[i]) { |
| 145 | rdev->scratch.free[i] = false; |
| 146 | *reg = rdev->scratch.reg[i]; |
| 147 | return 0; |
| 148 | } |
| 149 | } |
| 150 | return -EINVAL; |
| 151 | } |
| 152 | |
| 153 | void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg) |
| 154 | { |
| 155 | int i; |
| 156 | |
| 157 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
| 158 | if (rdev->scratch.reg[i] == reg) { |
| 159 | rdev->scratch.free[i] = true; |
| 160 | return; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 165 | void radeon_wb_disable(struct radeon_device *rdev) |
| 166 | { |
| 167 | int r; |
| 168 | |
| 169 | if (rdev->wb.wb_obj) { |
| 170 | r = radeon_bo_reserve(rdev->wb.wb_obj, false); |
| 171 | if (unlikely(r != 0)) |
| 172 | return; |
| 173 | radeon_bo_kunmap(rdev->wb.wb_obj); |
| 174 | radeon_bo_unpin(rdev->wb.wb_obj); |
| 175 | radeon_bo_unreserve(rdev->wb.wb_obj); |
| 176 | } |
| 177 | rdev->wb.enabled = false; |
| 178 | } |
| 179 | |
| 180 | void radeon_wb_fini(struct radeon_device *rdev) |
| 181 | { |
| 182 | radeon_wb_disable(rdev); |
| 183 | if (rdev->wb.wb_obj) { |
| 184 | radeon_bo_unref(&rdev->wb.wb_obj); |
| 185 | rdev->wb.wb = NULL; |
| 186 | rdev->wb.wb_obj = NULL; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | int radeon_wb_init(struct radeon_device *rdev) |
| 191 | { |
| 192 | int r; |
| 193 | |
| 194 | if (rdev->wb.wb_obj == NULL) { |
Daniel Vetter | 441921d | 2011-02-18 17:59:16 +0100 | [diff] [blame] | 195 | r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true, |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 196 | RADEON_GEM_DOMAIN_GTT, &rdev->wb.wb_obj); |
| 197 | if (r) { |
| 198 | dev_warn(rdev->dev, "(%d) create WB bo failed\n", r); |
| 199 | return r; |
| 200 | } |
| 201 | } |
| 202 | r = radeon_bo_reserve(rdev->wb.wb_obj, false); |
| 203 | if (unlikely(r != 0)) { |
| 204 | radeon_wb_fini(rdev); |
| 205 | return r; |
| 206 | } |
| 207 | r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT, |
| 208 | &rdev->wb.gpu_addr); |
| 209 | if (r) { |
| 210 | radeon_bo_unreserve(rdev->wb.wb_obj); |
| 211 | dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r); |
| 212 | radeon_wb_fini(rdev); |
| 213 | return r; |
| 214 | } |
| 215 | r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb); |
| 216 | radeon_bo_unreserve(rdev->wb.wb_obj); |
| 217 | if (r) { |
| 218 | dev_warn(rdev->dev, "(%d) map WB bo failed\n", r); |
| 219 | radeon_wb_fini(rdev); |
| 220 | return r; |
| 221 | } |
| 222 | |
Alex Deucher | e6ba759 | 2011-06-13 22:02:51 +0000 | [diff] [blame] | 223 | /* clear wb memory */ |
| 224 | memset((char *)rdev->wb.wb, 0, RADEON_GPU_PAGE_SIZE); |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 225 | /* disable event_write fences */ |
| 226 | rdev->wb.use_event = false; |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 227 | /* disabled via module param */ |
Jerome Glisse | 3b7a2b2 | 2012-05-09 15:34:47 +0200 | [diff] [blame] | 228 | if (radeon_no_wb == 1) { |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 229 | rdev->wb.enabled = false; |
Jerome Glisse | 3b7a2b2 | 2012-05-09 15:34:47 +0200 | [diff] [blame] | 230 | } else { |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 231 | if (rdev->flags & RADEON_IS_AGP) { |
Alex Deucher | 28eebb7 | 2012-01-03 09:48:38 -0500 | [diff] [blame] | 232 | /* often unreliable on AGP */ |
| 233 | rdev->wb.enabled = false; |
| 234 | } else if (rdev->family < CHIP_R300) { |
| 235 | /* often unreliable on pre-r300 */ |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 236 | rdev->wb.enabled = false; |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 237 | } else { |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 238 | rdev->wb.enabled = true; |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 239 | /* event_write fences are only available on r600+ */ |
Jerome Glisse | 3b7a2b2 | 2012-05-09 15:34:47 +0200 | [diff] [blame] | 240 | if (rdev->family >= CHIP_R600) { |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 241 | rdev->wb.use_event = true; |
Jerome Glisse | 3b7a2b2 | 2012-05-09 15:34:47 +0200 | [diff] [blame] | 242 | } |
Alex Deucher | d0f8a85 | 2010-09-04 05:04:34 -0400 | [diff] [blame] | 243 | } |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 244 | } |
Alex Deucher | c994ead | 2012-05-03 17:06:28 -0400 | [diff] [blame] | 245 | /* always use writeback/events on NI, APUs */ |
| 246 | if (rdev->family >= CHIP_PALM) { |
Alex Deucher | 7d52785 | 2011-01-06 21:19:27 -0500 | [diff] [blame] | 247 | rdev->wb.enabled = true; |
| 248 | rdev->wb.use_event = true; |
| 249 | } |
Alex Deucher | 724c80e | 2010-08-27 18:25:25 -0400 | [diff] [blame] | 250 | |
| 251 | dev_info(rdev->dev, "WB %sabled\n", rdev->wb.enabled ? "en" : "dis"); |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 256 | /** |
| 257 | * radeon_vram_location - try to find VRAM location |
| 258 | * @rdev: radeon device structure holding all necessary informations |
| 259 | * @mc: memory controller structure holding memory informations |
| 260 | * @base: base address at which to put VRAM |
| 261 | * |
| 262 | * Function will place try to place VRAM at base address provided |
| 263 | * as parameter (which is so far either PCI aperture address or |
| 264 | * for IGP TOM base address). |
| 265 | * |
| 266 | * If there is not enough space to fit the unvisible VRAM in the 32bits |
| 267 | * address space then we limit the VRAM size to the aperture. |
| 268 | * |
| 269 | * If we are using AGP and if the AGP aperture doesn't allow us to have |
| 270 | * room for all the VRAM than we restrict the VRAM to the PCI aperture |
| 271 | * size and print a warning. |
| 272 | * |
| 273 | * This function will never fails, worst case are limiting VRAM. |
| 274 | * |
| 275 | * Note: GTT start, end, size should be initialized before calling this |
| 276 | * function on AGP platform. |
| 277 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 278 | * Note: We don't explicitly enforce VRAM start to be aligned on VRAM size, |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 279 | * this shouldn't be a problem as we are using the PCI aperture as a reference. |
| 280 | * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but |
| 281 | * not IGP. |
| 282 | * |
| 283 | * Note: we use mc_vram_size as on some board we need to program the mc to |
| 284 | * cover the whole aperture even if VRAM size is inferior to aperture size |
| 285 | * Novell bug 204882 + along with lots of ubuntu ones |
| 286 | * |
| 287 | * Note: when limiting vram it's safe to overwritte real_vram_size because |
| 288 | * we are not in case where real_vram_size is inferior to mc_vram_size (ie |
| 289 | * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu |
| 290 | * ones) |
| 291 | * |
| 292 | * Note: IGP TOM addr should be the same as the aperture addr, we don't |
| 293 | * explicitly check for that thought. |
| 294 | * |
| 295 | * FIXME: when reducing VRAM size align new size on power of 2. |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 296 | */ |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 297 | void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 298 | { |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 299 | mc->vram_start = base; |
| 300 | if (mc->mc_vram_size > (0xFFFFFFFF - base + 1)) { |
| 301 | dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n"); |
| 302 | mc->real_vram_size = mc->aper_size; |
| 303 | mc->mc_vram_size = mc->aper_size; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 304 | } |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 305 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
Jerome Glisse | 2cbeb4e | 2010-08-16 11:54:36 -0400 | [diff] [blame] | 306 | if (rdev->flags & RADEON_IS_AGP && mc->vram_end > mc->gtt_start && mc->vram_start <= mc->gtt_end) { |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 307 | dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n"); |
| 308 | mc->real_vram_size = mc->aper_size; |
| 309 | mc->mc_vram_size = mc->aper_size; |
| 310 | } |
| 311 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
Michel Dänzer | ba95c45 | 2011-08-19 15:24:18 +0000 | [diff] [blame] | 312 | if (radeon_vram_limit && radeon_vram_limit < mc->real_vram_size) |
| 313 | mc->real_vram_size = radeon_vram_limit; |
Alex Deucher | dd7cc55 | 2010-12-03 14:37:21 -0500 | [diff] [blame] | 314 | dev_info(rdev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n", |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 315 | mc->mc_vram_size >> 20, mc->vram_start, |
| 316 | mc->vram_end, mc->real_vram_size >> 20); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 317 | } |
| 318 | |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 319 | /** |
| 320 | * radeon_gtt_location - try to find GTT location |
| 321 | * @rdev: radeon device structure holding all necessary informations |
| 322 | * @mc: memory controller structure holding memory informations |
| 323 | * |
| 324 | * Function will place try to place GTT before or after VRAM. |
| 325 | * |
| 326 | * If GTT size is bigger than space left then we ajust GTT size. |
| 327 | * Thus function will never fails. |
| 328 | * |
| 329 | * FIXME: when reducing GTT size align new size on power of 2. |
| 330 | */ |
| 331 | void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc) |
| 332 | { |
| 333 | u64 size_af, size_bf; |
| 334 | |
Alex Deucher | 8d369bb | 2010-07-15 10:51:10 -0400 | [diff] [blame] | 335 | size_af = ((0xFFFFFFFF - mc->vram_end) + mc->gtt_base_align) & ~mc->gtt_base_align; |
| 336 | size_bf = mc->vram_start & ~mc->gtt_base_align; |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 337 | if (size_bf > size_af) { |
| 338 | if (mc->gtt_size > size_bf) { |
| 339 | dev_warn(rdev->dev, "limiting GTT\n"); |
| 340 | mc->gtt_size = size_bf; |
| 341 | } |
Alex Deucher | 8d369bb | 2010-07-15 10:51:10 -0400 | [diff] [blame] | 342 | mc->gtt_start = (mc->vram_start & ~mc->gtt_base_align) - mc->gtt_size; |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 343 | } else { |
| 344 | if (mc->gtt_size > size_af) { |
| 345 | dev_warn(rdev->dev, "limiting GTT\n"); |
| 346 | mc->gtt_size = size_af; |
| 347 | } |
Alex Deucher | 8d369bb | 2010-07-15 10:51:10 -0400 | [diff] [blame] | 348 | mc->gtt_start = (mc->vram_end + 1 + mc->gtt_base_align) & ~mc->gtt_base_align; |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 349 | } |
| 350 | mc->gtt_end = mc->gtt_start + mc->gtt_size - 1; |
Alex Deucher | dd7cc55 | 2010-12-03 14:37:21 -0500 | [diff] [blame] | 351 | dev_info(rdev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n", |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 352 | mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end); |
| 353 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 354 | |
| 355 | /* |
| 356 | * GPU helpers function. |
| 357 | */ |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 358 | bool radeon_card_posted(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 359 | { |
| 360 | uint32_t reg; |
| 361 | |
Matthew Garrett | bcc65fd | 2011-08-08 16:21:16 +0000 | [diff] [blame] | 362 | if (efi_enabled && rdev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE) |
| 363 | return false; |
| 364 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 365 | /* first check CRTCs */ |
Alex Deucher | 1800740 | 2010-11-22 17:56:28 -0500 | [diff] [blame] | 366 | if (ASIC_IS_DCE41(rdev)) { |
| 367 | reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) | |
| 368 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET); |
| 369 | if (reg & EVERGREEN_CRTC_MASTER_EN) |
| 370 | return true; |
| 371 | } else if (ASIC_IS_DCE4(rdev)) { |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 372 | reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) | |
| 373 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) | |
| 374 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) | |
| 375 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) | |
| 376 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) | |
| 377 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET); |
| 378 | if (reg & EVERGREEN_CRTC_MASTER_EN) |
| 379 | return true; |
| 380 | } else if (ASIC_IS_AVIVO(rdev)) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 381 | reg = RREG32(AVIVO_D1CRTC_CONTROL) | |
| 382 | RREG32(AVIVO_D2CRTC_CONTROL); |
| 383 | if (reg & AVIVO_CRTC_EN) { |
| 384 | return true; |
| 385 | } |
| 386 | } else { |
| 387 | reg = RREG32(RADEON_CRTC_GEN_CNTL) | |
| 388 | RREG32(RADEON_CRTC2_GEN_CNTL); |
| 389 | if (reg & RADEON_CRTC_EN) { |
| 390 | return true; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | /* then check MEM_SIZE, in case the crtcs are off */ |
| 395 | if (rdev->family >= CHIP_R600) |
| 396 | reg = RREG32(R600_CONFIG_MEMSIZE); |
| 397 | else |
| 398 | reg = RREG32(RADEON_CONFIG_MEMSIZE); |
| 399 | |
| 400 | if (reg) |
| 401 | return true; |
| 402 | |
| 403 | return false; |
| 404 | |
| 405 | } |
| 406 | |
Alex Deucher | f47299c | 2010-03-16 20:54:38 -0400 | [diff] [blame] | 407 | void radeon_update_bandwidth_info(struct radeon_device *rdev) |
| 408 | { |
| 409 | fixed20_12 a; |
Alex Deucher | 8807286 | 2010-08-10 12:33:20 -0400 | [diff] [blame] | 410 | u32 sclk = rdev->pm.current_sclk; |
| 411 | u32 mclk = rdev->pm.current_mclk; |
| 412 | |
| 413 | /* sclk/mclk in Mhz */ |
| 414 | a.full = dfixed_const(100); |
| 415 | rdev->pm.sclk.full = dfixed_const(sclk); |
| 416 | rdev->pm.sclk.full = dfixed_div(rdev->pm.sclk, a); |
| 417 | rdev->pm.mclk.full = dfixed_const(mclk); |
| 418 | rdev->pm.mclk.full = dfixed_div(rdev->pm.mclk, a); |
Alex Deucher | f47299c | 2010-03-16 20:54:38 -0400 | [diff] [blame] | 419 | |
| 420 | if (rdev->flags & RADEON_IS_IGP) { |
Ben Skeggs | 68adac5 | 2010-04-28 11:46:42 +1000 | [diff] [blame] | 421 | a.full = dfixed_const(16); |
Alex Deucher | f47299c | 2010-03-16 20:54:38 -0400 | [diff] [blame] | 422 | /* core_bandwidth = sclk(Mhz) * 16 */ |
Ben Skeggs | 68adac5 | 2010-04-28 11:46:42 +1000 | [diff] [blame] | 423 | rdev->pm.core_bandwidth.full = dfixed_div(rdev->pm.sclk, a); |
Alex Deucher | f47299c | 2010-03-16 20:54:38 -0400 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
Dave Airlie | 72542d7 | 2009-12-01 14:06:31 +1000 | [diff] [blame] | 427 | bool radeon_boot_test_post_card(struct radeon_device *rdev) |
| 428 | { |
| 429 | if (radeon_card_posted(rdev)) |
| 430 | return true; |
| 431 | |
| 432 | if (rdev->bios) { |
| 433 | DRM_INFO("GPU not posted. posting now...\n"); |
| 434 | if (rdev->is_atom_bios) |
| 435 | atom_asic_init(rdev->mode_info.atom_context); |
| 436 | else |
| 437 | radeon_combios_asic_init(rdev->ddev); |
| 438 | return true; |
| 439 | } else { |
| 440 | dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); |
| 441 | return false; |
| 442 | } |
| 443 | } |
| 444 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 445 | int radeon_dummy_page_init(struct radeon_device *rdev) |
| 446 | { |
Dave Airlie | 8256856 | 2010-02-05 16:00:07 +1000 | [diff] [blame] | 447 | if (rdev->dummy_page.page) |
| 448 | return 0; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 449 | rdev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO); |
| 450 | if (rdev->dummy_page.page == NULL) |
| 451 | return -ENOMEM; |
| 452 | rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page, |
| 453 | 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
Benjamin Herrenschmidt | a30f6fb7 | 2010-08-10 14:48:58 +1000 | [diff] [blame] | 454 | if (pci_dma_mapping_error(rdev->pdev, rdev->dummy_page.addr)) { |
| 455 | dev_err(&rdev->pdev->dev, "Failed to DMA MAP the dummy page\n"); |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 456 | __free_page(rdev->dummy_page.page); |
| 457 | rdev->dummy_page.page = NULL; |
| 458 | return -ENOMEM; |
| 459 | } |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | void radeon_dummy_page_fini(struct radeon_device *rdev) |
| 464 | { |
| 465 | if (rdev->dummy_page.page == NULL) |
| 466 | return; |
| 467 | pci_unmap_page(rdev->pdev, rdev->dummy_page.addr, |
| 468 | PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 469 | __free_page(rdev->dummy_page.page); |
| 470 | rdev->dummy_page.page = NULL; |
| 471 | } |
| 472 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 473 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 474 | /* ATOM accessor methods */ |
| 475 | static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) |
| 476 | { |
| 477 | struct radeon_device *rdev = info->dev->dev_private; |
| 478 | uint32_t r; |
| 479 | |
| 480 | r = rdev->pll_rreg(rdev, reg); |
| 481 | return r; |
| 482 | } |
| 483 | |
| 484 | static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) |
| 485 | { |
| 486 | struct radeon_device *rdev = info->dev->dev_private; |
| 487 | |
| 488 | rdev->pll_wreg(rdev, reg, val); |
| 489 | } |
| 490 | |
| 491 | static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) |
| 492 | { |
| 493 | struct radeon_device *rdev = info->dev->dev_private; |
| 494 | uint32_t r; |
| 495 | |
| 496 | r = rdev->mc_rreg(rdev, reg); |
| 497 | return r; |
| 498 | } |
| 499 | |
| 500 | static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) |
| 501 | { |
| 502 | struct radeon_device *rdev = info->dev->dev_private; |
| 503 | |
| 504 | rdev->mc_wreg(rdev, reg, val); |
| 505 | } |
| 506 | |
| 507 | static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) |
| 508 | { |
| 509 | struct radeon_device *rdev = info->dev->dev_private; |
| 510 | |
| 511 | WREG32(reg*4, val); |
| 512 | } |
| 513 | |
| 514 | static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) |
| 515 | { |
| 516 | struct radeon_device *rdev = info->dev->dev_private; |
| 517 | uint32_t r; |
| 518 | |
| 519 | r = RREG32(reg*4); |
| 520 | return r; |
| 521 | } |
| 522 | |
Alex Deucher | 351a52a | 2010-06-30 11:52:50 -0400 | [diff] [blame] | 523 | static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val) |
| 524 | { |
| 525 | struct radeon_device *rdev = info->dev->dev_private; |
| 526 | |
| 527 | WREG32_IO(reg*4, val); |
| 528 | } |
| 529 | |
| 530 | static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg) |
| 531 | { |
| 532 | struct radeon_device *rdev = info->dev->dev_private; |
| 533 | uint32_t r; |
| 534 | |
| 535 | r = RREG32_IO(reg*4); |
| 536 | return r; |
| 537 | } |
| 538 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 539 | int radeon_atombios_init(struct radeon_device *rdev) |
| 540 | { |
Mathias Fröhlich | 61c4b24 | 2009-10-27 15:08:01 -0400 | [diff] [blame] | 541 | struct card_info *atom_card_info = |
| 542 | kzalloc(sizeof(struct card_info), GFP_KERNEL); |
| 543 | |
| 544 | if (!atom_card_info) |
| 545 | return -ENOMEM; |
| 546 | |
| 547 | rdev->mode_info.atom_card_info = atom_card_info; |
| 548 | atom_card_info->dev = rdev->ddev; |
| 549 | atom_card_info->reg_read = cail_reg_read; |
| 550 | atom_card_info->reg_write = cail_reg_write; |
Alex Deucher | 351a52a | 2010-06-30 11:52:50 -0400 | [diff] [blame] | 551 | /* needed for iio ops */ |
| 552 | if (rdev->rio_mem) { |
| 553 | atom_card_info->ioreg_read = cail_ioreg_read; |
| 554 | atom_card_info->ioreg_write = cail_ioreg_write; |
| 555 | } else { |
| 556 | DRM_ERROR("Unable to find PCI I/O BAR; using MMIO for ATOM IIO\n"); |
| 557 | atom_card_info->ioreg_read = cail_reg_read; |
| 558 | atom_card_info->ioreg_write = cail_reg_write; |
| 559 | } |
Mathias Fröhlich | 61c4b24 | 2009-10-27 15:08:01 -0400 | [diff] [blame] | 560 | atom_card_info->mc_read = cail_mc_read; |
| 561 | atom_card_info->mc_write = cail_mc_write; |
| 562 | atom_card_info->pll_read = cail_pll_read; |
| 563 | atom_card_info->pll_write = cail_pll_write; |
| 564 | |
| 565 | rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios); |
Rafał Miłecki | c31ad97 | 2009-12-17 00:00:46 +0100 | [diff] [blame] | 566 | mutex_init(&rdev->mode_info.atom_context->mutex); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 567 | radeon_atom_initialize_bios_scratch_regs(rdev->ddev); |
Dave Airlie | d904ef9 | 2009-11-17 06:29:46 +1000 | [diff] [blame] | 568 | atom_allocate_fb_scratch(rdev->mode_info.atom_context); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | void radeon_atombios_fini(struct radeon_device *rdev) |
| 573 | { |
Jerome Glisse | 4a04a84 | 2009-12-09 17:39:16 +0100 | [diff] [blame] | 574 | if (rdev->mode_info.atom_context) { |
| 575 | kfree(rdev->mode_info.atom_context->scratch); |
| 576 | kfree(rdev->mode_info.atom_context); |
| 577 | } |
Mathias Fröhlich | 61c4b24 | 2009-10-27 15:08:01 -0400 | [diff] [blame] | 578 | kfree(rdev->mode_info.atom_card_info); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | int radeon_combios_init(struct radeon_device *rdev) |
| 582 | { |
| 583 | radeon_combios_initialize_bios_scratch_regs(rdev->ddev); |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | void radeon_combios_fini(struct radeon_device *rdev) |
| 588 | { |
| 589 | } |
| 590 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 591 | /* if we get transitioned to only one device, tak VGA back */ |
| 592 | static unsigned int radeon_vga_set_decode(void *cookie, bool state) |
| 593 | { |
| 594 | struct radeon_device *rdev = cookie; |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 595 | radeon_vga_set_state(rdev, state); |
| 596 | if (state) |
| 597 | return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | |
| 598 | VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 599 | else |
| 600 | return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 601 | } |
Dave Airlie | c1176d6 | 2009-10-08 14:03:05 +1000 | [diff] [blame] | 602 | |
Jerome Glisse | 3642133 | 2009-12-11 21:18:34 +0100 | [diff] [blame] | 603 | void radeon_check_arguments(struct radeon_device *rdev) |
| 604 | { |
| 605 | /* vramlimit must be a power of two */ |
| 606 | switch (radeon_vram_limit) { |
| 607 | case 0: |
| 608 | case 4: |
| 609 | case 8: |
| 610 | case 16: |
| 611 | case 32: |
| 612 | case 64: |
| 613 | case 128: |
| 614 | case 256: |
| 615 | case 512: |
| 616 | case 1024: |
| 617 | case 2048: |
| 618 | case 4096: |
| 619 | break; |
| 620 | default: |
| 621 | dev_warn(rdev->dev, "vram limit (%d) must be a power of 2\n", |
| 622 | radeon_vram_limit); |
| 623 | radeon_vram_limit = 0; |
| 624 | break; |
| 625 | } |
| 626 | radeon_vram_limit = radeon_vram_limit << 20; |
| 627 | /* gtt size must be power of two and greater or equal to 32M */ |
| 628 | switch (radeon_gart_size) { |
| 629 | case 4: |
| 630 | case 8: |
| 631 | case 16: |
| 632 | dev_warn(rdev->dev, "gart size (%d) too small forcing to 512M\n", |
| 633 | radeon_gart_size); |
| 634 | radeon_gart_size = 512; |
| 635 | break; |
| 636 | case 32: |
| 637 | case 64: |
| 638 | case 128: |
| 639 | case 256: |
| 640 | case 512: |
| 641 | case 1024: |
| 642 | case 2048: |
| 643 | case 4096: |
| 644 | break; |
| 645 | default: |
| 646 | dev_warn(rdev->dev, "gart size (%d) must be a power of 2\n", |
| 647 | radeon_gart_size); |
| 648 | radeon_gart_size = 512; |
| 649 | break; |
| 650 | } |
| 651 | rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; |
| 652 | /* AGP mode can only be -1, 1, 2, 4, 8 */ |
| 653 | switch (radeon_agpmode) { |
| 654 | case -1: |
| 655 | case 0: |
| 656 | case 1: |
| 657 | case 2: |
| 658 | case 4: |
| 659 | case 8: |
| 660 | break; |
| 661 | default: |
| 662 | dev_warn(rdev->dev, "invalid AGP mode %d (valid mode: " |
| 663 | "-1, 0, 1, 2, 4, 8)\n", radeon_agpmode); |
| 664 | radeon_agpmode = 0; |
| 665 | break; |
| 666 | } |
| 667 | } |
| 668 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 669 | static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) |
| 670 | { |
| 671 | struct drm_device *dev = pci_get_drvdata(pdev); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 672 | pm_message_t pmm = { .event = PM_EVENT_SUSPEND }; |
| 673 | if (state == VGA_SWITCHEROO_ON) { |
| 674 | printk(KERN_INFO "radeon: switched on\n"); |
| 675 | /* don't suspend or resume card normally */ |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 676 | dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 677 | radeon_resume_kms(dev); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 678 | dev->switch_power_state = DRM_SWITCH_POWER_ON; |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 679 | drm_kms_helper_poll_enable(dev); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 680 | } else { |
| 681 | printk(KERN_INFO "radeon: switched off\n"); |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 682 | drm_kms_helper_poll_disable(dev); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 683 | dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 684 | radeon_suspend_kms(dev, pmm); |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 685 | dev->switch_power_state = DRM_SWITCH_POWER_OFF; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | |
| 689 | static bool radeon_switcheroo_can_switch(struct pci_dev *pdev) |
| 690 | { |
| 691 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 692 | bool can_switch; |
| 693 | |
| 694 | spin_lock(&dev->count_lock); |
| 695 | can_switch = (dev->open_count == 0); |
| 696 | spin_unlock(&dev->count_lock); |
| 697 | return can_switch; |
| 698 | } |
| 699 | |
Takashi Iwai | 26ec685 | 2012-05-11 07:51:17 +0200 | [diff] [blame^] | 700 | static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = { |
| 701 | .set_gpu_state = radeon_switcheroo_set_state, |
| 702 | .reprobe = NULL, |
| 703 | .can_switch = radeon_switcheroo_can_switch, |
| 704 | }; |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 705 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 706 | int radeon_device_init(struct radeon_device *rdev, |
| 707 | struct drm_device *ddev, |
| 708 | struct pci_dev *pdev, |
| 709 | uint32_t flags) |
| 710 | { |
Alex Deucher | 351a52a | 2010-06-30 11:52:50 -0400 | [diff] [blame] | 711 | int r, i; |
Dave Airlie | ad49f50 | 2009-07-10 22:36:26 +1000 | [diff] [blame] | 712 | int dma_bits; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 713 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 714 | rdev->shutdown = false; |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 715 | rdev->dev = &pdev->dev; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 716 | rdev->ddev = ddev; |
| 717 | rdev->pdev = pdev; |
| 718 | rdev->flags = flags; |
| 719 | rdev->family = flags & RADEON_FAMILY_MASK; |
| 720 | rdev->is_atom_bios = false; |
| 721 | rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT; |
| 722 | rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; |
Jerome Glisse | 733289c | 2009-09-16 15:24:21 +0200 | [diff] [blame] | 723 | rdev->accel_working = false; |
Jerome Glisse | 1b5331d | 2010-04-12 20:21:53 +0000 | [diff] [blame] | 724 | |
Thomas Reim | d522d9c | 2011-07-29 14:28:59 +0000 | [diff] [blame] | 725 | DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X).\n", |
| 726 | radeon_family_name[rdev->family], pdev->vendor, pdev->device, |
| 727 | pdev->subsystem_vendor, pdev->subsystem_device); |
Jerome Glisse | 1b5331d | 2010-04-12 20:21:53 +0000 | [diff] [blame] | 728 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 729 | /* mutex initialization are all done here so we |
| 730 | * can recall function without having locking issues */ |
Michel Dänzer | 7a1619b | 2011-11-10 18:57:26 +0100 | [diff] [blame] | 731 | radeon_mutex_init(&rdev->cs_mutex); |
Christian König | d6999bc | 2012-05-09 15:34:45 +0200 | [diff] [blame] | 732 | mutex_init(&rdev->ring_lock); |
Alex Deucher | 40bacf1 | 2009-12-23 03:23:21 -0500 | [diff] [blame] | 733 | mutex_init(&rdev->dc_hw_i2c_mutex); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 734 | if (rdev->family >= CHIP_R600) |
| 735 | spin_lock_init(&rdev->ih.lock); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 736 | mutex_init(&rdev->gem.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 737 | mutex_init(&rdev->pm.mutex); |
Matthew Garrett | 5876dd2 | 2010-04-26 15:52:20 -0400 | [diff] [blame] | 738 | mutex_init(&rdev->vram_mutex); |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 739 | INIT_LIST_HEAD(&rdev->gem.objects); |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 740 | init_waitqueue_head(&rdev->irq.vblank_queue); |
Alex Deucher | 2031f77 | 2010-04-22 12:52:11 -0400 | [diff] [blame] | 741 | init_waitqueue_head(&rdev->irq.idle_queue); |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 742 | /* initialize vm here */ |
| 743 | rdev->vm_manager.use_bitmap = 1; |
| 744 | rdev->vm_manager.max_pfn = 1 << 20; |
| 745 | INIT_LIST_HEAD(&rdev->vm_manager.lru_vm); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 746 | |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 747 | /* Set asic functions */ |
| 748 | r = radeon_asic_init(rdev); |
Jerome Glisse | 3642133 | 2009-12-11 21:18:34 +0100 | [diff] [blame] | 749 | if (r) |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 750 | return r; |
Jerome Glisse | 3642133 | 2009-12-11 21:18:34 +0100 | [diff] [blame] | 751 | radeon_check_arguments(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 752 | |
Alex Deucher | f95df9c | 2010-03-21 14:02:25 -0400 | [diff] [blame] | 753 | /* all of the newer IGP chips have an internal gart |
| 754 | * However some rs4xx report as AGP, so remove that here. |
| 755 | */ |
| 756 | if ((rdev->family >= CHIP_RS400) && |
| 757 | (rdev->flags & RADEON_IS_IGP)) { |
| 758 | rdev->flags &= ~RADEON_IS_AGP; |
| 759 | } |
| 760 | |
Jerome Glisse | 30256a3 | 2009-11-30 17:47:59 +0100 | [diff] [blame] | 761 | if (rdev->flags & RADEON_IS_AGP && radeon_agpmode == -1) { |
Jerome Glisse | b574f25 | 2009-10-06 19:04:29 +0200 | [diff] [blame] | 762 | radeon_agp_disable(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 763 | } |
| 764 | |
Dave Airlie | ad49f50 | 2009-07-10 22:36:26 +1000 | [diff] [blame] | 765 | /* set DMA mask + need_dma32 flags. |
| 766 | * PCIE - can handle 40-bits. |
Alex Deucher | 005a83f | 2011-10-05 10:02:57 -0400 | [diff] [blame] | 767 | * IGP - can handle 40-bits |
Dave Airlie | ad49f50 | 2009-07-10 22:36:26 +1000 | [diff] [blame] | 768 | * AGP - generally dma32 is safest |
Alex Deucher | 005a83f | 2011-10-05 10:02:57 -0400 | [diff] [blame] | 769 | * PCI - dma32 for legacy pci gart, 40 bits on newer asics |
Dave Airlie | ad49f50 | 2009-07-10 22:36:26 +1000 | [diff] [blame] | 770 | */ |
| 771 | rdev->need_dma32 = false; |
| 772 | if (rdev->flags & RADEON_IS_AGP) |
| 773 | rdev->need_dma32 = true; |
Alex Deucher | 005a83f | 2011-10-05 10:02:57 -0400 | [diff] [blame] | 774 | if ((rdev->flags & RADEON_IS_PCI) && |
| 775 | (rdev->family < CHIP_RS400)) |
Dave Airlie | ad49f50 | 2009-07-10 22:36:26 +1000 | [diff] [blame] | 776 | rdev->need_dma32 = true; |
| 777 | |
| 778 | dma_bits = rdev->need_dma32 ? 32 : 40; |
| 779 | r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits)); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 780 | if (r) { |
Daniel Haid | 62fff81 | 2011-06-08 20:04:45 +1000 | [diff] [blame] | 781 | rdev->need_dma32 = true; |
Konrad Rzeszutek Wilk | c52494f | 2011-10-17 17:15:08 -0400 | [diff] [blame] | 782 | dma_bits = 32; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 783 | printk(KERN_WARNING "radeon: No suitable DMA available.\n"); |
| 784 | } |
Konrad Rzeszutek Wilk | c52494f | 2011-10-17 17:15:08 -0400 | [diff] [blame] | 785 | r = pci_set_consistent_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits)); |
| 786 | if (r) { |
| 787 | pci_set_consistent_dma_mask(rdev->pdev, DMA_BIT_MASK(32)); |
| 788 | printk(KERN_WARNING "radeon: No coherent DMA available.\n"); |
| 789 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 790 | |
| 791 | /* Registers mapping */ |
| 792 | /* TODO: block userspace mapping of io register */ |
Jordan Crouse | 01d73a6 | 2010-05-27 13:40:24 -0600 | [diff] [blame] | 793 | rdev->rmmio_base = pci_resource_start(rdev->pdev, 2); |
| 794 | rdev->rmmio_size = pci_resource_len(rdev->pdev, 2); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 795 | rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size); |
| 796 | if (rdev->rmmio == NULL) { |
| 797 | return -ENOMEM; |
| 798 | } |
| 799 | DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base); |
| 800 | DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size); |
| 801 | |
Alex Deucher | 351a52a | 2010-06-30 11:52:50 -0400 | [diff] [blame] | 802 | /* io port mapping */ |
| 803 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 804 | if (pci_resource_flags(rdev->pdev, i) & IORESOURCE_IO) { |
| 805 | rdev->rio_mem_size = pci_resource_len(rdev->pdev, i); |
| 806 | rdev->rio_mem = pci_iomap(rdev->pdev, i, rdev->rio_mem_size); |
| 807 | break; |
| 808 | } |
| 809 | } |
| 810 | if (rdev->rio_mem == NULL) |
| 811 | DRM_ERROR("Unable to find PCI I/O BAR\n"); |
| 812 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 813 | /* if we have > 1 VGA cards, then disable the radeon VGA resources */ |
Dave Airlie | 93239ea | 2009-10-28 11:09:58 +1000 | [diff] [blame] | 814 | /* this will fail for cards that aren't VGA class devices, just |
| 815 | * ignore it */ |
| 816 | vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode); |
Takashi Iwai | 26ec685 | 2012-05-11 07:51:17 +0200 | [diff] [blame^] | 817 | vga_switcheroo_register_client(rdev->pdev, &radeon_switcheroo_ops); |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 818 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 819 | r = radeon_init(rdev); |
Jerome Glisse | b574f25 | 2009-10-06 19:04:29 +0200 | [diff] [blame] | 820 | if (r) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 821 | return r; |
Michel Dänzer | b1e3a6d | 2009-06-23 16:12:54 +0200 | [diff] [blame] | 822 | |
Jerome Glisse | b574f25 | 2009-10-06 19:04:29 +0200 | [diff] [blame] | 823 | if (rdev->flags & RADEON_IS_AGP && !rdev->accel_working) { |
| 824 | /* Acceleration not working on AGP card try again |
| 825 | * with fallback to PCI or PCIE GART |
| 826 | */ |
Jerome Glisse | a2d07b7 | 2010-03-09 14:45:11 +0000 | [diff] [blame] | 827 | radeon_asic_reset(rdev); |
Jerome Glisse | b574f25 | 2009-10-06 19:04:29 +0200 | [diff] [blame] | 828 | radeon_fini(rdev); |
| 829 | radeon_agp_disable(rdev); |
| 830 | r = radeon_init(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 831 | if (r) |
| 832 | return r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 833 | } |
Christian König | 60a7e39 | 2011-09-27 12:31:00 +0200 | [diff] [blame] | 834 | if ((radeon_testing & 1)) { |
Michel Dänzer | ecc0b32 | 2009-07-21 11:23:57 +0200 | [diff] [blame] | 835 | radeon_test_moves(rdev); |
| 836 | } |
Christian König | 60a7e39 | 2011-09-27 12:31:00 +0200 | [diff] [blame] | 837 | if ((radeon_testing & 2)) { |
| 838 | radeon_test_syncing(rdev); |
| 839 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 840 | if (radeon_benchmarking) { |
Ilija Hadzic | 638dd7d | 2011-10-12 23:29:39 -0400 | [diff] [blame] | 841 | radeon_benchmark(rdev, radeon_benchmarking); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 842 | } |
Jerome Glisse | 6cf8a3f | 2009-09-10 21:46:48 +0200 | [diff] [blame] | 843 | return 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 844 | } |
| 845 | |
Christian König | 4d8bf9a | 2011-10-24 14:54:54 +0200 | [diff] [blame] | 846 | static void radeon_debugfs_remove_files(struct radeon_device *rdev); |
| 847 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 848 | void radeon_device_fini(struct radeon_device *rdev) |
| 849 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 850 | DRM_INFO("radeon: finishing device.\n"); |
| 851 | rdev->shutdown = true; |
Jerome Glisse | 90aca4d | 2010-03-09 14:45:12 +0000 | [diff] [blame] | 852 | /* evict vram memory */ |
| 853 | radeon_bo_evict_vram(rdev); |
Jerome Glisse | 62a8ea3 | 2009-10-01 18:02:11 +0200 | [diff] [blame] | 854 | radeon_fini(rdev); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 855 | vga_switcheroo_unregister_client(rdev->pdev); |
Dave Airlie | c1176d6 | 2009-10-08 14:03:05 +1000 | [diff] [blame] | 856 | vga_client_register(rdev->pdev, NULL, NULL, NULL); |
Alex Deucher | e0a2ca7 | 2010-07-08 12:24:52 -0400 | [diff] [blame] | 857 | if (rdev->rio_mem) |
| 858 | pci_iounmap(rdev->pdev, rdev->rio_mem); |
Alex Deucher | 351a52a | 2010-06-30 11:52:50 -0400 | [diff] [blame] | 859 | rdev->rio_mem = NULL; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 860 | iounmap(rdev->rmmio); |
| 861 | rdev->rmmio = NULL; |
Christian König | 4d8bf9a | 2011-10-24 14:54:54 +0200 | [diff] [blame] | 862 | radeon_debugfs_remove_files(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | |
| 866 | /* |
| 867 | * Suspend & resume. |
| 868 | */ |
| 869 | int radeon_suspend_kms(struct drm_device *dev, pm_message_t state) |
| 870 | { |
Darren Jenkins | 875c186 | 2009-12-30 12:18:30 +1100 | [diff] [blame] | 871 | struct radeon_device *rdev; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 872 | struct drm_crtc *crtc; |
Alex Deucher | d8dcaa1 | 2010-06-02 12:08:41 -0400 | [diff] [blame] | 873 | struct drm_connector *connector; |
Alex Deucher | 7465280 | 2011-08-25 13:39:48 -0400 | [diff] [blame] | 874 | int i, r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 875 | |
Darren Jenkins | 875c186 | 2009-12-30 12:18:30 +1100 | [diff] [blame] | 876 | if (dev == NULL || dev->dev_private == NULL) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 877 | return -ENODEV; |
| 878 | } |
| 879 | if (state.event == PM_EVENT_PRETHAW) { |
| 880 | return 0; |
| 881 | } |
Darren Jenkins | 875c186 | 2009-12-30 12:18:30 +1100 | [diff] [blame] | 882 | rdev = dev->dev_private; |
| 883 | |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 884 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 885 | return 0; |
Alex Deucher | d8dcaa1 | 2010-06-02 12:08:41 -0400 | [diff] [blame] | 886 | |
Seth Forshee | 86698c2 | 2012-01-31 19:06:25 -0600 | [diff] [blame] | 887 | drm_kms_helper_poll_disable(dev); |
| 888 | |
Alex Deucher | d8dcaa1 | 2010-06-02 12:08:41 -0400 | [diff] [blame] | 889 | /* turn off display hw */ |
| 890 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 891 | drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF); |
| 892 | } |
| 893 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 894 | /* unpin the front buffers */ |
| 895 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 896 | struct radeon_framebuffer *rfb = to_radeon_framebuffer(crtc->fb); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 897 | struct radeon_bo *robj; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 898 | |
| 899 | if (rfb == NULL || rfb->obj == NULL) { |
| 900 | continue; |
| 901 | } |
Daniel Vetter | 7e4d15d | 2011-02-18 17:59:17 +0100 | [diff] [blame] | 902 | robj = gem_to_radeon_bo(rfb->obj); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 903 | /* don't unpin kernel fb objects */ |
| 904 | if (!radeon_fbdev_robj_is_fb(rdev, robj)) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 905 | r = radeon_bo_reserve(robj, false); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 906 | if (r == 0) { |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 907 | radeon_bo_unpin(robj); |
| 908 | radeon_bo_unreserve(robj); |
| 909 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | /* evict vram memory */ |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 913 | radeon_bo_evict_vram(rdev); |
Christian König | 8a47cc9 | 2012-05-09 15:34:48 +0200 | [diff] [blame] | 914 | |
| 915 | mutex_lock(&rdev->ring_lock); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 916 | /* wait for gpu to finish processing current batch */ |
Alex Deucher | 7465280 | 2011-08-25 13:39:48 -0400 | [diff] [blame] | 917 | for (i = 0; i < RADEON_NUM_RINGS; i++) |
Christian König | 8a47cc9 | 2012-05-09 15:34:48 +0200 | [diff] [blame] | 918 | radeon_fence_wait_empty_locked(rdev, i); |
| 919 | mutex_unlock(&rdev->ring_lock); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 920 | |
Yang Zhao | f657c2a | 2009-09-15 12:21:01 +1000 | [diff] [blame] | 921 | radeon_save_bios_scratch_regs(rdev); |
| 922 | |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 923 | radeon_pm_suspend(rdev); |
Jerome Glisse | 62a8ea3 | 2009-10-01 18:02:11 +0200 | [diff] [blame] | 924 | radeon_suspend(rdev); |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 925 | radeon_hpd_fini(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 926 | /* evict remaining vram memory */ |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 927 | radeon_bo_evict_vram(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 928 | |
Jerome Glisse | 10b0612 | 2010-05-21 18:48:54 +0200 | [diff] [blame] | 929 | radeon_agp_suspend(rdev); |
| 930 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 931 | pci_save_state(dev->pdev); |
| 932 | if (state.event == PM_EVENT_SUSPEND) { |
| 933 | /* Shut down the device */ |
| 934 | pci_disable_device(dev->pdev); |
| 935 | pci_set_power_state(dev->pdev, PCI_D3hot); |
| 936 | } |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 937 | console_lock(); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 938 | radeon_fbdev_set_suspend(rdev, 1); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 939 | console_unlock(); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 940 | return 0; |
| 941 | } |
| 942 | |
| 943 | int radeon_resume_kms(struct drm_device *dev) |
| 944 | { |
Cedric Godin | 09bdf59 | 2010-06-11 14:40:56 -0400 | [diff] [blame] | 945 | struct drm_connector *connector; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 946 | struct radeon_device *rdev = dev->dev_private; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 947 | |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 948 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 949 | return 0; |
| 950 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 951 | console_lock(); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 952 | pci_set_power_state(dev->pdev, PCI_D0); |
| 953 | pci_restore_state(dev->pdev); |
| 954 | if (pci_enable_device(dev->pdev)) { |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 955 | console_unlock(); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 956 | return -1; |
| 957 | } |
Dave Airlie | 0ebf171 | 2009-11-05 15:39:10 +1000 | [diff] [blame] | 958 | /* resume AGP if in use */ |
| 959 | radeon_agp_resume(rdev); |
Jerome Glisse | 62a8ea3 | 2009-10-01 18:02:11 +0200 | [diff] [blame] | 960 | radeon_resume(rdev); |
Alex Deucher | ce8f537 | 2010-05-07 15:10:16 -0400 | [diff] [blame] | 961 | radeon_pm_resume(rdev); |
Yang Zhao | f657c2a | 2009-09-15 12:21:01 +1000 | [diff] [blame] | 962 | radeon_restore_bios_scratch_regs(rdev); |
Cedric Godin | 09bdf59 | 2010-06-11 14:40:56 -0400 | [diff] [blame] | 963 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 964 | radeon_fbdev_set_suspend(rdev, 0); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 965 | console_unlock(); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 966 | |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 967 | /* init dig PHYs, disp eng pll */ |
| 968 | if (rdev->is_atom_bios) { |
Alex Deucher | ac89af1 | 2011-05-22 13:20:36 -0400 | [diff] [blame] | 969 | radeon_atom_encoder_init(rdev); |
Alex Deucher | f3f1f03 | 2012-03-20 17:18:04 -0400 | [diff] [blame] | 970 | radeon_atom_disp_eng_pll_init(rdev); |
Alex Deucher | 3fa47d9 | 2012-01-20 14:56:39 -0500 | [diff] [blame] | 971 | } |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 972 | /* reset hpd state */ |
| 973 | radeon_hpd_init(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 974 | /* blat the mode back in */ |
| 975 | drm_helper_resume_force_mode(dev); |
Alex Deucher | a93f344 | 2010-12-20 11:22:29 -0500 | [diff] [blame] | 976 | /* turn on display hw */ |
| 977 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 978 | drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON); |
| 979 | } |
Seth Forshee | 86698c2 | 2012-01-31 19:06:25 -0600 | [diff] [blame] | 980 | |
| 981 | drm_kms_helper_poll_enable(dev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 982 | return 0; |
| 983 | } |
| 984 | |
Jerome Glisse | 90aca4d | 2010-03-09 14:45:12 +0000 | [diff] [blame] | 985 | int radeon_gpu_reset(struct radeon_device *rdev) |
| 986 | { |
| 987 | int r; |
Dave Airlie | 8fd1b84 | 2011-02-10 14:46:06 +1000 | [diff] [blame] | 988 | int resched; |
Jerome Glisse | 90aca4d | 2010-03-09 14:45:12 +0000 | [diff] [blame] | 989 | |
| 990 | radeon_save_bios_scratch_regs(rdev); |
Dave Airlie | 8fd1b84 | 2011-02-10 14:46:06 +1000 | [diff] [blame] | 991 | /* block TTM */ |
| 992 | resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev); |
Jerome Glisse | 90aca4d | 2010-03-09 14:45:12 +0000 | [diff] [blame] | 993 | radeon_suspend(rdev); |
| 994 | |
| 995 | r = radeon_asic_reset(rdev); |
| 996 | if (!r) { |
| 997 | dev_info(rdev->dev, "GPU reset succeed\n"); |
| 998 | radeon_resume(rdev); |
| 999 | radeon_restore_bios_scratch_regs(rdev); |
| 1000 | drm_helper_resume_force_mode(rdev->ddev); |
Dave Airlie | 8fd1b84 | 2011-02-10 14:46:06 +1000 | [diff] [blame] | 1001 | ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched); |
Jerome Glisse | 90aca4d | 2010-03-09 14:45:12 +0000 | [diff] [blame] | 1002 | } |
Michel Dänzer | 7a1619b | 2011-11-10 18:57:26 +0100 | [diff] [blame] | 1003 | |
Michel Dänzer | 7a1619b | 2011-11-10 18:57:26 +0100 | [diff] [blame] | 1004 | if (r) { |
| 1005 | /* bad news, how to tell it to userspace ? */ |
| 1006 | dev_info(rdev->dev, "GPU reset failed\n"); |
| 1007 | } |
| 1008 | |
Jerome Glisse | 90aca4d | 2010-03-09 14:45:12 +0000 | [diff] [blame] | 1009 | return r; |
| 1010 | } |
| 1011 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1012 | |
| 1013 | /* |
| 1014 | * Debugfs |
| 1015 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1016 | int radeon_debugfs_add_files(struct radeon_device *rdev, |
| 1017 | struct drm_info_list *files, |
| 1018 | unsigned nfiles) |
| 1019 | { |
| 1020 | unsigned i; |
| 1021 | |
Christian König | 4d8bf9a | 2011-10-24 14:54:54 +0200 | [diff] [blame] | 1022 | for (i = 0; i < rdev->debugfs_count; i++) { |
| 1023 | if (rdev->debugfs[i].files == files) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1024 | /* Already registered */ |
| 1025 | return 0; |
| 1026 | } |
| 1027 | } |
Michael Witten | c245cb9 | 2011-09-16 20:45:30 +0000 | [diff] [blame] | 1028 | |
Christian König | 4d8bf9a | 2011-10-24 14:54:54 +0200 | [diff] [blame] | 1029 | i = rdev->debugfs_count + 1; |
Michael Witten | c245cb9 | 2011-09-16 20:45:30 +0000 | [diff] [blame] | 1030 | if (i > RADEON_DEBUGFS_MAX_COMPONENTS) { |
| 1031 | DRM_ERROR("Reached maximum number of debugfs components.\n"); |
| 1032 | DRM_ERROR("Report so we increase " |
| 1033 | "RADEON_DEBUGFS_MAX_COMPONENTS.\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1034 | return -EINVAL; |
| 1035 | } |
Christian König | 4d8bf9a | 2011-10-24 14:54:54 +0200 | [diff] [blame] | 1036 | rdev->debugfs[rdev->debugfs_count].files = files; |
| 1037 | rdev->debugfs[rdev->debugfs_count].num_files = nfiles; |
| 1038 | rdev->debugfs_count = i; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1039 | #if defined(CONFIG_DEBUG_FS) |
| 1040 | drm_debugfs_create_files(files, nfiles, |
| 1041 | rdev->ddev->control->debugfs_root, |
| 1042 | rdev->ddev->control); |
| 1043 | drm_debugfs_create_files(files, nfiles, |
| 1044 | rdev->ddev->primary->debugfs_root, |
| 1045 | rdev->ddev->primary); |
| 1046 | #endif |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
Christian König | 4d8bf9a | 2011-10-24 14:54:54 +0200 | [diff] [blame] | 1050 | static void radeon_debugfs_remove_files(struct radeon_device *rdev) |
| 1051 | { |
| 1052 | #if defined(CONFIG_DEBUG_FS) |
| 1053 | unsigned i; |
| 1054 | |
| 1055 | for (i = 0; i < rdev->debugfs_count; i++) { |
| 1056 | drm_debugfs_remove_files(rdev->debugfs[i].files, |
| 1057 | rdev->debugfs[i].num_files, |
| 1058 | rdev->ddev->control); |
| 1059 | drm_debugfs_remove_files(rdev->debugfs[i].files, |
| 1060 | rdev->debugfs[i].num_files, |
| 1061 | rdev->ddev->primary); |
| 1062 | } |
| 1063 | #endif |
| 1064 | } |
| 1065 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1066 | #if defined(CONFIG_DEBUG_FS) |
| 1067 | int radeon_debugfs_init(struct drm_minor *minor) |
| 1068 | { |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
| 1072 | void radeon_debugfs_cleanup(struct drm_minor *minor) |
| 1073 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1074 | } |
| 1075 | #endif |