2017-03-03 18:37:23 -05:00
/*
* Copyright 2016 Advanced Micro Devices , Inc .
*
* Permission is hereby granted , free of charge , to any person obtaining a
* copy of this software and associated documentation files ( the " Software " ) ,
* to deal in the Software without restriction , including without limitation
* the rights to use , copy , modify , merge , publish , distribute , sublicense ,
* and / or sell copies of the Software , and to permit persons to whom the
* Software is furnished to do so , subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software .
*
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL
* THE COPYRIGHT HOLDER ( S ) OR AUTHOR ( S ) BE LIABLE FOR ANY CLAIM , DAMAGES OR
* OTHER LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE ,
* ARISING FROM , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE .
*
* Author : Huang Rui
*
*/
# ifndef __AMDGPU_PSP_H__
# define __AMDGPU_PSP_H__
# include "amdgpu.h"
# include "psp_gfx_if.h"
2018-09-28 15:01:57 +08:00
# include "ta_xgmi_if.h"
2018-10-30 13:44:46 +08:00
# include "ta_ras_if.h"
2020-07-17 16:55:20 +08:00
# include "ta_rap_if.h"
2017-03-03 18:37:23 -05:00
# define PSP_FENCE_BUFFER_SIZE 0x1000
# define PSP_CMD_BUFFER_SIZE 0x1000
2018-10-11 15:36:15 +08:00
# define PSP_XGMI_SHARED_MEM_SIZE 0x4000
2018-11-21 11:17:49 +08:00
# define PSP_RAS_SHARED_MEM_SIZE 0x4000
2017-03-21 16:51:00 +08:00
# define PSP_1_MEG 0x100000
2018-08-14 10:33:25 +08:00
# define PSP_TMR_SIZE 0x400000
2019-06-19 14:37:29 -04:00
# define PSP_HDCP_SHARED_MEM_SIZE 0x4000
2019-06-19 14:40:58 -04:00
# define PSP_DTM_SHARED_MEM_SIZE 0x4000
2020-07-17 16:55:20 +08:00
# define PSP_RAP_SHARED_MEM_SIZE 0x4000
2019-06-19 14:37:29 -04:00
# define PSP_SHARED_MEM_SIZE 0x4000
2017-03-03 18:37:23 -05:00
2018-01-23 16:17:24 -05:00
struct psp_context ;
2018-09-29 21:52:50 +08:00
struct psp_xgmi_node_info ;
2018-06-27 17:24:46 -04:00
struct psp_xgmi_topology_info ;
2018-01-23 16:17:24 -05:00
2019-07-11 22:02:02 +08:00
enum psp_bootloader_cmd {
PSP_BL__LOAD_SYSDRV = 0x10000 ,
PSP_BL__LOAD_SOSDRV = 0x20000 ,
PSP_BL__LOAD_KEY_DATABASE = 0x80000 ,
2019-09-30 14:07:00 +08:00
PSP_BL__DRAM_LONG_TRAIN = 0x100000 ,
PSP_BL__DRAM_SHORT_TRAIN = 0x200000 ,
2020-05-06 16:19:41 +08:00
PSP_BL__LOAD_TOS_SPL_TABLE = 0x10000000 ,
2019-07-11 22:02:02 +08:00
} ;
2017-03-03 18:37:23 -05:00
enum psp_ring_type
{
PSP_RING_TYPE__INVALID = 0 ,
/*
* These values map to the way the PSP kernel identifies the
* rings .
*/
PSP_RING_TYPE__UM = 1 , /* User mode ring (formerly called RBI) */
PSP_RING_TYPE__KM = 2 /* Kernel mode ring (formerly called GPCOM) */
} ;
struct psp_ring
{
enum psp_ring_type ring_type ;
struct psp_gfx_rb_frame * ring_mem ;
uint64_t ring_mem_mc_addr ;
void * ring_mem_handle ;
uint32_t ring_size ;
} ;
2019-05-06 15:27:23 +08:00
/* More registers may will be supported */
enum psp_reg_prog_id {
PSP_REG_IH_RB_CNTL = 0 , /* register IH_RB_CNTL */
PSP_REG_IH_RB_CNTL_RING1 = 1 , /* register IH_RB_CNTL_RING1 */
PSP_REG_IH_RB_CNTL_RING2 = 2 , /* register IH_RB_CNTL_RING2 */
PSP_REG_LAST
} ;
2018-01-23 16:17:24 -05:00
struct psp_funcs
2017-03-03 18:37:23 -05:00
{
int ( * init_microcode ) ( struct psp_context * psp ) ;
2019-07-11 00:13:54 +08:00
int ( * bootloader_load_kdb ) ( struct psp_context * psp ) ;
2020-05-06 16:19:41 +08:00
int ( * bootloader_load_spl ) ( struct psp_context * psp ) ;
2017-03-03 18:37:23 -05:00
int ( * bootloader_load_sysdrv ) ( struct psp_context * psp ) ;
int ( * bootloader_load_sos ) ( struct psp_context * psp ) ;
int ( * ring_init ) ( struct psp_context * psp , enum psp_ring_type ring_type ) ;
2018-08-02 17:54:21 +08:00
int ( * ring_create ) ( struct psp_context * psp ,
enum psp_ring_type ring_type ) ;
2017-09-08 13:04:52 +08:00
int ( * ring_stop ) ( struct psp_context * psp ,
enum psp_ring_type ring_type ) ;
2017-04-17 08:50:18 -04:00
int ( * ring_destroy ) ( struct psp_context * psp ,
enum psp_ring_type ring_type ) ;
2017-03-03 18:37:23 -05:00
bool ( * smu_reload_quirk ) ( struct psp_context * psp ) ;
2017-09-14 16:25:19 +08:00
int ( * mode1_reset ) ( struct psp_context * psp ) ;
2019-09-30 14:07:00 +08:00
int ( * mem_training ) ( struct psp_context * psp , uint32_t ops ) ;
2019-11-18 17:13:56 +08:00
uint32_t ( * ring_get_wptr ) ( struct psp_context * psp ) ;
void ( * ring_set_wptr ) ( struct psp_context * psp , uint32_t value ) ;
2019-12-19 13:05:15 -05:00
int ( * load_usbc_pd_fw ) ( struct psp_context * psp , dma_addr_t dma_addr ) ;
int ( * read_usbc_pd_fw ) ( struct psp_context * psp , uint32_t * fw_ver ) ;
2018-01-23 16:17:24 -05:00
} ;
2019-04-17 14:28:18 -04:00
# define AMDGPU_XGMI_MAX_CONNECTED_NODES 64
struct psp_xgmi_node_info {
uint64_t node_id ;
uint8_t num_hops ;
uint8_t is_sharing_enabled ;
enum ta_xgmi_assigned_sdma_engine sdma_engine ;
} ;
struct psp_xgmi_topology_info {
uint32_t num_nodes ;
struct psp_xgmi_node_info nodes [ AMDGPU_XGMI_MAX_CONNECTED_NODES ] ;
} ;
2019-12-02 13:16:09 +08:00
struct psp_asd_context {
bool asd_initialized ;
uint32_t session_id ;
} ;
2018-10-11 15:36:15 +08:00
struct psp_xgmi_context {
uint8_t initialized ;
uint32_t session_id ;
struct amdgpu_bo * xgmi_shared_bo ;
uint64_t xgmi_shared_mc_addr ;
void * xgmi_shared_buf ;
2019-04-17 14:28:18 -04:00
struct psp_xgmi_topology_info top_info ;
2018-10-11 15:36:15 +08:00
} ;
2018-11-21 11:17:49 +08:00
struct psp_ras_context {
/*ras fw*/
bool ras_initialized ;
uint32_t session_id ;
struct amdgpu_bo * ras_shared_bo ;
uint64_t ras_shared_mc_addr ;
void * ras_shared_buf ;
2018-10-31 14:38:28 +08:00
struct amdgpu_ras * ras ;
2018-11-21 11:17:49 +08:00
} ;
2019-06-19 14:37:29 -04:00
struct psp_hdcp_context {
bool hdcp_initialized ;
uint32_t session_id ;
struct amdgpu_bo * hdcp_shared_bo ;
uint64_t hdcp_shared_mc_addr ;
void * hdcp_shared_buf ;
2020-03-30 17:44:00 -04:00
struct mutex mutex ;
2019-06-19 14:37:29 -04:00
} ;
2019-06-19 14:40:58 -04:00
struct psp_dtm_context {
bool dtm_initialized ;
uint32_t session_id ;
struct amdgpu_bo * dtm_shared_bo ;
uint64_t dtm_shared_mc_addr ;
void * dtm_shared_buf ;
2020-03-30 17:44:00 -04:00
struct mutex mutex ;
2019-06-19 14:40:58 -04:00
} ;
2020-07-17 16:55:20 +08:00
struct psp_rap_context {
bool rap_initialized ;
uint32_t session_id ;
struct amdgpu_bo * rap_shared_bo ;
uint64_t rap_shared_mc_addr ;
void * rap_shared_buf ;
struct mutex mutex ;
} ;
2019-09-30 14:07:00 +08:00
# define MEM_TRAIN_SYSTEM_SIGNATURE 0x54534942
# define GDDR6_MEM_TRAINING_DATA_SIZE_IN_BYTES 0x1000
# define GDDR6_MEM_TRAINING_OFFSET 0x8000
2020-01-20 15:08:35 +08:00
/*Define the VRAM size that will be encroached by BIST training.*/
# define GDDR6_MEM_TRAINING_ENCROACHED_SIZE 0x2000000
2019-09-30 14:07:00 +08:00
enum psp_memory_training_init_flag {
PSP_MEM_TRAIN_NOT_SUPPORT = 0x0 ,
PSP_MEM_TRAIN_SUPPORT = 0x1 ,
PSP_MEM_TRAIN_INIT_FAILED = 0x2 ,
PSP_MEM_TRAIN_RESERVE_SUCCESS = 0x4 ,
PSP_MEM_TRAIN_INIT_SUCCESS = 0x8 ,
} ;
enum psp_memory_training_ops {
PSP_MEM_TRAIN_SEND_LONG_MSG = 0x1 ,
PSP_MEM_TRAIN_SAVE = 0x2 ,
PSP_MEM_TRAIN_RESTORE = 0x4 ,
PSP_MEM_TRAIN_SEND_SHORT_MSG = 0x8 ,
PSP_MEM_TRAIN_COLD_BOOT = PSP_MEM_TRAIN_SEND_LONG_MSG ,
PSP_MEM_TRAIN_RESUME = PSP_MEM_TRAIN_SEND_SHORT_MSG ,
} ;
struct psp_memory_training_context {
/*training data size*/
u64 train_data_size ;
/*
* sys_cache
* cpu virtual address
* system memory buffer that used to store the training data .
*/
void * sys_cache ;
/*vram offset of the p2c training data*/
u64 p2c_train_data_offset ;
/*vram offset of the c2p training data*/
u64 c2p_train_data_offset ;
struct amdgpu_bo * c2p_bo ;
enum psp_memory_training_init_flag init ;
u32 training_cnt ;
} ;
2018-01-23 16:17:24 -05:00
struct psp_context
{
struct amdgpu_device * adev ;
struct psp_ring km_ring ;
struct psp_gfx_cmd_resp * cmd ;
2018-08-02 17:54:21 +08:00
const struct psp_funcs * funcs ;
2017-03-03 18:37:23 -05:00
2018-09-28 14:23:11 +08:00
/* firmware buffer */
2018-08-02 17:54:21 +08:00
struct amdgpu_bo * fw_pri_bo ;
uint64_t fw_pri_mc_addr ;
2017-03-21 16:51:00 +08:00
void * fw_pri_buf ;
2017-03-03 18:37:23 -05:00
/* sos firmware */
const struct firmware * sos_fw ;
uint32_t sos_fw_version ;
uint32_t sos_feature_version ;
uint32_t sys_bin_size ;
uint32_t sos_bin_size ;
2018-10-19 21:46:05 +08:00
uint32_t toc_bin_size ;
2019-07-11 00:13:54 +08:00
uint32_t kdb_bin_size ;
2020-05-06 14:57:13 +08:00
uint32_t spl_bin_size ;
2017-03-03 18:37:23 -05:00
uint8_t * sys_start_addr ;
uint8_t * sos_start_addr ;
2018-10-22 20:34:17 +08:00
uint8_t * toc_start_addr ;
2019-07-11 00:13:54 +08:00
uint8_t * kdb_start_addr ;
2020-05-06 14:57:13 +08:00
uint8_t * spl_start_addr ;
2017-03-03 18:37:23 -05:00
/* tmr buffer */
2018-08-02 17:54:21 +08:00
struct amdgpu_bo * tmr_bo ;
uint64_t tmr_mc_addr ;
2017-03-03 18:37:23 -05:00
2019-12-02 13:16:09 +08:00
/* asd firmware */
2017-03-03 18:37:23 -05:00
const struct firmware * asd_fw ;
uint32_t asd_fw_version ;
uint32_t asd_feature_version ;
uint32_t asd_ucode_size ;
uint8_t * asd_start_addr ;
/* fence buffer */
2018-08-02 17:54:21 +08:00
struct amdgpu_bo * fence_buf_bo ;
uint64_t fence_buf_mc_addr ;
2017-03-03 18:37:23 -05:00
void * fence_buf ;
2017-06-11 18:57:08 +08:00
/* cmd buffer */
struct amdgpu_bo * cmd_buf_bo ;
uint64_t cmd_buf_mc_addr ;
struct psp_gfx_cmd_resp * cmd_buf_mem ;
2018-09-28 14:23:11 +08:00
/* fence value associated with cmd buffer */
atomic_t fence_value ;
2018-12-13 01:21:30 +08:00
/* flag to mark whether gfx fw autoload is supported or not */
bool autoload_supported ;
2020-02-24 17:06:41 +08:00
/* flag to mark whether df cstate management centralized to PMFW */
bool pmfw_centralized_cstate_management ;
2018-10-11 15:36:15 +08:00
/* xgmi ta firmware and buffer */
const struct firmware * ta_fw ;
2018-11-20 10:32:00 +08:00
uint32_t ta_fw_version ;
2018-10-11 15:36:15 +08:00
uint32_t ta_xgmi_ucode_version ;
uint32_t ta_xgmi_ucode_size ;
uint8_t * ta_xgmi_start_addr ;
2018-11-20 10:32:00 +08:00
uint32_t ta_ras_ucode_version ;
uint32_t ta_ras_ucode_size ;
uint8_t * ta_ras_start_addr ;
2019-06-19 14:37:29 -04:00
uint32_t ta_hdcp_ucode_version ;
uint32_t ta_hdcp_ucode_size ;
uint8_t * ta_hdcp_start_addr ;
2019-06-19 14:40:58 -04:00
uint32_t ta_dtm_ucode_version ;
uint32_t ta_dtm_ucode_size ;
uint8_t * ta_dtm_start_addr ;
2020-07-17 16:55:20 +08:00
uint32_t ta_rap_ucode_version ;
uint32_t ta_rap_ucode_size ;
uint8_t * ta_rap_start_addr ;
2019-12-02 13:16:09 +08:00
struct psp_asd_context asd_context ;
2018-10-11 15:36:15 +08:00
struct psp_xgmi_context xgmi_context ;
2018-11-21 11:17:49 +08:00
struct psp_ras_context ras ;
2019-06-19 14:37:29 -04:00
struct psp_hdcp_context hdcp_context ;
2019-06-19 14:40:58 -04:00
struct psp_dtm_context dtm_context ;
2020-07-17 16:55:20 +08:00
struct psp_rap_context rap_context ;
2019-07-08 13:33:22 -05:00
struct mutex mutex ;
2019-09-30 14:07:00 +08:00
struct psp_memory_training_context mem_train_ctx ;
2017-03-03 18:37:23 -05:00
} ;
struct amdgpu_psp_funcs {
bool ( * check_fw_loading_status ) ( struct amdgpu_device * adev ,
enum AMDGPU_UCODE_ID ) ;
} ;
2018-06-27 17:24:46 -04:00
2018-01-23 16:17:24 -05:00
# define psp_ring_init(psp, type) (psp)->funcs->ring_init((psp), (type))
# define psp_ring_create(psp, type) (psp)->funcs->ring_create((psp), (type))
# define psp_ring_stop(psp, type) (psp)->funcs->ring_stop((psp), (type))
# define psp_ring_destroy(psp, type) ((psp)->funcs->ring_destroy((psp), (type)))
2017-03-03 18:37:23 -05:00
# define psp_init_microcode(psp) \
2018-01-23 16:17:24 -05:00
( ( psp ) - > funcs - > init_microcode ? ( psp ) - > funcs - > init_microcode ( ( psp ) ) : 0 )
2019-07-11 00:13:54 +08:00
# define psp_bootloader_load_kdb(psp) \
( ( psp ) - > funcs - > bootloader_load_kdb ? ( psp ) - > funcs - > bootloader_load_kdb ( ( psp ) ) : 0 )
2020-05-06 16:19:41 +08:00
# define psp_bootloader_load_spl(psp) \
( ( psp ) - > funcs - > bootloader_load_spl ? ( psp ) - > funcs - > bootloader_load_spl ( ( psp ) ) : 0 )
2017-03-03 18:37:23 -05:00
# define psp_bootloader_load_sysdrv(psp) \
2018-01-23 16:17:24 -05:00
( ( psp ) - > funcs - > bootloader_load_sysdrv ? ( psp ) - > funcs - > bootloader_load_sysdrv ( ( psp ) ) : 0 )
2017-03-03 18:37:23 -05:00
# define psp_bootloader_load_sos(psp) \
2018-01-23 16:17:24 -05:00
( ( psp ) - > funcs - > bootloader_load_sos ? ( psp ) - > funcs - > bootloader_load_sos ( ( psp ) ) : 0 )
2017-03-03 18:37:23 -05:00
# define psp_smu_reload_quirk(psp) \
2018-01-23 16:17:24 -05:00
( ( psp ) - > funcs - > smu_reload_quirk ? ( psp ) - > funcs - > smu_reload_quirk ( ( psp ) ) : false )
2017-09-14 16:25:19 +08:00
# define psp_mode1_reset(psp) \
2018-01-23 16:17:24 -05:00
( ( psp ) - > funcs - > mode1_reset ? ( psp ) - > funcs - > mode1_reset ( ( psp ) ) : false )
2019-09-30 14:07:00 +08:00
# define psp_mem_training(psp, ops) \
( ( psp ) - > funcs - > mem_training ? ( psp ) - > funcs - > mem_training ( ( psp ) , ( ops ) ) : 0 )
2017-03-03 18:37:23 -05:00
2019-11-18 17:13:56 +08:00
# define psp_ring_get_wptr(psp) (psp)->funcs->ring_get_wptr((psp))
# define psp_ring_set_wptr(psp, value) (psp)->funcs->ring_set_wptr((psp), (value))
2019-12-19 13:05:15 -05:00
# define psp_load_usbc_pd_fw(psp, dma_addr) \
( ( psp ) - > funcs - > load_usbc_pd_fw ? \
( psp ) - > funcs - > load_usbc_pd_fw ( ( psp ) , ( dma_addr ) ) : - EINVAL )
# define psp_read_usbc_pd_fw(psp, fw_ver) \
( ( psp ) - > funcs - > read_usbc_pd_fw ? \
( psp ) - > funcs - > read_usbc_pd_fw ( ( psp ) , fw_ver ) : - EINVAL )
2017-03-03 18:37:23 -05:00
extern const struct amd_ip_funcs psp_ip_funcs ;
extern const struct amdgpu_ip_block_version psp_v3_1_ip_block ;
extern int psp_wait_for ( struct psp_context * psp , uint32_t reg_index ,
uint32_t field_val , uint32_t mask , bool check_changed ) ;
2016-12-16 10:01:55 +08:00
extern const struct amdgpu_ip_block_version psp_v10_0_ip_block ;
2019-08-09 10:32:15 -05:00
extern const struct amdgpu_ip_block_version psp_v12_0_ip_block ;
2016-12-16 10:01:55 +08:00
2018-01-23 16:27:31 -05:00
int psp_gpu_reset ( struct amdgpu_device * adev ) ;
2019-05-14 11:31:04 +08:00
int psp_update_vcn_sram ( struct amdgpu_device * adev , int inst_idx ,
uint64_t cmd_gpu_addr , int cmd_size ) ;
2019-12-23 16:51:42 +08:00
int psp_xgmi_initialize ( struct psp_context * psp ) ;
int psp_xgmi_terminate ( struct psp_context * psp ) ;
2018-09-28 15:01:57 +08:00
int psp_xgmi_invoke ( struct psp_context * psp , uint32_t ta_cmd_id ) ;
2020-05-04 19:39:24 +08:00
int psp_xgmi_get_hive_id ( struct psp_context * psp , uint64_t * hive_id ) ;
int psp_xgmi_get_node_id ( struct psp_context * psp , uint64_t * node_id ) ;
int psp_xgmi_get_topology_info ( struct psp_context * psp ,
int number_devices ,
struct psp_xgmi_topology_info * topology ) ;
int psp_xgmi_set_topology_info ( struct psp_context * psp ,
int number_devices ,
struct psp_xgmi_topology_info * topology ) ;
2018-11-21 11:17:49 +08:00
int psp_ras_invoke ( struct psp_context * psp , uint32_t ta_cmd_id ) ;
int psp_ras_enable_features ( struct psp_context * psp ,
union ta_ras_cmd_input * info , bool enable ) ;
2020-05-04 20:50:32 +08:00
int psp_ras_trigger_error ( struct psp_context * psp ,
struct ta_ras_trigger_error_input * info ) ;
2019-06-19 14:37:29 -04:00
int psp_hdcp_invoke ( struct psp_context * psp , uint32_t ta_cmd_id ) ;
2019-06-19 14:40:58 -04:00
int psp_dtm_invoke ( struct psp_context * psp , uint32_t ta_cmd_id ) ;
2020-07-17 16:55:20 +08:00
int psp_rap_invoke ( struct psp_context * psp , uint32_t ta_cmd_id ) ;
2018-11-21 11:17:49 +08:00
2018-10-24 19:41:13 +08:00
int psp_rlc_autoload_start ( struct psp_context * psp ) ;
2018-05-11 14:54:50 +08:00
extern const struct amdgpu_ip_block_version psp_v11_0_ip_block ;
2019-05-06 15:27:23 +08:00
int psp_reg_program ( struct psp_context * psp , enum psp_reg_prog_id reg ,
uint32_t value ) ;
2019-11-18 17:03:12 +08:00
int psp_ring_cmd_submit ( struct psp_context * psp ,
uint64_t cmd_buf_mc_addr ,
uint64_t fence_mc_addr ,
int index ) ;
2020-04-20 17:15:07 +08:00
int psp_init_asd_microcode ( struct psp_context * psp ,
const char * chip_name ) ;
2020-04-20 17:47:53 +08:00
int psp_init_sos_microcode ( struct psp_context * psp ,
const char * chip_name ) ;
2020-07-06 17:08:33 +08:00
int psp_init_ta_microcode ( struct psp_context * psp ,
const char * chip_name ) ;
2017-03-03 18:37:23 -05:00
# endif