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