Skip to content

Commit

Permalink
drm/xe: re-order lmem init check and wait for initialization to complete
Browse files Browse the repository at this point in the history
Lmem init check should be done only after pcode initialization
status is complete. Move lmem init check after pcode status
check. Also wait for a short while after pcode status check
to allow completion of the task.

Failing to do so, can lead to aborting the module load
leaving the system unusable. Wait until the lmem initialization
is complete within a timeout (60s) or till the user aborts.

v2: use bool as return type
    re-order the code comment (Rodrigo)
    add comment for deferring probe (Himal)

v3: rebase

Signed-off-by: Riana Tauro <riana.tauro@intel.com>
Acked-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240410085005.1126343-3-riana.tauro@intel.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
  • Loading branch information
Riana Tauro authored and Rodrigo Vivi committed Apr 10, 2024
1 parent 933fd5f commit 797b0e9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 28 deletions.
62 changes: 59 additions & 3 deletions drivers/gpu/drm/xe/xe_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,68 @@ static int xe_set_dma_info(struct xe_device *xe)
return err;
}

static bool verify_lmem_ready(struct xe_gt *gt)
{
u32 val = xe_mmio_read32(gt, GU_CNTL) & LMEM_INIT;

return !!val;
}

static int wait_for_lmem_ready(struct xe_device *xe)
{
struct xe_gt *gt = xe_root_mmio_gt(xe);
unsigned long timeout, start;

if (!IS_DGFX(xe))
return 0;

if (IS_SRIOV_VF(xe))
return 0;

if (verify_lmem_ready(gt))
return 0;

drm_dbg(&xe->drm, "Waiting for lmem initialization\n");

start = jiffies;
timeout = start + msecs_to_jiffies(60 * 1000); /* 60 sec! */

do {
if (signal_pending(current))
return -EINTR;

/*
* The boot firmware initializes local memory and
* assesses its health. If memory training fails,
* the punit will have been instructed to keep the GT powered
* down.we won't be able to communicate with it
*
* If the status check is done before punit updates the register,
* it can lead to the system being unusable.
* use a timeout and defer the probe to prevent this.
*/
if (time_after(jiffies, timeout)) {
drm_dbg(&xe->drm, "lmem not initialized by firmware\n");
return -EPROBE_DEFER;
}

msleep(20);

} while (!verify_lmem_ready(gt));

drm_dbg(&xe->drm, "lmem ready after %ums",
jiffies_to_msecs(jiffies - start));

return 0;
}

/**
* xe_device_probe_early: Device early probe
* @xe: xe device instance
*
* Initialize MMIO resources that don't require any
* knowledge about tile count. Also initialize pcode
* knowledge about tile count. Also initialize pcode and
* check vram initialization on root tile.
*
* Return: 0 on success, error code on failure
*/
Expand All @@ -441,11 +497,11 @@ int xe_device_probe_early(struct xe_device *xe)

xe_sriov_probe_early(xe);

err = xe_mmio_verify_vram(xe);
err = xe_pcode_probe_early(xe);
if (err)
return err;

err = xe_pcode_probe_early(xe);
err = wait_for_lmem_ready(xe);
if (err)
return err;

Expand Down
24 changes: 0 additions & 24 deletions drivers/gpu/drm/xe/xe_mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,30 +420,6 @@ int xe_mmio_init(struct xe_device *xe)
return drmm_add_action_or_reset(&xe->drm, mmio_fini, xe);
}

int xe_mmio_verify_vram(struct xe_device *xe)
{
struct xe_gt *gt = xe_root_mmio_gt(xe);

if (!IS_DGFX(xe))
return 0;

if (IS_SRIOV_VF(xe))
return 0;

/*
* The boot firmware initializes local memory and assesses its health.
* If memory training fails, the punit will have been instructed to
* keep the GT powered down; we won't be able to communicate with it
* and we should not continue with driver initialization.
*/
if (!(xe_mmio_read32(gt, GU_CNTL) & LMEM_INIT)) {
drm_err(&xe->drm, "VRAM not initialized by firmware\n");
return -ENODEV;
}

return 0;
}

u8 xe_mmio_read8(struct xe_gt *gt, struct xe_reg reg)
{
struct xe_tile *tile = gt_to_tile(gt);
Expand Down
1 change: 0 additions & 1 deletion drivers/gpu/drm/xe/xe_mmio.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ struct xe_device;
#define LMEM_BAR 2

int xe_mmio_init(struct xe_device *xe);
int xe_mmio_verify_vram(struct xe_device *xe);
void xe_mmio_probe_tiles(struct xe_device *xe);

u8 xe_mmio_read8(struct xe_gt *gt, struct xe_reg reg);
Expand Down

0 comments on commit 797b0e9

Please sign in to comment.