Skip to content

Commit ff6cd29

Browse files
committed
drm/xe: Cleanup unwind of gt initialization
The only thing in xe_gt_remove() that really needs to happen on the device remove callback is the xe_uc_remove(). That's because of the following call chain: xe_gt_remove() xe_uc_remove() xe_gsc_remove() xe_gsc_proxy_remove() Move xe_gsc_proxy_remove() to be handled as a xe_device_remove_action, so it's recorded when it should run during device removal. The rest can be handled normally by devm infra. Besides removing the deep call chain above, xe_device_probe() doesn't have to unwind the gt loop and it's also more in line with the xe_device_probe() style. Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com> Reviewed-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250213192909.996148-7-lucas.demarchi@intel.com Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
1 parent c0aeb90 commit ff6cd29

File tree

10 files changed

+47
-99
lines changed

10 files changed

+47
-99
lines changed

drivers/gpu/drm/xe/xe_device.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,6 @@ int xe_device_probe(struct xe_device *xe)
750750
struct xe_tile *tile;
751751
struct xe_gt *gt;
752752
int err;
753-
u8 last_gt;
754753
u8 id;
755754

756755
xe->probing = true;
@@ -861,18 +860,16 @@ int xe_device_probe(struct xe_device *xe)
861860
return err;
862861

863862
for_each_gt(gt, xe, id) {
864-
last_gt = id;
865-
866863
err = xe_gt_init(gt);
867864
if (err)
868-
goto err_fini_gt;
865+
return err;
869866
}
870867

871868
xe_heci_gsc_init(xe);
872869

873870
err = xe_oa_init(xe);
874871
if (err)
875-
goto err_fini_gt;
872+
return err;
876873

877874
err = xe_display_init(xe);
878875
if (err)
@@ -911,14 +908,6 @@ int xe_device_probe(struct xe_device *xe)
911908
err_fini_oa:
912909
xe_oa_fini(xe);
913910

914-
err_fini_gt:
915-
for_each_gt(gt, xe, id) {
916-
if (id < last_gt)
917-
xe_gt_remove(gt);
918-
else
919-
break;
920-
}
921-
922911
return err;
923912
}
924913

@@ -987,9 +976,6 @@ static void xe_device_remove_display(struct xe_device *xe)
987976

988977
void xe_device_remove(struct xe_device *xe)
989978
{
990-
struct xe_gt *gt;
991-
u8 id;
992-
993979
xe_oa_unregister(xe);
994980

995981
xe_device_remove_display(xe);
@@ -998,9 +984,6 @@ void xe_device_remove(struct xe_device *xe)
998984

999985
xe_heci_gsc_fini(xe);
1000986

1001-
for_each_gt(gt, xe, id)
1002-
xe_gt_remove(gt);
1003-
1004987
xe_device_call_remove_actions(xe);
1005988
}
1006989

drivers/gpu/drm/xe/xe_gsc.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,6 @@ void xe_gsc_wait_for_worker_completion(struct xe_gsc *gsc)
555555
flush_work(&gsc->work);
556556
}
557557

