blob: 8c2204c7b3847c3ce18042b48d70516155b843e5 [file] [log] [blame]
Huang Rui0e5ca0d2017-03-03 18:37:23 -05001/*
2 * Copyright 2016 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 * Author: Huang Rui
23 *
24 */
25
26#include <linux/firmware.h>
Masahiro Yamada248a1d62017-04-24 13:50:21 +090027#include <drm/drmP.h>
Huang Rui0e5ca0d2017-03-03 18:37:23 -050028#include "amdgpu.h"
29#include "amdgpu_psp.h"
30#include "amdgpu_ucode.h"
31#include "soc15_common.h"
32#include "psp_v3_1.h"
Huang Ruic1798b52016-12-16 10:08:48 +080033#include "psp_v10_0.h"
Huang Rui0e5ca0d2017-03-03 18:37:23 -050034
35static void psp_set_funcs(struct amdgpu_device *adev);
36
37static int psp_early_init(void *handle)
38{
39 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
40
41 psp_set_funcs(adev);
42
43 return 0;
44}
45
46static int psp_sw_init(void *handle)
47{
48 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
49 struct psp_context *psp = &adev->psp;
50 int ret;
51
52 switch (adev->asic_type) {
53 case CHIP_VEGA10:
54 psp->init_microcode = psp_v3_1_init_microcode;
55 psp->bootloader_load_sysdrv = psp_v3_1_bootloader_load_sysdrv;
56 psp->bootloader_load_sos = psp_v3_1_bootloader_load_sos;
57 psp->prep_cmd_buf = psp_v3_1_prep_cmd_buf;
58 psp->ring_init = psp_v3_1_ring_init;
Huang Ruibe70bbd2017-03-21 18:36:57 +080059 psp->ring_create = psp_v3_1_ring_create;
Trigger Huange3c5e982017-04-17 08:50:18 -040060 psp->ring_destroy = psp_v3_1_ring_destroy;
Huang Rui0e5ca0d2017-03-03 18:37:23 -050061 psp->cmd_submit = psp_v3_1_cmd_submit;
62 psp->compare_sram_data = psp_v3_1_compare_sram_data;
63 psp->smu_reload_quirk = psp_v3_1_smu_reload_quirk;
64 break;
Huang Ruic1798b52016-12-16 10:08:48 +080065 case CHIP_RAVEN:
Junwei Zhang16a53a02017-07-19 08:23:24 +080066#if 0
Junwei Zhang6ab77112017-07-14 18:31:18 +080067 psp->init_microcode = psp_v10_0_init_microcode;
Junwei Zhang16a53a02017-07-19 08:23:24 +080068#endif
Huang Ruic1798b52016-12-16 10:08:48 +080069 psp->prep_cmd_buf = psp_v10_0_prep_cmd_buf;
70 psp->ring_init = psp_v10_0_ring_init;
Junwei Zhangccce0552017-07-14 18:34:48 +080071 psp->ring_create = psp_v10_0_ring_create;
Junwei Zhanga4f478b2017-07-14 18:37:44 +080072 psp->ring_destroy = psp_v10_0_ring_destroy;
Huang Ruic1798b52016-12-16 10:08:48 +080073 psp->cmd_submit = psp_v10_0_cmd_submit;
74 psp->compare_sram_data = psp_v10_0_compare_sram_data;
75 break;
Huang Rui0e5ca0d2017-03-03 18:37:23 -050076 default:
77 return -EINVAL;
78 }
79
80 psp->adev = adev;
81
82 ret = psp_init_microcode(psp);
83 if (ret) {
84 DRM_ERROR("Failed to load psp firmware!\n");
85 return ret;
86 }
87
88 return 0;
89}
90
91static int psp_sw_fini(void *handle)
92{
93 return 0;
94}
95
96int psp_wait_for(struct psp_context *psp, uint32_t reg_index,
97 uint32_t reg_val, uint32_t mask, bool check_changed)
98{
99 uint32_t val;
100 int i;
101 struct amdgpu_device *adev = psp->adev;
102
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500103 for (i = 0; i < adev->usec_timeout; i++) {
Zhang, Jerry2890dec2017-07-14 18:20:17 +0800104 val = RREG32(reg_index);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500105 if (check_changed) {
106 if (val != reg_val)
107 return 0;
108 } else {
109 if ((val & mask) == reg_val)
110 return 0;
111 }
112 udelay(1);
113 }
114
115 return -ETIME;
116}
117
118static int
119psp_cmd_submit_buf(struct psp_context *psp,
120 struct amdgpu_firmware_info *ucode,
121 struct psp_gfx_cmd_resp *cmd, uint64_t fence_mc_addr,
122 int index)
123{
124 int ret;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500125
Huang Ruia1952da2017-06-11 18:57:08 +0800126 memset(psp->cmd_buf_mem, 0, PSP_CMD_BUFFER_SIZE);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500127
Huang Ruia1952da2017-06-11 18:57:08 +0800128 memcpy(psp->cmd_buf_mem, cmd, sizeof(struct psp_gfx_cmd_resp));
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500129
Huang Ruia1952da2017-06-11 18:57:08 +0800130 ret = psp_cmd_submit(psp, ucode, psp->cmd_buf_mc_addr,
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500131 fence_mc_addr, index);
132
133 while (*((unsigned int *)psp->fence_buf) != index) {
134 msleep(1);
kbuild test robotca7f65c2017-03-31 18:15:10 +0800135 }
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500136
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500137 return ret;
138}
139
140static void psp_prep_tmr_cmd_buf(struct psp_gfx_cmd_resp *cmd,
141 uint64_t tmr_mc, uint32_t size)
142{
143 cmd->cmd_id = GFX_CMD_ID_SETUP_TMR;
Alex Deucherf03defe2017-06-22 18:26:33 -0400144 cmd->cmd.cmd_setup_tmr.buf_phy_addr_lo = lower_32_bits(tmr_mc);
145 cmd->cmd.cmd_setup_tmr.buf_phy_addr_hi = upper_32_bits(tmr_mc);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500146 cmd->cmd.cmd_setup_tmr.buf_size = size;
147}
148
149/* Set up Trusted Memory Region */
150static int psp_tmr_init(struct psp_context *psp)
151{
152 int ret;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500153
154 /*
155 * Allocate 3M memory aligned to 1M from Frame Buffer (local
156 * physical).
157 *
158 * Note: this memory need be reserved till the driver
159 * uninitializes.
160 */
161 ret = amdgpu_bo_create_kernel(psp->adev, 0x300000, 0x100000,
162 AMDGPU_GEM_DOMAIN_VRAM,
163 &psp->tmr_bo, &psp->tmr_mc_addr, &psp->tmr_buf);
Huang Rui6f2b1fc2017-03-21 16:18:11 +0800164
165 return ret;
166}
167
168static int psp_tmr_load(struct psp_context *psp)
169{
170 int ret;
171 struct psp_gfx_cmd_resp *cmd;
172
173 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
174 if (!cmd)
175 return -ENOMEM;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500176
177 psp_prep_tmr_cmd_buf(cmd, psp->tmr_mc_addr, 0x300000);
178
179 ret = psp_cmd_submit_buf(psp, NULL, cmd,
180 psp->fence_buf_mc_addr, 1);
181 if (ret)
Huang Rui6f2b1fc2017-03-21 16:18:11 +0800182 goto failed;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500183
184 kfree(cmd);
185
186 return 0;
187
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500188failed:
189 kfree(cmd);
190 return ret;
191}
192
193static void psp_prep_asd_cmd_buf(struct psp_gfx_cmd_resp *cmd,
194 uint64_t asd_mc, uint64_t asd_mc_shared,
195 uint32_t size, uint32_t shared_size)
196{
197 cmd->cmd_id = GFX_CMD_ID_LOAD_ASD;
198 cmd->cmd.cmd_load_ta.app_phy_addr_lo = lower_32_bits(asd_mc);
199 cmd->cmd.cmd_load_ta.app_phy_addr_hi = upper_32_bits(asd_mc);
200 cmd->cmd.cmd_load_ta.app_len = size;
201
202 cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_lo = lower_32_bits(asd_mc_shared);
203 cmd->cmd.cmd_load_ta.cmd_buf_phy_addr_hi = upper_32_bits(asd_mc_shared);
204 cmd->cmd.cmd_load_ta.cmd_buf_len = shared_size;
205}
206
Huang Ruif5cfef92017-03-21 18:02:04 +0800207static int psp_asd_init(struct psp_context *psp)
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500208{
209 int ret;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500210
211 /*
212 * Allocate 16k memory aligned to 4k from Frame Buffer (local
213 * physical) for shared ASD <-> Driver
214 */
Huang Ruif5cfef92017-03-21 18:02:04 +0800215 ret = amdgpu_bo_create_kernel(psp->adev, PSP_ASD_SHARED_MEM_SIZE,
216 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
217 &psp->asd_shared_bo,
218 &psp->asd_shared_mc_addr,
219 &psp->asd_shared_buf);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500220
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500221 return ret;
222}
223
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500224static int psp_asd_load(struct psp_context *psp)
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500225{
226 int ret;
227 struct psp_gfx_cmd_resp *cmd;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500228
Xiangliang Yu943cafb2017-05-04 11:05:13 +0800229 /* If PSP version doesn't match ASD version, asd loading will be failed.
230 * add workaround to bypass it for sriov now.
231 * TODO: add version check to make it common
232 */
233 if (amdgpu_sriov_vf(psp->adev))
234 return 0;
235
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500236 cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
237 if (!cmd)
238 return -ENOMEM;
239
Huang Rui2b0c3ae2017-03-22 10:16:05 +0800240 memset(psp->fw_pri_buf, 0, PSP_1_MEG);
241 memcpy(psp->fw_pri_buf, psp->asd_start_addr, psp->asd_ucode_size);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500242
Huang Ruif5cfef92017-03-21 18:02:04 +0800243 psp_prep_asd_cmd_buf(cmd, psp->fw_pri_mc_addr, psp->asd_shared_mc_addr,
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500244 psp->asd_ucode_size, PSP_ASD_SHARED_MEM_SIZE);
245
246 ret = psp_cmd_submit_buf(psp, NULL, cmd,
247 psp->fence_buf_mc_addr, 2);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500248
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500249 kfree(cmd);
250
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500251 return ret;
252}
253
Huang Ruibe70bbd2017-03-21 18:36:57 +0800254static int psp_hw_start(struct psp_context *psp)
255{
256 int ret;
257
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500258 ret = psp_bootloader_load_sysdrv(psp);
259 if (ret)
Huang Ruibe70bbd2017-03-21 18:36:57 +0800260 return ret;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500261
262 ret = psp_bootloader_load_sos(psp);
263 if (ret)
Huang Ruibe70bbd2017-03-21 18:36:57 +0800264 return ret;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500265
Huang Ruibe70bbd2017-03-21 18:36:57 +0800266 ret = psp_ring_create(psp, PSP_RING_TYPE__KM);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500267 if (ret)
Huang Ruibe70bbd2017-03-21 18:36:57 +0800268 return ret;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500269
Huang Ruibe70bbd2017-03-21 18:36:57 +0800270 ret = psp_tmr_load(psp);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500271 if (ret)
Huang Ruibe70bbd2017-03-21 18:36:57 +0800272 return ret;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500273
274 ret = psp_asd_load(psp);
275 if (ret)
Huang Ruibe70bbd2017-03-21 18:36:57 +0800276 return ret;
277
278 return 0;
279}
280
281static int psp_np_fw_load(struct psp_context *psp)
282{
283 int i, ret;
284 struct amdgpu_firmware_info *ucode;
285 struct amdgpu_device* adev = psp->adev;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500286
287 for (i = 0; i < adev->firmware.max_ucodes; i++) {
288 ucode = &adev->firmware.ucode[i];
289 if (!ucode->fw)
290 continue;
291
292 if (ucode->ucode_id == AMDGPU_UCODE_ID_SMC &&
293 psp_smu_reload_quirk(psp))
294 continue;
Daniel Wange993ca42017-04-20 11:45:09 +0800295 if (amdgpu_sriov_vf(adev) &&
296 (ucode->ucode_id == AMDGPU_UCODE_ID_SDMA0
297 || ucode->ucode_id == AMDGPU_UCODE_ID_SDMA1
298 || ucode->ucode_id == AMDGPU_UCODE_ID_RLC_G))
299 /*skip ucode loading in SRIOV VF */
300 continue;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500301
Huang Ruibe70bbd2017-03-21 18:36:57 +0800302 ret = psp_prep_cmd_buf(ucode, psp->cmd);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500303 if (ret)
Huang Ruibe70bbd2017-03-21 18:36:57 +0800304 return ret;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500305
Huang Ruibe70bbd2017-03-21 18:36:57 +0800306 ret = psp_cmd_submit_buf(psp, ucode, psp->cmd,
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500307 psp->fence_buf_mc_addr, i + 3);
308 if (ret)
Huang Ruibe70bbd2017-03-21 18:36:57 +0800309 return ret;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500310
311#if 0
312 /* check if firmware loaded sucessfully */
313 if (!amdgpu_psp_check_fw_loading_status(adev, i))
314 return -EINVAL;
315#endif
316 }
317
Huang Ruibe70bbd2017-03-21 18:36:57 +0800318 return 0;
319}
320
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500321static int psp_load_fw(struct amdgpu_device *adev)
322{
323 int ret;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500324 struct psp_context *psp = &adev->psp;
325
Huang Rui67bef0f2017-06-29 14:21:49 +0800326 psp->cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
327 if (!psp->cmd)
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500328 return -ENOMEM;
329
Huang Rui53a5cf52017-03-21 16:51:00 +0800330 ret = amdgpu_bo_create_kernel(adev, PSP_1_MEG, PSP_1_MEG,
331 AMDGPU_GEM_DOMAIN_GTT,
332 &psp->fw_pri_bo,
333 &psp->fw_pri_mc_addr,
334 &psp->fw_pri_buf);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500335 if (ret)
336 goto failed;
337
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500338 ret = amdgpu_bo_create_kernel(adev, PSP_FENCE_BUFFER_SIZE, PAGE_SIZE,
339 AMDGPU_GEM_DOMAIN_VRAM,
340 &psp->fence_buf_bo,
341 &psp->fence_buf_mc_addr,
342 &psp->fence_buf);
343 if (ret)
Huang Ruia1952da2017-06-11 18:57:08 +0800344 goto failed_mem2;
345
346 ret = amdgpu_bo_create_kernel(adev, PSP_CMD_BUFFER_SIZE, PAGE_SIZE,
347 AMDGPU_GEM_DOMAIN_VRAM,
348 &psp->cmd_buf_bo, &psp->cmd_buf_mc_addr,
349 (void **)&psp->cmd_buf_mem);
350 if (ret)
Huang Rui53a5cf52017-03-21 16:51:00 +0800351 goto failed_mem1;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500352
353 memset(psp->fence_buf, 0, PSP_FENCE_BUFFER_SIZE);
354
Huang Ruibe70bbd2017-03-21 18:36:57 +0800355 ret = psp_ring_init(psp, PSP_RING_TYPE__KM);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500356 if (ret)
Huang Ruia1952da2017-06-11 18:57:08 +0800357 goto failed_mem;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500358
Huang Ruibe70bbd2017-03-21 18:36:57 +0800359 ret = psp_tmr_init(psp);
Huang Rui6f2b1fc2017-03-21 16:18:11 +0800360 if (ret)
361 goto failed_mem;
362
Huang Ruif5cfef92017-03-21 18:02:04 +0800363 ret = psp_asd_init(psp);
364 if (ret)
365 goto failed_mem;
366
Huang Ruibe70bbd2017-03-21 18:36:57 +0800367 ret = psp_hw_start(psp);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500368 if (ret)
369 goto failed_mem;
370
Huang Ruibe70bbd2017-03-21 18:36:57 +0800371 ret = psp_np_fw_load(psp);
372 if (ret)
373 goto failed_mem;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500374
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500375 return 0;
376
377failed_mem:
Huang Ruia1952da2017-06-11 18:57:08 +0800378 amdgpu_bo_free_kernel(&psp->cmd_buf_bo,
379 &psp->cmd_buf_mc_addr,
380 (void **)&psp->cmd_buf_mem);
381failed_mem1:
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500382 amdgpu_bo_free_kernel(&psp->fence_buf_bo,
383 &psp->fence_buf_mc_addr, &psp->fence_buf);
Huang Ruia1952da2017-06-11 18:57:08 +0800384failed_mem2:
Huang Rui53a5cf52017-03-21 16:51:00 +0800385 amdgpu_bo_free_kernel(&psp->fw_pri_bo,
386 &psp->fw_pri_mc_addr, &psp->fw_pri_buf);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500387failed:
Huang Rui67bef0f2017-06-29 14:21:49 +0800388 kfree(psp->cmd);
389 psp->cmd = NULL;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500390 return ret;
391}
392
393static int psp_hw_init(void *handle)
394{
395 int ret;
396 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
397
398
399 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
400 return 0;
401
402 mutex_lock(&adev->firmware.mutex);
403 /*
404 * This sequence is just used on hw_init only once, no need on
405 * resume.
406 */
407 ret = amdgpu_ucode_init_bo(adev);
408 if (ret)
409 goto failed;
410
411 ret = psp_load_fw(adev);
412 if (ret) {
413 DRM_ERROR("PSP firmware loading failed\n");
414 goto failed;
415 }
416
417 mutex_unlock(&adev->firmware.mutex);
418 return 0;
419
420failed:
421 adev->firmware.load_type = AMDGPU_FW_LOAD_DIRECT;
422 mutex_unlock(&adev->firmware.mutex);
423 return -EINVAL;
424}
425
426static int psp_hw_fini(void *handle)
427{
428 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
429 struct psp_context *psp = &adev->psp;
430
Trigger Huange3c5e982017-04-17 08:50:18 -0400431 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
432 return 0;
433
434 amdgpu_ucode_fini_bo(adev);
435
436 psp_ring_destroy(psp, PSP_RING_TYPE__KM);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500437
Huang Ruiedc4d3d2017-06-02 10:42:28 +0800438 amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, &psp->tmr_buf);
439 amdgpu_bo_free_kernel(&psp->fw_pri_bo,
440 &psp->fw_pri_mc_addr, &psp->fw_pri_buf);
441 amdgpu_bo_free_kernel(&psp->fence_buf_bo,
442 &psp->fence_buf_mc_addr, &psp->fence_buf);
Huang Rui311146c2017-06-11 18:28:00 +0800443 amdgpu_bo_free_kernel(&psp->asd_shared_bo, &psp->asd_shared_mc_addr,
444 &psp->asd_shared_buf);
Huang Ruia1952da2017-06-11 18:57:08 +0800445 amdgpu_bo_free_kernel(&psp->cmd_buf_bo, &psp->cmd_buf_mc_addr,
446 (void **)&psp->cmd_buf_mem);
Huang Ruib4de2c52017-04-10 15:29:42 +0800447
Huang Rui67bef0f2017-06-29 14:21:49 +0800448 kfree(psp->cmd);
449 psp->cmd = NULL;
450
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500451 return 0;
452}
453
454static int psp_suspend(void *handle)
455{
456 return 0;
457}
458
459static int psp_resume(void *handle)
460{
461 int ret;
462 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
Huang Rui93ea9b92017-03-23 11:20:25 +0800463 struct psp_context *psp = &adev->psp;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500464
465 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP)
466 return 0;
467
Huang Rui93ea9b92017-03-23 11:20:25 +0800468 DRM_INFO("PSP is resuming...\n");
469
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500470 mutex_lock(&adev->firmware.mutex);
471
Huang Rui93ea9b92017-03-23 11:20:25 +0800472 ret = psp_hw_start(psp);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500473 if (ret)
Huang Rui93ea9b92017-03-23 11:20:25 +0800474 goto failed;
475
476 ret = psp_np_fw_load(psp);
477 if (ret)
478 goto failed;
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500479
480 mutex_unlock(&adev->firmware.mutex);
481
Huang Rui93ea9b92017-03-23 11:20:25 +0800482 return 0;
483
484failed:
485 DRM_ERROR("PSP resume failed\n");
486 mutex_unlock(&adev->firmware.mutex);
Huang Rui0e5ca0d2017-03-03 18:37:23 -0500487 return ret;
488}
489
490static bool psp_check_fw_loading_status(struct amdgpu_device *adev,
491 enum AMDGPU_UCODE_ID ucode_type)
492{
493 struct amdgpu_firmware_info *ucode = NULL;
494
495 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
496 DRM_INFO("firmware is not loaded by PSP\n");
497 return true;
498 }
499
500 if (!adev->firmware.fw_size)
501 return false;
502
503 ucode = &adev->firmware.ucode[ucode_type];
504 if (!ucode->fw || !ucode->ucode_size)
505 return false;
506
507 return psp_compare_sram_data(&adev->psp, ucode, ucode_type);
508}
509
510static int psp_set_clockgating_state(void *handle,
511 enum amd_clockgating_state state)
512{
513 return 0;
514}
515
516static int psp_set_powergating_state(void *handle,
517 enum amd_powergating_state state)
518{
519 return 0;
520}
521
522const struct amd_ip_funcs psp_ip_funcs = {
523 .name = "psp",
524 .early_init = psp_early_init,
525 .late_init = NULL,
526 .sw_init = psp_sw_init,
527 .sw_fini = psp_sw_fini,
528 .hw_init = psp_hw_init,
529 .hw_fini = psp_hw_fini,
530 .suspend = psp_suspend,
531 .resume = psp_resume,
532 .is_idle = NULL,
533 .wait_for_idle = NULL,
534 .soft_reset = NULL,
535 .set_clockgating_state = psp_set_clockgating_state,
536 .set_powergating_state = psp_set_powergating_state,
537};
538
539static const struct amdgpu_psp_funcs psp_funcs = {
540 .check_fw_loading_status = psp_check_fw_loading_status,
541};
542
543static void psp_set_funcs(struct amdgpu_device *adev)
544{
545 if (NULL == adev->firmware.funcs)
546 adev->firmware.funcs = &psp_funcs;
547}
548
549const struct amdgpu_ip_block_version psp_v3_1_ip_block =
550{
551 .type = AMD_IP_BLOCK_TYPE_PSP,
552 .major = 3,
553 .minor = 1,
554 .rev = 0,
555 .funcs = &psp_ip_funcs,
556};
Huang Ruidfbd6432016-12-16 10:01:55 +0800557
558const struct amdgpu_ip_block_version psp_v10_0_ip_block =
559{
560 .type = AMD_IP_BLOCK_TYPE_PSP,
561 .major = 10,
562 .minor = 0,
563 .rev = 0,
564 .funcs = &psp_ip_funcs,
565};