Linux Audio

Check our new training course

Linux kernel drivers training

Mar 31-Apr 9, 2025, special US time zones
Register
Loading...
v6.13.7
  1// SPDX-License-Identifier: MIT
  2/*
  3 * Copyright © 2022 Intel Corporation
  4 */
  5
  6#include "xe_uc.h"
  7
  8#include "xe_assert.h"
  9#include "xe_device.h"
 10#include "xe_gsc.h"
 11#include "xe_gsc_proxy.h"
 12#include "xe_gt.h"
 13#include "xe_gt_printk.h"
 14#include "xe_gt_sriov_vf.h"
 15#include "xe_guc.h"
 
 16#include "xe_guc_pc.h"
 
 17#include "xe_huc.h"
 18#include "xe_sriov.h"
 19#include "xe_uc_fw.h"
 20#include "xe_wopcm.h"
 21
 22static struct xe_gt *
 23uc_to_gt(struct xe_uc *uc)
 24{
 25	return container_of(uc, struct xe_gt, uc);
 26}
 27
 28static struct xe_device *
 29uc_to_xe(struct xe_uc *uc)
 30{
 31	return gt_to_xe(uc_to_gt(uc));
 32}
 33
 34/* Should be called once at driver load only */
 35int xe_uc_init(struct xe_uc *uc)
 36{
 
 37	int ret;
 38
 
 
 39	/*
 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".
 42	 */
 43	ret = xe_guc_init(&uc->guc);
 44	if (ret)
 45		goto err;
 46
 47	ret = xe_huc_init(&uc->huc);
 48	if (ret)
 49		goto err;
 50
 51	ret = xe_gsc_init(&uc->gsc);
 52	if (ret)
 53		goto err;
 54
 55	if (!xe_device_uc_enabled(uc_to_xe(uc)))
 56		return 0;
 57
 58	if (IS_SRIOV_VF(uc_to_xe(uc)))
 59		return 0;
 60
 61	ret = xe_wopcm_init(&uc->wopcm);
 62	if (ret)
 63		goto err;
 64
 
 
 
 
 
 
 
 
 
 
 65	return 0;
 66
 67err:
 68	xe_gt_err(uc_to_gt(uc), "Failed to initialize uC (%pe)\n", ERR_PTR(ret));
 
 69	return ret;
 70}
 71
 72/**
 73 * xe_uc_init_post_hwconfig - init Uc post hwconfig load
 74 * @uc: The UC object
 75 *
 76 * Return: 0 on success, negative error code on error.
 77 */
 78int xe_uc_init_post_hwconfig(struct xe_uc *uc)
 79{
 80	int err;
 81
 82	/* GuC submission not enabled, nothing to do */
 83	if (!xe_device_uc_enabled(uc_to_xe(uc)))
 84		return 0;
 85
 86	err = xe_uc_sanitize_reset(uc);
 87	if (err)
 88		return err;
 89
 90	err = xe_guc_init_post_hwconfig(&uc->guc);
 91	if (err)
 92		return err;
 93
 94	err = xe_huc_init_post_hwconfig(&uc->huc);
 95	if (err)
 96		return err;
 97
 98	return xe_gsc_init_post_hwconfig(&uc->gsc);
 99}