558-
/**
559-
* xe_gsc_remove() - Clean up the GSC structures before driver removal
560-
* @gsc: the GSC uC
561-
*/
562-
void xe_gsc_remove(struct xe_gsc *gsc)
563-
{
564-
xe_gsc_proxy_remove(gsc);
565-
}
566-
567558
/*
568559
* wa_14015076503: if the GSC FW is loaded, we need to alert it before doing a
569560
* GSC engine reset by writing a notification bit in the GS1 register and then

drivers/gpu/drm/xe/xe_gsc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ int xe_gsc_init(struct xe_gsc *gsc);
1717
int xe_gsc_init_post_hwconfig(struct xe_gsc *gsc);
1818
void xe_gsc_wait_for_worker_completion(struct xe_gsc *gsc);
1919
void xe_gsc_load_start(struct xe_gsc *gsc);
20-
void xe_gsc_remove(struct xe_gsc *gsc);
2120
void xe_gsc_hwe_irq_handler(struct xe_hw_engine *hwe, u16 intr_vec);
2221

2322
void xe_gsc_wa_14015076503(struct xe_gt *gt, bool prep);

drivers/gpu/drm/xe/xe_gsc_proxy.c

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,34 @@ static int proxy_channel_alloc(struct xe_gsc *gsc)
423423
return 0;
424424
}
425425

426+
static void xe_gsc_proxy_remove(void *arg)
427+
{
428+
struct xe_gsc *gsc = arg;
429+
struct xe_gt *gt = gsc_to_gt(gsc);
430+
struct xe_device *xe = gt_to_xe(gt);
431+
unsigned int fw_ref = 0;
432+
433+
if (!gsc->proxy.component_added)
434+
return;
435+
436+
/* disable HECI2 IRQs */
437+
xe_pm_runtime_get(xe);
438+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GSC);
439+
if (!fw_ref)
440+
xe_gt_err(gt, "failed to get forcewake to disable GSC interrupts\n");
441+
442+
/* try do disable irq even if forcewake failed */
443+
gsc_proxy_irq_toggle(gsc, false);
444+
445+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
446+
xe_pm_runtime_put(xe);
447+
448+
xe_gsc_wait_for_worker_completion(gsc);
449+
450+
component_del(xe->drm.dev, &xe_gsc_proxy_component_ops);
451+
gsc->proxy.component_added = false;
452+
}
453+
426454
/**
427455
* xe_gsc_proxy_init() - init objects and MEI component required by GSC proxy
428456
* @gsc: the GSC uC
@@ -462,40 +490,7 @@ int xe_gsc_proxy_init(struct xe_gsc *gsc)
462490

463491
gsc->proxy.component_added = true;
464492

465-
/* the component must be removed before unload, so can't use drmm for cleanup */
466-
467-
return 0;
468-
}
469-
470-
/**
471-
* xe_gsc_proxy_remove() - remove the GSC proxy MEI component
472-
* @gsc: the GSC uC
473-
*/
474-
void xe_gsc_proxy_remove(struct xe_gsc *gsc)
475-
{
476-
struct xe_gt *gt = gsc_to_gt(gsc);
477-
struct xe_device *xe = gt_to_xe(gt);
478-
unsigned int fw_ref = 0;
479-
480-
if (!gsc->proxy.component_added)
481-
return;
482-
483-
/* disable HECI2 IRQs */
484-
xe_pm_runtime_get(xe);
485-
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FW_GSC);
486-
if (!fw_ref)
487-
xe_gt_err(gt, "failed to get forcewake to disable GSC interrupts\n");
488-
489-
/* try do disable irq even if forcewake failed */
490-
gsc_proxy_irq_toggle(gsc, false);
491-
492-
xe_force_wake_put(gt_to_fw(gt), fw_ref);
493-
xe_pm_runtime_put(xe);
494-
495-
xe_gsc_wait_for_worker_completion(gsc);
496-
497-
component_del(xe->drm.dev, &xe_gsc_proxy_component_ops);
498-
gsc->proxy.component_added = false;
493+
return xe_device_add_action_or_reset(xe, xe_gsc_proxy_remove, gsc);
499494
}
500495

