1 /*
2  * Copyright 2016 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 __DC_HUBBUB_DCN10_H__
27 #define __DC_HUBBUB_DCN10_H__
28 
29 #include "core_types.h"
30 #include "dchubbub.h"
31 
32 #define TO_DCN10_HUBBUB(hubbub)\
33 	container_of(hubbub, struct dcn10_hubbub, base)
34 
35 #define HUBHUB_REG_LIST_DCN()\
36 	SR(DCHUBBUB_ARB_DATA_URGENCY_WATERMARK_A),\
37 	SR(DCHUBBUB_ARB_PTE_META_URGENCY_WATERMARK_A),\
38 	SR(DCHUBBUB_ARB_ALLOW_DRAM_CLK_CHANGE_WATERMARK_A),\
39 	SR(DCHUBBUB_ARB_DATA_URGENCY_WATERMARK_B),\
40 	SR(DCHUBBUB_ARB_PTE_META_URGENCY_WATERMARK_B),\
41 	SR(DCHUBBUB_ARB_ALLOW_DRAM_CLK_CHANGE_WATERMARK_B),\
42 	SR(DCHUBBUB_ARB_DATA_URGENCY_WATERMARK_C),\
43 	SR(DCHUBBUB_ARB_PTE_META_URGENCY_WATERMARK_C),\
44 	SR(DCHUBBUB_ARB_ALLOW_DRAM_CLK_CHANGE_WATERMARK_C),\
45 	SR(DCHUBBUB_ARB_DATA_URGENCY_WATERMARK_D),\
46 	SR(DCHUBBUB_ARB_PTE_META_URGENCY_WATERMARK_D),\
47 	SR(DCHUBBUB_ARB_ALLOW_DRAM_CLK_CHANGE_WATERMARK_D),\
48 	SR(DCHUBBUB_ARB_WATERMARK_CHANGE_CNTL),\
49 	SR(DCHUBBUB_ARB_DRAM_STATE_CNTL),\
50 	SR(DCHUBBUB_ARB_SAT_LEVEL),\
51 	SR(DCHUBBUB_ARB_DF_REQ_OUTSTAND),\
52 	SR(DCHUBBUB_GLOBAL_TIMER_CNTL), \
53 	SR(DCHUBBUB_TEST_DEBUG_INDEX), \
54 	SR(DCHUBBUB_TEST_DEBUG_DATA),\
55 	SR(DCHUBBUB_SOFT_RESET)
56 
57 #define HUBBUB_SR_WATERMARK_REG_LIST()\
58 	SR(DCHUBBUB_ARB_ALLOW_SR_ENTER_WATERMARK_A),\
59 	SR(DCHUBBUB_ARB_ALLOW_SR_EXIT_WATERMARK_A),\
60 	SR(DCHUBBUB_ARB_ALLOW_SR_ENTER_WATERMARK_B),\
61 	SR(DCHUBBUB_ARB_ALLOW_SR_EXIT_WATERMARK_B),\
62 	SR(DCHUBBUB_ARB_ALLOW_SR_ENTER_WATERMARK_C),\
63 	SR(DCHUBBUB_ARB_ALLOW_SR_EXIT_WATERMARK_C),\
64 	SR(DCHUBBUB_ARB_ALLOW_SR_ENTER_WATERMARK_D),\
65 	SR(DCHUBBUB_ARB_ALLOW_SR_EXIT_WATERMARK_D)
66 
67 #define HUBBUB_REG_LIST_DCN10(id)\
68 	HUBHUB_REG_LIST_DCN(), \
69 	HUBBUB_SR_WATERMARK_REG_LIST(), \
70 	SR(DCHUBBUB_SDPIF_FB_TOP),\
71 	SR(DCHUBBUB_SDPIF_FB_BASE),\
72 	SR(DCHUBBUB_SDPIF_FB_OFFSET),\
73 	SR(DCHUBBUB_SDPIF_AGP_BASE),\
74 	SR(DCHUBBUB_SDPIF_AGP_BOT),\
75 	SR(DCHUBBUB_SDPIF_AGP_TOP)
76 
77 struct dcn_hubbub_registers {
78 	uint32_t DCHUBBUB_ARB_DATA_URGENCY_WATERMARK_A;
79 	uint32_t DCHUBBUB_ARB_PTE_META_URGENCY_WATERMARK_A;
80 	uint32_t DCHUBBUB_ARB_ALLOW_SR_ENTER_WATERMARK_A;
81 	uint32_t DCHUBBUB_ARB_ALLOW_SR_EXIT_WATERMARK_A;
82 	uint32_t DCHUBBUB_ARB_ALLOW_DRAM_CLK_CHANGE_WATERMARK_A;
83 	uint32_t DCHUBBUB_ARB_DATA_URGENCY_WATERMARK_B;
84 	uint32_t DCHUBBUB_ARB_PTE_META_URGENCY_WATERMARK_B;
85 	uint32_t DCHUBBUB_ARB_ALLOW_SR_ENTER_WATERMARK_B;
86 	uint32_t DCHUBBUB_ARB_ALLOW_SR_EXIT_WATERMARK_B;
87 	uint32_t DCHUBBUB_ARB_ALLOW_DRAM_CLK_CHANGE_WATERMARK_B;
88 	uint32_t DCHUBBUB_ARB_DATA_URGENCY_WATERMARK_C;
89 	uint32_t DCHUBBUB_ARB_PTE_META_URGENCY_WATERMARK_C;
90 	uint32_t DCHUBBUB_ARB_ALLOW_SR_ENTER_WATERMARK_C;
91 	uint32_t DCHUBBUB_ARB_ALLOW_SR_EXIT_WATERMARK_C;
92 	uint32_t DCHUBBUB_ARB_ALLOW_DRAM_CLK_CHANGE_WATERMARK_C;
93 	uint32_t DCHUBBUB_ARB_DATA_URGENCY_WATERMARK_D;
94 	uint32_t DCHUBBUB_ARB_PTE_META_URGENCY_WATERMARK_D;
95 	uint32_t DCHUBBUB_ARB_ALLOW_SR_ENTER_WATERMARK_D;
96 	uint32_t DCHUBBUB_ARB_ALLOW_SR_EXIT_WATERMARK_D;
97 	uint32_t DCHUBBUB_ARB_ALLOW_DRAM_CLK_CHANGE_WATERMARK_D;
98 	uint32_t DCHUBBUB_ARB_WATERMARK_CHANGE_CNTL;
99 	uint32_t DCHUBBUB_ARB_SAT_LEVEL;
100 	uint32_t DCHUBBUB_ARB_DF_REQ_OUTSTAND;
101 	uint32_t DCHUBBUB_GLOBAL_TIMER_CNTL;
102 	uint32_t DCHUBBUB_ARB_DRAM_STATE_CNTL;
103 	uint32_t DCHUBBUB_TEST_DEBUG_INDEX;
104 	uint32_t DCHUBBUB_TEST_DEBUG_DATA;
105 	uint32_t DCHUBBUB_SDPIF_FB_TOP;
106 	uint32_t DCHUBBUB_SDPIF_FB_BASE;
107 	uint32_t DCHUBBUB_SDPIF_FB_OFFSET;
108 	uint32_t DCHUBBUB_SDPIF_AGP_BASE;
109 	uint32_t DCHUBBUB_SDPIF_AGP_BOT;
110 	uint32_t DCHUBBUB_SDPIF_AGP_TOP;
111 	uint32_t DCHUBBUB_CRC_CTRL;
112 	uint32_t DCHUBBUB_SOFT_RESET;
113 	uint32_t DCN_VM_FB_LOCATION_BASE;
114 	uint32_t DCN_VM_FB_LOCATION_TOP;
115 	uint32_t DCN_VM_FB_OFFSET;
116 	uint32_t DCN_VM_AGP_BOT;
117 	uint32_t DCN_VM_AGP_TOP;
118 	uint32_t DCN_VM_AGP_BASE;
119 };
120 
121 /* set field name */
122 #define HUBBUB_SF(reg_name, field_name, post_fix)\
123 	.field_name = reg_name ## __ ## field_name ## post_fix
124 
125 
126 #define HUBBUB_MASK_SH_LIST_DCN(mask_sh)\
127 		HUBBUB_SF(DCHUBBUB_GLOBAL_TIMER_CNTL, DCHUBBUB_GLOBAL_TIMER_ENABLE, mask_sh), \
128 		HUBBUB_SF(DCHUBBUB_SOFT_RESET, DCHUBBUB_GLOBAL_SOFT_RESET, mask_sh), \
129 		HUBBUB_SF(DCHUBBUB_ARB_WATERMARK_CHANGE_CNTL, DCHUBBUB_ARB_WATERMARK_CHANGE_REQUEST, mask_sh), \
130 		HUBBUB_SF(DCHUBBUB_ARB_WATERMARK_CHANGE_CNTL, DCHUBBUB_ARB_WATERMARK_CHANGE_DONE_INTERRUPT_DISABLE, mask_sh), \
131 		HUBBUB_SF(DCHUBBUB_ARB_DRAM_STATE_CNTL, DCHUBBUB_ARB_ALLOW_SELF_REFRESH_FORCE_VALUE, mask_sh), \
132 		HUBBUB_SF(DCHUBBUB_ARB_DRAM_STATE_CNTL, DCHUBBUB_ARB_ALLOW_SELF_REFRESH_FORCE_ENABLE, mask_sh), \
133 		HUBBUB_SF(DCHUBBUB_ARB_DRAM_STATE_CNTL, DCHUBBUB_ARB_ALLOW_PSTATE_CHANGE_FORCE_VALUE, mask_sh), \
134 		HUBBUB_SF(DCHUBBUB_ARB_DRAM_STATE_CNTL, DCHUBBUB_ARB_ALLOW_PSTATE_CHANGE_FORCE_ENABLE, mask_sh), \
135 		HUBBUB_SF(DCHUBBUB_ARB_SAT_LEVEL, DCHUBBUB_ARB_SAT_LEVEL, mask_sh), \
136 		HUBBUB_SF(DCHUBBUB_ARB_DF_REQ_OUTSTAND, DCHUBBUB_ARB_MIN_REQ_OUTSTAND, mask_sh)
137 
138 #define HUBBUB_MASK_SH_LIST_DCN10(mask_sh)\
139 		HUBBUB_MASK_SH_LIST_DCN(mask_sh), \
140 		HUBBUB_SF(DCHUBBUB_SDPIF_FB_TOP, SDPIF_FB_TOP, mask_sh), \
141 		HUBBUB_SF(DCHUBBUB_SDPIF_FB_BASE, SDPIF_FB_BASE, mask_sh), \
142 		HUBBUB_SF(DCHUBBUB_SDPIF_FB_OFFSET, SDPIF_FB_OFFSET, mask_sh), \
143 		HUBBUB_SF(DCHUBBUB_SDPIF_AGP_BASE, SDPIF_AGP_BASE, mask_sh), \
144 		HUBBUB_SF(DCHUBBUB_SDPIF_AGP_BOT, SDPIF_AGP_BOT, mask_sh), \
145 		HUBBUB_SF(DCHUBBUB_SDPIF_AGP_TOP, SDPIF_AGP_TOP, mask_sh)
146 
147 #define DCN_HUBBUB_REG_FIELD_LIST(type) \
148 		type DCHUBBUB_GLOBAL_TIMER_ENABLE; \
149 		type DCHUBBUB_ARB_WATERMARK_CHANGE_REQUEST;\
150 		type DCHUBBUB_ARB_WATERMARK_CHANGE_DONE_INTERRUPT_DISABLE;\
151 		type DCHUBBUB_ARB_ALLOW_SELF_REFRESH_FORCE_VALUE;\
152 		type DCHUBBUB_ARB_ALLOW_SELF_REFRESH_FORCE_ENABLE;\
153 		type DCHUBBUB_ARB_ALLOW_PSTATE_CHANGE_FORCE_VALUE;\
154 		type DCHUBBUB_ARB_ALLOW_PSTATE_CHANGE_FORCE_ENABLE;\
155 		type DCHUBBUB_ARB_SAT_LEVEL;\
156 		type DCHUBBUB_ARB_MIN_REQ_OUTSTAND;\
157 		type DCHUBBUB_GLOBAL_TIMER_REFDIV;\
158 		type DCHUBBUB_GLOBAL_SOFT_RESET; \
159 		type SDPIF_FB_TOP;\
160 		type SDPIF_FB_BASE;\
161 		type SDPIF_FB_OFFSET;\
162 		type SDPIF_AGP_BASE;\
163 		type SDPIF_AGP_BOT;\
164 		type SDPIF_AGP_TOP;\
165 		type FB_BASE;\
166 		type FB_TOP;\
167 		type FB_OFFSET;\
168 		type AGP_BOT;\
169 		type AGP_TOP;\
170 		type AGP_BASE
171 
172 
173 struct dcn_hubbub_shift {
174 	DCN_HUBBUB_REG_FIELD_LIST(uint8_t);
175 };
176 
177 struct dcn_hubbub_mask {
178 	DCN_HUBBUB_REG_FIELD_LIST(uint32_t);
179 };
180 
181 struct dc;
182 
183 struct dcn10_hubbub {
184 	struct hubbub base;
185 	const struct dcn_hubbub_registers *regs;
186 	const struct dcn_hubbub_shift *shifts;
187 	const struct dcn_hubbub_mask *masks;
188 	unsigned int debug_test_index_pstate;
189 	struct dcn_watermark_set watermarks;
190 };
191 
192 void hubbub1_update_dchub(
193 	struct hubbub *hubbub,
194 	struct dchub_init_data *dh_data);
195 
196 bool hubbub1_verify_allow_pstate_change_high(
197 	struct hubbub *hubbub);
198 
199 void hubbub1_wm_change_req_wa(struct hubbub *hubbub);
200 
201 void hubbub1_program_watermarks(
202 		struct hubbub *hubbub,
203 		struct dcn_watermark_set *watermarks,
204 		unsigned int refclk_mhz,
205 		bool safe_to_lower);
206 
207 void hubbub1_allow_self_refresh_control(struct hubbub *hubbub, bool allow);
208 
209 bool hububu1_is_allow_self_refresh_enabled(struct hubbub *hubub);
210 
211 void hubbub1_toggle_watermark_change_req(
212 		struct hubbub *hubbub);
213 
214 void hubbub1_wm_read_state(struct hubbub *hubbub,
215 		struct dcn_hubbub_wm *wm);
216 
217 void hubbub1_soft_reset(struct hubbub *hubbub, bool reset);
218 void hubbub1_construct(struct hubbub *hubbub,
219 	struct dc_context *ctx,
220 	const struct dcn_hubbub_registers *hubbub_regs,
221 	const struct dcn_hubbub_shift *hubbub_shift,
222 	const struct dcn_hubbub_mask *hubbub_mask);
223 
224 #endif
225