GNU Linux-libre 4.19.264-gnu1
[releases.git] / drivers / gpu / drm / amd / powerplay / smumgr / smumgr.c
1 /*
2  * Copyright 2015 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  */
23
24 #include <linux/delay.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
29 #include <drm/amdgpu_drm.h>
30 #include "smumgr.h"
31
32 /*(DEBLOBBED)*/
33
34 int smum_thermal_avfs_enable(struct pp_hwmgr *hwmgr)
35 {
36         if (NULL != hwmgr->smumgr_funcs->thermal_avfs_enable)
37                 return hwmgr->smumgr_funcs->thermal_avfs_enable(hwmgr);
38
39         return 0;
40 }
41
42 int smum_thermal_setup_fan_table(struct pp_hwmgr *hwmgr)
43 {
44         if (NULL != hwmgr->smumgr_funcs->thermal_setup_fan_table)
45                 return hwmgr->smumgr_funcs->thermal_setup_fan_table(hwmgr);
46
47         return 0;
48 }
49
50 int smum_update_sclk_threshold(struct pp_hwmgr *hwmgr)
51 {
52
53         if (NULL != hwmgr->smumgr_funcs->update_sclk_threshold)
54                 return hwmgr->smumgr_funcs->update_sclk_threshold(hwmgr);
55
56         return 0;
57 }
58
59 int smum_update_smc_table(struct pp_hwmgr *hwmgr, uint32_t type)
60 {
61
62         if (NULL != hwmgr->smumgr_funcs->update_smc_table)
63                 return hwmgr->smumgr_funcs->update_smc_table(hwmgr, type);
64
65         return 0;
66 }
67
68 uint32_t smum_get_offsetof(struct pp_hwmgr *hwmgr, uint32_t type, uint32_t member)
69 {
70         if (NULL != hwmgr->smumgr_funcs->get_offsetof)
71                 return hwmgr->smumgr_funcs->get_offsetof(type, member);
72
73         return 0;
74 }
75
76 int smum_process_firmware_header(struct pp_hwmgr *hwmgr)
77 {
78         if (NULL != hwmgr->smumgr_funcs->process_firmware_header)
79                 return hwmgr->smumgr_funcs->process_firmware_header(hwmgr);
80         return 0;
81 }
82
83 uint32_t smum_get_argument(struct pp_hwmgr *hwmgr)
84 {
85         if (NULL != hwmgr->smumgr_funcs->get_argument)
86                 return hwmgr->smumgr_funcs->get_argument(hwmgr);
87
88         return 0;
89 }
90
91 uint32_t smum_get_mac_definition(struct pp_hwmgr *hwmgr, uint32_t value)
92 {
93         if (NULL != hwmgr->smumgr_funcs->get_mac_definition)
94                 return hwmgr->smumgr_funcs->get_mac_definition(value);
95
96         return 0;
97 }
98
99 int smum_download_powerplay_table(struct pp_hwmgr *hwmgr, void **table)
100 {
101         if (NULL != hwmgr->smumgr_funcs->download_pptable_settings)
102                 return hwmgr->smumgr_funcs->download_pptable_settings(hwmgr,
103                                                                         table);
104         return 0;
105 }
106
107 int smum_upload_powerplay_table(struct pp_hwmgr *hwmgr)
108 {
109         if (NULL != hwmgr->smumgr_funcs->upload_pptable_settings)
110                 return hwmgr->smumgr_funcs->upload_pptable_settings(hwmgr);
111
112         return 0;
113 }
114
115 int smum_send_msg_to_smc(struct pp_hwmgr *hwmgr, uint16_t msg)
116 {
117         if (hwmgr == NULL || hwmgr->smumgr_funcs->send_msg_to_smc == NULL)
118                 return -EINVAL;
119
120         return hwmgr->smumgr_funcs->send_msg_to_smc(hwmgr, msg);
121 }
122
123 int smum_send_msg_to_smc_with_parameter(struct pp_hwmgr *hwmgr,
124                                         uint16_t msg, uint32_t parameter)
125 {
126         if (hwmgr == NULL ||
127                 hwmgr->smumgr_funcs->send_msg_to_smc_with_parameter == NULL)
128                 return -EINVAL;
129         return hwmgr->smumgr_funcs->send_msg_to_smc_with_parameter(
130                                                 hwmgr, msg, parameter);
131 }
132
133 int smum_init_smc_table(struct pp_hwmgr *hwmgr)
134 {
135         if (NULL != hwmgr->smumgr_funcs->init_smc_table)
136                 return hwmgr->smumgr_funcs->init_smc_table(hwmgr);
137
138         return 0;
139 }
140
141 int smum_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
142 {
143         if (NULL != hwmgr->smumgr_funcs->populate_all_graphic_levels)
144                 return hwmgr->smumgr_funcs->populate_all_graphic_levels(hwmgr);
145
146         return 0;
147 }
148
149 int smum_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
150 {
151         if (NULL != hwmgr->smumgr_funcs->populate_all_memory_levels)
152                 return hwmgr->smumgr_funcs->populate_all_memory_levels(hwmgr);
153
154         return 0;
155 }
156
157 /*this interface is needed by island ci/vi */
158 int smum_initialize_mc_reg_table(struct pp_hwmgr *hwmgr)
159 {
160         if (NULL != hwmgr->smumgr_funcs->initialize_mc_reg_table)
161                 return hwmgr->smumgr_funcs->initialize_mc_reg_table(hwmgr);
162
163         return 0;
164 }
165
166 bool smum_is_dpm_running(struct pp_hwmgr *hwmgr)
167 {
168         if (NULL != hwmgr->smumgr_funcs->is_dpm_running)
169                 return hwmgr->smumgr_funcs->is_dpm_running(hwmgr);
170
171         return true;
172 }
173
174 bool smum_is_hw_avfs_present(struct pp_hwmgr *hwmgr)
175 {
176         if (hwmgr->smumgr_funcs->is_hw_avfs_present)
177                 return hwmgr->smumgr_funcs->is_hw_avfs_present(hwmgr);
178
179         return false;
180 }
181
182 int smum_update_dpm_settings(struct pp_hwmgr *hwmgr, void *profile_setting)
183 {
184         if (hwmgr->smumgr_funcs->update_dpm_settings)
185                 return hwmgr->smumgr_funcs->update_dpm_settings(hwmgr, profile_setting);
186
187         return -EINVAL;
188 }
189
190 int smum_smc_table_manager(struct pp_hwmgr *hwmgr, uint8_t *table, uint16_t table_id, bool rw)
191 {
192         if (hwmgr->smumgr_funcs->smc_table_manager)
193                 return hwmgr->smumgr_funcs->smc_table_manager(hwmgr, table, table_id, rw);
194
195         return -EINVAL;
196 }
197
198 int smum_stop_smc(struct pp_hwmgr *hwmgr)
199 {
200         if (hwmgr->smumgr_funcs->stop_smc)
201                 return hwmgr->smumgr_funcs->stop_smc(hwmgr);
202
203         return 0;
204 }