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