1 /*
2  * Copyright 2020 Advanced Micro Devices, Inc.
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 #ifndef _DMUB_DCN31_H_
27 #define _DMUB_DCN31_H_
28 
29 #include "dmub_dcn20.h"
30 
31 struct dmub_srv;
32 
33 /* DCN31 register definitions. */
34 
35 #define DMUB_DCN31_REGS() \
36 	DMUB_SR(DMCUB_CNTL) \
37 	DMUB_SR(DMCUB_CNTL2) \
38 	DMUB_SR(DMCUB_SEC_CNTL) \
39 	DMUB_SR(DMCUB_INBOX1_BASE_ADDRESS) \
40 	DMUB_SR(DMCUB_INBOX1_SIZE) \
41 	DMUB_SR(DMCUB_INBOX1_RPTR) \
42 	DMUB_SR(DMCUB_INBOX1_WPTR) \
43 	DMUB_SR(DMCUB_OUTBOX0_BASE_ADDRESS) \
44 	DMUB_SR(DMCUB_OUTBOX0_SIZE) \
45 	DMUB_SR(DMCUB_OUTBOX0_RPTR) \
46 	DMUB_SR(DMCUB_OUTBOX0_WPTR) \
47 	DMUB_SR(DMCUB_OUTBOX1_BASE_ADDRESS) \
48 	DMUB_SR(DMCUB_OUTBOX1_SIZE) \
49 	DMUB_SR(DMCUB_OUTBOX1_RPTR) \
50 	DMUB_SR(DMCUB_OUTBOX1_WPTR) \
51 	DMUB_SR(DMCUB_REGION3_CW0_OFFSET) \
52 	DMUB_SR(DMCUB_REGION3_CW1_OFFSET) \
53 	DMUB_SR(DMCUB_REGION3_CW2_OFFSET) \
54 	DMUB_SR(DMCUB_REGION3_CW3_OFFSET) \
55 	DMUB_SR(DMCUB_REGION3_CW4_OFFSET) \
56 	DMUB_SR(DMCUB_REGION3_CW5_OFFSET) \
57 	DMUB_SR(DMCUB_REGION3_CW6_OFFSET) \
58 	DMUB_SR(DMCUB_REGION3_CW7_OFFSET) \
59 	DMUB_SR(DMCUB_REGION3_CW0_OFFSET_HIGH) \
60 	DMUB_SR(DMCUB_REGION3_CW1_OFFSET_HIGH) \
61 	DMUB_SR(DMCUB_REGION3_CW2_OFFSET_HIGH) \
62 	DMUB_SR(DMCUB_REGION3_CW3_OFFSET_HIGH) \
63 	DMUB_SR(DMCUB_REGION3_CW4_OFFSET_HIGH) \
64 	DMUB_SR(DMCUB_REGION3_CW5_OFFSET_HIGH) \
65 	DMUB_SR(DMCUB_REGION3_CW6_OFFSET_HIGH) \
66 	DMUB_SR(DMCUB_REGION3_CW7_OFFSET_HIGH) \
67 	DMUB_SR(DMCUB_REGION3_CW0_BASE_ADDRESS) \
68 	DMUB_SR(DMCUB_REGION3_CW1_BASE_ADDRESS) \
69 	DMUB_SR(DMCUB_REGION3_CW2_BASE_ADDRESS) \
70 	DMUB_SR(DMCUB_REGION3_CW3_BASE_ADDRESS) \
71 	DMUB_SR(DMCUB_REGION3_CW4_BASE_ADDRESS) \
72 	DMUB_SR(DMCUB_REGION3_CW5_BASE_ADDRESS) \
73 	DMUB_SR(DMCUB_REGION3_CW6_BASE_ADDRESS) \
74 	DMUB_SR(DMCUB_REGION3_CW7_BASE_ADDRESS) \
75 	DMUB_SR(DMCUB_REGION3_CW0_TOP_ADDRESS) \
76 	DMUB_SR(DMCUB_REGION3_CW1_TOP_ADDRESS) \
77 	DMUB_SR(DMCUB_REGION3_CW2_TOP_ADDRESS) \
78 	DMUB_SR(DMCUB_REGION3_CW3_TOP_ADDRESS) \
79 	DMUB_SR(DMCUB_REGION3_CW4_TOP_ADDRESS) \
80 	DMUB_SR(DMCUB_REGION3_CW5_TOP_ADDRESS) \
81 	DMUB_SR(DMCUB_REGION3_CW6_TOP_ADDRESS) \
82 	DMUB_SR(DMCUB_REGION3_CW7_TOP_ADDRESS) \
83 	DMUB_SR(DMCUB_REGION4_OFFSET) \
84 	DMUB_SR(DMCUB_REGION4_OFFSET_HIGH) \
85 	DMUB_SR(DMCUB_REGION4_TOP_ADDRESS) \
86 	DMUB_SR(DMCUB_REGION5_OFFSET) \
87 	DMUB_SR(DMCUB_REGION5_OFFSET_HIGH) \
88 	DMUB_SR(DMCUB_REGION5_TOP_ADDRESS) \
89 	DMUB_SR(DMCUB_SCRATCH0) \
90 	DMUB_SR(DMCUB_SCRATCH1) \
91 	DMUB_SR(DMCUB_SCRATCH2) \
92 	DMUB_SR(DMCUB_SCRATCH3) \
93 	DMUB_SR(DMCUB_SCRATCH4) \
94 	DMUB_SR(DMCUB_SCRATCH5) \
95 	DMUB_SR(DMCUB_SCRATCH6) \
96 	DMUB_SR(DMCUB_SCRATCH7) \
97 	DMUB_SR(DMCUB_SCRATCH8) \
98 	DMUB_SR(DMCUB_SCRATCH9) \
99 	DMUB_SR(DMCUB_SCRATCH10) \
100 	DMUB_SR(DMCUB_SCRATCH11) \
101 	DMUB_SR(DMCUB_SCRATCH12) \
102 	DMUB_SR(DMCUB_SCRATCH13) \
103 	DMUB_SR(DMCUB_SCRATCH14) \
104 	DMUB_SR(DMCUB_SCRATCH15) \
105 	DMUB_SR(DMCUB_GPINT_DATAIN1) \
106 	DMUB_SR(CC_DC_PIPE_DIS) \
107 	DMUB_SR(MMHUBBUB_SOFT_RESET) \
108 	DMUB_SR(DCN_VM_FB_LOCATION_BASE) \
109 	DMUB_SR(DCN_VM_FB_OFFSET) \
110 	DMUB_SR(DMCUB_TIMER_CURRENT)
111 
112 #define DMUB_DCN31_FIELDS() \
113 	DMUB_SF(DMCUB_CNTL, DMCUB_ENABLE) \
114 	DMUB_SF(DMCUB_CNTL, DMCUB_TRACEPORT_EN) \
115 	DMUB_SF(DMCUB_CNTL2, DMCUB_SOFT_RESET) \
116 	DMUB_SF(DMCUB_SEC_CNTL, DMCUB_SEC_RESET) \
117 	DMUB_SF(DMCUB_SEC_CNTL, DMCUB_MEM_UNIT_ID) \
118 	DMUB_SF(DMCUB_REGION3_CW0_TOP_ADDRESS, DMCUB_REGION3_CW0_TOP_ADDRESS) \
119 	DMUB_SF(DMCUB_REGION3_CW0_TOP_ADDRESS, DMCUB_REGION3_CW0_ENABLE) \
120 	DMUB_SF(DMCUB_REGION3_CW1_TOP_ADDRESS, DMCUB_REGION3_CW1_TOP_ADDRESS) \
121 	DMUB_SF(DMCUB_REGION3_CW1_TOP_ADDRESS, DMCUB_REGION3_CW1_ENABLE) \
122 	DMUB_SF(DMCUB_REGION3_CW2_TOP_ADDRESS, DMCUB_REGION3_CW2_TOP_ADDRESS) \
123 	DMUB_SF(DMCUB_REGION3_CW2_TOP_ADDRESS, DMCUB_REGION3_CW2_ENABLE) \
124 	DMUB_SF(DMCUB_REGION3_CW3_TOP_ADDRESS, DMCUB_REGION3_CW3_TOP_ADDRESS) \
125 	DMUB_SF(DMCUB_REGION3_CW3_TOP_ADDRESS, DMCUB_REGION3_CW3_ENABLE) \
126 	DMUB_SF(DMCUB_REGION3_CW4_TOP_ADDRESS, DMCUB_REGION3_CW4_TOP_ADDRESS) \
127 	DMUB_SF(DMCUB_REGION3_CW4_TOP_ADDRESS, DMCUB_REGION3_CW4_ENABLE) \
128 	DMUB_SF(DMCUB_REGION3_CW5_TOP_ADDRESS, DMCUB_REGION3_CW5_TOP_ADDRESS) \
129 	DMUB_SF(DMCUB_REGION3_CW5_TOP_ADDRESS, DMCUB_REGION3_CW5_ENABLE) \
130 	DMUB_SF(DMCUB_REGION3_CW6_TOP_ADDRESS, DMCUB_REGION3_CW6_TOP_ADDRESS) \
131 	DMUB_SF(DMCUB_REGION3_CW6_TOP_ADDRESS, DMCUB_REGION3_CW6_ENABLE) \
132 	DMUB_SF(DMCUB_REGION3_CW7_TOP_ADDRESS, DMCUB_REGION3_CW7_TOP_ADDRESS) \
133 	DMUB_SF(DMCUB_REGION3_CW7_TOP_ADDRESS, DMCUB_REGION3_CW7_ENABLE) \
134 	DMUB_SF(DMCUB_REGION4_TOP_ADDRESS, DMCUB_REGION4_TOP_ADDRESS) \
135 	DMUB_SF(DMCUB_REGION4_TOP_ADDRESS, DMCUB_REGION4_ENABLE) \
136 	DMUB_SF(DMCUB_REGION5_TOP_ADDRESS, DMCUB_REGION5_TOP_ADDRESS) \
137 	DMUB_SF(DMCUB_REGION5_TOP_ADDRESS, DMCUB_REGION5_ENABLE) \
138 	DMUB_SF(CC_DC_PIPE_DIS, DC_DMCUB_ENABLE) \
139 	DMUB_SF(MMHUBBUB_SOFT_RESET, DMUIF_SOFT_RESET) \
140 	DMUB_SF(DCN_VM_FB_LOCATION_BASE, FB_BASE) \
141 	DMUB_SF(DCN_VM_FB_OFFSET, FB_OFFSET)
142 
143 struct dmub_srv_dcn31_reg_offset {
144 #define DMUB_SR(reg) uint32_t reg;
145 	DMUB_DCN31_REGS()
146 #undef DMUB_SR
147 };
148 
149 struct dmub_srv_dcn31_reg_shift {
150 #define DMUB_SF(reg, field) uint8_t reg##__##field;
151 	DMUB_DCN31_FIELDS()
152 #undef DMUB_SF
153 };
154 
155 struct dmub_srv_dcn31_reg_mask {
156 #define DMUB_SF(reg, field) uint32_t reg##__##field;
157 	DMUB_DCN31_FIELDS()
158 #undef DMUB_SF
159 };
160 
161 struct dmub_srv_dcn31_regs {
162 	const struct dmub_srv_dcn31_reg_offset offset;
163 	const struct dmub_srv_dcn31_reg_mask mask;
164 	const struct dmub_srv_dcn31_reg_shift shift;
165 };
166 
167 extern const struct dmub_srv_dcn31_regs dmub_srv_dcn31_regs;
168 
169 /* Hardware functions. */
170 
171 
172 void dmub_dcn31_init(struct dmub_srv *dmub);
173 
174 void dmub_dcn31_reset(struct dmub_srv *dmub);
175 
176 void dmub_dcn31_reset_release(struct dmub_srv *dmub);
177 
178 void dmub_dcn31_backdoor_load(struct dmub_srv *dmub,
179 			      const struct dmub_window *cw0,
180 			      const struct dmub_window *cw1);
181 
182 void dmub_dcn31_setup_windows(struct dmub_srv *dmub,
183 			      const struct dmub_window *cw2,
184 			      const struct dmub_window *cw3,
185 			      const struct dmub_window *cw4,
186 			      const struct dmub_window *cw5,
187 			      const struct dmub_window *cw6);
188 
189 void dmub_dcn31_setup_mailbox(struct dmub_srv *dmub,
190 			      const struct dmub_region *inbox1);
191 
192 uint32_t dmub_dcn31_get_inbox1_rptr(struct dmub_srv *dmub);
193 
194 void dmub_dcn31_set_inbox1_wptr(struct dmub_srv *dmub, uint32_t wptr_offset);
195 
196 void dmub_dcn31_setup_out_mailbox(struct dmub_srv *dmub,
197 			      const struct dmub_region *outbox1);
198 
199 uint32_t dmub_dcn31_get_outbox1_wptr(struct dmub_srv *dmub);
200 
201 void dmub_dcn31_set_outbox1_rptr(struct dmub_srv *dmub, uint32_t rptr_offset);
202 
203 bool dmub_dcn31_is_hw_init(struct dmub_srv *dmub);
204 
205 bool dmub_dcn31_is_supported(struct dmub_srv *dmub);
206 
207 void dmub_dcn31_set_gpint(struct dmub_srv *dmub,
208 			  union dmub_gpint_data_register reg);
209 
210 bool dmub_dcn31_is_gpint_acked(struct dmub_srv *dmub,
211 			       union dmub_gpint_data_register reg);
212 
213 uint32_t dmub_dcn31_get_gpint_response(struct dmub_srv *dmub);
214 
215 void dmub_dcn31_enable_dmub_boot_options(struct dmub_srv *dmub, const struct dmub_srv_hw_params *params);
216 
217 void dmub_dcn31_skip_dmub_panel_power_sequence(struct dmub_srv *dmub, bool skip);
218 
219 union dmub_fw_boot_status dmub_dcn31_get_fw_boot_status(struct dmub_srv *dmub);
220 
221 void dmub_dcn31_setup_outbox0(struct dmub_srv *dmub,
222 			      const struct dmub_region *outbox0);
223 
224 uint32_t dmub_dcn31_get_outbox0_wptr(struct dmub_srv *dmub);
225 
226 void dmub_dcn31_set_outbox0_rptr(struct dmub_srv *dmub, uint32_t rptr_offset);
227 
228 uint32_t dmub_dcn31_get_current_time(struct dmub_srv *dmub);
229 
230 #endif /* _DMUB_DCN31_H_ */
231