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