1 // SPDX-License-Identifier: MIT
3 * Copyright © 2022 Intel Corporation
10 #include "xe_gsc_proxy.h"
13 #include "xe_guc_db_mgr.h"
14 #include "xe_guc_pc.h"
15 #include "xe_guc_submit.h"
21 uc_to_gt(struct xe_uc *uc)
23 return container_of(uc, struct xe_gt, uc);
26 static struct xe_device *
27 uc_to_xe(struct xe_uc *uc)
29 return gt_to_xe(uc_to_gt(uc));
32 /* Should be called once at driver load only */
33 int xe_uc_init(struct xe_uc *uc)
35 struct xe_device *xe = uc_to_xe(uc);
38 xe_device_mem_access_get(xe);
41 * We call the GuC/HuC/GSC init functions even if GuC submission is off
42 * to correctly move our tracking of the FW state to "disabled".
44 ret = xe_guc_init(&uc->guc);
48 ret = xe_huc_init(&uc->huc);
52 ret = xe_gsc_init(&uc->gsc);
56 if (!xe_device_uc_enabled(uc_to_xe(uc)))
59 ret = xe_wopcm_init(&uc->wopcm);
63 ret = xe_guc_submit_init(&uc->guc);
67 ret = xe_guc_db_mgr_init(&uc->guc.dbm, ~0);
71 xe_device_mem_access_put(xe);
76 xe_device_mem_access_put(xe);
82 * xe_uc_init_post_hwconfig - init Uc post hwconfig load
85 * Return: 0 on success, negative error code on error.
87 int xe_uc_init_post_hwconfig(struct xe_uc *uc)
91 /* GuC submission not enabled, nothing to do */
92 if (!xe_device_uc_enabled(uc_to_xe(uc)))
95 err = xe_uc_sanitize_reset(uc);
99 err = xe_guc_init_post_hwconfig(&uc->guc);
103 err = xe_huc_init_post_hwconfig(&uc->huc);
107 return xe_gsc_init_post_hwconfig(&uc->gsc);
110 static int uc_reset(struct xe_uc *uc)
112 struct xe_device *xe = uc_to_xe(uc);
115 ret = xe_guc_reset(&uc->guc);
117 drm_err(&xe->drm, "Failed to reset GuC, ret = %d\n", ret);
124 static void xe_uc_sanitize(struct xe_uc *uc)
126 xe_huc_sanitize(&uc->huc);
127 xe_guc_sanitize(&uc->guc);
130 int xe_uc_sanitize_reset(struct xe_uc *uc)
138 * xe_uc_init_hwconfig - minimally init Uc, read and parse hwconfig
141 * Return: 0 on success, negative error code on error.
143 int xe_uc_init_hwconfig(struct xe_uc *uc)
147 /* GuC submission not enabled, nothing to do */
148 if (!xe_device_uc_enabled(uc_to_xe(uc)))
151 ret = xe_guc_min_load_for_hwconfig(&uc->guc);
159 * Should be called during driver load, after every GT reset, and after every
160 * suspend to reload / auth the firmwares.
162 int xe_uc_init_hw(struct xe_uc *uc)
166 /* GuC submission not enabled, nothing to do */
167 if (!xe_device_uc_enabled(uc_to_xe(uc)))
170 ret = xe_huc_upload(&uc->huc);
174 ret = xe_guc_upload(&uc->guc);
178 ret = xe_guc_enable_communication(&uc->guc);
182 ret = xe_gt_record_default_lrcs(uc_to_gt(uc));
186 ret = xe_guc_post_load_init(&uc->guc);
190 ret = xe_guc_pc_start(&uc->guc.pc);
194 /* We don't fail the driver load if HuC fails to auth, but let's warn */
195 ret = xe_huc_auth(&uc->huc, XE_HUC_AUTH_VIA_GUC);
196 xe_gt_assert(uc_to_gt(uc), !ret);
198 /* GSC load is async */
199 xe_gsc_load_start(&uc->gsc);
204 int xe_uc_fini_hw(struct xe_uc *uc)
206 return xe_uc_sanitize_reset(uc);
209 int xe_uc_reset_prepare(struct xe_uc *uc)
211 /* GuC submission not enabled, nothing to do */
212 if (!xe_device_uc_enabled(uc_to_xe(uc)))
215 return xe_guc_reset_prepare(&uc->guc);
218 void xe_uc_gucrc_disable(struct xe_uc *uc)
220 XE_WARN_ON(xe_guc_pc_gucrc_disable(&uc->guc.pc));
223 void xe_uc_stop_prepare(struct xe_uc *uc)
225 xe_gsc_wait_for_worker_completion(&uc->gsc);
226 xe_guc_stop_prepare(&uc->guc);
229 int xe_uc_stop(struct xe_uc *uc)
231 /* GuC submission not enabled, nothing to do */
232 if (!xe_device_uc_enabled(uc_to_xe(uc)))
235 return xe_guc_stop(&uc->guc);
238 int xe_uc_start(struct xe_uc *uc)
240 /* GuC submission not enabled, nothing to do */
241 if (!xe_device_uc_enabled(uc_to_xe(uc)))
244 return xe_guc_start(&uc->guc);
247 static void uc_reset_wait(struct xe_uc *uc)
252 xe_guc_reset_wait(&uc->guc);
254 ret = xe_uc_reset_prepare(uc);
259 int xe_uc_suspend(struct xe_uc *uc)
263 /* GuC submission not enabled, nothing to do */
264 if (!xe_device_uc_enabled(uc_to_xe(uc)))
269 ret = xe_uc_stop(uc);
273 return xe_guc_suspend(&uc->guc);
277 * xe_uc_remove() - Clean up the UC structures before driver removal
280 * This function should only act on objects/structures that must be cleaned
281 * before the driver removal callback is complete and therefore can't be
282 * deferred to a drmm action.
284 void xe_uc_remove(struct xe_uc *uc)
286 xe_gsc_remove(&uc->gsc);