Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [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 | */ |
Chunming Zhou | 0875dc9 | 2016-06-12 15:41:58 +0800 | [diff] [blame] | 28 | #include <linux/kthread.h> |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 29 | #include <linux/console.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/debugfs.h> |
| 32 | #include <drm/drmP.h> |
| 33 | #include <drm/drm_crtc_helper.h> |
| 34 | #include <drm/amdgpu_drm.h> |
| 35 | #include <linux/vgaarb.h> |
| 36 | #include <linux/vga_switcheroo.h> |
| 37 | #include <linux/efi.h> |
| 38 | #include "amdgpu.h" |
Tom St Denis | f4b373f | 2016-05-31 08:02:27 -0400 | [diff] [blame] | 39 | #include "amdgpu_trace.h" |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 40 | #include "amdgpu_i2c.h" |
| 41 | #include "atom.h" |
| 42 | #include "amdgpu_atombios.h" |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 43 | #include "amd_pcie.h" |
Ken Wang | 33f3480 | 2016-01-21 17:29:41 +0800 | [diff] [blame] | 44 | #ifdef CONFIG_DRM_AMDGPU_SI |
| 45 | #include "si.h" |
| 46 | #endif |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 47 | #ifdef CONFIG_DRM_AMDGPU_CIK |
| 48 | #include "cik.h" |
| 49 | #endif |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 50 | #include "vi.h" |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 51 | #include "bif/bif_4_1_d.h" |
Emily Deng | 9accf2f | 2016-08-10 16:01:25 +0800 | [diff] [blame] | 52 | #include <linux/pci.h> |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 53 | #include <linux/firmware.h> |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 54 | |
| 55 | static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev); |
| 56 | static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev); |
| 57 | |
| 58 | static const char *amdgpu_asic_name[] = { |
Ken Wang | da69c161 | 2016-01-21 19:08:55 +0800 | [diff] [blame] | 59 | "TAHITI", |
| 60 | "PITCAIRN", |
| 61 | "VERDE", |
| 62 | "OLAND", |
| 63 | "HAINAN", |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 64 | "BONAIRE", |
| 65 | "KAVERI", |
| 66 | "KABINI", |
| 67 | "HAWAII", |
| 68 | "MULLINS", |
| 69 | "TOPAZ", |
| 70 | "TONGA", |
David Zhang | 48299f9 | 2015-07-08 01:05:16 +0800 | [diff] [blame] | 71 | "FIJI", |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 72 | "CARRIZO", |
Samuel Li | 139f491 | 2015-10-08 14:50:27 -0400 | [diff] [blame] | 73 | "STONEY", |
Flora Cui | 2cc0c0b | 2016-03-14 18:33:29 -0400 | [diff] [blame] | 74 | "POLARIS10", |
| 75 | "POLARIS11", |
Junwei Zhang | c4642a4 | 2016-12-14 15:32:28 -0500 | [diff] [blame] | 76 | "POLARIS12", |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 77 | "LAST", |
| 78 | }; |
| 79 | |
| 80 | bool amdgpu_device_is_px(struct drm_device *dev) |
| 81 | { |
| 82 | struct amdgpu_device *adev = dev->dev_private; |
| 83 | |
Jammy Zhou | 2f7d10b | 2015-07-22 11:29:01 +0800 | [diff] [blame] | 84 | if (adev->flags & AMD_IS_PX) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 85 | return true; |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * MMIO register access helper functions. |
| 91 | */ |
| 92 | uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg, |
| 93 | bool always_indirect) |
| 94 | { |
Tom St Denis | f4b373f | 2016-05-31 08:02:27 -0400 | [diff] [blame] | 95 | uint32_t ret; |
| 96 | |
Xiangliang Yu | bc992ba | 2017-01-12 14:29:34 +0800 | [diff] [blame] | 97 | if (amdgpu_sriov_runtime(adev)) { |
| 98 | BUG_ON(in_interrupt()); |
| 99 | return amdgpu_virt_kiq_rreg(adev, reg); |
| 100 | } |
| 101 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 102 | if ((reg * 4) < adev->rmmio_size && !always_indirect) |
Tom St Denis | f4b373f | 2016-05-31 08:02:27 -0400 | [diff] [blame] | 103 | ret = readl(((void __iomem *)adev->rmmio) + (reg * 4)); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 104 | else { |
| 105 | unsigned long flags; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 106 | |
| 107 | spin_lock_irqsave(&adev->mmio_idx_lock, flags); |
| 108 | writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4)); |
| 109 | ret = readl(((void __iomem *)adev->rmmio) + (mmMM_DATA * 4)); |
| 110 | spin_unlock_irqrestore(&adev->mmio_idx_lock, flags); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 111 | } |
Tom St Denis | f4b373f | 2016-05-31 08:02:27 -0400 | [diff] [blame] | 112 | trace_amdgpu_mm_rreg(adev->pdev->device, reg, ret); |
| 113 | return ret; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v, |
| 117 | bool always_indirect) |
| 118 | { |
Tom St Denis | f4b373f | 2016-05-31 08:02:27 -0400 | [diff] [blame] | 119 | trace_amdgpu_mm_wreg(adev->pdev->device, reg, v); |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 120 | |
Xiangliang Yu | bc992ba | 2017-01-12 14:29:34 +0800 | [diff] [blame] | 121 | if (amdgpu_sriov_runtime(adev)) { |
| 122 | BUG_ON(in_interrupt()); |
| 123 | return amdgpu_virt_kiq_wreg(adev, reg, v); |
| 124 | } |
| 125 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 126 | if ((reg * 4) < adev->rmmio_size && !always_indirect) |
| 127 | writel(v, ((void __iomem *)adev->rmmio) + (reg * 4)); |
| 128 | else { |
| 129 | unsigned long flags; |
| 130 | |
| 131 | spin_lock_irqsave(&adev->mmio_idx_lock, flags); |
| 132 | writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4)); |
| 133 | writel(v, ((void __iomem *)adev->rmmio) + (mmMM_DATA * 4)); |
| 134 | spin_unlock_irqrestore(&adev->mmio_idx_lock, flags); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg) |
| 139 | { |
| 140 | if ((reg * 4) < adev->rio_mem_size) |
| 141 | return ioread32(adev->rio_mem + (reg * 4)); |
| 142 | else { |
| 143 | iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4)); |
| 144 | return ioread32(adev->rio_mem + (mmMM_DATA * 4)); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 149 | { |
| 150 | |
| 151 | if ((reg * 4) < adev->rio_mem_size) |
| 152 | iowrite32(v, adev->rio_mem + (reg * 4)); |
| 153 | else { |
| 154 | iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4)); |
| 155 | iowrite32(v, adev->rio_mem + (mmMM_DATA * 4)); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * amdgpu_mm_rdoorbell - read a doorbell dword |
| 161 | * |
| 162 | * @adev: amdgpu_device pointer |
| 163 | * @index: doorbell index |
| 164 | * |
| 165 | * Returns the value in the doorbell aperture at the |
| 166 | * requested doorbell index (CIK). |
| 167 | */ |
| 168 | u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index) |
| 169 | { |
| 170 | if (index < adev->doorbell.num_doorbells) { |
| 171 | return readl(adev->doorbell.ptr + index); |
| 172 | } else { |
| 173 | DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index); |
| 174 | return 0; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * amdgpu_mm_wdoorbell - write a doorbell dword |
| 180 | * |
| 181 | * @adev: amdgpu_device pointer |
| 182 | * @index: doorbell index |
| 183 | * @v: value to write |
| 184 | * |
| 185 | * Writes @v to the doorbell aperture at the |
| 186 | * requested doorbell index (CIK). |
| 187 | */ |
| 188 | void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v) |
| 189 | { |
| 190 | if (index < adev->doorbell.num_doorbells) { |
| 191 | writel(v, adev->doorbell.ptr + index); |
| 192 | } else { |
| 193 | DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * amdgpu_invalid_rreg - dummy reg read function |
| 199 | * |
| 200 | * @adev: amdgpu device pointer |
| 201 | * @reg: offset of register |
| 202 | * |
| 203 | * Dummy register read function. Used for register blocks |
| 204 | * that certain asics don't have (all asics). |
| 205 | * Returns the value in the register. |
| 206 | */ |
| 207 | static uint32_t amdgpu_invalid_rreg(struct amdgpu_device *adev, uint32_t reg) |
| 208 | { |
| 209 | DRM_ERROR("Invalid callback to read register 0x%04X\n", reg); |
| 210 | BUG(); |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * amdgpu_invalid_wreg - dummy reg write function |
| 216 | * |
| 217 | * @adev: amdgpu device pointer |
| 218 | * @reg: offset of register |
| 219 | * @v: value to write to the register |
| 220 | * |
| 221 | * Dummy register read function. Used for register blocks |
| 222 | * that certain asics don't have (all asics). |
| 223 | */ |
| 224 | static void amdgpu_invalid_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) |
| 225 | { |
| 226 | DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n", |
| 227 | reg, v); |
| 228 | BUG(); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * amdgpu_block_invalid_rreg - dummy reg read function |
| 233 | * |
| 234 | * @adev: amdgpu device pointer |
| 235 | * @block: offset of instance |
| 236 | * @reg: offset of register |
| 237 | * |
| 238 | * Dummy register read function. Used for register blocks |
| 239 | * that certain asics don't have (all asics). |
| 240 | * Returns the value in the register. |
| 241 | */ |
| 242 | static uint32_t amdgpu_block_invalid_rreg(struct amdgpu_device *adev, |
| 243 | uint32_t block, uint32_t reg) |
| 244 | { |
| 245 | DRM_ERROR("Invalid callback to read register 0x%04X in block 0x%04X\n", |
| 246 | reg, block); |
| 247 | BUG(); |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * amdgpu_block_invalid_wreg - dummy reg write function |
| 253 | * |
| 254 | * @adev: amdgpu device pointer |
| 255 | * @block: offset of instance |
| 256 | * @reg: offset of register |
| 257 | * @v: value to write to the register |
| 258 | * |
| 259 | * Dummy register read function. Used for register blocks |
| 260 | * that certain asics don't have (all asics). |
| 261 | */ |
| 262 | static void amdgpu_block_invalid_wreg(struct amdgpu_device *adev, |
| 263 | uint32_t block, |
| 264 | uint32_t reg, uint32_t v) |
| 265 | { |
| 266 | DRM_ERROR("Invalid block callback to write register 0x%04X in block 0x%04X with 0x%08X\n", |
| 267 | reg, block, v); |
| 268 | BUG(); |
| 269 | } |
| 270 | |
| 271 | static int amdgpu_vram_scratch_init(struct amdgpu_device *adev) |
| 272 | { |
| 273 | int r; |
| 274 | |
| 275 | if (adev->vram_scratch.robj == NULL) { |
| 276 | r = amdgpu_bo_create(adev, AMDGPU_GPU_PAGE_SIZE, |
Alex Deucher | 857d913 | 2015-08-27 00:14:16 -0400 | [diff] [blame] | 277 | PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_VRAM, |
Christian König | 03f48dd | 2016-08-15 17:00:22 +0200 | [diff] [blame] | 278 | AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED | |
| 279 | AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, |
Christian König | 72d7668 | 2015-09-03 17:34:59 +0200 | [diff] [blame] | 280 | NULL, NULL, &adev->vram_scratch.robj); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 281 | if (r) { |
| 282 | return r; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | r = amdgpu_bo_reserve(adev->vram_scratch.robj, false); |
| 287 | if (unlikely(r != 0)) |
| 288 | return r; |
| 289 | r = amdgpu_bo_pin(adev->vram_scratch.robj, |
| 290 | AMDGPU_GEM_DOMAIN_VRAM, &adev->vram_scratch.gpu_addr); |
| 291 | if (r) { |
| 292 | amdgpu_bo_unreserve(adev->vram_scratch.robj); |
| 293 | return r; |
| 294 | } |
| 295 | r = amdgpu_bo_kmap(adev->vram_scratch.robj, |
| 296 | (void **)&adev->vram_scratch.ptr); |
| 297 | if (r) |
| 298 | amdgpu_bo_unpin(adev->vram_scratch.robj); |
| 299 | amdgpu_bo_unreserve(adev->vram_scratch.robj); |
| 300 | |
| 301 | return r; |
| 302 | } |
| 303 | |
| 304 | static void amdgpu_vram_scratch_fini(struct amdgpu_device *adev) |
| 305 | { |
| 306 | int r; |
| 307 | |
| 308 | if (adev->vram_scratch.robj == NULL) { |
| 309 | return; |
| 310 | } |
| 311 | r = amdgpu_bo_reserve(adev->vram_scratch.robj, false); |
| 312 | if (likely(r == 0)) { |
| 313 | amdgpu_bo_kunmap(adev->vram_scratch.robj); |
| 314 | amdgpu_bo_unpin(adev->vram_scratch.robj); |
| 315 | amdgpu_bo_unreserve(adev->vram_scratch.robj); |
| 316 | } |
| 317 | amdgpu_bo_unref(&adev->vram_scratch.robj); |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * amdgpu_program_register_sequence - program an array of registers. |
| 322 | * |
| 323 | * @adev: amdgpu_device pointer |
| 324 | * @registers: pointer to the register array |
| 325 | * @array_size: size of the register array |
| 326 | * |
| 327 | * Programs an array or registers with and and or masks. |
| 328 | * This is a helper for setting golden registers. |
| 329 | */ |
| 330 | void amdgpu_program_register_sequence(struct amdgpu_device *adev, |
| 331 | const u32 *registers, |
| 332 | const u32 array_size) |
| 333 | { |
| 334 | u32 tmp, reg, and_mask, or_mask; |
| 335 | int i; |
| 336 | |
| 337 | if (array_size % 3) |
| 338 | return; |
| 339 | |
| 340 | for (i = 0; i < array_size; i +=3) { |
| 341 | reg = registers[i + 0]; |
| 342 | and_mask = registers[i + 1]; |
| 343 | or_mask = registers[i + 2]; |
| 344 | |
| 345 | if (and_mask == 0xffffffff) { |
| 346 | tmp = or_mask; |
| 347 | } else { |
| 348 | tmp = RREG32(reg); |
| 349 | tmp &= ~and_mask; |
| 350 | tmp |= or_mask; |
| 351 | } |
| 352 | WREG32(reg, tmp); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | void amdgpu_pci_config_reset(struct amdgpu_device *adev) |
| 357 | { |
| 358 | pci_write_config_dword(adev->pdev, 0x7c, AMDGPU_ASIC_RESET_DATA); |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * GPU doorbell aperture helpers function. |
| 363 | */ |
| 364 | /** |
| 365 | * amdgpu_doorbell_init - Init doorbell driver information. |
| 366 | * |
| 367 | * @adev: amdgpu_device pointer |
| 368 | * |
| 369 | * Init doorbell driver information (CIK) |
| 370 | * Returns 0 on success, error on failure. |
| 371 | */ |
| 372 | static int amdgpu_doorbell_init(struct amdgpu_device *adev) |
| 373 | { |
| 374 | /* doorbell bar mapping */ |
| 375 | adev->doorbell.base = pci_resource_start(adev->pdev, 2); |
| 376 | adev->doorbell.size = pci_resource_len(adev->pdev, 2); |
| 377 | |
Christian König | edf600d | 2016-05-03 15:54:54 +0200 | [diff] [blame] | 378 | adev->doorbell.num_doorbells = min_t(u32, adev->doorbell.size / sizeof(u32), |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 379 | AMDGPU_DOORBELL_MAX_ASSIGNMENT+1); |
| 380 | if (adev->doorbell.num_doorbells == 0) |
| 381 | return -EINVAL; |
| 382 | |
| 383 | adev->doorbell.ptr = ioremap(adev->doorbell.base, adev->doorbell.num_doorbells * sizeof(u32)); |
| 384 | if (adev->doorbell.ptr == NULL) { |
| 385 | return -ENOMEM; |
| 386 | } |
| 387 | DRM_INFO("doorbell mmio base: 0x%08X\n", (uint32_t)adev->doorbell.base); |
| 388 | DRM_INFO("doorbell mmio size: %u\n", (unsigned)adev->doorbell.size); |
| 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * amdgpu_doorbell_fini - Tear down doorbell driver information. |
| 395 | * |
| 396 | * @adev: amdgpu_device pointer |
| 397 | * |
| 398 | * Tear down doorbell driver information (CIK) |
| 399 | */ |
| 400 | static void amdgpu_doorbell_fini(struct amdgpu_device *adev) |
| 401 | { |
| 402 | iounmap(adev->doorbell.ptr); |
| 403 | adev->doorbell.ptr = NULL; |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * amdgpu_doorbell_get_kfd_info - Report doorbell configuration required to |
| 408 | * setup amdkfd |
| 409 | * |
| 410 | * @adev: amdgpu_device pointer |
| 411 | * @aperture_base: output returning doorbell aperture base physical address |
| 412 | * @aperture_size: output returning doorbell aperture size in bytes |
| 413 | * @start_offset: output returning # of doorbell bytes reserved for amdgpu. |
| 414 | * |
| 415 | * amdgpu and amdkfd share the doorbell aperture. amdgpu sets it up, |
| 416 | * takes doorbells required for its own rings and reports the setup to amdkfd. |
| 417 | * amdgpu reserved doorbells are at the start of the doorbell aperture. |
| 418 | */ |
| 419 | void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev, |
| 420 | phys_addr_t *aperture_base, |
| 421 | size_t *aperture_size, |
| 422 | size_t *start_offset) |
| 423 | { |
| 424 | /* |
| 425 | * The first num_doorbells are used by amdgpu. |
| 426 | * amdkfd takes whatever's left in the aperture. |
| 427 | */ |
| 428 | if (adev->doorbell.size > adev->doorbell.num_doorbells * sizeof(u32)) { |
| 429 | *aperture_base = adev->doorbell.base; |
| 430 | *aperture_size = adev->doorbell.size; |
| 431 | *start_offset = adev->doorbell.num_doorbells * sizeof(u32); |
| 432 | } else { |
| 433 | *aperture_base = 0; |
| 434 | *aperture_size = 0; |
| 435 | *start_offset = 0; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * amdgpu_wb_*() |
| 441 | * Writeback is the the method by which the the GPU updates special pages |
| 442 | * in memory with the status of certain GPU events (fences, ring pointers, |
| 443 | * etc.). |
| 444 | */ |
| 445 | |
| 446 | /** |
| 447 | * amdgpu_wb_fini - Disable Writeback and free memory |
| 448 | * |
| 449 | * @adev: amdgpu_device pointer |
| 450 | * |
| 451 | * Disables Writeback and frees the Writeback memory (all asics). |
| 452 | * Used at driver shutdown. |
| 453 | */ |
| 454 | static void amdgpu_wb_fini(struct amdgpu_device *adev) |
| 455 | { |
| 456 | if (adev->wb.wb_obj) { |
Alex Deucher | a76ed48 | 2016-10-21 15:30:36 -0400 | [diff] [blame] | 457 | amdgpu_bo_free_kernel(&adev->wb.wb_obj, |
| 458 | &adev->wb.gpu_addr, |
| 459 | (void **)&adev->wb.wb); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 460 | adev->wb.wb_obj = NULL; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * amdgpu_wb_init- Init Writeback driver info and allocate memory |
| 466 | * |
| 467 | * @adev: amdgpu_device pointer |
| 468 | * |
| 469 | * Disables Writeback and frees the Writeback memory (all asics). |
| 470 | * Used at driver startup. |
| 471 | * Returns 0 on success or an -error on failure. |
| 472 | */ |
| 473 | static int amdgpu_wb_init(struct amdgpu_device *adev) |
| 474 | { |
| 475 | int r; |
| 476 | |
| 477 | if (adev->wb.wb_obj == NULL) { |
Huang Rui | 60a970a6 | 2017-03-15 10:13:32 +0800 | [diff] [blame] | 478 | r = amdgpu_bo_create_kernel(adev, AMDGPU_MAX_WB * sizeof(uint32_t), |
Alex Deucher | a76ed48 | 2016-10-21 15:30:36 -0400 | [diff] [blame] | 479 | PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT, |
| 480 | &adev->wb.wb_obj, &adev->wb.gpu_addr, |
| 481 | (void **)&adev->wb.wb); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 482 | if (r) { |
| 483 | dev_warn(adev->dev, "(%d) create WB bo failed\n", r); |
| 484 | return r; |
| 485 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 486 | |
| 487 | adev->wb.num_wb = AMDGPU_MAX_WB; |
| 488 | memset(&adev->wb.used, 0, sizeof(adev->wb.used)); |
| 489 | |
| 490 | /* clear wb memory */ |
Huang Rui | 60a970a6 | 2017-03-15 10:13:32 +0800 | [diff] [blame] | 491 | memset((char *)adev->wb.wb, 0, AMDGPU_MAX_WB * sizeof(uint32_t)); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * amdgpu_wb_get - Allocate a wb entry |
| 499 | * |
| 500 | * @adev: amdgpu_device pointer |
| 501 | * @wb: wb index |
| 502 | * |
| 503 | * Allocate a wb slot for use by the driver (all asics). |
| 504 | * Returns 0 on success or -EINVAL on failure. |
| 505 | */ |
| 506 | int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb) |
| 507 | { |
| 508 | unsigned long offset = find_first_zero_bit(adev->wb.used, adev->wb.num_wb); |
| 509 | if (offset < adev->wb.num_wb) { |
| 510 | __set_bit(offset, adev->wb.used); |
| 511 | *wb = offset; |
| 512 | return 0; |
| 513 | } else { |
| 514 | return -EINVAL; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * amdgpu_wb_free - Free a wb entry |
| 520 | * |
| 521 | * @adev: amdgpu_device pointer |
| 522 | * @wb: wb index |
| 523 | * |
| 524 | * Free a wb slot allocated for use by the driver (all asics) |
| 525 | */ |
| 526 | void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb) |
| 527 | { |
| 528 | if (wb < adev->wb.num_wb) |
| 529 | __clear_bit(wb, adev->wb.used); |
| 530 | } |
| 531 | |
| 532 | /** |
| 533 | * amdgpu_vram_location - try to find VRAM location |
| 534 | * @adev: amdgpu device structure holding all necessary informations |
| 535 | * @mc: memory controller structure holding memory informations |
| 536 | * @base: base address at which to put VRAM |
| 537 | * |
| 538 | * Function will place try to place VRAM at base address provided |
| 539 | * as parameter (which is so far either PCI aperture address or |
| 540 | * for IGP TOM base address). |
| 541 | * |
| 542 | * If there is not enough space to fit the unvisible VRAM in the 32bits |
| 543 | * address space then we limit the VRAM size to the aperture. |
| 544 | * |
| 545 | * Note: We don't explicitly enforce VRAM start to be aligned on VRAM size, |
| 546 | * this shouldn't be a problem as we are using the PCI aperture as a reference. |
| 547 | * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but |
| 548 | * not IGP. |
| 549 | * |
| 550 | * Note: we use mc_vram_size as on some board we need to program the mc to |
| 551 | * cover the whole aperture even if VRAM size is inferior to aperture size |
| 552 | * Novell bug 204882 + along with lots of ubuntu ones |
| 553 | * |
| 554 | * Note: when limiting vram it's safe to overwritte real_vram_size because |
| 555 | * we are not in case where real_vram_size is inferior to mc_vram_size (ie |
| 556 | * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu |
| 557 | * ones) |
| 558 | * |
| 559 | * Note: IGP TOM addr should be the same as the aperture addr, we don't |
| 560 | * explicitly check for that thought. |
| 561 | * |
| 562 | * FIXME: when reducing VRAM size align new size on power of 2. |
| 563 | */ |
| 564 | void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base) |
| 565 | { |
| 566 | uint64_t limit = (uint64_t)amdgpu_vram_limit << 20; |
| 567 | |
| 568 | mc->vram_start = base; |
| 569 | if (mc->mc_vram_size > (adev->mc.mc_mask - base + 1)) { |
| 570 | dev_warn(adev->dev, "limiting VRAM to PCI aperture size\n"); |
| 571 | mc->real_vram_size = mc->aper_size; |
| 572 | mc->mc_vram_size = mc->aper_size; |
| 573 | } |
| 574 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
| 575 | if (limit && limit < mc->real_vram_size) |
| 576 | mc->real_vram_size = limit; |
| 577 | dev_info(adev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n", |
| 578 | mc->mc_vram_size >> 20, mc->vram_start, |
| 579 | mc->vram_end, mc->real_vram_size >> 20); |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * amdgpu_gtt_location - try to find GTT location |
| 584 | * @adev: amdgpu device structure holding all necessary informations |
| 585 | * @mc: memory controller structure holding memory informations |
| 586 | * |
| 587 | * Function will place try to place GTT before or after VRAM. |
| 588 | * |
| 589 | * If GTT size is bigger than space left then we ajust GTT size. |
| 590 | * Thus function will never fails. |
| 591 | * |
| 592 | * FIXME: when reducing GTT size align new size on power of 2. |
| 593 | */ |
| 594 | void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc) |
| 595 | { |
| 596 | u64 size_af, size_bf; |
| 597 | |
| 598 | size_af = ((adev->mc.mc_mask - mc->vram_end) + mc->gtt_base_align) & ~mc->gtt_base_align; |
| 599 | size_bf = mc->vram_start & ~mc->gtt_base_align; |
| 600 | if (size_bf > size_af) { |
| 601 | if (mc->gtt_size > size_bf) { |
| 602 | dev_warn(adev->dev, "limiting GTT\n"); |
| 603 | mc->gtt_size = size_bf; |
| 604 | } |
| 605 | mc->gtt_start = (mc->vram_start & ~mc->gtt_base_align) - mc->gtt_size; |
| 606 | } else { |
| 607 | if (mc->gtt_size > size_af) { |
| 608 | dev_warn(adev->dev, "limiting GTT\n"); |
| 609 | mc->gtt_size = size_af; |
| 610 | } |
| 611 | mc->gtt_start = (mc->vram_end + 1 + mc->gtt_base_align) & ~mc->gtt_base_align; |
| 612 | } |
| 613 | mc->gtt_end = mc->gtt_start + mc->gtt_size - 1; |
| 614 | dev_info(adev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n", |
| 615 | mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end); |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | * GPU helpers function. |
| 620 | */ |
| 621 | /** |
Jim Qu | c836fec | 2017-02-10 15:59:59 +0800 | [diff] [blame] | 622 | * amdgpu_need_post - check if the hw need post or not |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 623 | * |
| 624 | * @adev: amdgpu_device pointer |
| 625 | * |
Jim Qu | c836fec | 2017-02-10 15:59:59 +0800 | [diff] [blame] | 626 | * Check if the asic has been initialized (all asics) at driver startup |
| 627 | * or post is needed if hw reset is performed. |
| 628 | * Returns true if need or false if not. |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 629 | */ |
Jim Qu | c836fec | 2017-02-10 15:59:59 +0800 | [diff] [blame] | 630 | bool amdgpu_need_post(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 631 | { |
| 632 | uint32_t reg; |
| 633 | |
Jim Qu | c836fec | 2017-02-10 15:59:59 +0800 | [diff] [blame] | 634 | if (adev->has_hw_reset) { |
| 635 | adev->has_hw_reset = false; |
| 636 | return true; |
| 637 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 638 | /* then check MEM_SIZE, in case the crtcs are off */ |
| 639 | reg = RREG32(mmCONFIG_MEMSIZE); |
| 640 | |
| 641 | if (reg) |
Jim Qu | c836fec | 2017-02-10 15:59:59 +0800 | [diff] [blame] | 642 | return false; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 643 | |
Jim Qu | c836fec | 2017-02-10 15:59:59 +0800 | [diff] [blame] | 644 | return true; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 645 | |
| 646 | } |
| 647 | |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 648 | static bool amdgpu_vpost_needed(struct amdgpu_device *adev) |
| 649 | { |
| 650 | if (amdgpu_sriov_vf(adev)) |
| 651 | return false; |
| 652 | |
| 653 | if (amdgpu_passthrough(adev)) { |
Monk Liu | 1da2c32 | 2016-11-11 11:24:29 +0800 | [diff] [blame] | 654 | /* for FIJI: In whole GPU pass-through virtualization case, after VM reboot |
| 655 | * some old smc fw still need driver do vPost otherwise gpu hang, while |
| 656 | * those smc fw version above 22.15 doesn't have this flaw, so we force |
| 657 | * vpost executed for smc version below 22.15 |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 658 | */ |
| 659 | if (adev->asic_type == CHIP_FIJI) { |
| 660 | int err; |
| 661 | uint32_t fw_ver; |
| 662 | err = request_firmware(&adev->pm.fw, "amdgpu/fiji_smc.bin", adev->dev); |
| 663 | /* force vPost if error occured */ |
| 664 | if (err) |
| 665 | return true; |
| 666 | |
| 667 | fw_ver = *((uint32_t *)adev->pm.fw->data + 69); |
Monk Liu | 1da2c32 | 2016-11-11 11:24:29 +0800 | [diff] [blame] | 668 | if (fw_ver < 0x00160e00) |
| 669 | return true; |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 670 | } |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 671 | } |
Jim Qu | c836fec | 2017-02-10 15:59:59 +0800 | [diff] [blame] | 672 | return amdgpu_need_post(adev); |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 673 | } |
| 674 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 675 | /** |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 676 | * amdgpu_dummy_page_init - init dummy page used by the driver |
| 677 | * |
| 678 | * @adev: amdgpu_device pointer |
| 679 | * |
| 680 | * Allocate the dummy page used by the driver (all asics). |
| 681 | * This dummy page is used by the driver as a filler for gart entries |
| 682 | * when pages are taken out of the GART |
| 683 | * Returns 0 on sucess, -ENOMEM on failure. |
| 684 | */ |
| 685 | int amdgpu_dummy_page_init(struct amdgpu_device *adev) |
| 686 | { |
| 687 | if (adev->dummy_page.page) |
| 688 | return 0; |
| 689 | adev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO); |
| 690 | if (adev->dummy_page.page == NULL) |
| 691 | return -ENOMEM; |
| 692 | adev->dummy_page.addr = pci_map_page(adev->pdev, adev->dummy_page.page, |
| 693 | 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 694 | if (pci_dma_mapping_error(adev->pdev, adev->dummy_page.addr)) { |
| 695 | dev_err(&adev->pdev->dev, "Failed to DMA MAP the dummy page\n"); |
| 696 | __free_page(adev->dummy_page.page); |
| 697 | adev->dummy_page.page = NULL; |
| 698 | return -ENOMEM; |
| 699 | } |
| 700 | return 0; |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * amdgpu_dummy_page_fini - free dummy page used by the driver |
| 705 | * |
| 706 | * @adev: amdgpu_device pointer |
| 707 | * |
| 708 | * Frees the dummy page used by the driver (all asics). |
| 709 | */ |
| 710 | void amdgpu_dummy_page_fini(struct amdgpu_device *adev) |
| 711 | { |
| 712 | if (adev->dummy_page.page == NULL) |
| 713 | return; |
| 714 | pci_unmap_page(adev->pdev, adev->dummy_page.addr, |
| 715 | PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 716 | __free_page(adev->dummy_page.page); |
| 717 | adev->dummy_page.page = NULL; |
| 718 | } |
| 719 | |
| 720 | |
| 721 | /* ATOM accessor methods */ |
| 722 | /* |
| 723 | * ATOM is an interpreted byte code stored in tables in the vbios. The |
| 724 | * driver registers callbacks to access registers and the interpreter |
| 725 | * in the driver parses the tables and executes then to program specific |
| 726 | * actions (set display modes, asic init, etc.). See amdgpu_atombios.c, |
| 727 | * atombios.h, and atom.c |
| 728 | */ |
| 729 | |
| 730 | /** |
| 731 | * cail_pll_read - read PLL register |
| 732 | * |
| 733 | * @info: atom card_info pointer |
| 734 | * @reg: PLL register offset |
| 735 | * |
| 736 | * Provides a PLL register accessor for the atom interpreter (r4xx+). |
| 737 | * Returns the value of the PLL register. |
| 738 | */ |
| 739 | static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) |
| 740 | { |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | /** |
| 745 | * cail_pll_write - write PLL register |
| 746 | * |
| 747 | * @info: atom card_info pointer |
| 748 | * @reg: PLL register offset |
| 749 | * @val: value to write to the pll register |
| 750 | * |
| 751 | * Provides a PLL register accessor for the atom interpreter (r4xx+). |
| 752 | */ |
| 753 | static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) |
| 754 | { |
| 755 | |
| 756 | } |
| 757 | |
| 758 | /** |
| 759 | * cail_mc_read - read MC (Memory Controller) register |
| 760 | * |
| 761 | * @info: atom card_info pointer |
| 762 | * @reg: MC register offset |
| 763 | * |
| 764 | * Provides an MC register accessor for the atom interpreter (r4xx+). |
| 765 | * Returns the value of the MC register. |
| 766 | */ |
| 767 | static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) |
| 768 | { |
| 769 | return 0; |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * cail_mc_write - write MC (Memory Controller) register |
| 774 | * |
| 775 | * @info: atom card_info pointer |
| 776 | * @reg: MC register offset |
| 777 | * @val: value to write to the pll register |
| 778 | * |
| 779 | * Provides a MC register accessor for the atom interpreter (r4xx+). |
| 780 | */ |
| 781 | static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) |
| 782 | { |
| 783 | |
| 784 | } |
| 785 | |
| 786 | /** |
| 787 | * cail_reg_write - write MMIO register |
| 788 | * |
| 789 | * @info: atom card_info pointer |
| 790 | * @reg: MMIO register offset |
| 791 | * @val: value to write to the pll register |
| 792 | * |
| 793 | * Provides a MMIO register accessor for the atom interpreter (r4xx+). |
| 794 | */ |
| 795 | static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) |
| 796 | { |
| 797 | struct amdgpu_device *adev = info->dev->dev_private; |
| 798 | |
| 799 | WREG32(reg, val); |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * cail_reg_read - read MMIO register |
| 804 | * |
| 805 | * @info: atom card_info pointer |
| 806 | * @reg: MMIO register offset |
| 807 | * |
| 808 | * Provides an MMIO register accessor for the atom interpreter (r4xx+). |
| 809 | * Returns the value of the MMIO register. |
| 810 | */ |
| 811 | static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) |
| 812 | { |
| 813 | struct amdgpu_device *adev = info->dev->dev_private; |
| 814 | uint32_t r; |
| 815 | |
| 816 | r = RREG32(reg); |
| 817 | return r; |
| 818 | } |
| 819 | |
| 820 | /** |
| 821 | * cail_ioreg_write - write IO register |
| 822 | * |
| 823 | * @info: atom card_info pointer |
| 824 | * @reg: IO register offset |
| 825 | * @val: value to write to the pll register |
| 826 | * |
| 827 | * Provides a IO register accessor for the atom interpreter (r4xx+). |
| 828 | */ |
| 829 | static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val) |
| 830 | { |
| 831 | struct amdgpu_device *adev = info->dev->dev_private; |
| 832 | |
| 833 | WREG32_IO(reg, val); |
| 834 | } |
| 835 | |
| 836 | /** |
| 837 | * cail_ioreg_read - read IO register |
| 838 | * |
| 839 | * @info: atom card_info pointer |
| 840 | * @reg: IO register offset |
| 841 | * |
| 842 | * Provides an IO register accessor for the atom interpreter (r4xx+). |
| 843 | * Returns the value of the IO register. |
| 844 | */ |
| 845 | static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg) |
| 846 | { |
| 847 | struct amdgpu_device *adev = info->dev->dev_private; |
| 848 | uint32_t r; |
| 849 | |
| 850 | r = RREG32_IO(reg); |
| 851 | return r; |
| 852 | } |
| 853 | |
| 854 | /** |
| 855 | * amdgpu_atombios_fini - free the driver info and callbacks for atombios |
| 856 | * |
| 857 | * @adev: amdgpu_device pointer |
| 858 | * |
| 859 | * Frees the driver info and register access callbacks for the ATOM |
| 860 | * interpreter (r4xx+). |
| 861 | * Called at driver shutdown. |
| 862 | */ |
| 863 | static void amdgpu_atombios_fini(struct amdgpu_device *adev) |
| 864 | { |
Monk Liu | 89e0ec9 | 2016-05-27 19:34:11 +0800 | [diff] [blame] | 865 | if (adev->mode_info.atom_context) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 866 | kfree(adev->mode_info.atom_context->scratch); |
Monk Liu | 89e0ec9 | 2016-05-27 19:34:11 +0800 | [diff] [blame] | 867 | kfree(adev->mode_info.atom_context->iio); |
| 868 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 869 | kfree(adev->mode_info.atom_context); |
| 870 | adev->mode_info.atom_context = NULL; |
| 871 | kfree(adev->mode_info.atom_card_info); |
| 872 | adev->mode_info.atom_card_info = NULL; |
| 873 | } |
| 874 | |
| 875 | /** |
| 876 | * amdgpu_atombios_init - init the driver info and callbacks for atombios |
| 877 | * |
| 878 | * @adev: amdgpu_device pointer |
| 879 | * |
| 880 | * Initializes the driver info and register access callbacks for the |
| 881 | * ATOM interpreter (r4xx+). |
| 882 | * Returns 0 on sucess, -ENOMEM on failure. |
| 883 | * Called at driver startup. |
| 884 | */ |
| 885 | static int amdgpu_atombios_init(struct amdgpu_device *adev) |
| 886 | { |
| 887 | struct card_info *atom_card_info = |
| 888 | kzalloc(sizeof(struct card_info), GFP_KERNEL); |
| 889 | |
| 890 | if (!atom_card_info) |
| 891 | return -ENOMEM; |
| 892 | |
| 893 | adev->mode_info.atom_card_info = atom_card_info; |
| 894 | atom_card_info->dev = adev->ddev; |
| 895 | atom_card_info->reg_read = cail_reg_read; |
| 896 | atom_card_info->reg_write = cail_reg_write; |
| 897 | /* needed for iio ops */ |
| 898 | if (adev->rio_mem) { |
| 899 | atom_card_info->ioreg_read = cail_ioreg_read; |
| 900 | atom_card_info->ioreg_write = cail_ioreg_write; |
| 901 | } else { |
Amber Lin | b64a18c | 2017-01-04 08:06:58 -0500 | [diff] [blame] | 902 | DRM_INFO("PCI I/O BAR is not found. Using MMIO to access ATOM BIOS\n"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 903 | atom_card_info->ioreg_read = cail_reg_read; |
| 904 | atom_card_info->ioreg_write = cail_reg_write; |
| 905 | } |
| 906 | atom_card_info->mc_read = cail_mc_read; |
| 907 | atom_card_info->mc_write = cail_mc_write; |
| 908 | atom_card_info->pll_read = cail_pll_read; |
| 909 | atom_card_info->pll_write = cail_pll_write; |
| 910 | |
| 911 | adev->mode_info.atom_context = amdgpu_atom_parse(atom_card_info, adev->bios); |
| 912 | if (!adev->mode_info.atom_context) { |
| 913 | amdgpu_atombios_fini(adev); |
| 914 | return -ENOMEM; |
| 915 | } |
| 916 | |
| 917 | mutex_init(&adev->mode_info.atom_context->mutex); |
| 918 | amdgpu_atombios_scratch_regs_init(adev); |
| 919 | amdgpu_atom_allocate_fb_scratch(adev->mode_info.atom_context); |
| 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | /* if we get transitioned to only one device, take VGA back */ |
| 924 | /** |
| 925 | * amdgpu_vga_set_decode - enable/disable vga decode |
| 926 | * |
| 927 | * @cookie: amdgpu_device pointer |
| 928 | * @state: enable/disable vga decode |
| 929 | * |
| 930 | * Enable/disable vga decode (all asics). |
| 931 | * Returns VGA resource flags. |
| 932 | */ |
| 933 | static unsigned int amdgpu_vga_set_decode(void *cookie, bool state) |
| 934 | { |
| 935 | struct amdgpu_device *adev = cookie; |
| 936 | amdgpu_asic_set_vga_state(adev, state); |
| 937 | if (state) |
| 938 | return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | |
| 939 | VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 940 | else |
| 941 | return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 942 | } |
| 943 | |
| 944 | /** |
| 945 | * amdgpu_check_pot_argument - check that argument is a power of two |
| 946 | * |
| 947 | * @arg: value to check |
| 948 | * |
| 949 | * Validates that a certain argument is a power of two (all asics). |
| 950 | * Returns true if argument is valid. |
| 951 | */ |
| 952 | static bool amdgpu_check_pot_argument(int arg) |
| 953 | { |
| 954 | return (arg & (arg - 1)) == 0; |
| 955 | } |
| 956 | |
| 957 | /** |
| 958 | * amdgpu_check_arguments - validate module params |
| 959 | * |
| 960 | * @adev: amdgpu_device pointer |
| 961 | * |
| 962 | * Validates certain module parameters and updates |
| 963 | * the associated values used by the driver (all asics). |
| 964 | */ |
| 965 | static void amdgpu_check_arguments(struct amdgpu_device *adev) |
| 966 | { |
Chunming Zhou | 5b01123 | 2015-12-10 17:34:33 +0800 | [diff] [blame] | 967 | if (amdgpu_sched_jobs < 4) { |
| 968 | dev_warn(adev->dev, "sched jobs (%d) must be at least 4\n", |
| 969 | amdgpu_sched_jobs); |
| 970 | amdgpu_sched_jobs = 4; |
| 971 | } else if (!amdgpu_check_pot_argument(amdgpu_sched_jobs)){ |
| 972 | dev_warn(adev->dev, "sched jobs (%d) must be a power of 2\n", |
| 973 | amdgpu_sched_jobs); |
| 974 | amdgpu_sched_jobs = roundup_pow_of_two(amdgpu_sched_jobs); |
| 975 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 976 | |
| 977 | if (amdgpu_gart_size != -1) { |
Christian König | c4e1a13 | 2016-03-17 16:25:15 +0100 | [diff] [blame] | 978 | /* gtt size must be greater or equal to 32M */ |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 979 | if (amdgpu_gart_size < 32) { |
| 980 | dev_warn(adev->dev, "gart size (%d) too small\n", |
| 981 | amdgpu_gart_size); |
| 982 | amdgpu_gart_size = -1; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
| 986 | if (!amdgpu_check_pot_argument(amdgpu_vm_size)) { |
| 987 | dev_warn(adev->dev, "VM size (%d) must be a power of 2\n", |
| 988 | amdgpu_vm_size); |
Alex Deucher | 8dacc12 | 2015-05-11 16:20:58 -0400 | [diff] [blame] | 989 | amdgpu_vm_size = 8; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | if (amdgpu_vm_size < 1) { |
| 993 | dev_warn(adev->dev, "VM size (%d) too small, min is 1GB\n", |
| 994 | amdgpu_vm_size); |
Alex Deucher | 8dacc12 | 2015-05-11 16:20:58 -0400 | [diff] [blame] | 995 | amdgpu_vm_size = 8; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | /* |
| 999 | * Max GPUVM size for Cayman, SI and CI are 40 bits. |
| 1000 | */ |
| 1001 | if (amdgpu_vm_size > 1024) { |
| 1002 | dev_warn(adev->dev, "VM size (%d) too large, max is 1TB\n", |
| 1003 | amdgpu_vm_size); |
Alex Deucher | 8dacc12 | 2015-05-11 16:20:58 -0400 | [diff] [blame] | 1004 | amdgpu_vm_size = 8; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | /* defines number of bits in page table versus page directory, |
| 1008 | * a page is 4KB so we have 12 bits offset, minimum 9 bits in the |
| 1009 | * page table and the remaining bits are in the page directory */ |
| 1010 | if (amdgpu_vm_block_size == -1) { |
| 1011 | |
| 1012 | /* Total bits covered by PD + PTs */ |
| 1013 | unsigned bits = ilog2(amdgpu_vm_size) + 18; |
| 1014 | |
| 1015 | /* Make sure the PD is 4K in size up to 8GB address space. |
| 1016 | Above that split equal between PD and PTs */ |
| 1017 | if (amdgpu_vm_size <= 8) |
| 1018 | amdgpu_vm_block_size = bits - 9; |
| 1019 | else |
| 1020 | amdgpu_vm_block_size = (bits + 3) / 2; |
| 1021 | |
| 1022 | } else if (amdgpu_vm_block_size < 9) { |
| 1023 | dev_warn(adev->dev, "VM page table size (%d) too small\n", |
| 1024 | amdgpu_vm_block_size); |
| 1025 | amdgpu_vm_block_size = 9; |
| 1026 | } |
| 1027 | |
| 1028 | if (amdgpu_vm_block_size > 24 || |
| 1029 | (amdgpu_vm_size * 1024) < (1ull << amdgpu_vm_block_size)) { |
| 1030 | dev_warn(adev->dev, "VM page table size (%d) too large\n", |
| 1031 | amdgpu_vm_block_size); |
| 1032 | amdgpu_vm_block_size = 9; |
| 1033 | } |
Christian König | 6a7f76e | 2016-08-24 15:51:49 +0200 | [diff] [blame] | 1034 | |
jimqu | 526bae3 | 2016-11-07 09:53:10 +0800 | [diff] [blame] | 1035 | if (amdgpu_vram_page_split != -1 && (amdgpu_vram_page_split < 16 || |
| 1036 | !amdgpu_check_pot_argument(amdgpu_vram_page_split))) { |
Christian König | 6a7f76e | 2016-08-24 15:51:49 +0200 | [diff] [blame] | 1037 | dev_warn(adev->dev, "invalid VRAM page split (%d)\n", |
| 1038 | amdgpu_vram_page_split); |
| 1039 | amdgpu_vram_page_split = 1024; |
| 1040 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * amdgpu_switcheroo_set_state - set switcheroo state |
| 1045 | * |
| 1046 | * @pdev: pci dev pointer |
Lukas Wunner | 1694467 | 2015-09-05 11:17:35 +0200 | [diff] [blame] | 1047 | * @state: vga_switcheroo state |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1048 | * |
| 1049 | * Callback for the switcheroo driver. Suspends or resumes the |
| 1050 | * the asics before or after it is powered up using ACPI methods. |
| 1051 | */ |
| 1052 | static void amdgpu_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) |
| 1053 | { |
| 1054 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 1055 | |
| 1056 | if (amdgpu_device_is_px(dev) && state == VGA_SWITCHEROO_OFF) |
| 1057 | return; |
| 1058 | |
| 1059 | if (state == VGA_SWITCHEROO_ON) { |
| 1060 | unsigned d3_delay = dev->pdev->d3_delay; |
| 1061 | |
| 1062 | printk(KERN_INFO "amdgpu: switched on\n"); |
| 1063 | /* don't suspend or resume card normally */ |
| 1064 | dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; |
| 1065 | |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 1066 | amdgpu_device_resume(dev, true, true); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1067 | |
| 1068 | dev->pdev->d3_delay = d3_delay; |
| 1069 | |
| 1070 | dev->switch_power_state = DRM_SWITCH_POWER_ON; |
| 1071 | drm_kms_helper_poll_enable(dev); |
| 1072 | } else { |
| 1073 | printk(KERN_INFO "amdgpu: switched off\n"); |
| 1074 | drm_kms_helper_poll_disable(dev); |
| 1075 | dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 1076 | amdgpu_device_suspend(dev, true, true); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1077 | dev->switch_power_state = DRM_SWITCH_POWER_OFF; |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | /** |
| 1082 | * amdgpu_switcheroo_can_switch - see if switcheroo state can change |
| 1083 | * |
| 1084 | * @pdev: pci dev pointer |
| 1085 | * |
| 1086 | * Callback for the switcheroo driver. Check of the switcheroo |
| 1087 | * state can be changed. |
| 1088 | * Returns true if the state can be changed, false if not. |
| 1089 | */ |
| 1090 | static bool amdgpu_switcheroo_can_switch(struct pci_dev *pdev) |
| 1091 | { |
| 1092 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 1093 | |
| 1094 | /* |
| 1095 | * FIXME: open_count is protected by drm_global_mutex but that would lead to |
| 1096 | * locking inversion with the driver load path. And the access here is |
| 1097 | * completely racy anyway. So don't bother with locking for now. |
| 1098 | */ |
| 1099 | return dev->open_count == 0; |
| 1100 | } |
| 1101 | |
| 1102 | static const struct vga_switcheroo_client_ops amdgpu_switcheroo_ops = { |
| 1103 | .set_gpu_state = amdgpu_switcheroo_set_state, |
| 1104 | .reprobe = NULL, |
| 1105 | .can_switch = amdgpu_switcheroo_can_switch, |
| 1106 | }; |
| 1107 | |
| 1108 | int amdgpu_set_clockgating_state(struct amdgpu_device *adev, |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1109 | enum amd_ip_block_type block_type, |
| 1110 | enum amd_clockgating_state state) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1111 | { |
| 1112 | int i, r = 0; |
| 1113 | |
| 1114 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1115 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | 9ecbe7f | 2016-06-23 11:53:12 -0400 | [diff] [blame] | 1116 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1117 | if (adev->ip_blocks[i].version->type == block_type) { |
| 1118 | r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev, |
| 1119 | state); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1120 | if (r) |
| 1121 | return r; |
Alex Deucher | a225bf1 | 2016-06-23 11:48:30 -0400 | [diff] [blame] | 1122 | break; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | return r; |
| 1126 | } |
| 1127 | |
| 1128 | int amdgpu_set_powergating_state(struct amdgpu_device *adev, |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1129 | enum amd_ip_block_type block_type, |
| 1130 | enum amd_powergating_state state) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1131 | { |
| 1132 | int i, r = 0; |
| 1133 | |
| 1134 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1135 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | 9ecbe7f | 2016-06-23 11:53:12 -0400 | [diff] [blame] | 1136 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1137 | if (adev->ip_blocks[i].version->type == block_type) { |
| 1138 | r = adev->ip_blocks[i].version->funcs->set_powergating_state((void *)adev, |
| 1139 | state); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1140 | if (r) |
| 1141 | return r; |
Alex Deucher | a225bf1 | 2016-06-23 11:48:30 -0400 | [diff] [blame] | 1142 | break; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1143 | } |
| 1144 | } |
| 1145 | return r; |
| 1146 | } |
| 1147 | |
Huang Rui | 6cb2d4e | 2017-01-05 18:44:41 +0800 | [diff] [blame] | 1148 | void amdgpu_get_clockgating_state(struct amdgpu_device *adev, u32 *flags) |
| 1149 | { |
| 1150 | int i; |
| 1151 | |
| 1152 | for (i = 0; i < adev->num_ip_blocks; i++) { |
| 1153 | if (!adev->ip_blocks[i].status.valid) |
| 1154 | continue; |
| 1155 | if (adev->ip_blocks[i].version->funcs->get_clockgating_state) |
| 1156 | adev->ip_blocks[i].version->funcs->get_clockgating_state((void *)adev, flags); |
| 1157 | } |
| 1158 | } |
| 1159 | |
Alex Deucher | 5dbbb60 | 2016-06-23 11:41:04 -0400 | [diff] [blame] | 1160 | int amdgpu_wait_for_idle(struct amdgpu_device *adev, |
| 1161 | enum amd_ip_block_type block_type) |
| 1162 | { |
| 1163 | int i, r; |
| 1164 | |
| 1165 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1166 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | 9ecbe7f | 2016-06-23 11:53:12 -0400 | [diff] [blame] | 1167 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1168 | if (adev->ip_blocks[i].version->type == block_type) { |
| 1169 | r = adev->ip_blocks[i].version->funcs->wait_for_idle((void *)adev); |
Alex Deucher | 5dbbb60 | 2016-06-23 11:41:04 -0400 | [diff] [blame] | 1170 | if (r) |
| 1171 | return r; |
| 1172 | break; |
| 1173 | } |
| 1174 | } |
| 1175 | return 0; |
| 1176 | |
| 1177 | } |
| 1178 | |
| 1179 | bool amdgpu_is_idle(struct amdgpu_device *adev, |
| 1180 | enum amd_ip_block_type block_type) |
| 1181 | { |
| 1182 | int i; |
| 1183 | |
| 1184 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1185 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | 9ecbe7f | 2016-06-23 11:53:12 -0400 | [diff] [blame] | 1186 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1187 | if (adev->ip_blocks[i].version->type == block_type) |
| 1188 | return adev->ip_blocks[i].version->funcs->is_idle((void *)adev); |
Alex Deucher | 5dbbb60 | 2016-06-23 11:41:04 -0400 | [diff] [blame] | 1189 | } |
| 1190 | return true; |
| 1191 | |
| 1192 | } |
| 1193 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1194 | struct amdgpu_ip_block * amdgpu_get_ip_block(struct amdgpu_device *adev, |
| 1195 | enum amd_ip_block_type type) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1196 | { |
| 1197 | int i; |
| 1198 | |
| 1199 | for (i = 0; i < adev->num_ip_blocks; i++) |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1200 | if (adev->ip_blocks[i].version->type == type) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1201 | return &adev->ip_blocks[i]; |
| 1202 | |
| 1203 | return NULL; |
| 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * amdgpu_ip_block_version_cmp |
| 1208 | * |
| 1209 | * @adev: amdgpu_device pointer |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1210 | * @type: enum amd_ip_block_type |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1211 | * @major: major version |
| 1212 | * @minor: minor version |
| 1213 | * |
| 1214 | * return 0 if equal or greater |
| 1215 | * return 1 if smaller or the ip_block doesn't exist |
| 1216 | */ |
| 1217 | int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev, |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1218 | enum amd_ip_block_type type, |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1219 | u32 major, u32 minor) |
| 1220 | { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1221 | struct amdgpu_ip_block *ip_block = amdgpu_get_ip_block(adev, type); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1222 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1223 | if (ip_block && ((ip_block->version->major > major) || |
| 1224 | ((ip_block->version->major == major) && |
| 1225 | (ip_block->version->minor >= minor)))) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1226 | return 0; |
| 1227 | |
| 1228 | return 1; |
| 1229 | } |
| 1230 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1231 | /** |
| 1232 | * amdgpu_ip_block_add |
| 1233 | * |
| 1234 | * @adev: amdgpu_device pointer |
| 1235 | * @ip_block_version: pointer to the IP to add |
| 1236 | * |
| 1237 | * Adds the IP block driver information to the collection of IPs |
| 1238 | * on the asic. |
| 1239 | */ |
| 1240 | int amdgpu_ip_block_add(struct amdgpu_device *adev, |
| 1241 | const struct amdgpu_ip_block_version *ip_block_version) |
| 1242 | { |
| 1243 | if (!ip_block_version) |
| 1244 | return -EINVAL; |
| 1245 | |
| 1246 | adev->ip_blocks[adev->num_ip_blocks++].version = ip_block_version; |
| 1247 | |
| 1248 | return 0; |
| 1249 | } |
| 1250 | |
Alex Deucher | 483ef98 | 2016-09-30 12:43:04 -0400 | [diff] [blame] | 1251 | static void amdgpu_device_enable_virtual_display(struct amdgpu_device *adev) |
Emily Deng | 9accf2f | 2016-08-10 16:01:25 +0800 | [diff] [blame] | 1252 | { |
| 1253 | adev->enable_virtual_display = false; |
| 1254 | |
| 1255 | if (amdgpu_virtual_display) { |
| 1256 | struct drm_device *ddev = adev->ddev; |
| 1257 | const char *pci_address_name = pci_name(ddev->pdev); |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 1258 | char *pciaddstr, *pciaddstr_tmp, *pciaddname_tmp, *pciaddname; |
Emily Deng | 9accf2f | 2016-08-10 16:01:25 +0800 | [diff] [blame] | 1259 | |
| 1260 | pciaddstr = kstrdup(amdgpu_virtual_display, GFP_KERNEL); |
| 1261 | pciaddstr_tmp = pciaddstr; |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 1262 | while ((pciaddname_tmp = strsep(&pciaddstr_tmp, ";"))) { |
| 1263 | pciaddname = strsep(&pciaddname_tmp, ","); |
Yintian Tao | 967de2a | 2017-01-22 15:16:51 +0800 | [diff] [blame] | 1264 | if (!strcmp("all", pciaddname) |
| 1265 | || !strcmp(pci_address_name, pciaddname)) { |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 1266 | long num_crtc; |
| 1267 | int res = -1; |
| 1268 | |
Emily Deng | 9accf2f | 2016-08-10 16:01:25 +0800 | [diff] [blame] | 1269 | adev->enable_virtual_display = true; |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 1270 | |
| 1271 | if (pciaddname_tmp) |
| 1272 | res = kstrtol(pciaddname_tmp, 10, |
| 1273 | &num_crtc); |
| 1274 | |
| 1275 | if (!res) { |
| 1276 | if (num_crtc < 1) |
| 1277 | num_crtc = 1; |
| 1278 | if (num_crtc > 6) |
| 1279 | num_crtc = 6; |
| 1280 | adev->mode_info.num_crtc = num_crtc; |
| 1281 | } else { |
| 1282 | adev->mode_info.num_crtc = 1; |
| 1283 | } |
Emily Deng | 9accf2f | 2016-08-10 16:01:25 +0800 | [diff] [blame] | 1284 | break; |
| 1285 | } |
| 1286 | } |
| 1287 | |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 1288 | DRM_INFO("virtual display string:%s, %s:virtual_display:%d, num_crtc:%d\n", |
| 1289 | amdgpu_virtual_display, pci_address_name, |
| 1290 | adev->enable_virtual_display, adev->mode_info.num_crtc); |
Emily Deng | 9accf2f | 2016-08-10 16:01:25 +0800 | [diff] [blame] | 1291 | |
| 1292 | kfree(pciaddstr); |
| 1293 | } |
| 1294 | } |
| 1295 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1296 | static int amdgpu_early_init(struct amdgpu_device *adev) |
| 1297 | { |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1298 | int i, r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1299 | |
Alex Deucher | 483ef98 | 2016-09-30 12:43:04 -0400 | [diff] [blame] | 1300 | amdgpu_device_enable_virtual_display(adev); |
Emily Deng | a6be757 | 2016-08-08 11:37:50 +0800 | [diff] [blame] | 1301 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1302 | switch (adev->asic_type) { |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1303 | case CHIP_TOPAZ: |
| 1304 | case CHIP_TONGA: |
David Zhang | 48299f9 | 2015-07-08 01:05:16 +0800 | [diff] [blame] | 1305 | case CHIP_FIJI: |
Flora Cui | 2cc0c0b | 2016-03-14 18:33:29 -0400 | [diff] [blame] | 1306 | case CHIP_POLARIS11: |
| 1307 | case CHIP_POLARIS10: |
Junwei Zhang | c4642a4 | 2016-12-14 15:32:28 -0500 | [diff] [blame] | 1308 | case CHIP_POLARIS12: |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1309 | case CHIP_CARRIZO: |
Samuel Li | 39bb0c9 | 2015-10-08 16:31:43 -0400 | [diff] [blame] | 1310 | case CHIP_STONEY: |
| 1311 | if (adev->asic_type == CHIP_CARRIZO || adev->asic_type == CHIP_STONEY) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1312 | adev->family = AMDGPU_FAMILY_CZ; |
| 1313 | else |
| 1314 | adev->family = AMDGPU_FAMILY_VI; |
| 1315 | |
| 1316 | r = vi_set_ip_blocks(adev); |
| 1317 | if (r) |
| 1318 | return r; |
| 1319 | break; |
Ken Wang | 33f3480 | 2016-01-21 17:29:41 +0800 | [diff] [blame] | 1320 | #ifdef CONFIG_DRM_AMDGPU_SI |
| 1321 | case CHIP_VERDE: |
| 1322 | case CHIP_TAHITI: |
| 1323 | case CHIP_PITCAIRN: |
| 1324 | case CHIP_OLAND: |
| 1325 | case CHIP_HAINAN: |
Ken Wang | 295d0da | 2016-05-24 21:02:53 +0800 | [diff] [blame] | 1326 | adev->family = AMDGPU_FAMILY_SI; |
Ken Wang | 33f3480 | 2016-01-21 17:29:41 +0800 | [diff] [blame] | 1327 | r = si_set_ip_blocks(adev); |
| 1328 | if (r) |
| 1329 | return r; |
| 1330 | break; |
| 1331 | #endif |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 1332 | #ifdef CONFIG_DRM_AMDGPU_CIK |
| 1333 | case CHIP_BONAIRE: |
| 1334 | case CHIP_HAWAII: |
| 1335 | case CHIP_KAVERI: |
| 1336 | case CHIP_KABINI: |
| 1337 | case CHIP_MULLINS: |
| 1338 | if ((adev->asic_type == CHIP_BONAIRE) || (adev->asic_type == CHIP_HAWAII)) |
| 1339 | adev->family = AMDGPU_FAMILY_CI; |
| 1340 | else |
| 1341 | adev->family = AMDGPU_FAMILY_KV; |
| 1342 | |
| 1343 | r = cik_set_ip_blocks(adev); |
| 1344 | if (r) |
| 1345 | return r; |
| 1346 | break; |
| 1347 | #endif |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1348 | default: |
| 1349 | /* FIXME: not supported yet */ |
| 1350 | return -EINVAL; |
| 1351 | } |
| 1352 | |
Xiangliang Yu | 3149d9d | 2017-01-12 15:14:36 +0800 | [diff] [blame] | 1353 | if (amdgpu_sriov_vf(adev)) { |
| 1354 | r = amdgpu_virt_request_full_gpu(adev, true); |
| 1355 | if (r) |
| 1356 | return r; |
| 1357 | } |
| 1358 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1359 | for (i = 0; i < adev->num_ip_blocks; i++) { |
| 1360 | if ((amdgpu_ip_block_mask & (1 << i)) == 0) { |
| 1361 | DRM_ERROR("disabled ip block: %d\n", i); |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1362 | adev->ip_blocks[i].status.valid = false; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1363 | } else { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1364 | if (adev->ip_blocks[i].version->funcs->early_init) { |
| 1365 | r = adev->ip_blocks[i].version->funcs->early_init((void *)adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1366 | if (r == -ENOENT) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1367 | adev->ip_blocks[i].status.valid = false; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1368 | } else if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1369 | DRM_ERROR("early_init of IP block <%s> failed %d\n", |
| 1370 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1371 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1372 | } else { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1373 | adev->ip_blocks[i].status.valid = true; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1374 | } |
Alex Deucher | 974e6b6 | 2015-07-10 13:59:44 -0400 | [diff] [blame] | 1375 | } else { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1376 | adev->ip_blocks[i].status.valid = true; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1377 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1378 | } |
| 1379 | } |
| 1380 | |
Nicolai Hähnle | 395d1fb | 2016-06-02 12:32:07 +0200 | [diff] [blame] | 1381 | adev->cg_flags &= amdgpu_cg_mask; |
| 1382 | adev->pg_flags &= amdgpu_pg_mask; |
| 1383 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1384 | return 0; |
| 1385 | } |
| 1386 | |
| 1387 | static int amdgpu_init(struct amdgpu_device *adev) |
| 1388 | { |
| 1389 | int i, r; |
| 1390 | |
| 1391 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1392 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1393 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1394 | r = adev->ip_blocks[i].version->funcs->sw_init((void *)adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1395 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1396 | DRM_ERROR("sw_init of IP block <%s> failed %d\n", |
| 1397 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1398 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1399 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1400 | adev->ip_blocks[i].status.sw = true; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1401 | /* need to do gmc hw init early so we can allocate gpu mem */ |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1402 | if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1403 | r = amdgpu_vram_scratch_init(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1404 | if (r) { |
| 1405 | DRM_ERROR("amdgpu_vram_scratch_init failed %d\n", r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1406 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1407 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1408 | r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1409 | if (r) { |
| 1410 | DRM_ERROR("hw_init %d failed %d\n", i, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1411 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1412 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1413 | r = amdgpu_wb_init(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1414 | if (r) { |
| 1415 | DRM_ERROR("amdgpu_wb_init failed %d\n", r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1416 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1417 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1418 | adev->ip_blocks[i].status.hw = true; |
Monk Liu | 2493664 | 2017-01-09 15:54:32 +0800 | [diff] [blame] | 1419 | |
| 1420 | /* right after GMC hw init, we create CSA */ |
| 1421 | if (amdgpu_sriov_vf(adev)) { |
| 1422 | r = amdgpu_allocate_static_csa(adev); |
| 1423 | if (r) { |
| 1424 | DRM_ERROR("allocate CSA failed %d\n", r); |
| 1425 | return r; |
| 1426 | } |
| 1427 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1432 | if (!adev->ip_blocks[i].status.sw) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1433 | continue; |
| 1434 | /* gmc hw init is done early */ |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1435 | if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1436 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1437 | r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1438 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1439 | DRM_ERROR("hw_init of IP block <%s> failed %d\n", |
| 1440 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1441 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1442 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1443 | adev->ip_blocks[i].status.hw = true; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | return 0; |
| 1447 | } |
| 1448 | |
| 1449 | static int amdgpu_late_init(struct amdgpu_device *adev) |
| 1450 | { |
| 1451 | int i = 0, r; |
| 1452 | |
| 1453 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1454 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1455 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1456 | if (adev->ip_blocks[i].version->funcs->late_init) { |
| 1457 | r = adev->ip_blocks[i].version->funcs->late_init((void *)adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1458 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1459 | DRM_ERROR("late_init of IP block <%s> failed %d\n", |
| 1460 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1461 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1462 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1463 | adev->ip_blocks[i].status.late_initialized = true; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1464 | } |
Alex Deucher | 4a446d5 | 2016-10-07 14:48:18 -0400 | [diff] [blame] | 1465 | /* skip CG for VCE/UVD, it's handled specially */ |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1466 | if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD && |
| 1467 | adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) { |
Alex Deucher | 4a446d5 | 2016-10-07 14:48:18 -0400 | [diff] [blame] | 1468 | /* enable clockgating to save power */ |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1469 | r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev, |
| 1470 | AMD_CG_STATE_GATE); |
Alex Deucher | 4a446d5 | 2016-10-07 14:48:18 -0400 | [diff] [blame] | 1471 | if (r) { |
| 1472 | DRM_ERROR("set_clockgating_state(gate) of IP block <%s> failed %d\n", |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1473 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | 4a446d5 | 2016-10-07 14:48:18 -0400 | [diff] [blame] | 1474 | return r; |
| 1475 | } |
Arindam Nath | b0b00ff | 2016-10-07 19:01:37 +0530 | [diff] [blame] | 1476 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | return 0; |
| 1480 | } |
| 1481 | |
| 1482 | static int amdgpu_fini(struct amdgpu_device *adev) |
| 1483 | { |
| 1484 | int i, r; |
| 1485 | |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1486 | /* need to disable SMC first */ |
| 1487 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1488 | if (!adev->ip_blocks[i].status.hw) |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1489 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1490 | if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) { |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1491 | /* ungate blocks before hw fini so that we can shutdown the blocks safely */ |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1492 | r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev, |
| 1493 | AMD_CG_STATE_UNGATE); |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1494 | if (r) { |
| 1495 | DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n", |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1496 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1497 | return r; |
| 1498 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1499 | r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev); |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1500 | /* XXX handle errors */ |
| 1501 | if (r) { |
| 1502 | DRM_DEBUG("hw_fini of IP block <%s> failed %d\n", |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1503 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1504 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1505 | adev->ip_blocks[i].status.hw = false; |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1506 | break; |
| 1507 | } |
| 1508 | } |
| 1509 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1510 | for (i = adev->num_ip_blocks - 1; i >= 0; i--) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1511 | if (!adev->ip_blocks[i].status.hw) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1512 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1513 | if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1514 | amdgpu_wb_fini(adev); |
| 1515 | amdgpu_vram_scratch_fini(adev); |
| 1516 | } |
Rex Zhu | 8201a67 | 2016-11-24 21:44:44 +0800 | [diff] [blame] | 1517 | |
| 1518 | if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD && |
| 1519 | adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) { |
| 1520 | /* ungate blocks before hw fini so that we can shutdown the blocks safely */ |
| 1521 | r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev, |
| 1522 | AMD_CG_STATE_UNGATE); |
| 1523 | if (r) { |
| 1524 | DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n", |
| 1525 | adev->ip_blocks[i].version->funcs->name, r); |
| 1526 | return r; |
| 1527 | } |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1528 | } |
Rex Zhu | 8201a67 | 2016-11-24 21:44:44 +0800 | [diff] [blame] | 1529 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1530 | r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1531 | /* XXX handle errors */ |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1532 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1533 | DRM_DEBUG("hw_fini of IP block <%s> failed %d\n", |
| 1534 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1535 | } |
Rex Zhu | 8201a67 | 2016-11-24 21:44:44 +0800 | [diff] [blame] | 1536 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1537 | adev->ip_blocks[i].status.hw = false; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | for (i = adev->num_ip_blocks - 1; i >= 0; i--) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1541 | if (!adev->ip_blocks[i].status.sw) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1542 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1543 | r = adev->ip_blocks[i].version->funcs->sw_fini((void *)adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1544 | /* XXX handle errors */ |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1545 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1546 | DRM_DEBUG("sw_fini of IP block <%s> failed %d\n", |
| 1547 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1548 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1549 | adev->ip_blocks[i].status.sw = false; |
| 1550 | adev->ip_blocks[i].status.valid = false; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1551 | } |
| 1552 | |
Monk Liu | a6dcfd9 | 2016-05-19 14:36:34 +0800 | [diff] [blame] | 1553 | for (i = adev->num_ip_blocks - 1; i >= 0; i--) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1554 | if (!adev->ip_blocks[i].status.late_initialized) |
Grazvydas Ignotas | 8a2eef1 | 2016-10-03 00:06:44 +0300 | [diff] [blame] | 1555 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1556 | if (adev->ip_blocks[i].version->funcs->late_fini) |
| 1557 | adev->ip_blocks[i].version->funcs->late_fini((void *)adev); |
| 1558 | adev->ip_blocks[i].status.late_initialized = false; |
Monk Liu | a6dcfd9 | 2016-05-19 14:36:34 +0800 | [diff] [blame] | 1559 | } |
| 1560 | |
Xiangliang Yu | 3149d9d | 2017-01-12 15:14:36 +0800 | [diff] [blame] | 1561 | if (amdgpu_sriov_vf(adev)) { |
Monk Liu | 2493664 | 2017-01-09 15:54:32 +0800 | [diff] [blame] | 1562 | amdgpu_bo_free_kernel(&adev->virt.csa_obj, &adev->virt.csa_vmid0_addr, NULL); |
Xiangliang Yu | 3149d9d | 2017-01-12 15:14:36 +0800 | [diff] [blame] | 1563 | amdgpu_virt_release_full_gpu(adev, false); |
| 1564 | } |
Monk Liu | 2493664 | 2017-01-09 15:54:32 +0800 | [diff] [blame] | 1565 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1566 | return 0; |
| 1567 | } |
| 1568 | |
Alex Deucher | faefba9 | 2016-12-06 10:38:29 -0500 | [diff] [blame] | 1569 | int amdgpu_suspend(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1570 | { |
| 1571 | int i, r; |
| 1572 | |
Xiangliang Yu | e941ea9 | 2017-01-18 12:47:55 +0800 | [diff] [blame] | 1573 | if (amdgpu_sriov_vf(adev)) |
| 1574 | amdgpu_virt_request_full_gpu(adev, false); |
| 1575 | |
Flora Cui | c5a93a2 | 2016-02-26 10:45:25 +0800 | [diff] [blame] | 1576 | /* ungate SMC block first */ |
| 1577 | r = amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_SMC, |
| 1578 | AMD_CG_STATE_UNGATE); |
| 1579 | if (r) { |
| 1580 | DRM_ERROR("set_clockgating_state(ungate) SMC failed %d\n",r); |
| 1581 | } |
| 1582 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1583 | for (i = adev->num_ip_blocks - 1; i >= 0; i--) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1584 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1585 | continue; |
| 1586 | /* ungate blocks so that suspend can properly shut them down */ |
Flora Cui | c5a93a2 | 2016-02-26 10:45:25 +0800 | [diff] [blame] | 1587 | if (i != AMD_IP_BLOCK_TYPE_SMC) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1588 | r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev, |
| 1589 | AMD_CG_STATE_UNGATE); |
Flora Cui | c5a93a2 | 2016-02-26 10:45:25 +0800 | [diff] [blame] | 1590 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1591 | DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n", |
| 1592 | adev->ip_blocks[i].version->funcs->name, r); |
Flora Cui | c5a93a2 | 2016-02-26 10:45:25 +0800 | [diff] [blame] | 1593 | } |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1594 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1595 | /* XXX handle errors */ |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1596 | r = adev->ip_blocks[i].version->funcs->suspend(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1597 | /* XXX handle errors */ |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1598 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1599 | DRM_ERROR("suspend of IP block <%s> failed %d\n", |
| 1600 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1601 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1602 | } |
| 1603 | |
Xiangliang Yu | e941ea9 | 2017-01-18 12:47:55 +0800 | [diff] [blame] | 1604 | if (amdgpu_sriov_vf(adev)) |
| 1605 | amdgpu_virt_release_full_gpu(adev, false); |
| 1606 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1607 | return 0; |
| 1608 | } |
| 1609 | |
Monk Liu | e4f0fdc | 2017-02-09 11:55:49 +0800 | [diff] [blame^] | 1610 | static int amdgpu_sriov_reinit_early(struct amdgpu_device *adev) |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1611 | { |
| 1612 | int i, r; |
| 1613 | |
| 1614 | for (i = 0; i < adev->num_ip_blocks; i++) { |
| 1615 | if (!adev->ip_blocks[i].status.valid) |
| 1616 | continue; |
| 1617 | |
| 1618 | if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON || |
| 1619 | adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC || |
| 1620 | adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_IH) |
Monk Liu | e4f0fdc | 2017-02-09 11:55:49 +0800 | [diff] [blame^] | 1621 | r = adev->ip_blocks[i].version->funcs->hw_init(adev); |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1622 | |
| 1623 | if (r) { |
| 1624 | DRM_ERROR("resume of IP block <%s> failed %d\n", |
| 1625 | adev->ip_blocks[i].version->funcs->name, r); |
| 1626 | return r; |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | return 0; |
| 1631 | } |
| 1632 | |
Monk Liu | e4f0fdc | 2017-02-09 11:55:49 +0800 | [diff] [blame^] | 1633 | static int amdgpu_sriov_reinit_late(struct amdgpu_device *adev) |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1634 | { |
| 1635 | int i, r; |
| 1636 | |
| 1637 | for (i = 0; i < adev->num_ip_blocks; i++) { |
| 1638 | if (!adev->ip_blocks[i].status.valid) |
| 1639 | continue; |
| 1640 | |
| 1641 | if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON || |
| 1642 | adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC || |
| 1643 | adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_IH ) |
| 1644 | continue; |
| 1645 | |
Monk Liu | e4f0fdc | 2017-02-09 11:55:49 +0800 | [diff] [blame^] | 1646 | r = adev->ip_blocks[i].version->funcs->hw_init(adev); |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1647 | if (r) { |
| 1648 | DRM_ERROR("resume of IP block <%s> failed %d\n", |
| 1649 | adev->ip_blocks[i].version->funcs->name, r); |
| 1650 | return r; |
| 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | return 0; |
| 1655 | } |
| 1656 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1657 | static int amdgpu_resume(struct amdgpu_device *adev) |
| 1658 | { |
| 1659 | int i, r; |
| 1660 | |
| 1661 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1662 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1663 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1664 | r = adev->ip_blocks[i].version->funcs->resume(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1665 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1666 | DRM_ERROR("resume of IP block <%s> failed %d\n", |
| 1667 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1668 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1669 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | return 0; |
| 1673 | } |
| 1674 | |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 1675 | static void amdgpu_device_detect_sriov_bios(struct amdgpu_device *adev) |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 1676 | { |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 1677 | if (amdgpu_atombios_has_gpu_virtualization_table(adev)) |
Xiangliang Yu | 5a5099c | 2017-01-09 18:06:57 -0500 | [diff] [blame] | 1678 | adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS; |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 1679 | } |
| 1680 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1681 | /** |
| 1682 | * amdgpu_device_init - initialize the driver |
| 1683 | * |
| 1684 | * @adev: amdgpu_device pointer |
| 1685 | * @pdev: drm dev pointer |
| 1686 | * @pdev: pci dev pointer |
| 1687 | * @flags: driver flags |
| 1688 | * |
| 1689 | * Initializes the driver info and hw (all asics). |
| 1690 | * Returns 0 for success or an error on failure. |
| 1691 | * Called at driver startup. |
| 1692 | */ |
| 1693 | int amdgpu_device_init(struct amdgpu_device *adev, |
| 1694 | struct drm_device *ddev, |
| 1695 | struct pci_dev *pdev, |
| 1696 | uint32_t flags) |
| 1697 | { |
| 1698 | int r, i; |
| 1699 | bool runtime = false; |
Marek Olšák | 95844d2 | 2016-08-17 23:49:27 +0200 | [diff] [blame] | 1700 | u32 max_MBps; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1701 | |
| 1702 | adev->shutdown = false; |
| 1703 | adev->dev = &pdev->dev; |
| 1704 | adev->ddev = ddev; |
| 1705 | adev->pdev = pdev; |
| 1706 | adev->flags = flags; |
Jammy Zhou | 2f7d10b | 2015-07-22 11:29:01 +0800 | [diff] [blame] | 1707 | adev->asic_type = flags & AMD_ASIC_MASK; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1708 | adev->usec_timeout = AMDGPU_MAX_USEC_TIMEOUT; |
| 1709 | adev->mc.gtt_size = 512 * 1024 * 1024; |
| 1710 | adev->accel_working = false; |
| 1711 | adev->num_rings = 0; |
| 1712 | adev->mman.buffer_funcs = NULL; |
| 1713 | adev->mman.buffer_funcs_ring = NULL; |
| 1714 | adev->vm_manager.vm_pte_funcs = NULL; |
Christian König | 2d55e45 | 2016-02-08 17:37:38 +0100 | [diff] [blame] | 1715 | adev->vm_manager.vm_pte_num_rings = 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1716 | adev->gart.gart_funcs = NULL; |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 1717 | adev->fence_context = dma_fence_context_alloc(AMDGPU_MAX_RINGS); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1718 | |
| 1719 | adev->smc_rreg = &amdgpu_invalid_rreg; |
| 1720 | adev->smc_wreg = &amdgpu_invalid_wreg; |
| 1721 | adev->pcie_rreg = &amdgpu_invalid_rreg; |
| 1722 | adev->pcie_wreg = &amdgpu_invalid_wreg; |
Huang Rui | 36b9a95 | 2016-08-31 13:23:25 +0800 | [diff] [blame] | 1723 | adev->pciep_rreg = &amdgpu_invalid_rreg; |
| 1724 | adev->pciep_wreg = &amdgpu_invalid_wreg; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1725 | adev->uvd_ctx_rreg = &amdgpu_invalid_rreg; |
| 1726 | adev->uvd_ctx_wreg = &amdgpu_invalid_wreg; |
| 1727 | adev->didt_rreg = &amdgpu_invalid_rreg; |
| 1728 | adev->didt_wreg = &amdgpu_invalid_wreg; |
Rex Zhu | ccdbb20 | 2016-06-08 12:47:41 +0800 | [diff] [blame] | 1729 | adev->gc_cac_rreg = &amdgpu_invalid_rreg; |
| 1730 | adev->gc_cac_wreg = &amdgpu_invalid_wreg; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1731 | adev->audio_endpt_rreg = &amdgpu_block_invalid_rreg; |
| 1732 | adev->audio_endpt_wreg = &amdgpu_block_invalid_wreg; |
| 1733 | |
Rex Zhu | ccdbb20 | 2016-06-08 12:47:41 +0800 | [diff] [blame] | 1734 | |
Alex Deucher | 3e39ab9 | 2015-06-05 15:04:33 -0400 | [diff] [blame] | 1735 | DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X 0x%02X).\n", |
| 1736 | amdgpu_asic_name[adev->asic_type], pdev->vendor, pdev->device, |
| 1737 | pdev->subsystem_vendor, pdev->subsystem_device, pdev->revision); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1738 | |
| 1739 | /* mutex initialization are all done here so we |
| 1740 | * can recall function without having locking issues */ |
Christian König | 8d0a7ce | 2015-11-03 20:58:50 +0100 | [diff] [blame] | 1741 | mutex_init(&adev->vm_manager.lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1742 | atomic_set(&adev->irq.ih.lock, 0); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1743 | mutex_init(&adev->pm.mutex); |
| 1744 | mutex_init(&adev->gfx.gpu_clock_mutex); |
| 1745 | mutex_init(&adev->srbm_mutex); |
| 1746 | mutex_init(&adev->grbm_idx_mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1747 | mutex_init(&adev->mn_lock); |
| 1748 | hash_init(adev->mn_hash); |
| 1749 | |
| 1750 | amdgpu_check_arguments(adev); |
| 1751 | |
| 1752 | /* Registers mapping */ |
| 1753 | /* TODO: block userspace mapping of io register */ |
| 1754 | spin_lock_init(&adev->mmio_idx_lock); |
| 1755 | spin_lock_init(&adev->smc_idx_lock); |
| 1756 | spin_lock_init(&adev->pcie_idx_lock); |
| 1757 | spin_lock_init(&adev->uvd_ctx_idx_lock); |
| 1758 | spin_lock_init(&adev->didt_idx_lock); |
Rex Zhu | ccdbb20 | 2016-06-08 12:47:41 +0800 | [diff] [blame] | 1759 | spin_lock_init(&adev->gc_cac_idx_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1760 | spin_lock_init(&adev->audio_endpt_idx_lock); |
Marek Olšák | 95844d2 | 2016-08-17 23:49:27 +0200 | [diff] [blame] | 1761 | spin_lock_init(&adev->mm_stats.lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1762 | |
Chunming Zhou | 0c4e7fa | 2016-08-17 11:41:30 +0800 | [diff] [blame] | 1763 | INIT_LIST_HEAD(&adev->shadow_list); |
| 1764 | mutex_init(&adev->shadow_list_lock); |
| 1765 | |
Chunming Zhou | 5c1354b | 2016-08-30 16:13:10 +0800 | [diff] [blame] | 1766 | INIT_LIST_HEAD(&adev->gtt_list); |
| 1767 | spin_lock_init(&adev->gtt_list_lock); |
| 1768 | |
Ken Wang | da69c161 | 2016-01-21 19:08:55 +0800 | [diff] [blame] | 1769 | if (adev->asic_type >= CHIP_BONAIRE) { |
| 1770 | adev->rmmio_base = pci_resource_start(adev->pdev, 5); |
| 1771 | adev->rmmio_size = pci_resource_len(adev->pdev, 5); |
| 1772 | } else { |
| 1773 | adev->rmmio_base = pci_resource_start(adev->pdev, 2); |
| 1774 | adev->rmmio_size = pci_resource_len(adev->pdev, 2); |
| 1775 | } |
Chunming Zhou | 5c1354b | 2016-08-30 16:13:10 +0800 | [diff] [blame] | 1776 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1777 | adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size); |
| 1778 | if (adev->rmmio == NULL) { |
| 1779 | return -ENOMEM; |
| 1780 | } |
| 1781 | DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base); |
| 1782 | DRM_INFO("register mmio size: %u\n", (unsigned)adev->rmmio_size); |
| 1783 | |
Ken Wang | da69c161 | 2016-01-21 19:08:55 +0800 | [diff] [blame] | 1784 | if (adev->asic_type >= CHIP_BONAIRE) |
| 1785 | /* doorbell bar mapping */ |
| 1786 | amdgpu_doorbell_init(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1787 | |
| 1788 | /* io port mapping */ |
| 1789 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 1790 | if (pci_resource_flags(adev->pdev, i) & IORESOURCE_IO) { |
| 1791 | adev->rio_mem_size = pci_resource_len(adev->pdev, i); |
| 1792 | adev->rio_mem = pci_iomap(adev->pdev, i, adev->rio_mem_size); |
| 1793 | break; |
| 1794 | } |
| 1795 | } |
| 1796 | if (adev->rio_mem == NULL) |
Amber Lin | b64a18c | 2017-01-04 08:06:58 -0500 | [diff] [blame] | 1797 | DRM_INFO("PCI I/O BAR is not found.\n"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1798 | |
| 1799 | /* early init functions */ |
| 1800 | r = amdgpu_early_init(adev); |
| 1801 | if (r) |
| 1802 | return r; |
| 1803 | |
| 1804 | /* if we have > 1 VGA cards, then disable the amdgpu VGA resources */ |
| 1805 | /* this will fail for cards that aren't VGA class devices, just |
| 1806 | * ignore it */ |
| 1807 | vga_client_register(adev->pdev, adev, NULL, amdgpu_vga_set_decode); |
| 1808 | |
| 1809 | if (amdgpu_runtime_pm == 1) |
| 1810 | runtime = true; |
Alex Deucher | e9bef45 | 2016-04-25 13:12:18 -0400 | [diff] [blame] | 1811 | if (amdgpu_device_is_px(ddev)) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1812 | runtime = true; |
| 1813 | vga_switcheroo_register_client(adev->pdev, &amdgpu_switcheroo_ops, runtime); |
| 1814 | if (runtime) |
| 1815 | vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain); |
| 1816 | |
| 1817 | /* Read BIOS */ |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1818 | if (!amdgpu_get_bios(adev)) { |
| 1819 | r = -EINVAL; |
| 1820 | goto failed; |
| 1821 | } |
Nils Wallménius | f7e9e9f | 2016-12-14 21:52:45 +0100 | [diff] [blame] | 1822 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1823 | r = amdgpu_atombios_init(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1824 | if (r) { |
| 1825 | dev_err(adev->dev, "amdgpu_atombios_init failed\n"); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1826 | goto failed; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1827 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1828 | |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 1829 | /* detect if we are with an SRIOV vbios */ |
| 1830 | amdgpu_device_detect_sriov_bios(adev); |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 1831 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1832 | /* Post card if necessary */ |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 1833 | if (amdgpu_vpost_needed(adev)) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1834 | if (!adev->bios) { |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 1835 | dev_err(adev->dev, "no vBIOS found\n"); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1836 | r = -EINVAL; |
| 1837 | goto failed; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1838 | } |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 1839 | DRM_INFO("GPU posting now...\n"); |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 1840 | r = amdgpu_atom_asic_init(adev->mode_info.atom_context); |
| 1841 | if (r) { |
| 1842 | dev_err(adev->dev, "gpu post error!\n"); |
| 1843 | goto failed; |
| 1844 | } |
| 1845 | } else { |
| 1846 | DRM_INFO("GPU post is not needed\n"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | /* Initialize clocks */ |
| 1850 | r = amdgpu_atombios_get_clock_info(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1851 | if (r) { |
| 1852 | dev_err(adev->dev, "amdgpu_atombios_get_clock_info failed\n"); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1853 | goto failed; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1854 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1855 | /* init i2c buses */ |
| 1856 | amdgpu_atombios_i2c_init(adev); |
| 1857 | |
| 1858 | /* Fence driver */ |
| 1859 | r = amdgpu_fence_driver_init(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1860 | if (r) { |
| 1861 | dev_err(adev->dev, "amdgpu_fence_driver_init failed\n"); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1862 | goto failed; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1863 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1864 | |
| 1865 | /* init the mode config */ |
| 1866 | drm_mode_config_init(adev->ddev); |
| 1867 | |
| 1868 | r = amdgpu_init(adev); |
| 1869 | if (r) { |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1870 | dev_err(adev->dev, "amdgpu_init failed\n"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1871 | amdgpu_fini(adev); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1872 | goto failed; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | adev->accel_working = true; |
| 1876 | |
Marek Olšák | 95844d2 | 2016-08-17 23:49:27 +0200 | [diff] [blame] | 1877 | /* Initialize the buffer migration limit. */ |
| 1878 | if (amdgpu_moverate >= 0) |
| 1879 | max_MBps = amdgpu_moverate; |
| 1880 | else |
| 1881 | max_MBps = 8; /* Allow 8 MB/s. */ |
| 1882 | /* Get a log2 for easy divisions. */ |
| 1883 | adev->mm_stats.log2_max_MBps = ilog2(max(1u, max_MBps)); |
| 1884 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1885 | r = amdgpu_ib_pool_init(adev); |
| 1886 | if (r) { |
| 1887 | dev_err(adev->dev, "IB initialization failed (%d).\n", r); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1888 | goto failed; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | r = amdgpu_ib_ring_tests(adev); |
| 1892 | if (r) |
| 1893 | DRM_ERROR("ib ring test failed (%d).\n", r); |
| 1894 | |
Monk Liu | 9bc92b9 | 2017-02-08 17:38:13 +0800 | [diff] [blame] | 1895 | amdgpu_fbdev_init(adev); |
| 1896 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1897 | r = amdgpu_gem_debugfs_init(adev); |
Monk Liu | 3f14e62 | 2017-02-09 13:42:27 +0800 | [diff] [blame] | 1898 | if (r) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1899 | DRM_ERROR("registering gem debugfs failed (%d).\n", r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1900 | |
| 1901 | r = amdgpu_debugfs_regs_init(adev); |
Monk Liu | 3f14e62 | 2017-02-09 13:42:27 +0800 | [diff] [blame] | 1902 | if (r) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1903 | DRM_ERROR("registering register debugfs failed (%d).\n", r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1904 | |
Huang Rui | 50ab253 | 2016-06-12 15:51:09 +0800 | [diff] [blame] | 1905 | r = amdgpu_debugfs_firmware_init(adev); |
Monk Liu | 3f14e62 | 2017-02-09 13:42:27 +0800 | [diff] [blame] | 1906 | if (r) |
Huang Rui | 50ab253 | 2016-06-12 15:51:09 +0800 | [diff] [blame] | 1907 | DRM_ERROR("registering firmware debugfs failed (%d).\n", r); |
Huang Rui | 50ab253 | 2016-06-12 15:51:09 +0800 | [diff] [blame] | 1908 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1909 | if ((amdgpu_testing & 1)) { |
| 1910 | if (adev->accel_working) |
| 1911 | amdgpu_test_moves(adev); |
| 1912 | else |
| 1913 | DRM_INFO("amdgpu: acceleration disabled, skipping move tests\n"); |
| 1914 | } |
| 1915 | if ((amdgpu_testing & 2)) { |
| 1916 | if (adev->accel_working) |
| 1917 | amdgpu_test_syncing(adev); |
| 1918 | else |
| 1919 | DRM_INFO("amdgpu: acceleration disabled, skipping sync tests\n"); |
| 1920 | } |
| 1921 | if (amdgpu_benchmarking) { |
| 1922 | if (adev->accel_working) |
| 1923 | amdgpu_benchmark(adev, amdgpu_benchmarking); |
| 1924 | else |
| 1925 | DRM_INFO("amdgpu: acceleration disabled, skipping benchmarks\n"); |
| 1926 | } |
| 1927 | |
| 1928 | /* enable clockgating, etc. after ib tests, etc. since some blocks require |
| 1929 | * explicit gating rather than handling it automatically. |
| 1930 | */ |
| 1931 | r = amdgpu_late_init(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1932 | if (r) { |
| 1933 | dev_err(adev->dev, "amdgpu_late_init failed\n"); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1934 | goto failed; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1935 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1936 | |
| 1937 | return 0; |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1938 | |
| 1939 | failed: |
| 1940 | if (runtime) |
| 1941 | vga_switcheroo_fini_domain_pm_ops(adev->dev); |
| 1942 | return r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1943 | } |
| 1944 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1945 | /** |
| 1946 | * amdgpu_device_fini - tear down the driver |
| 1947 | * |
| 1948 | * @adev: amdgpu_device pointer |
| 1949 | * |
| 1950 | * Tear down the driver info (all asics). |
| 1951 | * Called at driver shutdown. |
| 1952 | */ |
| 1953 | void amdgpu_device_fini(struct amdgpu_device *adev) |
| 1954 | { |
| 1955 | int r; |
| 1956 | |
| 1957 | DRM_INFO("amdgpu: finishing device.\n"); |
| 1958 | adev->shutdown = true; |
Grazvydas Ignotas | a951ed8 | 2016-09-25 23:34:48 +0300 | [diff] [blame] | 1959 | drm_crtc_force_disable_all(adev->ddev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1960 | /* evict vram memory */ |
| 1961 | amdgpu_bo_evict_vram(adev); |
| 1962 | amdgpu_ib_pool_fini(adev); |
| 1963 | amdgpu_fence_driver_fini(adev); |
| 1964 | amdgpu_fbdev_fini(adev); |
| 1965 | r = amdgpu_fini(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1966 | adev->accel_working = false; |
| 1967 | /* free i2c buses */ |
| 1968 | amdgpu_i2c_fini(adev); |
| 1969 | amdgpu_atombios_fini(adev); |
| 1970 | kfree(adev->bios); |
| 1971 | adev->bios = NULL; |
| 1972 | vga_switcheroo_unregister_client(adev->pdev); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1973 | if (adev->flags & AMD_IS_PX) |
| 1974 | vga_switcheroo_fini_domain_pm_ops(adev->dev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1975 | vga_client_register(adev->pdev, NULL, NULL, NULL); |
| 1976 | if (adev->rio_mem) |
| 1977 | pci_iounmap(adev->pdev, adev->rio_mem); |
| 1978 | adev->rio_mem = NULL; |
| 1979 | iounmap(adev->rmmio); |
| 1980 | adev->rmmio = NULL; |
Ken Wang | da69c161 | 2016-01-21 19:08:55 +0800 | [diff] [blame] | 1981 | if (adev->asic_type >= CHIP_BONAIRE) |
| 1982 | amdgpu_doorbell_fini(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1983 | amdgpu_debugfs_regs_cleanup(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | |
| 1987 | /* |
| 1988 | * Suspend & resume. |
| 1989 | */ |
| 1990 | /** |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 1991 | * amdgpu_device_suspend - initiate device suspend |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1992 | * |
| 1993 | * @pdev: drm dev pointer |
| 1994 | * @state: suspend state |
| 1995 | * |
| 1996 | * Puts the hw in the suspend state (all asics). |
| 1997 | * Returns 0 for success or an error on failure. |
| 1998 | * Called at driver suspend. |
| 1999 | */ |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 2000 | int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2001 | { |
| 2002 | struct amdgpu_device *adev; |
| 2003 | struct drm_crtc *crtc; |
| 2004 | struct drm_connector *connector; |
Alex Deucher | 5ceb54c | 2015-08-05 12:41:48 -0400 | [diff] [blame] | 2005 | int r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2006 | |
| 2007 | if (dev == NULL || dev->dev_private == NULL) { |
| 2008 | return -ENODEV; |
| 2009 | } |
| 2010 | |
| 2011 | adev = dev->dev_private; |
| 2012 | |
| 2013 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
| 2014 | return 0; |
| 2015 | |
| 2016 | drm_kms_helper_poll_disable(dev); |
| 2017 | |
| 2018 | /* turn off display hw */ |
Alex Deucher | 4c7fbc3 | 2015-09-23 14:32:06 -0400 | [diff] [blame] | 2019 | drm_modeset_lock_all(dev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2020 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 2021 | drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF); |
| 2022 | } |
Alex Deucher | 4c7fbc3 | 2015-09-23 14:32:06 -0400 | [diff] [blame] | 2023 | drm_modeset_unlock_all(dev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2024 | |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2025 | /* unpin the front buffers and cursors */ |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2026 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2027 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2028 | struct amdgpu_framebuffer *rfb = to_amdgpu_framebuffer(crtc->primary->fb); |
| 2029 | struct amdgpu_bo *robj; |
| 2030 | |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2031 | if (amdgpu_crtc->cursor_bo) { |
| 2032 | struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo); |
| 2033 | r = amdgpu_bo_reserve(aobj, false); |
| 2034 | if (r == 0) { |
| 2035 | amdgpu_bo_unpin(aobj); |
| 2036 | amdgpu_bo_unreserve(aobj); |
| 2037 | } |
| 2038 | } |
| 2039 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2040 | if (rfb == NULL || rfb->obj == NULL) { |
| 2041 | continue; |
| 2042 | } |
| 2043 | robj = gem_to_amdgpu_bo(rfb->obj); |
| 2044 | /* don't unpin kernel fb objects */ |
| 2045 | if (!amdgpu_fbdev_robj_is_fb(adev, robj)) { |
| 2046 | r = amdgpu_bo_reserve(robj, false); |
| 2047 | if (r == 0) { |
| 2048 | amdgpu_bo_unpin(robj); |
| 2049 | amdgpu_bo_unreserve(robj); |
| 2050 | } |
| 2051 | } |
| 2052 | } |
| 2053 | /* evict vram memory */ |
| 2054 | amdgpu_bo_evict_vram(adev); |
| 2055 | |
Alex Deucher | 5ceb54c | 2015-08-05 12:41:48 -0400 | [diff] [blame] | 2056 | amdgpu_fence_driver_suspend(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2057 | |
| 2058 | r = amdgpu_suspend(adev); |
| 2059 | |
Alex Deucher | a0a71e4 | 2016-10-10 12:41:36 -0400 | [diff] [blame] | 2060 | /* evict remaining vram memory |
| 2061 | * This second call to evict vram is to evict the gart page table |
| 2062 | * using the CPU. |
| 2063 | */ |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2064 | amdgpu_bo_evict_vram(adev); |
| 2065 | |
Alex Deucher | e695e77 | 2016-10-19 14:40:58 -0400 | [diff] [blame] | 2066 | amdgpu_atombios_scratch_regs_save(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2067 | pci_save_state(dev->pdev); |
| 2068 | if (suspend) { |
| 2069 | /* Shut down the device */ |
| 2070 | pci_disable_device(dev->pdev); |
| 2071 | pci_set_power_state(dev->pdev, PCI_D3hot); |
jimqu | 74b0b15 | 2016-09-07 17:09:12 +0800 | [diff] [blame] | 2072 | } else { |
| 2073 | r = amdgpu_asic_reset(adev); |
| 2074 | if (r) |
| 2075 | DRM_ERROR("amdgpu asic reset failed\n"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | if (fbcon) { |
| 2079 | console_lock(); |
| 2080 | amdgpu_fbdev_set_suspend(adev, 1); |
| 2081 | console_unlock(); |
| 2082 | } |
| 2083 | return 0; |
| 2084 | } |
| 2085 | |
| 2086 | /** |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 2087 | * amdgpu_device_resume - initiate device resume |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2088 | * |
| 2089 | * @pdev: drm dev pointer |
| 2090 | * |
| 2091 | * Bring the hw back to operating state (all asics). |
| 2092 | * Returns 0 for success or an error on failure. |
| 2093 | * Called at driver resume. |
| 2094 | */ |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 2095 | int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2096 | { |
| 2097 | struct drm_connector *connector; |
| 2098 | struct amdgpu_device *adev = dev->dev_private; |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2099 | struct drm_crtc *crtc; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2100 | int r; |
| 2101 | |
| 2102 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
| 2103 | return 0; |
| 2104 | |
jimqu | 74b0b15 | 2016-09-07 17:09:12 +0800 | [diff] [blame] | 2105 | if (fbcon) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2106 | console_lock(); |
jimqu | 74b0b15 | 2016-09-07 17:09:12 +0800 | [diff] [blame] | 2107 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2108 | if (resume) { |
| 2109 | pci_set_power_state(dev->pdev, PCI_D0); |
| 2110 | pci_restore_state(dev->pdev); |
jimqu | 74b0b15 | 2016-09-07 17:09:12 +0800 | [diff] [blame] | 2111 | r = pci_enable_device(dev->pdev); |
| 2112 | if (r) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2113 | if (fbcon) |
| 2114 | console_unlock(); |
jimqu | 74b0b15 | 2016-09-07 17:09:12 +0800 | [diff] [blame] | 2115 | return r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2116 | } |
| 2117 | } |
Alex Deucher | e695e77 | 2016-10-19 14:40:58 -0400 | [diff] [blame] | 2118 | amdgpu_atombios_scratch_regs_restore(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2119 | |
| 2120 | /* post card */ |
Jim Qu | c836fec | 2017-02-10 15:59:59 +0800 | [diff] [blame] | 2121 | if (amdgpu_need_post(adev)) { |
jimqu | 74b0b15 | 2016-09-07 17:09:12 +0800 | [diff] [blame] | 2122 | r = amdgpu_atom_asic_init(adev->mode_info.atom_context); |
| 2123 | if (r) |
| 2124 | DRM_ERROR("amdgpu asic init failed\n"); |
| 2125 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2126 | |
| 2127 | r = amdgpu_resume(adev); |
Flora Cui | ca19852 | 2016-02-04 15:10:08 +0800 | [diff] [blame] | 2128 | if (r) |
| 2129 | DRM_ERROR("amdgpu_resume failed (%d).\n", r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2130 | |
Alex Deucher | 5ceb54c | 2015-08-05 12:41:48 -0400 | [diff] [blame] | 2131 | amdgpu_fence_driver_resume(adev); |
| 2132 | |
Flora Cui | ca19852 | 2016-02-04 15:10:08 +0800 | [diff] [blame] | 2133 | if (resume) { |
| 2134 | r = amdgpu_ib_ring_tests(adev); |
| 2135 | if (r) |
| 2136 | DRM_ERROR("ib ring test failed (%d).\n", r); |
| 2137 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2138 | |
| 2139 | r = amdgpu_late_init(adev); |
Jim Qu | c085bd5 | 2017-03-01 15:53:29 +0800 | [diff] [blame] | 2140 | if (r) { |
| 2141 | if (fbcon) |
| 2142 | console_unlock(); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2143 | return r; |
Jim Qu | c085bd5 | 2017-03-01 15:53:29 +0800 | [diff] [blame] | 2144 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2145 | |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2146 | /* pin cursors */ |
| 2147 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 2148 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 2149 | |
| 2150 | if (amdgpu_crtc->cursor_bo) { |
| 2151 | struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo); |
| 2152 | r = amdgpu_bo_reserve(aobj, false); |
| 2153 | if (r == 0) { |
| 2154 | r = amdgpu_bo_pin(aobj, |
| 2155 | AMDGPU_GEM_DOMAIN_VRAM, |
| 2156 | &amdgpu_crtc->cursor_addr); |
| 2157 | if (r != 0) |
| 2158 | DRM_ERROR("Failed to pin cursor BO (%d)\n", r); |
| 2159 | amdgpu_bo_unreserve(aobj); |
| 2160 | } |
| 2161 | } |
| 2162 | } |
| 2163 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2164 | /* blat the mode back in */ |
| 2165 | if (fbcon) { |
| 2166 | drm_helper_resume_force_mode(dev); |
| 2167 | /* turn on display hw */ |
Alex Deucher | 4c7fbc3 | 2015-09-23 14:32:06 -0400 | [diff] [blame] | 2168 | drm_modeset_lock_all(dev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2169 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 2170 | drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON); |
| 2171 | } |
Alex Deucher | 4c7fbc3 | 2015-09-23 14:32:06 -0400 | [diff] [blame] | 2172 | drm_modeset_unlock_all(dev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | drm_kms_helper_poll_enable(dev); |
Lyude | 23a1a9e | 2016-07-18 11:41:37 -0400 | [diff] [blame] | 2176 | |
| 2177 | /* |
| 2178 | * Most of the connector probing functions try to acquire runtime pm |
| 2179 | * refs to ensure that the GPU is powered on when connector polling is |
| 2180 | * performed. Since we're calling this from a runtime PM callback, |
| 2181 | * trying to acquire rpm refs will cause us to deadlock. |
| 2182 | * |
| 2183 | * Since we're guaranteed to be holding the rpm lock, it's safe to |
| 2184 | * temporarily disable the rpm helpers so this doesn't deadlock us. |
| 2185 | */ |
| 2186 | #ifdef CONFIG_PM |
| 2187 | dev->dev->power.disable_depth++; |
| 2188 | #endif |
Alex Deucher | 54fb2a5 | 2015-11-24 14:30:56 -0500 | [diff] [blame] | 2189 | drm_helper_hpd_irq_event(dev); |
Lyude | 23a1a9e | 2016-07-18 11:41:37 -0400 | [diff] [blame] | 2190 | #ifdef CONFIG_PM |
| 2191 | dev->dev->power.disable_depth--; |
| 2192 | #endif |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2193 | |
| 2194 | if (fbcon) { |
| 2195 | amdgpu_fbdev_set_suspend(adev, 0); |
| 2196 | console_unlock(); |
| 2197 | } |
| 2198 | |
| 2199 | return 0; |
| 2200 | } |
| 2201 | |
Chunming Zhou | 63fbf42 | 2016-07-15 11:19:20 +0800 | [diff] [blame] | 2202 | static bool amdgpu_check_soft_reset(struct amdgpu_device *adev) |
| 2203 | { |
| 2204 | int i; |
| 2205 | bool asic_hang = false; |
| 2206 | |
| 2207 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2208 | if (!adev->ip_blocks[i].status.valid) |
Chunming Zhou | 63fbf42 | 2016-07-15 11:19:20 +0800 | [diff] [blame] | 2209 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2210 | if (adev->ip_blocks[i].version->funcs->check_soft_reset) |
| 2211 | adev->ip_blocks[i].status.hang = |
| 2212 | adev->ip_blocks[i].version->funcs->check_soft_reset(adev); |
| 2213 | if (adev->ip_blocks[i].status.hang) { |
| 2214 | DRM_INFO("IP block:%s is hung!\n", adev->ip_blocks[i].version->funcs->name); |
Chunming Zhou | 63fbf42 | 2016-07-15 11:19:20 +0800 | [diff] [blame] | 2215 | asic_hang = true; |
| 2216 | } |
| 2217 | } |
| 2218 | return asic_hang; |
| 2219 | } |
| 2220 | |
Baoyou Xie | 4d44665 | 2016-09-18 22:09:35 +0800 | [diff] [blame] | 2221 | static int amdgpu_pre_soft_reset(struct amdgpu_device *adev) |
Chunming Zhou | d31a501 | 2016-07-18 10:04:34 +0800 | [diff] [blame] | 2222 | { |
| 2223 | int i, r = 0; |
| 2224 | |
| 2225 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2226 | if (!adev->ip_blocks[i].status.valid) |
Chunming Zhou | d31a501 | 2016-07-18 10:04:34 +0800 | [diff] [blame] | 2227 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2228 | if (adev->ip_blocks[i].status.hang && |
| 2229 | adev->ip_blocks[i].version->funcs->pre_soft_reset) { |
| 2230 | r = adev->ip_blocks[i].version->funcs->pre_soft_reset(adev); |
Chunming Zhou | d31a501 | 2016-07-18 10:04:34 +0800 | [diff] [blame] | 2231 | if (r) |
| 2232 | return r; |
| 2233 | } |
| 2234 | } |
| 2235 | |
| 2236 | return 0; |
| 2237 | } |
| 2238 | |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2239 | static bool amdgpu_need_full_reset(struct amdgpu_device *adev) |
| 2240 | { |
Alex Deucher | da146d3 | 2016-10-13 16:07:03 -0400 | [diff] [blame] | 2241 | int i; |
| 2242 | |
| 2243 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2244 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | da146d3 | 2016-10-13 16:07:03 -0400 | [diff] [blame] | 2245 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2246 | if ((adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) || |
| 2247 | (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) || |
| 2248 | (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_ACP) || |
| 2249 | (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_DCE)) { |
| 2250 | if (adev->ip_blocks[i].status.hang) { |
Alex Deucher | da146d3 | 2016-10-13 16:07:03 -0400 | [diff] [blame] | 2251 | DRM_INFO("Some block need full reset!\n"); |
| 2252 | return true; |
| 2253 | } |
| 2254 | } |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2255 | } |
| 2256 | return false; |
| 2257 | } |
| 2258 | |
| 2259 | static int amdgpu_soft_reset(struct amdgpu_device *adev) |
| 2260 | { |
| 2261 | int i, r = 0; |
| 2262 | |
| 2263 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2264 | if (!adev->ip_blocks[i].status.valid) |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2265 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2266 | if (adev->ip_blocks[i].status.hang && |
| 2267 | adev->ip_blocks[i].version->funcs->soft_reset) { |
| 2268 | r = adev->ip_blocks[i].version->funcs->soft_reset(adev); |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2269 | if (r) |
| 2270 | return r; |
| 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | return 0; |
| 2275 | } |
| 2276 | |
| 2277 | static int amdgpu_post_soft_reset(struct amdgpu_device *adev) |
| 2278 | { |
| 2279 | int i, r = 0; |
| 2280 | |
| 2281 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2282 | if (!adev->ip_blocks[i].status.valid) |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2283 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2284 | if (adev->ip_blocks[i].status.hang && |
| 2285 | adev->ip_blocks[i].version->funcs->post_soft_reset) |
| 2286 | r = adev->ip_blocks[i].version->funcs->post_soft_reset(adev); |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2287 | if (r) |
| 2288 | return r; |
| 2289 | } |
| 2290 | |
| 2291 | return 0; |
| 2292 | } |
| 2293 | |
Chunming Zhou | 3ad81f1 | 2016-08-05 17:30:17 +0800 | [diff] [blame] | 2294 | bool amdgpu_need_backup(struct amdgpu_device *adev) |
| 2295 | { |
| 2296 | if (adev->flags & AMD_IS_APU) |
| 2297 | return false; |
| 2298 | |
| 2299 | return amdgpu_lockup_timeout > 0 ? true : false; |
| 2300 | } |
| 2301 | |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2302 | static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev, |
| 2303 | struct amdgpu_ring *ring, |
| 2304 | struct amdgpu_bo *bo, |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 2305 | struct dma_fence **fence) |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2306 | { |
| 2307 | uint32_t domain; |
| 2308 | int r; |
| 2309 | |
| 2310 | if (!bo->shadow) |
| 2311 | return 0; |
| 2312 | |
| 2313 | r = amdgpu_bo_reserve(bo, false); |
| 2314 | if (r) |
| 2315 | return r; |
| 2316 | domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type); |
| 2317 | /* if bo has been evicted, then no need to recover */ |
| 2318 | if (domain == AMDGPU_GEM_DOMAIN_VRAM) { |
| 2319 | r = amdgpu_bo_restore_from_shadow(adev, ring, bo, |
| 2320 | NULL, fence, true); |
| 2321 | if (r) { |
| 2322 | DRM_ERROR("recover page table failed!\n"); |
| 2323 | goto err; |
| 2324 | } |
| 2325 | } |
| 2326 | err: |
| 2327 | amdgpu_bo_unreserve(bo); |
| 2328 | return r; |
| 2329 | } |
| 2330 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2331 | /** |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 2332 | * amdgpu_sriov_gpu_reset - reset the asic |
| 2333 | * |
| 2334 | * @adev: amdgpu device pointer |
| 2335 | * @voluntary: if this reset is requested by guest. |
| 2336 | * (true means by guest and false means by HYPERVISOR ) |
| 2337 | * |
| 2338 | * Attempt the reset the GPU if it has hung (all asics). |
| 2339 | * for SRIOV case. |
| 2340 | * Returns 0 for success or an error on failure. |
| 2341 | */ |
| 2342 | int amdgpu_sriov_gpu_reset(struct amdgpu_device *adev, bool voluntary) |
| 2343 | { |
| 2344 | int i, r = 0; |
| 2345 | int resched; |
| 2346 | struct amdgpu_bo *bo, *tmp; |
| 2347 | struct amdgpu_ring *ring; |
| 2348 | struct dma_fence *fence = NULL, *next = NULL; |
| 2349 | |
Monk Liu | 147b598 | 2017-01-25 15:48:01 +0800 | [diff] [blame] | 2350 | mutex_lock(&adev->virt.lock_reset); |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 2351 | atomic_inc(&adev->gpu_reset_counter); |
| 2352 | |
| 2353 | /* block TTM */ |
| 2354 | resched = ttm_bo_lock_delayed_workqueue(&adev->mman.bdev); |
| 2355 | |
| 2356 | /* block scheduler */ |
| 2357 | for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { |
| 2358 | ring = adev->rings[i]; |
| 2359 | |
| 2360 | if (!ring || !ring->sched.thread) |
| 2361 | continue; |
| 2362 | |
| 2363 | kthread_park(ring->sched.thread); |
| 2364 | amd_sched_hw_job_reset(&ring->sched); |
| 2365 | } |
| 2366 | |
| 2367 | /* after all hw jobs are reset, hw fence is meaningless, so force_completion */ |
| 2368 | amdgpu_fence_driver_force_completion(adev); |
| 2369 | |
| 2370 | /* request to take full control of GPU before re-initialization */ |
| 2371 | if (voluntary) |
| 2372 | amdgpu_virt_reset_gpu(adev); |
| 2373 | else |
| 2374 | amdgpu_virt_request_full_gpu(adev, true); |
| 2375 | |
| 2376 | |
| 2377 | /* Resume IP prior to SMC */ |
Monk Liu | e4f0fdc | 2017-02-09 11:55:49 +0800 | [diff] [blame^] | 2378 | amdgpu_sriov_reinit_early(adev); |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 2379 | |
| 2380 | /* we need recover gart prior to run SMC/CP/SDMA resume */ |
| 2381 | amdgpu_ttm_recover_gart(adev); |
| 2382 | |
| 2383 | /* now we are okay to resume SMC/CP/SDMA */ |
Monk Liu | e4f0fdc | 2017-02-09 11:55:49 +0800 | [diff] [blame^] | 2384 | amdgpu_sriov_reinit_late(adev); |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 2385 | |
| 2386 | amdgpu_irq_gpu_reset_resume_helper(adev); |
| 2387 | |
| 2388 | if (amdgpu_ib_ring_tests(adev)) |
| 2389 | dev_err(adev->dev, "[GPU_RESET] ib ring test failed (%d).\n", r); |
| 2390 | |
| 2391 | /* release full control of GPU after ib test */ |
| 2392 | amdgpu_virt_release_full_gpu(adev, true); |
| 2393 | |
| 2394 | DRM_INFO("recover vram bo from shadow\n"); |
| 2395 | |
| 2396 | ring = adev->mman.buffer_funcs_ring; |
| 2397 | mutex_lock(&adev->shadow_list_lock); |
| 2398 | list_for_each_entry_safe(bo, tmp, &adev->shadow_list, shadow_list) { |
| 2399 | amdgpu_recover_vram_from_shadow(adev, ring, bo, &next); |
| 2400 | if (fence) { |
| 2401 | r = dma_fence_wait(fence, false); |
| 2402 | if (r) { |
| 2403 | WARN(r, "recovery from shadow isn't completed\n"); |
| 2404 | break; |
| 2405 | } |
| 2406 | } |
| 2407 | |
| 2408 | dma_fence_put(fence); |
| 2409 | fence = next; |
| 2410 | } |
| 2411 | mutex_unlock(&adev->shadow_list_lock); |
| 2412 | |
| 2413 | if (fence) { |
| 2414 | r = dma_fence_wait(fence, false); |
| 2415 | if (r) |
| 2416 | WARN(r, "recovery from shadow isn't completed\n"); |
| 2417 | } |
| 2418 | dma_fence_put(fence); |
| 2419 | |
| 2420 | for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { |
| 2421 | struct amdgpu_ring *ring = adev->rings[i]; |
| 2422 | if (!ring || !ring->sched.thread) |
| 2423 | continue; |
| 2424 | |
| 2425 | amd_sched_job_recovery(&ring->sched); |
| 2426 | kthread_unpark(ring->sched.thread); |
| 2427 | } |
| 2428 | |
| 2429 | drm_helper_resume_force_mode(adev->ddev); |
| 2430 | ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched); |
| 2431 | if (r) { |
| 2432 | /* bad news, how to tell it to userspace ? */ |
| 2433 | dev_info(adev->dev, "GPU reset failed\n"); |
| 2434 | } |
| 2435 | |
Monk Liu | 147b598 | 2017-01-25 15:48:01 +0800 | [diff] [blame] | 2436 | mutex_unlock(&adev->virt.lock_reset); |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 2437 | return r; |
| 2438 | } |
| 2439 | |
| 2440 | /** |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2441 | * amdgpu_gpu_reset - reset the asic |
| 2442 | * |
| 2443 | * @adev: amdgpu device pointer |
| 2444 | * |
| 2445 | * Attempt the reset the GPU if it has hung (all asics). |
| 2446 | * Returns 0 for success or an error on failure. |
| 2447 | */ |
| 2448 | int amdgpu_gpu_reset(struct amdgpu_device *adev) |
| 2449 | { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2450 | int i, r; |
| 2451 | int resched; |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2452 | bool need_full_reset; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2453 | |
Xiangliang Yu | fb140b2 | 2016-12-17 22:48:57 +0800 | [diff] [blame] | 2454 | if (amdgpu_sriov_vf(adev)) |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 2455 | return amdgpu_sriov_gpu_reset(adev, true); |
Xiangliang Yu | fb140b2 | 2016-12-17 22:48:57 +0800 | [diff] [blame] | 2456 | |
Chunming Zhou | 63fbf42 | 2016-07-15 11:19:20 +0800 | [diff] [blame] | 2457 | if (!amdgpu_check_soft_reset(adev)) { |
| 2458 | DRM_INFO("No hardware hang detected. Did some blocks stall?\n"); |
| 2459 | return 0; |
| 2460 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2461 | |
Marek Olšák | d94aed5 | 2015-05-05 21:13:49 +0200 | [diff] [blame] | 2462 | atomic_inc(&adev->gpu_reset_counter); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2463 | |
Chunming Zhou | a3c47d6 | 2016-06-30 16:44:41 +0800 | [diff] [blame] | 2464 | /* block TTM */ |
| 2465 | resched = ttm_bo_lock_delayed_workqueue(&adev->mman.bdev); |
| 2466 | |
Chunming Zhou | 0875dc9 | 2016-06-12 15:41:58 +0800 | [diff] [blame] | 2467 | /* block scheduler */ |
| 2468 | for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { |
| 2469 | struct amdgpu_ring *ring = adev->rings[i]; |
| 2470 | |
| 2471 | if (!ring) |
| 2472 | continue; |
| 2473 | kthread_park(ring->sched.thread); |
Chunming Zhou | aa1c890 | 2016-06-30 13:56:02 +0800 | [diff] [blame] | 2474 | amd_sched_hw_job_reset(&ring->sched); |
Chunming Zhou | 0875dc9 | 2016-06-12 15:41:58 +0800 | [diff] [blame] | 2475 | } |
Chunming Zhou | 2200eda | 2016-06-30 16:53:02 +0800 | [diff] [blame] | 2476 | /* after all hw jobs are reset, hw fence is meaningless, so force_completion */ |
| 2477 | amdgpu_fence_driver_force_completion(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2478 | |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2479 | need_full_reset = amdgpu_need_full_reset(adev); |
| 2480 | |
| 2481 | if (!need_full_reset) { |
| 2482 | amdgpu_pre_soft_reset(adev); |
| 2483 | r = amdgpu_soft_reset(adev); |
| 2484 | amdgpu_post_soft_reset(adev); |
| 2485 | if (r || amdgpu_check_soft_reset(adev)) { |
| 2486 | DRM_INFO("soft reset failed, will fallback to full reset!\n"); |
| 2487 | need_full_reset = true; |
| 2488 | } |
| 2489 | } |
| 2490 | |
| 2491 | if (need_full_reset) { |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2492 | r = amdgpu_suspend(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2493 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2494 | retry: |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2495 | /* Disable fb access */ |
| 2496 | if (adev->mode_info.num_crtc) { |
| 2497 | struct amdgpu_mode_mc_save save; |
| 2498 | amdgpu_display_stop_mc_access(adev, &save); |
| 2499 | amdgpu_wait_for_idle(adev, AMD_IP_BLOCK_TYPE_GMC); |
| 2500 | } |
Alex Deucher | e695e77 | 2016-10-19 14:40:58 -0400 | [diff] [blame] | 2501 | amdgpu_atombios_scratch_regs_save(adev); |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2502 | r = amdgpu_asic_reset(adev); |
Alex Deucher | e695e77 | 2016-10-19 14:40:58 -0400 | [diff] [blame] | 2503 | amdgpu_atombios_scratch_regs_restore(adev); |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2504 | /* post card */ |
| 2505 | amdgpu_atom_asic_init(adev->mode_info.atom_context); |
Alex Deucher | bfa9926 | 2016-01-15 11:59:48 -0500 | [diff] [blame] | 2506 | |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2507 | if (!r) { |
| 2508 | dev_info(adev->dev, "GPU reset succeeded, trying to resume\n"); |
| 2509 | r = amdgpu_resume(adev); |
| 2510 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2511 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2512 | if (!r) { |
Chunming Zhou | e72cfd5 | 2016-07-27 13:15:20 +0800 | [diff] [blame] | 2513 | amdgpu_irq_gpu_reset_resume_helper(adev); |
Chunming Zhou | 2c0d731 | 2016-08-30 16:36:25 +0800 | [diff] [blame] | 2514 | if (need_full_reset && amdgpu_need_backup(adev)) { |
| 2515 | r = amdgpu_ttm_recover_gart(adev); |
| 2516 | if (r) |
| 2517 | DRM_ERROR("gart recovery failed!!!\n"); |
| 2518 | } |
Chunming Zhou | 1f46508 | 2016-06-30 15:02:26 +0800 | [diff] [blame] | 2519 | r = amdgpu_ib_ring_tests(adev); |
| 2520 | if (r) { |
| 2521 | dev_err(adev->dev, "ib ring test failed (%d).\n", r); |
Chunming Zhou | 40019dc | 2016-06-29 16:01:49 +0800 | [diff] [blame] | 2522 | r = amdgpu_suspend(adev); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2523 | need_full_reset = true; |
Chunming Zhou | 40019dc | 2016-06-29 16:01:49 +0800 | [diff] [blame] | 2524 | goto retry; |
Chunming Zhou | 1f46508 | 2016-06-30 15:02:26 +0800 | [diff] [blame] | 2525 | } |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2526 | /** |
| 2527 | * recovery vm page tables, since we cannot depend on VRAM is |
| 2528 | * consistent after gpu full reset. |
| 2529 | */ |
| 2530 | if (need_full_reset && amdgpu_need_backup(adev)) { |
| 2531 | struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring; |
| 2532 | struct amdgpu_bo *bo, *tmp; |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 2533 | struct dma_fence *fence = NULL, *next = NULL; |
Chunming Zhou | 1f46508 | 2016-06-30 15:02:26 +0800 | [diff] [blame] | 2534 | |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2535 | DRM_INFO("recover vram bo from shadow\n"); |
| 2536 | mutex_lock(&adev->shadow_list_lock); |
| 2537 | list_for_each_entry_safe(bo, tmp, &adev->shadow_list, shadow_list) { |
| 2538 | amdgpu_recover_vram_from_shadow(adev, ring, bo, &next); |
| 2539 | if (fence) { |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 2540 | r = dma_fence_wait(fence, false); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2541 | if (r) { |
Monk Liu | 1d7b17b | 2017-01-22 18:52:56 +0800 | [diff] [blame] | 2542 | WARN(r, "recovery from shadow isn't completed\n"); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2543 | break; |
| 2544 | } |
| 2545 | } |
| 2546 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 2547 | dma_fence_put(fence); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2548 | fence = next; |
| 2549 | } |
| 2550 | mutex_unlock(&adev->shadow_list_lock); |
| 2551 | if (fence) { |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 2552 | r = dma_fence_wait(fence, false); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2553 | if (r) |
Monk Liu | 1d7b17b | 2017-01-22 18:52:56 +0800 | [diff] [blame] | 2554 | WARN(r, "recovery from shadow isn't completed\n"); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2555 | } |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 2556 | dma_fence_put(fence); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2557 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2558 | for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { |
| 2559 | struct amdgpu_ring *ring = adev->rings[i]; |
| 2560 | if (!ring) |
| 2561 | continue; |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2562 | |
Chunming Zhou | aa1c890 | 2016-06-30 13:56:02 +0800 | [diff] [blame] | 2563 | amd_sched_job_recovery(&ring->sched); |
Chunming Zhou | 0875dc9 | 2016-06-12 15:41:58 +0800 | [diff] [blame] | 2564 | kthread_unpark(ring->sched.thread); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2565 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2566 | } else { |
Chunming Zhou | 2200eda | 2016-06-30 16:53:02 +0800 | [diff] [blame] | 2567 | dev_err(adev->dev, "asic resume failed (%d).\n", r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2568 | for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { |
Chunming Zhou | 0875dc9 | 2016-06-12 15:41:58 +0800 | [diff] [blame] | 2569 | if (adev->rings[i]) { |
| 2570 | kthread_unpark(adev->rings[i]->sched.thread); |
Chunming Zhou | 0875dc9 | 2016-06-12 15:41:58 +0800 | [diff] [blame] | 2571 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2572 | } |
| 2573 | } |
| 2574 | |
| 2575 | drm_helper_resume_force_mode(adev->ddev); |
| 2576 | |
| 2577 | ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched); |
| 2578 | if (r) { |
| 2579 | /* bad news, how to tell it to userspace ? */ |
| 2580 | dev_info(adev->dev, "GPU reset failed\n"); |
| 2581 | } |
| 2582 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2583 | return r; |
| 2584 | } |
| 2585 | |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 2586 | void amdgpu_get_pcie_info(struct amdgpu_device *adev) |
| 2587 | { |
| 2588 | u32 mask; |
| 2589 | int ret; |
| 2590 | |
Alex Deucher | cd474ba | 2016-02-04 10:21:23 -0500 | [diff] [blame] | 2591 | if (amdgpu_pcie_gen_cap) |
| 2592 | adev->pm.pcie_gen_mask = amdgpu_pcie_gen_cap; |
| 2593 | |
| 2594 | if (amdgpu_pcie_lane_cap) |
| 2595 | adev->pm.pcie_mlw_mask = amdgpu_pcie_lane_cap; |
| 2596 | |
| 2597 | /* covers APUs as well */ |
| 2598 | if (pci_is_root_bus(adev->pdev->bus)) { |
| 2599 | if (adev->pm.pcie_gen_mask == 0) |
| 2600 | adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK; |
| 2601 | if (adev->pm.pcie_mlw_mask == 0) |
| 2602 | adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK; |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 2603 | return; |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 2604 | } |
Alex Deucher | cd474ba | 2016-02-04 10:21:23 -0500 | [diff] [blame] | 2605 | |
| 2606 | if (adev->pm.pcie_gen_mask == 0) { |
| 2607 | ret = drm_pcie_get_speed_cap_mask(adev->ddev, &mask); |
| 2608 | if (!ret) { |
| 2609 | adev->pm.pcie_gen_mask = (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 | |
| 2610 | CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 | |
| 2611 | CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3); |
| 2612 | |
| 2613 | if (mask & DRM_PCIE_SPEED_25) |
| 2614 | adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1; |
| 2615 | if (mask & DRM_PCIE_SPEED_50) |
| 2616 | adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2; |
| 2617 | if (mask & DRM_PCIE_SPEED_80) |
| 2618 | adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3; |
| 2619 | } else { |
| 2620 | adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK; |
| 2621 | } |
| 2622 | } |
| 2623 | if (adev->pm.pcie_mlw_mask == 0) { |
| 2624 | ret = drm_pcie_get_max_link_width(adev->ddev, &mask); |
| 2625 | if (!ret) { |
| 2626 | switch (mask) { |
| 2627 | case 32: |
| 2628 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 | |
| 2629 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 | |
| 2630 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 | |
| 2631 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 | |
| 2632 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 | |
| 2633 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2634 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2635 | break; |
| 2636 | case 16: |
| 2637 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 | |
| 2638 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 | |
| 2639 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 | |
| 2640 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 | |
| 2641 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2642 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2643 | break; |
| 2644 | case 12: |
| 2645 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 | |
| 2646 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 | |
| 2647 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 | |
| 2648 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2649 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2650 | break; |
| 2651 | case 8: |
| 2652 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 | |
| 2653 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 | |
| 2654 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2655 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2656 | break; |
| 2657 | case 4: |
| 2658 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 | |
| 2659 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2660 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2661 | break; |
| 2662 | case 2: |
| 2663 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2664 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2665 | break; |
| 2666 | case 1: |
| 2667 | adev->pm.pcie_mlw_mask = CAIL_PCIE_LINK_WIDTH_SUPPORT_X1; |
| 2668 | break; |
| 2669 | default: |
| 2670 | break; |
| 2671 | } |
| 2672 | } else { |
| 2673 | adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK; |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 2674 | } |
| 2675 | } |
| 2676 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2677 | |
| 2678 | /* |
| 2679 | * Debugfs |
| 2680 | */ |
| 2681 | int amdgpu_debugfs_add_files(struct amdgpu_device *adev, |
Nils Wallménius | 06ab683 | 2016-05-02 12:46:15 -0400 | [diff] [blame] | 2682 | const struct drm_info_list *files, |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2683 | unsigned nfiles) |
| 2684 | { |
| 2685 | unsigned i; |
| 2686 | |
| 2687 | for (i = 0; i < adev->debugfs_count; i++) { |
| 2688 | if (adev->debugfs[i].files == files) { |
| 2689 | /* Already registered */ |
| 2690 | return 0; |
| 2691 | } |
| 2692 | } |
| 2693 | |
| 2694 | i = adev->debugfs_count + 1; |
| 2695 | if (i > AMDGPU_DEBUGFS_MAX_COMPONENTS) { |
| 2696 | DRM_ERROR("Reached maximum number of debugfs components.\n"); |
| 2697 | DRM_ERROR("Report so we increase " |
| 2698 | "AMDGPU_DEBUGFS_MAX_COMPONENTS.\n"); |
| 2699 | return -EINVAL; |
| 2700 | } |
| 2701 | adev->debugfs[adev->debugfs_count].files = files; |
| 2702 | adev->debugfs[adev->debugfs_count].num_files = nfiles; |
| 2703 | adev->debugfs_count = i; |
| 2704 | #if defined(CONFIG_DEBUG_FS) |
| 2705 | drm_debugfs_create_files(files, nfiles, |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2706 | adev->ddev->primary->debugfs_root, |
| 2707 | adev->ddev->primary); |
| 2708 | #endif |
| 2709 | return 0; |
| 2710 | } |
| 2711 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2712 | #if defined(CONFIG_DEBUG_FS) |
| 2713 | |
| 2714 | static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user *buf, |
| 2715 | size_t size, loff_t *pos) |
| 2716 | { |
Al Viro | 4506309 | 2016-12-04 18:24:56 -0500 | [diff] [blame] | 2717 | struct amdgpu_device *adev = file_inode(f)->i_private; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2718 | ssize_t result = 0; |
| 2719 | int r; |
Tom St Denis | bd12267 | 2016-07-28 09:39:22 -0400 | [diff] [blame] | 2720 | bool pm_pg_lock, use_bank; |
Tom St Denis | 56628159 | 2016-06-27 11:55:07 -0400 | [diff] [blame] | 2721 | unsigned instance_bank, sh_bank, se_bank; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2722 | |
| 2723 | if (size & 0x3 || *pos & 0x3) |
| 2724 | return -EINVAL; |
| 2725 | |
Tom St Denis | bd12267 | 2016-07-28 09:39:22 -0400 | [diff] [blame] | 2726 | /* are we reading registers for which a PG lock is necessary? */ |
| 2727 | pm_pg_lock = (*pos >> 23) & 1; |
| 2728 | |
Tom St Denis | 56628159 | 2016-06-27 11:55:07 -0400 | [diff] [blame] | 2729 | if (*pos & (1ULL << 62)) { |
| 2730 | se_bank = (*pos >> 24) & 0x3FF; |
| 2731 | sh_bank = (*pos >> 34) & 0x3FF; |
| 2732 | instance_bank = (*pos >> 44) & 0x3FF; |
Tom St Denis | 32977f9 | 2016-10-09 07:41:26 -0400 | [diff] [blame] | 2733 | |
| 2734 | if (se_bank == 0x3FF) |
| 2735 | se_bank = 0xFFFFFFFF; |
| 2736 | if (sh_bank == 0x3FF) |
| 2737 | sh_bank = 0xFFFFFFFF; |
| 2738 | if (instance_bank == 0x3FF) |
| 2739 | instance_bank = 0xFFFFFFFF; |
Tom St Denis | 56628159 | 2016-06-27 11:55:07 -0400 | [diff] [blame] | 2740 | use_bank = 1; |
Tom St Denis | 56628159 | 2016-06-27 11:55:07 -0400 | [diff] [blame] | 2741 | } else { |
| 2742 | use_bank = 0; |
| 2743 | } |
| 2744 | |
Tom St Denis | 801a6aa9a6 | 2017-03-15 05:34:25 -0400 | [diff] [blame] | 2745 | *pos &= (1UL << 22) - 1; |
Tom St Denis | bd12267 | 2016-07-28 09:39:22 -0400 | [diff] [blame] | 2746 | |
Tom St Denis | 56628159 | 2016-06-27 11:55:07 -0400 | [diff] [blame] | 2747 | if (use_bank) { |
Tom St Denis | 32977f9 | 2016-10-09 07:41:26 -0400 | [diff] [blame] | 2748 | if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) || |
| 2749 | (se_bank != 0xFFFFFFFF && se_bank >= adev->gfx.config.max_shader_engines)) |
Tom St Denis | 56628159 | 2016-06-27 11:55:07 -0400 | [diff] [blame] | 2750 | return -EINVAL; |
| 2751 | mutex_lock(&adev->grbm_idx_mutex); |
| 2752 | amdgpu_gfx_select_se_sh(adev, se_bank, |
| 2753 | sh_bank, instance_bank); |
| 2754 | } |
| 2755 | |
Tom St Denis | bd12267 | 2016-07-28 09:39:22 -0400 | [diff] [blame] | 2756 | if (pm_pg_lock) |
| 2757 | mutex_lock(&adev->pm.mutex); |
| 2758 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2759 | while (size) { |
| 2760 | uint32_t value; |
| 2761 | |
| 2762 | if (*pos > adev->rmmio_size) |
Tom St Denis | 56628159 | 2016-06-27 11:55:07 -0400 | [diff] [blame] | 2763 | goto end; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2764 | |
| 2765 | value = RREG32(*pos >> 2); |
| 2766 | r = put_user(value, (uint32_t *)buf); |
Tom St Denis | 56628159 | 2016-06-27 11:55:07 -0400 | [diff] [blame] | 2767 | if (r) { |
| 2768 | result = r; |
| 2769 | goto end; |
| 2770 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2771 | |
| 2772 | result += 4; |
| 2773 | buf += 4; |
| 2774 | *pos += 4; |
| 2775 | size -= 4; |
| 2776 | } |
| 2777 | |
Tom St Denis | 56628159 | 2016-06-27 11:55:07 -0400 | [diff] [blame] | 2778 | end: |
| 2779 | if (use_bank) { |
| 2780 | amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff); |
| 2781 | mutex_unlock(&adev->grbm_idx_mutex); |
| 2782 | } |
| 2783 | |
Tom St Denis | bd12267 | 2016-07-28 09:39:22 -0400 | [diff] [blame] | 2784 | if (pm_pg_lock) |
| 2785 | mutex_unlock(&adev->pm.mutex); |
| 2786 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2787 | return result; |
| 2788 | } |
| 2789 | |
| 2790 | static ssize_t amdgpu_debugfs_regs_write(struct file *f, const char __user *buf, |
| 2791 | size_t size, loff_t *pos) |
| 2792 | { |
Al Viro | 4506309 | 2016-12-04 18:24:56 -0500 | [diff] [blame] | 2793 | struct amdgpu_device *adev = file_inode(f)->i_private; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2794 | ssize_t result = 0; |
| 2795 | int r; |
Tom St Denis | 394fdde | 2016-10-10 07:31:23 -0400 | [diff] [blame] | 2796 | bool pm_pg_lock, use_bank; |
| 2797 | unsigned instance_bank, sh_bank, se_bank; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2798 | |
| 2799 | if (size & 0x3 || *pos & 0x3) |
| 2800 | return -EINVAL; |
| 2801 | |
Tom St Denis | 394fdde | 2016-10-10 07:31:23 -0400 | [diff] [blame] | 2802 | /* are we reading registers for which a PG lock is necessary? */ |
| 2803 | pm_pg_lock = (*pos >> 23) & 1; |
| 2804 | |
| 2805 | if (*pos & (1ULL << 62)) { |
| 2806 | se_bank = (*pos >> 24) & 0x3FF; |
| 2807 | sh_bank = (*pos >> 34) & 0x3FF; |
| 2808 | instance_bank = (*pos >> 44) & 0x3FF; |
| 2809 | |
| 2810 | if (se_bank == 0x3FF) |
| 2811 | se_bank = 0xFFFFFFFF; |
| 2812 | if (sh_bank == 0x3FF) |
| 2813 | sh_bank = 0xFFFFFFFF; |
| 2814 | if (instance_bank == 0x3FF) |
| 2815 | instance_bank = 0xFFFFFFFF; |
| 2816 | use_bank = 1; |
| 2817 | } else { |
| 2818 | use_bank = 0; |
| 2819 | } |
| 2820 | |
Tom St Denis | 801a6aa9a6 | 2017-03-15 05:34:25 -0400 | [diff] [blame] | 2821 | *pos &= (1UL << 22) - 1; |
Tom St Denis | 394fdde | 2016-10-10 07:31:23 -0400 | [diff] [blame] | 2822 | |
| 2823 | if (use_bank) { |
| 2824 | if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) || |
| 2825 | (se_bank != 0xFFFFFFFF && se_bank >= adev->gfx.config.max_shader_engines)) |
| 2826 | return -EINVAL; |
| 2827 | mutex_lock(&adev->grbm_idx_mutex); |
| 2828 | amdgpu_gfx_select_se_sh(adev, se_bank, |
| 2829 | sh_bank, instance_bank); |
| 2830 | } |
| 2831 | |
| 2832 | if (pm_pg_lock) |
| 2833 | mutex_lock(&adev->pm.mutex); |
| 2834 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2835 | while (size) { |
| 2836 | uint32_t value; |
| 2837 | |
| 2838 | if (*pos > adev->rmmio_size) |
| 2839 | return result; |
| 2840 | |
| 2841 | r = get_user(value, (uint32_t *)buf); |
| 2842 | if (r) |
| 2843 | return r; |
| 2844 | |
| 2845 | WREG32(*pos >> 2, value); |
| 2846 | |
| 2847 | result += 4; |
| 2848 | buf += 4; |
| 2849 | *pos += 4; |
| 2850 | size -= 4; |
| 2851 | } |
| 2852 | |
Tom St Denis | 394fdde | 2016-10-10 07:31:23 -0400 | [diff] [blame] | 2853 | if (use_bank) { |
| 2854 | amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff); |
| 2855 | mutex_unlock(&adev->grbm_idx_mutex); |
| 2856 | } |
| 2857 | |
| 2858 | if (pm_pg_lock) |
| 2859 | mutex_unlock(&adev->pm.mutex); |
| 2860 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2861 | return result; |
| 2862 | } |
| 2863 | |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 2864 | static ssize_t amdgpu_debugfs_regs_pcie_read(struct file *f, char __user *buf, |
| 2865 | size_t size, loff_t *pos) |
| 2866 | { |
Al Viro | 4506309 | 2016-12-04 18:24:56 -0500 | [diff] [blame] | 2867 | struct amdgpu_device *adev = file_inode(f)->i_private; |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 2868 | ssize_t result = 0; |
| 2869 | int r; |
| 2870 | |
| 2871 | if (size & 0x3 || *pos & 0x3) |
| 2872 | return -EINVAL; |
| 2873 | |
| 2874 | while (size) { |
| 2875 | uint32_t value; |
| 2876 | |
| 2877 | value = RREG32_PCIE(*pos >> 2); |
| 2878 | r = put_user(value, (uint32_t *)buf); |
| 2879 | if (r) |
| 2880 | return r; |
| 2881 | |
| 2882 | result += 4; |
| 2883 | buf += 4; |
| 2884 | *pos += 4; |
| 2885 | size -= 4; |
| 2886 | } |
| 2887 | |
| 2888 | return result; |
| 2889 | } |
| 2890 | |
| 2891 | static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user *buf, |
| 2892 | size_t size, loff_t *pos) |
| 2893 | { |
Al Viro | 4506309 | 2016-12-04 18:24:56 -0500 | [diff] [blame] | 2894 | struct amdgpu_device *adev = file_inode(f)->i_private; |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 2895 | ssize_t result = 0; |
| 2896 | int r; |
| 2897 | |
| 2898 | if (size & 0x3 || *pos & 0x3) |
| 2899 | return -EINVAL; |
| 2900 | |
| 2901 | while (size) { |
| 2902 | uint32_t value; |
| 2903 | |
| 2904 | r = get_user(value, (uint32_t *)buf); |
| 2905 | if (r) |
| 2906 | return r; |
| 2907 | |
| 2908 | WREG32_PCIE(*pos >> 2, value); |
| 2909 | |
| 2910 | result += 4; |
| 2911 | buf += 4; |
| 2912 | *pos += 4; |
| 2913 | size -= 4; |
| 2914 | } |
| 2915 | |
| 2916 | return result; |
| 2917 | } |
| 2918 | |
| 2919 | static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf, |
| 2920 | size_t size, loff_t *pos) |
| 2921 | { |
Al Viro | 4506309 | 2016-12-04 18:24:56 -0500 | [diff] [blame] | 2922 | struct amdgpu_device *adev = file_inode(f)->i_private; |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 2923 | ssize_t result = 0; |
| 2924 | int r; |
| 2925 | |
| 2926 | if (size & 0x3 || *pos & 0x3) |
| 2927 | return -EINVAL; |
| 2928 | |
| 2929 | while (size) { |
| 2930 | uint32_t value; |
| 2931 | |
| 2932 | value = RREG32_DIDT(*pos >> 2); |
| 2933 | r = put_user(value, (uint32_t *)buf); |
| 2934 | if (r) |
| 2935 | return r; |
| 2936 | |
| 2937 | result += 4; |
| 2938 | buf += 4; |
| 2939 | *pos += 4; |
| 2940 | size -= 4; |
| 2941 | } |
| 2942 | |
| 2943 | return result; |
| 2944 | } |
| 2945 | |
| 2946 | static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user *buf, |
| 2947 | size_t size, loff_t *pos) |
| 2948 | { |
Al Viro | 4506309 | 2016-12-04 18:24:56 -0500 | [diff] [blame] | 2949 | struct amdgpu_device *adev = file_inode(f)->i_private; |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 2950 | ssize_t result = 0; |
| 2951 | int r; |
| 2952 | |
| 2953 | if (size & 0x3 || *pos & 0x3) |
| 2954 | return -EINVAL; |
| 2955 | |
| 2956 | while (size) { |
| 2957 | uint32_t value; |
| 2958 | |
| 2959 | r = get_user(value, (uint32_t *)buf); |
| 2960 | if (r) |
| 2961 | return r; |
| 2962 | |
| 2963 | WREG32_DIDT(*pos >> 2, value); |
| 2964 | |
| 2965 | result += 4; |
| 2966 | buf += 4; |
| 2967 | *pos += 4; |
| 2968 | size -= 4; |
| 2969 | } |
| 2970 | |
| 2971 | return result; |
| 2972 | } |
| 2973 | |
| 2974 | static ssize_t amdgpu_debugfs_regs_smc_read(struct file *f, char __user *buf, |
| 2975 | size_t size, loff_t *pos) |
| 2976 | { |
Al Viro | 4506309 | 2016-12-04 18:24:56 -0500 | [diff] [blame] | 2977 | struct amdgpu_device *adev = file_inode(f)->i_private; |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 2978 | ssize_t result = 0; |
| 2979 | int r; |
| 2980 | |
| 2981 | if (size & 0x3 || *pos & 0x3) |
| 2982 | return -EINVAL; |
| 2983 | |
| 2984 | while (size) { |
| 2985 | uint32_t value; |
| 2986 | |
Tom St Denis | 6fc0dea | 2016-08-29 08:39:29 -0400 | [diff] [blame] | 2987 | value = RREG32_SMC(*pos); |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 2988 | r = put_user(value, (uint32_t *)buf); |
| 2989 | if (r) |
| 2990 | return r; |
| 2991 | |
| 2992 | result += 4; |
| 2993 | buf += 4; |
| 2994 | *pos += 4; |
| 2995 | size -= 4; |
| 2996 | } |
| 2997 | |
| 2998 | return result; |
| 2999 | } |
| 3000 | |
| 3001 | static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *buf, |
| 3002 | size_t size, loff_t *pos) |
| 3003 | { |
Al Viro | 4506309 | 2016-12-04 18:24:56 -0500 | [diff] [blame] | 3004 | struct amdgpu_device *adev = file_inode(f)->i_private; |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 3005 | ssize_t result = 0; |
| 3006 | int r; |
| 3007 | |
| 3008 | if (size & 0x3 || *pos & 0x3) |
| 3009 | return -EINVAL; |
| 3010 | |
| 3011 | while (size) { |
| 3012 | uint32_t value; |
| 3013 | |
| 3014 | r = get_user(value, (uint32_t *)buf); |
| 3015 | if (r) |
| 3016 | return r; |
| 3017 | |
Tom St Denis | 6fc0dea | 2016-08-29 08:39:29 -0400 | [diff] [blame] | 3018 | WREG32_SMC(*pos, value); |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 3019 | |
| 3020 | result += 4; |
| 3021 | buf += 4; |
| 3022 | *pos += 4; |
| 3023 | size -= 4; |
| 3024 | } |
| 3025 | |
| 3026 | return result; |
| 3027 | } |
| 3028 | |
Tom St Denis | 1e05141 | 2016-06-27 09:57:18 -0400 | [diff] [blame] | 3029 | static ssize_t amdgpu_debugfs_gca_config_read(struct file *f, char __user *buf, |
| 3030 | size_t size, loff_t *pos) |
| 3031 | { |
Al Viro | 4506309 | 2016-12-04 18:24:56 -0500 | [diff] [blame] | 3032 | struct amdgpu_device *adev = file_inode(f)->i_private; |
Tom St Denis | 1e05141 | 2016-06-27 09:57:18 -0400 | [diff] [blame] | 3033 | ssize_t result = 0; |
| 3034 | int r; |
| 3035 | uint32_t *config, no_regs = 0; |
| 3036 | |
| 3037 | if (size & 0x3 || *pos & 0x3) |
| 3038 | return -EINVAL; |
| 3039 | |
Markus Elfring | ecab766 | 2016-09-18 17:00:52 +0200 | [diff] [blame] | 3040 | config = kmalloc_array(256, sizeof(*config), GFP_KERNEL); |
Tom St Denis | 1e05141 | 2016-06-27 09:57:18 -0400 | [diff] [blame] | 3041 | if (!config) |
| 3042 | return -ENOMEM; |
| 3043 | |
| 3044 | /* version, increment each time something is added */ |
Tom St Denis | 9a99935 | 2017-01-18 13:01:25 -0500 | [diff] [blame] | 3045 | config[no_regs++] = 3; |
Tom St Denis | 1e05141 | 2016-06-27 09:57:18 -0400 | [diff] [blame] | 3046 | config[no_regs++] = adev->gfx.config.max_shader_engines; |
| 3047 | config[no_regs++] = adev->gfx.config.max_tile_pipes; |
| 3048 | config[no_regs++] = adev->gfx.config.max_cu_per_sh; |
| 3049 | config[no_regs++] = adev->gfx.config.max_sh_per_se; |
| 3050 | config[no_regs++] = adev->gfx.config.max_backends_per_se; |
| 3051 | config[no_regs++] = adev->gfx.config.max_texture_channel_caches; |
| 3052 | config[no_regs++] = adev->gfx.config.max_gprs; |
| 3053 | config[no_regs++] = adev->gfx.config.max_gs_threads; |
| 3054 | config[no_regs++] = adev->gfx.config.max_hw_contexts; |
| 3055 | config[no_regs++] = adev->gfx.config.sc_prim_fifo_size_frontend; |
| 3056 | config[no_regs++] = adev->gfx.config.sc_prim_fifo_size_backend; |
| 3057 | config[no_regs++] = adev->gfx.config.sc_hiz_tile_fifo_size; |
| 3058 | config[no_regs++] = adev->gfx.config.sc_earlyz_tile_fifo_size; |
| 3059 | config[no_regs++] = adev->gfx.config.num_tile_pipes; |
| 3060 | config[no_regs++] = adev->gfx.config.backend_enable_mask; |
| 3061 | config[no_regs++] = adev->gfx.config.mem_max_burst_length_bytes; |
| 3062 | config[no_regs++] = adev->gfx.config.mem_row_size_in_kb; |
| 3063 | config[no_regs++] = adev->gfx.config.shader_engine_tile_size; |
| 3064 | config[no_regs++] = adev->gfx.config.num_gpus; |
| 3065 | config[no_regs++] = adev->gfx.config.multi_gpu_tile_size; |
| 3066 | config[no_regs++] = adev->gfx.config.mc_arb_ramcfg; |
| 3067 | config[no_regs++] = adev->gfx.config.gb_addr_config; |
| 3068 | config[no_regs++] = adev->gfx.config.num_rbs; |
| 3069 | |
Tom St Denis | 89a8f30 | 2016-08-12 15:14:31 -0400 | [diff] [blame] | 3070 | /* rev==1 */ |
| 3071 | config[no_regs++] = adev->rev_id; |
| 3072 | config[no_regs++] = adev->pg_flags; |
| 3073 | config[no_regs++] = adev->cg_flags; |
| 3074 | |
Tom St Denis | e9f11dc | 2016-08-17 12:00:51 -0400 | [diff] [blame] | 3075 | /* rev==2 */ |
| 3076 | config[no_regs++] = adev->family; |
| 3077 | config[no_regs++] = adev->external_rev_id; |
| 3078 | |
Tom St Denis | 9a99935 | 2017-01-18 13:01:25 -0500 | [diff] [blame] | 3079 | /* rev==3 */ |
| 3080 | config[no_regs++] = adev->pdev->device; |
| 3081 | config[no_regs++] = adev->pdev->revision; |
| 3082 | config[no_regs++] = adev->pdev->subsystem_device; |
| 3083 | config[no_regs++] = adev->pdev->subsystem_vendor; |
| 3084 | |
Tom St Denis | 1e05141 | 2016-06-27 09:57:18 -0400 | [diff] [blame] | 3085 | while (size && (*pos < no_regs * 4)) { |
| 3086 | uint32_t value; |
| 3087 | |
| 3088 | value = config[*pos >> 2]; |
| 3089 | r = put_user(value, (uint32_t *)buf); |
| 3090 | if (r) { |
| 3091 | kfree(config); |
| 3092 | return r; |
| 3093 | } |
| 3094 | |
| 3095 | result += 4; |
| 3096 | buf += 4; |
| 3097 | *pos += 4; |
| 3098 | size -= 4; |
| 3099 | } |
| 3100 | |
| 3101 | kfree(config); |
| 3102 | return result; |
| 3103 | } |
| 3104 | |
Tom St Denis | f2cdaf2 | 2016-09-15 10:08:44 -0400 | [diff] [blame] | 3105 | static ssize_t amdgpu_debugfs_sensor_read(struct file *f, char __user *buf, |
| 3106 | size_t size, loff_t *pos) |
| 3107 | { |
Al Viro | 4506309 | 2016-12-04 18:24:56 -0500 | [diff] [blame] | 3108 | struct amdgpu_device *adev = file_inode(f)->i_private; |
Tom St Denis | f2cdaf2 | 2016-09-15 10:08:44 -0400 | [diff] [blame] | 3109 | int idx, r; |
| 3110 | int32_t value; |
| 3111 | |
| 3112 | if (size != 4 || *pos & 0x3) |
| 3113 | return -EINVAL; |
| 3114 | |
| 3115 | /* convert offset to sensor number */ |
| 3116 | idx = *pos >> 2; |
| 3117 | |
| 3118 | if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor) |
| 3119 | r = adev->powerplay.pp_funcs->read_sensor(adev->powerplay.pp_handle, idx, &value); |
| 3120 | else |
| 3121 | return -EINVAL; |
| 3122 | |
| 3123 | if (!r) |
| 3124 | r = put_user(value, (int32_t *)buf); |
| 3125 | |
| 3126 | return !r ? 4 : r; |
| 3127 | } |
Tom St Denis | 1e05141 | 2016-06-27 09:57:18 -0400 | [diff] [blame] | 3128 | |
Tom St Denis | 273d7aa | 2016-10-11 14:48:55 -0400 | [diff] [blame] | 3129 | static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf, |
| 3130 | size_t size, loff_t *pos) |
| 3131 | { |
| 3132 | struct amdgpu_device *adev = f->f_inode->i_private; |
| 3133 | int r, x; |
| 3134 | ssize_t result=0; |
Tom St Denis | 472259f | 2016-10-14 09:49:09 -0400 | [diff] [blame] | 3135 | uint32_t offset, se, sh, cu, wave, simd, data[32]; |
Tom St Denis | 273d7aa | 2016-10-11 14:48:55 -0400 | [diff] [blame] | 3136 | |
| 3137 | if (size & 3 || *pos & 3) |
| 3138 | return -EINVAL; |
| 3139 | |
| 3140 | /* decode offset */ |
| 3141 | offset = (*pos & 0x7F); |
| 3142 | se = ((*pos >> 7) & 0xFF); |
| 3143 | sh = ((*pos >> 15) & 0xFF); |
| 3144 | cu = ((*pos >> 23) & 0xFF); |
| 3145 | wave = ((*pos >> 31) & 0xFF); |
| 3146 | simd = ((*pos >> 37) & 0xFF); |
Tom St Denis | 273d7aa | 2016-10-11 14:48:55 -0400 | [diff] [blame] | 3147 | |
| 3148 | /* switch to the specific se/sh/cu */ |
| 3149 | mutex_lock(&adev->grbm_idx_mutex); |
| 3150 | amdgpu_gfx_select_se_sh(adev, se, sh, cu); |
| 3151 | |
| 3152 | x = 0; |
Tom St Denis | 472259f | 2016-10-14 09:49:09 -0400 | [diff] [blame] | 3153 | if (adev->gfx.funcs->read_wave_data) |
| 3154 | adev->gfx.funcs->read_wave_data(adev, simd, wave, data, &x); |
Tom St Denis | 273d7aa | 2016-10-11 14:48:55 -0400 | [diff] [blame] | 3155 | |
| 3156 | amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 3157 | mutex_unlock(&adev->grbm_idx_mutex); |
| 3158 | |
Tom St Denis | 5ecfb3b | 2016-10-13 12:15:03 -0400 | [diff] [blame] | 3159 | if (!x) |
| 3160 | return -EINVAL; |
| 3161 | |
Tom St Denis | 472259f | 2016-10-14 09:49:09 -0400 | [diff] [blame] | 3162 | while (size && (offset < x * 4)) { |
Tom St Denis | 273d7aa | 2016-10-11 14:48:55 -0400 | [diff] [blame] | 3163 | uint32_t value; |
| 3164 | |
Tom St Denis | 472259f | 2016-10-14 09:49:09 -0400 | [diff] [blame] | 3165 | value = data[offset >> 2]; |
Tom St Denis | 273d7aa | 2016-10-11 14:48:55 -0400 | [diff] [blame] | 3166 | r = put_user(value, (uint32_t *)buf); |
| 3167 | if (r) |
| 3168 | return r; |
| 3169 | |
| 3170 | result += 4; |
| 3171 | buf += 4; |
Tom St Denis | 472259f | 2016-10-14 09:49:09 -0400 | [diff] [blame] | 3172 | offset += 4; |
Tom St Denis | 273d7aa | 2016-10-11 14:48:55 -0400 | [diff] [blame] | 3173 | size -= 4; |
| 3174 | } |
| 3175 | |
| 3176 | return result; |
| 3177 | } |
| 3178 | |
Tom St Denis | c5a60ce | 2016-12-05 11:39:19 -0500 | [diff] [blame] | 3179 | static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf, |
| 3180 | size_t size, loff_t *pos) |
| 3181 | { |
| 3182 | struct amdgpu_device *adev = f->f_inode->i_private; |
| 3183 | int r; |
| 3184 | ssize_t result = 0; |
| 3185 | uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data; |
| 3186 | |
| 3187 | if (size & 3 || *pos & 3) |
| 3188 | return -EINVAL; |
| 3189 | |
| 3190 | /* decode offset */ |
| 3191 | offset = (*pos & 0xFFF); /* in dwords */ |
| 3192 | se = ((*pos >> 12) & 0xFF); |
| 3193 | sh = ((*pos >> 20) & 0xFF); |
| 3194 | cu = ((*pos >> 28) & 0xFF); |
| 3195 | wave = ((*pos >> 36) & 0xFF); |
| 3196 | simd = ((*pos >> 44) & 0xFF); |
| 3197 | thread = ((*pos >> 52) & 0xFF); |
| 3198 | bank = ((*pos >> 60) & 1); |
| 3199 | |
| 3200 | data = kmalloc_array(1024, sizeof(*data), GFP_KERNEL); |
| 3201 | if (!data) |
| 3202 | return -ENOMEM; |
| 3203 | |
| 3204 | /* switch to the specific se/sh/cu */ |
| 3205 | mutex_lock(&adev->grbm_idx_mutex); |
| 3206 | amdgpu_gfx_select_se_sh(adev, se, sh, cu); |
| 3207 | |
| 3208 | if (bank == 0) { |
| 3209 | if (adev->gfx.funcs->read_wave_vgprs) |
| 3210 | adev->gfx.funcs->read_wave_vgprs(adev, simd, wave, thread, offset, size>>2, data); |
| 3211 | } else { |
| 3212 | if (adev->gfx.funcs->read_wave_sgprs) |
| 3213 | adev->gfx.funcs->read_wave_sgprs(adev, simd, wave, offset, size>>2, data); |
| 3214 | } |
| 3215 | |
| 3216 | amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF); |
| 3217 | mutex_unlock(&adev->grbm_idx_mutex); |
| 3218 | |
| 3219 | while (size) { |
| 3220 | uint32_t value; |
| 3221 | |
| 3222 | value = data[offset++]; |
| 3223 | r = put_user(value, (uint32_t *)buf); |
| 3224 | if (r) { |
| 3225 | result = r; |
| 3226 | goto err; |
| 3227 | } |
| 3228 | |
| 3229 | result += 4; |
| 3230 | buf += 4; |
| 3231 | size -= 4; |
| 3232 | } |
| 3233 | |
| 3234 | err: |
| 3235 | kfree(data); |
| 3236 | return result; |
| 3237 | } |
| 3238 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 3239 | static const struct file_operations amdgpu_debugfs_regs_fops = { |
| 3240 | .owner = THIS_MODULE, |
| 3241 | .read = amdgpu_debugfs_regs_read, |
| 3242 | .write = amdgpu_debugfs_regs_write, |
| 3243 | .llseek = default_llseek |
| 3244 | }; |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 3245 | static const struct file_operations amdgpu_debugfs_regs_didt_fops = { |
| 3246 | .owner = THIS_MODULE, |
| 3247 | .read = amdgpu_debugfs_regs_didt_read, |
| 3248 | .write = amdgpu_debugfs_regs_didt_write, |
| 3249 | .llseek = default_llseek |
| 3250 | }; |
| 3251 | static const struct file_operations amdgpu_debugfs_regs_pcie_fops = { |
| 3252 | .owner = THIS_MODULE, |
| 3253 | .read = amdgpu_debugfs_regs_pcie_read, |
| 3254 | .write = amdgpu_debugfs_regs_pcie_write, |
| 3255 | .llseek = default_llseek |
| 3256 | }; |
| 3257 | static const struct file_operations amdgpu_debugfs_regs_smc_fops = { |
| 3258 | .owner = THIS_MODULE, |
| 3259 | .read = amdgpu_debugfs_regs_smc_read, |
| 3260 | .write = amdgpu_debugfs_regs_smc_write, |
| 3261 | .llseek = default_llseek |
| 3262 | }; |
| 3263 | |
Tom St Denis | 1e05141 | 2016-06-27 09:57:18 -0400 | [diff] [blame] | 3264 | static const struct file_operations amdgpu_debugfs_gca_config_fops = { |
| 3265 | .owner = THIS_MODULE, |
| 3266 | .read = amdgpu_debugfs_gca_config_read, |
| 3267 | .llseek = default_llseek |
| 3268 | }; |
| 3269 | |
Tom St Denis | f2cdaf2 | 2016-09-15 10:08:44 -0400 | [diff] [blame] | 3270 | static const struct file_operations amdgpu_debugfs_sensors_fops = { |
| 3271 | .owner = THIS_MODULE, |
| 3272 | .read = amdgpu_debugfs_sensor_read, |
| 3273 | .llseek = default_llseek |
| 3274 | }; |
| 3275 | |
Tom St Denis | 273d7aa | 2016-10-11 14:48:55 -0400 | [diff] [blame] | 3276 | static const struct file_operations amdgpu_debugfs_wave_fops = { |
| 3277 | .owner = THIS_MODULE, |
| 3278 | .read = amdgpu_debugfs_wave_read, |
| 3279 | .llseek = default_llseek |
| 3280 | }; |
Tom St Denis | c5a60ce | 2016-12-05 11:39:19 -0500 | [diff] [blame] | 3281 | static const struct file_operations amdgpu_debugfs_gpr_fops = { |
| 3282 | .owner = THIS_MODULE, |
| 3283 | .read = amdgpu_debugfs_gpr_read, |
| 3284 | .llseek = default_llseek |
| 3285 | }; |
Tom St Denis | 273d7aa | 2016-10-11 14:48:55 -0400 | [diff] [blame] | 3286 | |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 3287 | static const struct file_operations *debugfs_regs[] = { |
| 3288 | &amdgpu_debugfs_regs_fops, |
| 3289 | &amdgpu_debugfs_regs_didt_fops, |
| 3290 | &amdgpu_debugfs_regs_pcie_fops, |
| 3291 | &amdgpu_debugfs_regs_smc_fops, |
Tom St Denis | 1e05141 | 2016-06-27 09:57:18 -0400 | [diff] [blame] | 3292 | &amdgpu_debugfs_gca_config_fops, |
Tom St Denis | f2cdaf2 | 2016-09-15 10:08:44 -0400 | [diff] [blame] | 3293 | &amdgpu_debugfs_sensors_fops, |
Tom St Denis | 273d7aa | 2016-10-11 14:48:55 -0400 | [diff] [blame] | 3294 | &amdgpu_debugfs_wave_fops, |
Tom St Denis | c5a60ce | 2016-12-05 11:39:19 -0500 | [diff] [blame] | 3295 | &amdgpu_debugfs_gpr_fops, |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 3296 | }; |
| 3297 | |
| 3298 | static const char *debugfs_regs_names[] = { |
| 3299 | "amdgpu_regs", |
| 3300 | "amdgpu_regs_didt", |
| 3301 | "amdgpu_regs_pcie", |
| 3302 | "amdgpu_regs_smc", |
Tom St Denis | 1e05141 | 2016-06-27 09:57:18 -0400 | [diff] [blame] | 3303 | "amdgpu_gca_config", |
Tom St Denis | f2cdaf2 | 2016-09-15 10:08:44 -0400 | [diff] [blame] | 3304 | "amdgpu_sensors", |
Tom St Denis | 273d7aa | 2016-10-11 14:48:55 -0400 | [diff] [blame] | 3305 | "amdgpu_wave", |
Tom St Denis | c5a60ce | 2016-12-05 11:39:19 -0500 | [diff] [blame] | 3306 | "amdgpu_gpr", |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 3307 | }; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 3308 | |
| 3309 | static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev) |
| 3310 | { |
| 3311 | struct drm_minor *minor = adev->ddev->primary; |
| 3312 | struct dentry *ent, *root = minor->debugfs_root; |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 3313 | unsigned i, j; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 3314 | |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 3315 | for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) { |
| 3316 | ent = debugfs_create_file(debugfs_regs_names[i], |
| 3317 | S_IFREG | S_IRUGO, root, |
| 3318 | adev, debugfs_regs[i]); |
| 3319 | if (IS_ERR(ent)) { |
| 3320 | for (j = 0; j < i; j++) { |
| 3321 | debugfs_remove(adev->debugfs_regs[i]); |
| 3322 | adev->debugfs_regs[i] = NULL; |
| 3323 | } |
| 3324 | return PTR_ERR(ent); |
| 3325 | } |
| 3326 | |
| 3327 | if (!i) |
| 3328 | i_size_write(ent->d_inode, adev->rmmio_size); |
| 3329 | adev->debugfs_regs[i] = ent; |
| 3330 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 3331 | |
| 3332 | return 0; |
| 3333 | } |
| 3334 | |
| 3335 | static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev) |
| 3336 | { |
Tom St Denis | adcec28 | 2016-04-15 13:08:44 -0400 | [diff] [blame] | 3337 | unsigned i; |
| 3338 | |
| 3339 | for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) { |
| 3340 | if (adev->debugfs_regs[i]) { |
| 3341 | debugfs_remove(adev->debugfs_regs[i]); |
| 3342 | adev->debugfs_regs[i] = NULL; |
| 3343 | } |
| 3344 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | int amdgpu_debugfs_init(struct drm_minor *minor) |
| 3348 | { |
| 3349 | return 0; |
| 3350 | } |
Alexander Kuleshov | 7cebc72 | 2015-06-27 13:16:05 +0600 | [diff] [blame] | 3351 | #else |
| 3352 | static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev) |
| 3353 | { |
| 3354 | return 0; |
| 3355 | } |
| 3356 | static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev) { } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 3357 | #endif |