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> |
| 29 | #include <drm/drmP.h> |
| 30 | #include <drm/drm_crtc_helper.h> |
| 31 | #include <drm/radeon_drm.h> |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 32 | #include <linux/vgaarb.h> |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 33 | #include <linux/vga_switcheroo.h> |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 34 | #include "radeon_reg.h" |
| 35 | #include "radeon.h" |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 36 | #include "atom.h" |
| 37 | |
| 38 | /* |
Michel Dänzer | b1e3a6d | 2009-06-23 16:12:54 +0200 | [diff] [blame] | 39 | * Clear GPU surface registers. |
| 40 | */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 41 | void radeon_surface_init(struct radeon_device *rdev) |
Michel Dänzer | b1e3a6d | 2009-06-23 16:12:54 +0200 | [diff] [blame] | 42 | { |
| 43 | /* FIXME: check this out */ |
| 44 | if (rdev->family < CHIP_R600) { |
| 45 | int i; |
| 46 | |
Dave Airlie | 550e2d9 | 2009-12-09 14:15:38 +1000 | [diff] [blame] | 47 | for (i = 0; i < RADEON_GEM_MAX_SURFACES; i++) { |
| 48 | if (rdev->surface_regs[i].bo) |
| 49 | radeon_bo_get_surface_reg(rdev->surface_regs[i].bo); |
| 50 | else |
| 51 | radeon_clear_surface_reg(rdev, i); |
Michel Dänzer | b1e3a6d | 2009-06-23 16:12:54 +0200 | [diff] [blame] | 52 | } |
Dave Airlie | e024e11 | 2009-06-24 09:48:08 +1000 | [diff] [blame] | 53 | /* enable surfaces */ |
| 54 | WREG32(RADEON_SURFACE_CNTL, 0); |
Michel Dänzer | b1e3a6d | 2009-06-23 16:12:54 +0200 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
| 58 | /* |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 59 | * GPU scratch registers helpers function. |
| 60 | */ |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 61 | void radeon_scratch_init(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 62 | { |
| 63 | int i; |
| 64 | |
| 65 | /* FIXME: check this out */ |
| 66 | if (rdev->family < CHIP_R300) { |
| 67 | rdev->scratch.num_reg = 5; |
| 68 | } else { |
| 69 | rdev->scratch.num_reg = 7; |
| 70 | } |
| 71 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
| 72 | rdev->scratch.free[i] = true; |
| 73 | rdev->scratch.reg[i] = RADEON_SCRATCH_REG0 + (i * 4); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg) |
| 78 | { |
| 79 | int i; |
| 80 | |
| 81 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
| 82 | if (rdev->scratch.free[i]) { |
| 83 | rdev->scratch.free[i] = false; |
| 84 | *reg = rdev->scratch.reg[i]; |
| 85 | return 0; |
| 86 | } |
| 87 | } |
| 88 | return -EINVAL; |
| 89 | } |
| 90 | |
| 91 | void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg) |
| 92 | { |
| 93 | int i; |
| 94 | |
| 95 | for (i = 0; i < rdev->scratch.num_reg; i++) { |
| 96 | if (rdev->scratch.reg[i] == reg) { |
| 97 | rdev->scratch.free[i] = true; |
| 98 | return; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 103 | /** |
| 104 | * radeon_vram_location - try to find VRAM location |
| 105 | * @rdev: radeon device structure holding all necessary informations |
| 106 | * @mc: memory controller structure holding memory informations |
| 107 | * @base: base address at which to put VRAM |
| 108 | * |
| 109 | * Function will place try to place VRAM at base address provided |
| 110 | * as parameter (which is so far either PCI aperture address or |
| 111 | * for IGP TOM base address). |
| 112 | * |
| 113 | * If there is not enough space to fit the unvisible VRAM in the 32bits |
| 114 | * address space then we limit the VRAM size to the aperture. |
| 115 | * |
| 116 | * If we are using AGP and if the AGP aperture doesn't allow us to have |
| 117 | * room for all the VRAM than we restrict the VRAM to the PCI aperture |
| 118 | * size and print a warning. |
| 119 | * |
| 120 | * This function will never fails, worst case are limiting VRAM. |
| 121 | * |
| 122 | * Note: GTT start, end, size should be initialized before calling this |
| 123 | * function on AGP platform. |
| 124 | * |
| 125 | * Note: We don't explictly enforce VRAM start to be aligned on VRAM size, |
| 126 | * this shouldn't be a problem as we are using the PCI aperture as a reference. |
| 127 | * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but |
| 128 | * not IGP. |
| 129 | * |
| 130 | * Note: we use mc_vram_size as on some board we need to program the mc to |
| 131 | * cover the whole aperture even if VRAM size is inferior to aperture size |
| 132 | * Novell bug 204882 + along with lots of ubuntu ones |
| 133 | * |
| 134 | * Note: when limiting vram it's safe to overwritte real_vram_size because |
| 135 | * we are not in case where real_vram_size is inferior to mc_vram_size (ie |
| 136 | * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu |
| 137 | * ones) |
| 138 | * |
| 139 | * Note: IGP TOM addr should be the same as the aperture addr, we don't |
| 140 | * explicitly check for that thought. |
| 141 | * |
| 142 | * FIXME: when reducing VRAM size align new size on power of 2. |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 143 | */ |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 144 | 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] | 145 | { |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 146 | mc->vram_start = base; |
| 147 | if (mc->mc_vram_size > (0xFFFFFFFF - base + 1)) { |
| 148 | dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n"); |
| 149 | mc->real_vram_size = mc->aper_size; |
| 150 | mc->mc_vram_size = mc->aper_size; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 151 | } |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 152 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
| 153 | if (rdev->flags & RADEON_IS_AGP && mc->vram_end > mc->gtt_start && mc->vram_end <= mc->gtt_end) { |
| 154 | dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n"); |
| 155 | mc->real_vram_size = mc->aper_size; |
| 156 | mc->mc_vram_size = mc->aper_size; |
| 157 | } |
| 158 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
| 159 | dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n", |
| 160 | mc->mc_vram_size >> 20, mc->vram_start, |
| 161 | mc->vram_end, mc->real_vram_size >> 20); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Jerome Glisse | d594e46 | 2010-02-17 21:54:29 +0000 | [diff] [blame] | 164 | /** |
| 165 | * radeon_gtt_location - try to find GTT location |
| 166 | * @rdev: radeon device structure holding all necessary informations |
| 167 | * @mc: memory controller structure holding memory informations |
| 168 | * |
| 169 | * Function will place try to place GTT before or after VRAM. |
| 170 | * |
| 171 | * If GTT size is bigger than space left then we ajust GTT size. |
| 172 | * Thus function will never fails. |
| 173 | * |
| 174 | * FIXME: when reducing GTT size align new size on power of 2. |
| 175 | */ |
| 176 | void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc) |
| 177 | { |
| 178 | u64 size_af, size_bf; |
| 179 | |
| 180 | size_af = 0xFFFFFFFF - mc->vram_end; |
| 181 | size_bf = mc->vram_start; |
| 182 | if (size_bf > size_af) { |
| 183 | if (mc->gtt_size > size_bf) { |
| 184 | dev_warn(rdev->dev, "limiting GTT\n"); |
| 185 | mc->gtt_size = size_bf; |
| 186 | } |
| 187 | mc->gtt_start = mc->vram_start - mc->gtt_size; |
| 188 | } else { |
| 189 | if (mc->gtt_size > size_af) { |
| 190 | dev_warn(rdev->dev, "limiting GTT\n"); |
| 191 | mc->gtt_size = size_af; |
| 192 | } |
| 193 | mc->gtt_start = mc->vram_end + 1; |
| 194 | } |
| 195 | mc->gtt_end = mc->gtt_start + mc->gtt_size - 1; |
| 196 | dev_info(rdev->dev, "GTT: %lluM 0x%08llX - 0x%08llX\n", |
| 197 | mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end); |
| 198 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 199 | |
| 200 | /* |
| 201 | * GPU helpers function. |
| 202 | */ |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 203 | bool radeon_card_posted(struct radeon_device *rdev) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 204 | { |
| 205 | uint32_t reg; |
| 206 | |
| 207 | /* first check CRTCs */ |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 208 | if (ASIC_IS_DCE4(rdev)) { |
| 209 | reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) | |
| 210 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) | |
| 211 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) | |
| 212 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) | |
| 213 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) | |
| 214 | RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET); |
| 215 | if (reg & EVERGREEN_CRTC_MASTER_EN) |
| 216 | return true; |
| 217 | } else if (ASIC_IS_AVIVO(rdev)) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 218 | reg = RREG32(AVIVO_D1CRTC_CONTROL) | |
| 219 | RREG32(AVIVO_D2CRTC_CONTROL); |
| 220 | if (reg & AVIVO_CRTC_EN) { |
| 221 | return true; |
| 222 | } |
| 223 | } else { |
| 224 | reg = RREG32(RADEON_CRTC_GEN_CNTL) | |
| 225 | RREG32(RADEON_CRTC2_GEN_CNTL); |
| 226 | if (reg & RADEON_CRTC_EN) { |
| 227 | return true; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | /* then check MEM_SIZE, in case the crtcs are off */ |
| 232 | if (rdev->family >= CHIP_R600) |
| 233 | reg = RREG32(R600_CONFIG_MEMSIZE); |
| 234 | else |
| 235 | reg = RREG32(RADEON_CONFIG_MEMSIZE); |
| 236 | |
| 237 | if (reg) |
| 238 | return true; |
| 239 | |
| 240 | return false; |
| 241 | |
| 242 | } |
| 243 | |
Alex Deucher | f47299c | 2010-03-16 20:54:38 -0400 | [diff] [blame^] | 244 | void radeon_update_bandwidth_info(struct radeon_device *rdev) |
| 245 | { |
| 246 | fixed20_12 a; |
| 247 | u32 sclk, mclk; |
| 248 | |
| 249 | if (rdev->flags & RADEON_IS_IGP) { |
| 250 | sclk = radeon_get_engine_clock(rdev); |
| 251 | mclk = rdev->clock.default_mclk; |
| 252 | |
| 253 | a.full = rfixed_const(100); |
| 254 | rdev->pm.sclk.full = rfixed_const(sclk); |
| 255 | rdev->pm.sclk.full = rfixed_div(rdev->pm.sclk, a); |
| 256 | rdev->pm.mclk.full = rfixed_const(mclk); |
| 257 | rdev->pm.mclk.full = rfixed_div(rdev->pm.mclk, a); |
| 258 | |
| 259 | a.full = rfixed_const(16); |
| 260 | /* core_bandwidth = sclk(Mhz) * 16 */ |
| 261 | rdev->pm.core_bandwidth.full = rfixed_div(rdev->pm.sclk, a); |
| 262 | } else { |
| 263 | sclk = radeon_get_engine_clock(rdev); |
| 264 | mclk = radeon_get_memory_clock(rdev); |
| 265 | |
| 266 | a.full = rfixed_const(100); |
| 267 | rdev->pm.sclk.full = rfixed_const(sclk); |
| 268 | rdev->pm.sclk.full = rfixed_div(rdev->pm.sclk, a); |
| 269 | rdev->pm.mclk.full = rfixed_const(mclk); |
| 270 | rdev->pm.mclk.full = rfixed_div(rdev->pm.mclk, a); |
| 271 | } |
| 272 | } |
| 273 | |
Dave Airlie | 72542d7 | 2009-12-01 14:06:31 +1000 | [diff] [blame] | 274 | bool radeon_boot_test_post_card(struct radeon_device *rdev) |
| 275 | { |
| 276 | if (radeon_card_posted(rdev)) |
| 277 | return true; |
| 278 | |
| 279 | if (rdev->bios) { |
| 280 | DRM_INFO("GPU not posted. posting now...\n"); |
| 281 | if (rdev->is_atom_bios) |
| 282 | atom_asic_init(rdev->mode_info.atom_context); |
| 283 | else |
| 284 | radeon_combios_asic_init(rdev->ddev); |
| 285 | return true; |
| 286 | } else { |
| 287 | dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); |
| 288 | return false; |
| 289 | } |
| 290 | } |
| 291 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 292 | int radeon_dummy_page_init(struct radeon_device *rdev) |
| 293 | { |
Dave Airlie | 8256856 | 2010-02-05 16:00:07 +1000 | [diff] [blame] | 294 | if (rdev->dummy_page.page) |
| 295 | return 0; |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 296 | rdev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO); |
| 297 | if (rdev->dummy_page.page == NULL) |
| 298 | return -ENOMEM; |
| 299 | rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page, |
| 300 | 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 301 | if (!rdev->dummy_page.addr) { |
| 302 | __free_page(rdev->dummy_page.page); |
| 303 | rdev->dummy_page.page = NULL; |
| 304 | return -ENOMEM; |
| 305 | } |
| 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | void radeon_dummy_page_fini(struct radeon_device *rdev) |
| 310 | { |
| 311 | if (rdev->dummy_page.page == NULL) |
| 312 | return; |
| 313 | pci_unmap_page(rdev->pdev, rdev->dummy_page.addr, |
| 314 | PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 315 | __free_page(rdev->dummy_page.page); |
| 316 | rdev->dummy_page.page = NULL; |
| 317 | } |
| 318 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 319 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 320 | /* ATOM accessor methods */ |
| 321 | static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) |
| 322 | { |
| 323 | struct radeon_device *rdev = info->dev->dev_private; |
| 324 | uint32_t r; |
| 325 | |
| 326 | r = rdev->pll_rreg(rdev, reg); |
| 327 | return r; |
| 328 | } |
| 329 | |
| 330 | static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) |
| 331 | { |
| 332 | struct radeon_device *rdev = info->dev->dev_private; |
| 333 | |
| 334 | rdev->pll_wreg(rdev, reg, val); |
| 335 | } |
| 336 | |
| 337 | static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) |
| 338 | { |
| 339 | struct radeon_device *rdev = info->dev->dev_private; |
| 340 | uint32_t r; |
| 341 | |
| 342 | r = rdev->mc_rreg(rdev, reg); |
| 343 | return r; |
| 344 | } |
| 345 | |
| 346 | static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) |
| 347 | { |
| 348 | struct radeon_device *rdev = info->dev->dev_private; |
| 349 | |
| 350 | rdev->mc_wreg(rdev, reg, val); |
| 351 | } |
| 352 | |
| 353 | static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) |
| 354 | { |
| 355 | struct radeon_device *rdev = info->dev->dev_private; |
| 356 | |
| 357 | WREG32(reg*4, val); |
| 358 | } |
| 359 | |
| 360 | static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) |
| 361 | { |
| 362 | struct radeon_device *rdev = info->dev->dev_private; |
| 363 | uint32_t r; |
| 364 | |
| 365 | r = RREG32(reg*4); |
| 366 | return r; |
| 367 | } |
| 368 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 369 | int radeon_atombios_init(struct radeon_device *rdev) |
| 370 | { |
Mathias Fröhlich | 61c4b24 | 2009-10-27 15:08:01 -0400 | [diff] [blame] | 371 | struct card_info *atom_card_info = |
| 372 | kzalloc(sizeof(struct card_info), GFP_KERNEL); |
| 373 | |
| 374 | if (!atom_card_info) |
| 375 | return -ENOMEM; |
| 376 | |
| 377 | rdev->mode_info.atom_card_info = atom_card_info; |
| 378 | atom_card_info->dev = rdev->ddev; |
| 379 | atom_card_info->reg_read = cail_reg_read; |
| 380 | atom_card_info->reg_write = cail_reg_write; |
| 381 | atom_card_info->mc_read = cail_mc_read; |
| 382 | atom_card_info->mc_write = cail_mc_write; |
| 383 | atom_card_info->pll_read = cail_pll_read; |
| 384 | atom_card_info->pll_write = cail_pll_write; |
| 385 | |
| 386 | 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] | 387 | mutex_init(&rdev->mode_info.atom_context->mutex); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 388 | radeon_atom_initialize_bios_scratch_regs(rdev->ddev); |
Dave Airlie | d904ef9 | 2009-11-17 06:29:46 +1000 | [diff] [blame] | 389 | atom_allocate_fb_scratch(rdev->mode_info.atom_context); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | void radeon_atombios_fini(struct radeon_device *rdev) |
| 394 | { |
Jerome Glisse | 4a04a84 | 2009-12-09 17:39:16 +0100 | [diff] [blame] | 395 | if (rdev->mode_info.atom_context) { |
| 396 | kfree(rdev->mode_info.atom_context->scratch); |
| 397 | kfree(rdev->mode_info.atom_context); |
| 398 | } |
Mathias Fröhlich | 61c4b24 | 2009-10-27 15:08:01 -0400 | [diff] [blame] | 399 | kfree(rdev->mode_info.atom_card_info); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | int radeon_combios_init(struct radeon_device *rdev) |
| 403 | { |
| 404 | radeon_combios_initialize_bios_scratch_regs(rdev->ddev); |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | void radeon_combios_fini(struct radeon_device *rdev) |
| 409 | { |
| 410 | } |
| 411 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 412 | /* if we get transitioned to only one device, tak VGA back */ |
| 413 | static unsigned int radeon_vga_set_decode(void *cookie, bool state) |
| 414 | { |
| 415 | struct radeon_device *rdev = cookie; |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 416 | radeon_vga_set_state(rdev, state); |
| 417 | if (state) |
| 418 | return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | |
| 419 | VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 420 | else |
| 421 | return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 422 | } |
Dave Airlie | c1176d6 | 2009-10-08 14:03:05 +1000 | [diff] [blame] | 423 | |
Jerome Glisse | 3642133 | 2009-12-11 21:18:34 +0100 | [diff] [blame] | 424 | void radeon_check_arguments(struct radeon_device *rdev) |
| 425 | { |
| 426 | /* vramlimit must be a power of two */ |
| 427 | switch (radeon_vram_limit) { |
| 428 | case 0: |
| 429 | case 4: |
| 430 | case 8: |
| 431 | case 16: |
| 432 | case 32: |
| 433 | case 64: |
| 434 | case 128: |
| 435 | case 256: |
| 436 | case 512: |
| 437 | case 1024: |
| 438 | case 2048: |
| 439 | case 4096: |
| 440 | break; |
| 441 | default: |
| 442 | dev_warn(rdev->dev, "vram limit (%d) must be a power of 2\n", |
| 443 | radeon_vram_limit); |
| 444 | radeon_vram_limit = 0; |
| 445 | break; |
| 446 | } |
| 447 | radeon_vram_limit = radeon_vram_limit << 20; |
| 448 | /* gtt size must be power of two and greater or equal to 32M */ |
| 449 | switch (radeon_gart_size) { |
| 450 | case 4: |
| 451 | case 8: |
| 452 | case 16: |
| 453 | dev_warn(rdev->dev, "gart size (%d) too small forcing to 512M\n", |
| 454 | radeon_gart_size); |
| 455 | radeon_gart_size = 512; |
| 456 | break; |
| 457 | case 32: |
| 458 | case 64: |
| 459 | case 128: |
| 460 | case 256: |
| 461 | case 512: |
| 462 | case 1024: |
| 463 | case 2048: |
| 464 | case 4096: |
| 465 | break; |
| 466 | default: |
| 467 | dev_warn(rdev->dev, "gart size (%d) must be a power of 2\n", |
| 468 | radeon_gart_size); |
| 469 | radeon_gart_size = 512; |
| 470 | break; |
| 471 | } |
| 472 | rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; |
| 473 | /* AGP mode can only be -1, 1, 2, 4, 8 */ |
| 474 | switch (radeon_agpmode) { |
| 475 | case -1: |
| 476 | case 0: |
| 477 | case 1: |
| 478 | case 2: |
| 479 | case 4: |
| 480 | case 8: |
| 481 | break; |
| 482 | default: |
| 483 | dev_warn(rdev->dev, "invalid AGP mode %d (valid mode: " |
| 484 | "-1, 0, 1, 2, 4, 8)\n", radeon_agpmode); |
| 485 | radeon_agpmode = 0; |
| 486 | break; |
| 487 | } |
| 488 | } |
| 489 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 490 | static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) |
| 491 | { |
| 492 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 493 | struct radeon_device *rdev = dev->dev_private; |
| 494 | pm_message_t pmm = { .event = PM_EVENT_SUSPEND }; |
| 495 | if (state == VGA_SWITCHEROO_ON) { |
| 496 | printk(KERN_INFO "radeon: switched on\n"); |
| 497 | /* don't suspend or resume card normally */ |
| 498 | rdev->powered_down = false; |
| 499 | radeon_resume_kms(dev); |
| 500 | } else { |
| 501 | printk(KERN_INFO "radeon: switched off\n"); |
| 502 | radeon_suspend_kms(dev, pmm); |
| 503 | /* don't suspend or resume card normally */ |
| 504 | rdev->powered_down = true; |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | static bool radeon_switcheroo_can_switch(struct pci_dev *pdev) |
| 509 | { |
| 510 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 511 | bool can_switch; |
| 512 | |
| 513 | spin_lock(&dev->count_lock); |
| 514 | can_switch = (dev->open_count == 0); |
| 515 | spin_unlock(&dev->count_lock); |
| 516 | return can_switch; |
| 517 | } |
| 518 | |
| 519 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 520 | int radeon_device_init(struct radeon_device *rdev, |
| 521 | struct drm_device *ddev, |
| 522 | struct pci_dev *pdev, |
| 523 | uint32_t flags) |
| 524 | { |
Jerome Glisse | 6cf8a3f5 | 2009-09-10 21:46:48 +0200 | [diff] [blame] | 525 | int r; |
Dave Airlie | ad49f50 | 2009-07-10 22:36:26 +1000 | [diff] [blame] | 526 | int dma_bits; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 527 | |
| 528 | DRM_INFO("radeon: Initializing kernel modesetting.\n"); |
| 529 | rdev->shutdown = false; |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 530 | rdev->dev = &pdev->dev; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 531 | rdev->ddev = ddev; |
| 532 | rdev->pdev = pdev; |
| 533 | rdev->flags = flags; |
| 534 | rdev->family = flags & RADEON_FAMILY_MASK; |
| 535 | rdev->is_atom_bios = false; |
| 536 | rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT; |
| 537 | rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; |
| 538 | rdev->gpu_lockup = false; |
Jerome Glisse | 733289c | 2009-09-16 15:24:21 +0200 | [diff] [blame] | 539 | rdev->accel_working = false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 540 | /* mutex initialization are all done here so we |
| 541 | * can recall function without having locking issues */ |
| 542 | mutex_init(&rdev->cs_mutex); |
| 543 | mutex_init(&rdev->ib_pool.mutex); |
| 544 | mutex_init(&rdev->cp.mutex); |
Alex Deucher | 40bacf1 | 2009-12-23 03:23:21 -0500 | [diff] [blame] | 545 | mutex_init(&rdev->dc_hw_i2c_mutex); |
Alex Deucher | d8f60cf | 2009-12-01 13:43:46 -0500 | [diff] [blame] | 546 | if (rdev->family >= CHIP_R600) |
| 547 | spin_lock_init(&rdev->ih.lock); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 548 | mutex_init(&rdev->gem.mutex); |
Rafał Miłecki | c913e23 | 2009-12-22 23:02:16 +0100 | [diff] [blame] | 549 | mutex_init(&rdev->pm.mutex); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 550 | rwlock_init(&rdev->fence_drv.lock); |
Jerome Glisse | 9f022dd | 2009-09-11 15:35:22 +0200 | [diff] [blame] | 551 | INIT_LIST_HEAD(&rdev->gem.objects); |
Rafał Miłecki | 73a6d3f | 2010-01-08 00:22:47 +0100 | [diff] [blame] | 552 | init_waitqueue_head(&rdev->irq.vblank_queue); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 553 | |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 554 | /* setup workqueue */ |
| 555 | rdev->wq = create_workqueue("radeon"); |
| 556 | if (rdev->wq == NULL) |
| 557 | return -ENOMEM; |
| 558 | |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 559 | /* Set asic functions */ |
| 560 | r = radeon_asic_init(rdev); |
Jerome Glisse | 3642133 | 2009-12-11 21:18:34 +0100 | [diff] [blame] | 561 | if (r) |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 562 | return r; |
Jerome Glisse | 3642133 | 2009-12-11 21:18:34 +0100 | [diff] [blame] | 563 | radeon_check_arguments(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 564 | |
Jerome Glisse | 30256a3 | 2009-11-30 17:47:59 +0100 | [diff] [blame] | 565 | if (rdev->flags & RADEON_IS_AGP && radeon_agpmode == -1) { |
Jerome Glisse | b574f25 | 2009-10-06 19:04:29 +0200 | [diff] [blame] | 566 | radeon_agp_disable(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 567 | } |
| 568 | |
Dave Airlie | ad49f50 | 2009-07-10 22:36:26 +1000 | [diff] [blame] | 569 | /* set DMA mask + need_dma32 flags. |
| 570 | * PCIE - can handle 40-bits. |
| 571 | * IGP - can handle 40-bits (in theory) |
| 572 | * AGP - generally dma32 is safest |
| 573 | * PCI - only dma32 |
| 574 | */ |
| 575 | rdev->need_dma32 = false; |
| 576 | if (rdev->flags & RADEON_IS_AGP) |
| 577 | rdev->need_dma32 = true; |
| 578 | if (rdev->flags & RADEON_IS_PCI) |
| 579 | rdev->need_dma32 = true; |
| 580 | |
| 581 | dma_bits = rdev->need_dma32 ? 32 : 40; |
| 582 | r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits)); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 583 | if (r) { |
| 584 | printk(KERN_WARNING "radeon: No suitable DMA available.\n"); |
| 585 | } |
| 586 | |
| 587 | /* Registers mapping */ |
| 588 | /* TODO: block userspace mapping of io register */ |
| 589 | rdev->rmmio_base = drm_get_resource_start(rdev->ddev, 2); |
| 590 | rdev->rmmio_size = drm_get_resource_len(rdev->ddev, 2); |
| 591 | rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size); |
| 592 | if (rdev->rmmio == NULL) { |
| 593 | return -ENOMEM; |
| 594 | } |
| 595 | DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base); |
| 596 | DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size); |
| 597 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 598 | /* if we have > 1 VGA cards, then disable the radeon VGA resources */ |
Dave Airlie | 93239ea | 2009-10-28 11:09:58 +1000 | [diff] [blame] | 599 | /* this will fail for cards that aren't VGA class devices, just |
| 600 | * ignore it */ |
| 601 | vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 602 | vga_switcheroo_register_client(rdev->pdev, |
| 603 | radeon_switcheroo_set_state, |
| 604 | radeon_switcheroo_can_switch); |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 605 | |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 606 | r = radeon_init(rdev); |
Jerome Glisse | b574f25 | 2009-10-06 19:04:29 +0200 | [diff] [blame] | 607 | if (r) |
Jerome Glisse | 3ce0a23 | 2009-09-08 10:10:24 +1000 | [diff] [blame] | 608 | return r; |
Michel Dänzer | b1e3a6d | 2009-06-23 16:12:54 +0200 | [diff] [blame] | 609 | |
Jerome Glisse | b574f25 | 2009-10-06 19:04:29 +0200 | [diff] [blame] | 610 | if (rdev->flags & RADEON_IS_AGP && !rdev->accel_working) { |
| 611 | /* Acceleration not working on AGP card try again |
| 612 | * with fallback to PCI or PCIE GART |
| 613 | */ |
Jerome Glisse | 1a029b7 | 2009-10-06 19:04:30 +0200 | [diff] [blame] | 614 | radeon_gpu_reset(rdev); |
Jerome Glisse | b574f25 | 2009-10-06 19:04:29 +0200 | [diff] [blame] | 615 | radeon_fini(rdev); |
| 616 | radeon_agp_disable(rdev); |
| 617 | r = radeon_init(rdev); |
Jerome Glisse | 4aac047 | 2009-09-14 18:29:49 +0200 | [diff] [blame] | 618 | if (r) |
| 619 | return r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 620 | } |
Michel Dänzer | ecc0b32 | 2009-07-21 11:23:57 +0200 | [diff] [blame] | 621 | if (radeon_testing) { |
| 622 | radeon_test_moves(rdev); |
| 623 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 624 | if (radeon_benchmarking) { |
| 625 | radeon_benchmark(rdev); |
| 626 | } |
Jerome Glisse | 6cf8a3f5 | 2009-09-10 21:46:48 +0200 | [diff] [blame] | 627 | return 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | void radeon_device_fini(struct radeon_device *rdev) |
| 631 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 632 | DRM_INFO("radeon: finishing device.\n"); |
| 633 | rdev->shutdown = true; |
Jerome Glisse | 62a8ea3 | 2009-10-01 18:02:11 +0200 | [diff] [blame] | 634 | radeon_fini(rdev); |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 635 | destroy_workqueue(rdev->wq); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 636 | vga_switcheroo_unregister_client(rdev->pdev); |
Dave Airlie | c1176d6 | 2009-10-08 14:03:05 +1000 | [diff] [blame] | 637 | vga_client_register(rdev->pdev, NULL, NULL, NULL); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 638 | iounmap(rdev->rmmio); |
| 639 | rdev->rmmio = NULL; |
| 640 | } |
| 641 | |
| 642 | |
| 643 | /* |
| 644 | * Suspend & resume. |
| 645 | */ |
| 646 | int radeon_suspend_kms(struct drm_device *dev, pm_message_t state) |
| 647 | { |
Darren Jenkins | 875c186 | 2009-12-30 12:18:30 +1100 | [diff] [blame] | 648 | struct radeon_device *rdev; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 649 | struct drm_crtc *crtc; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 650 | int r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 651 | |
Darren Jenkins | 875c186 | 2009-12-30 12:18:30 +1100 | [diff] [blame] | 652 | if (dev == NULL || dev->dev_private == NULL) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 653 | return -ENODEV; |
| 654 | } |
| 655 | if (state.event == PM_EVENT_PRETHAW) { |
| 656 | return 0; |
| 657 | } |
Darren Jenkins | 875c186 | 2009-12-30 12:18:30 +1100 | [diff] [blame] | 658 | rdev = dev->dev_private; |
| 659 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 660 | if (rdev->powered_down) |
| 661 | return 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 662 | /* unpin the front buffers */ |
| 663 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 664 | struct radeon_framebuffer *rfb = to_radeon_framebuffer(crtc->fb); |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 665 | struct radeon_bo *robj; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 666 | |
| 667 | if (rfb == NULL || rfb->obj == NULL) { |
| 668 | continue; |
| 669 | } |
| 670 | robj = rfb->obj->driver_private; |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 671 | if (robj != rdev->fbdev_rbo) { |
| 672 | r = radeon_bo_reserve(robj, false); |
| 673 | if (unlikely(r == 0)) { |
| 674 | radeon_bo_unpin(robj); |
| 675 | radeon_bo_unreserve(robj); |
| 676 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | /* evict vram memory */ |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 680 | radeon_bo_evict_vram(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 681 | /* wait for gpu to finish processing current batch */ |
| 682 | radeon_fence_wait_last(rdev); |
| 683 | |
Yang Zhao | f657c2a | 2009-09-15 12:21:01 +1000 | [diff] [blame] | 684 | radeon_save_bios_scratch_regs(rdev); |
| 685 | |
Jerome Glisse | 62a8ea3 | 2009-10-01 18:02:11 +0200 | [diff] [blame] | 686 | radeon_suspend(rdev); |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 687 | radeon_hpd_fini(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 688 | /* evict remaining vram memory */ |
Jerome Glisse | 4c78867 | 2009-11-20 14:29:23 +0100 | [diff] [blame] | 689 | radeon_bo_evict_vram(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 690 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 691 | pci_save_state(dev->pdev); |
| 692 | if (state.event == PM_EVENT_SUSPEND) { |
| 693 | /* Shut down the device */ |
| 694 | pci_disable_device(dev->pdev); |
| 695 | pci_set_power_state(dev->pdev, PCI_D3hot); |
| 696 | } |
| 697 | acquire_console_sem(); |
| 698 | fb_set_suspend(rdev->fbdev_info, 1); |
| 699 | release_console_sem(); |
| 700 | return 0; |
| 701 | } |
| 702 | |
| 703 | int radeon_resume_kms(struct drm_device *dev) |
| 704 | { |
| 705 | struct radeon_device *rdev = dev->dev_private; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 706 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 707 | if (rdev->powered_down) |
| 708 | return 0; |
| 709 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 710 | acquire_console_sem(); |
| 711 | pci_set_power_state(dev->pdev, PCI_D0); |
| 712 | pci_restore_state(dev->pdev); |
| 713 | if (pci_enable_device(dev->pdev)) { |
| 714 | release_console_sem(); |
| 715 | return -1; |
| 716 | } |
| 717 | pci_set_master(dev->pdev); |
Dave Airlie | 0ebf171 | 2009-11-05 15:39:10 +1000 | [diff] [blame] | 718 | /* resume AGP if in use */ |
| 719 | radeon_agp_resume(rdev); |
Jerome Glisse | 62a8ea3 | 2009-10-01 18:02:11 +0200 | [diff] [blame] | 720 | radeon_resume(rdev); |
Yang Zhao | f657c2a | 2009-09-15 12:21:01 +1000 | [diff] [blame] | 721 | radeon_restore_bios_scratch_regs(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 722 | fb_set_suspend(rdev->fbdev_info, 0); |
| 723 | release_console_sem(); |
| 724 | |
Alex Deucher | d4877cf | 2009-12-04 16:56:37 -0500 | [diff] [blame] | 725 | /* reset hpd state */ |
| 726 | radeon_hpd_init(rdev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 727 | /* blat the mode back in */ |
| 728 | drm_helper_resume_force_mode(dev); |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | |
| 733 | /* |
| 734 | * Debugfs |
| 735 | */ |
| 736 | struct radeon_debugfs { |
| 737 | struct drm_info_list *files; |
| 738 | unsigned num_files; |
| 739 | }; |
| 740 | static struct radeon_debugfs _radeon_debugfs[RADEON_DEBUGFS_MAX_NUM_FILES]; |
| 741 | static unsigned _radeon_debugfs_count = 0; |
| 742 | |
| 743 | int radeon_debugfs_add_files(struct radeon_device *rdev, |
| 744 | struct drm_info_list *files, |
| 745 | unsigned nfiles) |
| 746 | { |
| 747 | unsigned i; |
| 748 | |
| 749 | for (i = 0; i < _radeon_debugfs_count; i++) { |
| 750 | if (_radeon_debugfs[i].files == files) { |
| 751 | /* Already registered */ |
| 752 | return 0; |
| 753 | } |
| 754 | } |
| 755 | if ((_radeon_debugfs_count + nfiles) > RADEON_DEBUGFS_MAX_NUM_FILES) { |
| 756 | DRM_ERROR("Reached maximum number of debugfs files.\n"); |
| 757 | DRM_ERROR("Report so we increase RADEON_DEBUGFS_MAX_NUM_FILES.\n"); |
| 758 | return -EINVAL; |
| 759 | } |
| 760 | _radeon_debugfs[_radeon_debugfs_count].files = files; |
| 761 | _radeon_debugfs[_radeon_debugfs_count].num_files = nfiles; |
| 762 | _radeon_debugfs_count++; |
| 763 | #if defined(CONFIG_DEBUG_FS) |
| 764 | drm_debugfs_create_files(files, nfiles, |
| 765 | rdev->ddev->control->debugfs_root, |
| 766 | rdev->ddev->control); |
| 767 | drm_debugfs_create_files(files, nfiles, |
| 768 | rdev->ddev->primary->debugfs_root, |
| 769 | rdev->ddev->primary); |
| 770 | #endif |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | #if defined(CONFIG_DEBUG_FS) |
| 775 | int radeon_debugfs_init(struct drm_minor *minor) |
| 776 | { |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | void radeon_debugfs_cleanup(struct drm_minor *minor) |
| 781 | { |
| 782 | unsigned i; |
| 783 | |
| 784 | for (i = 0; i < _radeon_debugfs_count; i++) { |
| 785 | drm_debugfs_remove_files(_radeon_debugfs[i].files, |
| 786 | _radeon_debugfs[i].num_files, minor); |
| 787 | } |
| 788 | } |
| 789 | #endif |