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> |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 31 | #include <drm/drmP.h> |
| 32 | #include <drm/drm_crtc_helper.h> |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 33 | #include <drm/drm_atomic_helper.h> |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 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> |
Gavin Wan | 8904194 | 2017-06-23 13:55:15 -0400 | [diff] [blame] | 56 | #include "amdgpu_vf_error.h" |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 57 | |
Yong Zhao | ba99770 | 2015-11-09 17:21:45 -0500 | [diff] [blame] | 58 | #include "amdgpu_amdkfd.h" |
Rex Zhu | d2f52ac | 2017-09-22 17:47:27 +0800 | [diff] [blame] | 59 | #include "amdgpu_pm.h" |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 60 | |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 61 | MODULE_FIRMWARE("amdgpu/vega10_gpu_info.bin"); |
Alex Deucher | 2d2e5e7 | 2017-05-09 12:27:35 -0400 | [diff] [blame] | 62 | MODULE_FIRMWARE("amdgpu/raven_gpu_info.bin"); |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 63 | |
Shirish S | 2dc80b0 | 2017-05-25 10:05:25 +0530 | [diff] [blame] | 64 | #define AMDGPU_RESUME_MS 2000 |
| 65 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 66 | static const char *amdgpu_asic_name[] = { |
Ken Wang | da69c161 | 2016-01-21 19:08:55 +0800 | [diff] [blame] | 67 | "TAHITI", |
| 68 | "PITCAIRN", |
| 69 | "VERDE", |
| 70 | "OLAND", |
| 71 | "HAINAN", |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 72 | "BONAIRE", |
| 73 | "KAVERI", |
| 74 | "KABINI", |
| 75 | "HAWAII", |
| 76 | "MULLINS", |
| 77 | "TOPAZ", |
| 78 | "TONGA", |
David Zhang | 48299f9 | 2015-07-08 01:05:16 +0800 | [diff] [blame] | 79 | "FIJI", |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 80 | "CARRIZO", |
Samuel Li | 139f491 | 2015-10-08 14:50:27 -0400 | [diff] [blame] | 81 | "STONEY", |
Flora Cui | 2cc0c0b | 2016-03-14 18:33:29 -0400 | [diff] [blame] | 82 | "POLARIS10", |
| 83 | "POLARIS11", |
Junwei Zhang | c4642a4 | 2016-12-14 15:32:28 -0500 | [diff] [blame] | 84 | "POLARIS12", |
Ken Wang | d4196f0 | 2016-03-09 09:28:32 +0800 | [diff] [blame] | 85 | "VEGA10", |
Chunming Zhou | 2ca8a5d | 2016-12-07 17:31:19 +0800 | [diff] [blame] | 86 | "RAVEN", |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 87 | "LAST", |
| 88 | }; |
| 89 | |
| 90 | bool amdgpu_device_is_px(struct drm_device *dev) |
| 91 | { |
| 92 | struct amdgpu_device *adev = dev->dev_private; |
| 93 | |
Jammy Zhou | 2f7d10b | 2015-07-22 11:29:01 +0800 | [diff] [blame] | 94 | if (adev->flags & AMD_IS_PX) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 95 | return true; |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * MMIO register access helper functions. |
| 101 | */ |
| 102 | uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg, |
Monk Liu | 15d72fd | 2017-01-25 15:07:40 +0800 | [diff] [blame] | 103 | uint32_t acc_flags) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 104 | { |
Tom St Denis | f4b373f | 2016-05-31 08:02:27 -0400 | [diff] [blame] | 105 | uint32_t ret; |
| 106 | |
pding | 43ca8ef | 2017-10-13 15:38:35 +0800 | [diff] [blame] | 107 | if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev)) |
Xiangliang Yu | bc992ba | 2017-01-12 14:29:34 +0800 | [diff] [blame] | 108 | return amdgpu_virt_kiq_rreg(adev, reg); |
Xiangliang Yu | bc992ba | 2017-01-12 14:29:34 +0800 | [diff] [blame] | 109 | |
Monk Liu | 15d72fd | 2017-01-25 15:07:40 +0800 | [diff] [blame] | 110 | if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX)) |
Tom St Denis | f4b373f | 2016-05-31 08:02:27 -0400 | [diff] [blame] | 111 | ret = readl(((void __iomem *)adev->rmmio) + (reg * 4)); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 112 | else { |
| 113 | unsigned long flags; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 114 | |
| 115 | spin_lock_irqsave(&adev->mmio_idx_lock, flags); |
| 116 | writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4)); |
| 117 | ret = readl(((void __iomem *)adev->rmmio) + (mmMM_DATA * 4)); |
| 118 | spin_unlock_irqrestore(&adev->mmio_idx_lock, flags); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 119 | } |
Tom St Denis | f4b373f | 2016-05-31 08:02:27 -0400 | [diff] [blame] | 120 | trace_amdgpu_mm_rreg(adev->pdev->device, reg, ret); |
| 121 | return ret; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | 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] | 125 | uint32_t acc_flags) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 126 | { |
Tom St Denis | f4b373f | 2016-05-31 08:02:27 -0400 | [diff] [blame] | 127 | trace_amdgpu_mm_wreg(adev->pdev->device, reg, v); |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 128 | |
Ken Wang | 47ed4e1 | 2017-07-04 13:11:52 +0800 | [diff] [blame] | 129 | if (adev->asic_type >= CHIP_VEGA10 && reg == 0) { |
| 130 | adev->last_mm_index = v; |
| 131 | } |
| 132 | |
pding | 43ca8ef | 2017-10-13 15:38:35 +0800 | [diff] [blame] | 133 | if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev)) |
Xiangliang Yu | bc992ba | 2017-01-12 14:29:34 +0800 | [diff] [blame] | 134 | return amdgpu_virt_kiq_wreg(adev, reg, v); |
Xiangliang Yu | bc992ba | 2017-01-12 14:29:34 +0800 | [diff] [blame] | 135 | |
Monk Liu | 15d72fd | 2017-01-25 15:07:40 +0800 | [diff] [blame] | 136 | if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX)) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 137 | writel(v, ((void __iomem *)adev->rmmio) + (reg * 4)); |
| 138 | else { |
| 139 | unsigned long flags; |
| 140 | |
| 141 | spin_lock_irqsave(&adev->mmio_idx_lock, flags); |
| 142 | writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4)); |
| 143 | writel(v, ((void __iomem *)adev->rmmio) + (mmMM_DATA * 4)); |
| 144 | spin_unlock_irqrestore(&adev->mmio_idx_lock, flags); |
| 145 | } |
Ken Wang | 47ed4e1 | 2017-07-04 13:11:52 +0800 | [diff] [blame] | 146 | |
| 147 | if (adev->asic_type >= CHIP_VEGA10 && reg == 1 && adev->last_mm_index == 0x5702C) { |
| 148 | udelay(500); |
| 149 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg) |
| 153 | { |
| 154 | if ((reg * 4) < adev->rio_mem_size) |
| 155 | return ioread32(adev->rio_mem + (reg * 4)); |
| 156 | else { |
| 157 | iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4)); |
| 158 | return ioread32(adev->rio_mem + (mmMM_DATA * 4)); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v) |
| 163 | { |
Ken Wang | 47ed4e1 | 2017-07-04 13:11:52 +0800 | [diff] [blame] | 164 | if (adev->asic_type >= CHIP_VEGA10 && reg == 0) { |
| 165 | adev->last_mm_index = v; |
| 166 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 167 | |
| 168 | if ((reg * 4) < adev->rio_mem_size) |
| 169 | iowrite32(v, adev->rio_mem + (reg * 4)); |
| 170 | else { |
| 171 | iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4)); |
| 172 | iowrite32(v, adev->rio_mem + (mmMM_DATA * 4)); |
| 173 | } |
Ken Wang | 47ed4e1 | 2017-07-04 13:11:52 +0800 | [diff] [blame] | 174 | |
| 175 | if (adev->asic_type >= CHIP_VEGA10 && reg == 1 && adev->last_mm_index == 0x5702C) { |
| 176 | udelay(500); |
| 177 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /** |
| 181 | * amdgpu_mm_rdoorbell - read a doorbell dword |
| 182 | * |
| 183 | * @adev: amdgpu_device pointer |
| 184 | * @index: doorbell index |
| 185 | * |
| 186 | * Returns the value in the doorbell aperture at the |
| 187 | * requested doorbell index (CIK). |
| 188 | */ |
| 189 | u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index) |
| 190 | { |
| 191 | if (index < adev->doorbell.num_doorbells) { |
| 192 | return readl(adev->doorbell.ptr + index); |
| 193 | } else { |
| 194 | DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index); |
| 195 | return 0; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * amdgpu_mm_wdoorbell - write a doorbell dword |
| 201 | * |
| 202 | * @adev: amdgpu_device pointer |
| 203 | * @index: doorbell index |
| 204 | * @v: value to write |
| 205 | * |
| 206 | * Writes @v to the doorbell aperture at the |
| 207 | * requested doorbell index (CIK). |
| 208 | */ |
| 209 | void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v) |
| 210 | { |
| 211 | if (index < adev->doorbell.num_doorbells) { |
| 212 | writel(v, adev->doorbell.ptr + index); |
| 213 | } else { |
| 214 | DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /** |
Ken Wang | 832be40 | 2016-03-18 15:23:08 +0800 | [diff] [blame] | 219 | * amdgpu_mm_rdoorbell64 - read a doorbell Qword |
| 220 | * |
| 221 | * @adev: amdgpu_device pointer |
| 222 | * @index: doorbell index |
| 223 | * |
| 224 | * Returns the value in the doorbell aperture at the |
| 225 | * requested doorbell index (VEGA10+). |
| 226 | */ |
| 227 | u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index) |
| 228 | { |
| 229 | if (index < adev->doorbell.num_doorbells) { |
| 230 | return atomic64_read((atomic64_t *)(adev->doorbell.ptr + index)); |
| 231 | } else { |
| 232 | DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index); |
| 233 | return 0; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * amdgpu_mm_wdoorbell64 - write a doorbell Qword |
| 239 | * |
| 240 | * @adev: amdgpu_device pointer |
| 241 | * @index: doorbell index |
| 242 | * @v: value to write |
| 243 | * |
| 244 | * Writes @v to the doorbell aperture at the |
| 245 | * requested doorbell index (VEGA10+). |
| 246 | */ |
| 247 | void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v) |
| 248 | { |
| 249 | if (index < adev->doorbell.num_doorbells) { |
| 250 | atomic64_set((atomic64_t *)(adev->doorbell.ptr + index), v); |
| 251 | } else { |
| 252 | DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | /** |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 257 | * amdgpu_invalid_rreg - dummy reg read function |
| 258 | * |
| 259 | * @adev: amdgpu device pointer |
| 260 | * @reg: offset of register |
| 261 | * |
| 262 | * Dummy register read function. Used for register blocks |
| 263 | * that certain asics don't have (all asics). |
| 264 | * Returns the value in the register. |
| 265 | */ |
| 266 | static uint32_t amdgpu_invalid_rreg(struct amdgpu_device *adev, uint32_t reg) |
| 267 | { |
| 268 | DRM_ERROR("Invalid callback to read register 0x%04X\n", reg); |
| 269 | BUG(); |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * amdgpu_invalid_wreg - dummy reg write function |
| 275 | * |
| 276 | * @adev: amdgpu device pointer |
| 277 | * @reg: offset of register |
| 278 | * @v: value to write to the register |
| 279 | * |
| 280 | * Dummy register read function. Used for register blocks |
| 281 | * that certain asics don't have (all asics). |
| 282 | */ |
| 283 | static void amdgpu_invalid_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v) |
| 284 | { |
| 285 | DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n", |
| 286 | reg, v); |
| 287 | BUG(); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * amdgpu_block_invalid_rreg - dummy reg read function |
| 292 | * |
| 293 | * @adev: amdgpu device pointer |
| 294 | * @block: offset of instance |
| 295 | * @reg: offset of register |
| 296 | * |
| 297 | * Dummy register read function. Used for register blocks |
| 298 | * that certain asics don't have (all asics). |
| 299 | * Returns the value in the register. |
| 300 | */ |
| 301 | static uint32_t amdgpu_block_invalid_rreg(struct amdgpu_device *adev, |
| 302 | uint32_t block, uint32_t reg) |
| 303 | { |
| 304 | DRM_ERROR("Invalid callback to read register 0x%04X in block 0x%04X\n", |
| 305 | reg, block); |
| 306 | BUG(); |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * amdgpu_block_invalid_wreg - dummy reg write function |
| 312 | * |
| 313 | * @adev: amdgpu device pointer |
| 314 | * @block: offset of instance |
| 315 | * @reg: offset of register |
| 316 | * @v: value to write to the register |
| 317 | * |
| 318 | * Dummy register read function. Used for register blocks |
| 319 | * that certain asics don't have (all asics). |
| 320 | */ |
| 321 | static void amdgpu_block_invalid_wreg(struct amdgpu_device *adev, |
| 322 | uint32_t block, |
| 323 | uint32_t reg, uint32_t v) |
| 324 | { |
| 325 | DRM_ERROR("Invalid block callback to write register 0x%04X in block 0x%04X with 0x%08X\n", |
| 326 | reg, block, v); |
| 327 | BUG(); |
| 328 | } |
| 329 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 330 | static int amdgpu_device_vram_scratch_init(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 331 | { |
Christian König | a4a0277 | 2017-07-27 17:24:36 +0200 | [diff] [blame] | 332 | return amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE, |
| 333 | PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM, |
| 334 | &adev->vram_scratch.robj, |
| 335 | &adev->vram_scratch.gpu_addr, |
| 336 | (void **)&adev->vram_scratch.ptr); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 337 | } |
| 338 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 339 | static void amdgpu_device_vram_scratch_fini(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 340 | { |
Christian König | 078af1a | 2017-07-27 17:43:00 +0200 | [diff] [blame] | 341 | amdgpu_bo_free_kernel(&adev->vram_scratch.robj, NULL, NULL); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /** |
Alex Deucher | 9c3f2b5 | 2017-12-14 16:20:19 -0500 | [diff] [blame] | 345 | * amdgpu_device_program_register_sequence - program an array of registers. |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 346 | * |
| 347 | * @adev: amdgpu_device pointer |
| 348 | * @registers: pointer to the register array |
| 349 | * @array_size: size of the register array |
| 350 | * |
| 351 | * Programs an array or registers with and and or masks. |
| 352 | * This is a helper for setting golden registers. |
| 353 | */ |
Alex Deucher | 9c3f2b5 | 2017-12-14 16:20:19 -0500 | [diff] [blame] | 354 | void amdgpu_device_program_register_sequence(struct amdgpu_device *adev, |
| 355 | const u32 *registers, |
| 356 | const u32 array_size) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 357 | { |
| 358 | u32 tmp, reg, and_mask, or_mask; |
| 359 | int i; |
| 360 | |
| 361 | if (array_size % 3) |
| 362 | return; |
| 363 | |
| 364 | for (i = 0; i < array_size; i +=3) { |
| 365 | reg = registers[i + 0]; |
| 366 | and_mask = registers[i + 1]; |
| 367 | or_mask = registers[i + 2]; |
| 368 | |
| 369 | if (and_mask == 0xffffffff) { |
| 370 | tmp = or_mask; |
| 371 | } else { |
| 372 | tmp = RREG32(reg); |
| 373 | tmp &= ~and_mask; |
| 374 | tmp |= or_mask; |
| 375 | } |
| 376 | WREG32(reg, tmp); |
| 377 | } |
| 378 | } |
| 379 | |
Alex Deucher | 8111c38 | 2017-12-14 16:22:53 -0500 | [diff] [blame] | 380 | void amdgpu_device_pci_config_reset(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 381 | { |
| 382 | pci_write_config_dword(adev->pdev, 0x7c, AMDGPU_ASIC_RESET_DATA); |
| 383 | } |
| 384 | |
| 385 | /* |
| 386 | * GPU doorbell aperture helpers function. |
| 387 | */ |
| 388 | /** |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 389 | * amdgpu_device_doorbell_init - Init doorbell driver information. |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 390 | * |
| 391 | * @adev: amdgpu_device pointer |
| 392 | * |
| 393 | * Init doorbell driver information (CIK) |
| 394 | * Returns 0 on success, error on failure. |
| 395 | */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 396 | static int amdgpu_device_doorbell_init(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 397 | { |
Christian König | 705e519 | 2017-06-08 11:15:16 +0200 | [diff] [blame] | 398 | /* No doorbell on SI hardware generation */ |
| 399 | if (adev->asic_type < CHIP_BONAIRE) { |
| 400 | adev->doorbell.base = 0; |
| 401 | adev->doorbell.size = 0; |
| 402 | adev->doorbell.num_doorbells = 0; |
| 403 | adev->doorbell.ptr = NULL; |
| 404 | return 0; |
| 405 | } |
| 406 | |
Christian König | d6895ad | 2017-02-28 10:36:43 +0100 | [diff] [blame] | 407 | if (pci_resource_flags(adev->pdev, 2) & IORESOURCE_UNSET) |
| 408 | return -EINVAL; |
| 409 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 410 | /* doorbell bar mapping */ |
| 411 | adev->doorbell.base = pci_resource_start(adev->pdev, 2); |
| 412 | adev->doorbell.size = pci_resource_len(adev->pdev, 2); |
| 413 | |
Christian König | edf600d | 2016-05-03 15:54:54 +0200 | [diff] [blame] | 414 | adev->doorbell.num_doorbells = min_t(u32, adev->doorbell.size / sizeof(u32), |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 415 | AMDGPU_DOORBELL_MAX_ASSIGNMENT+1); |
| 416 | if (adev->doorbell.num_doorbells == 0) |
| 417 | return -EINVAL; |
| 418 | |
Christian König | 8972e5d | 2017-03-06 13:34:57 +0100 | [diff] [blame] | 419 | adev->doorbell.ptr = ioremap(adev->doorbell.base, |
| 420 | adev->doorbell.num_doorbells * |
| 421 | sizeof(u32)); |
| 422 | if (adev->doorbell.ptr == NULL) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 423 | return -ENOMEM; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | /** |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 429 | * amdgpu_device_doorbell_fini - Tear down doorbell driver information. |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 430 | * |
| 431 | * @adev: amdgpu_device pointer |
| 432 | * |
| 433 | * Tear down doorbell driver information (CIK) |
| 434 | */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 435 | static void amdgpu_device_doorbell_fini(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 436 | { |
| 437 | iounmap(adev->doorbell.ptr); |
| 438 | adev->doorbell.ptr = NULL; |
| 439 | } |
| 440 | |
Alex Deucher | 22cb016 | 2017-12-14 16:27:11 -0500 | [diff] [blame] | 441 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 442 | |
| 443 | /* |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 444 | * amdgpu_device_wb_*() |
Alex Xie | 455a7bc | 2017-05-08 21:36:03 -0400 | [diff] [blame] | 445 | * Writeback is the method by which the GPU updates special pages in memory |
Alex Xie | ea81a17 | 2017-05-08 13:41:11 -0400 | [diff] [blame] | 446 | * with the status of certain GPU events (fences, ring pointers,etc.). |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 447 | */ |
| 448 | |
| 449 | /** |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 450 | * amdgpu_device_wb_fini - Disable Writeback and free memory |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 451 | * |
| 452 | * @adev: amdgpu_device pointer |
| 453 | * |
| 454 | * Disables Writeback and frees the Writeback memory (all asics). |
| 455 | * Used at driver shutdown. |
| 456 | */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 457 | static void amdgpu_device_wb_fini(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 458 | { |
| 459 | if (adev->wb.wb_obj) { |
Alex Deucher | a76ed48 | 2016-10-21 15:30:36 -0400 | [diff] [blame] | 460 | amdgpu_bo_free_kernel(&adev->wb.wb_obj, |
| 461 | &adev->wb.gpu_addr, |
| 462 | (void **)&adev->wb.wb); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 463 | adev->wb.wb_obj = NULL; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | /** |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 468 | * amdgpu_device_wb_init- Init Writeback driver info and allocate memory |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 469 | * |
| 470 | * @adev: amdgpu_device pointer |
| 471 | * |
Alex Xie | 455a7bc | 2017-05-08 21:36:03 -0400 | [diff] [blame] | 472 | * Initializes writeback and allocates writeback memory (all asics). |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 473 | * Used at driver startup. |
| 474 | * Returns 0 on success or an -error on failure. |
| 475 | */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 476 | static int amdgpu_device_wb_init(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 477 | { |
| 478 | int r; |
| 479 | |
| 480 | if (adev->wb.wb_obj == NULL) { |
Alex Deucher | 97407b6 | 2017-07-28 12:14:15 -0400 | [diff] [blame] | 481 | /* AMDGPU_MAX_WB * sizeof(uint32_t) * 8 = AMDGPU_MAX_WB 256bit slots */ |
| 482 | r = amdgpu_bo_create_kernel(adev, AMDGPU_MAX_WB * sizeof(uint32_t) * 8, |
Alex Deucher | a76ed48 | 2016-10-21 15:30:36 -0400 | [diff] [blame] | 483 | PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT, |
| 484 | &adev->wb.wb_obj, &adev->wb.gpu_addr, |
| 485 | (void **)&adev->wb.wb); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 486 | if (r) { |
| 487 | dev_warn(adev->dev, "(%d) create WB bo failed\n", r); |
| 488 | return r; |
| 489 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 490 | |
| 491 | adev->wb.num_wb = AMDGPU_MAX_WB; |
| 492 | memset(&adev->wb.used, 0, sizeof(adev->wb.used)); |
| 493 | |
| 494 | /* clear wb memory */ |
Monk Liu | 7346958 | 2017-12-29 17:06:41 +0800 | [diff] [blame^] | 495 | memset((char *)adev->wb.wb, 0, AMDGPU_MAX_WB * sizeof(uint32_t) * 8); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | /** |
Alex Deucher | 131b4b3 | 2017-12-14 16:03:43 -0500 | [diff] [blame] | 502 | * amdgpu_device_wb_get - Allocate a wb entry |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 503 | * |
| 504 | * @adev: amdgpu_device pointer |
| 505 | * @wb: wb index |
| 506 | * |
| 507 | * Allocate a wb slot for use by the driver (all asics). |
| 508 | * Returns 0 on success or -EINVAL on failure. |
| 509 | */ |
Alex Deucher | 131b4b3 | 2017-12-14 16:03:43 -0500 | [diff] [blame] | 510 | int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 511 | { |
| 512 | unsigned long offset = find_first_zero_bit(adev->wb.used, adev->wb.num_wb); |
Alex Deucher | 97407b6 | 2017-07-28 12:14:15 -0400 | [diff] [blame] | 513 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 514 | if (offset < adev->wb.num_wb) { |
| 515 | __set_bit(offset, adev->wb.used); |
Monk Liu | 63ae07c | 2017-10-17 19:18:56 +0800 | [diff] [blame] | 516 | *wb = offset << 3; /* convert to dw offset */ |
Monk Liu | 0915fdb | 2017-06-19 10:19:41 -0400 | [diff] [blame] | 517 | return 0; |
| 518 | } else { |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | } |
| 522 | |
Ken Wang | 7014285 | 2016-03-18 15:08:49 +0800 | [diff] [blame] | 523 | /** |
Alex Deucher | 131b4b3 | 2017-12-14 16:03:43 -0500 | [diff] [blame] | 524 | * amdgpu_device_wb_free - Free a wb entry |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 525 | * |
| 526 | * @adev: amdgpu_device pointer |
| 527 | * @wb: wb index |
| 528 | * |
| 529 | * Free a wb slot allocated for use by the driver (all asics) |
| 530 | */ |
Alex Deucher | 131b4b3 | 2017-12-14 16:03:43 -0500 | [diff] [blame] | 531 | void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 532 | { |
Monk Liu | 7346958 | 2017-12-29 17:06:41 +0800 | [diff] [blame^] | 533 | wb >>= 3; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 534 | if (wb < adev->wb.num_wb) |
Monk Liu | 7346958 | 2017-12-29 17:06:41 +0800 | [diff] [blame^] | 535 | __clear_bit(wb, adev->wb.used); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /** |
Alex Deucher | 2543e28 | 2017-12-14 16:33:36 -0500 | [diff] [blame] | 539 | * amdgpu_device_vram_location - try to find VRAM location |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 540 | * @adev: amdgpu device structure holding all necessary informations |
| 541 | * @mc: memory controller structure holding memory informations |
| 542 | * @base: base address at which to put VRAM |
| 543 | * |
Alex Xie | 455a7bc | 2017-05-08 21:36:03 -0400 | [diff] [blame] | 544 | * Function will try to place VRAM at base address provided |
Christian König | 3d647c8 | 2017-11-16 19:36:10 +0100 | [diff] [blame] | 545 | * as parameter. |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 546 | */ |
Alex Deucher | 2543e28 | 2017-12-14 16:33:36 -0500 | [diff] [blame] | 547 | void amdgpu_device_vram_location(struct amdgpu_device *adev, |
Christian König | 770d13b | 2018-01-12 14:52:22 +0100 | [diff] [blame] | 548 | struct amdgpu_gmc *mc, u64 base) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 549 | { |
| 550 | uint64_t limit = (uint64_t)amdgpu_vram_limit << 20; |
| 551 | |
| 552 | mc->vram_start = base; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 553 | mc->vram_end = mc->vram_start + mc->mc_vram_size - 1; |
| 554 | if (limit && limit < mc->real_vram_size) |
| 555 | mc->real_vram_size = limit; |
| 556 | dev_info(adev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n", |
| 557 | mc->mc_vram_size >> 20, mc->vram_start, |
| 558 | mc->vram_end, mc->real_vram_size >> 20); |
| 559 | } |
| 560 | |
| 561 | /** |
Alex Deucher | 2543e28 | 2017-12-14 16:33:36 -0500 | [diff] [blame] | 562 | * amdgpu_device_gart_location - try to find GTT location |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 563 | * @adev: amdgpu device structure holding all necessary informations |
| 564 | * @mc: memory controller structure holding memory informations |
| 565 | * |
| 566 | * Function will place try to place GTT before or after VRAM. |
| 567 | * |
| 568 | * If GTT size is bigger than space left then we ajust GTT size. |
| 569 | * Thus function will never fails. |
| 570 | * |
| 571 | * FIXME: when reducing GTT size align new size on power of 2. |
| 572 | */ |
Alex Deucher | 2543e28 | 2017-12-14 16:33:36 -0500 | [diff] [blame] | 573 | void amdgpu_device_gart_location(struct amdgpu_device *adev, |
Christian König | 770d13b | 2018-01-12 14:52:22 +0100 | [diff] [blame] | 574 | struct amdgpu_gmc *mc) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 575 | { |
| 576 | u64 size_af, size_bf; |
| 577 | |
Christian König | 770d13b | 2018-01-12 14:52:22 +0100 | [diff] [blame] | 578 | size_af = adev->gmc.mc_mask - mc->vram_end; |
Christian König | ed21c04 | 2017-07-06 22:26:05 +0200 | [diff] [blame] | 579 | size_bf = mc->vram_start; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 580 | if (size_bf > size_af) { |
Christian König | 6f02a69 | 2017-07-07 11:56:59 +0200 | [diff] [blame] | 581 | if (mc->gart_size > size_bf) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 582 | dev_warn(adev->dev, "limiting GTT\n"); |
Christian König | 6f02a69 | 2017-07-07 11:56:59 +0200 | [diff] [blame] | 583 | mc->gart_size = size_bf; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 584 | } |
Christian König | 6f02a69 | 2017-07-07 11:56:59 +0200 | [diff] [blame] | 585 | mc->gart_start = 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 586 | } else { |
Christian König | 6f02a69 | 2017-07-07 11:56:59 +0200 | [diff] [blame] | 587 | if (mc->gart_size > size_af) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 588 | dev_warn(adev->dev, "limiting GTT\n"); |
Christian König | 6f02a69 | 2017-07-07 11:56:59 +0200 | [diff] [blame] | 589 | mc->gart_size = size_af; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 590 | } |
Christian König | b98f1b9 | 2017-11-16 20:12:51 +0100 | [diff] [blame] | 591 | /* VCE doesn't like it when BOs cross a 4GB segment, so align |
| 592 | * the GART base on a 4GB boundary as well. |
| 593 | */ |
| 594 | mc->gart_start = ALIGN(mc->vram_end + 1, 0x100000000ULL); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 595 | } |
Christian König | 6f02a69 | 2017-07-07 11:56:59 +0200 | [diff] [blame] | 596 | mc->gart_end = mc->gart_start + mc->gart_size - 1; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 597 | dev_info(adev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n", |
Christian König | 6f02a69 | 2017-07-07 11:56:59 +0200 | [diff] [blame] | 598 | mc->gart_size >> 20, mc->gart_start, mc->gart_end); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 599 | } |
| 600 | |
Christian König | d6895ad | 2017-02-28 10:36:43 +0100 | [diff] [blame] | 601 | /** |
| 602 | * amdgpu_device_resize_fb_bar - try to resize FB BAR |
| 603 | * |
| 604 | * @adev: amdgpu_device pointer |
| 605 | * |
| 606 | * Try to resize FB BAR to make all VRAM CPU accessible. We try very hard not |
| 607 | * to fail, but if any of the BARs is not accessible after the size we abort |
| 608 | * driver loading by returning -ENODEV. |
| 609 | */ |
| 610 | int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev) |
| 611 | { |
Christian König | 770d13b | 2018-01-12 14:52:22 +0100 | [diff] [blame] | 612 | u64 space_needed = roundup_pow_of_two(adev->gmc.real_vram_size); |
Christian König | d6895ad | 2017-02-28 10:36:43 +0100 | [diff] [blame] | 613 | u32 rbar_size = order_base_2(((space_needed >> 20) | 1)) - 1; |
Christian König | 31b8ada | 2017-11-15 20:07:38 +0100 | [diff] [blame] | 614 | struct pci_bus *root; |
| 615 | struct resource *res; |
| 616 | unsigned i; |
Christian König | d6895ad | 2017-02-28 10:36:43 +0100 | [diff] [blame] | 617 | u16 cmd; |
| 618 | int r; |
| 619 | |
pding | 0c03b91 | 2017-11-07 11:02:00 +0800 | [diff] [blame] | 620 | /* Bypass for VF */ |
| 621 | if (amdgpu_sriov_vf(adev)) |
| 622 | return 0; |
| 623 | |
Christian König | 31b8ada | 2017-11-15 20:07:38 +0100 | [diff] [blame] | 624 | /* Check if the root BUS has 64bit memory resources */ |
| 625 | root = adev->pdev->bus; |
| 626 | while (root->parent) |
| 627 | root = root->parent; |
| 628 | |
| 629 | pci_bus_for_each_resource(root, res, i) { |
Christian König | 0ebb7c5 | 2018-01-07 10:18:57 +0100 | [diff] [blame] | 630 | if (res && res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) && |
Christian König | 31b8ada | 2017-11-15 20:07:38 +0100 | [diff] [blame] | 631 | res->start > 0x100000000ull) |
| 632 | break; |
| 633 | } |
| 634 | |
| 635 | /* Trying to resize is pointless without a root hub window above 4GB */ |
| 636 | if (!res) |
| 637 | return 0; |
| 638 | |
Christian König | d6895ad | 2017-02-28 10:36:43 +0100 | [diff] [blame] | 639 | /* Disable memory decoding while we change the BAR addresses and size */ |
| 640 | pci_read_config_word(adev->pdev, PCI_COMMAND, &cmd); |
| 641 | pci_write_config_word(adev->pdev, PCI_COMMAND, |
| 642 | cmd & ~PCI_COMMAND_MEMORY); |
| 643 | |
| 644 | /* Free the VRAM and doorbell BAR, we most likely need to move both. */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 645 | amdgpu_device_doorbell_fini(adev); |
Christian König | d6895ad | 2017-02-28 10:36:43 +0100 | [diff] [blame] | 646 | if (adev->asic_type >= CHIP_BONAIRE) |
| 647 | pci_release_resource(adev->pdev, 2); |
| 648 | |
| 649 | pci_release_resource(adev->pdev, 0); |
| 650 | |
| 651 | r = pci_resize_resource(adev->pdev, 0, rbar_size); |
| 652 | if (r == -ENOSPC) |
| 653 | DRM_INFO("Not enough PCI address space for a large BAR."); |
| 654 | else if (r && r != -ENOTSUPP) |
| 655 | DRM_ERROR("Problem resizing BAR0 (%d).", r); |
| 656 | |
| 657 | pci_assign_unassigned_bus_resources(adev->pdev->bus); |
| 658 | |
| 659 | /* When the doorbell or fb BAR isn't available we have no chance of |
| 660 | * using the device. |
| 661 | */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 662 | r = amdgpu_device_doorbell_init(adev); |
Christian König | d6895ad | 2017-02-28 10:36:43 +0100 | [diff] [blame] | 663 | if (r || (pci_resource_flags(adev->pdev, 0) & IORESOURCE_UNSET)) |
| 664 | return -ENODEV; |
| 665 | |
| 666 | pci_write_config_word(adev->pdev, PCI_COMMAND, cmd); |
| 667 | |
| 668 | return 0; |
| 669 | } |
Horace Chen | a05502e | 2017-09-29 14:41:57 +0800 | [diff] [blame] | 670 | |
| 671 | /* |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 672 | * GPU helpers function. |
| 673 | */ |
| 674 | /** |
Alex Deucher | 39c640c | 2017-12-15 16:22:11 -0500 | [diff] [blame] | 675 | * amdgpu_device_need_post - check if the hw need post or not |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 676 | * |
| 677 | * @adev: amdgpu_device pointer |
| 678 | * |
Jim Qu | c836fec | 2017-02-10 15:59:59 +0800 | [diff] [blame] | 679 | * Check if the asic has been initialized (all asics) at driver startup |
| 680 | * or post is needed if hw reset is performed. |
| 681 | * Returns true if need or false if not. |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 682 | */ |
Alex Deucher | 39c640c | 2017-12-15 16:22:11 -0500 | [diff] [blame] | 683 | bool amdgpu_device_need_post(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 684 | { |
| 685 | uint32_t reg; |
| 686 | |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 687 | if (amdgpu_sriov_vf(adev)) |
| 688 | return false; |
| 689 | |
| 690 | if (amdgpu_passthrough(adev)) { |
Monk Liu | 1da2c32 | 2016-11-11 11:24:29 +0800 | [diff] [blame] | 691 | /* for FIJI: In whole GPU pass-through virtualization case, after VM reboot |
| 692 | * some old smc fw still need driver do vPost otherwise gpu hang, while |
| 693 | * those smc fw version above 22.15 doesn't have this flaw, so we force |
| 694 | * vpost executed for smc version below 22.15 |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 695 | */ |
| 696 | if (adev->asic_type == CHIP_FIJI) { |
| 697 | int err; |
| 698 | uint32_t fw_ver; |
| 699 | err = request_firmware(&adev->pm.fw, "amdgpu/fiji_smc.bin", adev->dev); |
| 700 | /* force vPost if error occured */ |
| 701 | if (err) |
| 702 | return true; |
| 703 | |
| 704 | fw_ver = *((uint32_t *)adev->pm.fw->data + 69); |
Monk Liu | 1da2c32 | 2016-11-11 11:24:29 +0800 | [diff] [blame] | 705 | if (fw_ver < 0x00160e00) |
| 706 | return true; |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 707 | } |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 708 | } |
pding | 91fe77e | 2017-10-19 09:38:39 +0800 | [diff] [blame] | 709 | |
| 710 | if (adev->has_hw_reset) { |
| 711 | adev->has_hw_reset = false; |
| 712 | return true; |
| 713 | } |
| 714 | |
| 715 | /* bios scratch used on CIK+ */ |
| 716 | if (adev->asic_type >= CHIP_BONAIRE) |
| 717 | return amdgpu_atombios_scratch_need_asic_init(adev); |
| 718 | |
| 719 | /* check MEM_SIZE for older asics */ |
| 720 | reg = amdgpu_asic_get_config_memsize(adev); |
| 721 | |
| 722 | if ((reg != 0) && (reg != 0xffffffff)) |
| 723 | return false; |
| 724 | |
| 725 | return true; |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 726 | } |
| 727 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 728 | /* if we get transitioned to only one device, take VGA back */ |
| 729 | /** |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 730 | * amdgpu_device_vga_set_decode - enable/disable vga decode |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 731 | * |
| 732 | * @cookie: amdgpu_device pointer |
| 733 | * @state: enable/disable vga decode |
| 734 | * |
| 735 | * Enable/disable vga decode (all asics). |
| 736 | * Returns VGA resource flags. |
| 737 | */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 738 | static unsigned int amdgpu_device_vga_set_decode(void *cookie, bool state) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 739 | { |
| 740 | struct amdgpu_device *adev = cookie; |
| 741 | amdgpu_asic_set_vga_state(adev, state); |
| 742 | if (state) |
| 743 | return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | |
| 744 | VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 745 | else |
| 746 | return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 747 | } |
| 748 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 749 | static void amdgpu_device_check_block_size(struct amdgpu_device *adev) |
Chunming Zhou | a1adf8b | 2017-03-27 11:36:57 +0800 | [diff] [blame] | 750 | { |
| 751 | /* defines number of bits in page table versus page directory, |
| 752 | * a page is 4KB so we have 12 bits offset, minimum 9 bits in the |
| 753 | * page table and the remaining bits are in the page directory */ |
Junwei Zhang | bab4fee | 2017-04-05 13:54:56 +0800 | [diff] [blame] | 754 | if (amdgpu_vm_block_size == -1) |
| 755 | return; |
Chunming Zhou | a1adf8b | 2017-03-27 11:36:57 +0800 | [diff] [blame] | 756 | |
Junwei Zhang | bab4fee | 2017-04-05 13:54:56 +0800 | [diff] [blame] | 757 | if (amdgpu_vm_block_size < 9) { |
Chunming Zhou | a1adf8b | 2017-03-27 11:36:57 +0800 | [diff] [blame] | 758 | dev_warn(adev->dev, "VM page table size (%d) too small\n", |
| 759 | amdgpu_vm_block_size); |
Christian König | 9748912 | 2017-11-27 16:22:05 +0100 | [diff] [blame] | 760 | amdgpu_vm_block_size = -1; |
Chunming Zhou | a1adf8b | 2017-03-27 11:36:57 +0800 | [diff] [blame] | 761 | } |
Chunming Zhou | a1adf8b | 2017-03-27 11:36:57 +0800 | [diff] [blame] | 762 | } |
| 763 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 764 | static void amdgpu_device_check_vm_size(struct amdgpu_device *adev) |
Zhang, Jerry | 83ca145 | 2017-03-29 16:08:31 +0800 | [diff] [blame] | 765 | { |
Alex Deucher | 64dab07 | 2017-06-15 18:20:09 -0400 | [diff] [blame] | 766 | /* no need to check the default value */ |
| 767 | if (amdgpu_vm_size == -1) |
| 768 | return; |
| 769 | |
Zhang, Jerry | 83ca145 | 2017-03-29 16:08:31 +0800 | [diff] [blame] | 770 | if (amdgpu_vm_size < 1) { |
| 771 | dev_warn(adev->dev, "VM size (%d) too small, min is 1GB\n", |
| 772 | amdgpu_vm_size); |
Christian König | f336812 | 2017-11-23 12:57:18 +0100 | [diff] [blame] | 773 | amdgpu_vm_size = -1; |
Zhang, Jerry | 83ca145 | 2017-03-29 16:08:31 +0800 | [diff] [blame] | 774 | } |
Zhang, Jerry | 83ca145 | 2017-03-29 16:08:31 +0800 | [diff] [blame] | 775 | } |
| 776 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 777 | /** |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 778 | * amdgpu_device_check_arguments - validate module params |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 779 | * |
| 780 | * @adev: amdgpu_device pointer |
| 781 | * |
| 782 | * Validates certain module parameters and updates |
| 783 | * the associated values used by the driver (all asics). |
| 784 | */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 785 | static void amdgpu_device_check_arguments(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 786 | { |
Chunming Zhou | 5b01123 | 2015-12-10 17:34:33 +0800 | [diff] [blame] | 787 | if (amdgpu_sched_jobs < 4) { |
| 788 | dev_warn(adev->dev, "sched jobs (%d) must be at least 4\n", |
| 789 | amdgpu_sched_jobs); |
| 790 | amdgpu_sched_jobs = 4; |
Alex Deucher | 7611750 | 2017-06-21 12:31:41 -0400 | [diff] [blame] | 791 | } else if (!is_power_of_2(amdgpu_sched_jobs)){ |
Chunming Zhou | 5b01123 | 2015-12-10 17:34:33 +0800 | [diff] [blame] | 792 | dev_warn(adev->dev, "sched jobs (%d) must be a power of 2\n", |
| 793 | amdgpu_sched_jobs); |
| 794 | amdgpu_sched_jobs = roundup_pow_of_two(amdgpu_sched_jobs); |
| 795 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 796 | |
Alex Deucher | 83e74db | 2017-08-21 11:58:25 -0400 | [diff] [blame] | 797 | if (amdgpu_gart_size != -1 && amdgpu_gart_size < 32) { |
Christian König | f9321cc | 2017-07-07 13:44:05 +0200 | [diff] [blame] | 798 | /* gart size must be greater or equal to 32M */ |
| 799 | dev_warn(adev->dev, "gart size (%d) too small\n", |
| 800 | amdgpu_gart_size); |
Alex Deucher | 83e74db | 2017-08-21 11:58:25 -0400 | [diff] [blame] | 801 | amdgpu_gart_size = -1; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 802 | } |
| 803 | |
Christian König | 36d3837 | 2017-07-07 13:17:45 +0200 | [diff] [blame] | 804 | if (amdgpu_gtt_size != -1 && amdgpu_gtt_size < 32) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 805 | /* gtt size must be greater or equal to 32M */ |
Christian König | 36d3837 | 2017-07-07 13:17:45 +0200 | [diff] [blame] | 806 | dev_warn(adev->dev, "gtt size (%d) too small\n", |
| 807 | amdgpu_gtt_size); |
| 808 | amdgpu_gtt_size = -1; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 809 | } |
| 810 | |
Roger He | d07f14b | 2017-08-15 16:05:59 +0800 | [diff] [blame] | 811 | /* valid range is between 4 and 9 inclusive */ |
| 812 | if (amdgpu_vm_fragment_size != -1 && |
| 813 | (amdgpu_vm_fragment_size > 9 || amdgpu_vm_fragment_size < 4)) { |
| 814 | dev_warn(adev->dev, "valid range is between 4 and 9\n"); |
| 815 | amdgpu_vm_fragment_size = -1; |
| 816 | } |
| 817 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 818 | amdgpu_device_check_vm_size(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 819 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 820 | amdgpu_device_check_block_size(adev); |
Christian König | 6a7f76e | 2016-08-24 15:51:49 +0200 | [diff] [blame] | 821 | |
jimqu | 526bae3 | 2016-11-07 09:53:10 +0800 | [diff] [blame] | 822 | if (amdgpu_vram_page_split != -1 && (amdgpu_vram_page_split < 16 || |
Alex Deucher | 7611750 | 2017-06-21 12:31:41 -0400 | [diff] [blame] | 823 | !is_power_of_2(amdgpu_vram_page_split))) { |
Christian König | 6a7f76e | 2016-08-24 15:51:49 +0200 | [diff] [blame] | 824 | dev_warn(adev->dev, "invalid VRAM page split (%d)\n", |
| 825 | amdgpu_vram_page_split); |
| 826 | amdgpu_vram_page_split = 1024; |
| 827 | } |
Andrey Grodzovsky | 8854695 | 2017-12-13 14:36:53 -0500 | [diff] [blame] | 828 | |
| 829 | if (amdgpu_lockup_timeout == 0) { |
| 830 | dev_warn(adev->dev, "lockup_timeout msut be > 0, adjusting to 10000\n"); |
| 831 | amdgpu_lockup_timeout = 10000; |
| 832 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | /** |
| 836 | * amdgpu_switcheroo_set_state - set switcheroo state |
| 837 | * |
| 838 | * @pdev: pci dev pointer |
Lukas Wunner | 1694467 | 2015-09-05 11:17:35 +0200 | [diff] [blame] | 839 | * @state: vga_switcheroo state |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 840 | * |
| 841 | * Callback for the switcheroo driver. Suspends or resumes the |
| 842 | * the asics before or after it is powered up using ACPI methods. |
| 843 | */ |
| 844 | static void amdgpu_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state) |
| 845 | { |
| 846 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 847 | |
| 848 | if (amdgpu_device_is_px(dev) && state == VGA_SWITCHEROO_OFF) |
| 849 | return; |
| 850 | |
| 851 | if (state == VGA_SWITCHEROO_ON) { |
Joe Perches | 7ca8529 | 2017-02-28 04:55:52 -0800 | [diff] [blame] | 852 | pr_info("amdgpu: switched on\n"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 853 | /* don't suspend or resume card normally */ |
| 854 | dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; |
| 855 | |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 856 | amdgpu_device_resume(dev, true, true); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 857 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 858 | dev->switch_power_state = DRM_SWITCH_POWER_ON; |
| 859 | drm_kms_helper_poll_enable(dev); |
| 860 | } else { |
Joe Perches | 7ca8529 | 2017-02-28 04:55:52 -0800 | [diff] [blame] | 861 | pr_info("amdgpu: switched off\n"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 862 | drm_kms_helper_poll_disable(dev); |
| 863 | dev->switch_power_state = DRM_SWITCH_POWER_CHANGING; |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 864 | amdgpu_device_suspend(dev, true, true); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 865 | dev->switch_power_state = DRM_SWITCH_POWER_OFF; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * amdgpu_switcheroo_can_switch - see if switcheroo state can change |
| 871 | * |
| 872 | * @pdev: pci dev pointer |
| 873 | * |
| 874 | * Callback for the switcheroo driver. Check of the switcheroo |
| 875 | * state can be changed. |
| 876 | * Returns true if the state can be changed, false if not. |
| 877 | */ |
| 878 | static bool amdgpu_switcheroo_can_switch(struct pci_dev *pdev) |
| 879 | { |
| 880 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 881 | |
| 882 | /* |
| 883 | * FIXME: open_count is protected by drm_global_mutex but that would lead to |
| 884 | * locking inversion with the driver load path. And the access here is |
| 885 | * completely racy anyway. So don't bother with locking for now. |
| 886 | */ |
| 887 | return dev->open_count == 0; |
| 888 | } |
| 889 | |
| 890 | static const struct vga_switcheroo_client_ops amdgpu_switcheroo_ops = { |
| 891 | .set_gpu_state = amdgpu_switcheroo_set_state, |
| 892 | .reprobe = NULL, |
| 893 | .can_switch = amdgpu_switcheroo_can_switch, |
| 894 | }; |
| 895 | |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 896 | int amdgpu_device_ip_set_clockgating_state(struct amdgpu_device *adev, |
| 897 | enum amd_ip_block_type block_type, |
| 898 | enum amd_clockgating_state state) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 899 | { |
| 900 | int i, r = 0; |
| 901 | |
| 902 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 903 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | 9ecbe7f | 2016-06-23 11:53:12 -0400 | [diff] [blame] | 904 | continue; |
Rex Zhu | c722865 | 2017-02-22 15:33:46 +0800 | [diff] [blame] | 905 | if (adev->ip_blocks[i].version->type != block_type) |
| 906 | continue; |
| 907 | if (!adev->ip_blocks[i].version->funcs->set_clockgating_state) |
| 908 | continue; |
| 909 | r = adev->ip_blocks[i].version->funcs->set_clockgating_state( |
| 910 | (void *)adev, state); |
| 911 | if (r) |
| 912 | DRM_ERROR("set_clockgating_state of IP block <%s> failed %d\n", |
| 913 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 914 | } |
| 915 | return r; |
| 916 | } |
| 917 | |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 918 | int amdgpu_device_ip_set_powergating_state(struct amdgpu_device *adev, |
| 919 | enum amd_ip_block_type block_type, |
| 920 | enum amd_powergating_state state) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 921 | { |
| 922 | int i, r = 0; |
| 923 | |
| 924 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 925 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | 9ecbe7f | 2016-06-23 11:53:12 -0400 | [diff] [blame] | 926 | continue; |
Rex Zhu | c722865 | 2017-02-22 15:33:46 +0800 | [diff] [blame] | 927 | if (adev->ip_blocks[i].version->type != block_type) |
| 928 | continue; |
| 929 | if (!adev->ip_blocks[i].version->funcs->set_powergating_state) |
| 930 | continue; |
| 931 | r = adev->ip_blocks[i].version->funcs->set_powergating_state( |
| 932 | (void *)adev, state); |
| 933 | if (r) |
| 934 | DRM_ERROR("set_powergating_state of IP block <%s> failed %d\n", |
| 935 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 936 | } |
| 937 | return r; |
| 938 | } |
| 939 | |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 940 | void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev, |
| 941 | u32 *flags) |
Huang Rui | 6cb2d4e | 2017-01-05 18:44:41 +0800 | [diff] [blame] | 942 | { |
| 943 | int i; |
| 944 | |
| 945 | for (i = 0; i < adev->num_ip_blocks; i++) { |
| 946 | if (!adev->ip_blocks[i].status.valid) |
| 947 | continue; |
| 948 | if (adev->ip_blocks[i].version->funcs->get_clockgating_state) |
| 949 | adev->ip_blocks[i].version->funcs->get_clockgating_state((void *)adev, flags); |
| 950 | } |
| 951 | } |
| 952 | |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 953 | int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev, |
| 954 | enum amd_ip_block_type block_type) |
Alex Deucher | 5dbbb60 | 2016-06-23 11:41:04 -0400 | [diff] [blame] | 955 | { |
| 956 | int i, r; |
| 957 | |
| 958 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 959 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | 9ecbe7f | 2016-06-23 11:53:12 -0400 | [diff] [blame] | 960 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 961 | if (adev->ip_blocks[i].version->type == block_type) { |
| 962 | r = adev->ip_blocks[i].version->funcs->wait_for_idle((void *)adev); |
Alex Deucher | 5dbbb60 | 2016-06-23 11:41:04 -0400 | [diff] [blame] | 963 | if (r) |
| 964 | return r; |
| 965 | break; |
| 966 | } |
| 967 | } |
| 968 | return 0; |
| 969 | |
| 970 | } |
| 971 | |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 972 | bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev, |
| 973 | enum amd_ip_block_type block_type) |
Alex Deucher | 5dbbb60 | 2016-06-23 11:41:04 -0400 | [diff] [blame] | 974 | { |
| 975 | int i; |
| 976 | |
| 977 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 978 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | 9ecbe7f | 2016-06-23 11:53:12 -0400 | [diff] [blame] | 979 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 980 | if (adev->ip_blocks[i].version->type == block_type) |
| 981 | return adev->ip_blocks[i].version->funcs->is_idle((void *)adev); |
Alex Deucher | 5dbbb60 | 2016-06-23 11:41:04 -0400 | [diff] [blame] | 982 | } |
| 983 | return true; |
| 984 | |
| 985 | } |
| 986 | |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 987 | struct amdgpu_ip_block * |
| 988 | amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev, |
| 989 | enum amd_ip_block_type type) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 990 | { |
| 991 | int i; |
| 992 | |
| 993 | for (i = 0; i < adev->num_ip_blocks; i++) |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 994 | if (adev->ip_blocks[i].version->type == type) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 995 | return &adev->ip_blocks[i]; |
| 996 | |
| 997 | return NULL; |
| 998 | } |
| 999 | |
| 1000 | /** |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 1001 | * amdgpu_device_ip_block_version_cmp |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1002 | * |
| 1003 | * @adev: amdgpu_device pointer |
yanyang1 | 5fc3aee | 2015-05-22 14:39:35 -0400 | [diff] [blame] | 1004 | * @type: enum amd_ip_block_type |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1005 | * @major: major version |
| 1006 | * @minor: minor version |
| 1007 | * |
| 1008 | * return 0 if equal or greater |
| 1009 | * return 1 if smaller or the ip_block doesn't exist |
| 1010 | */ |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 1011 | int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev, |
| 1012 | enum amd_ip_block_type type, |
| 1013 | u32 major, u32 minor) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1014 | { |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 1015 | struct amdgpu_ip_block *ip_block = amdgpu_device_ip_get_ip_block(adev, type); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1016 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1017 | if (ip_block && ((ip_block->version->major > major) || |
| 1018 | ((ip_block->version->major == major) && |
| 1019 | (ip_block->version->minor >= minor)))) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1020 | return 0; |
| 1021 | |
| 1022 | return 1; |
| 1023 | } |
| 1024 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1025 | /** |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 1026 | * amdgpu_device_ip_block_add |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1027 | * |
| 1028 | * @adev: amdgpu_device pointer |
| 1029 | * @ip_block_version: pointer to the IP to add |
| 1030 | * |
| 1031 | * Adds the IP block driver information to the collection of IPs |
| 1032 | * on the asic. |
| 1033 | */ |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 1034 | int amdgpu_device_ip_block_add(struct amdgpu_device *adev, |
| 1035 | const struct amdgpu_ip_block_version *ip_block_version) |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1036 | { |
| 1037 | if (!ip_block_version) |
| 1038 | return -EINVAL; |
| 1039 | |
Shaoyun Liu | e966a72 | 2018-02-01 16:45:26 -0500 | [diff] [blame] | 1040 | DRM_INFO("add ip block number %d <%s>\n", adev->num_ip_blocks, |
Huang Rui | a0bae35 | 2017-05-03 09:52:06 +0800 | [diff] [blame] | 1041 | ip_block_version->funcs->name); |
| 1042 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1043 | adev->ip_blocks[adev->num_ip_blocks++].version = ip_block_version; |
| 1044 | |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
Alex Deucher | 483ef98 | 2016-09-30 12:43:04 -0400 | [diff] [blame] | 1048 | static void amdgpu_device_enable_virtual_display(struct amdgpu_device *adev) |
Emily Deng | 9accf2f | 2016-08-10 16:01:25 +0800 | [diff] [blame] | 1049 | { |
| 1050 | adev->enable_virtual_display = false; |
| 1051 | |
| 1052 | if (amdgpu_virtual_display) { |
| 1053 | struct drm_device *ddev = adev->ddev; |
| 1054 | const char *pci_address_name = pci_name(ddev->pdev); |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 1055 | char *pciaddstr, *pciaddstr_tmp, *pciaddname_tmp, *pciaddname; |
Emily Deng | 9accf2f | 2016-08-10 16:01:25 +0800 | [diff] [blame] | 1056 | |
| 1057 | pciaddstr = kstrdup(amdgpu_virtual_display, GFP_KERNEL); |
| 1058 | pciaddstr_tmp = pciaddstr; |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 1059 | while ((pciaddname_tmp = strsep(&pciaddstr_tmp, ";"))) { |
| 1060 | pciaddname = strsep(&pciaddname_tmp, ","); |
Yintian Tao | 967de2a | 2017-01-22 15:16:51 +0800 | [diff] [blame] | 1061 | if (!strcmp("all", pciaddname) |
| 1062 | || !strcmp(pci_address_name, pciaddname)) { |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 1063 | long num_crtc; |
| 1064 | int res = -1; |
| 1065 | |
Emily Deng | 9accf2f | 2016-08-10 16:01:25 +0800 | [diff] [blame] | 1066 | adev->enable_virtual_display = true; |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 1067 | |
| 1068 | if (pciaddname_tmp) |
| 1069 | res = kstrtol(pciaddname_tmp, 10, |
| 1070 | &num_crtc); |
| 1071 | |
| 1072 | if (!res) { |
| 1073 | if (num_crtc < 1) |
| 1074 | num_crtc = 1; |
| 1075 | if (num_crtc > 6) |
| 1076 | num_crtc = 6; |
| 1077 | adev->mode_info.num_crtc = num_crtc; |
| 1078 | } else { |
| 1079 | adev->mode_info.num_crtc = 1; |
| 1080 | } |
Emily Deng | 9accf2f | 2016-08-10 16:01:25 +0800 | [diff] [blame] | 1081 | break; |
| 1082 | } |
| 1083 | } |
| 1084 | |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 1085 | DRM_INFO("virtual display string:%s, %s:virtual_display:%d, num_crtc:%d\n", |
| 1086 | amdgpu_virtual_display, pci_address_name, |
| 1087 | adev->enable_virtual_display, adev->mode_info.num_crtc); |
Emily Deng | 9accf2f | 2016-08-10 16:01:25 +0800 | [diff] [blame] | 1088 | |
| 1089 | kfree(pciaddstr); |
| 1090 | } |
| 1091 | } |
| 1092 | |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1093 | static int amdgpu_device_parse_gpu_info_fw(struct amdgpu_device *adev) |
| 1094 | { |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1095 | const char *chip_name; |
| 1096 | char fw_name[30]; |
| 1097 | int err; |
| 1098 | const struct gpu_info_firmware_header_v1_0 *hdr; |
| 1099 | |
Huang Rui | ab4fe3e | 2017-06-05 22:11:59 +0800 | [diff] [blame] | 1100 | adev->firmware.gpu_info_fw = NULL; |
| 1101 | |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1102 | switch (adev->asic_type) { |
| 1103 | case CHIP_TOPAZ: |
| 1104 | case CHIP_TONGA: |
| 1105 | case CHIP_FIJI: |
| 1106 | case CHIP_POLARIS11: |
| 1107 | case CHIP_POLARIS10: |
| 1108 | case CHIP_POLARIS12: |
| 1109 | case CHIP_CARRIZO: |
| 1110 | case CHIP_STONEY: |
| 1111 | #ifdef CONFIG_DRM_AMDGPU_SI |
| 1112 | case CHIP_VERDE: |
| 1113 | case CHIP_TAHITI: |
| 1114 | case CHIP_PITCAIRN: |
| 1115 | case CHIP_OLAND: |
| 1116 | case CHIP_HAINAN: |
| 1117 | #endif |
| 1118 | #ifdef CONFIG_DRM_AMDGPU_CIK |
| 1119 | case CHIP_BONAIRE: |
| 1120 | case CHIP_HAWAII: |
| 1121 | case CHIP_KAVERI: |
| 1122 | case CHIP_KABINI: |
| 1123 | case CHIP_MULLINS: |
| 1124 | #endif |
| 1125 | default: |
| 1126 | return 0; |
| 1127 | case CHIP_VEGA10: |
| 1128 | chip_name = "vega10"; |
| 1129 | break; |
Alex Deucher | 2d2e5e7 | 2017-05-09 12:27:35 -0400 | [diff] [blame] | 1130 | case CHIP_RAVEN: |
| 1131 | chip_name = "raven"; |
| 1132 | break; |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_gpu_info.bin", chip_name); |
Huang Rui | ab4fe3e | 2017-06-05 22:11:59 +0800 | [diff] [blame] | 1136 | err = request_firmware(&adev->firmware.gpu_info_fw, fw_name, adev->dev); |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1137 | if (err) { |
| 1138 | dev_err(adev->dev, |
| 1139 | "Failed to load gpu_info firmware \"%s\"\n", |
| 1140 | fw_name); |
| 1141 | goto out; |
| 1142 | } |
Huang Rui | ab4fe3e | 2017-06-05 22:11:59 +0800 | [diff] [blame] | 1143 | err = amdgpu_ucode_validate(adev->firmware.gpu_info_fw); |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1144 | if (err) { |
| 1145 | dev_err(adev->dev, |
| 1146 | "Failed to validate gpu_info firmware \"%s\"\n", |
| 1147 | fw_name); |
| 1148 | goto out; |
| 1149 | } |
| 1150 | |
Huang Rui | ab4fe3e | 2017-06-05 22:11:59 +0800 | [diff] [blame] | 1151 | hdr = (const struct gpu_info_firmware_header_v1_0 *)adev->firmware.gpu_info_fw->data; |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1152 | amdgpu_ucode_print_gpu_info_hdr(&hdr->header); |
| 1153 | |
| 1154 | switch (hdr->version_major) { |
| 1155 | case 1: |
| 1156 | { |
| 1157 | const struct gpu_info_firmware_v1_0 *gpu_info_fw = |
Huang Rui | ab4fe3e | 2017-06-05 22:11:59 +0800 | [diff] [blame] | 1158 | (const struct gpu_info_firmware_v1_0 *)(adev->firmware.gpu_info_fw->data + |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1159 | le32_to_cpu(hdr->header.ucode_array_offset_bytes)); |
| 1160 | |
Alex Deucher | b5ab16b | 2017-05-11 19:09:49 -0400 | [diff] [blame] | 1161 | adev->gfx.config.max_shader_engines = le32_to_cpu(gpu_info_fw->gc_num_se); |
| 1162 | adev->gfx.config.max_cu_per_sh = le32_to_cpu(gpu_info_fw->gc_num_cu_per_sh); |
| 1163 | adev->gfx.config.max_sh_per_se = le32_to_cpu(gpu_info_fw->gc_num_sh_per_se); |
| 1164 | adev->gfx.config.max_backends_per_se = le32_to_cpu(gpu_info_fw->gc_num_rb_per_se); |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1165 | adev->gfx.config.max_texture_channel_caches = |
Alex Deucher | b5ab16b | 2017-05-11 19:09:49 -0400 | [diff] [blame] | 1166 | le32_to_cpu(gpu_info_fw->gc_num_tccs); |
| 1167 | adev->gfx.config.max_gprs = le32_to_cpu(gpu_info_fw->gc_num_gprs); |
| 1168 | adev->gfx.config.max_gs_threads = le32_to_cpu(gpu_info_fw->gc_num_max_gs_thds); |
| 1169 | adev->gfx.config.gs_vgt_table_depth = le32_to_cpu(gpu_info_fw->gc_gs_table_depth); |
| 1170 | adev->gfx.config.gs_prim_buffer_depth = le32_to_cpu(gpu_info_fw->gc_gsprim_buff_depth); |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1171 | adev->gfx.config.double_offchip_lds_buf = |
Alex Deucher | b5ab16b | 2017-05-11 19:09:49 -0400 | [diff] [blame] | 1172 | le32_to_cpu(gpu_info_fw->gc_double_offchip_lds_buffer); |
| 1173 | adev->gfx.cu_info.wave_front_size = le32_to_cpu(gpu_info_fw->gc_wave_size); |
Hawking Zhang | 51fd037 | 2017-06-09 22:30:52 +0800 | [diff] [blame] | 1174 | adev->gfx.cu_info.max_waves_per_simd = |
| 1175 | le32_to_cpu(gpu_info_fw->gc_max_waves_per_simd); |
| 1176 | adev->gfx.cu_info.max_scratch_slots_per_cu = |
| 1177 | le32_to_cpu(gpu_info_fw->gc_max_scratch_slots_per_cu); |
| 1178 | adev->gfx.cu_info.lds_size = le32_to_cpu(gpu_info_fw->gc_lds_size); |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1179 | break; |
| 1180 | } |
| 1181 | default: |
| 1182 | dev_err(adev->dev, |
| 1183 | "Unsupported gpu_info table %d\n", hdr->header.ucode_version); |
| 1184 | err = -EINVAL; |
| 1185 | goto out; |
| 1186 | } |
| 1187 | out: |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1188 | return err; |
| 1189 | } |
| 1190 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1191 | static int amdgpu_device_ip_early_init(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1192 | { |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1193 | int i, r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1194 | |
Alex Deucher | 483ef98 | 2016-09-30 12:43:04 -0400 | [diff] [blame] | 1195 | amdgpu_device_enable_virtual_display(adev); |
Emily Deng | a6be757 | 2016-08-08 11:37:50 +0800 | [diff] [blame] | 1196 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1197 | switch (adev->asic_type) { |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1198 | case CHIP_TOPAZ: |
| 1199 | case CHIP_TONGA: |
David Zhang | 48299f9 | 2015-07-08 01:05:16 +0800 | [diff] [blame] | 1200 | case CHIP_FIJI: |
Flora Cui | 2cc0c0b | 2016-03-14 18:33:29 -0400 | [diff] [blame] | 1201 | case CHIP_POLARIS11: |
| 1202 | case CHIP_POLARIS10: |
Junwei Zhang | c4642a4 | 2016-12-14 15:32:28 -0500 | [diff] [blame] | 1203 | case CHIP_POLARIS12: |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1204 | case CHIP_CARRIZO: |
Samuel Li | 39bb0c9 | 2015-10-08 16:31:43 -0400 | [diff] [blame] | 1205 | case CHIP_STONEY: |
| 1206 | if (adev->asic_type == CHIP_CARRIZO || adev->asic_type == CHIP_STONEY) |
Alex Deucher | aaa36a9 | 2015-04-20 17:31:14 -0400 | [diff] [blame] | 1207 | adev->family = AMDGPU_FAMILY_CZ; |
| 1208 | else |
| 1209 | adev->family = AMDGPU_FAMILY_VI; |
| 1210 | |
| 1211 | r = vi_set_ip_blocks(adev); |
| 1212 | if (r) |
| 1213 | return r; |
| 1214 | break; |
Ken Wang | 33f3480 | 2016-01-21 17:29:41 +0800 | [diff] [blame] | 1215 | #ifdef CONFIG_DRM_AMDGPU_SI |
| 1216 | case CHIP_VERDE: |
| 1217 | case CHIP_TAHITI: |
| 1218 | case CHIP_PITCAIRN: |
| 1219 | case CHIP_OLAND: |
| 1220 | case CHIP_HAINAN: |
Ken Wang | 295d0da | 2016-05-24 21:02:53 +0800 | [diff] [blame] | 1221 | adev->family = AMDGPU_FAMILY_SI; |
Ken Wang | 33f3480 | 2016-01-21 17:29:41 +0800 | [diff] [blame] | 1222 | r = si_set_ip_blocks(adev); |
| 1223 | if (r) |
| 1224 | return r; |
| 1225 | break; |
| 1226 | #endif |
Alex Deucher | a2e73f5 | 2015-04-20 17:09:27 -0400 | [diff] [blame] | 1227 | #ifdef CONFIG_DRM_AMDGPU_CIK |
| 1228 | case CHIP_BONAIRE: |
| 1229 | case CHIP_HAWAII: |
| 1230 | case CHIP_KAVERI: |
| 1231 | case CHIP_KABINI: |
| 1232 | case CHIP_MULLINS: |
| 1233 | if ((adev->asic_type == CHIP_BONAIRE) || (adev->asic_type == CHIP_HAWAII)) |
| 1234 | adev->family = AMDGPU_FAMILY_CI; |
| 1235 | else |
| 1236 | adev->family = AMDGPU_FAMILY_KV; |
| 1237 | |
| 1238 | r = cik_set_ip_blocks(adev); |
| 1239 | if (r) |
| 1240 | return r; |
| 1241 | break; |
| 1242 | #endif |
Chunming Zhou | 2ca8a5d | 2016-12-07 17:31:19 +0800 | [diff] [blame] | 1243 | case CHIP_VEGA10: |
| 1244 | case CHIP_RAVEN: |
| 1245 | if (adev->asic_type == CHIP_RAVEN) |
| 1246 | adev->family = AMDGPU_FAMILY_RV; |
| 1247 | else |
| 1248 | adev->family = AMDGPU_FAMILY_AI; |
Ken Wang | 460826e | 2017-03-06 14:53:16 -0500 | [diff] [blame] | 1249 | |
| 1250 | r = soc15_set_ip_blocks(adev); |
| 1251 | if (r) |
| 1252 | return r; |
| 1253 | break; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1254 | default: |
| 1255 | /* FIXME: not supported yet */ |
| 1256 | return -EINVAL; |
| 1257 | } |
| 1258 | |
Alex Deucher | e2a75f8 | 2017-04-27 16:58:01 -0400 | [diff] [blame] | 1259 | r = amdgpu_device_parse_gpu_info_fw(adev); |
| 1260 | if (r) |
| 1261 | return r; |
| 1262 | |
pding | 1884734 | 2017-11-06 10:21:26 +0800 | [diff] [blame] | 1263 | amdgpu_amdkfd_device_probe(adev); |
| 1264 | |
Xiangliang Yu | 3149d9d | 2017-01-12 15:14:36 +0800 | [diff] [blame] | 1265 | if (amdgpu_sriov_vf(adev)) { |
| 1266 | r = amdgpu_virt_request_full_gpu(adev, true); |
| 1267 | if (r) |
pding | 5ffa61c | 2017-10-30 14:07:24 +0800 | [diff] [blame] | 1268 | return -EAGAIN; |
Xiangliang Yu | 3149d9d | 2017-01-12 15:14:36 +0800 | [diff] [blame] | 1269 | } |
| 1270 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1271 | for (i = 0; i < adev->num_ip_blocks; i++) { |
| 1272 | if ((amdgpu_ip_block_mask & (1 << i)) == 0) { |
Huang Rui | ed8cf00 | 2017-05-03 09:40:17 +0800 | [diff] [blame] | 1273 | DRM_ERROR("disabled ip block: %d <%s>\n", |
| 1274 | i, adev->ip_blocks[i].version->funcs->name); |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1275 | adev->ip_blocks[i].status.valid = false; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1276 | } else { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1277 | if (adev->ip_blocks[i].version->funcs->early_init) { |
| 1278 | r = adev->ip_blocks[i].version->funcs->early_init((void *)adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1279 | if (r == -ENOENT) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1280 | adev->ip_blocks[i].status.valid = false; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1281 | } else if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1282 | DRM_ERROR("early_init of IP block <%s> failed %d\n", |
| 1283 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1284 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1285 | } else { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1286 | adev->ip_blocks[i].status.valid = true; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1287 | } |
Alex Deucher | 974e6b6 | 2015-07-10 13:59:44 -0400 | [diff] [blame] | 1288 | } else { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1289 | adev->ip_blocks[i].status.valid = true; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1290 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1291 | } |
| 1292 | } |
| 1293 | |
Nicolai Hähnle | 395d1fb | 2016-06-02 12:32:07 +0200 | [diff] [blame] | 1294 | adev->cg_flags &= amdgpu_cg_mask; |
| 1295 | adev->pg_flags &= amdgpu_pg_mask; |
| 1296 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1297 | return 0; |
| 1298 | } |
| 1299 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1300 | static int amdgpu_device_ip_init(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1301 | { |
| 1302 | int i, r; |
| 1303 | |
| 1304 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1305 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1306 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1307 | r = adev->ip_blocks[i].version->funcs->sw_init((void *)adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1308 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1309 | DRM_ERROR("sw_init of IP block <%s> failed %d\n", |
| 1310 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1311 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1312 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1313 | adev->ip_blocks[i].status.sw = true; |
Shaoyun Liu | bfca028 | 2018-02-01 17:37:50 -0500 | [diff] [blame] | 1314 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1315 | /* 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] | 1316 | if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) { |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1317 | r = amdgpu_device_vram_scratch_init(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1318 | if (r) { |
| 1319 | DRM_ERROR("amdgpu_vram_scratch_init failed %d\n", r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1320 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1321 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1322 | r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1323 | if (r) { |
| 1324 | DRM_ERROR("hw_init %d failed %d\n", i, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1325 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1326 | } |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1327 | r = amdgpu_device_wb_init(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1328 | if (r) { |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1329 | DRM_ERROR("amdgpu_device_wb_init failed %d\n", r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1330 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1331 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1332 | adev->ip_blocks[i].status.hw = true; |
Monk Liu | 2493664 | 2017-01-09 15:54:32 +0800 | [diff] [blame] | 1333 | |
| 1334 | /* right after GMC hw init, we create CSA */ |
| 1335 | if (amdgpu_sriov_vf(adev)) { |
| 1336 | r = amdgpu_allocate_static_csa(adev); |
| 1337 | if (r) { |
| 1338 | DRM_ERROR("allocate CSA failed %d\n", r); |
| 1339 | return r; |
| 1340 | } |
| 1341 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1346 | if (!adev->ip_blocks[i].status.sw) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1347 | continue; |
Shaoyun Liu | bfca028 | 2018-02-01 17:37:50 -0500 | [diff] [blame] | 1348 | if (adev->ip_blocks[i].status.hw) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1349 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1350 | r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1351 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1352 | DRM_ERROR("hw_init of IP block <%s> failed %d\n", |
| 1353 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1354 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1355 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1356 | adev->ip_blocks[i].status.hw = true; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1357 | } |
| 1358 | |
pding | 1884734 | 2017-11-06 10:21:26 +0800 | [diff] [blame] | 1359 | amdgpu_amdkfd_device_init(adev); |
pding | c6332b9 | 2017-11-06 11:21:55 +0800 | [diff] [blame] | 1360 | |
| 1361 | if (amdgpu_sriov_vf(adev)) |
| 1362 | amdgpu_virt_release_full_gpu(adev, true); |
| 1363 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1364 | return 0; |
| 1365 | } |
| 1366 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1367 | static void amdgpu_device_fill_reset_magic(struct amdgpu_device *adev) |
Chunming Zhou | 0c49e0b | 2017-05-15 14:20:00 +0800 | [diff] [blame] | 1368 | { |
| 1369 | memcpy(adev->reset_magic, adev->gart.ptr, AMDGPU_RESET_MAGIC_NUM); |
| 1370 | } |
| 1371 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1372 | static bool amdgpu_device_check_vram_lost(struct amdgpu_device *adev) |
Chunming Zhou | 0c49e0b | 2017-05-15 14:20:00 +0800 | [diff] [blame] | 1373 | { |
| 1374 | return !!memcmp(adev->gart.ptr, adev->reset_magic, |
| 1375 | AMDGPU_RESET_MAGIC_NUM); |
| 1376 | } |
| 1377 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1378 | static int amdgpu_device_ip_late_set_cg_state(struct amdgpu_device *adev) |
Shirish S | 2dc80b0 | 2017-05-25 10:05:25 +0530 | [diff] [blame] | 1379 | { |
| 1380 | int i = 0, r; |
| 1381 | |
Shaoyun Liu | 4a2ba39 | 2018-02-05 16:41:33 -0500 | [diff] [blame] | 1382 | if (amdgpu_emu_mode == 1) |
| 1383 | return 0; |
| 1384 | |
Shirish S | 2dc80b0 | 2017-05-25 10:05:25 +0530 | [diff] [blame] | 1385 | for (i = 0; i < adev->num_ip_blocks; i++) { |
| 1386 | if (!adev->ip_blocks[i].status.valid) |
| 1387 | continue; |
| 1388 | /* skip CG for VCE/UVD, it's handled specially */ |
| 1389 | if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD && |
| 1390 | adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) { |
| 1391 | /* enable clockgating to save power */ |
| 1392 | r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev, |
| 1393 | AMD_CG_STATE_GATE); |
| 1394 | if (r) { |
| 1395 | DRM_ERROR("set_clockgating_state(gate) of IP block <%s> failed %d\n", |
| 1396 | adev->ip_blocks[i].version->funcs->name, r); |
| 1397 | return r; |
| 1398 | } |
| 1399 | } |
| 1400 | } |
| 1401 | return 0; |
| 1402 | } |
| 1403 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1404 | static int amdgpu_device_ip_late_init(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1405 | { |
| 1406 | int i = 0, r; |
| 1407 | |
| 1408 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1409 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1410 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1411 | if (adev->ip_blocks[i].version->funcs->late_init) { |
| 1412 | r = adev->ip_blocks[i].version->funcs->late_init((void *)adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1413 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1414 | DRM_ERROR("late_init of IP block <%s> failed %d\n", |
| 1415 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1416 | return r; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1417 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1418 | adev->ip_blocks[i].status.late_initialized = true; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1419 | } |
| 1420 | } |
| 1421 | |
Shirish S | 2dc80b0 | 2017-05-25 10:05:25 +0530 | [diff] [blame] | 1422 | mod_delayed_work(system_wq, &adev->late_init_work, |
| 1423 | msecs_to_jiffies(AMDGPU_RESUME_MS)); |
| 1424 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1425 | amdgpu_device_fill_reset_magic(adev); |
Chunming Zhou | 0c49e0b | 2017-05-15 14:20:00 +0800 | [diff] [blame] | 1426 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1427 | return 0; |
| 1428 | } |
| 1429 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1430 | static int amdgpu_device_ip_fini(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1431 | { |
| 1432 | int i, r; |
| 1433 | |
pding | 1884734 | 2017-11-06 10:21:26 +0800 | [diff] [blame] | 1434 | amdgpu_amdkfd_device_fini(adev); |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1435 | /* need to disable SMC first */ |
| 1436 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1437 | if (!adev->ip_blocks[i].status.hw) |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1438 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1439 | if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) { |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1440 | /* 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] | 1441 | r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev, |
| 1442 | AMD_CG_STATE_UNGATE); |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1443 | if (r) { |
| 1444 | 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] | 1445 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1446 | return r; |
| 1447 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1448 | r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev); |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1449 | /* XXX handle errors */ |
| 1450 | if (r) { |
| 1451 | DRM_DEBUG("hw_fini of IP block <%s> failed %d\n", |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1452 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1453 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1454 | adev->ip_blocks[i].status.hw = false; |
Alex Deucher | 3e96dbf | 2016-10-13 11:22:17 -0400 | [diff] [blame] | 1455 | break; |
| 1456 | } |
| 1457 | } |
| 1458 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1459 | for (i = adev->num_ip_blocks - 1; i >= 0; i--) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1460 | if (!adev->ip_blocks[i].status.hw) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1461 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1462 | if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) { |
Monk Liu | 84e5b51 | 2017-11-14 16:52:14 +0800 | [diff] [blame] | 1463 | amdgpu_free_static_csa(adev); |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1464 | amdgpu_device_wb_fini(adev); |
| 1465 | amdgpu_device_vram_scratch_fini(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1466 | } |
Rex Zhu | 8201a67 | 2016-11-24 21:44:44 +0800 | [diff] [blame] | 1467 | |
| 1468 | if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD && |
| 1469 | adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) { |
| 1470 | /* ungate blocks before hw fini so that we can shutdown the blocks safely */ |
| 1471 | r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev, |
| 1472 | AMD_CG_STATE_UNGATE); |
| 1473 | if (r) { |
| 1474 | DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n", |
| 1475 | adev->ip_blocks[i].version->funcs->name, r); |
| 1476 | return r; |
| 1477 | } |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1478 | } |
Rex Zhu | 8201a67 | 2016-11-24 21:44:44 +0800 | [diff] [blame] | 1479 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1480 | r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1481 | /* XXX handle errors */ |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1482 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1483 | DRM_DEBUG("hw_fini of IP block <%s> failed %d\n", |
| 1484 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1485 | } |
Rex Zhu | 8201a67 | 2016-11-24 21:44:44 +0800 | [diff] [blame] | 1486 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1487 | adev->ip_blocks[i].status.hw = false; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1488 | } |
| 1489 | |
Alex Deucher | 9950cda | 2018-01-18 19:05:36 -0500 | [diff] [blame] | 1490 | /* disable all interrupts */ |
| 1491 | amdgpu_irq_disable_all(adev); |
| 1492 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1493 | for (i = adev->num_ip_blocks - 1; i >= 0; i--) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1494 | if (!adev->ip_blocks[i].status.sw) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1495 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1496 | r = adev->ip_blocks[i].version->funcs->sw_fini((void *)adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1497 | /* XXX handle errors */ |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1498 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1499 | DRM_DEBUG("sw_fini of IP block <%s> failed %d\n", |
| 1500 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1501 | } |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1502 | adev->ip_blocks[i].status.sw = false; |
| 1503 | adev->ip_blocks[i].status.valid = false; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1504 | } |
| 1505 | |
Monk Liu | a6dcfd9 | 2016-05-19 14:36:34 +0800 | [diff] [blame] | 1506 | for (i = adev->num_ip_blocks - 1; i >= 0; i--) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1507 | if (!adev->ip_blocks[i].status.late_initialized) |
Grazvydas Ignotas | 8a2eef1 | 2016-10-03 00:06:44 +0300 | [diff] [blame] | 1508 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1509 | if (adev->ip_blocks[i].version->funcs->late_fini) |
| 1510 | adev->ip_blocks[i].version->funcs->late_fini((void *)adev); |
| 1511 | adev->ip_blocks[i].status.late_initialized = false; |
Monk Liu | a6dcfd9 | 2016-05-19 14:36:34 +0800 | [diff] [blame] | 1512 | } |
| 1513 | |
Monk Liu | 030308f | 2017-09-15 15:34:52 +0800 | [diff] [blame] | 1514 | if (amdgpu_sriov_vf(adev)) |
Monk Liu | 2413613 | 2017-11-14 16:56:55 +0800 | [diff] [blame] | 1515 | if (amdgpu_virt_release_full_gpu(adev, false)) |
| 1516 | DRM_ERROR("failed to release exclusive mode on fini\n"); |
Monk Liu | 2493664 | 2017-01-09 15:54:32 +0800 | [diff] [blame] | 1517 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1518 | return 0; |
| 1519 | } |
| 1520 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1521 | static void amdgpu_device_ip_late_init_func_handler(struct work_struct *work) |
Shirish S | 2dc80b0 | 2017-05-25 10:05:25 +0530 | [diff] [blame] | 1522 | { |
| 1523 | struct amdgpu_device *adev = |
| 1524 | container_of(work, struct amdgpu_device, late_init_work.work); |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1525 | amdgpu_device_ip_late_set_cg_state(adev); |
Shirish S | 2dc80b0 | 2017-05-25 10:05:25 +0530 | [diff] [blame] | 1526 | } |
| 1527 | |
Alex Deucher | cdd61df | 2017-12-14 16:47:40 -0500 | [diff] [blame] | 1528 | int amdgpu_device_ip_suspend(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1529 | { |
| 1530 | int i, r; |
| 1531 | |
Xiangliang Yu | e941ea9 | 2017-01-18 12:47:55 +0800 | [diff] [blame] | 1532 | if (amdgpu_sriov_vf(adev)) |
| 1533 | amdgpu_virt_request_full_gpu(adev, false); |
| 1534 | |
Flora Cui | c5a93a2 | 2016-02-26 10:45:25 +0800 | [diff] [blame] | 1535 | /* ungate SMC block first */ |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 1536 | r = amdgpu_device_ip_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_SMC, |
| 1537 | AMD_CG_STATE_UNGATE); |
Flora Cui | c5a93a2 | 2016-02-26 10:45:25 +0800 | [diff] [blame] | 1538 | if (r) { |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 1539 | DRM_ERROR("set_clockgating_state(ungate) SMC failed %d\n", r); |
Flora Cui | c5a93a2 | 2016-02-26 10:45:25 +0800 | [diff] [blame] | 1540 | } |
| 1541 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1542 | for (i = adev->num_ip_blocks - 1; i >= 0; i--) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1543 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1544 | continue; |
| 1545 | /* ungate blocks so that suspend can properly shut them down */ |
Flora Cui | c5a93a2 | 2016-02-26 10:45:25 +0800 | [diff] [blame] | 1546 | if (i != AMD_IP_BLOCK_TYPE_SMC) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1547 | r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev, |
| 1548 | AMD_CG_STATE_UNGATE); |
Flora Cui | c5a93a2 | 2016-02-26 10:45:25 +0800 | [diff] [blame] | 1549 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1550 | DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n", |
| 1551 | adev->ip_blocks[i].version->funcs->name, r); |
Flora Cui | c5a93a2 | 2016-02-26 10:45:25 +0800 | [diff] [blame] | 1552 | } |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1553 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1554 | /* XXX handle errors */ |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1555 | r = adev->ip_blocks[i].version->funcs->suspend(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1556 | /* XXX handle errors */ |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1557 | if (r) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1558 | DRM_ERROR("suspend of IP block <%s> failed %d\n", |
| 1559 | adev->ip_blocks[i].version->funcs->name, r); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1560 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1561 | } |
| 1562 | |
Xiangliang Yu | e941ea9 | 2017-01-18 12:47:55 +0800 | [diff] [blame] | 1563 | if (amdgpu_sriov_vf(adev)) |
| 1564 | amdgpu_virt_release_full_gpu(adev, false); |
| 1565 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1566 | return 0; |
| 1567 | } |
| 1568 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1569 | static int amdgpu_device_ip_reinit_early_sriov(struct amdgpu_device *adev) |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1570 | { |
| 1571 | int i, r; |
| 1572 | |
Monk Liu | 2cb681b | 2017-04-26 12:00:49 +0800 | [diff] [blame] | 1573 | static enum amd_ip_block_type ip_order[] = { |
| 1574 | AMD_IP_BLOCK_TYPE_GMC, |
| 1575 | AMD_IP_BLOCK_TYPE_COMMON, |
Monk Liu | 2cb681b | 2017-04-26 12:00:49 +0800 | [diff] [blame] | 1576 | AMD_IP_BLOCK_TYPE_IH, |
| 1577 | }; |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1578 | |
Monk Liu | 2cb681b | 2017-04-26 12:00:49 +0800 | [diff] [blame] | 1579 | for (i = 0; i < ARRAY_SIZE(ip_order); i++) { |
| 1580 | int j; |
| 1581 | struct amdgpu_ip_block *block; |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1582 | |
Monk Liu | 2cb681b | 2017-04-26 12:00:49 +0800 | [diff] [blame] | 1583 | for (j = 0; j < adev->num_ip_blocks; j++) { |
| 1584 | block = &adev->ip_blocks[j]; |
| 1585 | |
| 1586 | if (block->version->type != ip_order[i] || |
| 1587 | !block->status.valid) |
| 1588 | continue; |
| 1589 | |
| 1590 | r = block->version->funcs->hw_init(adev); |
| 1591 | DRM_INFO("RE-INIT: %s %s\n", block->version->funcs->name, r?"failed":"successed"); |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | return 0; |
| 1596 | } |
| 1597 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1598 | static int amdgpu_device_ip_reinit_late_sriov(struct amdgpu_device *adev) |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1599 | { |
| 1600 | int i, r; |
| 1601 | |
Monk Liu | 2cb681b | 2017-04-26 12:00:49 +0800 | [diff] [blame] | 1602 | static enum amd_ip_block_type ip_order[] = { |
| 1603 | AMD_IP_BLOCK_TYPE_SMC, |
Monk Liu | ef4c166 | 2017-09-22 16:23:34 +0800 | [diff] [blame] | 1604 | AMD_IP_BLOCK_TYPE_PSP, |
Monk Liu | 2cb681b | 2017-04-26 12:00:49 +0800 | [diff] [blame] | 1605 | AMD_IP_BLOCK_TYPE_DCE, |
| 1606 | AMD_IP_BLOCK_TYPE_GFX, |
| 1607 | AMD_IP_BLOCK_TYPE_SDMA, |
Frank Min | 257deb8 | 2017-06-15 20:07:36 +0800 | [diff] [blame] | 1608 | AMD_IP_BLOCK_TYPE_UVD, |
| 1609 | AMD_IP_BLOCK_TYPE_VCE |
Monk Liu | 2cb681b | 2017-04-26 12:00:49 +0800 | [diff] [blame] | 1610 | }; |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1611 | |
Monk Liu | 2cb681b | 2017-04-26 12:00:49 +0800 | [diff] [blame] | 1612 | for (i = 0; i < ARRAY_SIZE(ip_order); i++) { |
| 1613 | int j; |
| 1614 | struct amdgpu_ip_block *block; |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1615 | |
Monk Liu | 2cb681b | 2017-04-26 12:00:49 +0800 | [diff] [blame] | 1616 | for (j = 0; j < adev->num_ip_blocks; j++) { |
| 1617 | block = &adev->ip_blocks[j]; |
| 1618 | |
| 1619 | if (block->version->type != ip_order[i] || |
| 1620 | !block->status.valid) |
| 1621 | continue; |
| 1622 | |
| 1623 | r = block->version->funcs->hw_init(adev); |
| 1624 | DRM_INFO("RE-INIT: %s %s\n", block->version->funcs->name, r?"failed":"successed"); |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 1625 | } |
| 1626 | } |
| 1627 | |
| 1628 | return 0; |
| 1629 | } |
| 1630 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1631 | static int amdgpu_device_ip_resume_phase1(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1632 | { |
| 1633 | int i, r; |
| 1634 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1635 | for (i = 0; i < adev->num_ip_blocks; i++) { |
| 1636 | if (!adev->ip_blocks[i].status.valid) |
| 1637 | continue; |
Chunming Zhou | fcf0649 | 2017-05-05 10:33:33 +0800 | [diff] [blame] | 1638 | if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON || |
| 1639 | adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC || |
| 1640 | adev->ip_blocks[i].version->type == |
| 1641 | AMD_IP_BLOCK_TYPE_IH) { |
| 1642 | r = adev->ip_blocks[i].version->funcs->resume(adev); |
| 1643 | if (r) { |
| 1644 | DRM_ERROR("resume of IP block <%s> failed %d\n", |
| 1645 | adev->ip_blocks[i].version->funcs->name, r); |
| 1646 | return r; |
| 1647 | } |
| 1648 | } |
| 1649 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1650 | |
Chunming Zhou | fcf0649 | 2017-05-05 10:33:33 +0800 | [diff] [blame] | 1651 | return 0; |
| 1652 | } |
| 1653 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1654 | static int amdgpu_device_ip_resume_phase2(struct amdgpu_device *adev) |
Chunming Zhou | fcf0649 | 2017-05-05 10:33:33 +0800 | [diff] [blame] | 1655 | { |
| 1656 | int i, r; |
| 1657 | |
| 1658 | for (i = 0; i < adev->num_ip_blocks; i++) { |
| 1659 | if (!adev->ip_blocks[i].status.valid) |
| 1660 | continue; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1661 | if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON || |
| 1662 | adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC || |
| 1663 | adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_IH ) |
| 1664 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 1665 | r = adev->ip_blocks[i].version->funcs->resume(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1666 | if (r) { |
| 1667 | DRM_ERROR("resume of IP block <%s> failed %d\n", |
| 1668 | adev->ip_blocks[i].version->funcs->name, r); |
| 1669 | return r; |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | return 0; |
| 1674 | } |
| 1675 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1676 | static int amdgpu_device_ip_resume(struct amdgpu_device *adev) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1677 | { |
Chunming Zhou | fcf0649 | 2017-05-05 10:33:33 +0800 | [diff] [blame] | 1678 | int r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1679 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1680 | r = amdgpu_device_ip_resume_phase1(adev); |
Chunming Zhou | fcf0649 | 2017-05-05 10:33:33 +0800 | [diff] [blame] | 1681 | if (r) |
| 1682 | return r; |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1683 | r = amdgpu_device_ip_resume_phase2(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1684 | |
Chunming Zhou | fcf0649 | 2017-05-05 10:33:33 +0800 | [diff] [blame] | 1685 | return r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1686 | } |
| 1687 | |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 1688 | static void amdgpu_device_detect_sriov_bios(struct amdgpu_device *adev) |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 1689 | { |
Monk Liu | 6867e1b | 2017-10-16 19:50:44 +0800 | [diff] [blame] | 1690 | if (amdgpu_sriov_vf(adev)) { |
| 1691 | if (adev->is_atom_fw) { |
| 1692 | if (amdgpu_atomfirmware_gpu_supports_virtualization(adev)) |
| 1693 | adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS; |
| 1694 | } else { |
| 1695 | if (amdgpu_atombios_has_gpu_virtualization_table(adev)) |
| 1696 | adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS; |
| 1697 | } |
| 1698 | |
| 1699 | if (!(adev->virt.caps & AMDGPU_SRIOV_CAPS_SRIOV_VBIOS)) |
| 1700 | amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_NO_VBIOS, 0, 0); |
Alex Deucher | a5bde2f | 2016-09-23 16:23:41 -0400 | [diff] [blame] | 1701 | } |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 1702 | } |
| 1703 | |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 1704 | bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type) |
| 1705 | { |
| 1706 | switch (asic_type) { |
| 1707 | #if defined(CONFIG_DRM_AMD_DC) |
| 1708 | case CHIP_BONAIRE: |
| 1709 | case CHIP_HAWAII: |
Alex Deucher | 0d6fbcc | 2017-08-10 14:39:48 -0400 | [diff] [blame] | 1710 | case CHIP_KAVERI: |
Alex Deucher | 367e668 | 2018-01-25 16:53:25 -0500 | [diff] [blame] | 1711 | case CHIP_KABINI: |
| 1712 | case CHIP_MULLINS: |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 1713 | case CHIP_CARRIZO: |
| 1714 | case CHIP_STONEY: |
| 1715 | case CHIP_POLARIS11: |
| 1716 | case CHIP_POLARIS10: |
Alex Deucher | 2c8ad2d | 2017-06-15 16:20:24 -0400 | [diff] [blame] | 1717 | case CHIP_POLARIS12: |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 1718 | case CHIP_TONGA: |
| 1719 | case CHIP_FIJI: |
| 1720 | #if defined(CONFIG_DRM_AMD_DC_PRE_VEGA) |
| 1721 | return amdgpu_dc != 0; |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 1722 | #endif |
Harry Wentland | 42f8ffa | 2017-09-15 14:07:30 -0400 | [diff] [blame] | 1723 | case CHIP_VEGA10: |
| 1724 | #if defined(CONFIG_DRM_AMD_DC_DCN1_0) |
Hawking Zhang | fd18785 | 2017-03-06 14:01:11 +0800 | [diff] [blame] | 1725 | case CHIP_RAVEN: |
Harry Wentland | 42f8ffa | 2017-09-15 14:07:30 -0400 | [diff] [blame] | 1726 | #endif |
Hawking Zhang | fd18785 | 2017-03-06 14:01:11 +0800 | [diff] [blame] | 1727 | return amdgpu_dc != 0; |
| 1728 | #endif |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 1729 | default: |
| 1730 | return false; |
| 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | /** |
| 1735 | * amdgpu_device_has_dc_support - check if dc is supported |
| 1736 | * |
| 1737 | * @adev: amdgpu_device_pointer |
| 1738 | * |
| 1739 | * Returns true for supported, false for not supported |
| 1740 | */ |
| 1741 | bool amdgpu_device_has_dc_support(struct amdgpu_device *adev) |
| 1742 | { |
Xiangliang Yu | 2555039d | 2017-01-10 17:34:52 +0800 | [diff] [blame] | 1743 | if (amdgpu_sriov_vf(adev)) |
| 1744 | return false; |
| 1745 | |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 1746 | return amdgpu_device_asic_has_dc_support(adev->asic_type); |
| 1747 | } |
| 1748 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1749 | /** |
| 1750 | * amdgpu_device_init - initialize the driver |
| 1751 | * |
| 1752 | * @adev: amdgpu_device pointer |
| 1753 | * @pdev: drm dev pointer |
| 1754 | * @pdev: pci dev pointer |
| 1755 | * @flags: driver flags |
| 1756 | * |
| 1757 | * Initializes the driver info and hw (all asics). |
| 1758 | * Returns 0 for success or an error on failure. |
| 1759 | * Called at driver startup. |
| 1760 | */ |
| 1761 | int amdgpu_device_init(struct amdgpu_device *adev, |
| 1762 | struct drm_device *ddev, |
| 1763 | struct pci_dev *pdev, |
| 1764 | uint32_t flags) |
| 1765 | { |
| 1766 | int r, i; |
| 1767 | bool runtime = false; |
Marek Olšák | 95844d2 | 2016-08-17 23:49:27 +0200 | [diff] [blame] | 1768 | u32 max_MBps; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1769 | |
| 1770 | adev->shutdown = false; |
| 1771 | adev->dev = &pdev->dev; |
| 1772 | adev->ddev = ddev; |
| 1773 | adev->pdev = pdev; |
| 1774 | adev->flags = flags; |
Jammy Zhou | 2f7d10b | 2015-07-22 11:29:01 +0800 | [diff] [blame] | 1775 | adev->asic_type = flags & AMD_ASIC_MASK; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1776 | adev->usec_timeout = AMDGPU_MAX_USEC_TIMEOUT; |
Shaoyun Liu | 593aa2d | 2018-02-07 14:43:13 -0500 | [diff] [blame] | 1777 | if (amdgpu_emu_mode == 1) |
| 1778 | adev->usec_timeout *= 2; |
Christian König | 770d13b | 2018-01-12 14:52:22 +0100 | [diff] [blame] | 1779 | adev->gmc.gart_size = 512 * 1024 * 1024; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1780 | adev->accel_working = false; |
| 1781 | adev->num_rings = 0; |
| 1782 | adev->mman.buffer_funcs = NULL; |
| 1783 | adev->mman.buffer_funcs_ring = NULL; |
| 1784 | adev->vm_manager.vm_pte_funcs = NULL; |
Christian König | 2d55e45 | 2016-02-08 17:37:38 +0100 | [diff] [blame] | 1785 | adev->vm_manager.vm_pte_num_rings = 0; |
Christian König | 132f34e | 2018-01-12 15:26:08 +0100 | [diff] [blame] | 1786 | adev->gmc.gmc_funcs = NULL; |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 1787 | adev->fence_context = dma_fence_context_alloc(AMDGPU_MAX_RINGS); |
Andres Rodriguez | b8866c2 | 2017-04-28 20:05:51 -0400 | [diff] [blame] | 1788 | bitmap_zero(adev->gfx.pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1789 | |
| 1790 | adev->smc_rreg = &amdgpu_invalid_rreg; |
| 1791 | adev->smc_wreg = &amdgpu_invalid_wreg; |
| 1792 | adev->pcie_rreg = &amdgpu_invalid_rreg; |
| 1793 | adev->pcie_wreg = &amdgpu_invalid_wreg; |
Huang Rui | 36b9a95 | 2016-08-31 13:23:25 +0800 | [diff] [blame] | 1794 | adev->pciep_rreg = &amdgpu_invalid_rreg; |
| 1795 | adev->pciep_wreg = &amdgpu_invalid_wreg; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1796 | adev->uvd_ctx_rreg = &amdgpu_invalid_rreg; |
| 1797 | adev->uvd_ctx_wreg = &amdgpu_invalid_wreg; |
| 1798 | adev->didt_rreg = &amdgpu_invalid_rreg; |
| 1799 | adev->didt_wreg = &amdgpu_invalid_wreg; |
Rex Zhu | ccdbb20 | 2016-06-08 12:47:41 +0800 | [diff] [blame] | 1800 | adev->gc_cac_rreg = &amdgpu_invalid_rreg; |
| 1801 | adev->gc_cac_wreg = &amdgpu_invalid_wreg; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1802 | adev->audio_endpt_rreg = &amdgpu_block_invalid_rreg; |
| 1803 | adev->audio_endpt_wreg = &amdgpu_block_invalid_wreg; |
| 1804 | |
Alex Deucher | 3e39ab9 | 2015-06-05 15:04:33 -0400 | [diff] [blame] | 1805 | DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X 0x%02X).\n", |
| 1806 | amdgpu_asic_name[adev->asic_type], pdev->vendor, pdev->device, |
| 1807 | pdev->subsystem_vendor, pdev->subsystem_device, pdev->revision); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1808 | |
| 1809 | /* mutex initialization are all done here so we |
| 1810 | * can recall function without having locking issues */ |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1811 | atomic_set(&adev->irq.ih.lock, 0); |
Huang Rui | 0e5ca0d | 2017-03-03 18:37:23 -0500 | [diff] [blame] | 1812 | mutex_init(&adev->firmware.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1813 | mutex_init(&adev->pm.mutex); |
| 1814 | mutex_init(&adev->gfx.gpu_clock_mutex); |
| 1815 | mutex_init(&adev->srbm_mutex); |
Andres Rodriguez | b8866c2 | 2017-04-28 20:05:51 -0400 | [diff] [blame] | 1816 | mutex_init(&adev->gfx.pipe_reserve_mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1817 | mutex_init(&adev->grbm_idx_mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1818 | mutex_init(&adev->mn_lock); |
Alex Deucher | e23b74a | 2017-09-28 09:47:32 -0400 | [diff] [blame] | 1819 | mutex_init(&adev->virt.vf_errors.lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1820 | hash_init(adev->mn_hash); |
Monk Liu | 13a752e | 2017-10-17 15:11:12 +0800 | [diff] [blame] | 1821 | mutex_init(&adev->lock_reset); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1822 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1823 | amdgpu_device_check_arguments(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1824 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1825 | spin_lock_init(&adev->mmio_idx_lock); |
| 1826 | spin_lock_init(&adev->smc_idx_lock); |
| 1827 | spin_lock_init(&adev->pcie_idx_lock); |
| 1828 | spin_lock_init(&adev->uvd_ctx_idx_lock); |
| 1829 | spin_lock_init(&adev->didt_idx_lock); |
Rex Zhu | ccdbb20 | 2016-06-08 12:47:41 +0800 | [diff] [blame] | 1830 | spin_lock_init(&adev->gc_cac_idx_lock); |
Evan Quan | 16abb5d | 2017-07-04 09:21:50 +0800 | [diff] [blame] | 1831 | spin_lock_init(&adev->se_cac_idx_lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1832 | spin_lock_init(&adev->audio_endpt_idx_lock); |
Marek Olšák | 95844d2 | 2016-08-17 23:49:27 +0200 | [diff] [blame] | 1833 | spin_lock_init(&adev->mm_stats.lock); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1834 | |
Chunming Zhou | 0c4e7fa | 2016-08-17 11:41:30 +0800 | [diff] [blame] | 1835 | INIT_LIST_HEAD(&adev->shadow_list); |
| 1836 | mutex_init(&adev->shadow_list_lock); |
| 1837 | |
Andres Rodriguez | 795f281 | 2017-03-06 16:27:55 -0500 | [diff] [blame] | 1838 | INIT_LIST_HEAD(&adev->ring_lru_list); |
| 1839 | spin_lock_init(&adev->ring_lru_list_lock); |
| 1840 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1841 | INIT_DELAYED_WORK(&adev->late_init_work, |
| 1842 | amdgpu_device_ip_late_init_func_handler); |
Shirish S | 2dc80b0 | 2017-05-25 10:05:25 +0530 | [diff] [blame] | 1843 | |
Alex Xie | 0fa4955 | 2017-06-08 14:58:05 -0400 | [diff] [blame] | 1844 | /* Registers mapping */ |
| 1845 | /* TODO: block userspace mapping of io register */ |
Ken Wang | da69c161 | 2016-01-21 19:08:55 +0800 | [diff] [blame] | 1846 | if (adev->asic_type >= CHIP_BONAIRE) { |
| 1847 | adev->rmmio_base = pci_resource_start(adev->pdev, 5); |
| 1848 | adev->rmmio_size = pci_resource_len(adev->pdev, 5); |
| 1849 | } else { |
| 1850 | adev->rmmio_base = pci_resource_start(adev->pdev, 2); |
| 1851 | adev->rmmio_size = pci_resource_len(adev->pdev, 2); |
| 1852 | } |
Chunming Zhou | 5c1354b | 2016-08-30 16:13:10 +0800 | [diff] [blame] | 1853 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1854 | adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size); |
| 1855 | if (adev->rmmio == NULL) { |
| 1856 | return -ENOMEM; |
| 1857 | } |
| 1858 | DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base); |
| 1859 | DRM_INFO("register mmio size: %u\n", (unsigned)adev->rmmio_size); |
| 1860 | |
Christian König | 705e519 | 2017-06-08 11:15:16 +0200 | [diff] [blame] | 1861 | /* doorbell bar mapping */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1862 | amdgpu_device_doorbell_init(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1863 | |
| 1864 | /* io port mapping */ |
| 1865 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 1866 | if (pci_resource_flags(adev->pdev, i) & IORESOURCE_IO) { |
| 1867 | adev->rio_mem_size = pci_resource_len(adev->pdev, i); |
| 1868 | adev->rio_mem = pci_iomap(adev->pdev, i, adev->rio_mem_size); |
| 1869 | break; |
| 1870 | } |
| 1871 | } |
| 1872 | if (adev->rio_mem == NULL) |
Amber Lin | b64a18c | 2017-01-04 08:06:58 -0500 | [diff] [blame] | 1873 | DRM_INFO("PCI I/O BAR is not found.\n"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1874 | |
| 1875 | /* early init functions */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1876 | r = amdgpu_device_ip_early_init(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1877 | if (r) |
| 1878 | return r; |
| 1879 | |
| 1880 | /* if we have > 1 VGA cards, then disable the amdgpu VGA resources */ |
| 1881 | /* this will fail for cards that aren't VGA class devices, just |
| 1882 | * ignore it */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1883 | vga_client_register(adev->pdev, adev, NULL, amdgpu_device_vga_set_decode); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1884 | |
Alex Deucher | e9bef45 | 2016-04-25 13:12:18 -0400 | [diff] [blame] | 1885 | if (amdgpu_device_is_px(ddev)) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1886 | runtime = true; |
Lukas Wunner | 84c8b22 | 2017-03-10 21:23:45 +0100 | [diff] [blame] | 1887 | if (!pci_is_thunderbolt_attached(adev->pdev)) |
| 1888 | vga_switcheroo_register_client(adev->pdev, |
| 1889 | &amdgpu_switcheroo_ops, runtime); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1890 | if (runtime) |
| 1891 | vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain); |
| 1892 | |
Shaoyun Liu | 9475a94 | 2018-02-01 18:13:23 -0500 | [diff] [blame] | 1893 | if (amdgpu_emu_mode == 1) { |
| 1894 | /* post the asic on emulation mode */ |
| 1895 | emu_soc_asic_init(adev); |
Shaoyun Liu | bfca028 | 2018-02-01 17:37:50 -0500 | [diff] [blame] | 1896 | goto fence_driver_init; |
Shaoyun Liu | 9475a94 | 2018-02-01 18:13:23 -0500 | [diff] [blame] | 1897 | } |
Shaoyun Liu | bfca028 | 2018-02-01 17:37:50 -0500 | [diff] [blame] | 1898 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1899 | /* Read BIOS */ |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1900 | if (!amdgpu_get_bios(adev)) { |
| 1901 | r = -EINVAL; |
| 1902 | goto failed; |
| 1903 | } |
Nils Wallménius | f7e9e9f | 2016-12-14 21:52:45 +0100 | [diff] [blame] | 1904 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1905 | r = amdgpu_atombios_init(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1906 | if (r) { |
| 1907 | dev_err(adev->dev, "amdgpu_atombios_init failed\n"); |
Alex Deucher | e23b74a | 2017-09-28 09:47:32 -0400 | [diff] [blame] | 1908 | amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL, 0, 0); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1909 | goto failed; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1910 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1911 | |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 1912 | /* detect if we are with an SRIOV vbios */ |
| 1913 | amdgpu_device_detect_sriov_bios(adev); |
Andres Rodriguez | 048765a | 2016-06-11 02:51:32 -0400 | [diff] [blame] | 1914 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1915 | /* Post card if necessary */ |
Alex Deucher | 39c640c | 2017-12-15 16:22:11 -0500 | [diff] [blame] | 1916 | if (amdgpu_device_need_post(adev)) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1917 | if (!adev->bios) { |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 1918 | dev_err(adev->dev, "no vBIOS found\n"); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1919 | r = -EINVAL; |
| 1920 | goto failed; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1921 | } |
Monk Liu | bec8637 | 2016-09-14 19:38:08 +0800 | [diff] [blame] | 1922 | DRM_INFO("GPU posting now...\n"); |
Monk Liu | 4e99a44 | 2016-03-31 13:26:59 +0800 | [diff] [blame] | 1923 | r = amdgpu_atom_asic_init(adev->mode_info.atom_context); |
| 1924 | if (r) { |
| 1925 | dev_err(adev->dev, "gpu post error!\n"); |
| 1926 | goto failed; |
| 1927 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1928 | } |
| 1929 | |
Alex Deucher | 88b64e9 | 2017-07-10 10:43:10 -0400 | [diff] [blame] | 1930 | if (adev->is_atom_fw) { |
| 1931 | /* Initialize clocks */ |
| 1932 | r = amdgpu_atomfirmware_get_clock_info(adev); |
| 1933 | if (r) { |
| 1934 | dev_err(adev->dev, "amdgpu_atomfirmware_get_clock_info failed\n"); |
Alex Deucher | e23b74a | 2017-09-28 09:47:32 -0400 | [diff] [blame] | 1935 | amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0); |
Alex Deucher | 88b64e9 | 2017-07-10 10:43:10 -0400 | [diff] [blame] | 1936 | goto failed; |
| 1937 | } |
| 1938 | } else { |
Alex Deucher | a5bde2f | 2016-09-23 16:23:41 -0400 | [diff] [blame] | 1939 | /* Initialize clocks */ |
| 1940 | r = amdgpu_atombios_get_clock_info(adev); |
| 1941 | if (r) { |
| 1942 | dev_err(adev->dev, "amdgpu_atombios_get_clock_info failed\n"); |
Alex Deucher | e23b74a | 2017-09-28 09:47:32 -0400 | [diff] [blame] | 1943 | amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0); |
Gavin Wan | 8904194 | 2017-06-23 13:55:15 -0400 | [diff] [blame] | 1944 | goto failed; |
Alex Deucher | a5bde2f | 2016-09-23 16:23:41 -0400 | [diff] [blame] | 1945 | } |
| 1946 | /* init i2c buses */ |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 1947 | if (!amdgpu_device_has_dc_support(adev)) |
| 1948 | amdgpu_atombios_i2c_init(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1949 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1950 | |
Shaoyun Liu | bfca028 | 2018-02-01 17:37:50 -0500 | [diff] [blame] | 1951 | fence_driver_init: |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1952 | /* Fence driver */ |
| 1953 | r = amdgpu_fence_driver_init(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1954 | if (r) { |
| 1955 | dev_err(adev->dev, "amdgpu_fence_driver_init failed\n"); |
Alex Deucher | e23b74a | 2017-09-28 09:47:32 -0400 | [diff] [blame] | 1956 | amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_FENCE_INIT_FAIL, 0, 0); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1957 | goto failed; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 1958 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1959 | |
| 1960 | /* init the mode config */ |
| 1961 | drm_mode_config_init(adev->ddev); |
| 1962 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1963 | r = amdgpu_device_ip_init(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1964 | if (r) { |
pding | 8840a38 | 2017-10-23 17:22:09 +0800 | [diff] [blame] | 1965 | /* failed in exclusive mode due to timeout */ |
| 1966 | if (amdgpu_sriov_vf(adev) && |
| 1967 | !amdgpu_sriov_runtime(adev) && |
| 1968 | amdgpu_virt_mmio_blocked(adev) && |
| 1969 | !amdgpu_virt_wait_reset(adev)) { |
| 1970 | dev_err(adev->dev, "VF exclusive mode timeout\n"); |
Pixel Ding | 1daee8b | 2017-11-08 11:03:14 +0800 | [diff] [blame] | 1971 | /* Don't send request since VF is inactive. */ |
| 1972 | adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME; |
| 1973 | adev->virt.ops = NULL; |
pding | 8840a38 | 2017-10-23 17:22:09 +0800 | [diff] [blame] | 1974 | r = -EAGAIN; |
| 1975 | goto failed; |
| 1976 | } |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1977 | dev_err(adev->dev, "amdgpu_device_ip_init failed\n"); |
Alex Deucher | e23b74a | 2017-09-28 09:47:32 -0400 | [diff] [blame] | 1978 | amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_INIT_FAIL, 0, 0); |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 1979 | amdgpu_device_ip_fini(adev); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1980 | goto failed; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | adev->accel_working = true; |
| 1984 | |
Alex Xie | e59c020 | 2017-06-01 09:42:59 -0400 | [diff] [blame] | 1985 | amdgpu_vm_check_compute_bug(adev); |
| 1986 | |
Marek Olšák | 95844d2 | 2016-08-17 23:49:27 +0200 | [diff] [blame] | 1987 | /* Initialize the buffer migration limit. */ |
| 1988 | if (amdgpu_moverate >= 0) |
| 1989 | max_MBps = amdgpu_moverate; |
| 1990 | else |
| 1991 | max_MBps = 8; /* Allow 8 MB/s. */ |
| 1992 | /* Get a log2 for easy divisions. */ |
| 1993 | adev->mm_stats.log2_max_MBps = ilog2(max(1u, max_MBps)); |
| 1994 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1995 | r = amdgpu_ib_pool_init(adev); |
| 1996 | if (r) { |
| 1997 | dev_err(adev->dev, "IB initialization failed (%d).\n", r); |
Alex Deucher | e23b74a | 2017-09-28 09:47:32 -0400 | [diff] [blame] | 1998 | amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_IB_INIT_FAIL, 0, r); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 1999 | goto failed; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | r = amdgpu_ib_ring_tests(adev); |
| 2003 | if (r) |
| 2004 | DRM_ERROR("ib ring test failed (%d).\n", r); |
| 2005 | |
Horace Chen | 2dc8f81 | 2017-10-09 16:17:16 +0800 | [diff] [blame] | 2006 | if (amdgpu_sriov_vf(adev)) |
| 2007 | amdgpu_virt_init_data_exchange(adev); |
| 2008 | |
Monk Liu | 9bc92b9 | 2017-02-08 17:38:13 +0800 | [diff] [blame] | 2009 | amdgpu_fbdev_init(adev); |
| 2010 | |
Rex Zhu | d2f52ac | 2017-09-22 17:47:27 +0800 | [diff] [blame] | 2011 | r = amdgpu_pm_sysfs_init(adev); |
| 2012 | if (r) |
| 2013 | DRM_ERROR("registering pm debugfs failed (%d).\n", r); |
| 2014 | |
Alex Deucher | 7575825 | 2017-12-14 15:23:14 -0500 | [diff] [blame] | 2015 | r = amdgpu_debugfs_gem_init(adev); |
Monk Liu | 3f14e62 | 2017-02-09 13:42:27 +0800 | [diff] [blame] | 2016 | if (r) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2017 | DRM_ERROR("registering gem debugfs failed (%d).\n", r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2018 | |
| 2019 | r = amdgpu_debugfs_regs_init(adev); |
Monk Liu | 3f14e62 | 2017-02-09 13:42:27 +0800 | [diff] [blame] | 2020 | if (r) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2021 | DRM_ERROR("registering register debugfs failed (%d).\n", r); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2022 | |
Huang Rui | 50ab253 | 2016-06-12 15:51:09 +0800 | [diff] [blame] | 2023 | r = amdgpu_debugfs_firmware_init(adev); |
Monk Liu | 3f14e62 | 2017-02-09 13:42:27 +0800 | [diff] [blame] | 2024 | if (r) |
Huang Rui | 50ab253 | 2016-06-12 15:51:09 +0800 | [diff] [blame] | 2025 | DRM_ERROR("registering firmware debugfs failed (%d).\n", r); |
Huang Rui | 50ab253 | 2016-06-12 15:51:09 +0800 | [diff] [blame] | 2026 | |
Christian König | 763efb6 | 2017-12-06 15:44:51 +0100 | [diff] [blame] | 2027 | r = amdgpu_debugfs_init(adev); |
Kent Russell | db95e21 | 2017-08-22 12:31:43 -0400 | [diff] [blame] | 2028 | if (r) |
Christian König | 763efb6 | 2017-12-06 15:44:51 +0100 | [diff] [blame] | 2029 | DRM_ERROR("Creating debugfs files failed (%d).\n", r); |
Kent Russell | db95e21 | 2017-08-22 12:31:43 -0400 | [diff] [blame] | 2030 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2031 | if ((amdgpu_testing & 1)) { |
| 2032 | if (adev->accel_working) |
| 2033 | amdgpu_test_moves(adev); |
| 2034 | else |
| 2035 | DRM_INFO("amdgpu: acceleration disabled, skipping move tests\n"); |
| 2036 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2037 | if (amdgpu_benchmarking) { |
| 2038 | if (adev->accel_working) |
| 2039 | amdgpu_benchmark(adev, amdgpu_benchmarking); |
| 2040 | else |
| 2041 | DRM_INFO("amdgpu: acceleration disabled, skipping benchmarks\n"); |
| 2042 | } |
| 2043 | |
| 2044 | /* enable clockgating, etc. after ib tests, etc. since some blocks require |
| 2045 | * explicit gating rather than handling it automatically. |
| 2046 | */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2047 | r = amdgpu_device_ip_late_init(adev); |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 2048 | if (r) { |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2049 | dev_err(adev->dev, "amdgpu_device_ip_late_init failed\n"); |
Alex Deucher | e23b74a | 2017-09-28 09:47:32 -0400 | [diff] [blame] | 2050 | amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_LATE_INIT_FAIL, 0, r); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 2051 | goto failed; |
Alex Deucher | 2c1a278 | 2015-12-07 17:02:53 -0500 | [diff] [blame] | 2052 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2053 | |
| 2054 | return 0; |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 2055 | |
| 2056 | failed: |
Gavin Wan | 8904194 | 2017-06-23 13:55:15 -0400 | [diff] [blame] | 2057 | amdgpu_vf_error_trans_all(adev); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 2058 | if (runtime) |
| 2059 | vga_switcheroo_fini_domain_pm_ops(adev->dev); |
pding | 8840a38 | 2017-10-23 17:22:09 +0800 | [diff] [blame] | 2060 | |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 2061 | return r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2062 | } |
| 2063 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2064 | /** |
| 2065 | * amdgpu_device_fini - tear down the driver |
| 2066 | * |
| 2067 | * @adev: amdgpu_device pointer |
| 2068 | * |
| 2069 | * Tear down the driver info (all asics). |
| 2070 | * Called at driver shutdown. |
| 2071 | */ |
| 2072 | void amdgpu_device_fini(struct amdgpu_device *adev) |
| 2073 | { |
| 2074 | int r; |
| 2075 | |
| 2076 | DRM_INFO("amdgpu: finishing device.\n"); |
| 2077 | adev->shutdown = true; |
Pixel Ding | db2c2a9 | 2017-04-25 16:47:42 +0800 | [diff] [blame] | 2078 | if (adev->mode_info.mode_config_initialized) |
| 2079 | drm_crtc_force_disable_all(adev->ddev); |
Monk Liu | b9141cd | 2017-11-22 19:21:43 +0800 | [diff] [blame] | 2080 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2081 | amdgpu_ib_pool_fini(adev); |
| 2082 | amdgpu_fence_driver_fini(adev); |
| 2083 | amdgpu_fbdev_fini(adev); |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2084 | r = amdgpu_device_ip_fini(adev); |
Huang Rui | ab4fe3e | 2017-06-05 22:11:59 +0800 | [diff] [blame] | 2085 | if (adev->firmware.gpu_info_fw) { |
| 2086 | release_firmware(adev->firmware.gpu_info_fw); |
| 2087 | adev->firmware.gpu_info_fw = NULL; |
| 2088 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2089 | adev->accel_working = false; |
Shirish S | 2dc80b0 | 2017-05-25 10:05:25 +0530 | [diff] [blame] | 2090 | cancel_delayed_work_sync(&adev->late_init_work); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2091 | /* free i2c buses */ |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 2092 | if (!amdgpu_device_has_dc_support(adev)) |
| 2093 | amdgpu_i2c_fini(adev); |
Shaoyun Liu | bfca028 | 2018-02-01 17:37:50 -0500 | [diff] [blame] | 2094 | |
| 2095 | if (amdgpu_emu_mode != 1) |
| 2096 | amdgpu_atombios_fini(adev); |
| 2097 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2098 | kfree(adev->bios); |
| 2099 | adev->bios = NULL; |
Lukas Wunner | 84c8b22 | 2017-03-10 21:23:45 +0100 | [diff] [blame] | 2100 | if (!pci_is_thunderbolt_attached(adev->pdev)) |
| 2101 | vga_switcheroo_unregister_client(adev->pdev); |
Alex Deucher | 83ba126 | 2016-06-03 18:21:41 -0400 | [diff] [blame] | 2102 | if (adev->flags & AMD_IS_PX) |
| 2103 | vga_switcheroo_fini_domain_pm_ops(adev->dev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2104 | vga_client_register(adev->pdev, NULL, NULL, NULL); |
| 2105 | if (adev->rio_mem) |
| 2106 | pci_iounmap(adev->pdev, adev->rio_mem); |
| 2107 | adev->rio_mem = NULL; |
| 2108 | iounmap(adev->rmmio); |
| 2109 | adev->rmmio = NULL; |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2110 | amdgpu_device_doorbell_fini(adev); |
Rex Zhu | d2f52ac | 2017-09-22 17:47:27 +0800 | [diff] [blame] | 2111 | amdgpu_pm_sysfs_fini(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2112 | amdgpu_debugfs_regs_cleanup(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | |
| 2116 | /* |
| 2117 | * Suspend & resume. |
| 2118 | */ |
| 2119 | /** |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 2120 | * amdgpu_device_suspend - initiate device suspend |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2121 | * |
| 2122 | * @pdev: drm dev pointer |
| 2123 | * @state: suspend state |
| 2124 | * |
| 2125 | * Puts the hw in the suspend state (all asics). |
| 2126 | * Returns 0 for success or an error on failure. |
| 2127 | * Called at driver suspend. |
| 2128 | */ |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 2129 | int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2130 | { |
| 2131 | struct amdgpu_device *adev; |
| 2132 | struct drm_crtc *crtc; |
| 2133 | struct drm_connector *connector; |
Alex Deucher | 5ceb54c | 2015-08-05 12:41:48 -0400 | [diff] [blame] | 2134 | int r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2135 | |
| 2136 | if (dev == NULL || dev->dev_private == NULL) { |
| 2137 | return -ENODEV; |
| 2138 | } |
| 2139 | |
| 2140 | adev = dev->dev_private; |
| 2141 | |
| 2142 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
| 2143 | return 0; |
| 2144 | |
| 2145 | drm_kms_helper_poll_disable(dev); |
| 2146 | |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 2147 | if (!amdgpu_device_has_dc_support(adev)) { |
| 2148 | /* turn off display hw */ |
| 2149 | drm_modeset_lock_all(dev); |
| 2150 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 2151 | drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF); |
| 2152 | } |
| 2153 | drm_modeset_unlock_all(dev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2154 | } |
| 2155 | |
Yong Zhao | ba99770 | 2015-11-09 17:21:45 -0500 | [diff] [blame] | 2156 | amdgpu_amdkfd_suspend(adev); |
| 2157 | |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2158 | /* unpin the front buffers and cursors */ |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2159 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2160 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2161 | struct amdgpu_framebuffer *rfb = to_amdgpu_framebuffer(crtc->primary->fb); |
| 2162 | struct amdgpu_bo *robj; |
| 2163 | |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2164 | if (amdgpu_crtc->cursor_bo) { |
| 2165 | struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo); |
Alex Xie | 7a6901d | 2017-04-24 13:52:41 -0400 | [diff] [blame] | 2166 | r = amdgpu_bo_reserve(aobj, true); |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2167 | if (r == 0) { |
| 2168 | amdgpu_bo_unpin(aobj); |
| 2169 | amdgpu_bo_unreserve(aobj); |
| 2170 | } |
| 2171 | } |
| 2172 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2173 | if (rfb == NULL || rfb->obj == NULL) { |
| 2174 | continue; |
| 2175 | } |
| 2176 | robj = gem_to_amdgpu_bo(rfb->obj); |
| 2177 | /* don't unpin kernel fb objects */ |
| 2178 | if (!amdgpu_fbdev_robj_is_fb(adev, robj)) { |
Alex Xie | 7a6901d | 2017-04-24 13:52:41 -0400 | [diff] [blame] | 2179 | r = amdgpu_bo_reserve(robj, true); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2180 | if (r == 0) { |
| 2181 | amdgpu_bo_unpin(robj); |
| 2182 | amdgpu_bo_unreserve(robj); |
| 2183 | } |
| 2184 | } |
| 2185 | } |
| 2186 | /* evict vram memory */ |
| 2187 | amdgpu_bo_evict_vram(adev); |
| 2188 | |
Alex Deucher | 5ceb54c | 2015-08-05 12:41:48 -0400 | [diff] [blame] | 2189 | amdgpu_fence_driver_suspend(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2190 | |
Alex Deucher | cdd61df | 2017-12-14 16:47:40 -0500 | [diff] [blame] | 2191 | r = amdgpu_device_ip_suspend(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2192 | |
Alex Deucher | a0a71e4 | 2016-10-10 12:41:36 -0400 | [diff] [blame] | 2193 | /* evict remaining vram memory |
| 2194 | * This second call to evict vram is to evict the gart page table |
| 2195 | * using the CPU. |
| 2196 | */ |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2197 | amdgpu_bo_evict_vram(adev); |
| 2198 | |
| 2199 | pci_save_state(dev->pdev); |
| 2200 | if (suspend) { |
| 2201 | /* Shut down the device */ |
| 2202 | pci_disable_device(dev->pdev); |
| 2203 | pci_set_power_state(dev->pdev, PCI_D3hot); |
jimqu | 74b0b15 | 2016-09-07 17:09:12 +0800 | [diff] [blame] | 2204 | } else { |
| 2205 | r = amdgpu_asic_reset(adev); |
| 2206 | if (r) |
| 2207 | DRM_ERROR("amdgpu asic reset failed\n"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | if (fbcon) { |
| 2211 | console_lock(); |
| 2212 | amdgpu_fbdev_set_suspend(adev, 1); |
| 2213 | console_unlock(); |
| 2214 | } |
| 2215 | return 0; |
| 2216 | } |
| 2217 | |
| 2218 | /** |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 2219 | * amdgpu_device_resume - initiate device resume |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2220 | * |
| 2221 | * @pdev: drm dev pointer |
| 2222 | * |
| 2223 | * Bring the hw back to operating state (all asics). |
| 2224 | * Returns 0 for success or an error on failure. |
| 2225 | * Called at driver resume. |
| 2226 | */ |
Alex Deucher | 810ddc3 | 2016-08-23 13:25:49 -0400 | [diff] [blame] | 2227 | int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2228 | { |
| 2229 | struct drm_connector *connector; |
| 2230 | struct amdgpu_device *adev = dev->dev_private; |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2231 | struct drm_crtc *crtc; |
Huang Rui | 03161a6 | 2017-04-13 16:12:26 +0800 | [diff] [blame] | 2232 | int r = 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2233 | |
| 2234 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
| 2235 | return 0; |
| 2236 | |
jimqu | 74b0b15 | 2016-09-07 17:09:12 +0800 | [diff] [blame] | 2237 | if (fbcon) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2238 | console_lock(); |
jimqu | 74b0b15 | 2016-09-07 17:09:12 +0800 | [diff] [blame] | 2239 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2240 | if (resume) { |
| 2241 | pci_set_power_state(dev->pdev, PCI_D0); |
| 2242 | pci_restore_state(dev->pdev); |
jimqu | 74b0b15 | 2016-09-07 17:09:12 +0800 | [diff] [blame] | 2243 | r = pci_enable_device(dev->pdev); |
Huang Rui | 03161a6 | 2017-04-13 16:12:26 +0800 | [diff] [blame] | 2244 | if (r) |
| 2245 | goto unlock; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | /* post card */ |
Alex Deucher | 39c640c | 2017-12-15 16:22:11 -0500 | [diff] [blame] | 2249 | if (amdgpu_device_need_post(adev)) { |
jimqu | 74b0b15 | 2016-09-07 17:09:12 +0800 | [diff] [blame] | 2250 | r = amdgpu_atom_asic_init(adev->mode_info.atom_context); |
| 2251 | if (r) |
| 2252 | DRM_ERROR("amdgpu asic init failed\n"); |
| 2253 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2254 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2255 | r = amdgpu_device_ip_resume(adev); |
Rex Zhu | e670721 | 2017-03-30 13:21:01 +0800 | [diff] [blame] | 2256 | if (r) { |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2257 | DRM_ERROR("amdgpu_device_ip_resume failed (%d).\n", r); |
Huang Rui | 03161a6 | 2017-04-13 16:12:26 +0800 | [diff] [blame] | 2258 | goto unlock; |
Rex Zhu | e670721 | 2017-03-30 13:21:01 +0800 | [diff] [blame] | 2259 | } |
Alex Deucher | 5ceb54c | 2015-08-05 12:41:48 -0400 | [diff] [blame] | 2260 | amdgpu_fence_driver_resume(adev); |
| 2261 | |
Flora Cui | ca19852 | 2016-02-04 15:10:08 +0800 | [diff] [blame] | 2262 | if (resume) { |
| 2263 | r = amdgpu_ib_ring_tests(adev); |
| 2264 | if (r) |
| 2265 | DRM_ERROR("ib ring test failed (%d).\n", r); |
| 2266 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2267 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2268 | r = amdgpu_device_ip_late_init(adev); |
Huang Rui | 03161a6 | 2017-04-13 16:12:26 +0800 | [diff] [blame] | 2269 | if (r) |
| 2270 | goto unlock; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2271 | |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2272 | /* pin cursors */ |
| 2273 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 2274 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 2275 | |
| 2276 | if (amdgpu_crtc->cursor_bo) { |
| 2277 | struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo); |
Alex Xie | 7a6901d | 2017-04-24 13:52:41 -0400 | [diff] [blame] | 2278 | r = amdgpu_bo_reserve(aobj, true); |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2279 | if (r == 0) { |
| 2280 | r = amdgpu_bo_pin(aobj, |
| 2281 | AMDGPU_GEM_DOMAIN_VRAM, |
| 2282 | &amdgpu_crtc->cursor_addr); |
| 2283 | if (r != 0) |
| 2284 | DRM_ERROR("Failed to pin cursor BO (%d)\n", r); |
| 2285 | amdgpu_bo_unreserve(aobj); |
| 2286 | } |
| 2287 | } |
| 2288 | } |
Yong Zhao | ba99770 | 2015-11-09 17:21:45 -0500 | [diff] [blame] | 2289 | r = amdgpu_amdkfd_resume(adev); |
| 2290 | if (r) |
| 2291 | return r; |
Alex Deucher | 756e688 | 2015-10-08 00:03:36 -0400 | [diff] [blame] | 2292 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2293 | /* blat the mode back in */ |
| 2294 | if (fbcon) { |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 2295 | if (!amdgpu_device_has_dc_support(adev)) { |
| 2296 | /* pre DCE11 */ |
| 2297 | drm_helper_resume_force_mode(dev); |
| 2298 | |
| 2299 | /* turn on display hw */ |
| 2300 | drm_modeset_lock_all(dev); |
| 2301 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 2302 | drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON); |
| 2303 | } |
| 2304 | drm_modeset_unlock_all(dev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2305 | } |
| 2306 | } |
| 2307 | |
| 2308 | drm_kms_helper_poll_enable(dev); |
Lyude | 23a1a9e | 2016-07-18 11:41:37 -0400 | [diff] [blame] | 2309 | |
| 2310 | /* |
| 2311 | * Most of the connector probing functions try to acquire runtime pm |
| 2312 | * refs to ensure that the GPU is powered on when connector polling is |
| 2313 | * performed. Since we're calling this from a runtime PM callback, |
| 2314 | * trying to acquire rpm refs will cause us to deadlock. |
| 2315 | * |
| 2316 | * Since we're guaranteed to be holding the rpm lock, it's safe to |
| 2317 | * temporarily disable the rpm helpers so this doesn't deadlock us. |
| 2318 | */ |
| 2319 | #ifdef CONFIG_PM |
| 2320 | dev->dev->power.disable_depth++; |
| 2321 | #endif |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 2322 | if (!amdgpu_device_has_dc_support(adev)) |
| 2323 | drm_helper_hpd_irq_event(dev); |
| 2324 | else |
| 2325 | drm_kms_helper_hotplug_event(dev); |
Lyude | 23a1a9e | 2016-07-18 11:41:37 -0400 | [diff] [blame] | 2326 | #ifdef CONFIG_PM |
| 2327 | dev->dev->power.disable_depth--; |
| 2328 | #endif |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2329 | |
Huang Rui | 03161a6 | 2017-04-13 16:12:26 +0800 | [diff] [blame] | 2330 | if (fbcon) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2331 | amdgpu_fbdev_set_suspend(adev, 0); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2332 | |
Huang Rui | 03161a6 | 2017-04-13 16:12:26 +0800 | [diff] [blame] | 2333 | unlock: |
| 2334 | if (fbcon) |
| 2335 | console_unlock(); |
| 2336 | |
| 2337 | return r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2338 | } |
| 2339 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2340 | static bool amdgpu_device_ip_check_soft_reset(struct amdgpu_device *adev) |
Chunming Zhou | 63fbf42 | 2016-07-15 11:19:20 +0800 | [diff] [blame] | 2341 | { |
| 2342 | int i; |
| 2343 | bool asic_hang = false; |
| 2344 | |
Monk Liu | f993d62 | 2017-10-16 19:46:01 +0800 | [diff] [blame] | 2345 | if (amdgpu_sriov_vf(adev)) |
| 2346 | return true; |
| 2347 | |
Chunming Zhou | 63fbf42 | 2016-07-15 11:19:20 +0800 | [diff] [blame] | 2348 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2349 | if (!adev->ip_blocks[i].status.valid) |
Chunming Zhou | 63fbf42 | 2016-07-15 11:19:20 +0800 | [diff] [blame] | 2350 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2351 | if (adev->ip_blocks[i].version->funcs->check_soft_reset) |
| 2352 | adev->ip_blocks[i].status.hang = |
| 2353 | adev->ip_blocks[i].version->funcs->check_soft_reset(adev); |
| 2354 | if (adev->ip_blocks[i].status.hang) { |
| 2355 | 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] | 2356 | asic_hang = true; |
| 2357 | } |
| 2358 | } |
| 2359 | return asic_hang; |
| 2360 | } |
| 2361 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2362 | static int amdgpu_device_ip_pre_soft_reset(struct amdgpu_device *adev) |
Chunming Zhou | d31a501 | 2016-07-18 10:04:34 +0800 | [diff] [blame] | 2363 | { |
| 2364 | int i, r = 0; |
| 2365 | |
| 2366 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2367 | if (!adev->ip_blocks[i].status.valid) |
Chunming Zhou | d31a501 | 2016-07-18 10:04:34 +0800 | [diff] [blame] | 2368 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2369 | if (adev->ip_blocks[i].status.hang && |
| 2370 | adev->ip_blocks[i].version->funcs->pre_soft_reset) { |
| 2371 | r = adev->ip_blocks[i].version->funcs->pre_soft_reset(adev); |
Chunming Zhou | d31a501 | 2016-07-18 10:04:34 +0800 | [diff] [blame] | 2372 | if (r) |
| 2373 | return r; |
| 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | return 0; |
| 2378 | } |
| 2379 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2380 | static bool amdgpu_device_ip_need_full_reset(struct amdgpu_device *adev) |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2381 | { |
Alex Deucher | da146d3 | 2016-10-13 16:07:03 -0400 | [diff] [blame] | 2382 | int i; |
| 2383 | |
| 2384 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2385 | if (!adev->ip_blocks[i].status.valid) |
Alex Deucher | da146d3 | 2016-10-13 16:07:03 -0400 | [diff] [blame] | 2386 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2387 | if ((adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) || |
| 2388 | (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) || |
| 2389 | (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_ACP) || |
Ken Wang | 98512bb | 2017-09-14 16:25:19 +0800 | [diff] [blame] | 2390 | (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_DCE) || |
| 2391 | adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2392 | if (adev->ip_blocks[i].status.hang) { |
Alex Deucher | da146d3 | 2016-10-13 16:07:03 -0400 | [diff] [blame] | 2393 | DRM_INFO("Some block need full reset!\n"); |
| 2394 | return true; |
| 2395 | } |
| 2396 | } |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2397 | } |
| 2398 | return false; |
| 2399 | } |
| 2400 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2401 | static int amdgpu_device_ip_soft_reset(struct amdgpu_device *adev) |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2402 | { |
| 2403 | int i, r = 0; |
| 2404 | |
| 2405 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2406 | if (!adev->ip_blocks[i].status.valid) |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2407 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2408 | if (adev->ip_blocks[i].status.hang && |
| 2409 | adev->ip_blocks[i].version->funcs->soft_reset) { |
| 2410 | r = adev->ip_blocks[i].version->funcs->soft_reset(adev); |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2411 | if (r) |
| 2412 | return r; |
| 2413 | } |
| 2414 | } |
| 2415 | |
| 2416 | return 0; |
| 2417 | } |
| 2418 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2419 | static int amdgpu_device_ip_post_soft_reset(struct amdgpu_device *adev) |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2420 | { |
| 2421 | int i, r = 0; |
| 2422 | |
| 2423 | for (i = 0; i < adev->num_ip_blocks; i++) { |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2424 | if (!adev->ip_blocks[i].status.valid) |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2425 | continue; |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 2426 | if (adev->ip_blocks[i].status.hang && |
| 2427 | adev->ip_blocks[i].version->funcs->post_soft_reset) |
| 2428 | r = adev->ip_blocks[i].version->funcs->post_soft_reset(adev); |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2429 | if (r) |
| 2430 | return r; |
| 2431 | } |
| 2432 | |
| 2433 | return 0; |
| 2434 | } |
| 2435 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2436 | static int amdgpu_device_recover_vram_from_shadow(struct amdgpu_device *adev, |
| 2437 | struct amdgpu_ring *ring, |
| 2438 | struct amdgpu_bo *bo, |
| 2439 | struct dma_fence **fence) |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2440 | { |
| 2441 | uint32_t domain; |
| 2442 | int r; |
| 2443 | |
Roger.He | 23d2e50 | 2017-04-21 14:24:26 +0800 | [diff] [blame] | 2444 | if (!bo->shadow) |
| 2445 | return 0; |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2446 | |
Alex Xie | 1d28479 | 2017-04-24 13:53:04 -0400 | [diff] [blame] | 2447 | r = amdgpu_bo_reserve(bo, true); |
Roger.He | 23d2e50 | 2017-04-21 14:24:26 +0800 | [diff] [blame] | 2448 | if (r) |
| 2449 | return r; |
| 2450 | domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type); |
| 2451 | /* if bo has been evicted, then no need to recover */ |
| 2452 | if (domain == AMDGPU_GEM_DOMAIN_VRAM) { |
Roger.He | 8252131 | 2017-04-21 13:08:43 +0800 | [diff] [blame] | 2453 | r = amdgpu_bo_validate(bo->shadow); |
| 2454 | if (r) { |
| 2455 | DRM_ERROR("bo validate failed!\n"); |
| 2456 | goto err; |
| 2457 | } |
| 2458 | |
Roger.He | 23d2e50 | 2017-04-21 14:24:26 +0800 | [diff] [blame] | 2459 | r = amdgpu_bo_restore_from_shadow(adev, ring, bo, |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2460 | NULL, fence, true); |
Roger.He | 23d2e50 | 2017-04-21 14:24:26 +0800 | [diff] [blame] | 2461 | if (r) { |
| 2462 | DRM_ERROR("recover page table failed!\n"); |
| 2463 | goto err; |
| 2464 | } |
| 2465 | } |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2466 | err: |
Roger.He | 23d2e50 | 2017-04-21 14:24:26 +0800 | [diff] [blame] | 2467 | amdgpu_bo_unreserve(bo); |
| 2468 | return r; |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2469 | } |
| 2470 | |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2471 | /* |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2472 | * amdgpu_device_reset - reset ASIC/GPU for bare-metal or passthrough |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 2473 | * |
| 2474 | * @adev: amdgpu device pointer |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2475 | * @reset_flags: output param tells caller the reset result |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 2476 | * |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2477 | * attempt to do soft-reset or full-reset and reinitialize Asic |
| 2478 | * return 0 means successed otherwise failed |
| 2479 | */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2480 | static int amdgpu_device_reset(struct amdgpu_device *adev, |
| 2481 | uint64_t* reset_flags) |
Monk Liu | a90ad3c | 2017-01-23 14:22:08 +0800 | [diff] [blame] | 2482 | { |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2483 | bool need_full_reset, vram_lost = 0; |
| 2484 | int r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2485 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2486 | need_full_reset = amdgpu_device_ip_need_full_reset(adev); |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2487 | |
| 2488 | if (!need_full_reset) { |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2489 | amdgpu_device_ip_pre_soft_reset(adev); |
| 2490 | r = amdgpu_device_ip_soft_reset(adev); |
| 2491 | amdgpu_device_ip_post_soft_reset(adev); |
| 2492 | if (r || amdgpu_device_ip_check_soft_reset(adev)) { |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2493 | DRM_INFO("soft reset failed, will fallback to full reset!\n"); |
| 2494 | need_full_reset = true; |
| 2495 | } |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2496 | |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | if (need_full_reset) { |
Alex Deucher | cdd61df | 2017-12-14 16:47:40 -0500 | [diff] [blame] | 2500 | r = amdgpu_device_ip_suspend(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2501 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2502 | retry: |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2503 | r = amdgpu_asic_reset(adev); |
| 2504 | /* post card */ |
| 2505 | amdgpu_atom_asic_init(adev->mode_info.atom_context); |
Alex Deucher | bfa9926 | 2016-01-15 11:59:48 -0500 | [diff] [blame] | 2506 | |
Chunming Zhou | 35d782f | 2016-07-15 15:57:13 +0800 | [diff] [blame] | 2507 | if (!r) { |
| 2508 | dev_info(adev->dev, "GPU reset succeeded, trying to resume\n"); |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2509 | r = amdgpu_device_ip_resume_phase1(adev); |
Chunming Zhou | fcf0649 | 2017-05-05 10:33:33 +0800 | [diff] [blame] | 2510 | if (r) |
| 2511 | goto out; |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2512 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2513 | vram_lost = amdgpu_device_check_vram_lost(adev); |
Chunming Zhou | f189213 | 2017-05-15 16:48:27 +0800 | [diff] [blame] | 2514 | if (vram_lost) { |
Chunming Zhou | 0c49e0b | 2017-05-15 14:20:00 +0800 | [diff] [blame] | 2515 | DRM_ERROR("VRAM is lost!\n"); |
Chunming Zhou | f189213 | 2017-05-15 16:48:27 +0800 | [diff] [blame] | 2516 | atomic_inc(&adev->vram_lost_counter); |
| 2517 | } |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2518 | |
Christian König | c1c7ce8 | 2017-10-16 16:50:32 +0200 | [diff] [blame] | 2519 | r = amdgpu_gtt_mgr_recover( |
| 2520 | &adev->mman.bdev.man[TTM_PL_TT]); |
Chunming Zhou | 2c0d731 | 2016-08-30 16:36:25 +0800 | [diff] [blame] | 2521 | if (r) |
Chunming Zhou | fcf0649 | 2017-05-05 10:33:33 +0800 | [diff] [blame] | 2522 | goto out; |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2523 | |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2524 | r = amdgpu_device_ip_resume_phase2(adev); |
Chunming Zhou | fcf0649 | 2017-05-05 10:33:33 +0800 | [diff] [blame] | 2525 | if (r) |
| 2526 | goto out; |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2527 | |
Chunming Zhou | 0c49e0b | 2017-05-15 14:20:00 +0800 | [diff] [blame] | 2528 | if (vram_lost) |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2529 | amdgpu_device_fill_reset_magic(adev); |
Chunming Zhou | 2c0d731 | 2016-08-30 16:36:25 +0800 | [diff] [blame] | 2530 | } |
Chunming Zhou | fcf0649 | 2017-05-05 10:33:33 +0800 | [diff] [blame] | 2531 | } |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2532 | |
Chunming Zhou | fcf0649 | 2017-05-05 10:33:33 +0800 | [diff] [blame] | 2533 | out: |
| 2534 | if (!r) { |
| 2535 | amdgpu_irq_gpu_reset_resume_helper(adev); |
Chunming Zhou | 1f46508 | 2016-06-30 15:02:26 +0800 | [diff] [blame] | 2536 | r = amdgpu_ib_ring_tests(adev); |
| 2537 | if (r) { |
| 2538 | dev_err(adev->dev, "ib ring test failed (%d).\n", r); |
Alex Deucher | cdd61df | 2017-12-14 16:47:40 -0500 | [diff] [blame] | 2539 | r = amdgpu_device_ip_suspend(adev); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2540 | need_full_reset = true; |
Chunming Zhou | 40019dc | 2016-06-29 16:01:49 +0800 | [diff] [blame] | 2541 | goto retry; |
Chunming Zhou | 1f46508 | 2016-06-30 15:02:26 +0800 | [diff] [blame] | 2542 | } |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | if (reset_flags) { |
| 2546 | if (vram_lost) |
| 2547 | (*reset_flags) |= AMDGPU_RESET_INFO_VRAM_LOST; |
| 2548 | |
| 2549 | if (need_full_reset) |
| 2550 | (*reset_flags) |= AMDGPU_RESET_INFO_FULLRESET; |
| 2551 | } |
| 2552 | |
| 2553 | return r; |
| 2554 | } |
| 2555 | |
| 2556 | /* |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2557 | * amdgpu_device_reset_sriov - reset ASIC for SR-IOV vf |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2558 | * |
| 2559 | * @adev: amdgpu device pointer |
| 2560 | * @reset_flags: output param tells caller the reset result |
| 2561 | * |
| 2562 | * do VF FLR and reinitialize Asic |
| 2563 | * return 0 means successed otherwise failed |
| 2564 | */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2565 | static int amdgpu_device_reset_sriov(struct amdgpu_device *adev, |
| 2566 | uint64_t *reset_flags, |
| 2567 | bool from_hypervisor) |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2568 | { |
| 2569 | int r; |
| 2570 | |
| 2571 | if (from_hypervisor) |
| 2572 | r = amdgpu_virt_request_full_gpu(adev, true); |
| 2573 | else |
| 2574 | r = amdgpu_virt_reset_gpu(adev); |
| 2575 | if (r) |
| 2576 | return r; |
| 2577 | |
| 2578 | /* Resume IP prior to SMC */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2579 | r = amdgpu_device_ip_reinit_early_sriov(adev); |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2580 | if (r) |
| 2581 | goto error; |
| 2582 | |
| 2583 | /* we need recover gart prior to run SMC/CP/SDMA resume */ |
Christian König | c1c7ce8 | 2017-10-16 16:50:32 +0200 | [diff] [blame] | 2584 | amdgpu_gtt_mgr_recover(&adev->mman.bdev.man[TTM_PL_TT]); |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2585 | |
| 2586 | /* now we are okay to resume SMC/CP/SDMA */ |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2587 | r = amdgpu_device_ip_reinit_late_sriov(adev); |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2588 | if (r) |
| 2589 | goto error; |
| 2590 | |
| 2591 | amdgpu_irq_gpu_reset_resume_helper(adev); |
| 2592 | r = amdgpu_ib_ring_tests(adev); |
| 2593 | if (r) |
| 2594 | dev_err(adev->dev, "[GPU_RESET] ib ring test failed (%d).\n", r); |
| 2595 | |
| 2596 | error: |
| 2597 | /* release full control of GPU after ib test */ |
| 2598 | amdgpu_virt_release_full_gpu(adev, true); |
| 2599 | |
| 2600 | if (reset_flags) { |
Monk Liu | 75bc609 | 2017-10-30 20:11:54 +0800 | [diff] [blame] | 2601 | if (adev->virt.gim_feature & AMDGIM_FEATURE_GIM_FLR_VRAMLOST) { |
| 2602 | (*reset_flags) |= AMDGPU_RESET_INFO_VRAM_LOST; |
| 2603 | atomic_inc(&adev->vram_lost_counter); |
| 2604 | } |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2605 | |
| 2606 | /* VF FLR or hotlink reset is always full-reset */ |
| 2607 | (*reset_flags) |= AMDGPU_RESET_INFO_FULLRESET; |
| 2608 | } |
| 2609 | |
| 2610 | return r; |
| 2611 | } |
| 2612 | |
| 2613 | /** |
Alex Deucher | 5f152b5 | 2017-12-15 16:40:49 -0500 | [diff] [blame] | 2614 | * amdgpu_device_gpu_recover - reset the asic and recover scheduler |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2615 | * |
| 2616 | * @adev: amdgpu device pointer |
| 2617 | * @job: which job trigger hang |
Andrey Grodzovsky | dcebf02 | 2017-12-12 14:09:30 -0500 | [diff] [blame] | 2618 | * @force forces reset regardless of amdgpu_gpu_recovery |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2619 | * |
| 2620 | * Attempt to reset the GPU if it has hung (all asics). |
| 2621 | * Returns 0 for success or an error on failure. |
| 2622 | */ |
Alex Deucher | 5f152b5 | 2017-12-15 16:40:49 -0500 | [diff] [blame] | 2623 | int amdgpu_device_gpu_recover(struct amdgpu_device *adev, |
| 2624 | struct amdgpu_job *job, bool force) |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2625 | { |
| 2626 | struct drm_atomic_state *state = NULL; |
| 2627 | uint64_t reset_flags = 0; |
| 2628 | int i, r, resched; |
| 2629 | |
Andrey Grodzovsky | 54bc139 | 2018-01-19 17:23:08 -0500 | [diff] [blame] | 2630 | if (!force && !amdgpu_device_ip_check_soft_reset(adev)) { |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2631 | DRM_INFO("No hardware hang detected. Did some blocks stall?\n"); |
| 2632 | return 0; |
| 2633 | } |
| 2634 | |
Andrey Grodzovsky | dcebf02 | 2017-12-12 14:09:30 -0500 | [diff] [blame] | 2635 | if (!force && (amdgpu_gpu_recovery == 0 || |
| 2636 | (amdgpu_gpu_recovery == -1 && !amdgpu_sriov_vf(adev)))) { |
| 2637 | DRM_INFO("GPU recovery disabled.\n"); |
| 2638 | return 0; |
| 2639 | } |
| 2640 | |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2641 | dev_info(adev->dev, "GPU reset begin!\n"); |
| 2642 | |
Monk Liu | 13a752e | 2017-10-17 15:11:12 +0800 | [diff] [blame] | 2643 | mutex_lock(&adev->lock_reset); |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2644 | atomic_inc(&adev->gpu_reset_counter); |
Monk Liu | 13a752e | 2017-10-17 15:11:12 +0800 | [diff] [blame] | 2645 | adev->in_gpu_reset = 1; |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2646 | |
| 2647 | /* block TTM */ |
| 2648 | resched = ttm_bo_lock_delayed_workqueue(&adev->mman.bdev); |
| 2649 | /* store modesetting */ |
| 2650 | if (amdgpu_device_has_dc_support(adev)) |
| 2651 | state = drm_atomic_helper_suspend(adev->ddev); |
| 2652 | |
| 2653 | /* block scheduler */ |
| 2654 | for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { |
| 2655 | struct amdgpu_ring *ring = adev->rings[i]; |
| 2656 | |
| 2657 | if (!ring || !ring->sched.thread) |
| 2658 | continue; |
| 2659 | |
| 2660 | /* only focus on the ring hit timeout if &job not NULL */ |
| 2661 | if (job && job->ring->idx != i) |
| 2662 | continue; |
| 2663 | |
| 2664 | kthread_park(ring->sched.thread); |
Lucas Stach | 1b1f42d | 2017-12-06 17:49:39 +0100 | [diff] [blame] | 2665 | drm_sched_hw_job_reset(&ring->sched, &job->base); |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2666 | |
| 2667 | /* after all hw jobs are reset, hw fence is meaningless, so force_completion */ |
| 2668 | amdgpu_fence_driver_force_completion(ring); |
| 2669 | } |
| 2670 | |
| 2671 | if (amdgpu_sriov_vf(adev)) |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2672 | r = amdgpu_device_reset_sriov(adev, &reset_flags, job ? false : true); |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2673 | else |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2674 | r = amdgpu_device_reset(adev, &reset_flags); |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2675 | |
| 2676 | if (!r) { |
| 2677 | if (((reset_flags & AMDGPU_RESET_INFO_FULLRESET) && !(adev->flags & AMD_IS_APU)) || |
| 2678 | (reset_flags & AMDGPU_RESET_INFO_VRAM_LOST)) { |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2679 | struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring; |
| 2680 | struct amdgpu_bo *bo, *tmp; |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 2681 | struct dma_fence *fence = NULL, *next = NULL; |
Chunming Zhou | 1f46508 | 2016-06-30 15:02:26 +0800 | [diff] [blame] | 2682 | |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2683 | DRM_INFO("recover vram bo from shadow\n"); |
| 2684 | mutex_lock(&adev->shadow_list_lock); |
| 2685 | list_for_each_entry_safe(bo, tmp, &adev->shadow_list, shadow_list) { |
Monk Liu | 236763d | 2017-05-01 16:15:31 +0800 | [diff] [blame] | 2686 | next = NULL; |
Alex Deucher | 06ec907 | 2017-12-14 15:02:39 -0500 | [diff] [blame] | 2687 | amdgpu_device_recover_vram_from_shadow(adev, ring, bo, &next); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2688 | if (fence) { |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 2689 | r = dma_fence_wait(fence, false); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2690 | if (r) { |
Monk Liu | 1d7b17b | 2017-01-22 18:52:56 +0800 | [diff] [blame] | 2691 | WARN(r, "recovery from shadow isn't completed\n"); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2692 | break; |
| 2693 | } |
| 2694 | } |
| 2695 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 2696 | dma_fence_put(fence); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2697 | fence = next; |
| 2698 | } |
| 2699 | mutex_unlock(&adev->shadow_list_lock); |
| 2700 | if (fence) { |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 2701 | r = dma_fence_wait(fence, false); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2702 | if (r) |
Monk Liu | 1d7b17b | 2017-01-22 18:52:56 +0800 | [diff] [blame] | 2703 | WARN(r, "recovery from shadow isn't completed\n"); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2704 | } |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 2705 | dma_fence_put(fence); |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2706 | } |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2707 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2708 | for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { |
| 2709 | struct amdgpu_ring *ring = adev->rings[i]; |
Chunming Zhou | 5168775 | 2017-04-24 17:09:15 +0800 | [diff] [blame] | 2710 | |
| 2711 | if (!ring || !ring->sched.thread) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2712 | continue; |
Chunming Zhou | 53cdccd | 2016-07-21 17:20:52 +0800 | [diff] [blame] | 2713 | |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2714 | /* only focus on the ring hit timeout if &job not NULL */ |
| 2715 | if (job && job->ring->idx != i) |
| 2716 | continue; |
| 2717 | |
Lucas Stach | 1b1f42d | 2017-12-06 17:49:39 +0100 | [diff] [blame] | 2718 | drm_sched_job_recovery(&ring->sched); |
Chunming Zhou | 0875dc9 | 2016-06-12 15:41:58 +0800 | [diff] [blame] | 2719 | kthread_unpark(ring->sched.thread); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2720 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2721 | } else { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2722 | for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2723 | struct amdgpu_ring *ring = adev->rings[i]; |
| 2724 | |
| 2725 | if (!ring || !ring->sched.thread) |
| 2726 | continue; |
| 2727 | |
| 2728 | /* only focus on the ring hit timeout if &job not NULL */ |
| 2729 | if (job && job->ring->idx != i) |
| 2730 | continue; |
| 2731 | |
| 2732 | kthread_unpark(adev->rings[i]->sched.thread); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2733 | } |
| 2734 | } |
| 2735 | |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 2736 | if (amdgpu_device_has_dc_support(adev)) { |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2737 | if (drm_atomic_helper_resume(adev->ddev, state)) |
| 2738 | dev_info(adev->dev, "drm resume failed:%d\n", r); |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2739 | } else { |
Harry Wentland | 4562236 | 2017-09-12 15:58:20 -0400 | [diff] [blame] | 2740 | drm_helper_resume_force_mode(adev->ddev); |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2741 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2742 | |
| 2743 | ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched); |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2744 | |
Gavin Wan | 8904194 | 2017-06-23 13:55:15 -0400 | [diff] [blame] | 2745 | if (r) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2746 | /* bad news, how to tell it to userspace ? */ |
Monk Liu | 5740682 | 2017-10-25 16:37:02 +0800 | [diff] [blame] | 2747 | dev_info(adev->dev, "GPU reset(%d) failed\n", atomic_read(&adev->gpu_reset_counter)); |
| 2748 | amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_GPU_RESET_FAIL, 0, r); |
| 2749 | } else { |
| 2750 | dev_info(adev->dev, "GPU reset(%d) successed!\n",atomic_read(&adev->gpu_reset_counter)); |
Gavin Wan | 8904194 | 2017-06-23 13:55:15 -0400 | [diff] [blame] | 2751 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2752 | |
Gavin Wan | 8904194 | 2017-06-23 13:55:15 -0400 | [diff] [blame] | 2753 | amdgpu_vf_error_trans_all(adev); |
Monk Liu | 13a752e | 2017-10-17 15:11:12 +0800 | [diff] [blame] | 2754 | adev->in_gpu_reset = 0; |
| 2755 | mutex_unlock(&adev->lock_reset); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2756 | return r; |
| 2757 | } |
| 2758 | |
Alex Deucher | 041d9d9 | 2017-12-15 16:49:33 -0500 | [diff] [blame] | 2759 | void amdgpu_device_get_pcie_info(struct amdgpu_device *adev) |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 2760 | { |
| 2761 | u32 mask; |
| 2762 | int ret; |
| 2763 | |
Alex Deucher | cd474ba | 2016-02-04 10:21:23 -0500 | [diff] [blame] | 2764 | if (amdgpu_pcie_gen_cap) |
| 2765 | adev->pm.pcie_gen_mask = amdgpu_pcie_gen_cap; |
| 2766 | |
| 2767 | if (amdgpu_pcie_lane_cap) |
| 2768 | adev->pm.pcie_mlw_mask = amdgpu_pcie_lane_cap; |
| 2769 | |
| 2770 | /* covers APUs as well */ |
| 2771 | if (pci_is_root_bus(adev->pdev->bus)) { |
| 2772 | if (adev->pm.pcie_gen_mask == 0) |
| 2773 | adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK; |
| 2774 | if (adev->pm.pcie_mlw_mask == 0) |
| 2775 | adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK; |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 2776 | return; |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 2777 | } |
Alex Deucher | cd474ba | 2016-02-04 10:21:23 -0500 | [diff] [blame] | 2778 | |
| 2779 | if (adev->pm.pcie_gen_mask == 0) { |
| 2780 | ret = drm_pcie_get_speed_cap_mask(adev->ddev, &mask); |
| 2781 | if (!ret) { |
| 2782 | adev->pm.pcie_gen_mask = (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 | |
| 2783 | CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 | |
| 2784 | CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3); |
| 2785 | |
| 2786 | if (mask & DRM_PCIE_SPEED_25) |
| 2787 | adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1; |
| 2788 | if (mask & DRM_PCIE_SPEED_50) |
| 2789 | adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2; |
| 2790 | if (mask & DRM_PCIE_SPEED_80) |
| 2791 | adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3; |
| 2792 | } else { |
| 2793 | adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK; |
| 2794 | } |
| 2795 | } |
| 2796 | if (adev->pm.pcie_mlw_mask == 0) { |
| 2797 | ret = drm_pcie_get_max_link_width(adev->ddev, &mask); |
| 2798 | if (!ret) { |
| 2799 | switch (mask) { |
| 2800 | case 32: |
| 2801 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 | |
| 2802 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 | |
| 2803 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 | |
| 2804 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 | |
| 2805 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 | |
| 2806 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2807 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2808 | break; |
| 2809 | case 16: |
| 2810 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 | |
| 2811 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 | |
| 2812 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 | |
| 2813 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 | |
| 2814 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2815 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2816 | break; |
| 2817 | case 12: |
| 2818 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 | |
| 2819 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 | |
| 2820 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 | |
| 2821 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2822 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2823 | break; |
| 2824 | case 8: |
| 2825 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 | |
| 2826 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 | |
| 2827 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2828 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2829 | break; |
| 2830 | case 4: |
| 2831 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 | |
| 2832 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2833 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2834 | break; |
| 2835 | case 2: |
| 2836 | adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 | |
| 2837 | CAIL_PCIE_LINK_WIDTH_SUPPORT_X1); |
| 2838 | break; |
| 2839 | case 1: |
| 2840 | adev->pm.pcie_mlw_mask = CAIL_PCIE_LINK_WIDTH_SUPPORT_X1; |
| 2841 | break; |
| 2842 | default: |
| 2843 | break; |
| 2844 | } |
| 2845 | } else { |
| 2846 | adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK; |
Alex Deucher | d0dd7f0 | 2015-11-11 19:45:06 -0500 | [diff] [blame] | 2847 | } |
| 2848 | } |
| 2849 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2850 | |