100
101static int uc_reset(struct xe_uc *uc)
102{
103	struct xe_device *xe = uc_to_xe(uc);
104	int ret;
105
106	ret = xe_guc_reset(&uc->guc);
107	if (ret) {
108		drm_err(&xe->drm, "Failed to reset GuC, ret = %d\n", ret);
109		return ret;
110	}
111
112	return 0;
113}
114
115static void xe_uc_sanitize(struct xe_uc *uc)
116{
117	xe_huc_sanitize(&uc->huc);
118	xe_guc_sanitize(&uc->guc);
119}
120
121int xe_uc_sanitize_reset(struct xe_uc *uc)
122{
123	xe_uc_sanitize(uc);
124
125	return uc_reset(uc);
126}
127
128/**
129 * xe_uc_init_hwconfig - minimally init Uc, read and parse hwconfig
130 * @uc: The UC object
131 *
132 * Return: 0 on success, negative error code on error.
133 */
134int xe_uc_init_hwconfig(struct xe_uc *uc)
135{
136	int ret;
137
138	/* GuC submission not enabled, nothing to do */
139	if (!xe_device_uc_enabled(uc_to_xe(uc)))
140		return 0;
141
142	ret = xe_guc_min_load_for_hwconfig(&uc->guc);
143	if (ret)
144		return ret;
145
146	return 0;
147}
148
149static int vf_uc_init_hw(struct xe_uc *uc)
150{
151	int err;
152
153	err = xe_uc_sanitize_reset(uc);
154	if (err)
155		return err;
156
157	err = xe_guc_enable_communication(&uc->guc);
158	if (err)
159		return err;
160
161	err = xe_gt_sriov_vf_connect(uc_to_gt(uc));
162	if (err)
163		return err;
164
165	uc->guc.submission_state.enabled = true;
166
167	err = xe_gt_record_default_lrcs(uc_to_gt(uc));
168	if (err)
169		return err;
170
171	return 0;
172}
173
174/*
175 * Should be called during driver load, after every GT reset, and after every
176 * suspend to reload / auth the firmwares.
177 */
178int xe_uc_init_hw(struct xe_uc *uc)
179{
180	int ret;
181
182	/* GuC submission not enabled, nothing to do */
183	if (!xe_device_uc_enabled(uc_to_xe(uc)))
184		return 0;
185
186	if (IS_SRIOV_VF(uc_to_xe(uc)))
187		return vf_uc_init_hw(uc);
188
189	ret = xe_huc_upload(&uc->huc);
190	if (ret)
191		return ret;
192
193	ret = xe_guc_upload(&uc->guc);
194	if (ret)
195		return ret;
196
197	ret = xe_guc_enable_communication(&uc->guc);
198	if (ret)
199		return ret;
200
201	ret = xe_gt_record_default_lrcs(uc_to_gt(uc));
202	if (ret)
203		return ret;
204
205	ret = xe_guc_post_load_init(&uc->guc);
206	if (ret)
207		return ret;
208
209	ret = xe_guc_pc_start(&uc->guc.pc);
210	if (ret)
211		return ret;
212
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);
216
217	/* GSC load is async */
218	xe_gsc_load_start(&uc->gsc);
219
220	return 0;
221}
222
223int xe_uc_fini_hw(struct xe_uc *uc)
224{
225	return xe_uc_sanitize_reset(uc);
226}
227
228int xe_uc_reset_prepare(struct xe_uc *uc)
229{
230	/* GuC submission not enabled, nothing to do */
231	if (!xe_device_uc_enabled(uc_to_xe(uc)))
232		return 0;
233
234	return xe_guc_reset_prepare(&uc->guc);
235}
236
237void xe_uc_gucrc_disable(struct xe_uc *uc)
238{
239	XE_WARN_ON(xe_guc_pc_gucrc_disable(&uc->guc.pc));
240}
241
242void xe_uc_stop_prepare(struct xe_uc *uc)
243{
244	xe_gsc_wait_for_worker_completion(&uc->gsc);
245	xe_guc_stop_prepare(&uc->guc);
246}
247
248void xe_uc_stop(struct xe_uc *uc)
249{
250	/* GuC submission not enabled, nothing to do */
251	if (!xe_device_uc_enabled(uc_to_xe(uc)))
252		return;
253
254	xe_guc_stop(&uc->guc);
255}
256
257int xe_uc_start(struct xe_uc *uc)
258{
259	/* GuC submission not enabled, nothing to do */
260	if (!xe_device_uc_enabled(uc_to_xe(uc)))
261		return 0;
262
263	return xe_guc_start(&uc->guc);
264}
265
266static void uc_reset_wait(struct xe_uc *uc)
267{
268	int ret;
269
270again:
271	xe_guc_reset_wait(&uc->guc);
272
273	ret = xe_uc_reset_prepare(uc);
274	if (ret)
275		goto again;
276}
277
278int xe_uc_suspend(struct xe_uc *uc)
279{
 
 
280	/* GuC submission not enabled, nothing to do */
281	if (!xe_device_uc_enabled(uc_to_xe(uc)))
282		return 0;
283
284	uc_reset_wait(uc);
285
286	xe_uc_stop(uc);
 
 
287
288	return xe_guc_suspend(&uc->guc);
289}
290
291/**
292 * xe_uc_remove() - Clean up the UC structures before driver removal
293 * @uc: the UC object
294 *
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.
298 */
299void xe_uc_remove(struct xe_uc *uc)
300{
301	xe_gsc_remove(&uc->gsc);
302}
303
304/**
305 * xe_uc_declare_wedged() - Declare UC wedged
306 * @uc: the UC object
307 *
308 * Wedge the UC which stops all submission, saves desired debug state, and
309 * cleans up anything which could timeout.
310 */
311void xe_uc_declare_wedged(struct xe_uc *uc)
312{
313	xe_gt_assert(uc_to_gt(uc), uc_to_xe(uc)->wedged.mode);
314
315	xe_guc_declare_wedged(&uc->guc);
316}
v6.9.4
  1// SPDX-License-Identifier: MIT
  2/*
  3 * Copyright © 2022 Intel Corporation
  4 */
  5
  6#include "xe_uc.h"
  7
 
  8#include "xe_device.h"
  9#include "xe_gsc.h"
 10#include "xe_gsc_proxy.h"
 11#include "xe_gt.h"
 
 
 12#include "xe_guc.h"
 13#include "xe_guc_db_mgr.h"
 14#include "xe_guc_pc.h"
 15#include "xe_guc_submit.h"
 16#include "xe_huc.h"
 
 17#include "xe_uc_fw.h"
 18#include "xe_wopcm.h"
 19
 20static struct xe_gt *
 21uc_to_gt(struct xe_uc *uc)
 22{
 23	return container_of(uc, struct xe_gt, uc);
 24}
 25
 26static struct xe_device *
 27uc_to_xe(struct xe_uc *uc)
 28{
 29	return gt_to_xe(uc_to_gt(uc));
 30}
 31
 32/* Should be called once at driver load only */
 33int xe_uc_init(struct xe_uc *uc)
 34{
 35	struct xe_device *xe = uc_to_xe(uc);
 36	int ret;
 37
 38	xe_device_mem_access_get(xe);
 39
 40	/*
 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".
 43	 */
 44	ret = xe_guc_init(&uc->guc);
 45	if (ret)
 46		goto err;
 47
 48	ret = xe_huc_init(&uc->huc);
 49	if (ret)
 50		goto err;
 51
 52	ret = xe_gsc_init(&uc->gsc);
 53	if (ret)
 54		goto err;
 55
 56	if (!xe_device_uc_enabled(uc_to_xe(uc)))
 57		goto err;
 
 
 
 58
 59	ret = xe_wopcm_init(&uc->wopcm);
 60	if (ret)
 61		goto err;
 62
 63	ret = xe_guc_submit_init(&uc->guc);
 64	if (ret)
 65		goto err;
 66
 67	ret = xe_guc_db_mgr_init(&uc->guc.dbm, ~0);
 68	if (ret)
 69		goto err;
 70
 71	xe_device_mem_access_put(xe);
 72
 73	return 0;
 74
 75err:
 76	xe_device_mem_access_put(xe);
 77
 78	return ret;
 79}
 80
 81/**
 82 * xe_uc_init_post_hwconfig - init Uc post hwconfig load
 83 * @uc: The UC object
 84 *
 85 * Return: 0 on success, negative error code on error.
 86 */
 87int xe_uc_init_post_hwconfig(struct xe_uc *uc)
 88{
 89	int err;
 90
 91	/* GuC submission not enabled, nothing to do */
 92	if (!xe_device_uc_enabled(uc_to_xe(uc)))
 93		return 0;
 94
 95	err = xe_uc_sanitize_reset(uc);
 96	if (err)
 97		return err;
 98
 99	err = xe_guc_init_post_hwconfig(&uc->guc);
100	if (err)
101		return err;
102
103	err = xe_huc_init_post_hwconfig(&uc->huc);
104	if (err)
105		return err;
106
107	return xe_gsc_init_post_hwconfig(&uc->gsc);
108}
109
110static int uc_reset(struct xe_uc *uc)
111{
112	struct xe_device *xe = uc_to_xe(uc);
113	int ret;
114
115	ret = xe_guc_reset(&uc->guc);
116	if (ret) {
117		drm_err(&xe->drm, "Failed to reset GuC, ret = %d\n", ret);
118		return ret;
119	}
120
121	return 0;
122}
123
124static void xe_uc_sanitize(struct xe_uc *uc)
125{
126	xe_huc_sanitize(&uc->huc);
127	xe_guc_sanitize(&uc->guc);
128}
129
130int xe_uc_sanitize_reset(struct xe_uc *uc)
131{
132	xe_uc_sanitize(uc);
133
134	return uc_reset(uc);
135}
136
137/**
138 * xe_uc_init_hwconfig - minimally init Uc, read and parse hwconfig
139 * @uc: The UC object
140 *
141 * Return: 0 on success, negative error code on error.
142 */
143int xe_uc_init_hwconfig(struct xe_uc *uc)
144{
145	int ret;
146
147	/* GuC submission not enabled, nothing to do */
148	if (!xe_device_uc_enabled(uc_to_xe(uc)))
149		return 0;
150
151	ret = xe_guc_min_load_for_hwconfig(&uc->guc);
152	if (ret)
153		return ret;
154
155	return 0;
156}
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158/*
159 * Should be called during driver load, after every GT reset, and after every
160 * suspend to reload / auth the firmwares.
161 */
162int xe_uc_init_hw(struct xe_uc *uc)
163{
164	int ret;
165
166	/* GuC submission not enabled, nothing to do */
167	if (!xe_device_uc_enabled(uc_to_xe(uc)))
168		return 0;
169
 
 
 
170	ret = xe_huc_upload(&uc->huc);
171	if (ret)
172		return ret;
173
174	ret = xe_guc_upload(&uc->guc);
175	if (ret)
176		return ret;
177
178	ret = xe_guc_enable_communication(&uc->guc);
179	if (ret)
180		return ret;
181
182	ret = xe_gt_record_default_lrcs(uc_to_gt(uc));
183	if (ret)
184		return ret;
185
186	ret = xe_guc_post_load_init(&uc->guc);
187	if (ret)
188		return ret;
189
190	ret = xe_guc_pc_start(&uc->guc.pc);
191	if (ret)
192		return ret;
193
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);
197
198	/* GSC load is async */
199	xe_gsc_load_start(&uc->gsc);
200
201	return 0;
202}
203
204int xe_uc_fini_hw(struct xe_uc *uc)
205{
206	return xe_uc_sanitize_reset(uc);
207}
208
209int xe_uc_reset_prepare(struct xe_uc *uc)
210{
211	/* GuC submission not enabled, nothing to do */
212	if (!xe_device_uc_enabled(uc_to_xe(uc)))
213		return 0;
214
215	return xe_guc_reset_prepare(&uc->guc);
216}
217
218void xe_uc_gucrc_disable(struct xe_uc *uc)
219{
220	XE_WARN_ON(xe_guc_pc_gucrc_disable(&uc->guc.pc));
221}
222
223void xe_uc_stop_prepare(struct xe_uc *uc)
224{
225	xe_gsc_wait_for_worker_completion(&uc->gsc);
226	xe_guc_stop_prepare(&uc->guc);
227}
228
229int xe_uc_stop(struct xe_uc *uc)
230{
231	/* GuC submission not enabled, nothing to do */
232	if (!xe_device_uc_enabled(uc_to_xe(uc)))
233		return 0;
234
235	return xe_guc_stop(&uc->guc);
236}
237
238int xe_uc_start(struct xe_uc *uc)
239{
240	/* GuC submission not enabled, nothing to do */
241	if (!xe_device_uc_enabled(uc_to_xe(uc)))
242		return 0;
243
244	return xe_guc_start(&uc->guc);
245}
246
247static void uc_reset_wait(struct xe_uc *uc)
248{
249	int ret;
250
251again:
252	xe_guc_reset_wait(&uc->guc);
253
254	ret = xe_uc_reset_prepare(uc);
255	if (ret)
256		goto again;
257}
258
259int xe_uc_suspend(struct xe_uc *uc)
260{
261	int ret;
262
263	/* GuC submission not enabled, nothing to do */
264	if (!xe_device_uc_enabled(uc_to_xe(uc)))
265		return 0;
266
267	uc_reset_wait(uc);
268
269	ret = xe_uc_stop(uc);
270	if (ret)
271		return ret;
272
273	return xe_guc_suspend(&uc->guc);
274}
275
276/**
277 * xe_uc_remove() - Clean up the UC structures before driver removal
278 * @uc: the UC object
279 *
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.
283 */
284void xe_uc_remove(struct xe_uc *uc)
285{
286	xe_gsc_remove(&uc->gsc);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287}