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