501496
/**

drivers/gpu/drm/xe/xe_gsc_proxy.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ struct xe_gsc;
1212

1313
int xe_gsc_proxy_init(struct xe_gsc *gsc);
1414
bool xe_gsc_proxy_init_done(struct xe_gsc *gsc);
15-
void xe_gsc_proxy_remove(struct xe_gsc *gsc);
1615
int xe_gsc_proxy_start(struct xe_gsc *gsc);
1716

1817
int xe_gsc_proxy_request_handler(struct xe_gsc *gsc);

drivers/gpu/drm/xe/xe_gsc_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/workqueue.h>
1414

1515
#include "xe_uc_fw_types.h"
16+
#include "xe_device_types.h"
1617

1718
struct xe_bo;
1819
struct xe_exec_queue;

drivers/gpu/drm/xe/xe_gt.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -141,26 +141,6 @@ static void xe_gt_disable_host_l2_vram(struct xe_gt *gt)
141141
xe_force_wake_put(gt_to_fw(gt), fw_ref);
142142
}
143143

144-
/**
145-
* xe_gt_remove() - Clean up the GT structures before driver removal
146-
* @gt: the GT object
147-
*
148-
* This function should only act on objects/structures that must be cleaned
149-
* before the driver removal callback is complete and therefore can't be
150-
* deferred to a drmm action.
151-
*/
152-
void xe_gt_remove(struct xe_gt *gt)
153-
{
154-
int i;
155-
156-
xe_uc_remove(&gt->uc);
157-
158-
for (i = 0; i < XE_ENGINE_CLASS_MAX; ++i)
159-
xe_hw_fence_irq_finish(&gt->fence_irq[i]);
160-
161-
xe_gt_disable_host_l2_vram(gt);
162-
}
163-
164144
static void gt_reset_worker(struct work_struct *w);
165145

166146
static int emit_nop_job(struct xe_gt *gt, struct xe_exec_queue *q)
@@ -583,6 +563,17 @@ int xe_gt_init_hwconfig(struct xe_gt *gt)
583563
return err;
584564
}
585565

566+
static void xe_gt_fini(void *arg)
567+
{
568+
struct xe_gt *gt = arg;
569+
int i;
570+
571+
for (i = 0; i < XE_ENGINE_CLASS_MAX; ++i)
572+
xe_hw_fence_irq_finish(&gt->fence_irq[i]);
573+
574+
xe_gt_disable_host_l2_vram(gt);
575+
}
576+
586577
int xe_gt_init(struct xe_gt *gt)
587578
{
588579
int err;
@@ -595,6 +586,10 @@ int xe_gt_init(struct xe_gt *gt)
595586
xe_hw_fence_irq_init(&gt->fence_irq[i]);
596587
}
597588

589+
err = devm_add_action_or_reset(gt_to_xe(gt)->drm.dev, xe_gt_fini, gt);
590+
if (err)
591+
return err;
592+
598593
err = xe_gt_pagefault_init(gt);
599594
if (err)
600595
return err;

drivers/gpu/drm/xe/xe_gt.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ int xe_gt_resume(struct xe_gt *gt);
5454
void xe_gt_reset_async(struct xe_gt *gt);
5555
void xe_gt_sanitize(struct xe_gt *gt);
5656
int xe_gt_sanitize_freq(struct xe_gt *gt);
57-
void xe_gt_remove(struct xe_gt *gt);
5857

5958
/**
6059
* xe_gt_wait_for_reset - wait for gt's async reset to finalize.

drivers/gpu/drm/xe/xe_uc.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -288,19 +288,6 @@ int xe_uc_suspend(struct xe_uc *uc)
288288
return xe_guc_suspend(&uc->guc);
289289
}
290290

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-
*/
299-
void xe_uc_remove(struct xe_uc *uc)
300-
{
301-
xe_gsc_remove(&uc->gsc);
302-
}
303-
304291
/**
305292
* xe_uc_declare_wedged() - Declare UC wedged
306293
* @uc: the UC object

drivers/gpu/drm/xe/xe_uc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ void xe_uc_stop(struct xe_uc *uc);
2020
int xe_uc_start(struct xe_uc *uc);
2121
int xe_uc_suspend(struct xe_uc *uc);
2222
int xe_uc_sanitize_reset(struct xe_uc *uc);
23-
void xe_uc_remove(struct xe_uc *uc);
2423
void xe_uc_declare_wedged(struct xe_uc *uc);
2524

2625
#endif

0 commit comments

Comments
 (0)