[RFC PATCH] drm/imagination: Move PowerVR GPU init to the drivers's open callback

From: Javier Martinez Canillas
Date: Tue Jan 09 2024 - 08:47:05 EST


Currently the device is initialized in the driver's probe callback. But as
part of this initialization, the required firmware is loaded and this will
fail when the driver is built-in, unless FW is included in the initramfs:

$ dmesg | grep powervr
[ 2.969757] powervr fd00000.gpu: Direct firmware load for powervr/rogue_33.15.11.3_v1.fw failed with error -2
[ 2.979727] powervr fd00000.gpu: [drm] *ERROR* failed to load firmware powervr/rogue_33.15.11.3_v1.fw (err=-2)
[ 2.989885] powervr: probe of fd00000.gpu failed with error -2

$ ls -lh /lib/firmware/powervr/rogue_33.15.11.3_v1.fw.xz
-rw-r--r-- 1 root root 51K Dec 12 19:00 /lib/firmware/powervr/rogue_33.15.11.3_v1.fw.xz

To prevent this, let's delay the PowerVR GPU-specific initialization until
the render device is opened by user-space. By then, the root filesystem
will be mounted already and the driver able to find the required firmware.

Besides the mentioned problem, it seems more correct to only load firmware
and request the IRQ if the device is opened rather than do these on probe.

Fixes: f99f5f3ea7ef ("drm/imagination: Add GPU ID parsing and firmware loading")
Signed-off-by: Javier Martinez Canillas <javierm@xxxxxxxxxx>
---
drivers/gpu/drm/imagination/pvr_device.c | 41 +++++++-----------------
drivers/gpu/drm/imagination/pvr_device.h | 2 ++
drivers/gpu/drm/imagination/pvr_drv.c | 19 +++++++----
3 files changed, 27 insertions(+), 35 deletions(-)

