1 /* 2 * Copyright 2019 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 #include "dmub_hw_lock_mgr.h" 27 #include "dc_dmub_srv.h" 28 #include "dc_types.h" 29 #include "core_types.h" 30 31 void dmub_hw_lock_mgr_cmd(struct dc_dmub_srv *dmub_srv, 32 bool lock, 33 union dmub_hw_lock_flags *hw_locks, 34 struct dmub_hw_lock_inst_flags *inst_flags) 35 { 36 union dmub_rb_cmd cmd; 37 38 memset(&cmd, 0, sizeof(cmd)); 39 cmd.lock_hw.header.type = DMUB_CMD__HW_LOCK; 40 cmd.lock_hw.header.sub_type = 0; 41 cmd.lock_hw.header.payload_bytes = sizeof(struct dmub_cmd_lock_hw_data); 42 cmd.lock_hw.lock_hw_data.client = HW_LOCK_CLIENT_DRIVER; 43 cmd.lock_hw.lock_hw_data.lock = lock; 44 cmd.lock_hw.lock_hw_data.hw_locks.u8All = hw_locks->u8All; 45 memcpy(&cmd.lock_hw.lock_hw_data.inst_flags, inst_flags, sizeof(struct dmub_hw_lock_inst_flags)); 46 47 if (!lock) 48 cmd.lock_hw.lock_hw_data.should_release = 1; 49 50 dc_wake_and_execute_dmub_cmd(dmub_srv->ctx, &cmd, DM_DMUB_WAIT_TYPE_WAIT); 51 } 52 53 void dmub_hw_lock_mgr_inbox0_cmd(struct dc_dmub_srv *dmub_srv, 54 union dmub_inbox0_cmd_lock_hw hw_lock_cmd) 55 { 56 union dmub_inbox0_data_register data = { 0 }; 57 58 data.inbox0_cmd_lock_hw = hw_lock_cmd; 59 dc_dmub_srv_clear_inbox0_ack(dmub_srv); 60 dc_dmub_srv_send_inbox0_cmd(dmub_srv, data); 61 dc_dmub_srv_wait_for_inbox0_ack(dmub_srv); 62 } 63 64 bool dmub_hw_lock_mgr_does_link_require_lock(const struct dc *dc, const struct dc_link *link) 65 { 66 if (!link) 67 return false; 68 69 if (link->psr_settings.psr_version == DC_PSR_VERSION_SU_1) 70 return true; 71 72 if (link->replay_settings.replay_feature_enabled) 73 return true; 74 75 if (link->psr_settings.psr_version == DC_PSR_VERSION_1) { 76 struct dc_link *edp_links[MAX_NUM_EDP]; 77 int edp_num; 78 79 dc_get_edp_links(dc, edp_links, &edp_num); 80 if (edp_num == 1) 81 return true; 82 } 83 return false; 84 } 85 86 bool dmub_hw_lock_mgr_does_context_require_lock(const struct dc *dc, const struct dc_state *context) 87 { 88 if (!context) 89 return false; 90 for (int i = 0; i < context->stream_count; i++) { 91 const struct dc_link *link = context->streams[i]->link; 92 93 if (dmub_hw_lock_mgr_does_link_require_lock(dc, link)) 94 return true; 95 } 96 return false; 97 } 98 99 bool should_use_dmub_inbox1_lock(const struct dc *dc, const struct dc_link *link) 100 { 101 /* ASIC doesn't support DMUB */ 102 if (!dc->ctx->dmub_srv) 103 return false; 104 105 if (dc->ctx->dce_version >= DCN_VERSION_4_01) 106 return false; 107 108 return dmub_hw_lock_mgr_does_link_require_lock(dc, link); 109 } 110