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