18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2014 Advanced Micro Devices, Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#ifndef __AMDGPU_RLC_H__
258c2ecf20Sopenharmony_ci#define __AMDGPU_RLC_H__
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#include "clearstate_defs.h"
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* firmware ID used in rlc toc */
308c2ecf20Sopenharmony_citypedef enum _FIRMWARE_ID_ {
318c2ecf20Sopenharmony_ci	FIRMWARE_ID_INVALID					= 0,
328c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLC_G_UCODE					= 1,
338c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLC_TOC					= 2,
348c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLCG_SCRATCH                                = 3,
358c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLC_SRM_ARAM                                = 4,
368c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLC_SRM_INDEX_ADDR                          = 5,
378c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLC_SRM_INDEX_DATA                          = 6,
388c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLC_P_UCODE                                 = 7,
398c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLC_V_UCODE                                 = 8,
408c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLX6_UCODE                                  = 9,
418c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLX6_DRAM_BOOT                              = 10,
428c2ecf20Sopenharmony_ci	FIRMWARE_ID_GLOBAL_TAP_DELAYS                           = 11,
438c2ecf20Sopenharmony_ci	FIRMWARE_ID_SE0_TAP_DELAYS                              = 12,
448c2ecf20Sopenharmony_ci	FIRMWARE_ID_SE1_TAP_DELAYS                              = 13,
458c2ecf20Sopenharmony_ci	FIRMWARE_ID_GLOBAL_SE0_SE1_SKEW_DELAYS                  = 14,
468c2ecf20Sopenharmony_ci	FIRMWARE_ID_SDMA0_UCODE                                 = 15,
478c2ecf20Sopenharmony_ci	FIRMWARE_ID_SDMA0_JT                                    = 16,
488c2ecf20Sopenharmony_ci	FIRMWARE_ID_SDMA1_UCODE                                 = 17,
498c2ecf20Sopenharmony_ci	FIRMWARE_ID_SDMA1_JT                                    = 18,
508c2ecf20Sopenharmony_ci	FIRMWARE_ID_CP_CE                                       = 19,
518c2ecf20Sopenharmony_ci	FIRMWARE_ID_CP_PFP                                      = 20,
528c2ecf20Sopenharmony_ci	FIRMWARE_ID_CP_ME                                       = 21,
538c2ecf20Sopenharmony_ci	FIRMWARE_ID_CP_MEC                                      = 22,
548c2ecf20Sopenharmony_ci	FIRMWARE_ID_CP_MES                                      = 23,
558c2ecf20Sopenharmony_ci	FIRMWARE_ID_MES_STACK                                   = 24,
568c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLC_SRM_DRAM_SR                             = 25,
578c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLCG_SCRATCH_SR                             = 26,
588c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLCP_SCRATCH_SR                             = 27,
598c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLCV_SCRATCH_SR                             = 28,
608c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLX6_DRAM_SR                                = 29,
618c2ecf20Sopenharmony_ci	FIRMWARE_ID_SDMA0_PG_CONTEXT                            = 30,
628c2ecf20Sopenharmony_ci	FIRMWARE_ID_SDMA1_PG_CONTEXT                            = 31,
638c2ecf20Sopenharmony_ci	FIRMWARE_ID_GLOBAL_MUX_SELECT_RAM                       = 32,
648c2ecf20Sopenharmony_ci	FIRMWARE_ID_SE0_MUX_SELECT_RAM                          = 33,
658c2ecf20Sopenharmony_ci	FIRMWARE_ID_SE1_MUX_SELECT_RAM                          = 34,
668c2ecf20Sopenharmony_ci	FIRMWARE_ID_ACCUM_CTRL_RAM                              = 35,
678c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLCP_CAM                                    = 36,
688c2ecf20Sopenharmony_ci	FIRMWARE_ID_RLC_SPP_CAM_EXT                             = 37,
698c2ecf20Sopenharmony_ci	FIRMWARE_ID_MAX                                         = 38,
708c2ecf20Sopenharmony_ci} FIRMWARE_ID;
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_citypedef struct _RLC_TABLE_OF_CONTENT {
738c2ecf20Sopenharmony_ci	union {
748c2ecf20Sopenharmony_ci		unsigned int	DW0;
758c2ecf20Sopenharmony_ci		struct {
768c2ecf20Sopenharmony_ci			unsigned int	offset		: 25;
778c2ecf20Sopenharmony_ci			unsigned int	id		: 7;
788c2ecf20Sopenharmony_ci		};
798c2ecf20Sopenharmony_ci	};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	union {
828c2ecf20Sopenharmony_ci		unsigned int	DW1;
838c2ecf20Sopenharmony_ci		struct {
848c2ecf20Sopenharmony_ci			unsigned int	load_at_boot		: 1;
858c2ecf20Sopenharmony_ci			unsigned int	load_at_vddgfx		: 1;
868c2ecf20Sopenharmony_ci			unsigned int	load_at_reset		: 1;
878c2ecf20Sopenharmony_ci			unsigned int	memory_destination	: 2;
888c2ecf20Sopenharmony_ci			unsigned int	vfflr_image_code	: 4;
898c2ecf20Sopenharmony_ci			unsigned int	load_mode_direct	: 1;
908c2ecf20Sopenharmony_ci			unsigned int	save_for_vddgfx		: 1;
918c2ecf20Sopenharmony_ci			unsigned int	save_for_vfflr		: 1;
928c2ecf20Sopenharmony_ci			unsigned int	reserved		: 1;
938c2ecf20Sopenharmony_ci			unsigned int	signed_source		: 1;
948c2ecf20Sopenharmony_ci			unsigned int	size			: 18;
958c2ecf20Sopenharmony_ci		};
968c2ecf20Sopenharmony_ci	};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	union {
998c2ecf20Sopenharmony_ci		unsigned int	DW2;
1008c2ecf20Sopenharmony_ci		struct {
1018c2ecf20Sopenharmony_ci			unsigned int	indirect_addr_reg	: 16;
1028c2ecf20Sopenharmony_ci			unsigned int	index			: 16;
1038c2ecf20Sopenharmony_ci		};
1048c2ecf20Sopenharmony_ci	};
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	union {
1078c2ecf20Sopenharmony_ci		unsigned int	DW3;
1088c2ecf20Sopenharmony_ci		struct {
1098c2ecf20Sopenharmony_ci			unsigned int	indirect_data_reg	: 16;
1108c2ecf20Sopenharmony_ci			unsigned int	indirect_start_offset	: 16;
1118c2ecf20Sopenharmony_ci		};
1128c2ecf20Sopenharmony_ci	};
1138c2ecf20Sopenharmony_ci} RLC_TABLE_OF_CONTENT;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#define RLC_TOC_MAX_SIZE		64
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistruct amdgpu_rlc_funcs {
1188c2ecf20Sopenharmony_ci	bool (*is_rlc_enabled)(struct amdgpu_device *adev);
1198c2ecf20Sopenharmony_ci	void (*set_safe_mode)(struct amdgpu_device *adev);
1208c2ecf20Sopenharmony_ci	void (*unset_safe_mode)(struct amdgpu_device *adev);
1218c2ecf20Sopenharmony_ci	int  (*init)(struct amdgpu_device *adev);
1228c2ecf20Sopenharmony_ci	u32  (*get_csb_size)(struct amdgpu_device *adev);
1238c2ecf20Sopenharmony_ci	void (*get_csb_buffer)(struct amdgpu_device *adev, volatile u32 *buffer);
1248c2ecf20Sopenharmony_ci	int  (*get_cp_table_num)(struct amdgpu_device *adev);
1258c2ecf20Sopenharmony_ci	int  (*resume)(struct amdgpu_device *adev);
1268c2ecf20Sopenharmony_ci	void (*stop)(struct amdgpu_device *adev);
1278c2ecf20Sopenharmony_ci	void (*reset)(struct amdgpu_device *adev);
1288c2ecf20Sopenharmony_ci	void (*start)(struct amdgpu_device *adev);
1298c2ecf20Sopenharmony_ci	void (*update_spm_vmid)(struct amdgpu_device *adev, unsigned vmid);
1308c2ecf20Sopenharmony_ci	void (*rlcg_wreg)(struct amdgpu_device *adev, u32 offset, u32 v);
1318c2ecf20Sopenharmony_ci	bool (*is_rlcg_access_range)(struct amdgpu_device *adev, uint32_t reg);
1328c2ecf20Sopenharmony_ci};
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistruct amdgpu_rlc {
1358c2ecf20Sopenharmony_ci	/* for power gating */
1368c2ecf20Sopenharmony_ci	struct amdgpu_bo        *save_restore_obj;
1378c2ecf20Sopenharmony_ci	uint64_t                save_restore_gpu_addr;
1388c2ecf20Sopenharmony_ci	volatile uint32_t       *sr_ptr;
1398c2ecf20Sopenharmony_ci	const u32               *reg_list;
1408c2ecf20Sopenharmony_ci	u32                     reg_list_size;
1418c2ecf20Sopenharmony_ci	/* for clear state */
1428c2ecf20Sopenharmony_ci	struct amdgpu_bo        *clear_state_obj;
1438c2ecf20Sopenharmony_ci	uint64_t                clear_state_gpu_addr;
1448c2ecf20Sopenharmony_ci	volatile uint32_t       *cs_ptr;
1458c2ecf20Sopenharmony_ci	const struct cs_section_def   *cs_data;
1468c2ecf20Sopenharmony_ci	u32                     clear_state_size;
1478c2ecf20Sopenharmony_ci	/* for cp tables */
1488c2ecf20Sopenharmony_ci	struct amdgpu_bo        *cp_table_obj;
1498c2ecf20Sopenharmony_ci	uint64_t                cp_table_gpu_addr;
1508c2ecf20Sopenharmony_ci	volatile uint32_t       *cp_table_ptr;
1518c2ecf20Sopenharmony_ci	u32                     cp_table_size;
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	/* safe mode for updating CG/PG state */
1548c2ecf20Sopenharmony_ci	bool in_safe_mode;
1558c2ecf20Sopenharmony_ci	const struct amdgpu_rlc_funcs *funcs;
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	/* for firmware data */
1588c2ecf20Sopenharmony_ci	u32 save_and_restore_offset;
1598c2ecf20Sopenharmony_ci	u32 clear_state_descriptor_offset;
1608c2ecf20Sopenharmony_ci	u32 avail_scratch_ram_locations;
1618c2ecf20Sopenharmony_ci	u32 reg_restore_list_size;
1628c2ecf20Sopenharmony_ci	u32 reg_list_format_start;
1638c2ecf20Sopenharmony_ci	u32 reg_list_format_separate_start;
1648c2ecf20Sopenharmony_ci	u32 starting_offsets_start;
1658c2ecf20Sopenharmony_ci	u32 reg_list_format_size_bytes;
1668c2ecf20Sopenharmony_ci	u32 reg_list_size_bytes;
1678c2ecf20Sopenharmony_ci	u32 reg_list_format_direct_reg_list_length;
1688c2ecf20Sopenharmony_ci	u32 save_restore_list_cntl_size_bytes;
1698c2ecf20Sopenharmony_ci	u32 save_restore_list_gpm_size_bytes;
1708c2ecf20Sopenharmony_ci	u32 save_restore_list_srm_size_bytes;
1718c2ecf20Sopenharmony_ci	u32 rlc_iram_ucode_size_bytes;
1728c2ecf20Sopenharmony_ci	u32 rlc_dram_ucode_size_bytes;
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	u32 *register_list_format;
1758c2ecf20Sopenharmony_ci	u32 *register_restore;
1768c2ecf20Sopenharmony_ci	u8 *save_restore_list_cntl;
1778c2ecf20Sopenharmony_ci	u8 *save_restore_list_gpm;
1788c2ecf20Sopenharmony_ci	u8 *save_restore_list_srm;
1798c2ecf20Sopenharmony_ci	u8 *rlc_iram_ucode;
1808c2ecf20Sopenharmony_ci	u8 *rlc_dram_ucode;
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	bool is_rlc_v2_1;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	/* for rlc autoload */
1858c2ecf20Sopenharmony_ci	struct amdgpu_bo	*rlc_autoload_bo;
1868c2ecf20Sopenharmony_ci	u64			rlc_autoload_gpu_addr;
1878c2ecf20Sopenharmony_ci	void			*rlc_autoload_ptr;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	/* rlc toc buffer */
1908c2ecf20Sopenharmony_ci	struct amdgpu_bo	*rlc_toc_bo;
1918c2ecf20Sopenharmony_ci	uint64_t		rlc_toc_gpu_addr;
1928c2ecf20Sopenharmony_ci	void			*rlc_toc_buf;
1938c2ecf20Sopenharmony_ci};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_civoid amdgpu_gfx_rlc_enter_safe_mode(struct amdgpu_device *adev);
1968c2ecf20Sopenharmony_civoid amdgpu_gfx_rlc_exit_safe_mode(struct amdgpu_device *adev);
1978c2ecf20Sopenharmony_ciint amdgpu_gfx_rlc_init_sr(struct amdgpu_device *adev, u32 dws);
1988c2ecf20Sopenharmony_ciint amdgpu_gfx_rlc_init_csb(struct amdgpu_device *adev);
1998c2ecf20Sopenharmony_ciint amdgpu_gfx_rlc_init_cpt(struct amdgpu_device *adev);
2008c2ecf20Sopenharmony_civoid amdgpu_gfx_rlc_setup_cp_table(struct amdgpu_device *adev);
2018c2ecf20Sopenharmony_civoid amdgpu_gfx_rlc_fini(struct amdgpu_device *adev);
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci#endif
204