Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Advanced Micro Devices, Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | * |
| 23 | */ |
Chunming Zhou | 57ff96c | 2015-04-24 17:38:20 +0800 | [diff] [blame] | 24 | #include <linux/list.h> |
| 25 | #include <linux/slab.h> |
Chunming Zhou | 57ff96c | 2015-04-24 17:38:20 +0800 | [diff] [blame] | 26 | #include <drm/drmP.h> |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 27 | #include <linux/firmware.h> |
Chunming Zhou | 57ff96c | 2015-04-24 17:38:20 +0800 | [diff] [blame] | 28 | #include <drm/amdgpu_drm.h> |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 29 | #include "amdgpu.h" |
Chunming Zhou | 25da442 | 2015-05-22 12:14:04 -0400 | [diff] [blame] | 30 | #include "atom.h" |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 31 | #include "amdgpu_ucode.h" |
| 32 | |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 33 | struct amdgpu_cgs_device { |
| 34 | struct cgs_device base; |
| 35 | struct amdgpu_device *adev; |
| 36 | }; |
| 37 | |
| 38 | #define CGS_FUNC_ADEV \ |
| 39 | struct amdgpu_device *adev = \ |
| 40 | ((struct amdgpu_cgs_device *)cgs_device)->adev |
| 41 | |
Rex Zhu | ba89a3e | 2017-09-25 20:45:52 +0800 | [diff] [blame] | 42 | |
Dave Airlie | 110e6f2 | 2016-04-12 13:25:48 +1000 | [diff] [blame] | 43 | static uint32_t amdgpu_cgs_read_register(struct cgs_device *cgs_device, unsigned offset) |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 44 | { |
Chunming Zhou | aba684d | 2015-05-22 11:29:30 -0400 | [diff] [blame] | 45 | CGS_FUNC_ADEV; |
| 46 | return RREG32(offset); |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Dave Airlie | 110e6f2 | 2016-04-12 13:25:48 +1000 | [diff] [blame] | 49 | static void amdgpu_cgs_write_register(struct cgs_device *cgs_device, unsigned offset, |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 50 | uint32_t value) |
| 51 | { |
Chunming Zhou | aba684d | 2015-05-22 11:29:30 -0400 | [diff] [blame] | 52 | CGS_FUNC_ADEV; |
| 53 | WREG32(offset, value); |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 54 | } |
| 55 | |
Dave Airlie | 110e6f2 | 2016-04-12 13:25:48 +1000 | [diff] [blame] | 56 | static uint32_t amdgpu_cgs_read_ind_register(struct cgs_device *cgs_device, |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 57 | enum cgs_ind_reg space, |
| 58 | unsigned index) |
| 59 | { |
Chunming Zhou | aba684d | 2015-05-22 11:29:30 -0400 | [diff] [blame] | 60 | CGS_FUNC_ADEV; |
| 61 | switch (space) { |
| 62 | case CGS_IND_REG__MMIO: |
| 63 | return RREG32_IDX(index); |
| 64 | case CGS_IND_REG__PCIE: |
| 65 | return RREG32_PCIE(index); |
| 66 | case CGS_IND_REG__SMC: |
| 67 | return RREG32_SMC(index); |
| 68 | case CGS_IND_REG__UVD_CTX: |
| 69 | return RREG32_UVD_CTX(index); |
| 70 | case CGS_IND_REG__DIDT: |
| 71 | return RREG32_DIDT(index); |
Rex Zhu | ccdbb20 | 2016-06-08 12:47:41 +0800 | [diff] [blame] | 72 | case CGS_IND_REG_GC_CAC: |
| 73 | return RREG32_GC_CAC(index); |
Evan Quan | c62a59d | 2017-07-04 09:24:34 +0800 | [diff] [blame] | 74 | case CGS_IND_REG_SE_CAC: |
| 75 | return RREG32_SE_CAC(index); |
Chunming Zhou | aba684d | 2015-05-22 11:29:30 -0400 | [diff] [blame] | 76 | case CGS_IND_REG__AUDIO_ENDPT: |
| 77 | DRM_ERROR("audio endpt register access not implemented.\n"); |
| 78 | return 0; |
| 79 | } |
| 80 | WARN(1, "Invalid indirect register space"); |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
Dave Airlie | 110e6f2 | 2016-04-12 13:25:48 +1000 | [diff] [blame] | 84 | static void amdgpu_cgs_write_ind_register(struct cgs_device *cgs_device, |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 85 | enum cgs_ind_reg space, |
| 86 | unsigned index, uint32_t value) |
| 87 | { |
Chunming Zhou | aba684d | 2015-05-22 11:29:30 -0400 | [diff] [blame] | 88 | CGS_FUNC_ADEV; |
| 89 | switch (space) { |
| 90 | case CGS_IND_REG__MMIO: |
| 91 | return WREG32_IDX(index, value); |
| 92 | case CGS_IND_REG__PCIE: |
| 93 | return WREG32_PCIE(index, value); |
| 94 | case CGS_IND_REG__SMC: |
| 95 | return WREG32_SMC(index, value); |
| 96 | case CGS_IND_REG__UVD_CTX: |
| 97 | return WREG32_UVD_CTX(index, value); |
| 98 | case CGS_IND_REG__DIDT: |
| 99 | return WREG32_DIDT(index, value); |
Rex Zhu | ccdbb20 | 2016-06-08 12:47:41 +0800 | [diff] [blame] | 100 | case CGS_IND_REG_GC_CAC: |
| 101 | return WREG32_GC_CAC(index, value); |
Evan Quan | c62a59d | 2017-07-04 09:24:34 +0800 | [diff] [blame] | 102 | case CGS_IND_REG_SE_CAC: |
| 103 | return WREG32_SE_CAC(index, value); |
Chunming Zhou | aba684d | 2015-05-22 11:29:30 -0400 | [diff] [blame] | 104 | case CGS_IND_REG__AUDIO_ENDPT: |
| 105 | DRM_ERROR("audio endpt register access not implemented.\n"); |
| 106 | return; |
| 107 | } |
| 108 | WARN(1, "Invalid indirect register space"); |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 109 | } |
| 110 | |
Dave Airlie | 110e6f2 | 2016-04-12 13:25:48 +1000 | [diff] [blame] | 111 | static uint32_t fw_type_convert(struct cgs_device *cgs_device, uint32_t fw_type) |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 112 | { |
| 113 | CGS_FUNC_ADEV; |
| 114 | enum AMDGPU_UCODE_ID result = AMDGPU_UCODE_ID_MAXIMUM; |
| 115 | |
| 116 | switch (fw_type) { |
| 117 | case CGS_UCODE_ID_SDMA0: |
| 118 | result = AMDGPU_UCODE_ID_SDMA0; |
| 119 | break; |
| 120 | case CGS_UCODE_ID_SDMA1: |
| 121 | result = AMDGPU_UCODE_ID_SDMA1; |
| 122 | break; |
| 123 | case CGS_UCODE_ID_CP_CE: |
| 124 | result = AMDGPU_UCODE_ID_CP_CE; |
| 125 | break; |
| 126 | case CGS_UCODE_ID_CP_PFP: |
| 127 | result = AMDGPU_UCODE_ID_CP_PFP; |
| 128 | break; |
| 129 | case CGS_UCODE_ID_CP_ME: |
| 130 | result = AMDGPU_UCODE_ID_CP_ME; |
| 131 | break; |
| 132 | case CGS_UCODE_ID_CP_MEC: |
| 133 | case CGS_UCODE_ID_CP_MEC_JT1: |
| 134 | result = AMDGPU_UCODE_ID_CP_MEC1; |
| 135 | break; |
| 136 | case CGS_UCODE_ID_CP_MEC_JT2: |
Monk Liu | 4c2b245 | 2016-09-27 16:39:58 +0800 | [diff] [blame] | 137 | /* for VI. JT2 should be the same as JT1, because: |
| 138 | 1, MEC2 and MEC1 use exactly same FW. |
| 139 | 2, JT2 is not pached but JT1 is. |
| 140 | */ |
| 141 | if (adev->asic_type >= CHIP_TOPAZ) |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 142 | result = AMDGPU_UCODE_ID_CP_MEC1; |
Monk Liu | 4c2b245 | 2016-09-27 16:39:58 +0800 | [diff] [blame] | 143 | else |
| 144 | result = AMDGPU_UCODE_ID_CP_MEC2; |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 145 | break; |
| 146 | case CGS_UCODE_ID_RLC_G: |
| 147 | result = AMDGPU_UCODE_ID_RLC_G; |
| 148 | break; |
Monk Liu | bed5712 | 2016-09-26 16:35:03 +0800 | [diff] [blame] | 149 | case CGS_UCODE_ID_STORAGE: |
| 150 | result = AMDGPU_UCODE_ID_STORAGE; |
| 151 | break; |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 152 | default: |
| 153 | DRM_ERROR("Firmware type not supported\n"); |
| 154 | } |
| 155 | return result; |
| 156 | } |
| 157 | |
Frank Min | fc76cbf | 2016-04-27 18:53:29 +0800 | [diff] [blame] | 158 | static uint16_t amdgpu_get_firmware_version(struct cgs_device *cgs_device, |
| 159 | enum cgs_ucode_id type) |
| 160 | { |
| 161 | CGS_FUNC_ADEV; |
Xiangliang Yu | 188a301 | 2016-11-24 16:28:46 +0800 | [diff] [blame] | 162 | uint16_t fw_version = 0; |
Frank Min | fc76cbf | 2016-04-27 18:53:29 +0800 | [diff] [blame] | 163 | |
| 164 | switch (type) { |
| 165 | case CGS_UCODE_ID_SDMA0: |
| 166 | fw_version = adev->sdma.instance[0].fw_version; |
| 167 | break; |
| 168 | case CGS_UCODE_ID_SDMA1: |
| 169 | fw_version = adev->sdma.instance[1].fw_version; |
| 170 | break; |
| 171 | case CGS_UCODE_ID_CP_CE: |
| 172 | fw_version = adev->gfx.ce_fw_version; |
| 173 | break; |
| 174 | case CGS_UCODE_ID_CP_PFP: |
| 175 | fw_version = adev->gfx.pfp_fw_version; |
| 176 | break; |
| 177 | case CGS_UCODE_ID_CP_ME: |
| 178 | fw_version = adev->gfx.me_fw_version; |
| 179 | break; |
| 180 | case CGS_UCODE_ID_CP_MEC: |
| 181 | fw_version = adev->gfx.mec_fw_version; |
| 182 | break; |
| 183 | case CGS_UCODE_ID_CP_MEC_JT1: |
| 184 | fw_version = adev->gfx.mec_fw_version; |
| 185 | break; |
| 186 | case CGS_UCODE_ID_CP_MEC_JT2: |
| 187 | fw_version = adev->gfx.mec_fw_version; |
| 188 | break; |
| 189 | case CGS_UCODE_ID_RLC_G: |
| 190 | fw_version = adev->gfx.rlc_fw_version; |
| 191 | break; |
Xiangliang Yu | 188a301 | 2016-11-24 16:28:46 +0800 | [diff] [blame] | 192 | case CGS_UCODE_ID_STORAGE: |
| 193 | break; |
Frank Min | fc76cbf | 2016-04-27 18:53:29 +0800 | [diff] [blame] | 194 | default: |
| 195 | DRM_ERROR("firmware type %d do not have version\n", type); |
Xiangliang Yu | 188a301 | 2016-11-24 16:28:46 +0800 | [diff] [blame] | 196 | break; |
Frank Min | fc76cbf | 2016-04-27 18:53:29 +0800 | [diff] [blame] | 197 | } |
| 198 | return fw_version; |
| 199 | } |
| 200 | |
Dave Airlie | 110e6f2 | 2016-04-12 13:25:48 +1000 | [diff] [blame] | 201 | static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device, |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 202 | enum cgs_ucode_id type, |
| 203 | struct cgs_firmware_info *info) |
| 204 | { |
| 205 | CGS_FUNC_ADEV; |
| 206 | |
yanyang1 | 735f002 | 2016-02-05 17:39:37 +0800 | [diff] [blame] | 207 | if ((CGS_UCODE_ID_SMU != type) && (CGS_UCODE_ID_SMU_SK != type)) { |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 208 | uint64_t gpu_addr; |
| 209 | uint32_t data_size; |
| 210 | const struct gfx_firmware_header_v1_0 *header; |
| 211 | enum AMDGPU_UCODE_ID id; |
| 212 | struct amdgpu_firmware_info *ucode; |
| 213 | |
| 214 | id = fw_type_convert(cgs_device, type); |
| 215 | ucode = &adev->firmware.ucode[id]; |
| 216 | if (ucode->fw == NULL) |
| 217 | return -EINVAL; |
| 218 | |
| 219 | gpu_addr = ucode->mc_addr; |
| 220 | header = (const struct gfx_firmware_header_v1_0 *)ucode->fw->data; |
| 221 | data_size = le32_to_cpu(header->header.ucode_size_bytes); |
| 222 | |
| 223 | if ((type == CGS_UCODE_ID_CP_MEC_JT1) || |
| 224 | (type == CGS_UCODE_ID_CP_MEC_JT2)) { |
Monk Liu | 4c2b245 | 2016-09-27 16:39:58 +0800 | [diff] [blame] | 225 | gpu_addr += ALIGN(le32_to_cpu(header->header.ucode_size_bytes), PAGE_SIZE); |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 226 | data_size = le32_to_cpu(header->jt_size) << 2; |
| 227 | } |
Monk Liu | 4c2b245 | 2016-09-27 16:39:58 +0800 | [diff] [blame] | 228 | |
| 229 | info->kptr = ucode->kaddr; |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 230 | info->image_size = data_size; |
Monk Liu | 4c2b245 | 2016-09-27 16:39:58 +0800 | [diff] [blame] | 231 | info->mc_addr = gpu_addr; |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 232 | info->version = (uint16_t)le32_to_cpu(header->header.ucode_version); |
Monk Liu | 4c2b245 | 2016-09-27 16:39:58 +0800 | [diff] [blame] | 233 | |
| 234 | if (CGS_UCODE_ID_CP_MEC == type) |
Evan Quan | e68760b | 2017-08-10 15:17:56 +0800 | [diff] [blame] | 235 | info->image_size = le32_to_cpu(header->jt_offset) << 2; |
Monk Liu | 4c2b245 | 2016-09-27 16:39:58 +0800 | [diff] [blame] | 236 | |
Frank Min | fc76cbf | 2016-04-27 18:53:29 +0800 | [diff] [blame] | 237 | info->fw_version = amdgpu_get_firmware_version(cgs_device, type); |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 238 | info->feature_version = (uint16_t)le32_to_cpu(header->ucode_feature_version); |
| 239 | } else { |
| 240 | char fw_name[30] = {0}; |
| 241 | int err = 0; |
| 242 | uint32_t ucode_size; |
| 243 | uint32_t ucode_start_address; |
| 244 | const uint8_t *src; |
| 245 | const struct smc_firmware_header_v1_0 *hdr; |
Huang Rui | d1de1ed | 2017-02-16 11:53:38 +0800 | [diff] [blame] | 246 | const struct common_firmware_header *header; |
| 247 | struct amdgpu_firmware_info *ucode = NULL; |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 248 | |
Mykola Lysenko | 0b45541 | 2016-03-30 05:50:11 -0400 | [diff] [blame] | 249 | if (!adev->pm.fw) { |
| 250 | switch (adev->asic_type) { |
Rex Zhu | 6df9855 | 2017-09-08 14:05:51 +0800 | [diff] [blame] | 251 | case CHIP_TAHITI: |
| 252 | strcpy(fw_name, "radeon/tahiti_smc.bin"); |
| 253 | break; |
| 254 | case CHIP_PITCAIRN: |
| 255 | if ((adev->pdev->revision == 0x81) && |
| 256 | ((adev->pdev->device == 0x6810) || |
| 257 | (adev->pdev->device == 0x6811))) { |
| 258 | info->is_kicker = true; |
| 259 | strcpy(fw_name, "radeon/pitcairn_k_smc.bin"); |
| 260 | } else { |
| 261 | strcpy(fw_name, "radeon/pitcairn_smc.bin"); |
| 262 | } |
| 263 | break; |
| 264 | case CHIP_VERDE: |
| 265 | if (((adev->pdev->device == 0x6820) && |
| 266 | ((adev->pdev->revision == 0x81) || |
| 267 | (adev->pdev->revision == 0x83))) || |
| 268 | ((adev->pdev->device == 0x6821) && |
| 269 | ((adev->pdev->revision == 0x83) || |
| 270 | (adev->pdev->revision == 0x87))) || |
| 271 | ((adev->pdev->revision == 0x87) && |
| 272 | ((adev->pdev->device == 0x6823) || |
| 273 | (adev->pdev->device == 0x682b)))) { |
| 274 | info->is_kicker = true; |
| 275 | strcpy(fw_name, "radeon/verde_k_smc.bin"); |
| 276 | } else { |
| 277 | strcpy(fw_name, "radeon/verde_smc.bin"); |
| 278 | } |
| 279 | break; |
| 280 | case CHIP_OLAND: |
| 281 | if (((adev->pdev->revision == 0x81) && |
| 282 | ((adev->pdev->device == 0x6600) || |
| 283 | (adev->pdev->device == 0x6604) || |
| 284 | (adev->pdev->device == 0x6605) || |
| 285 | (adev->pdev->device == 0x6610))) || |
| 286 | ((adev->pdev->revision == 0x83) && |
| 287 | (adev->pdev->device == 0x6610))) { |
| 288 | info->is_kicker = true; |
| 289 | strcpy(fw_name, "radeon/oland_k_smc.bin"); |
| 290 | } else { |
| 291 | strcpy(fw_name, "radeon/oland_smc.bin"); |
| 292 | } |
| 293 | break; |
| 294 | case CHIP_HAINAN: |
| 295 | if (((adev->pdev->revision == 0x81) && |
| 296 | (adev->pdev->device == 0x6660)) || |
| 297 | ((adev->pdev->revision == 0x83) && |
| 298 | ((adev->pdev->device == 0x6660) || |
| 299 | (adev->pdev->device == 0x6663) || |
| 300 | (adev->pdev->device == 0x6665) || |
| 301 | (adev->pdev->device == 0x6667)))) { |
| 302 | info->is_kicker = true; |
| 303 | strcpy(fw_name, "radeon/hainan_k_smc.bin"); |
| 304 | } else if ((adev->pdev->revision == 0xc3) && |
| 305 | (adev->pdev->device == 0x6665)) { |
| 306 | info->is_kicker = true; |
| 307 | strcpy(fw_name, "radeon/banks_k_2_smc.bin"); |
| 308 | } else { |
| 309 | strcpy(fw_name, "radeon/hainan_smc.bin"); |
| 310 | } |
| 311 | break; |
| 312 | case CHIP_BONAIRE: |
| 313 | if ((adev->pdev->revision == 0x80) || |
| 314 | (adev->pdev->revision == 0x81) || |
| 315 | (adev->pdev->device == 0x665f)) { |
| 316 | info->is_kicker = true; |
| 317 | strcpy(fw_name, "radeon/bonaire_k_smc.bin"); |
| 318 | } else { |
| 319 | strcpy(fw_name, "radeon/bonaire_smc.bin"); |
| 320 | } |
| 321 | break; |
| 322 | case CHIP_HAWAII: |
| 323 | if (adev->pdev->revision == 0x80) { |
| 324 | info->is_kicker = true; |
| 325 | strcpy(fw_name, "radeon/hawaii_k_smc.bin"); |
| 326 | } else { |
| 327 | strcpy(fw_name, "radeon/hawaii_smc.bin"); |
| 328 | } |
| 329 | break; |
Huang Rui | 340efe2 | 2016-06-19 23:55:14 +0800 | [diff] [blame] | 330 | case CHIP_TOPAZ: |
Alex Deucher | 3b49662 | 2016-10-27 18:33:00 -0400 | [diff] [blame] | 331 | if (((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0x81)) || |
| 332 | ((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0x83)) || |
Huang Rui | 5d7213b | 2017-02-10 16:42:19 +0800 | [diff] [blame] | 333 | ((adev->pdev->device == 0x6907) && (adev->pdev->revision == 0x87))) { |
| 334 | info->is_kicker = true; |
Alex Deucher | 3b49662 | 2016-10-27 18:33:00 -0400 | [diff] [blame] | 335 | strcpy(fw_name, "amdgpu/topaz_k_smc.bin"); |
Huang Rui | 5d7213b | 2017-02-10 16:42:19 +0800 | [diff] [blame] | 336 | } else |
Alex Deucher | 3b49662 | 2016-10-27 18:33:00 -0400 | [diff] [blame] | 337 | strcpy(fw_name, "amdgpu/topaz_smc.bin"); |
Huang Rui | 340efe2 | 2016-06-19 23:55:14 +0800 | [diff] [blame] | 338 | break; |
Mykola Lysenko | 0b45541 | 2016-03-30 05:50:11 -0400 | [diff] [blame] | 339 | case CHIP_TONGA: |
Alex Deucher | 646cccb | 2016-10-26 16:41:39 -0400 | [diff] [blame] | 340 | if (((adev->pdev->device == 0x6939) && (adev->pdev->revision == 0xf1)) || |
Huang Rui | 5d7213b | 2017-02-10 16:42:19 +0800 | [diff] [blame] | 341 | ((adev->pdev->device == 0x6938) && (adev->pdev->revision == 0xf1))) { |
| 342 | info->is_kicker = true; |
Alex Deucher | 646cccb | 2016-10-26 16:41:39 -0400 | [diff] [blame] | 343 | strcpy(fw_name, "amdgpu/tonga_k_smc.bin"); |
Huang Rui | 5d7213b | 2017-02-10 16:42:19 +0800 | [diff] [blame] | 344 | } else |
Alex Deucher | 646cccb | 2016-10-26 16:41:39 -0400 | [diff] [blame] | 345 | strcpy(fw_name, "amdgpu/tonga_smc.bin"); |
Mykola Lysenko | 0b45541 | 2016-03-30 05:50:11 -0400 | [diff] [blame] | 346 | break; |
| 347 | case CHIP_FIJI: |
| 348 | strcpy(fw_name, "amdgpu/fiji_smc.bin"); |
| 349 | break; |
| 350 | case CHIP_POLARIS11: |
Alex Deucher | a52d120 | 2017-02-08 22:35:51 -0500 | [diff] [blame] | 351 | if (type == CGS_UCODE_ID_SMU) { |
| 352 | if (((adev->pdev->device == 0x67ef) && |
| 353 | ((adev->pdev->revision == 0xe0) || |
| 354 | (adev->pdev->revision == 0xe2) || |
| 355 | (adev->pdev->revision == 0xe5))) || |
| 356 | ((adev->pdev->device == 0x67ff) && |
| 357 | ((adev->pdev->revision == 0xcf) || |
| 358 | (adev->pdev->revision == 0xef) || |
Huang Rui | 5d7213b | 2017-02-10 16:42:19 +0800 | [diff] [blame] | 359 | (adev->pdev->revision == 0xff)))) { |
| 360 | info->is_kicker = true; |
Alex Deucher | a52d120 | 2017-02-08 22:35:51 -0500 | [diff] [blame] | 361 | strcpy(fw_name, "amdgpu/polaris11_k_smc.bin"); |
Huang Rui | 5d7213b | 2017-02-10 16:42:19 +0800 | [diff] [blame] | 362 | } else |
Alex Deucher | a52d120 | 2017-02-08 22:35:51 -0500 | [diff] [blame] | 363 | strcpy(fw_name, "amdgpu/polaris11_smc.bin"); |
| 364 | } else if (type == CGS_UCODE_ID_SMU_SK) { |
Mykola Lysenko | 0b45541 | 2016-03-30 05:50:11 -0400 | [diff] [blame] | 365 | strcpy(fw_name, "amdgpu/polaris11_smc_sk.bin"); |
Alex Deucher | a52d120 | 2017-02-08 22:35:51 -0500 | [diff] [blame] | 366 | } |
Mykola Lysenko | 0b45541 | 2016-03-30 05:50:11 -0400 | [diff] [blame] | 367 | break; |
| 368 | case CHIP_POLARIS10: |
Alex Deucher | a52d120 | 2017-02-08 22:35:51 -0500 | [diff] [blame] | 369 | if (type == CGS_UCODE_ID_SMU) { |
| 370 | if ((adev->pdev->device == 0x67df) && |
| 371 | ((adev->pdev->revision == 0xe0) || |
| 372 | (adev->pdev->revision == 0xe3) || |
| 373 | (adev->pdev->revision == 0xe4) || |
| 374 | (adev->pdev->revision == 0xe5) || |
| 375 | (adev->pdev->revision == 0xe7) || |
Huang Rui | 5d7213b | 2017-02-10 16:42:19 +0800 | [diff] [blame] | 376 | (adev->pdev->revision == 0xef))) { |
| 377 | info->is_kicker = true; |
Alex Deucher | a52d120 | 2017-02-08 22:35:51 -0500 | [diff] [blame] | 378 | strcpy(fw_name, "amdgpu/polaris10_k_smc.bin"); |
Huang Rui | 5d7213b | 2017-02-10 16:42:19 +0800 | [diff] [blame] | 379 | } else |
Alex Deucher | a52d120 | 2017-02-08 22:35:51 -0500 | [diff] [blame] | 380 | strcpy(fw_name, "amdgpu/polaris10_smc.bin"); |
| 381 | } else if (type == CGS_UCODE_ID_SMU_SK) { |
Mykola Lysenko | 0b45541 | 2016-03-30 05:50:11 -0400 | [diff] [blame] | 382 | strcpy(fw_name, "amdgpu/polaris10_smc_sk.bin"); |
Alex Deucher | a52d120 | 2017-02-08 22:35:51 -0500 | [diff] [blame] | 383 | } |
Mykola Lysenko | 0b45541 | 2016-03-30 05:50:11 -0400 | [diff] [blame] | 384 | break; |
Junwei Zhang | c4642a4 | 2016-12-14 15:32:28 -0500 | [diff] [blame] | 385 | case CHIP_POLARIS12: |
| 386 | strcpy(fw_name, "amdgpu/polaris12_smc.bin"); |
| 387 | break; |
Leo Liu | 5830bb9 | 2017-11-09 13:24:47 -0500 | [diff] [blame] | 388 | case CHIP_VEGAM: |
| 389 | strcpy(fw_name, "amdgpu/vegam_smc.bin"); |
| 390 | break; |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 391 | case CHIP_VEGA10: |
Evan Quan | 747f6c9 | 2017-06-23 15:08:15 +0800 | [diff] [blame] | 392 | if ((adev->pdev->device == 0x687f) && |
| 393 | ((adev->pdev->revision == 0xc0) || |
| 394 | (adev->pdev->revision == 0xc1) || |
| 395 | (adev->pdev->revision == 0xc3))) |
| 396 | strcpy(fw_name, "amdgpu/vega10_acg_smc.bin"); |
| 397 | else |
| 398 | strcpy(fw_name, "amdgpu/vega10_smc.bin"); |
Ken Wang | 220ab9b | 2017-03-06 14:49:53 -0500 | [diff] [blame] | 399 | break; |
Hawking Zhang | ad0ad9a | 2018-03-19 14:11:09 -0500 | [diff] [blame] | 400 | case CHIP_VEGA12: |
| 401 | strcpy(fw_name, "amdgpu/vega12_smc.bin"); |
| 402 | break; |
Mykola Lysenko | 0b45541 | 2016-03-30 05:50:11 -0400 | [diff] [blame] | 403 | default: |
| 404 | DRM_ERROR("SMC firmware not supported\n"); |
| 405 | return -EINVAL; |
| 406 | } |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 407 | |
Mykola Lysenko | 0b45541 | 2016-03-30 05:50:11 -0400 | [diff] [blame] | 408 | err = request_firmware(&adev->pm.fw, fw_name, adev->dev); |
| 409 | if (err) { |
| 410 | DRM_ERROR("Failed to request firmware\n"); |
| 411 | return err; |
| 412 | } |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 413 | |
Mykola Lysenko | 0b45541 | 2016-03-30 05:50:11 -0400 | [diff] [blame] | 414 | err = amdgpu_ucode_validate(adev->pm.fw); |
| 415 | if (err) { |
| 416 | DRM_ERROR("Failed to load firmware \"%s\"", fw_name); |
| 417 | release_firmware(adev->pm.fw); |
| 418 | adev->pm.fw = NULL; |
| 419 | return err; |
| 420 | } |
Huang Rui | d1de1ed | 2017-02-16 11:53:38 +0800 | [diff] [blame] | 421 | |
| 422 | if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) { |
| 423 | ucode = &adev->firmware.ucode[AMDGPU_UCODE_ID_SMC]; |
| 424 | ucode->ucode_id = AMDGPU_UCODE_ID_SMC; |
| 425 | ucode->fw = adev->pm.fw; |
| 426 | header = (const struct common_firmware_header *)ucode->fw->data; |
| 427 | adev->firmware.fw_size += |
| 428 | ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE); |
| 429 | } |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data; |
yanyang1 | c66875b | 2016-05-30 15:30:54 +0800 | [diff] [blame] | 433 | amdgpu_ucode_print_smc_hdr(&hdr->header); |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 434 | adev->pm.fw_version = le32_to_cpu(hdr->header.ucode_version); |
| 435 | ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes); |
| 436 | ucode_start_address = le32_to_cpu(hdr->ucode_start_addr); |
| 437 | src = (const uint8_t *)(adev->pm.fw->data + |
| 438 | le32_to_cpu(hdr->header.ucode_array_offset_bytes)); |
| 439 | |
| 440 | info->version = adev->pm.fw_version; |
| 441 | info->image_size = ucode_size; |
Huang Rui | 340efe2 | 2016-06-19 23:55:14 +0800 | [diff] [blame] | 442 | info->ucode_start_address = ucode_start_address; |
Jammy Zhou | bf3911b0 | 2015-05-13 18:58:05 +0800 | [diff] [blame] | 443 | info->kptr = (void *)src; |
| 444 | } |
| 445 | return 0; |
| 446 | } |
| 447 | |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 448 | static const struct cgs_ops amdgpu_cgs_ops = { |
Kees Cook | 613e61a | 2016-12-16 17:02:32 -0800 | [diff] [blame] | 449 | .read_register = amdgpu_cgs_read_register, |
| 450 | .write_register = amdgpu_cgs_write_register, |
| 451 | .read_ind_register = amdgpu_cgs_read_ind_register, |
| 452 | .write_ind_register = amdgpu_cgs_write_ind_register, |
Kees Cook | 613e61a | 2016-12-16 17:02:32 -0800 | [diff] [blame] | 453 | .get_firmware_info = amdgpu_cgs_get_firmware_info, |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 454 | }; |
| 455 | |
Dave Airlie | 110e6f2 | 2016-04-12 13:25:48 +1000 | [diff] [blame] | 456 | struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev) |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 457 | { |
| 458 | struct amdgpu_cgs_device *cgs_device = |
| 459 | kmalloc(sizeof(*cgs_device), GFP_KERNEL); |
| 460 | |
| 461 | if (!cgs_device) { |
| 462 | DRM_ERROR("Couldn't allocate CGS device structure\n"); |
| 463 | return NULL; |
| 464 | } |
| 465 | |
| 466 | cgs_device->base.ops = &amdgpu_cgs_ops; |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 467 | cgs_device->adev = adev; |
| 468 | |
Dave Airlie | 110e6f2 | 2016-04-12 13:25:48 +1000 | [diff] [blame] | 469 | return (struct cgs_device *)cgs_device; |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 470 | } |
| 471 | |
Dave Airlie | 110e6f2 | 2016-04-12 13:25:48 +1000 | [diff] [blame] | 472 | void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device) |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 473 | { |
| 474 | kfree(cgs_device); |
| 475 | } |