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