Home | History | Annotate | Line # | Download | only in amdgpu
      1  1.3  riastrad /*	$NetBSD: amdgpu_rlc.h,v 1.3 2021/12/19 12:02:39 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2014 Advanced Micro Devices, Inc.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     14  1.1  riastrad  * all copies or substantial portions of the Software.
     15  1.1  riastrad  *
     16  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     23  1.1  riastrad  *
     24  1.1  riastrad  */
     25  1.1  riastrad 
     26  1.1  riastrad #ifndef __AMDGPU_RLC_H__
     27  1.1  riastrad #define __AMDGPU_RLC_H__
     28  1.1  riastrad 
     29  1.1  riastrad #include "clearstate_defs.h"
     30  1.1  riastrad 
     31  1.1  riastrad /* firmware ID used in rlc toc */
     32  1.1  riastrad typedef enum _FIRMWARE_ID_ {
     33  1.1  riastrad 	FIRMWARE_ID_INVALID					= 0,
     34  1.1  riastrad 	FIRMWARE_ID_RLC_G_UCODE					= 1,
     35  1.1  riastrad 	FIRMWARE_ID_RLC_TOC					= 2,
     36  1.1  riastrad 	FIRMWARE_ID_RLCG_SCRATCH                                = 3,
     37  1.1  riastrad 	FIRMWARE_ID_RLC_SRM_ARAM                                = 4,
     38  1.1  riastrad 	FIRMWARE_ID_RLC_SRM_INDEX_ADDR                          = 5,
     39  1.1  riastrad 	FIRMWARE_ID_RLC_SRM_INDEX_DATA                          = 6,
     40  1.1  riastrad 	FIRMWARE_ID_RLC_P_UCODE                                 = 7,
     41  1.1  riastrad 	FIRMWARE_ID_RLC_V_UCODE                                 = 8,
     42  1.1  riastrad 	FIRMWARE_ID_RLX6_UCODE                                  = 9,
     43  1.1  riastrad 	FIRMWARE_ID_RLX6_DRAM_BOOT                              = 10,
     44  1.1  riastrad 	FIRMWARE_ID_GLOBAL_TAP_DELAYS                           = 11,
     45  1.1  riastrad 	FIRMWARE_ID_SE0_TAP_DELAYS                              = 12,
     46  1.1  riastrad 	FIRMWARE_ID_SE1_TAP_DELAYS                              = 13,
     47  1.1  riastrad 	FIRMWARE_ID_GLOBAL_SE0_SE1_SKEW_DELAYS                  = 14,
     48  1.1  riastrad 	FIRMWARE_ID_SDMA0_UCODE                                 = 15,
     49  1.1  riastrad 	FIRMWARE_ID_SDMA0_JT                                    = 16,
     50  1.1  riastrad 	FIRMWARE_ID_SDMA1_UCODE                                 = 17,
     51  1.1  riastrad 	FIRMWARE_ID_SDMA1_JT                                    = 18,
     52  1.1  riastrad 	FIRMWARE_ID_CP_CE                                       = 19,
     53  1.1  riastrad 	FIRMWARE_ID_CP_PFP                                      = 20,
     54  1.1  riastrad 	FIRMWARE_ID_CP_ME                                       = 21,
     55  1.1  riastrad 	FIRMWARE_ID_CP_MEC                                      = 22,
     56  1.1  riastrad 	FIRMWARE_ID_CP_MES                                      = 23,
     57  1.1  riastrad 	FIRMWARE_ID_MES_STACK                                   = 24,
     58  1.1  riastrad 	FIRMWARE_ID_RLC_SRM_DRAM_SR                             = 25,
     59  1.1  riastrad 	FIRMWARE_ID_RLCG_SCRATCH_SR                             = 26,
     60  1.1  riastrad 	FIRMWARE_ID_RLCP_SCRATCH_SR                             = 27,
     61  1.1  riastrad 	FIRMWARE_ID_RLCV_SCRATCH_SR                             = 28,
     62  1.1  riastrad 	FIRMWARE_ID_RLX6_DRAM_SR                                = 29,
     63  1.1  riastrad 	FIRMWARE_ID_SDMA0_PG_CONTEXT                            = 30,
     64  1.1  riastrad 	FIRMWARE_ID_SDMA1_PG_CONTEXT                            = 31,
     65  1.1  riastrad 	FIRMWARE_ID_GLOBAL_MUX_SELECT_RAM                       = 32,
     66  1.1  riastrad 	FIRMWARE_ID_SE0_MUX_SELECT_RAM                          = 33,
     67  1.1  riastrad 	FIRMWARE_ID_SE1_MUX_SELECT_RAM                          = 34,
     68  1.1  riastrad 	FIRMWARE_ID_ACCUM_CTRL_RAM                              = 35,
     69  1.1  riastrad 	FIRMWARE_ID_RLCP_CAM                                    = 36,
     70  1.1  riastrad 	FIRMWARE_ID_RLC_SPP_CAM_EXT                             = 37,
     71  1.1  riastrad 	FIRMWARE_ID_MAX                                         = 38,
     72  1.1  riastrad } FIRMWARE_ID;
     73  1.1  riastrad 
     74  1.1  riastrad typedef struct _RLC_TABLE_OF_CONTENT {
     75  1.1  riastrad 	union {
     76  1.1  riastrad 		unsigned int	DW0;
     77  1.1  riastrad 		struct {
     78  1.1  riastrad 			unsigned int	offset		: 25;
     79  1.1  riastrad 			unsigned int	id		: 7;
     80  1.1  riastrad 		};
     81  1.1  riastrad 	};
     82  1.1  riastrad 
     83  1.1  riastrad 	union {
     84  1.1  riastrad 		unsigned int	DW1;
     85  1.1  riastrad 		struct {
     86  1.1  riastrad 			unsigned int	load_at_boot		: 1;
     87  1.1  riastrad 			unsigned int	load_at_vddgfx		: 1;
     88  1.1  riastrad 			unsigned int	load_at_reset		: 1;
     89  1.1  riastrad 			unsigned int	memory_destination	: 2;
     90  1.1  riastrad 			unsigned int	vfflr_image_code	: 4;
     91  1.1  riastrad 			unsigned int	load_mode_direct	: 1;
     92  1.1  riastrad 			unsigned int	save_for_vddgfx		: 1;
     93  1.1  riastrad 			unsigned int	save_for_vfflr		: 1;
     94  1.1  riastrad 			unsigned int	reserved		: 1;
     95  1.1  riastrad 			unsigned int	signed_source		: 1;
     96  1.1  riastrad 			unsigned int	size			: 18;
     97  1.1  riastrad 		};
     98  1.1  riastrad 	};
     99  1.1  riastrad 
    100  1.1  riastrad 	union {
    101  1.1  riastrad 		unsigned int	DW2;
    102  1.1  riastrad 		struct {
    103  1.1  riastrad 			unsigned int	indirect_addr_reg	: 16;
    104  1.1  riastrad 			unsigned int	index			: 16;
    105  1.1  riastrad 		};
    106  1.1  riastrad 	};
    107  1.1  riastrad 
    108  1.1  riastrad 	union {
    109  1.1  riastrad 		unsigned int	DW3;
    110  1.1  riastrad 		struct {
    111  1.1  riastrad 			unsigned int	indirect_data_reg	: 16;
    112  1.1  riastrad 			unsigned int	indirect_start_offset	: 16;
    113  1.1  riastrad 		};
    114  1.1  riastrad 	};
    115  1.1  riastrad } RLC_TABLE_OF_CONTENT;
    116  1.1  riastrad 
    117  1.1  riastrad #define RLC_TOC_MAX_SIZE		64
    118  1.1  riastrad 
    119  1.1  riastrad struct amdgpu_rlc_funcs {
    120  1.1  riastrad 	bool (*is_rlc_enabled)(struct amdgpu_device *adev);
    121  1.1  riastrad 	void (*set_safe_mode)(struct amdgpu_device *adev);
    122  1.1  riastrad 	void (*unset_safe_mode)(struct amdgpu_device *adev);
    123  1.1  riastrad 	int  (*init)(struct amdgpu_device *adev);
    124  1.1  riastrad 	u32  (*get_csb_size)(struct amdgpu_device *adev);
    125  1.1  riastrad 	void (*get_csb_buffer)(struct amdgpu_device *adev, volatile u32 *buffer);
    126  1.1  riastrad 	int  (*get_cp_table_num)(struct amdgpu_device *adev);
    127  1.1  riastrad 	int  (*resume)(struct amdgpu_device *adev);
    128  1.1  riastrad 	void (*stop)(struct amdgpu_device *adev);
    129  1.1  riastrad 	void (*reset)(struct amdgpu_device *adev);
    130  1.1  riastrad 	void (*start)(struct amdgpu_device *adev);
    131  1.1  riastrad };
    132  1.1  riastrad 
    133  1.1  riastrad struct amdgpu_rlc {
    134  1.1  riastrad 	/* for power gating */
    135  1.1  riastrad 	struct amdgpu_bo        *save_restore_obj;
    136  1.1  riastrad 	uint64_t                save_restore_gpu_addr;
    137  1.1  riastrad 	volatile uint32_t       *sr_ptr;
    138  1.1  riastrad 	const u32               *reg_list;
    139  1.1  riastrad 	u32                     reg_list_size;
    140  1.1  riastrad 	/* for clear state */
    141  1.1  riastrad 	struct amdgpu_bo        *clear_state_obj;
    142  1.1  riastrad 	uint64_t                clear_state_gpu_addr;
    143  1.1  riastrad 	volatile uint32_t       *cs_ptr;
    144  1.1  riastrad 	const struct cs_section_def   *cs_data;
    145  1.1  riastrad 	u32                     clear_state_size;
    146  1.1  riastrad 	/* for cp tables */
    147  1.1  riastrad 	struct amdgpu_bo        *cp_table_obj;
    148  1.1  riastrad 	uint64_t                cp_table_gpu_addr;
    149  1.1  riastrad 	volatile uint32_t       *cp_table_ptr;
    150  1.1  riastrad 	u32                     cp_table_size;
    151  1.1  riastrad 
    152  1.1  riastrad 	/* safe mode for updating CG/PG state */
    153  1.1  riastrad 	bool in_safe_mode;
    154  1.1  riastrad 	const struct amdgpu_rlc_funcs *funcs;
    155  1.1  riastrad 
    156  1.1  riastrad 	/* for firmware data */
    157  1.1  riastrad 	u32 save_and_restore_offset;
    158  1.1  riastrad 	u32 clear_state_descriptor_offset;
    159  1.1  riastrad 	u32 avail_scratch_ram_locations;
    160  1.1  riastrad 	u32 reg_restore_list_size;
    161  1.1  riastrad 	u32 reg_list_format_start;
    162  1.1  riastrad 	u32 reg_list_format_separate_start;
    163  1.1  riastrad 	u32 starting_offsets_start;
    164  1.1  riastrad 	u32 reg_list_format_size_bytes;
    165  1.1  riastrad 	u32 reg_list_size_bytes;
    166  1.1  riastrad 	u32 reg_list_format_direct_reg_list_length;
    167  1.1  riastrad 	u32 save_restore_list_cntl_size_bytes;
    168  1.1  riastrad 	u32 save_restore_list_gpm_size_bytes;
    169  1.1  riastrad 	u32 save_restore_list_srm_size_bytes;
    170  1.1  riastrad 
    171  1.1  riastrad 	u32 *register_list_format;
    172  1.1  riastrad 	u32 *register_restore;
    173  1.3  riastrad 	const u8 *save_restore_list_cntl;
    174  1.3  riastrad 	const u8 *save_restore_list_gpm;
    175  1.3  riastrad 	const u8 *save_restore_list_srm;
    176  1.1  riastrad 
    177  1.1  riastrad 	bool is_rlc_v2_1;
    178  1.1  riastrad 
    179  1.1  riastrad 	/* for rlc autoload */
    180  1.1  riastrad 	struct amdgpu_bo	*rlc_autoload_bo;
    181  1.1  riastrad 	u64			rlc_autoload_gpu_addr;
    182  1.1  riastrad 	void			*rlc_autoload_ptr;
    183  1.1  riastrad 
    184  1.1  riastrad 	/* rlc toc buffer */
    185  1.1  riastrad 	struct amdgpu_bo	*rlc_toc_bo;
    186  1.1  riastrad 	uint64_t		rlc_toc_gpu_addr;
    187  1.1  riastrad 	void			*rlc_toc_buf;
    188  1.1  riastrad };
    189  1.1  riastrad 
    190  1.1  riastrad void amdgpu_gfx_rlc_enter_safe_mode(struct amdgpu_device *adev);
    191  1.1  riastrad void amdgpu_gfx_rlc_exit_safe_mode(struct amdgpu_device *adev);
    192  1.1  riastrad int amdgpu_gfx_rlc_init_sr(struct amdgpu_device *adev, u32 dws);
    193  1.1  riastrad int amdgpu_gfx_rlc_init_csb(struct amdgpu_device *adev);
    194  1.1  riastrad int amdgpu_gfx_rlc_init_cpt(struct amdgpu_device *adev);
    195  1.1  riastrad void amdgpu_gfx_rlc_setup_cp_table(struct amdgpu_device *adev);
    196  1.1  riastrad void amdgpu_gfx_rlc_fini(struct amdgpu_device *adev);
    197  1.1  riastrad 
    198  1.1  riastrad #endif
    199