2 * Copyright 2019 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
23 #include <linux/firmware.h>
24 #include <linux/slab.h>
25 #include <linux/module.h>
26 #include <linux/pci.h>
28 #include <drm/amdgpu_drm.h>
31 #include "amdgpu_atombios.h"
32 #include "amdgpu_ih.h"
33 #include "amdgpu_uvd.h"
34 #include "amdgpu_vce.h"
35 #include "amdgpu_ucode.h"
36 #include "amdgpu_psp.h"
40 #include "gc/gc_10_1_0_offset.h"
41 #include "gc/gc_10_1_0_sh_mask.h"
42 #include "mp/mp_11_0_offset.h"
45 #include "soc15_common.h"
46 #include "gmc_v10_0.h"
47 #include "gfxhub_v2_0.h"
48 #include "mmhub_v2_0.h"
49 #include "nbio_v2_3.h"
50 #include "nbio_v7_2.h"
53 #include "navi10_ih.h"
54 #include "gfx_v10_0.h"
55 #include "sdma_v5_0.h"
56 #include "sdma_v5_2.h"
58 #include "jpeg_v2_0.h"
60 #include "jpeg_v3_0.h"
61 #include "amdgpu_vkms.h"
62 #include "mes_v10_1.h"
64 #include "smuio_v11_0.h"
65 #include "smuio_v11_0_6.h"
67 static const struct amd_ip_funcs nv_common_ip_funcs
;
70 static const struct amdgpu_video_codec_info nv_video_codecs_encode_array
[] =
72 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC
, 4096, 2304, 0)},
73 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC
, 4096, 2304, 0)},
76 static const struct amdgpu_video_codecs nv_video_codecs_encode
=
78 .codec_count
= ARRAY_SIZE(nv_video_codecs_encode_array
),
79 .codec_array
= nv_video_codecs_encode_array
,
83 static const struct amdgpu_video_codec_info nv_video_codecs_decode_array
[] =
85 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2
, 4096, 4906, 3)},
86 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4
, 4096, 4906, 5)},
87 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC
, 4096, 4906, 52)},
88 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1
, 4096, 4906, 4)},
89 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC
, 8192, 4352, 186)},
90 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG
, 4096, 4096, 0)},
91 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9
, 8192, 4352, 0)},
94 static const struct amdgpu_video_codecs nv_video_codecs_decode
=
96 .codec_count
= ARRAY_SIZE(nv_video_codecs_decode_array
),
97 .codec_array
= nv_video_codecs_decode_array
,
101 static const struct amdgpu_video_codec_info sc_video_codecs_decode_array
[] =
103 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2
, 4096, 4906, 3)},
104 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4
, 4096, 4906, 5)},
105 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC
, 4096, 4906, 52)},
106 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1
, 4096, 4906, 4)},
107 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC
, 8192, 4352, 186)},
108 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG
, 4096, 4096, 0)},
109 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9
, 8192, 4352, 0)},
110 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1
, 8192, 4352, 0)},
113 static const struct amdgpu_video_codecs sc_video_codecs_decode
=
115 .codec_count
= ARRAY_SIZE(sc_video_codecs_decode_array
),
116 .codec_array
= sc_video_codecs_decode_array
,
119 /* SRIOV Sienna Cichlid, not const since data is controlled by host */
120 static struct amdgpu_video_codec_info sriov_sc_video_codecs_encode_array
[] =
122 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC
, 4096, 2304, 0)},
123 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC
, 4096, 2304, 0)},
126 static struct amdgpu_video_codec_info sriov_sc_video_codecs_decode_array
[] =
128 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2
, 4096, 4906, 3)},
129 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4
, 4096, 4906, 5)},
130 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC
, 4096, 4906, 52)},
131 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1
, 4096, 4906, 4)},
132 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC
, 8192, 4352, 186)},
133 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG
, 4096, 4096, 0)},
134 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9
, 8192, 4352, 0)},
135 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_AV1
, 8192, 4352, 0)},
138 static struct amdgpu_video_codecs sriov_sc_video_codecs_encode
=
140 .codec_count
= ARRAY_SIZE(sriov_sc_video_codecs_encode_array
),
141 .codec_array
= sriov_sc_video_codecs_encode_array
,
144 static struct amdgpu_video_codecs sriov_sc_video_codecs_decode
=
146 .codec_count
= ARRAY_SIZE(sriov_sc_video_codecs_decode_array
),
147 .codec_array
= sriov_sc_video_codecs_decode_array
,
151 static const struct amdgpu_video_codec_info bg_video_codecs_decode_array
[] = {
152 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC
, 4096, 4906, 52)},
153 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC
, 8192, 4352, 186)},
154 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9
, 8192, 4352, 0)},
157 static const struct amdgpu_video_codecs bg_video_codecs_decode
= {
158 .codec_count
= ARRAY_SIZE(bg_video_codecs_decode_array
),
159 .codec_array
= bg_video_codecs_decode_array
,
162 static const struct amdgpu_video_codecs bg_video_codecs_encode
= {
168 static const struct amdgpu_video_codec_info yc_video_codecs_decode_array
[] = {
169 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC
, 4096, 4906, 52)},
170 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC
, 8192, 4352, 186)},
171 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9
, 8192, 4352, 0)},
172 {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG
, 4096, 4096, 0)},
175 static const struct amdgpu_video_codecs yc_video_codecs_decode
= {
176 .codec_count
= ARRAY_SIZE(yc_video_codecs_decode_array
),
177 .codec_array
= yc_video_codecs_decode_array
,
180 static int nv_query_video_codecs(struct amdgpu_device
*adev
, bool encode
,
181 const struct amdgpu_video_codecs
**codecs
)
183 switch (adev
->asic_type
) {
184 case CHIP_SIENNA_CICHLID
:
185 if (amdgpu_sriov_vf(adev
)) {
187 *codecs
= &sriov_sc_video_codecs_encode
;
189 *codecs
= &sriov_sc_video_codecs_decode
;
192 *codecs
= &nv_video_codecs_encode
;
194 *codecs
= &sc_video_codecs_decode
;
197 case CHIP_NAVY_FLOUNDER
:
198 case CHIP_DIMGREY_CAVEFISH
:
201 *codecs
= &nv_video_codecs_encode
;
203 *codecs
= &sc_video_codecs_decode
;
205 case CHIP_YELLOW_CARP
:
207 *codecs
= &nv_video_codecs_encode
;
209 *codecs
= &yc_video_codecs_decode
;
211 case CHIP_BEIGE_GOBY
:
213 *codecs
= &bg_video_codecs_encode
;
215 *codecs
= &bg_video_codecs_decode
;
221 *codecs
= &nv_video_codecs_encode
;
223 *codecs
= &nv_video_codecs_decode
;
231 * Indirect registers accessor
233 static u32
nv_pcie_rreg(struct amdgpu_device
*adev
, u32 reg
)
235 unsigned long address
, data
;
236 address
= adev
->nbio
.funcs
->get_pcie_index_offset(adev
);
237 data
= adev
->nbio
.funcs
->get_pcie_data_offset(adev
);
239 return amdgpu_device_indirect_rreg(adev
, address
, data
, reg
);
242 static void nv_pcie_wreg(struct amdgpu_device
*adev
, u32 reg
, u32 v
)
244 unsigned long address
, data
;
246 address
= adev
->nbio
.funcs
->get_pcie_index_offset(adev
);
247 data
= adev
->nbio
.funcs
->get_pcie_data_offset(adev
);
249 amdgpu_device_indirect_wreg(adev
, address
, data
, reg
, v
);
252 static u64
nv_pcie_rreg64(struct amdgpu_device
*adev
, u32 reg
)
254 unsigned long address
, data
;
255 address
= adev
->nbio
.funcs
->get_pcie_index_offset(adev
);
256 data
= adev
->nbio
.funcs
->get_pcie_data_offset(adev
);
258 return amdgpu_device_indirect_rreg64(adev
, address
, data
, reg
);
261 static u32
nv_pcie_port_rreg(struct amdgpu_device
*adev
, u32 reg
)
263 unsigned long flags
, address
, data
;
265 address
= adev
->nbio
.funcs
->get_pcie_port_index_offset(adev
);
266 data
= adev
->nbio
.funcs
->get_pcie_port_data_offset(adev
);
268 spin_lock_irqsave(&adev
->pcie_idx_lock
, flags
);
269 WREG32(address
, reg
* 4);
270 (void)RREG32(address
);
272 spin_unlock_irqrestore(&adev
->pcie_idx_lock
, flags
);
276 static void nv_pcie_wreg64(struct amdgpu_device
*adev
, u32 reg
, u64 v
)
278 unsigned long address
, data
;
280 address
= adev
->nbio
.funcs
->get_pcie_index_offset(adev
);
281 data
= adev
->nbio
.funcs
->get_pcie_data_offset(adev
);
283 amdgpu_device_indirect_wreg64(adev
, address
, data
, reg
, v
);
286 static void nv_pcie_port_wreg(struct amdgpu_device
*adev
, u32 reg
, u32 v
)
288 unsigned long flags
, address
, data
;
290 address
= adev
->nbio
.funcs
->get_pcie_port_index_offset(adev
);
291 data
= adev
->nbio
.funcs
->get_pcie_port_data_offset(adev
);
293 spin_lock_irqsave(&adev
->pcie_idx_lock
, flags
);
294 WREG32(address
, reg
* 4);
295 (void)RREG32(address
);
298 spin_unlock_irqrestore(&adev
->pcie_idx_lock
, flags
);
301 static u32
nv_didt_rreg(struct amdgpu_device
*adev
, u32 reg
)
303 unsigned long flags
, address
, data
;
306 address
= SOC15_REG_OFFSET(GC
, 0, mmDIDT_IND_INDEX
);
307 data
= SOC15_REG_OFFSET(GC
, 0, mmDIDT_IND_DATA
);
309 spin_lock_irqsave(&adev
->didt_idx_lock
, flags
);
310 WREG32(address
, (reg
));
312 spin_unlock_irqrestore(&adev
->didt_idx_lock
, flags
);
316 static void nv_didt_wreg(struct amdgpu_device
*adev
, u32 reg
, u32 v
)
318 unsigned long flags
, address
, data
;
320 address
= SOC15_REG_OFFSET(GC
, 0, mmDIDT_IND_INDEX
);
321 data
= SOC15_REG_OFFSET(GC
, 0, mmDIDT_IND_DATA
);
323 spin_lock_irqsave(&adev
->didt_idx_lock
, flags
);
324 WREG32(address
, (reg
));
326 spin_unlock_irqrestore(&adev
->didt_idx_lock
, flags
);
329 static u32
nv_get_config_memsize(struct amdgpu_device
*adev
)
331 return adev
->nbio
.funcs
->get_memsize(adev
);
334 static u32
nv_get_xclk(struct amdgpu_device
*adev
)
336 return adev
->clock
.spll
.reference_freq
;
340 void nv_grbm_select(struct amdgpu_device
*adev
,
341 u32 me
, u32 pipe
, u32 queue
, u32 vmid
)
343 u32 grbm_gfx_cntl
= 0;
344 grbm_gfx_cntl
= REG_SET_FIELD(grbm_gfx_cntl
, GRBM_GFX_CNTL
, PIPEID
, pipe
);
345 grbm_gfx_cntl
= REG_SET_FIELD(grbm_gfx_cntl
, GRBM_GFX_CNTL
, MEID
, me
);
346 grbm_gfx_cntl
= REG_SET_FIELD(grbm_gfx_cntl
, GRBM_GFX_CNTL
, VMID
, vmid
);
347 grbm_gfx_cntl
= REG_SET_FIELD(grbm_gfx_cntl
, GRBM_GFX_CNTL
, QUEUEID
, queue
);
349 WREG32_SOC15(GC
, 0, mmGRBM_GFX_CNTL
, grbm_gfx_cntl
);
352 static void nv_vga_set_state(struct amdgpu_device
*adev
, bool state
)
357 static bool nv_read_disabled_bios(struct amdgpu_device
*adev
)
363 static bool nv_read_bios_from_rom(struct amdgpu_device
*adev
,
364 u8
*bios
, u32 length_bytes
)
368 u32 rom_index_offset
, rom_data_offset
;
372 if (length_bytes
== 0)
374 /* APU vbios image is part of sbios image */
375 if (adev
->flags
& AMD_IS_APU
)
378 dw_ptr
= (u32
*)bios
;
379 length_dw
= ALIGN(length_bytes
, 4) / 4;
382 adev
->smuio
.funcs
->get_rom_index_offset(adev
);
384 adev
->smuio
.funcs
->get_rom_data_offset(adev
);
386 /* set rom index to 0 */
387 WREG32(rom_index_offset
, 0);
388 /* read out the rom data */
389 for (i
= 0; i
< length_dw
; i
++)
390 dw_ptr
[i
] = RREG32(rom_data_offset
);
395 static struct soc15_allowed_register_entry nv_allowed_read_registers
[] = {
396 { SOC15_REG_ENTRY(GC
, 0, mmGRBM_STATUS
)},
397 { SOC15_REG_ENTRY(GC
, 0, mmGRBM_STATUS2
)},
398 { SOC15_REG_ENTRY(GC
, 0, mmGRBM_STATUS_SE0
)},
399 { SOC15_REG_ENTRY(GC
, 0, mmGRBM_STATUS_SE1
)},
400 { SOC15_REG_ENTRY(GC
, 0, mmGRBM_STATUS_SE2
)},
401 { SOC15_REG_ENTRY(GC
, 0, mmGRBM_STATUS_SE3
)},
402 { SOC15_REG_ENTRY(SDMA0
, 0, mmSDMA0_STATUS_REG
)},
403 { SOC15_REG_ENTRY(SDMA1
, 0, mmSDMA1_STATUS_REG
)},
404 { SOC15_REG_ENTRY(GC
, 0, mmCP_STAT
)},
405 { SOC15_REG_ENTRY(GC
, 0, mmCP_STALLED_STAT1
)},
406 { SOC15_REG_ENTRY(GC
, 0, mmCP_STALLED_STAT2
)},
407 { SOC15_REG_ENTRY(GC
, 0, mmCP_STALLED_STAT3
)},
408 { SOC15_REG_ENTRY(GC
, 0, mmCP_CPF_BUSY_STAT
)},
409 { SOC15_REG_ENTRY(GC
, 0, mmCP_CPF_STALLED_STAT1
)},
410 { SOC15_REG_ENTRY(GC
, 0, mmCP_CPF_STATUS
)},
411 { SOC15_REG_ENTRY(GC
, 0, mmCP_CPC_BUSY_STAT
)},
412 { SOC15_REG_ENTRY(GC
, 0, mmCP_CPC_STALLED_STAT1
)},
413 { SOC15_REG_ENTRY(GC
, 0, mmCP_CPC_STATUS
)},
414 { SOC15_REG_ENTRY(GC
, 0, mmGB_ADDR_CONFIG
)},
417 static uint32_t nv_read_indexed_register(struct amdgpu_device
*adev
, u32 se_num
,
418 u32 sh_num
, u32 reg_offset
)
422 mutex_lock(&adev
->grbm_idx_mutex
);
423 if (se_num
!= 0xffffffff || sh_num
!= 0xffffffff)
424 amdgpu_gfx_select_se_sh(adev
, se_num
, sh_num
, 0xffffffff);
426 val
= RREG32(reg_offset
);
428 if (se_num
!= 0xffffffff || sh_num
!= 0xffffffff)
429 amdgpu_gfx_select_se_sh(adev
, 0xffffffff, 0xffffffff, 0xffffffff);
430 mutex_unlock(&adev
->grbm_idx_mutex
);
434 static uint32_t nv_get_register_value(struct amdgpu_device
*adev
,
435 bool indexed
, u32 se_num
,
436 u32 sh_num
, u32 reg_offset
)
439 return nv_read_indexed_register(adev
, se_num
, sh_num
, reg_offset
);
441 if (reg_offset
== SOC15_REG_OFFSET(GC
, 0, mmGB_ADDR_CONFIG
))
442 return adev
->gfx
.config
.gb_addr_config
;
443 return RREG32(reg_offset
);
447 static int nv_read_register(struct amdgpu_device
*adev
, u32 se_num
,
448 u32 sh_num
, u32 reg_offset
, u32
*value
)
451 struct soc15_allowed_register_entry
*en
;
454 for (i
= 0; i
< ARRAY_SIZE(nv_allowed_read_registers
); i
++) {
455 en
= &nv_allowed_read_registers
[i
];
456 if ((i
== 7 && (adev
->sdma
.num_instances
== 1)) || /* some asics don't have SDMA1 */
458 (adev
->reg_offset
[en
->hwip
][en
->inst
][en
->seg
] + en
->reg_offset
))
461 *value
= nv_get_register_value(adev
,
462 nv_allowed_read_registers
[i
].grbm_indexed
,
463 se_num
, sh_num
, reg_offset
);
469 static int nv_asic_mode2_reset(struct amdgpu_device
*adev
)
474 amdgpu_atombios_scratch_regs_engine_hung(adev
, true);
477 pci_clear_master(adev
->pdev
);
479 amdgpu_device_cache_pci_state(adev
->pdev
);
481 ret
= amdgpu_dpm_mode2_reset(adev
);
483 dev_err(adev
->dev
, "GPU mode2 reset failed\n");
485 amdgpu_device_load_pci_state(adev
->pdev
);
487 /* wait for asic to come out of reset */
488 for (i
= 0; i
< adev
->usec_timeout
; i
++) {
489 u32 memsize
= adev
->nbio
.funcs
->get_memsize(adev
);
491 if (memsize
!= 0xffffffff)
496 amdgpu_atombios_scratch_regs_engine_hung(adev
, false);
501 static enum amd_reset_method
502 nv_asic_reset_method(struct amdgpu_device
*adev
)
504 if (amdgpu_reset_method
== AMD_RESET_METHOD_MODE1
||
505 amdgpu_reset_method
== AMD_RESET_METHOD_MODE2
||
506 amdgpu_reset_method
== AMD_RESET_METHOD_BACO
||
507 amdgpu_reset_method
== AMD_RESET_METHOD_PCI
)
508 return amdgpu_reset_method
;
510 if (amdgpu_reset_method
!= -1)
511 dev_warn(adev
->dev
, "Specified reset method:%d isn't supported, using AUTO instead.\n",
512 amdgpu_reset_method
);
514 switch (adev
->asic_type
) {
516 case CHIP_YELLOW_CARP
:
517 return AMD_RESET_METHOD_MODE2
;
518 case CHIP_SIENNA_CICHLID
:
519 case CHIP_NAVY_FLOUNDER
:
520 case CHIP_DIMGREY_CAVEFISH
:
521 case CHIP_BEIGE_GOBY
:
522 return AMD_RESET_METHOD_MODE1
;
524 if (amdgpu_dpm_is_baco_supported(adev
))
525 return AMD_RESET_METHOD_BACO
;
527 return AMD_RESET_METHOD_MODE1
;
531 static int nv_asic_reset(struct amdgpu_device
*adev
)
535 switch (nv_asic_reset_method(adev
)) {
536 case AMD_RESET_METHOD_PCI
:
537 dev_info(adev
->dev
, "PCI reset\n");
538 ret
= amdgpu_device_pci_reset(adev
);
540 case AMD_RESET_METHOD_BACO
:
541 dev_info(adev
->dev
, "BACO reset\n");
542 ret
= amdgpu_dpm_baco_reset(adev
);
544 case AMD_RESET_METHOD_MODE2
:
545 dev_info(adev
->dev
, "MODE2 reset\n");
546 ret
= nv_asic_mode2_reset(adev
);
549 dev_info(adev
->dev
, "MODE1 reset\n");
550 ret
= amdgpu_device_mode1_reset(adev
);
557 static int nv_set_uvd_clocks(struct amdgpu_device
*adev
, u32 vclk
, u32 dclk
)
563 static int nv_set_vce_clocks(struct amdgpu_device
*adev
, u32 evclk
, u32 ecclk
)
569 static void nv_pcie_gen3_enable(struct amdgpu_device
*adev
)
571 if (pci_is_root_bus(adev
->pdev
->bus
))
574 if (amdgpu_pcie_gen2
== 0)
577 if (!(adev
->pm
.pcie_gen_mask
& (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2
|
578 CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3
)))
584 static void nv_program_aspm(struct amdgpu_device
*adev
)
589 if (!(adev
->flags
& AMD_IS_APU
) &&
590 (adev
->nbio
.funcs
->program_aspm
))
591 adev
->nbio
.funcs
->program_aspm(adev
);
595 static void nv_enable_doorbell_aperture(struct amdgpu_device
*adev
,
598 adev
->nbio
.funcs
->enable_doorbell_aperture(adev
, enable
);
599 adev
->nbio
.funcs
->enable_doorbell_selfring_aperture(adev
, enable
);
602 static const struct amdgpu_ip_block_version nv_common_ip_block
=
604 .type
= AMD_IP_BLOCK_TYPE_COMMON
,
608 .funcs
= &nv_common_ip_funcs
,
611 static bool nv_is_headless_sku(struct pci_dev
*pdev
)
613 if ((pdev
->device
== 0x731E &&
614 (pdev
->revision
== 0xC6 || pdev
->revision
== 0xC7)) ||
615 (pdev
->device
== 0x7340 && pdev
->revision
== 0xC9) ||
616 (pdev
->device
== 0x7360 && pdev
->revision
== 0xC7))
621 static int nv_reg_base_init(struct amdgpu_device
*adev
)
625 if (amdgpu_discovery
) {
626 r
= amdgpu_discovery_reg_base_init(adev
);
628 DRM_WARN("failed to init reg base from ip discovery table, "
629 "fallback to legacy init method\n");
633 amdgpu_discovery_harvest_ip(adev
);
634 if (nv_is_headless_sku(adev
->pdev
)) {
635 adev
->harvest_ip_mask
|= AMD_HARVEST_IP_VCN_MASK
;
636 adev
->harvest_ip_mask
|= AMD_HARVEST_IP_JPEG_MASK
;
643 switch (adev
->asic_type
) {
645 navi10_reg_base_init(adev
);
648 navi14_reg_base_init(adev
);
651 navi12_reg_base_init(adev
);
653 case CHIP_SIENNA_CICHLID
:
654 case CHIP_NAVY_FLOUNDER
:
655 sienna_cichlid_reg_base_init(adev
);
658 vangogh_reg_base_init(adev
);
660 case CHIP_DIMGREY_CAVEFISH
:
661 dimgrey_cavefish_reg_base_init(adev
);
663 case CHIP_BEIGE_GOBY
:
664 beige_goby_reg_base_init(adev
);
666 case CHIP_YELLOW_CARP
:
667 yellow_carp_reg_base_init(adev
);
669 case CHIP_CYAN_SKILLFISH
:
670 cyan_skillfish_reg_base_init(adev
);
679 void nv_set_virt_ops(struct amdgpu_device
*adev
)
681 adev
->virt
.ops
= &xgpu_nv_virt_ops
;
684 int nv_set_ip_blocks(struct amdgpu_device
*adev
)
688 if (adev
->asic_type
== CHIP_CYAN_SKILLFISH
) {
689 adev
->nbio
.funcs
= &nbio_v2_3_funcs
;
690 adev
->nbio
.hdp_flush_reg
= &nbio_v2_3_hdp_flush_reg
;
691 } else if (adev
->flags
& AMD_IS_APU
) {
692 adev
->nbio
.funcs
= &nbio_v7_2_funcs
;
693 adev
->nbio
.hdp_flush_reg
= &nbio_v7_2_hdp_flush_reg
;
695 adev
->nbio
.funcs
= &nbio_v2_3_funcs
;
696 adev
->nbio
.hdp_flush_reg
= &nbio_v2_3_hdp_flush_reg
;
698 adev
->hdp
.funcs
= &hdp_v5_0_funcs
;
700 if (adev
->asic_type
>= CHIP_SIENNA_CICHLID
)
701 adev
->smuio
.funcs
= &smuio_v11_0_6_funcs
;
703 adev
->smuio
.funcs
= &smuio_v11_0_funcs
;
705 if (adev
->asic_type
== CHIP_SIENNA_CICHLID
)
706 adev
->gmc
.xgmi
.supported
= true;
708 /* Set IP register base before any HW register access */
709 r
= nv_reg_base_init(adev
);
713 switch (adev
->asic_type
) {
716 amdgpu_device_ip_block_add(adev
, &nv_common_ip_block
);
717 amdgpu_device_ip_block_add(adev
, &gmc_v10_0_ip_block
);
718 amdgpu_device_ip_block_add(adev
, &navi10_ih_ip_block
);
719 amdgpu_device_ip_block_add(adev
, &psp_v11_0_ip_block
);
720 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
&&
721 !amdgpu_sriov_vf(adev
))
722 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
723 if (adev
->enable_virtual_display
|| amdgpu_sriov_vf(adev
))
724 amdgpu_device_ip_block_add(adev
, &amdgpu_vkms_ip_block
);
725 #if defined(CONFIG_DRM_AMD_DC)
726 else if (amdgpu_device_has_dc_support(adev
))
727 amdgpu_device_ip_block_add(adev
, &dm_ip_block
);
729 amdgpu_device_ip_block_add(adev
, &gfx_v10_0_ip_block
);
730 amdgpu_device_ip_block_add(adev
, &sdma_v5_0_ip_block
);
731 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_DIRECT
&&
732 !amdgpu_sriov_vf(adev
))
733 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
734 amdgpu_device_ip_block_add(adev
, &vcn_v2_0_ip_block
);
735 amdgpu_device_ip_block_add(adev
, &jpeg_v2_0_ip_block
);
736 if (adev
->enable_mes
)
737 amdgpu_device_ip_block_add(adev
, &mes_v10_1_ip_block
);
740 amdgpu_device_ip_block_add(adev
, &nv_common_ip_block
);
741 amdgpu_device_ip_block_add(adev
, &gmc_v10_0_ip_block
);
742 if (!amdgpu_sriov_vf(adev
)) {
743 amdgpu_device_ip_block_add(adev
, &navi10_ih_ip_block
);
744 amdgpu_device_ip_block_add(adev
, &psp_v11_0_ip_block
);
746 amdgpu_device_ip_block_add(adev
, &psp_v11_0_ip_block
);
747 amdgpu_device_ip_block_add(adev
, &navi10_ih_ip_block
);
749 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
)
750 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
751 if (adev
->enable_virtual_display
|| amdgpu_sriov_vf(adev
))
752 amdgpu_device_ip_block_add(adev
, &amdgpu_vkms_ip_block
);
753 #if defined(CONFIG_DRM_AMD_DC)
754 else if (amdgpu_device_has_dc_support(adev
))
755 amdgpu_device_ip_block_add(adev
, &dm_ip_block
);
757 amdgpu_device_ip_block_add(adev
, &gfx_v10_0_ip_block
);
758 amdgpu_device_ip_block_add(adev
, &sdma_v5_0_ip_block
);
759 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_DIRECT
&&
760 !amdgpu_sriov_vf(adev
))
761 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
762 amdgpu_device_ip_block_add(adev
, &vcn_v2_0_ip_block
);
763 if (!amdgpu_sriov_vf(adev
))
764 amdgpu_device_ip_block_add(adev
, &jpeg_v2_0_ip_block
);
766 case CHIP_SIENNA_CICHLID
:
767 amdgpu_device_ip_block_add(adev
, &nv_common_ip_block
);
768 amdgpu_device_ip_block_add(adev
, &gmc_v10_0_ip_block
);
769 if (!amdgpu_sriov_vf(adev
)) {
770 amdgpu_device_ip_block_add(adev
, &navi10_ih_ip_block
);
771 if (likely(adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
))
772 amdgpu_device_ip_block_add(adev
, &psp_v11_0_ip_block
);
774 if (likely(adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
))
775 amdgpu_device_ip_block_add(adev
, &psp_v11_0_ip_block
);
776 amdgpu_device_ip_block_add(adev
, &navi10_ih_ip_block
);
778 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
&&
779 is_support_sw_smu(adev
))
780 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
781 if (adev
->enable_virtual_display
|| amdgpu_sriov_vf(adev
))
782 amdgpu_device_ip_block_add(adev
, &amdgpu_vkms_ip_block
);
783 #if defined(CONFIG_DRM_AMD_DC)
784 else if (amdgpu_device_has_dc_support(adev
))
785 amdgpu_device_ip_block_add(adev
, &dm_ip_block
);
787 amdgpu_device_ip_block_add(adev
, &gfx_v10_0_ip_block
);
788 amdgpu_device_ip_block_add(adev
, &sdma_v5_2_ip_block
);
789 amdgpu_device_ip_block_add(adev
, &vcn_v3_0_ip_block
);
790 if (!amdgpu_sriov_vf(adev
))
791 amdgpu_device_ip_block_add(adev
, &jpeg_v3_0_ip_block
);
792 if (adev
->enable_mes
)
793 amdgpu_device_ip_block_add(adev
, &mes_v10_1_ip_block
);
795 case CHIP_NAVY_FLOUNDER
:
796 amdgpu_device_ip_block_add(adev
, &nv_common_ip_block
);
797 amdgpu_device_ip_block_add(adev
, &gmc_v10_0_ip_block
);
798 amdgpu_device_ip_block_add(adev
, &navi10_ih_ip_block
);
799 if (likely(adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
))
800 amdgpu_device_ip_block_add(adev
, &psp_v11_0_ip_block
);
801 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
&&
802 is_support_sw_smu(adev
))
803 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
804 if (adev
->enable_virtual_display
|| amdgpu_sriov_vf(adev
))
805 amdgpu_device_ip_block_add(adev
, &amdgpu_vkms_ip_block
);
806 #if defined(CONFIG_DRM_AMD_DC)
807 else if (amdgpu_device_has_dc_support(adev
))
808 amdgpu_device_ip_block_add(adev
, &dm_ip_block
);
810 amdgpu_device_ip_block_add(adev
, &gfx_v10_0_ip_block
);
811 amdgpu_device_ip_block_add(adev
, &sdma_v5_2_ip_block
);
812 amdgpu_device_ip_block_add(adev
, &vcn_v3_0_ip_block
);
813 amdgpu_device_ip_block_add(adev
, &jpeg_v3_0_ip_block
);
814 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_DIRECT
&&
815 is_support_sw_smu(adev
))
816 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
819 amdgpu_device_ip_block_add(adev
, &nv_common_ip_block
);
820 amdgpu_device_ip_block_add(adev
, &gmc_v10_0_ip_block
);
821 amdgpu_device_ip_block_add(adev
, &navi10_ih_ip_block
);
822 if (likely(adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
))
823 amdgpu_device_ip_block_add(adev
, &psp_v11_0_ip_block
);
824 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
825 if (adev
->enable_virtual_display
|| amdgpu_sriov_vf(adev
))
826 amdgpu_device_ip_block_add(adev
, &amdgpu_vkms_ip_block
);
827 #if defined(CONFIG_DRM_AMD_DC)
828 else if (amdgpu_device_has_dc_support(adev
))
829 amdgpu_device_ip_block_add(adev
, &dm_ip_block
);
831 amdgpu_device_ip_block_add(adev
, &gfx_v10_0_ip_block
);
832 amdgpu_device_ip_block_add(adev
, &sdma_v5_2_ip_block
);
833 amdgpu_device_ip_block_add(adev
, &vcn_v3_0_ip_block
);
834 amdgpu_device_ip_block_add(adev
, &jpeg_v3_0_ip_block
);
836 case CHIP_DIMGREY_CAVEFISH
:
837 amdgpu_device_ip_block_add(adev
, &nv_common_ip_block
);
838 amdgpu_device_ip_block_add(adev
, &gmc_v10_0_ip_block
);
839 amdgpu_device_ip_block_add(adev
, &navi10_ih_ip_block
);
840 if (likely(adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
))
841 amdgpu_device_ip_block_add(adev
, &psp_v11_0_ip_block
);
842 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
&&
843 is_support_sw_smu(adev
))
844 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
845 if (adev
->enable_virtual_display
|| amdgpu_sriov_vf(adev
))
846 amdgpu_device_ip_block_add(adev
, &amdgpu_vkms_ip_block
);
847 #if defined(CONFIG_DRM_AMD_DC)
848 else if (amdgpu_device_has_dc_support(adev
))
849 amdgpu_device_ip_block_add(adev
, &dm_ip_block
);
851 amdgpu_device_ip_block_add(adev
, &gfx_v10_0_ip_block
);
852 amdgpu_device_ip_block_add(adev
, &sdma_v5_2_ip_block
);
853 amdgpu_device_ip_block_add(adev
, &vcn_v3_0_ip_block
);
854 amdgpu_device_ip_block_add(adev
, &jpeg_v3_0_ip_block
);
856 case CHIP_BEIGE_GOBY
:
857 amdgpu_device_ip_block_add(adev
, &nv_common_ip_block
);
858 amdgpu_device_ip_block_add(adev
, &gmc_v10_0_ip_block
);
859 amdgpu_device_ip_block_add(adev
, &navi10_ih_ip_block
);
860 if (likely(adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
))
861 amdgpu_device_ip_block_add(adev
, &psp_v11_0_ip_block
);
862 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
&&
863 is_support_sw_smu(adev
))
864 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
865 amdgpu_device_ip_block_add(adev
, &gfx_v10_0_ip_block
);
866 amdgpu_device_ip_block_add(adev
, &sdma_v5_2_ip_block
);
867 if (adev
->enable_virtual_display
|| amdgpu_sriov_vf(adev
))
868 amdgpu_device_ip_block_add(adev
, &amdgpu_vkms_ip_block
);
869 #if defined(CONFIG_DRM_AMD_DC)
870 else if (amdgpu_device_has_dc_support(adev
))
871 amdgpu_device_ip_block_add(adev
, &dm_ip_block
);
873 if (adev
->firmware
.load_type
== AMDGPU_FW_LOAD_DIRECT
&&
874 is_support_sw_smu(adev
))
875 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
876 amdgpu_device_ip_block_add(adev
, &vcn_v3_0_ip_block
);
878 case CHIP_YELLOW_CARP
:
879 amdgpu_device_ip_block_add(adev
, &nv_common_ip_block
);
880 amdgpu_device_ip_block_add(adev
, &gmc_v10_0_ip_block
);
881 amdgpu_device_ip_block_add(adev
, &navi10_ih_ip_block
);
882 if (likely(adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
))
883 amdgpu_device_ip_block_add(adev
, &psp_v13_0_ip_block
);
884 amdgpu_device_ip_block_add(adev
, &smu_v13_0_ip_block
);
885 if (adev
->enable_virtual_display
|| amdgpu_sriov_vf(adev
))
886 amdgpu_device_ip_block_add(adev
, &amdgpu_vkms_ip_block
);
887 amdgpu_device_ip_block_add(adev
, &gfx_v10_0_ip_block
);
888 amdgpu_device_ip_block_add(adev
, &sdma_v5_2_ip_block
);
889 if (adev
->enable_virtual_display
|| amdgpu_sriov_vf(adev
))
890 amdgpu_device_ip_block_add(adev
, &amdgpu_vkms_ip_block
);
891 #if defined(CONFIG_DRM_AMD_DC)
892 else if (amdgpu_device_has_dc_support(adev
))
893 amdgpu_device_ip_block_add(adev
, &dm_ip_block
);
895 amdgpu_device_ip_block_add(adev
, &vcn_v3_0_ip_block
);
896 amdgpu_device_ip_block_add(adev
, &jpeg_v3_0_ip_block
);
898 case CHIP_CYAN_SKILLFISH
:
899 amdgpu_device_ip_block_add(adev
, &nv_common_ip_block
);
900 amdgpu_device_ip_block_add(adev
, &gmc_v10_0_ip_block
);
901 amdgpu_device_ip_block_add(adev
, &navi10_ih_ip_block
);
902 if (adev
->apu_flags
& AMD_APU_IS_CYAN_SKILLFISH2
) {
903 if (likely(adev
->firmware
.load_type
== AMDGPU_FW_LOAD_PSP
))
904 amdgpu_device_ip_block_add(adev
, &psp_v11_0_8_ip_block
);
905 amdgpu_device_ip_block_add(adev
, &smu_v11_0_ip_block
);
907 if (adev
->enable_virtual_display
|| amdgpu_sriov_vf(adev
))
908 amdgpu_device_ip_block_add(adev
, &amdgpu_vkms_ip_block
);
909 amdgpu_device_ip_block_add(adev
, &gfx_v10_0_ip_block
);
910 amdgpu_device_ip_block_add(adev
, &sdma_v5_0_ip_block
);
919 static uint32_t nv_get_rev_id(struct amdgpu_device
*adev
)
921 return adev
->nbio
.funcs
->get_rev_id(adev
);
924 static bool nv_need_full_reset(struct amdgpu_device
*adev
)
929 static bool nv_need_reset_on_init(struct amdgpu_device
*adev
)
933 if (adev
->flags
& AMD_IS_APU
)
936 /* Check sOS sign of life register to confirm sys driver and sOS
937 * are already been loaded.
939 sol_reg
= RREG32_SOC15(MP0
, 0, mmMP0_SMN_C2PMSG_81
);
946 static uint64_t nv_get_pcie_replay_count(struct amdgpu_device
*adev
)
950 * dummy implement for pcie_replay_count sysfs interface
956 static void nv_init_doorbell_index(struct amdgpu_device
*adev
)
958 adev
->doorbell_index
.kiq
= AMDGPU_NAVI10_DOORBELL_KIQ
;
959 adev
->doorbell_index
.mec_ring0
= AMDGPU_NAVI10_DOORBELL_MEC_RING0
;
960 adev
->doorbell_index
.mec_ring1
= AMDGPU_NAVI10_DOORBELL_MEC_RING1
;
961 adev
->doorbell_index
.mec_ring2
= AMDGPU_NAVI10_DOORBELL_MEC_RING2
;
962 adev
->doorbell_index
.mec_ring3
= AMDGPU_NAVI10_DOORBELL_MEC_RING3
;
963 adev
->doorbell_index
.mec_ring4
= AMDGPU_NAVI10_DOORBELL_MEC_RING4
;
964 adev
->doorbell_index
.mec_ring5
= AMDGPU_NAVI10_DOORBELL_MEC_RING5
;
965 adev
->doorbell_index
.mec_ring6
= AMDGPU_NAVI10_DOORBELL_MEC_RING6
;
966 adev
->doorbell_index
.mec_ring7
= AMDGPU_NAVI10_DOORBELL_MEC_RING7
;
967 adev
->doorbell_index
.userqueue_start
= AMDGPU_NAVI10_DOORBELL_USERQUEUE_START
;
968 adev
->doorbell_index
.userqueue_end
= AMDGPU_NAVI10_DOORBELL_USERQUEUE_END
;
969 adev
->doorbell_index
.gfx_ring0
= AMDGPU_NAVI10_DOORBELL_GFX_RING0
;
970 adev
->doorbell_index
.gfx_ring1
= AMDGPU_NAVI10_DOORBELL_GFX_RING1
;
971 adev
->doorbell_index
.mes_ring
= AMDGPU_NAVI10_DOORBELL_MES_RING
;
972 adev
->doorbell_index
.sdma_engine
[0] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE0
;
973 adev
->doorbell_index
.sdma_engine
[1] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE1
;
974 adev
->doorbell_index
.sdma_engine
[2] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE2
;
975 adev
->doorbell_index
.sdma_engine
[3] = AMDGPU_NAVI10_DOORBELL_sDMA_ENGINE3
;
976 adev
->doorbell_index
.ih
= AMDGPU_NAVI10_DOORBELL_IH
;
977 adev
->doorbell_index
.vcn
.vcn_ring0_1
= AMDGPU_NAVI10_DOORBELL64_VCN0_1
;
978 adev
->doorbell_index
.vcn
.vcn_ring2_3
= AMDGPU_NAVI10_DOORBELL64_VCN2_3
;
979 adev
->doorbell_index
.vcn
.vcn_ring4_5
= AMDGPU_NAVI10_DOORBELL64_VCN4_5
;
980 adev
->doorbell_index
.vcn
.vcn_ring6_7
= AMDGPU_NAVI10_DOORBELL64_VCN6_7
;
981 adev
->doorbell_index
.first_non_cp
= AMDGPU_NAVI10_DOORBELL64_FIRST_NON_CP
;
982 adev
->doorbell_index
.last_non_cp
= AMDGPU_NAVI10_DOORBELL64_LAST_NON_CP
;
984 adev
->doorbell_index
.max_assignment
= AMDGPU_NAVI10_DOORBELL_MAX_ASSIGNMENT
<< 1;
985 adev
->doorbell_index
.sdma_doorbell_range
= 20;
988 static void nv_pre_asic_init(struct amdgpu_device
*adev
)
992 static int nv_update_umd_stable_pstate(struct amdgpu_device
*adev
,
996 amdgpu_gfx_rlc_enter_safe_mode(adev
);
998 amdgpu_gfx_rlc_exit_safe_mode(adev
);
1000 if (adev
->gfx
.funcs
->update_perfmon_mgcg
)
1001 adev
->gfx
.funcs
->update_perfmon_mgcg(adev
, !enter
);
1003 if (!(adev
->flags
& AMD_IS_APU
) &&
1004 (adev
->nbio
.funcs
->enable_aspm
))
1005 adev
->nbio
.funcs
->enable_aspm(adev
, !enter
);
1010 static const struct amdgpu_asic_funcs nv_asic_funcs
=
1012 .read_disabled_bios
= &nv_read_disabled_bios
,
1013 .read_bios_from_rom
= &nv_read_bios_from_rom
,
1014 .read_register
= &nv_read_register
,
1015 .reset
= &nv_asic_reset
,
1016 .reset_method
= &nv_asic_reset_method
,
1017 .set_vga_state
= &nv_vga_set_state
,
1018 .get_xclk
= &nv_get_xclk
,
1019 .set_uvd_clocks
= &nv_set_uvd_clocks
,
1020 .set_vce_clocks
= &nv_set_vce_clocks
,
1021 .get_config_memsize
= &nv_get_config_memsize
,
1022 .init_doorbell_index
= &nv_init_doorbell_index
,
1023 .need_full_reset
= &nv_need_full_reset
,
1024 .need_reset_on_init
= &nv_need_reset_on_init
,
1025 .get_pcie_replay_count
= &nv_get_pcie_replay_count
,
1026 .supports_baco
= &amdgpu_dpm_is_baco_supported
,
1027 .pre_asic_init
= &nv_pre_asic_init
,
1028 .update_umd_stable_pstate
= &nv_update_umd_stable_pstate
,
1029 .query_video_codecs
= &nv_query_video_codecs
,
1032 static int nv_common_early_init(void *handle
)
1034 #define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
1035 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1037 adev
->rmmio_remap
.reg_offset
= MMIO_REG_HOLE_OFFSET
;
1038 adev
->rmmio_remap
.bus_addr
= adev
->rmmio_base
+ MMIO_REG_HOLE_OFFSET
;
1039 adev
->smc_rreg
= NULL
;
1040 adev
->smc_wreg
= NULL
;
1041 adev
->pcie_rreg
= &nv_pcie_rreg
;
1042 adev
->pcie_wreg
= &nv_pcie_wreg
;
1043 adev
->pcie_rreg64
= &nv_pcie_rreg64
;
1044 adev
->pcie_wreg64
= &nv_pcie_wreg64
;
1045 adev
->pciep_rreg
= &nv_pcie_port_rreg
;
1046 adev
->pciep_wreg
= &nv_pcie_port_wreg
;
1048 /* TODO: will add them during VCN v2 implementation */
1049 adev
->uvd_ctx_rreg
= NULL
;
1050 adev
->uvd_ctx_wreg
= NULL
;
1052 adev
->didt_rreg
= &nv_didt_rreg
;
1053 adev
->didt_wreg
= &nv_didt_wreg
;
1055 adev
->asic_funcs
= &nv_asic_funcs
;
1057 adev
->rev_id
= nv_get_rev_id(adev
);
1058 adev
->external_rev_id
= 0xff;
1059 switch (adev
->asic_type
) {
1061 adev
->cg_flags
= AMD_CG_SUPPORT_GFX_MGCG
|
1062 AMD_CG_SUPPORT_GFX_CGCG
|
1063 AMD_CG_SUPPORT_IH_CG
|
1064 AMD_CG_SUPPORT_HDP_MGCG
|
1065 AMD_CG_SUPPORT_HDP_LS
|
1066 AMD_CG_SUPPORT_SDMA_MGCG
|
1067 AMD_CG_SUPPORT_SDMA_LS
|
1068 AMD_CG_SUPPORT_MC_MGCG
|
1069 AMD_CG_SUPPORT_MC_LS
|
1070 AMD_CG_SUPPORT_ATHUB_MGCG
|
1071 AMD_CG_SUPPORT_ATHUB_LS
|
1072 AMD_CG_SUPPORT_VCN_MGCG
|
1073 AMD_CG_SUPPORT_JPEG_MGCG
|
1074 AMD_CG_SUPPORT_BIF_MGCG
|
1075 AMD_CG_SUPPORT_BIF_LS
;
1076 adev
->pg_flags
= AMD_PG_SUPPORT_VCN
|
1077 AMD_PG_SUPPORT_VCN_DPG
|
1078 AMD_PG_SUPPORT_JPEG
|
1079 AMD_PG_SUPPORT_ATHUB
;
1080 adev
->external_rev_id
= adev
->rev_id
+ 0x1;
1083 adev
->cg_flags
= AMD_CG_SUPPORT_GFX_MGCG
|
1084 AMD_CG_SUPPORT_GFX_CGCG
|
1085 AMD_CG_SUPPORT_IH_CG
|
1086 AMD_CG_SUPPORT_HDP_MGCG
|
1087 AMD_CG_SUPPORT_HDP_LS
|
1088 AMD_CG_SUPPORT_SDMA_MGCG
|
1089 AMD_CG_SUPPORT_SDMA_LS
|
1090 AMD_CG_SUPPORT_MC_MGCG
|
1091 AMD_CG_SUPPORT_MC_LS
|
1092 AMD_CG_SUPPORT_ATHUB_MGCG
|
1093 AMD_CG_SUPPORT_ATHUB_LS
|
1094 AMD_CG_SUPPORT_VCN_MGCG
|
1095 AMD_CG_SUPPORT_JPEG_MGCG
|
1096 AMD_CG_SUPPORT_BIF_MGCG
|
1097 AMD_CG_SUPPORT_BIF_LS
;
1098 adev
->pg_flags
= AMD_PG_SUPPORT_VCN
|
1099 AMD_PG_SUPPORT_JPEG
|
1100 AMD_PG_SUPPORT_VCN_DPG
;
1101 adev
->external_rev_id
= adev
->rev_id
+ 20;
1104 adev
->cg_flags
= AMD_CG_SUPPORT_GFX_MGCG
|
1105 AMD_CG_SUPPORT_GFX_MGLS
|
1106 AMD_CG_SUPPORT_GFX_CGCG
|
1107 AMD_CG_SUPPORT_GFX_CP_LS
|
1108 AMD_CG_SUPPORT_GFX_RLC_LS
|
1109 AMD_CG_SUPPORT_IH_CG
|
1110 AMD_CG_SUPPORT_HDP_MGCG
|
1111 AMD_CG_SUPPORT_HDP_LS
|
1112 AMD_CG_SUPPORT_SDMA_MGCG
|
1113 AMD_CG_SUPPORT_SDMA_LS
|
1114 AMD_CG_SUPPORT_MC_MGCG
|
1115 AMD_CG_SUPPORT_MC_LS
|
1116 AMD_CG_SUPPORT_ATHUB_MGCG
|
1117 AMD_CG_SUPPORT_ATHUB_LS
|
1118 AMD_CG_SUPPORT_VCN_MGCG
|
1119 AMD_CG_SUPPORT_JPEG_MGCG
;
1120 adev
->pg_flags
= AMD_PG_SUPPORT_VCN
|
1121 AMD_PG_SUPPORT_VCN_DPG
|
1122 AMD_PG_SUPPORT_JPEG
|
1123 AMD_PG_SUPPORT_ATHUB
;
1124 /* guest vm gets 0xffffffff when reading RCC_DEV0_EPF0_STRAP0,
1125 * as a consequence, the rev_id and external_rev_id are wrong.
1126 * workaround it by hardcoding rev_id to 0 (default value).
1128 if (amdgpu_sriov_vf(adev
))
1130 adev
->external_rev_id
= adev
->rev_id
+ 0xa;
1132 case CHIP_SIENNA_CICHLID
:
1133 adev
->cg_flags
= AMD_CG_SUPPORT_GFX_MGCG
|
1134 AMD_CG_SUPPORT_GFX_CGCG
|
1135 AMD_CG_SUPPORT_GFX_CGLS
|
1136 AMD_CG_SUPPORT_GFX_3D_CGCG
|
1137 AMD_CG_SUPPORT_MC_MGCG
|
1138 AMD_CG_SUPPORT_VCN_MGCG
|
1139 AMD_CG_SUPPORT_JPEG_MGCG
|
1140 AMD_CG_SUPPORT_HDP_MGCG
|
1141 AMD_CG_SUPPORT_HDP_LS
|
1142 AMD_CG_SUPPORT_IH_CG
|
1143 AMD_CG_SUPPORT_MC_LS
;
1144 adev
->pg_flags
= AMD_PG_SUPPORT_VCN
|
1145 AMD_PG_SUPPORT_VCN_DPG
|
1146 AMD_PG_SUPPORT_JPEG
|
1147 AMD_PG_SUPPORT_ATHUB
|
1148 AMD_PG_SUPPORT_MMHUB
;
1149 if (amdgpu_sriov_vf(adev
)) {
1150 /* hypervisor control CG and PG enablement */
1154 adev
->external_rev_id
= adev
->rev_id
+ 0x28;
1156 case CHIP_NAVY_FLOUNDER
:
1157 adev
->cg_flags
= AMD_CG_SUPPORT_GFX_MGCG
|
1158 AMD_CG_SUPPORT_GFX_CGCG
|
1159 AMD_CG_SUPPORT_GFX_CGLS
|
1160 AMD_CG_SUPPORT_GFX_3D_CGCG
|
1161 AMD_CG_SUPPORT_VCN_MGCG
|
1162 AMD_CG_SUPPORT_JPEG_MGCG
|
1163 AMD_CG_SUPPORT_MC_MGCG
|
1164 AMD_CG_SUPPORT_MC_LS
|
1165 AMD_CG_SUPPORT_HDP_MGCG
|
1166 AMD_CG_SUPPORT_HDP_LS
|
1167 AMD_CG_SUPPORT_IH_CG
;
1168 adev
->pg_flags
= AMD_PG_SUPPORT_VCN
|
1169 AMD_PG_SUPPORT_VCN_DPG
|
1170 AMD_PG_SUPPORT_JPEG
|
1171 AMD_PG_SUPPORT_ATHUB
|
1172 AMD_PG_SUPPORT_MMHUB
;
1173 adev
->external_rev_id
= adev
->rev_id
+ 0x32;
1177 adev
->cg_flags
= AMD_CG_SUPPORT_GFX_MGCG
|
1178 AMD_CG_SUPPORT_GFX_MGLS
|
1179 AMD_CG_SUPPORT_GFX_CP_LS
|
1180 AMD_CG_SUPPORT_GFX_RLC_LS
|
1181 AMD_CG_SUPPORT_GFX_CGCG
|
1182 AMD_CG_SUPPORT_GFX_CGLS
|
1183 AMD_CG_SUPPORT_GFX_3D_CGCG
|
1184 AMD_CG_SUPPORT_GFX_3D_CGLS
|
1185 AMD_CG_SUPPORT_MC_MGCG
|
1186 AMD_CG_SUPPORT_MC_LS
|
1187 AMD_CG_SUPPORT_GFX_FGCG
|
1188 AMD_CG_SUPPORT_VCN_MGCG
|
1189 AMD_CG_SUPPORT_SDMA_MGCG
|
1190 AMD_CG_SUPPORT_SDMA_LS
|
1191 AMD_CG_SUPPORT_JPEG_MGCG
;
1192 adev
->pg_flags
= AMD_PG_SUPPORT_GFX_PG
|
1193 AMD_PG_SUPPORT_VCN
|
1194 AMD_PG_SUPPORT_VCN_DPG
|
1195 AMD_PG_SUPPORT_JPEG
;
1196 if (adev
->apu_flags
& AMD_APU_IS_VANGOGH
)
1197 adev
->external_rev_id
= adev
->rev_id
+ 0x01;
1199 case CHIP_DIMGREY_CAVEFISH
:
1200 adev
->cg_flags
= AMD_CG_SUPPORT_GFX_MGCG
|
1201 AMD_CG_SUPPORT_GFX_CGCG
|
1202 AMD_CG_SUPPORT_GFX_CGLS
|
1203 AMD_CG_SUPPORT_GFX_3D_CGCG
|
1204 AMD_CG_SUPPORT_VCN_MGCG
|
1205 AMD_CG_SUPPORT_JPEG_MGCG
|
1206 AMD_CG_SUPPORT_MC_MGCG
|
1207 AMD_CG_SUPPORT_MC_LS
|
1208 AMD_CG_SUPPORT_HDP_MGCG
|
1209 AMD_CG_SUPPORT_HDP_LS
|
1210 AMD_CG_SUPPORT_IH_CG
;
1211 adev
->pg_flags
= AMD_PG_SUPPORT_VCN
|
1212 AMD_PG_SUPPORT_VCN_DPG
|
1213 AMD_PG_SUPPORT_JPEG
|
1214 AMD_PG_SUPPORT_ATHUB
|
1215 AMD_PG_SUPPORT_MMHUB
;
1216 adev
->external_rev_id
= adev
->rev_id
+ 0x3c;
1218 case CHIP_BEIGE_GOBY
:
1219 adev
->cg_flags
= AMD_CG_SUPPORT_GFX_MGCG
|
1220 AMD_CG_SUPPORT_GFX_CGCG
|
1221 AMD_CG_SUPPORT_GFX_CGLS
|
1222 AMD_CG_SUPPORT_GFX_3D_CGCG
|
1223 AMD_CG_SUPPORT_MC_MGCG
|
1224 AMD_CG_SUPPORT_MC_LS
|
1225 AMD_CG_SUPPORT_HDP_MGCG
|
1226 AMD_CG_SUPPORT_HDP_LS
|
1227 AMD_CG_SUPPORT_IH_CG
|
1228 AMD_CG_SUPPORT_VCN_MGCG
;
1229 adev
->pg_flags
= AMD_PG_SUPPORT_VCN
|
1230 AMD_PG_SUPPORT_VCN_DPG
|
1231 AMD_PG_SUPPORT_ATHUB
|
1232 AMD_PG_SUPPORT_MMHUB
;
1233 adev
->external_rev_id
= adev
->rev_id
+ 0x46;
1235 case CHIP_YELLOW_CARP
:
1236 adev
->cg_flags
= AMD_CG_SUPPORT_GFX_MGCG
|
1237 AMD_CG_SUPPORT_GFX_MGLS
|
1238 AMD_CG_SUPPORT_GFX_CGCG
|
1239 AMD_CG_SUPPORT_GFX_CGLS
|
1240 AMD_CG_SUPPORT_GFX_3D_CGCG
|
1241 AMD_CG_SUPPORT_GFX_3D_CGLS
|
1242 AMD_CG_SUPPORT_GFX_RLC_LS
|
1243 AMD_CG_SUPPORT_GFX_CP_LS
|
1244 AMD_CG_SUPPORT_GFX_FGCG
|
1245 AMD_CG_SUPPORT_MC_MGCG
|
1246 AMD_CG_SUPPORT_MC_LS
|
1247 AMD_CG_SUPPORT_SDMA_LS
|
1248 AMD_CG_SUPPORT_HDP_MGCG
|
1249 AMD_CG_SUPPORT_HDP_LS
|
1250 AMD_CG_SUPPORT_ATHUB_MGCG
|
1251 AMD_CG_SUPPORT_ATHUB_LS
|
1252 AMD_CG_SUPPORT_IH_CG
|
1253 AMD_CG_SUPPORT_VCN_MGCG
|
1254 AMD_CG_SUPPORT_JPEG_MGCG
;
1255 adev
->pg_flags
= AMD_PG_SUPPORT_GFX_PG
|
1256 AMD_PG_SUPPORT_VCN
|
1257 AMD_PG_SUPPORT_VCN_DPG
|
1258 AMD_PG_SUPPORT_JPEG
;
1259 if (adev
->pdev
->device
== 0x1681)
1260 adev
->external_rev_id
= adev
->rev_id
+ 0x19;
1262 adev
->external_rev_id
= adev
->rev_id
+ 0x01;
1264 case CHIP_CYAN_SKILLFISH
:
1267 adev
->external_rev_id
= adev
->rev_id
+ 0x82;
1270 /* FIXME: not supported yet */
1274 if (adev
->harvest_ip_mask
& AMD_HARVEST_IP_VCN_MASK
)
1275 adev
->pg_flags
&= ~(AMD_PG_SUPPORT_VCN
|
1276 AMD_PG_SUPPORT_VCN_DPG
|
1277 AMD_PG_SUPPORT_JPEG
);
1279 if (amdgpu_sriov_vf(adev
)) {
1280 amdgpu_virt_init_setting(adev
);
1281 xgpu_nv_mailbox_set_irq_funcs(adev
);
1287 static int nv_common_late_init(void *handle
)
1289 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1291 if (amdgpu_sriov_vf(adev
)) {
1292 xgpu_nv_mailbox_get_irq(adev
);
1293 amdgpu_virt_update_sriov_video_codec(adev
,
1294 sriov_sc_video_codecs_encode_array
, ARRAY_SIZE(sriov_sc_video_codecs_encode_array
),
1295 sriov_sc_video_codecs_decode_array
, ARRAY_SIZE(sriov_sc_video_codecs_decode_array
));
1301 static int nv_common_sw_init(void *handle
)
1303 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1305 if (amdgpu_sriov_vf(adev
))
1306 xgpu_nv_mailbox_add_irq_id(adev
);
1311 static int nv_common_sw_fini(void *handle
)
1316 static int nv_common_hw_init(void *handle
)
1318 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1320 if (adev
->nbio
.funcs
->apply_lc_spc_mode_wa
)
1321 adev
->nbio
.funcs
->apply_lc_spc_mode_wa(adev
);
1323 if (adev
->nbio
.funcs
->apply_l1_link_width_reconfig_wa
)
1324 adev
->nbio
.funcs
->apply_l1_link_width_reconfig_wa(adev
);
1326 /* enable pcie gen2/3 link */
1327 nv_pcie_gen3_enable(adev
);
1329 nv_program_aspm(adev
);
1330 /* setup nbio registers */
1331 adev
->nbio
.funcs
->init_registers(adev
);
1332 /* remap HDP registers to a hole in mmio space,
1333 * for the purpose of expose those registers
1336 if (adev
->nbio
.funcs
->remap_hdp_registers
)
1337 adev
->nbio
.funcs
->remap_hdp_registers(adev
);
1338 /* enable the doorbell aperture */
1339 nv_enable_doorbell_aperture(adev
, true);
1344 static int nv_common_hw_fini(void *handle
)
1346 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1348 /* disable the doorbell aperture */
1349 nv_enable_doorbell_aperture(adev
, false);
1354 static int nv_common_suspend(void *handle
)
1356 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1358 return nv_common_hw_fini(adev
);
1361 static int nv_common_resume(void *handle
)
1363 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1365 return nv_common_hw_init(adev
);
1368 static bool nv_common_is_idle(void *handle
)
1373 static int nv_common_wait_for_idle(void *handle
)
1378 static int nv_common_soft_reset(void *handle
)
1383 static int nv_common_set_clockgating_state(void *handle
,
1384 enum amd_clockgating_state state
)
1386 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1388 if (amdgpu_sriov_vf(adev
))
1391 switch (adev
->asic_type
) {
1395 case CHIP_SIENNA_CICHLID
:
1396 case CHIP_NAVY_FLOUNDER
:
1397 case CHIP_DIMGREY_CAVEFISH
:
1398 case CHIP_BEIGE_GOBY
:
1399 adev
->nbio
.funcs
->update_medium_grain_clock_gating(adev
,
1400 state
== AMD_CG_STATE_GATE
);
1401 adev
->nbio
.funcs
->update_medium_grain_light_sleep(adev
,
1402 state
== AMD_CG_STATE_GATE
);
1403 adev
->hdp
.funcs
->update_clock_gating(adev
,
1404 state
== AMD_CG_STATE_GATE
);
1405 adev
->smuio
.funcs
->update_rom_clock_gating(adev
,
1406 state
== AMD_CG_STATE_GATE
);
1414 static int nv_common_set_powergating_state(void *handle
,
1415 enum amd_powergating_state state
)
1421 static void nv_common_get_clockgating_state(void *handle
, u32
*flags
)
1423 struct amdgpu_device
*adev
= (struct amdgpu_device
*)handle
;
1425 if (amdgpu_sriov_vf(adev
))
1428 adev
->nbio
.funcs
->get_clockgating_state(adev
, flags
);
1430 adev
->hdp
.funcs
->get_clock_gating_state(adev
, flags
);
1432 adev
->smuio
.funcs
->get_clock_gating_state(adev
, flags
);
1437 static const struct amd_ip_funcs nv_common_ip_funcs
= {
1438 .name
= "nv_common",
1439 .early_init
= nv_common_early_init
,
1440 .late_init
= nv_common_late_init
,
1441 .sw_init
= nv_common_sw_init
,
1442 .sw_fini
= nv_common_sw_fini
,
1443 .hw_init
= nv_common_hw_init
,
1444 .hw_fini
= nv_common_hw_fini
,
1445 .suspend
= nv_common_suspend
,
1446 .resume
= nv_common_resume
,
1447 .is_idle
= nv_common_is_idle
,
1448 .wait_for_idle
= nv_common_wait_for_idle
,
1449 .soft_reset
= nv_common_soft_reset
,
1450 .set_clockgating_state
= nv_common_set_clockgating_state
,
1451 .set_powergating_state
= nv_common_set_powergating_state
,
1452 .get_clockgating_state
= nv_common_get_clockgating_state
,