xref: /linux/drivers/gpu/drm/amd/amdgpu/mmsch_v1_0.h (revision 762f99f4f3cb41a775b5157dd761217beba65873)
1d7a98193SXiangliang Yu /*
2d7a98193SXiangliang Yu  * Copyright 2017 Advanced Micro Devices, Inc.
3d7a98193SXiangliang Yu  *
4d7a98193SXiangliang Yu  * Permission is hereby granted, free of charge, to any person obtaining a
5d7a98193SXiangliang Yu  * copy of this software and associated documentation files (the "Software"),
6d7a98193SXiangliang Yu  * to deal in the Software without restriction, including without limitation
7d7a98193SXiangliang Yu  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d7a98193SXiangliang Yu  * and/or sell copies of the Software, and to permit persons to whom the
9d7a98193SXiangliang Yu  * Software is furnished to do so, subject to the following conditions:
10d7a98193SXiangliang Yu  *
11d7a98193SXiangliang Yu  * The above copyright notice and this permission notice shall be included in
12d7a98193SXiangliang Yu  * all copies or substantial portions of the Software.
13d7a98193SXiangliang Yu  *
14d7a98193SXiangliang Yu  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15d7a98193SXiangliang Yu  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16d7a98193SXiangliang Yu  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17d7a98193SXiangliang Yu  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18d7a98193SXiangliang Yu  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19d7a98193SXiangliang Yu  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20d7a98193SXiangliang Yu  * OTHER DEALINGS IN THE SOFTWARE.
21d7a98193SXiangliang Yu  *
22d7a98193SXiangliang Yu  */
23d7a98193SXiangliang Yu 
24d7a98193SXiangliang Yu #ifndef __MMSCH_V1_0_H__
25d7a98193SXiangliang Yu #define __MMSCH_V1_0_H__
26d7a98193SXiangliang Yu 
27*424f2b2eSZhigang Luo #define MMSCH_VERSION	0x1
28d7a98193SXiangliang Yu 
29d7a98193SXiangliang Yu enum mmsch_v1_0_command_type {
30d7a98193SXiangliang Yu 	MMSCH_COMMAND__DIRECT_REG_WRITE = 0,
31d7a98193SXiangliang Yu 	MMSCH_COMMAND__DIRECT_REG_POLLING = 2,
32d7a98193SXiangliang Yu 	MMSCH_COMMAND__DIRECT_REG_READ_MODIFY_WRITE = 3,
33d7a98193SXiangliang Yu 	MMSCH_COMMAND__INDIRECT_REG_WRITE = 8,
34d7a98193SXiangliang Yu 	MMSCH_COMMAND__END = 0xf
35d7a98193SXiangliang Yu };
36d7a98193SXiangliang Yu 
37d7a98193SXiangliang Yu struct mmsch_v1_0_init_header {
38d7a98193SXiangliang Yu 	uint32_t version;
39d7a98193SXiangliang Yu 	uint32_t header_size;
40d7a98193SXiangliang Yu 	uint32_t vce_init_status;
41d7a98193SXiangliang Yu 	uint32_t uvd_init_status;
42d7a98193SXiangliang Yu 	uint32_t vce_table_offset;
43d7a98193SXiangliang Yu 	uint32_t vce_table_size;
44d7a98193SXiangliang Yu 	uint32_t uvd_table_offset;
45d7a98193SXiangliang Yu 	uint32_t uvd_table_size;
46d7a98193SXiangliang Yu };
47d7a98193SXiangliang Yu 
4895f1b55bSJane Jian struct mmsch_vf_eng_init_header {
4995f1b55bSJane Jian 	uint32_t init_status;
5095f1b55bSJane Jian 	uint32_t table_offset;
5195f1b55bSJane Jian 	uint32_t table_size;
5295f1b55bSJane Jian };
5395f1b55bSJane Jian 
5495f1b55bSJane Jian struct mmsch_v1_1_init_header {
5595f1b55bSJane Jian 	uint32_t version;
5695f1b55bSJane Jian 	uint32_t total_size;
5795f1b55bSJane Jian 	struct mmsch_vf_eng_init_header eng[2];
5895f1b55bSJane Jian };
5995f1b55bSJane Jian 
60d7a98193SXiangliang Yu struct mmsch_v1_0_cmd_direct_reg_header {
61d7a98193SXiangliang Yu 	uint32_t reg_offset   : 28;
62d7a98193SXiangliang Yu 	uint32_t command_type : 4;
63d7a98193SXiangliang Yu };
64d7a98193SXiangliang Yu 
65d7a98193SXiangliang Yu struct mmsch_v1_0_cmd_indirect_reg_header {
66d7a98193SXiangliang Yu 	uint32_t reg_offset    : 20;
67d7a98193SXiangliang Yu 	uint32_t reg_idx_space : 8;
68d7a98193SXiangliang Yu 	uint32_t command_type  : 4;
69d7a98193SXiangliang Yu };
70d7a98193SXiangliang Yu 
71d7a98193SXiangliang Yu struct mmsch_v1_0_cmd_direct_write {
72d7a98193SXiangliang Yu 	struct mmsch_v1_0_cmd_direct_reg_header cmd_header;
73d7a98193SXiangliang Yu 	uint32_t reg_value;
74d7a98193SXiangliang Yu };
75d7a98193SXiangliang Yu 
76d7a98193SXiangliang Yu struct mmsch_v1_0_cmd_direct_read_modify_write {
77d7a98193SXiangliang Yu 	struct mmsch_v1_0_cmd_direct_reg_header cmd_header;
78d7a98193SXiangliang Yu 	uint32_t write_data;
79d7a98193SXiangliang Yu 	uint32_t mask_value;
80d7a98193SXiangliang Yu };
81d7a98193SXiangliang Yu 
82d7a98193SXiangliang Yu struct mmsch_v1_0_cmd_direct_polling {
83d7a98193SXiangliang Yu 	struct mmsch_v1_0_cmd_direct_reg_header cmd_header;
84d7a98193SXiangliang Yu 	uint32_t mask_value;
85d7a98193SXiangliang Yu 	uint32_t wait_value;
86d7a98193SXiangliang Yu };
87d7a98193SXiangliang Yu 
88d7a98193SXiangliang Yu struct mmsch_v1_0_cmd_end {
89d7a98193SXiangliang Yu 	struct mmsch_v1_0_cmd_direct_reg_header cmd_header;
90d7a98193SXiangliang Yu };
91d7a98193SXiangliang Yu 
92d7a98193SXiangliang Yu struct mmsch_v1_0_cmd_indirect_write {
93d7a98193SXiangliang Yu 	struct mmsch_v1_0_cmd_indirect_reg_header cmd_header;
94d7a98193SXiangliang Yu 	uint32_t reg_value;
95d7a98193SXiangliang Yu };
96d7a98193SXiangliang Yu 
mmsch_v1_0_insert_direct_wt(struct mmsch_v1_0_cmd_direct_write * direct_wt,uint32_t * init_table,uint32_t reg_offset,uint32_t value)97a92f5ec0SFrank Min static inline void mmsch_v1_0_insert_direct_wt(struct mmsch_v1_0_cmd_direct_write *direct_wt,
98a92f5ec0SFrank Min 					       uint32_t *init_table,
99a92f5ec0SFrank Min 					       uint32_t reg_offset,
100a92f5ec0SFrank Min 					       uint32_t value)
101a92f5ec0SFrank Min {
102a92f5ec0SFrank Min 	direct_wt->cmd_header.reg_offset = reg_offset;
103a92f5ec0SFrank Min 	direct_wt->reg_value = value;
104a92f5ec0SFrank Min 	memcpy((void *)init_table, direct_wt, sizeof(struct mmsch_v1_0_cmd_direct_write));
105a92f5ec0SFrank Min }
106a92f5ec0SFrank Min 
mmsch_v1_0_insert_direct_rd_mod_wt(struct mmsch_v1_0_cmd_direct_read_modify_write * direct_rd_mod_wt,uint32_t * init_table,uint32_t reg_offset,uint32_t mask,uint32_t data)107a92f5ec0SFrank Min static inline void mmsch_v1_0_insert_direct_rd_mod_wt(struct mmsch_v1_0_cmd_direct_read_modify_write *direct_rd_mod_wt,
108a92f5ec0SFrank Min 						      uint32_t *init_table,
109a92f5ec0SFrank Min 						      uint32_t reg_offset,
110a92f5ec0SFrank Min 						      uint32_t mask, uint32_t data)
111a92f5ec0SFrank Min {
112a92f5ec0SFrank Min 	direct_rd_mod_wt->cmd_header.reg_offset = reg_offset;
113a92f5ec0SFrank Min 	direct_rd_mod_wt->mask_value = mask;
114a92f5ec0SFrank Min 	direct_rd_mod_wt->write_data = data;
115a92f5ec0SFrank Min 	memcpy((void *)init_table, direct_rd_mod_wt,
116a92f5ec0SFrank Min 	       sizeof(struct mmsch_v1_0_cmd_direct_read_modify_write));
117a92f5ec0SFrank Min }
118a92f5ec0SFrank Min 
mmsch_v1_0_insert_direct_poll(struct mmsch_v1_0_cmd_direct_polling * direct_poll,uint32_t * init_table,uint32_t reg_offset,uint32_t mask,uint32_t wait)119a92f5ec0SFrank Min static inline void mmsch_v1_0_insert_direct_poll(struct mmsch_v1_0_cmd_direct_polling *direct_poll,
120a92f5ec0SFrank Min 						 uint32_t *init_table,
121a92f5ec0SFrank Min 						 uint32_t reg_offset,
122a92f5ec0SFrank Min 						 uint32_t mask, uint32_t wait)
123a92f5ec0SFrank Min {
124a92f5ec0SFrank Min 	direct_poll->cmd_header.reg_offset = reg_offset;
125a92f5ec0SFrank Min 	direct_poll->mask_value = mask;
126a92f5ec0SFrank Min 	direct_poll->wait_value = wait;
127a92f5ec0SFrank Min 	memcpy((void *)init_table, direct_poll, sizeof(struct mmsch_v1_0_cmd_direct_polling));
128a92f5ec0SFrank Min }
129a92f5ec0SFrank Min 
130a92f5ec0SFrank Min #define MMSCH_V1_0_INSERT_DIRECT_RD_MOD_WT(reg, mask, data) { \
131a92f5ec0SFrank Min 	mmsch_v1_0_insert_direct_rd_mod_wt(&direct_rd_mod_wt, \
132a92f5ec0SFrank Min 					   init_table, (reg), \
133a92f5ec0SFrank Min 					   (mask), (data)); \
134a92f5ec0SFrank Min 	init_table += sizeof(struct mmsch_v1_0_cmd_direct_read_modify_write)/4; \
135a92f5ec0SFrank Min 	table_size += sizeof(struct mmsch_v1_0_cmd_direct_read_modify_write)/4; \
136a92f5ec0SFrank Min }
137a92f5ec0SFrank Min 
138a92f5ec0SFrank Min #define MMSCH_V1_0_INSERT_DIRECT_WT(reg, value) { \
139a92f5ec0SFrank Min 	mmsch_v1_0_insert_direct_wt(&direct_wt, \
140a92f5ec0SFrank Min 				    init_table, (reg), \
141a92f5ec0SFrank Min 				    (value)); \
142a92f5ec0SFrank Min 	init_table += sizeof(struct mmsch_v1_0_cmd_direct_write)/4; \
143a92f5ec0SFrank Min 	table_size += sizeof(struct mmsch_v1_0_cmd_direct_write)/4; \
144a92f5ec0SFrank Min }
145a92f5ec0SFrank Min 
146a92f5ec0SFrank Min #define MMSCH_V1_0_INSERT_DIRECT_POLL(reg, mask, wait) { \
147a92f5ec0SFrank Min 	mmsch_v1_0_insert_direct_poll(&direct_poll, \
148a92f5ec0SFrank Min 				      init_table, (reg), \
149a92f5ec0SFrank Min 				      (mask), (wait)); \
150a92f5ec0SFrank Min 	init_table += sizeof(struct mmsch_v1_0_cmd_direct_polling)/4; \
151a92f5ec0SFrank Min 	table_size += sizeof(struct mmsch_v1_0_cmd_direct_polling)/4; \
152a92f5ec0SFrank Min }
153a92f5ec0SFrank Min 
154d7a98193SXiangliang Yu #endif
155