diff --git a/drivers/gpu/drm/imagination/pvr_device.c b/drivers/gpu/drm/imagination/pvr_device.c
index 1704c0268589..1e0a3868394e 100644
--- a/drivers/gpu/drm/imagination/pvr_device.c
+++ b/drivers/gpu/drm/imagination/pvr_device.c
@@ -404,7 +404,7 @@ pvr_set_dma_info(struct pvr_device *pvr_dev)
* * Any error returned by pvr_memory_context_init(), or
* * Any error returned by pvr_request_firmware().
*/
-static int
+int
pvr_device_gpu_init(struct pvr_device *pvr_dev)
{
int err;
@@ -444,6 +444,10 @@ pvr_device_gpu_init(struct pvr_device *pvr_dev)
if (err)
goto err_vm_ctx_put;

+ err = pvr_device_irq_init(pvr_dev);
+ if (err)
+ goto err_vm_ctx_put;
+
return 0;

err_vm_ctx_put:
@@ -459,9 +463,15 @@ pvr_device_gpu_init(struct pvr_device *pvr_dev)
* pvr_device_gpu_fini() - GPU-specific deinitialization for a PowerVR device
* @pvr_dev: Target PowerVR device.
*/
-static void
+void
pvr_device_gpu_fini(struct pvr_device *pvr_dev)
{
+ /*
+ * Deinitialization stages are performed in reverse order compared to
+ * the initialization stages in pvr_device_gpu_init().
+ */
+ pvr_device_irq_fini(pvr_dev);
+
pvr_fw_fini(pvr_dev);

if (pvr_dev->fw_dev.processor_type != PVR_FW_PROCESSOR_TYPE_MIPS) {
@@ -519,43 +529,16 @@ pvr_device_init(struct pvr_device *pvr_dev)
if (err)
goto err_pm_runtime_put;

- /* Perform GPU-specific initialization steps. */
- err = pvr_device_gpu_init(pvr_dev);
- if (err)
- goto err_pm_runtime_put;
-
- err = pvr_device_irq_init(pvr_dev);
- if (err)
- goto err_device_gpu_fini;
-
pm_runtime_put(dev);

return 0;

-err_device_gpu_fini:
- pvr_device_gpu_fini(pvr_dev);
-
err_pm_runtime_put:
pm_runtime_put_sync_suspend(dev);

return err;
}

-/**
- * pvr_device_fini() - Deinitialize a PowerVR device
- * @pvr_dev: Target PowerVR device.
- */
-void
-pvr_device_fini(struct pvr_device *pvr_dev)
-{
- /*
- * Deinitialization stages are performed in reverse order compared to
- * the initialization stages in pvr_device_init().
- */
- pvr_device_irq_fini(pvr_dev);
- pvr_device_gpu_fini(pvr_dev);
-}
-
bool
pvr_device_has_uapi_quirk(struct pvr_device *pvr_dev, u32 quirk)
{
diff --git a/drivers/gpu/drm/imagination/pvr_device.h b/drivers/gpu/drm/imagination/pvr_device.h
index 2ca7e535799f..3083fcd3f91e 100644
--- a/drivers/gpu/drm/imagination/pvr_device.h
+++ b/drivers/gpu/drm/imagination/pvr_device.h
@@ -481,6 +481,8 @@ packed_bvnc_to_pvr_gpu_id(u64 bvnc, struct pvr_gpu_id *gpu_id)
gpu_id->c = bvnc & GENMASK_ULL(15, 0);
}

+int pvr_device_gpu_init(struct pvr_device *pvr_dev);
+void pvr_device_gpu_fini(struct pvr_device *pvr_dev);
int pvr_device_init(struct pvr_device *pvr_dev);
void pvr_device_fini(struct pvr_device *pvr_dev);
void pvr_device_reset(struct pvr_device *pvr_dev);
diff --git a/drivers/gpu/drm/imagination/pvr_drv.c b/drivers/gpu/drm/imagination/pvr_drv.c
index 5c3b2d58d766..f8fb45136326 100644
--- a/drivers/gpu/drm/imagination/pvr_drv.c
+++ b/drivers/gpu/drm/imagination/pvr_drv.c
@@ -1309,10 +1309,18 @@ pvr_drm_driver_open(struct drm_device *drm_dev, struct drm_file *file)
{
struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
struct pvr_file *pvr_file;
+ int err;
+
+ /* Perform GPU-specific initialization steps. */
+ err = pvr_device_gpu_init(pvr_dev);
+ if (err)
+ return err;

pvr_file = kzalloc(sizeof(*pvr_file), GFP_KERNEL);
- if (!pvr_file)
+ if (!pvr_file) {
+ pvr_device_gpu_fini(pvr_dev);
return -ENOMEM;
+ }

/*
* Store reference to base DRM file private data for use by
@@ -1354,6 +1362,7 @@ static void
pvr_drm_driver_postclose(__always_unused struct drm_device *drm_dev,
struct drm_file *file)
{
+ struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
struct pvr_file *pvr_file = to_pvr_file(file);

/* Kill remaining contexts. */
@@ -1364,6 +1373,8 @@ pvr_drm_driver_postclose(__always_unused struct drm_device *drm_dev,
pvr_destroy_hwrt_datasets_for_file(pvr_file);
pvr_destroy_vm_contexts_for_file(pvr_file);

+ pvr_device_gpu_fini(pvr_dev);
+
kfree(pvr_file);
file->driver_priv = NULL;
}
@@ -1430,16 +1441,13 @@ pvr_probe(struct platform_device *plat_dev)

err = drm_dev_register(drm_dev, 0);
if (err)
- goto err_device_fini;
+ goto err_watchdog_fini;

xa_init_flags(&pvr_dev->free_list_ids, XA_FLAGS_ALLOC1);
xa_init_flags(&pvr_dev->job_ids, XA_FLAGS_ALLOC1);

return 0;

-err_device_fini:
- pvr_device_fini(pvr_dev);
-
err_watchdog_fini:
pvr_watchdog_fini(pvr_dev);

@@ -1464,7 +1472,6 @@ pvr_remove(struct platform_device *plat_dev)
xa_destroy(&pvr_dev->free_list_ids);

pm_runtime_suspend(drm_dev->dev);
- pvr_device_fini(pvr_dev);
drm_dev_unplug(drm_dev);
pvr_watchdog_fini(pvr_dev);
pvr_queue_device_fini(pvr_dev);
--
2.43.0

--
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat