1*e4a580baSriastradh /* $NetBSD: amdgpu_cgs.c,v 1.7 2021/12/19 10:59:01 riastradh Exp $ */
2efa246c0Sriastradh
3efa246c0Sriastradh /*
4efa246c0Sriastradh * Copyright 2015 Advanced Micro Devices, Inc.
5efa246c0Sriastradh *
6efa246c0Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
7efa246c0Sriastradh * copy of this software and associated documentation files (the "Software"),
8efa246c0Sriastradh * to deal in the Software without restriction, including without limitation
9efa246c0Sriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10efa246c0Sriastradh * and/or sell copies of the Software, and to permit persons to whom the
11efa246c0Sriastradh * Software is furnished to do so, subject to the following conditions:
12efa246c0Sriastradh *
13efa246c0Sriastradh * The above copyright notice and this permission notice shall be included in
14efa246c0Sriastradh * all copies or substantial portions of the Software.
15efa246c0Sriastradh *
16efa246c0Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17efa246c0Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18efa246c0Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19efa246c0Sriastradh * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20efa246c0Sriastradh * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21efa246c0Sriastradh * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22efa246c0Sriastradh * OTHER DEALINGS IN THE SOFTWARE.
23efa246c0Sriastradh *
24efa246c0Sriastradh *
25efa246c0Sriastradh */
26efa246c0Sriastradh #include <sys/cdefs.h>
27*e4a580baSriastradh __KERNEL_RCSID(0, "$NetBSD: amdgpu_cgs.c,v 1.7 2021/12/19 10:59:01 riastradh Exp $");
28efa246c0Sriastradh
29efa246c0Sriastradh #include <linux/list.h>
30efa246c0Sriastradh #include <linux/pci.h>
3141ec0267Sriastradh #include <linux/slab.h>
3241ec0267Sriastradh
33efa246c0Sriastradh #include <linux/firmware.h>
34efa246c0Sriastradh #include <drm/amdgpu_drm.h>
35efa246c0Sriastradh #include "amdgpu.h"
36efa246c0Sriastradh #include "atom.h"
37efa246c0Sriastradh #include "amdgpu_ucode.h"
38efa246c0Sriastradh
39*e4a580baSriastradh #include <linux/nbsd-namespace.h>
40*e4a580baSriastradh
41efa246c0Sriastradh struct amdgpu_cgs_device {
42efa246c0Sriastradh struct cgs_device base;
43efa246c0Sriastradh struct amdgpu_device *adev;
44efa246c0Sriastradh };
45efa246c0Sriastradh
46efa246c0Sriastradh #define CGS_FUNC_ADEV \
47efa246c0Sriastradh struct amdgpu_device *adev = \
48efa246c0Sriastradh ((struct amdgpu_cgs_device *)cgs_device)->adev
49efa246c0Sriastradh
50efa246c0Sriastradh
amdgpu_cgs_read_register(struct cgs_device * cgs_device,unsigned offset)5141ec0267Sriastradh static uint32_t amdgpu_cgs_read_register(struct cgs_device *cgs_device, unsigned offset)
52efa246c0Sriastradh {
53efa246c0Sriastradh CGS_FUNC_ADEV;
54efa246c0Sriastradh return RREG32(offset);
55efa246c0Sriastradh }
56efa246c0Sriastradh
amdgpu_cgs_write_register(struct cgs_device * cgs_device,unsigned offset,uint32_t value)5741ec0267Sriastradh static void amdgpu_cgs_write_register(struct cgs_device *cgs_device, unsigned offset,
58efa246c0Sriastradh uint32_t value)
59efa246c0Sriastradh {
60efa246c0Sriastradh CGS_FUNC_ADEV;
61efa246c0Sriastradh WREG32(offset, value);
62efa246c0Sriastradh }
63efa246c0Sriastradh
amdgpu_cgs_read_ind_register(struct cgs_device * cgs_device,enum cgs_ind_reg space,unsigned index)6441ec0267Sriastradh static uint32_t amdgpu_cgs_read_ind_register(struct cgs_device *cgs_device,
65efa246c0Sriastradh enum cgs_ind_reg space,
66efa246c0Sriastradh unsigned index)
67efa246c0Sriastradh {
68efa246c0Sriastradh CGS_FUNC_ADEV;
69efa246c0Sriastradh switch (space) {
70efa246c0Sriastradh case CGS_IND_REG__MMIO:
71efa246c0Sriastradh return RREG32_IDX(index);
72efa246c0Sriastradh case CGS_IND_REG__PCIE:
73efa246c0Sriastradh return RREG32_PCIE(index);
74efa246c0Sriastradh case CGS_IND_REG__SMC:
75efa246c0Sriastradh return RREG32_SMC(index);
76efa246c0Sriastradh case CGS_IND_REG__UVD_CTX:
77efa246c0Sriastradh return RREG32_UVD_CTX(index);
78efa246c0Sriastradh case CGS_IND_REG__DIDT:
79efa246c0Sriastradh return RREG32_DIDT(index);
8041ec0267Sriastradh case CGS_IND_REG_GC_CAC:
8141ec0267Sriastradh return RREG32_GC_CAC(index);
8241ec0267Sriastradh case CGS_IND_REG_SE_CAC:
8341ec0267Sriastradh return RREG32_SE_CAC(index);
84efa246c0Sriastradh case CGS_IND_REG__AUDIO_ENDPT:
85efa246c0Sriastradh DRM_ERROR("audio endpt register access not implemented.\n");
86efa246c0Sriastradh return 0;
87efa246c0Sriastradh }
88efa246c0Sriastradh WARN(1, "Invalid indirect register space");
89efa246c0Sriastradh return 0;
90efa246c0Sriastradh }
91efa246c0Sriastradh
amdgpu_cgs_write_ind_register(struct cgs_device * cgs_device,enum cgs_ind_reg space,unsigned index,uint32_t value)9241ec0267Sriastradh static void amdgpu_cgs_write_ind_register(struct cgs_device *cgs_device,
93efa246c0Sriastradh enum cgs_ind_reg space,
94efa246c0Sriastradh unsigned index, uint32_t value)
95efa246c0Sriastradh {
96efa246c0Sriastradh CGS_FUNC_ADEV;
97efa246c0Sriastradh switch (space) {
98efa246c0Sriastradh case CGS_IND_REG__MMIO:
99efa246c0Sriastradh return WREG32_IDX(index, value);
100efa246c0Sriastradh case CGS_IND_REG__PCIE:
101efa246c0Sriastradh return WREG32_PCIE(index, value);
102efa246c0Sriastradh case CGS_IND_REG__SMC:
103efa246c0Sriastradh return WREG32_SMC(index, value);
104efa246c0Sriastradh case CGS_IND_REG__UVD_CTX:
105efa246c0Sriastradh return WREG32_UVD_CTX(index, value);
106efa246c0Sriastradh case CGS_IND_REG__DIDT:
107efa246c0Sriastradh return WREG32_DIDT(index, value);
10841ec0267Sriastradh case CGS_IND_REG_GC_CAC:
10941ec0267Sriastradh return WREG32_GC_CAC(index, value);
11041ec0267Sriastradh case CGS_IND_REG_SE_CAC:
11141ec0267Sriastradh return WREG32_SE_CAC(index, value);
112efa246c0Sriastradh case CGS_IND_REG__AUDIO_ENDPT:
113efa246c0Sriastradh DRM_ERROR("audio endpt register access not implemented.\n");
114efa246c0Sriastradh return;
115efa246c0Sriastradh }
116efa246c0Sriastradh WARN(1, "Invalid indirect register space");
117efa246c0Sriastradh }
118efa246c0Sriastradh
fw_type_convert(struct cgs_device * cgs_device,uint32_t fw_type)11941ec0267Sriastradh static uint32_t fw_type_convert(struct cgs_device *cgs_device, uint32_t fw_type)
120efa246c0Sriastradh {
121efa246c0Sriastradh CGS_FUNC_ADEV;
122efa246c0Sriastradh enum AMDGPU_UCODE_ID result = AMDGPU_UCODE_ID_MAXIMUM;
123efa246c0Sriastradh
124efa246c0Sriastradh switch (fw_type) {
125efa246c0Sriastradh case CGS_UCODE_ID_SDMA0:
126efa246c0Sriastradh result = AMDGPU_UCODE_ID_SDMA0;
127efa246c0Sriastradh break;
128efa246c0Sriastradh case CGS_UCODE_ID_SDMA1:
129efa246c0Sriastradh result = AMDGPU_UCODE_ID_SDMA1;
130efa246c0Sriastradh break;
131efa246c0Sriastradh case CGS_UCODE_ID_CP_CE:
132efa246c0Sriastradh result = AMDGPU_UCODE_ID_CP_CE;
133efa246c0Sriastradh break;
134efa246c0Sriastradh case CGS_UCODE_ID_CP_PFP:
135efa246c0Sriastradh result = AMDGPU_UCODE_ID_CP_PFP;
136efa246c0Sriastradh break;
137efa246c0Sriastradh case CGS_UCODE_ID_CP_ME:
138efa246c0Sriastradh result = AMDGPU_UCODE_ID_CP_ME;
139efa246c0Sriastradh break;
140efa246c0Sriastradh case CGS_UCODE_ID_CP_MEC:
141efa246c0Sriastradh case CGS_UCODE_ID_CP_MEC_JT1:
142efa246c0Sriastradh result = AMDGPU_UCODE_ID_CP_MEC1;
143efa246c0Sriastradh break;
144efa246c0Sriastradh case CGS_UCODE_ID_CP_MEC_JT2:
14541ec0267Sriastradh /* for VI. JT2 should be the same as JT1, because:
14641ec0267Sriastradh 1, MEC2 and MEC1 use exactly same FW.
14741ec0267Sriastradh 2, JT2 is not pached but JT1 is.
14841ec0267Sriastradh */
14941ec0267Sriastradh if (adev->asic_type >= CHIP_TOPAZ)
150efa246c0Sriastradh result = AMDGPU_UCODE_ID_CP_MEC1;
15141ec0267Sriastradh else
15241ec0267Sriastradh result = AMDGPU_UCODE_ID_CP_MEC2;
153efa246c0Sriastradh break;
154efa246c0Sriastradh case CGS_UCODE_ID_RLC_G:
155efa246c0Sriastradh result = AMDGPU_UCODE_ID_RLC_G;
156efa246c0Sriastradh break;
15741ec0267Sriastradh case CGS_UCODE_ID_STORAGE:
15841ec0267Sriastradh result = AMDGPU_UCODE_ID_STORAGE;
15941ec0267Sriastradh break;
160efa246c0Sriastradh default:
161efa246c0Sriastradh DRM_ERROR("Firmware type not supported\n");
162efa246c0Sriastradh }
163efa246c0Sriastradh return result;
164efa246c0Sriastradh }
165efa246c0Sriastradh
amdgpu_get_firmware_version(struct cgs_device * cgs_device,enum cgs_ucode_id type)16641ec0267Sriastradh static uint16_t amdgpu_get_firmware_version(struct cgs_device *cgs_device,
16741ec0267Sriastradh enum cgs_ucode_id type)
16841ec0267Sriastradh {
16941ec0267Sriastradh CGS_FUNC_ADEV;
17041ec0267Sriastradh uint16_t fw_version = 0;
17141ec0267Sriastradh
17241ec0267Sriastradh switch (type) {
17341ec0267Sriastradh case CGS_UCODE_ID_SDMA0:
17441ec0267Sriastradh fw_version = adev->sdma.instance[0].fw_version;
17541ec0267Sriastradh break;
17641ec0267Sriastradh case CGS_UCODE_ID_SDMA1:
17741ec0267Sriastradh fw_version = adev->sdma.instance[1].fw_version;
17841ec0267Sriastradh break;
17941ec0267Sriastradh case CGS_UCODE_ID_CP_CE:
18041ec0267Sriastradh fw_version = adev->gfx.ce_fw_version;
18141ec0267Sriastradh break;
18241ec0267Sriastradh case CGS_UCODE_ID_CP_PFP:
18341ec0267Sriastradh fw_version = adev->gfx.pfp_fw_version;
18441ec0267Sriastradh break;
18541ec0267Sriastradh case CGS_UCODE_ID_CP_ME:
18641ec0267Sriastradh fw_version = adev->gfx.me_fw_version;
18741ec0267Sriastradh break;
18841ec0267Sriastradh case CGS_UCODE_ID_CP_MEC:
18941ec0267Sriastradh fw_version = adev->gfx.mec_fw_version;
19041ec0267Sriastradh break;
19141ec0267Sriastradh case CGS_UCODE_ID_CP_MEC_JT1:
19241ec0267Sriastradh fw_version = adev->gfx.mec_fw_version;
19341ec0267Sriastradh break;
19441ec0267Sriastradh case CGS_UCODE_ID_CP_MEC_JT2:
19541ec0267Sriastradh fw_version = adev->gfx.mec_fw_version;
19641ec0267Sriastradh break;
19741ec0267Sriastradh case CGS_UCODE_ID_RLC_G:
19841ec0267Sriastradh fw_version = adev->gfx.rlc_fw_version;
19941ec0267Sriastradh break;
20041ec0267Sriastradh case CGS_UCODE_ID_STORAGE:
20141ec0267Sriastradh break;
20241ec0267Sriastradh default:
20341ec0267Sriastradh DRM_ERROR("firmware type %d do not have version\n", type);
20441ec0267Sriastradh break;
20541ec0267Sriastradh }
20641ec0267Sriastradh return fw_version;
20741ec0267Sriastradh }
20841ec0267Sriastradh
amdgpu_cgs_get_firmware_info(struct cgs_device * cgs_device,enum cgs_ucode_id type,struct cgs_firmware_info * info)20941ec0267Sriastradh static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
210efa246c0Sriastradh enum cgs_ucode_id type,
211efa246c0Sriastradh struct cgs_firmware_info *info)
212efa246c0Sriastradh {
213efa246c0Sriastradh CGS_FUNC_ADEV;
214efa246c0Sriastradh
21541ec0267Sriastradh if ((CGS_UCODE_ID_SMU != type) && (CGS_UCODE_ID_SMU_SK != type)) {
216efa246c0Sriastradh uint64_t gpu_addr;
217efa246c0Sriastradh uint32_t data_size;
218efa246c0Sriastradh const struct gfx_firmware_header_v1_0 *header;
219efa246c0Sriastradh enum AMDGPU_UCODE_ID id;
220efa246c0Sriastradh struct amdgpu_firmware_info *ucode;
221efa246c0Sriastradh
222efa246c0Sriastradh id = fw_type_convert(cgs_device, type);
223efa246c0Sriastradh ucode = &adev->firmware.ucode[id];
224efa246c0Sriastradh if (ucode->fw == NULL)
225efa246c0Sriastradh return -EINVAL;
226efa246c0Sriastradh
227efa246c0Sriastradh gpu_addr = ucode->mc_addr;
228efa246c0Sriastradh header = (const struct gfx_firmware_header_v1_0 *)ucode->fw->data;
229efa246c0Sriastradh data_size = le32_to_cpu(header->header.ucode_size_bytes);
230efa246c0Sriastradh
231efa246c0Sriastradh if ((type == CGS_UCODE_ID_CP_MEC_JT1) ||
232efa246c0Sriastradh (type == CGS_UCODE_ID_CP_MEC_JT2)) {
23341ec0267Sriastradh gpu_addr += ALIGN(le32_to_cpu(header->header.ucode_size_bytes), PAGE_SIZE);
234efa246c0Sriastradh data_size = le32_to_cpu(header->jt_size) << 2;
235efa246c0Sriastradh }
23641ec0267Sriastradh
23741ec0267Sriastradh info->kptr = ucode->kaddr;
238efa246c0Sriastradh info->image_size = data_size;
23941ec0267Sriastradh info->mc_addr = gpu_addr;
240efa246c0Sriastradh info->version = (uint16_t)le32_to_cpu(header->header.ucode_version);
24141ec0267Sriastradh
24241ec0267Sriastradh if (CGS_UCODE_ID_CP_MEC == type)
24341ec0267Sriastradh info->image_size = le32_to_cpu(header->jt_offset) << 2;
24441ec0267Sriastradh
24541ec0267Sriastradh info->fw_version = amdgpu_get_firmware_version(cgs_device, type);
246efa246c0Sriastradh info->feature_version = (uint16_t)le32_to_cpu(header->ucode_feature_version);
247efa246c0Sriastradh } else {
248efa246c0Sriastradh char fw_name[30] = {0};
249efa246c0Sriastradh int err = 0;
250efa246c0Sriastradh uint32_t ucode_size;
2510d50c49dSriastradh uint32_t ucode_start_address __unused;
252efa246c0Sriastradh const uint8_t *src;
253efa246c0Sriastradh const struct smc_firmware_header_v1_0 *hdr;
25441ec0267Sriastradh const struct common_firmware_header *header;
25541ec0267Sriastradh struct amdgpu_firmware_info *ucode = NULL;
256efa246c0Sriastradh
25741ec0267Sriastradh if (!adev->pm.fw) {
258efa246c0Sriastradh switch (adev->asic_type) {
25941ec0267Sriastradh case CHIP_TAHITI:
26041ec0267Sriastradh strcpy(fw_name, "radeon/tahiti_smc.bin");
26141ec0267Sriastradh break;
26241ec0267Sriastradh case CHIP_PITCAIRN:
26341ec0267Sriastradh if ((adev->pdev->revision == 0x81) &&
26441ec0267Sriastradh ((adev->pdev->device == 0x6810) ||
26541ec0267Sriastradh (adev->pdev->device == 0x6811))) {
26641ec0267Sriastradh info->is_kicker = true;
26741ec0267Sriastradh strcpy(fw_name, "radeon/pitcairn_k_smc.bin");
26841ec0267Sriastradh } else {
26941ec0267Sriastradh strcpy(fw_name, "radeon/pitcairn_smc.bin");
27041ec0267Sriastradh }
27141ec0267Sriastradh break;
27241ec0267Sriastradh case CHIP_VERDE:
27341ec0267Sriastradh if (((adev->pdev->device == 0x6820) &&
27441ec0267Sriastradh ((adev->pdev->revision == 0x81) ||
27541ec0267Sriastradh (adev->pdev->revision == 0x83))) ||
27641ec0267Sriastradh ((adev->pdev->device == 0x6821) &&
27741ec0267Sriastradh ((adev->pdev->revision == 0x83) ||
27841ec0267Sriastradh (adev->pdev->revision == 0x87))) ||
27941ec0267Sriastradh ((adev->pdev->revision == 0x87) &&
28041ec0267Sriastradh ((adev->pdev->device == 0x6823) ||
28141ec0267Sriastradh (adev->pdev->device == 0x682b)))) {
28241ec0267Sriastradh info->is_kicker = true;
28341ec0267Sriastradh strcpy(fw_name, "radeon/verde_k_smc.bin");
28441ec0267Sriastradh } else {
28541ec0267Sriastradh strcpy(fw_name, "radeon/verde_smc.bin");
28641ec0267Sriastradh }
28741ec0267Sriastradh break;
28841ec0267Sriastradh case CHIP_OLAND:
28941ec0267Sriastradh if (((adev->pdev->revision == 0x81) &&
29041ec0267Sriastradh ((adev->pdev->device == 0x6600) ||
29141ec0267Sriastradh (adev->pdev->device == 0x6604) ||
29241ec0267Sriastradh (adev->pdev->device == 0x6605) ||
29341ec0267Sriastradh (adev->pdev->device == 0x6610))) ||
29441ec0267Sriastradh ((adev->pdev->revision == 0x83) &&
29541ec0267Sriastradh (adev->pdev->device == 0x6610))) {
29641ec0267Sriastradh info->is_kicker = true;
29741ec0267Sriastradh strcpy(fw_name, "radeon/oland_k_smc.bin");
29841ec0267Sriastradh } else {
29941ec0267Sriastradh strcpy(fw_name, "radeon/oland_smc.bin");
30041ec0267Sriastradh }
30141ec0267Sriastradh break;
30241ec0267Sriastradh case CHIP_HAINAN:
30341ec0267Sriastradh if (((adev->pdev->revision == 0x81) &&
30441ec0267Sriastradh (adev->pdev->device == 0x6660)) ||
30541ec0267Sriastradh ((adev->pdev->revision == 0x83) &&
30641ec0267Sriastradh ((adev->pdev->device == 0x6660) ||
30741ec0267Sriastradh (adev->pdev->device == 0x6663) ||
30841ec0267Sriastradh (adev->pdev->device == 0x6665) ||
30941ec0267Sriastradh (adev->pdev->device == 0x6667)))) {
31041ec0267Sriastradh info->is_kicker = true;
31141ec0267Sriastradh strcpy(fw_name, "radeon/hainan_k_smc.bin");
31241ec0267Sriastradh } else if ((adev->pdev->revision == 0xc3) &&
31341ec0267Sriastradh (adev->pdev->device == 0x6665)) {
31441ec0267Sriastradh info->is_kicker = true;
31541ec0267Sriastradh strcpy(fw_name, "radeon/banks_k_2_smc.bin");
31641ec0267Sriastradh } else {
31741ec0267Sriastradh strcpy(fw_name, "radeon/hainan_smc.bin");
31841ec0267Sriastradh }
31941ec0267Sriastradh break;
32041ec0267Sriastradh case CHIP_BONAIRE:
32141ec0267Sriastradh if ((adev->pdev->revision == 0x80) ||
32241ec0267Sriastradh (adev->pdev->revision == 0x81) ||
32341ec0267Sriastradh (adev->pdev->device == 0x665f)) {
32441ec0267Sriastradh info->is_kicker = true;
32541ec0267Sriastradh strcpy(fw_name, "amdgpu/bonaire_k_smc.bin");
32641ec0267Sriastradh } else {
32741ec0267Sriastradh strcpy(fw_name, "amdgpu/bonaire_smc.bin");
32841ec0267Sriastradh }
32941ec0267Sriastradh break;
33041ec0267Sriastradh case CHIP_HAWAII:
33141ec0267Sriastradh if (adev->pdev->revision == 0x80) {
33241ec0267Sriastradh info->is_kicker = true;
33341ec0267Sriastradh strcpy(fw_name, "amdgpu/hawaii_k_smc.bin");
33441ec0267Sriastradh } else {
33541ec0267Sriastradh strcpy(fw_name, "amdgpu/hawaii_smc.bin");
33641ec0267Sriastradh }
33741ec0267Sriastradh break;
33841ec0267Sriastradh case CHIP_TOPAZ:
33941ec0267Sriastradh if (((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0x81)) ||
34041ec0267Sriastradh ((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0x83)) ||
34141ec0267Sriastradh ((adev->pdev->device == 0x6907) && (adev->pdev->revision == 0x87)) ||
34241ec0267Sriastradh ((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0xD1)) ||
34341ec0267Sriastradh ((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0xD3))) {
34441ec0267Sriastradh info->is_kicker = true;
34541ec0267Sriastradh strcpy(fw_name, "amdgpu/topaz_k_smc.bin");
34641ec0267Sriastradh } else
34741ec0267Sriastradh strcpy(fw_name, "amdgpu/topaz_smc.bin");
34841ec0267Sriastradh break;
349efa246c0Sriastradh case CHIP_TONGA:
35041ec0267Sriastradh if (((adev->pdev->device == 0x6939) && (adev->pdev->revision == 0xf1)) ||
35141ec0267Sriastradh ((adev->pdev->device == 0x6938) && (adev->pdev->revision == 0xf1))) {
35241ec0267Sriastradh info->is_kicker = true;
35341ec0267Sriastradh strcpy(fw_name, "amdgpu/tonga_k_smc.bin");
35441ec0267Sriastradh } else
355efa246c0Sriastradh strcpy(fw_name, "amdgpu/tonga_smc.bin");
356efa246c0Sriastradh break;
35741ec0267Sriastradh case CHIP_FIJI:
35841ec0267Sriastradh strcpy(fw_name, "amdgpu/fiji_smc.bin");
35941ec0267Sriastradh break;
36041ec0267Sriastradh case CHIP_POLARIS11:
36141ec0267Sriastradh if (type == CGS_UCODE_ID_SMU) {
36241ec0267Sriastradh if (((adev->pdev->device == 0x67ef) &&
36341ec0267Sriastradh ((adev->pdev->revision == 0xe0) ||
36441ec0267Sriastradh (adev->pdev->revision == 0xe5))) ||
36541ec0267Sriastradh ((adev->pdev->device == 0x67ff) &&
36641ec0267Sriastradh ((adev->pdev->revision == 0xcf) ||
36741ec0267Sriastradh (adev->pdev->revision == 0xef) ||
36841ec0267Sriastradh (adev->pdev->revision == 0xff)))) {
36941ec0267Sriastradh info->is_kicker = true;
37041ec0267Sriastradh strcpy(fw_name, "amdgpu/polaris11_k_smc.bin");
37141ec0267Sriastradh } else if ((adev->pdev->device == 0x67ef) &&
37241ec0267Sriastradh (adev->pdev->revision == 0xe2)) {
37341ec0267Sriastradh info->is_kicker = true;
37441ec0267Sriastradh strcpy(fw_name, "amdgpu/polaris11_k2_smc.bin");
37541ec0267Sriastradh } else {
37641ec0267Sriastradh strcpy(fw_name, "amdgpu/polaris11_smc.bin");
37741ec0267Sriastradh }
37841ec0267Sriastradh } else if (type == CGS_UCODE_ID_SMU_SK) {
37941ec0267Sriastradh strcpy(fw_name, "amdgpu/polaris11_smc_sk.bin");
38041ec0267Sriastradh }
38141ec0267Sriastradh break;
38241ec0267Sriastradh case CHIP_POLARIS10:
38341ec0267Sriastradh if (type == CGS_UCODE_ID_SMU) {
38441ec0267Sriastradh if (((adev->pdev->device == 0x67df) &&
38541ec0267Sriastradh ((adev->pdev->revision == 0xe0) ||
38641ec0267Sriastradh (adev->pdev->revision == 0xe3) ||
38741ec0267Sriastradh (adev->pdev->revision == 0xe4) ||
38841ec0267Sriastradh (adev->pdev->revision == 0xe5) ||
38941ec0267Sriastradh (adev->pdev->revision == 0xe7) ||
39041ec0267Sriastradh (adev->pdev->revision == 0xef))) ||
39141ec0267Sriastradh ((adev->pdev->device == 0x6fdf) &&
39241ec0267Sriastradh ((adev->pdev->revision == 0xef) ||
39341ec0267Sriastradh (adev->pdev->revision == 0xff)))) {
39441ec0267Sriastradh info->is_kicker = true;
39541ec0267Sriastradh strcpy(fw_name, "amdgpu/polaris10_k_smc.bin");
39641ec0267Sriastradh } else if ((adev->pdev->device == 0x67df) &&
39741ec0267Sriastradh ((adev->pdev->revision == 0xe1) ||
39841ec0267Sriastradh (adev->pdev->revision == 0xf7))) {
39941ec0267Sriastradh info->is_kicker = true;
40041ec0267Sriastradh strcpy(fw_name, "amdgpu/polaris10_k2_smc.bin");
40141ec0267Sriastradh } else {
40241ec0267Sriastradh strcpy(fw_name, "amdgpu/polaris10_smc.bin");
40341ec0267Sriastradh }
40441ec0267Sriastradh } else if (type == CGS_UCODE_ID_SMU_SK) {
40541ec0267Sriastradh strcpy(fw_name, "amdgpu/polaris10_smc_sk.bin");
40641ec0267Sriastradh }
40741ec0267Sriastradh break;
40841ec0267Sriastradh case CHIP_POLARIS12:
40941ec0267Sriastradh if (((adev->pdev->device == 0x6987) &&
41041ec0267Sriastradh ((adev->pdev->revision == 0xc0) ||
41141ec0267Sriastradh (adev->pdev->revision == 0xc3))) ||
41241ec0267Sriastradh ((adev->pdev->device == 0x6981) &&
41341ec0267Sriastradh ((adev->pdev->revision == 0x00) ||
41441ec0267Sriastradh (adev->pdev->revision == 0x01) ||
41541ec0267Sriastradh (adev->pdev->revision == 0x10)))) {
41641ec0267Sriastradh info->is_kicker = true;
41741ec0267Sriastradh strcpy(fw_name, "amdgpu/polaris12_k_smc.bin");
41841ec0267Sriastradh } else {
41941ec0267Sriastradh strcpy(fw_name, "amdgpu/polaris12_smc.bin");
42041ec0267Sriastradh }
42141ec0267Sriastradh break;
42241ec0267Sriastradh case CHIP_VEGAM:
42341ec0267Sriastradh strcpy(fw_name, "amdgpu/vegam_smc.bin");
42441ec0267Sriastradh break;
42541ec0267Sriastradh case CHIP_VEGA10:
42641ec0267Sriastradh if ((adev->pdev->device == 0x687f) &&
42741ec0267Sriastradh ((adev->pdev->revision == 0xc0) ||
42841ec0267Sriastradh (adev->pdev->revision == 0xc1) ||
42941ec0267Sriastradh (adev->pdev->revision == 0xc3)))
43041ec0267Sriastradh strcpy(fw_name, "amdgpu/vega10_acg_smc.bin");
43141ec0267Sriastradh else
43241ec0267Sriastradh strcpy(fw_name, "amdgpu/vega10_smc.bin");
43341ec0267Sriastradh break;
43441ec0267Sriastradh case CHIP_VEGA12:
43541ec0267Sriastradh strcpy(fw_name, "amdgpu/vega12_smc.bin");
43641ec0267Sriastradh break;
43741ec0267Sriastradh case CHIP_VEGA20:
43841ec0267Sriastradh strcpy(fw_name, "amdgpu/vega20_smc.bin");
43941ec0267Sriastradh break;
440efa246c0Sriastradh default:
441efa246c0Sriastradh DRM_ERROR("SMC firmware not supported\n");
442efa246c0Sriastradh return -EINVAL;
443efa246c0Sriastradh }
444efa246c0Sriastradh
445efa246c0Sriastradh err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
446efa246c0Sriastradh if (err) {
447efa246c0Sriastradh DRM_ERROR("Failed to request firmware\n");
448efa246c0Sriastradh return err;
449efa246c0Sriastradh }
450efa246c0Sriastradh
451efa246c0Sriastradh err = amdgpu_ucode_validate(adev->pm.fw);
452efa246c0Sriastradh if (err) {
453efa246c0Sriastradh DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
454efa246c0Sriastradh release_firmware(adev->pm.fw);
455efa246c0Sriastradh adev->pm.fw = NULL;
456efa246c0Sriastradh return err;
457efa246c0Sriastradh }
458efa246c0Sriastradh
45941ec0267Sriastradh if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
46041ec0267Sriastradh ucode = &adev->firmware.ucode[AMDGPU_UCODE_ID_SMC];
46141ec0267Sriastradh ucode->ucode_id = AMDGPU_UCODE_ID_SMC;
46241ec0267Sriastradh ucode->fw = adev->pm.fw;
46341ec0267Sriastradh header = (const struct common_firmware_header *)ucode->fw->data;
46441ec0267Sriastradh adev->firmware.fw_size +=
46541ec0267Sriastradh ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
46641ec0267Sriastradh }
46741ec0267Sriastradh }
46841ec0267Sriastradh
469efa246c0Sriastradh hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
47041ec0267Sriastradh amdgpu_ucode_print_smc_hdr(&hdr->header);
471efa246c0Sriastradh adev->pm.fw_version = le32_to_cpu(hdr->header.ucode_version);
472efa246c0Sriastradh ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes);
473efa246c0Sriastradh ucode_start_address = le32_to_cpu(hdr->ucode_start_addr);
474efa246c0Sriastradh src = (const uint8_t *)(adev->pm.fw->data +
475efa246c0Sriastradh le32_to_cpu(hdr->header.ucode_array_offset_bytes));
476efa246c0Sriastradh
477efa246c0Sriastradh info->version = adev->pm.fw_version;
478efa246c0Sriastradh info->image_size = ucode_size;
47941ec0267Sriastradh info->ucode_start_address = ucode_start_address;
4800d50c49dSriastradh info->kptr = (void *)__UNCONST(src); /* XXX used for? */
481efa246c0Sriastradh }
482efa246c0Sriastradh return 0;
483efa246c0Sriastradh }
484efa246c0Sriastradh
485efa246c0Sriastradh static const struct cgs_ops amdgpu_cgs_ops = {
48641ec0267Sriastradh .read_register = amdgpu_cgs_read_register,
48741ec0267Sriastradh .write_register = amdgpu_cgs_write_register,
48841ec0267Sriastradh .read_ind_register = amdgpu_cgs_read_ind_register,
48941ec0267Sriastradh .write_ind_register = amdgpu_cgs_write_ind_register,
49041ec0267Sriastradh .get_firmware_info = amdgpu_cgs_get_firmware_info,
491efa246c0Sriastradh };
492efa246c0Sriastradh
amdgpu_cgs_create_device(struct amdgpu_device * adev)49341ec0267Sriastradh struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev)
494efa246c0Sriastradh {
495efa246c0Sriastradh struct amdgpu_cgs_device *cgs_device =
496efa246c0Sriastradh kmalloc(sizeof(*cgs_device), GFP_KERNEL);
497efa246c0Sriastradh
498efa246c0Sriastradh if (!cgs_device) {
499efa246c0Sriastradh DRM_ERROR("Couldn't allocate CGS device structure\n");
500efa246c0Sriastradh return NULL;
501efa246c0Sriastradh }
502efa246c0Sriastradh
503efa246c0Sriastradh cgs_device->base.ops = &amdgpu_cgs_ops;
504efa246c0Sriastradh cgs_device->adev = adev;
505efa246c0Sriastradh
50641ec0267Sriastradh return (struct cgs_device *)cgs_device;
507efa246c0Sriastradh }
508efa246c0Sriastradh
amdgpu_cgs_destroy_device(struct cgs_device * cgs_device)50941ec0267Sriastradh void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device)
510efa246c0Sriastradh {
511efa246c0Sriastradh kfree(cgs_device);
512efa246c0Sriastradh }
513