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