2 * Copyright 2015 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.
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 "pp_instance.h"
32 #include "cgs_common.h"
34 MODULE_FIRMWARE("amdgpu/topaz_smc.bin");
35 MODULE_FIRMWARE("amdgpu/topaz_k_smc.bin");
36 MODULE_FIRMWARE("amdgpu/tonga_smc.bin");
37 MODULE_FIRMWARE("amdgpu/tonga_k_smc.bin");
38 MODULE_FIRMWARE("amdgpu/fiji_smc.bin");
39 MODULE_FIRMWARE("amdgpu/polaris10_smc.bin");
40 MODULE_FIRMWARE("amdgpu/polaris10_smc_sk.bin");
41 MODULE_FIRMWARE("amdgpu/polaris10_k_smc.bin");
42 MODULE_FIRMWARE("amdgpu/polaris11_smc.bin");
43 MODULE_FIRMWARE("amdgpu/polaris11_smc_sk.bin");
44 MODULE_FIRMWARE("amdgpu/polaris11_k_smc.bin");
45 MODULE_FIRMWARE("amdgpu/polaris12_smc.bin");
48 int smum_early_init(struct pp_instance
*handle
)
50 struct pp_smumgr
*smumgr
;
55 smumgr
= kzalloc(sizeof(struct pp_smumgr
), GFP_KERNEL
);
59 smumgr
->device
= handle
->device
;
60 smumgr
->chip_family
= handle
->chip_family
;
61 smumgr
->chip_id
= handle
->chip_id
;
62 smumgr
->usec_timeout
= AMD_MAX_USEC_TIMEOUT
;
63 smumgr
->reload_fw
= 1;
64 handle
->smu_mgr
= smumgr
;
66 switch (smumgr
->chip_family
) {
67 case AMDGPU_FAMILY_CZ
:
68 smumgr
->smumgr_funcs
= &cz_smu_funcs
;
70 case AMDGPU_FAMILY_VI
:
71 switch (smumgr
->chip_id
) {
73 smumgr
->smumgr_funcs
= &iceland_smu_funcs
;
76 smumgr
->smumgr_funcs
= &tonga_smu_funcs
;
79 smumgr
->smumgr_funcs
= &fiji_smu_funcs
;
84 smumgr
->smumgr_funcs
= &polaris10_smu_funcs
;
90 case AMDGPU_FAMILY_AI
:
91 switch (smumgr
->chip_id
) {
93 smumgr
->smumgr_funcs
= &vega10_smu_funcs
;
107 int smum_thermal_avfs_enable(struct pp_hwmgr
*hwmgr
,
108 void *input
, void *output
, void *storage
, int result
)
110 if (NULL
!= hwmgr
->smumgr
->smumgr_funcs
->thermal_avfs_enable
)
111 return hwmgr
->smumgr
->smumgr_funcs
->thermal_avfs_enable(hwmgr
);
116 int smum_thermal_setup_fan_table(struct pp_hwmgr
*hwmgr
,
117 void *input
, void *output
, void *storage
, int result
)
119 if (NULL
!= hwmgr
->smumgr
->smumgr_funcs
->thermal_setup_fan_table
)
120 return hwmgr
->smumgr
->smumgr_funcs
->thermal_setup_fan_table(hwmgr
);
125 int smum_update_sclk_threshold(struct pp_hwmgr
*hwmgr
)
128 if (NULL
!= hwmgr
->smumgr
->smumgr_funcs
->update_sclk_threshold
)
129 return hwmgr
->smumgr
->smumgr_funcs
->update_sclk_threshold(hwmgr
);
134 int smum_update_smc_table(struct pp_hwmgr
*hwmgr
, uint32_t type
)
137 if (NULL
!= hwmgr
->smumgr
->smumgr_funcs
->update_smc_table
)
138 return hwmgr
->smumgr
->smumgr_funcs
->update_smc_table(hwmgr
, type
);
143 uint32_t smum_get_offsetof(struct pp_smumgr
*smumgr
, uint32_t type
, uint32_t member
)
145 if (NULL
!= smumgr
->smumgr_funcs
->get_offsetof
)
146 return smumgr
->smumgr_funcs
->get_offsetof(type
, member
);
151 int smum_process_firmware_header(struct pp_hwmgr
*hwmgr
)
153 if (NULL
!= hwmgr
->smumgr
->smumgr_funcs
->process_firmware_header
)
154 return hwmgr
->smumgr
->smumgr_funcs
->process_firmware_header(hwmgr
);
158 int smum_get_argument(struct pp_smumgr
*smumgr
)
160 if (NULL
!= smumgr
->smumgr_funcs
->get_argument
)
161 return smumgr
->smumgr_funcs
->get_argument(smumgr
);
166 uint32_t smum_get_mac_definition(struct pp_smumgr
*smumgr
, uint32_t value
)
168 if (NULL
!= smumgr
->smumgr_funcs
->get_mac_definition
)
169 return smumgr
->smumgr_funcs
->get_mac_definition(value
);
174 int smum_download_powerplay_table(struct pp_smumgr
*smumgr
,
177 if (NULL
!= smumgr
->smumgr_funcs
->download_pptable_settings
)
178 return smumgr
->smumgr_funcs
->download_pptable_settings(smumgr
,
183 int smum_upload_powerplay_table(struct pp_smumgr
*smumgr
)
185 if (NULL
!= smumgr
->smumgr_funcs
->upload_pptable_settings
)
186 return smumgr
->smumgr_funcs
->upload_pptable_settings(smumgr
);
191 int smum_send_msg_to_smc(struct pp_smumgr
*smumgr
, uint16_t msg
)
193 if (smumgr
== NULL
|| smumgr
->smumgr_funcs
->send_msg_to_smc
== NULL
)
196 return smumgr
->smumgr_funcs
->send_msg_to_smc(smumgr
, msg
);
199 int smum_send_msg_to_smc_with_parameter(struct pp_smumgr
*smumgr
,
200 uint16_t msg
, uint32_t parameter
)
202 if (smumgr
== NULL
||
203 smumgr
->smumgr_funcs
->send_msg_to_smc_with_parameter
== NULL
)
205 return smumgr
->smumgr_funcs
->send_msg_to_smc_with_parameter(
206 smumgr
, msg
, parameter
);
210 * Returns once the part of the register indicated by the mask has
211 * reached the given value.
213 int smum_wait_on_register(struct pp_smumgr
*smumgr
,
215 uint32_t value
, uint32_t mask
)
220 if (smumgr
== NULL
|| smumgr
->device
== NULL
)
223 for (i
= 0; i
< smumgr
->usec_timeout
; i
++) {
224 cur_value
= cgs_read_register(smumgr
->device
, index
);
225 if ((cur_value
& mask
) == (value
& mask
))
230 /* timeout means wrong logic*/
231 if (i
== smumgr
->usec_timeout
)
237 int smum_wait_for_register_unequal(struct pp_smumgr
*smumgr
,
239 uint32_t value
, uint32_t mask
)
247 for (i
= 0; i
< smumgr
->usec_timeout
; i
++) {
248 cur_value
= cgs_read_register(smumgr
->device
,
250 if ((cur_value
& mask
) != (value
& mask
))
255 /* timeout means wrong logic */
256 if (i
== smumgr
->usec_timeout
)
264 * Returns once the part of the register indicated by the mask
265 * has reached the given value.The indirect space is described by
266 * giving the memory-mapped index of the indirect index register.
268 int smum_wait_on_indirect_register(struct pp_smumgr
*smumgr
,
269 uint32_t indirect_port
,
274 if (smumgr
== NULL
|| smumgr
->device
== NULL
)
277 cgs_write_register(smumgr
->device
, indirect_port
, index
);
278 return smum_wait_on_register(smumgr
, indirect_port
+ 1,
282 void smum_wait_for_indirect_register_unequal(
283 struct pp_smumgr
*smumgr
,
284 uint32_t indirect_port
,
289 if (smumgr
== NULL
|| smumgr
->device
== NULL
)
291 cgs_write_register(smumgr
->device
, indirect_port
, index
);
292 smum_wait_for_register_unequal(smumgr
, indirect_port
+ 1,
296 int smu_allocate_memory(void *device
, uint32_t size
,
297 enum cgs_gpu_mem_type type
,
298 uint32_t byte_align
, uint64_t *mc_addr
,
299 void **kptr
, void *handle
)
302 cgs_handle_t cgs_handle
;
304 if (device
== NULL
|| handle
== NULL
||
305 mc_addr
== NULL
|| kptr
== NULL
)
308 ret
= cgs_alloc_gpu_mem(device
, type
, size
, byte_align
,
309 0, 0, (cgs_handle_t
*)handle
);
313 cgs_handle
= *(cgs_handle_t
*)handle
;
315 ret
= cgs_gmap_gpu_mem(device
, cgs_handle
, mc_addr
);
319 ret
= cgs_kmap_gpu_mem(device
, cgs_handle
, kptr
);
326 cgs_gunmap_gpu_mem(device
, cgs_handle
);
329 cgs_free_gpu_mem(device
, cgs_handle
);
333 int smu_free_memory(void *device
, void *handle
)
335 cgs_handle_t cgs_handle
= (cgs_handle_t
)handle
;
337 if (device
== NULL
|| handle
== NULL
)
340 cgs_kunmap_gpu_mem(device
, cgs_handle
);
341 cgs_gunmap_gpu_mem(device
, cgs_handle
);
342 cgs_free_gpu_mem(device
, cgs_handle
);
347 int smum_init_smc_table(struct pp_hwmgr
*hwmgr
)
349 if (NULL
!= hwmgr
->smumgr
->smumgr_funcs
->init_smc_table
)
350 return hwmgr
->smumgr
->smumgr_funcs
->init_smc_table(hwmgr
);
355 int smum_populate_all_graphic_levels(struct pp_hwmgr
*hwmgr
)
357 if (NULL
!= hwmgr
->smumgr
->smumgr_funcs
->populate_all_graphic_levels
)
358 return hwmgr
->smumgr
->smumgr_funcs
->populate_all_graphic_levels(hwmgr
);
363 int smum_populate_all_memory_levels(struct pp_hwmgr
*hwmgr
)
365 if (NULL
!= hwmgr
->smumgr
->smumgr_funcs
->populate_all_memory_levels
)
366 return hwmgr
->smumgr
->smumgr_funcs
->populate_all_memory_levels(hwmgr
);
371 /*this interface is needed by island ci/vi */
372 int smum_initialize_mc_reg_table(struct pp_hwmgr
*hwmgr
)
374 if (NULL
!= hwmgr
->smumgr
->smumgr_funcs
->initialize_mc_reg_table
)
375 return hwmgr
->smumgr
->smumgr_funcs
->initialize_mc_reg_table(hwmgr
);
380 bool smum_is_dpm_running(struct pp_hwmgr
*hwmgr
)
382 if (NULL
!= hwmgr
->smumgr
->smumgr_funcs
->is_dpm_running
)
383 return hwmgr
->smumgr
->smumgr_funcs
->is_dpm_running(hwmgr
);
388 int smum_populate_requested_graphic_levels(struct pp_hwmgr
*hwmgr
,
389 struct amd_pp_profile
*request
)
391 if (hwmgr
->smumgr
->smumgr_funcs
->populate_requested_graphic_levels
)
392 return hwmgr
->smumgr
->smumgr_funcs
->populate_requested_graphic_levels(