2 * Copyright 2016 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.
22 * Author: Huang Rui <ray.huang@amd.com>
25 #include <linux/types.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/gfp.h>
31 #include "iceland_smumgr.h"
33 #include "smu_ucode_xfer_vi.h"
35 #include "smu/smu_7_1_1_d.h"
36 #include "smu/smu_7_1_1_sh_mask.h"
37 #include "cgs_common.h"
38 #include "iceland_smc.h"
40 #define ICELAND_SMC_SIZE 0x20000
42 static int iceland_start_smc(struct pp_smumgr
*smumgr
)
44 SMUM_WRITE_INDIRECT_FIELD(smumgr
->device
, CGS_IND_REG__SMC
,
45 SMC_SYSCON_RESET_CNTL
, rst_reg
, 0);
50 static void iceland_reset_smc(struct pp_smumgr
*smumgr
)
52 SMUM_WRITE_INDIRECT_FIELD(smumgr
->device
, CGS_IND_REG__SMC
,
53 SMC_SYSCON_RESET_CNTL
,
58 static void iceland_stop_smc_clock(struct pp_smumgr
*smumgr
)
60 SMUM_WRITE_INDIRECT_FIELD(smumgr
->device
, CGS_IND_REG__SMC
,
61 SMC_SYSCON_CLOCK_CNTL_0
,
65 static void iceland_start_smc_clock(struct pp_smumgr
*smumgr
)
67 SMUM_WRITE_INDIRECT_FIELD(smumgr
->device
, CGS_IND_REG__SMC
,
68 SMC_SYSCON_CLOCK_CNTL_0
,
72 static int iceland_smu_start_smc(struct pp_smumgr
*smumgr
)
74 /* set smc instruct start point at 0x0 */
75 smu7_program_jump_on_start(smumgr
);
77 /* enable smc clock */
78 iceland_start_smc_clock(smumgr
);
81 iceland_start_smc(smumgr
);
83 SMUM_WAIT_INDIRECT_FIELD(smumgr
, SMC_IND
, FIRMWARE_FLAGS
,
84 INTERRUPTS_ENABLED
, 1);
90 static int iceland_upload_smc_firmware_data(struct pp_smumgr
*smumgr
,
91 uint32_t length
, const uint8_t *src
,
92 uint32_t limit
, uint32_t start_addr
)
94 uint32_t byte_count
= length
;
97 PP_ASSERT_WITH_CODE((limit
>= byte_count
), "SMC address is beyond the SMC RAM area.", return -EINVAL
);
99 cgs_write_register(smumgr
->device
, mmSMC_IND_INDEX_0
, start_addr
);
100 SMUM_WRITE_FIELD(smumgr
->device
, SMC_IND_ACCESS_CNTL
, AUTO_INCREMENT_IND_0
, 1);
102 while (byte_count
>= 4) {
103 data
= src
[0] * 0x1000000 + src
[1] * 0x10000 + src
[2] * 0x100 + src
[3];
104 cgs_write_register(smumgr
->device
, mmSMC_IND_DATA_0
, data
);
109 SMUM_WRITE_FIELD(smumgr
->device
, SMC_IND_ACCESS_CNTL
, AUTO_INCREMENT_IND_0
, 0);
111 PP_ASSERT_WITH_CODE((0 == byte_count
), "SMC size must be dividable by 4.", return -EINVAL
);
117 static int iceland_smu_upload_firmware_image(struct pp_smumgr
*smumgr
)
120 struct cgs_firmware_info info
= {0};
122 if (smumgr
== NULL
|| smumgr
->device
== NULL
)
125 /* load SMC firmware */
126 cgs_get_firmware_info(smumgr
->device
,
127 smu7_convert_fw_type_to_cgs(UCODE_ID_SMU
), &info
);
129 if (info
.image_size
& 3) {
130 pr_err("[ powerplay ] SMC ucode is not 4 bytes aligned\n");
134 if (info
.image_size
> ICELAND_SMC_SIZE
) {
135 pr_err("[ powerplay ] SMC address is beyond the SMC RAM area\n");
139 /* wait for smc boot up */
140 SMUM_WAIT_INDIRECT_FIELD_UNEQUAL(smumgr
, SMC_IND
,
141 RCU_UC_EVENTS
, boot_seq_done
, 0);
143 /* clear firmware interrupt enable flag */
144 val
= cgs_read_ind_register(smumgr
->device
, CGS_IND_REG__SMC
,
145 ixSMC_SYSCON_MISC_CNTL
);
146 cgs_write_ind_register(smumgr
->device
, CGS_IND_REG__SMC
,
147 ixSMC_SYSCON_MISC_CNTL
, val
| 1);
150 iceland_stop_smc_clock(smumgr
);
153 iceland_reset_smc(smumgr
);
154 iceland_upload_smc_firmware_data(smumgr
, info
.image_size
,
155 (uint8_t *)info
.kptr
, ICELAND_SMC_SIZE
,
156 info
.ucode_start_address
);
161 static int iceland_request_smu_load_specific_fw(struct pp_smumgr
*smumgr
,
162 uint32_t firmwareType
)
167 static int iceland_start_smu(struct pp_smumgr
*smumgr
)
171 result
= iceland_smu_upload_firmware_image(smumgr
);
174 result
= iceland_smu_start_smc(smumgr
);
178 if (!smu7_is_smc_ram_running(smumgr
)) {
179 printk("smu not running, upload firmware again \n");
180 result
= iceland_smu_upload_firmware_image(smumgr
);
184 result
= iceland_smu_start_smc(smumgr
);
189 result
= smu7_request_smu_load_fw(smumgr
);
195 * Write a 32bit value to the SMC SRAM space.
196 * ALL PARAMETERS ARE IN HOST BYTE ORDER.
197 * @param smumgr the address of the powerplay hardware manager.
198 * @param smcAddress the address in the SMC RAM to access.
199 * @param value to write to the SMC SRAM.
201 static int iceland_smu_init(struct pp_smumgr
*smumgr
)
204 struct iceland_smumgr
*smu_data
= (struct iceland_smumgr
*)(smumgr
->backend
);
205 if (smu7_init(smumgr
))
208 for (i
= 0; i
< SMU71_MAX_LEVELS_GRAPHICS
; i
++)
209 smu_data
->activity_target
[i
] = 30;
214 static const struct pp_smumgr_func iceland_smu_funcs
= {
215 .smu_init
= &iceland_smu_init
,
216 .smu_fini
= &smu7_smu_fini
,
217 .start_smu
= &iceland_start_smu
,
218 .check_fw_load_finish
= &smu7_check_fw_load_finish
,
219 .request_smu_load_fw
= &smu7_reload_firmware
,
220 .request_smu_load_specific_fw
= &iceland_request_smu_load_specific_fw
,
221 .send_msg_to_smc
= &smu7_send_msg_to_smc
,
222 .send_msg_to_smc_with_parameter
= &smu7_send_msg_to_smc_with_parameter
,
223 .download_pptable_settings
= NULL
,
224 .upload_pptable_settings
= NULL
,
225 .get_offsetof
= iceland_get_offsetof
,
226 .process_firmware_header
= iceland_process_firmware_header
,
227 .init_smc_table
= iceland_init_smc_table
,
228 .update_sclk_threshold
= iceland_update_sclk_threshold
,
229 .thermal_setup_fan_table
= iceland_thermal_setup_fan_table
,
230 .populate_all_graphic_levels
= iceland_populate_all_graphic_levels
,
231 .populate_all_memory_levels
= iceland_populate_all_memory_levels
,
232 .get_mac_definition
= iceland_get_mac_definition
,
233 .initialize_mc_reg_table
= iceland_initialize_mc_reg_table
,
234 .is_dpm_running
= iceland_is_dpm_running
,
237 int iceland_smum_init(struct pp_smumgr
*smumgr
)
239 struct iceland_smumgr
*iceland_smu
= NULL
;
241 iceland_smu
= kzalloc(sizeof(struct iceland_smumgr
), GFP_KERNEL
);
243 if (iceland_smu
== NULL
)
246 smumgr
->backend
= iceland_smu
;
247 smumgr
->smumgr_funcs
= &iceland_smu_funcs
;