1 // SPDX-License-Identifier: MIT
3 * Copyright © 2022 Intel Corporation
11 #include "xe_gsc_proxy.h"
13 #include "xe_gt_printk.h"
14 #include "xe_gt_sriov_vf.h"
16 #include "xe_guc_pc.h"
23 uc_to_gt(struct xe_uc *uc)
25 return container_of(uc, struct xe_gt, uc);
28 static struct xe_device *
29 uc_to_xe(struct xe_uc *uc)
31 return gt_to_xe(uc_to_gt(uc));
34 /* Should be called once at driver load only */
35 int xe_uc_init(struct xe_uc *uc)
40 * We call the GuC/HuC/GSC init functions even if GuC submission is off
41 * to correctly move our tracking of the FW state to "disabled".
43 ret = xe_guc_init(&uc->guc);
47 ret = xe_huc_init(&uc->huc);
51 ret = xe_gsc_init(&uc->gsc);
55 if (!xe_device_uc_enabled(uc_to_xe(uc)))
58 if (IS_SRIOV_VF(uc_to_xe(uc)))
61 ret = xe_wopcm_init(&uc->wopcm);
68 xe_gt_err(uc_to_gt(uc), "Failed to initialize uC (%pe)\n", ERR_PTR(ret));
73 * xe_uc_init_post_hwconfig - init Uc post hwconfig load
76 * Return: 0 on success, negative error code on error.
78 int xe_uc_init_post_hwconfig(struct xe_uc *uc)
82 /* GuC submission not enabled, nothing to do */
83 if (!xe_device_uc_enabled(uc_to_xe(uc)))
86 err = xe_uc_sanitize_reset(uc);
90 err = xe_guc_init_post_hwconfig(&uc->guc);
94 err = xe_huc_init_post_hwconfig(&uc->huc);
98 return xe_gsc_init_post_hwconfig(&uc->gsc);
101 static int uc_reset(struct xe_uc *uc)
103 struct xe_device *xe = uc_to_xe(uc);
106 ret = xe_guc_reset(&uc->guc);
108 drm_err(&xe->drm, "Failed to reset GuC, ret = %d\n", ret);
115 static void xe_uc_sanitize(struct xe_uc *uc)
117 xe_huc_sanitize(&uc->huc);
118 xe_guc_sanitize(&uc->guc);
121 int xe_uc_sanitize_reset(struct xe_uc *uc)
129 * xe_uc_init_hwconfig - minimally init Uc, read and parse hwconfig
132 * Return: 0 on success, negative error code on error.
134 int xe_uc_init_hwconfig(struct xe_uc *uc)
138 /* GuC submission not enabled, nothing to do */
139 if (!xe_device_uc_enabled(uc_to_xe(uc)))
142 ret = xe_guc_min_load_for_hwconfig(&uc->guc);
149 static int vf_uc_init_hw(struct xe_uc *uc)
153 err = xe_uc_sanitize_reset(uc);
157 err = xe_guc_enable_communication(&uc->guc);
161 err = xe_gt_sriov_vf_connect(uc_to_gt(uc));
165 uc->guc.submission_state.enabled = true;
167 err = xe_gt_record_default_lrcs(uc_to_gt(uc));
175 * Should be called during driver load, after every GT reset, and after every
176 * suspend to reload / auth the firmwares.
178 int xe_uc_init_hw(struct xe_uc *uc)
182 /* GuC submission not enabled, nothing to do */
183 if (!xe_device_uc_enabled(uc_to_xe(uc)))
186 if (IS_SRIOV_VF(uc_to_xe(uc)))
187 return vf_uc_init_hw(uc);
189 ret = xe_huc_upload(&uc->huc);
193 ret = xe_guc_upload(&uc->guc);
197 ret = xe_guc_enable_communication(&uc->guc);
201 ret = xe_gt_record_default_lrcs(uc_to_gt(uc));
205 ret = xe_guc_post_load_init(&uc->guc);
209 ret = xe_guc_pc_start(&uc->guc.pc);
213 /* We don't fail the driver load if HuC fails to auth, but let's warn */
214 ret = xe_huc_auth(&uc->huc, XE_HUC_AUTH_VIA_GUC);
215 xe_gt_assert(uc_to_gt(uc), !ret);
217 /* GSC load is async */
218 xe_gsc_load_start(&uc->gsc);
223 int xe_uc_fini_hw(struct xe_uc *uc)
225 return xe_uc_sanitize_reset(uc);
228 int xe_uc_reset_prepare(struct xe_uc *uc)
230 /* GuC submission not enabled, nothing to do */
231 if (!xe_device_uc_enabled(uc_to_xe(uc)))
234 return xe_guc_reset_prepare(&uc->guc);
237 void xe_uc_gucrc_disable(struct xe_uc *uc)
239 XE_WARN_ON(xe_guc_pc_gucrc_disable(&uc->guc.pc));
242 void xe_uc_stop_prepare(struct xe_uc *uc)
244 xe_gsc_wait_for_worker_completion(&uc->gsc);
245 xe_guc_stop_prepare(&uc->guc);
248 void xe_uc_stop(struct xe_uc *uc)
250 /* GuC submission not enabled, nothing to do */
251 if (!xe_device_uc_enabled(uc_to_xe(uc)))
254 xe_guc_stop(&uc->guc);
257 int xe_uc_start(struct xe_uc *uc)
259 /* GuC submission not enabled, nothing to do */
260 if (!xe_device_uc_enabled(uc_to_xe(uc)))
263 return xe_guc_start(&uc->guc);
266 static void uc_reset_wait(struct xe_uc *uc)
271 xe_guc_reset_wait(&uc->guc);
273 ret = xe_uc_reset_prepare(uc);
278 int xe_uc_suspend(struct xe_uc *uc)
280 /* GuC submission not enabled, nothing to do */
281 if (!xe_device_uc_enabled(uc_to_xe(uc)))
288 return xe_guc_suspend(&uc->guc);
292 * xe_uc_remove() - Clean up the UC structures before driver removal
295 * This function should only act on objects/structures that must be cleaned
296 * before the driver removal callback is complete and therefore can't be
297 * deferred to a drmm action.
299 void xe_uc_remove(struct xe_uc *uc)
301 xe_gsc_remove(&uc->gsc);
305 * xe_uc_declare_wedged() - Declare UC wedged
308 * Wedge the UC which stops all submission, saves desired debug state, and
309 * cleans up anything which could timeout.
311 void xe_uc_declare_wedged(struct xe_uc *uc)
313 xe_gt_assert(uc_to_gt(uc), uc_to_xe(uc)->wedged.mode);
315 xe_guc_declare_wedged(&uc->guc);