WIP FPC-III support
[linux/fpc-iii.git] / drivers / gpu / drm / amd / display / dc / dc_dmub_srv.c
blobb987548119772544db73e9c0d7ac0c4278d0327d
1 /*
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.
22 * Authors: AMD
26 #include "dc.h"
27 #include "dc_dmub_srv.h"
28 #include "../dmub/dmub_srv.h"
30 static void dc_dmub_srv_construct(struct dc_dmub_srv *dc_srv, struct dc *dc,
31 struct dmub_srv *dmub)
33 dc_srv->dmub = dmub;
34 dc_srv->ctx = dc->ctx;
37 struct dc_dmub_srv *dc_dmub_srv_create(struct dc *dc, struct dmub_srv *dmub)
39 struct dc_dmub_srv *dc_srv =
40 kzalloc(sizeof(struct dc_dmub_srv), GFP_KERNEL);
42 if (dc_srv == NULL) {
43 BREAK_TO_DEBUGGER();
44 return NULL;
47 dc_dmub_srv_construct(dc_srv, dc, dmub);
49 return dc_srv;
52 void dc_dmub_srv_destroy(struct dc_dmub_srv **dmub_srv)
54 if (*dmub_srv) {
55 kfree(*dmub_srv);
56 *dmub_srv = NULL;
60 void dc_dmub_srv_cmd_queue(struct dc_dmub_srv *dc_dmub_srv,
61 union dmub_rb_cmd *cmd)
63 struct dmub_srv *dmub = dc_dmub_srv->dmub;
64 struct dc_context *dc_ctx = dc_dmub_srv->ctx;
65 enum dmub_status status;
67 status = dmub_srv_cmd_queue(dmub, cmd);
68 if (status == DMUB_STATUS_OK)
69 return;
71 if (status != DMUB_STATUS_QUEUE_FULL)
72 goto error;
74 /* Execute and wait for queue to become empty again. */
75 dc_dmub_srv_cmd_execute(dc_dmub_srv);
76 dc_dmub_srv_wait_idle(dc_dmub_srv);
78 /* Requeue the command. */
79 status = dmub_srv_cmd_queue(dmub, cmd);
80 if (status == DMUB_STATUS_OK)
81 return;
83 error:
84 DC_ERROR("Error queuing DMUB command: status=%d\n", status);
87 void dc_dmub_srv_cmd_execute(struct dc_dmub_srv *dc_dmub_srv)
89 struct dmub_srv *dmub = dc_dmub_srv->dmub;
90 struct dc_context *dc_ctx = dc_dmub_srv->ctx;
91 enum dmub_status status;
93 status = dmub_srv_cmd_execute(dmub);
94 if (status != DMUB_STATUS_OK)
95 DC_ERROR("Error starting DMUB execution: status=%d\n", status);
98 void dc_dmub_srv_wait_idle(struct dc_dmub_srv *dc_dmub_srv)
100 struct dmub_srv *dmub = dc_dmub_srv->dmub;
101 struct dc_context *dc_ctx = dc_dmub_srv->ctx;
102 enum dmub_status status;
104 status = dmub_srv_wait_for_idle(dmub, 100000);
105 if (status != DMUB_STATUS_OK)
106 DC_ERROR("Error waiting for DMUB idle: status=%d\n", status);
109 void dc_dmub_srv_wait_phy_init(struct dc_dmub_srv *dc_dmub_srv)
111 struct dmub_srv *dmub = dc_dmub_srv->dmub;
112 struct dc_context *dc_ctx = dc_dmub_srv->ctx;
113 enum dmub_status status;
115 for (;;) {
116 /* Wait up to a second for PHY init. */
117 status = dmub_srv_wait_for_phy_init(dmub, 1000000);
118 if (status == DMUB_STATUS_OK)
119 /* Initialization OK */
120 break;
122 DC_ERROR("DMCUB PHY init failed: status=%d\n", status);
123 ASSERT(0);
125 if (status != DMUB_STATUS_TIMEOUT)
127 * Server likely initialized or we don't have
128 * DMCUB HW support - this won't end.
130 break;
132 /* Continue spinning so we don't hang the ASIC. */
136 bool dc_dmub_srv_notify_stream_mask(struct dc_dmub_srv *dc_dmub_srv,
137 unsigned int stream_mask)
139 struct dmub_srv *dmub;
140 const uint32_t timeout = 30;
142 if (!dc_dmub_srv || !dc_dmub_srv->dmub)
143 return false;
145 dmub = dc_dmub_srv->dmub;
147 return dmub_srv_send_gpint_command(
148 dmub, DMUB_GPINT__IDLE_OPT_NOTIFY_STREAM_MASK,
149 stream_mask, timeout) == DMUB_STATUS_OK;