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"
30 static void dc_dmub_srv_construct(struct dc_dmub_srv
*dc_srv
, struct dc
*dc
,
31 struct dmub_srv
*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
);
47 dc_dmub_srv_construct(dc_srv
, dc
, dmub
);
52 void dc_dmub_srv_destroy(struct dc_dmub_srv
**dmub_srv
)
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
)
71 if (status
!= DMUB_STATUS_QUEUE_FULL
)
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
)
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
;
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 */
122 DC_ERROR("DMCUB PHY init failed: status=%d\n", status
);
125 if (status
!= DMUB_STATUS_TIMEOUT
)
127 * Server likely initialized or we don't have
128 * DMCUB HW support - this won't end.
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
)
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
;