2 * Copyright 2019 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
27 #include "dc_dmub_srv.h"
28 #include "../dmub/dmub_srv.h"
29 #include "dm_helpers.h"
31 #define CTX dc_dmub_srv->ctx
32 #define DC_LOGGER CTX->logger
34 static void dc_dmub_srv_construct(struct dc_dmub_srv *dc_srv, struct dc *dc,
35 struct dmub_srv *dmub)
38 dc_srv->ctx = dc->ctx;
41 struct dc_dmub_srv *dc_dmub_srv_create(struct dc *dc, struct dmub_srv *dmub)
43 struct dc_dmub_srv *dc_srv =
44 kzalloc(sizeof(struct dc_dmub_srv), GFP_KERNEL);
51 dc_dmub_srv_construct(dc_srv, dc, dmub);
56 void dc_dmub_srv_destroy(struct dc_dmub_srv **dmub_srv)
64 void dc_dmub_srv_cmd_queue(struct dc_dmub_srv *dc_dmub_srv,
65 union dmub_rb_cmd *cmd)
67 struct dmub_srv *dmub = dc_dmub_srv->dmub;
68 struct dc_context *dc_ctx = dc_dmub_srv->ctx;
69 enum dmub_status status;
71 status = dmub_srv_cmd_queue(dmub, cmd);
72 if (status == DMUB_STATUS_OK)
75 if (status != DMUB_STATUS_QUEUE_FULL)
78 /* Execute and wait for queue to become empty again. */
79 dc_dmub_srv_cmd_execute(dc_dmub_srv);
80 dc_dmub_srv_wait_idle(dc_dmub_srv);
82 /* Requeue the command. */
83 status = dmub_srv_cmd_queue(dmub, cmd);
84 if (status == DMUB_STATUS_OK)
88 DC_ERROR("Error queuing DMUB command: status=%d\n", status);
89 dc_dmub_srv_log_diagnostic_data(dc_dmub_srv);
92 void dc_dmub_srv_cmd_execute(struct dc_dmub_srv *dc_dmub_srv)
94 struct dmub_srv *dmub = dc_dmub_srv->dmub;
95 struct dc_context *dc_ctx = dc_dmub_srv->ctx;
96 enum dmub_status status;
98 status = dmub_srv_cmd_execute(dmub);
99 if (status != DMUB_STATUS_OK) {
100 DC_ERROR("Error starting DMUB execution: status=%d\n", status);
101 dc_dmub_srv_log_diagnostic_data(dc_dmub_srv);
105 void dc_dmub_srv_wait_idle(struct dc_dmub_srv *dc_dmub_srv)
107 struct dmub_srv *dmub = dc_dmub_srv->dmub;
108 struct dc_context *dc_ctx = dc_dmub_srv->ctx;
109 enum dmub_status status;
111 status = dmub_srv_wait_for_idle(dmub, 100000);
112 if (status != DMUB_STATUS_OK) {
113 DC_ERROR("Error waiting for DMUB idle: status=%d\n", status);
114 dc_dmub_srv_log_diagnostic_data(dc_dmub_srv);
118 void dc_dmub_srv_send_inbox0_cmd(struct dc_dmub_srv *dmub_srv,
119 union dmub_inbox0_data_register data)
121 struct dmub_srv *dmub = dmub_srv->dmub;
122 if (dmub->hw_funcs.send_inbox0_cmd)
123 dmub->hw_funcs.send_inbox0_cmd(dmub, data);
124 // TODO: Add wait command -- poll register for ACK
127 bool dc_dmub_srv_cmd_with_reply_data(struct dc_dmub_srv *dc_dmub_srv, union dmub_rb_cmd *cmd)
129 struct dmub_srv *dmub;
130 enum dmub_status status;
132 if (!dc_dmub_srv || !dc_dmub_srv->dmub)
135 dmub = dc_dmub_srv->dmub;
137 status = dmub_srv_cmd_with_reply_data(dmub, cmd);
138 if (status != DMUB_STATUS_OK) {
139 DC_LOG_DEBUG("No reply for DMUB command: status=%d\n", status);
146 void dc_dmub_srv_wait_phy_init(struct dc_dmub_srv *dc_dmub_srv)
148 struct dmub_srv *dmub = dc_dmub_srv->dmub;
149 struct dc_context *dc_ctx = dc_dmub_srv->ctx;
150 enum dmub_status status;
153 /* Wait up to a second for PHY init. */
154 status = dmub_srv_wait_for_phy_init(dmub, 1000000);
155 if (status == DMUB_STATUS_OK)
156 /* Initialization OK */
159 DC_ERROR("DMCUB PHY init failed: status=%d\n", status);
162 if (status != DMUB_STATUS_TIMEOUT)
164 * Server likely initialized or we don't have
165 * DMCUB HW support - this won't end.
169 /* Continue spinning so we don't hang the ASIC. */
173 bool dc_dmub_srv_notify_stream_mask(struct dc_dmub_srv *dc_dmub_srv,
174 unsigned int stream_mask)
176 struct dmub_srv *dmub;
177 const uint32_t timeout = 30;
179 if (!dc_dmub_srv || !dc_dmub_srv->dmub)
182 dmub = dc_dmub_srv->dmub;
184 return dmub_srv_send_gpint_command(
185 dmub, DMUB_GPINT__IDLE_OPT_NOTIFY_STREAM_MASK,
186 stream_mask, timeout) == DMUB_STATUS_OK;
189 bool dc_dmub_srv_is_restore_required(struct dc_dmub_srv *dc_dmub_srv)
191 struct dmub_srv *dmub;
192 struct dc_context *dc_ctx;
193 union dmub_fw_boot_status boot_status;
194 enum dmub_status status;
196 if (!dc_dmub_srv || !dc_dmub_srv->dmub)
199 dmub = dc_dmub_srv->dmub;
200 dc_ctx = dc_dmub_srv->ctx;
202 status = dmub_srv_get_fw_boot_status(dmub, &boot_status);
203 if (status != DMUB_STATUS_OK) {
204 DC_ERROR("Error querying DMUB boot status: error=%d\n", status);
208 return boot_status.bits.restore_required;
211 bool dc_dmub_srv_get_dmub_outbox0_msg(const struct dc *dc, struct dmcub_trace_buf_entry *entry)
213 struct dmub_srv *dmub = dc->ctx->dmub_srv->dmub;
214 return dmub_srv_get_outbox0_msg(dmub, entry);
217 void dc_dmub_trace_event_control(struct dc *dc, bool enable)
219 dm_helpers_dmub_outbox_interrupt_control(dc->ctx, enable);
222 bool dc_dmub_srv_get_diagnostic_data(struct dc_dmub_srv *dc_dmub_srv, struct dmub_diagnostic_data *diag_data)
224 if (!dc_dmub_srv || !dc_dmub_srv->dmub || !diag_data)
226 return dmub_srv_get_diagnostic_data(dc_dmub_srv->dmub, diag_data);
229 void dc_dmub_srv_log_diagnostic_data(struct dc_dmub_srv *dc_dmub_srv)
231 struct dmub_diagnostic_data diag_data = {0};
233 if (!dc_dmub_srv || !dc_dmub_srv->dmub) {
234 DC_LOG_ERROR("%s: invalid parameters.", __func__);
238 if (!dc_dmub_srv_get_diagnostic_data(dc_dmub_srv, &diag_data)) {
239 DC_LOG_ERROR("%s: dc_dmub_srv_get_diagnostic_data failed.", __func__);
245 " dmcub_version : %08x\n"
246 " scratch [0] : %08x\n"
247 " scratch [1] : %08x\n"
248 " scratch [2] : %08x\n"
249 " scratch [3] : %08x\n"
250 " scratch [4] : %08x\n"
251 " scratch [5] : %08x\n"
252 " scratch [6] : %08x\n"
253 " scratch [7] : %08x\n"
254 " scratch [8] : %08x\n"
255 " scratch [9] : %08x\n"
256 " scratch [10] : %08x\n"
257 " scratch [11] : %08x\n"
258 " scratch [12] : %08x\n"
259 " scratch [13] : %08x\n"
260 " scratch [14] : %08x\n"
261 " scratch [15] : %08x\n"
263 " unk_fault_addr : %08x\n"
264 " inst_fault_addr : %08x\n"
265 " data_fault_addr : %08x\n"
266 " inbox1_rptr : %08x\n"
267 " inbox1_wptr : %08x\n"
268 " inbox1_size : %08x\n"
269 " inbox0_rptr : %08x\n"
270 " inbox0_wptr : %08x\n"
271 " inbox0_size : %08x\n"
273 " is_soft_reset : %d\n"
274 " is_secure_reset : %d\n"
275 " is_traceport_en : %d\n"
278 diag_data.dmcub_version,
279 diag_data.scratch[0],
280 diag_data.scratch[1],
281 diag_data.scratch[2],
282 diag_data.scratch[3],
283 diag_data.scratch[4],
284 diag_data.scratch[5],
285 diag_data.scratch[6],
286 diag_data.scratch[7],
287 diag_data.scratch[8],
288 diag_data.scratch[9],
289 diag_data.scratch[10],
290 diag_data.scratch[11],
291 diag_data.scratch[12],
292 diag_data.scratch[13],
293 diag_data.scratch[14],
294 diag_data.scratch[15],
296 diag_data.undefined_address_fault_addr,
297 diag_data.inst_fetch_fault_addr,
298 diag_data.data_write_fault_addr,
299 diag_data.inbox1_rptr,
300 diag_data.inbox1_wptr,
301 diag_data.inbox1_size,
302 diag_data.inbox0_rptr,
303 diag_data.inbox0_wptr,
304 diag_data.inbox0_size,
305 diag_data.is_dmcub_enabled,
306 diag_data.is_dmcub_soft_reset,
307 diag_data.is_dmcub_secure_reset,
308 diag_data.is_traceport_en,
309 diag_data.is_cw0_enabled,
310 diag_data.is_cw6_enabled);