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  
dmub_hw_lock_mgr_cmd(struct dc_dmub_srv * dmub_srv,bool lock,union dmub_hw_lock_flags * hw_locks,struct dmub_hw_lock_inst_flags * inst_flags)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  
dmub_hw_lock_mgr_inbox0_cmd(struct dc_dmub_srv * dmub_srv,union dmub_inbox0_cmd_lock_hw hw_lock_cmd)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  
should_use_dmub_lock(struct dc_link * link)64  bool should_use_dmub_lock(struct dc_link *link)
65  {
66  	if (link->psr_settings.psr_version == DC_PSR_VERSION_SU_1)
67  		return true;
68  
69  	if (link->replay_settings.replay_feature_enabled)
70  		return true;
71  
72  	return false;
73  }
74