Skip to contentSkip to conversation

drm/v3d: Convert v3d logging to device-based DRM helpers

PATCH Applied Maíra Canal 2 participants 5 messages Jan 12 – Jan 19

Subsystems (3)
lore
Share & tools
lore

Maíra Canal

author maintainer
#0 lore raw

v2 cover drm/v3d: Convert v3d logging to device-based DRM helpers

This small series intends to replace the legacy DRM_DEBUG/INFO/WARN/ERROR logging with the corresponding device-based drm_dbg(), drm_info(), drm_warn() and drm_err() helpers. I split the series in two patches to ease the reviewing process as the first one has a minor code-refactor.

Thanks for the review!

Best regards,
- Maíra

---
v1 -> v2:

- [1/2, 2/2] Use the ``struct drm_file *file_priv`` pointer instead of passing ``struct v3d_dev`` to functions (Iago Toral)
- [2/2] s/drm_warn/drm_err in ``v3d_reset()`` (Iago Toral)
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Maíra Canal (2):
drm/v3d: Consolidate CPU job validation in a function drm/v3d: Convert v3d logging to device-based DRM helpers

 drivers/gpu/drm/v3d/v3d_bo.c     |   8 +--
 drivers/gpu/drm/v3d/v3d_drv.c    |   6 +-
 drivers/gpu/drm/v3d/v3d_gem.c    |  16 ++---
 drivers/gpu/drm/v3d/v3d_irq.c    |   8 +--
 drivers/gpu/drm/v3d/v3d_mmu.c    |   6 +-
 drivers/gpu/drm/v3d/v3d_sched.c  |   6 +-
 drivers/gpu/drm/v3d/v3d_submit.c | 140 +++++++++++++++++----------------------
 7 files changed, 88 insertions(+), 102 deletions(-)

---
base-commit: 44e4c88951fa9c73bfbde8269e443ea5343dd2af
change-id: 20260109-v3d-drm-debug-412cec00a4ac

author maintainer
#1 lore raw

PATCH v2 1/2 drm/v3d: Consolidate CPU job validation in a function

All CPU job extension parsers duplicate the same validation procedure:
ensure the extension is attached to a CPU job (not a GPU job) and that only a single CPU job extension is associated with a given job.

Create a function to consolidate these checks and reduce the boilerplate across the various CPU job extension handlers. While here, convert the legacy DRM_DEBUG with a more appropriate drm_dbg().

---
 drivers/gpu/drm/v3d/v3d_submit.c | 74 ++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 48 deletions(-)
drivers/gpu/drm/v3d/v3d_submit.c +26 -48
index 7de5a95ee7ca92d480af1f2996c12f2cefa56f34..55e810b7417dc673a0625473d9369c814c18bec6 100644
@@ -404,6 +404,26 @@ v3d_get_multisync_submit_deps(struct drm_file *file_priv,
 	return 0;
 }
 
+/* Returns false if the CPU job has an invalid configuration. */
+static bool
+v3d_validate_cpu_job(struct drm_file *file_priv, struct v3d_cpu_job *job)
+{
+	struct v3d_file_priv *v3d_priv = file_priv->driver_priv;
+	struct v3d_dev *v3d = v3d_priv->v3d;
+
+	if (!job) {
+		drm_dbg(&v3d->drm, "CPU job extension was attached to a GPU job.\n");
+		return false;
+	}
+
+	if (job->job_type) {
+		drm_dbg(&v3d->drm, "Two CPU job extensions were added to the same CPU job.\n");
+		return false;
+	}
+
+	return true;
+}
+
 /* Get data for the indirect CSD job submission. */
 static int
 v3d_get_cpu_indirect_csd_params(struct drm_file *file_priv,
@@ -415,15 +435,8 @@ v3d_get_cpu_indirect_csd_params(struct drm_file *file_priv,
 	struct drm_v3d_indirect_csd indirect_csd;
 	struct v3d_indirect_csd_info *info = &job->indirect_csd;
 
-	if (!job) {
-		DRM_DEBUG("CPU job extension was attached to a GPU job.\n");
+	if (!v3d_validate_cpu_job(file_priv, job))
 		return -EINVAL;
-	}
-
-	if (job->job_type) {
-		DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n");
-		return -EINVAL;
-	}
 
 	if (copy_from_user(&indirect_csd, ext, sizeof(indirect_csd)))
 		return -EFAULT;
@@ -458,15 +471,8 @@ v3d_get_cpu_timestamp_query_params(struct drm_file *file_priv,
 	unsigned int i;
 	int err;
 
-	if (!job) {
-		DRM_DEBUG("CPU job extension was attached to a GPU job.\n");
+	if (!v3d_validate_cpu_job(file_priv, job))
 		return -EINVAL;
-	}
-
-	if (job->job_type) {
-		DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n");
-		return -EINVAL;
-	}
 
 	if (copy_from_user(&timestamp, ext, sizeof(timestamp)))
 		return -EFAULT;
@@ -527,15 +533,8 @@ v3d_get_cpu_reset_timestamp_params(struct drm_file *file_priv,
 	unsigned int i;
 	int err;
 
-	if (!job) {
-		DRM_DEBUG("CPU job extension was attached to a GPU job.\n");
+	if (!v3d_validate_cpu_job(file_priv, job))
 		return -EINVAL;
-	}
-
-	if (job->job_type) {
-		DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n");
-		return -EINVAL;
-	}
 
 	if (copy_from_user(&reset, ext, sizeof(reset)))
 		return -EFAULT;
@@ -588,15 +587,8 @@ v3d_get_cpu_copy_query_results_params(struct drm_file *file_priv,
 	unsigned int i;
 	int err;
 
-	if (!job) {
-		DRM_DEBUG("CPU job extension was attached to a GPU job.\n");
+	if (!v3d_validate_cpu_job(file_priv, job))
 		return -EINVAL;
-	}
-
-	if (job->job_type) {
-		DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n");
-		return -EINVAL;
-	}
 
 	if (copy_from_user(&copy, ext, sizeof(copy)))
 		return -EFAULT;
@@ -724,15 +716,8 @@ v3d_get_cpu_reset_performance_params(struct drm_file *file_priv,
 	struct drm_v3d_reset_performance_query reset;
 	int err;
 
-	if (!job) {
-		DRM_DEBUG("CPU job extension was attached to a GPU job.\n");
+	if (!v3d_validate_cpu_job(file_priv, job))
 		return -EINVAL;
-	}
-
-	if (job->job_type) {
-		DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n");
-		return -EINVAL;
-	}
 
 	if (copy_from_user(&reset, ext, sizeof(reset)))
 		return -EFAULT;
@@ -770,15 +755,8 @@ v3d_get_cpu_copy_performance_query_params(struct drm_file *file_priv,
 	struct drm_v3d_copy_performance_query copy;
 	int err;
 
-	if (!job) {
-		DRM_DEBUG("CPU job extension was attached to a GPU job.\n");
+	if (!v3d_validate_cpu_job(file_priv, job))
 		return -EINVAL;
-	}
-
-	if (job->job_type) {
-		DRM_DEBUG("Two CPU job extensions were added to the same CPU job.\n");
-		return -EINVAL;
-	}
 
 	if (copy_from_user(&copy, ext, sizeof(copy)))
 		return -EFAULT;
Signature · 1 line
2.52.0
author maintainer
#2 lore raw

PATCH v2 2/2 drm/v3d: Convert v3d logging to device-based DRM helpers

In reply to Maíra Canal

Replace legacy DRM_DEBUG/INFO/WARN/ERROR logging with the corresponding device-based drm_dbg(), drm_info(), drm_warn() and drm_err() helpers. For some messages, adjust the log level to better reflect their severity.

This allows filtering via drm.debug, reduces log spam, and helps differentiate v3d logs from vc4 logs.

---
 drivers/gpu/drm/v3d/v3d_bo.c     |  8 ++---
 drivers/gpu/drm/v3d/v3d_drv.c    |  6 ++--
 drivers/gpu/drm/v3d/v3d_gem.c    | 16 +++++-----
 drivers/gpu/drm/v3d/v3d_irq.c    |  8 ++---
 drivers/gpu/drm/v3d/v3d_mmu.c    |  6 ++--
 drivers/gpu/drm/v3d/v3d_sched.c  |  6 ++--
 drivers/gpu/drm/v3d/v3d_submit.c | 66 ++++++++++++++++++++++------------------
 7 files changed, 62 insertions(+), 54 deletions(-)
drivers/gpu/drm/v3d/v3d_bo.c +4 -4
index c4316b768b3dad0b76e93b95e7c0dcc9dbf081f9..36aae97cf6da7aabd68dc56138e0105f74ab661b 100644
@@ -213,7 +213,7 @@ int v3d_create_bo_ioctl(struct drm_device *dev, void *data,
 	int ret;
 
 	if (args->flags != 0) {
-		DRM_INFO("unknown create_bo flags: %d\n", args->flags);
+		drm_dbg(dev, "unknown create_bo flags: %d\n", args->flags);
 		return -EINVAL;
 	}
 
@@ -236,13 +236,13 @@ int v3d_mmap_bo_ioctl(struct drm_device *dev, void *data,
 	struct drm_gem_object *gem_obj;
 
 	if (args->flags != 0) {
-		DRM_INFO("unknown mmap_bo flags: %d\n", args->flags);
+		drm_dbg(dev, "unknown mmap_bo flags: %d\n", args->flags);
 		return -EINVAL;
 	}
 
 	gem_obj = drm_gem_object_lookup(file_priv, args->handle);
 	if (!gem_obj) {
-		DRM_DEBUG("Failed to look up GEM BO %d\n", args->handle);
+		drm_dbg(dev, "Failed to look up GEM BO %d\n", args->handle);
 		return -ENOENT;
 	}
 
@@ -261,7 +261,7 @@ int v3d_get_bo_offset_ioctl(struct drm_device *dev, void *data,
 
 	gem_obj = drm_gem_object_lookup(file_priv, args->handle);
 	if (!gem_obj) {
-		DRM_DEBUG("Failed to look up GEM BO %d\n", args->handle);
+		drm_dbg(dev, "Failed to look up GEM BO %d\n", args->handle);
 		return -ENOENT;
 	}
 	bo = to_v3d_bo(gem_obj);
drivers/gpu/drm/v3d/v3d_drv.c +3 -3
index a11ca276061a8462977ed3d837ffcc96b2f444f6..8de4f151a5c02cbf970e72933d1a275968088357 100644
@@ -120,7 +120,7 @@ static int v3d_get_param_ioctl(struct drm_device *dev, void *data,
 		mutex_unlock(&v3d->reset_lock);
 		return 0;
 	default:
-		DRM_DEBUG("Unknown parameter %d\n", args->param);
+		drm_dbg(dev, "Unknown parameter %d\n", args->param);
 		return -EINVAL;
 	}
 }
@@ -297,7 +297,7 @@ v3d_idle_sms(struct v3d_dev *v3d)
 
 	if (wait_for((V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_TEE_CS),
 				    V3D_SMS_STATE) == V3D_SMS_IDLE), 100)) {
-		DRM_ERROR("Failed to power up SMS\n");
+		drm_err(&v3d->drm, "Failed to power up SMS\n");
 	}
 
 	v3d_reset_sms(v3d);
@@ -313,7 +313,7 @@ v3d_power_off_sms(struct v3d_dev *v3d)
 
 	if (wait_for((V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_TEE_CS),
 				    V3D_SMS_STATE) == V3D_SMS_POWER_OFF_STATE), 100)) {
-		DRM_ERROR("Failed to power off SMS\n");
+		drm_err(&v3d->drm, "Failed to power off SMS\n");
 	}
 }
 
drivers/gpu/drm/v3d/v3d_gem.c +8 -8
index 697b0b3ca92cf8f4cc7910a2a7b01ea43c79fe11..57965c0d6f6efea0019fb0b1a47addf2f586d138 100644
@@ -52,7 +52,7 @@ v3d_idle_axi(struct v3d_dev *v3d, int core)
 		      (V3D_GMP_STATUS_RD_COUNT_MASK |
 		       V3D_GMP_STATUS_WR_COUNT_MASK |
 		       V3D_GMP_STATUS_CFG_BUSY)) == 0, 100)) {
-		DRM_ERROR("Failed to wait for safe GMP shutdown\n");
+		drm_err(&v3d->drm, "Failed to wait for safe GMP shutdown\n");
 	}
 }
 
@@ -67,7 +67,7 @@ v3d_idle_gca(struct v3d_dev *v3d)
 	if (wait_for((V3D_GCA_READ(V3D_GCA_SAFE_SHUTDOWN_ACK) &
 		      V3D_GCA_SAFE_SHUTDOWN_ACK_ACKED) ==
 		     V3D_GCA_SAFE_SHUTDOWN_ACK_ACKED, 100)) {
-		DRM_ERROR("Failed to wait for safe GCA shutdown\n");
+		drm_err(&v3d->drm, "Failed to wait for safe GCA shutdown\n");
 	}
 }
 
@@ -117,7 +117,7 @@ v3d_reset_sms(struct v3d_dev *v3d)
 				     V3D_SMS_STATE) == V3D_SMS_ISOLATING_FOR_RESET) &&
 		     !(V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_REE_CS),
 				     V3D_SMS_STATE) == V3D_SMS_RESETTING), 100)) {
-		DRM_ERROR("Failed to wait for SMS reset\n");
+		drm_err(&v3d->drm, "Failed to wait for SMS reset\n");
 	}
 }
 
@@ -126,9 +126,9 @@ v3d_reset(struct v3d_dev *v3d)
 {
 	struct drm_device *dev = &v3d->drm;
 
-	DRM_DEV_ERROR(dev->dev, "Resetting GPU for hang.\n");
-	DRM_DEV_ERROR(dev->dev, "V3D_ERR_STAT: 0x%08x\n",
-		      V3D_CORE_READ(0, V3D_ERR_STAT));
+	drm_err(dev, "Resetting GPU for hang.\n");
+	drm_err(dev, "V3D_ERR_STAT: 0x%08x\n", V3D_CORE_READ(0, V3D_ERR_STAT));
+
 	trace_v3d_reset_begin(dev);
 
 	/* XXX: only needed for safe powerdown, not reset. */
@@ -216,7 +216,7 @@ v3d_clean_caches(struct v3d_dev *v3d)
 	V3D_CORE_WRITE(core, V3D_CTL_L2TCACTL, V3D_L2TCACTL_TMUWCF);
 	if (wait_for(!(V3D_CORE_READ(core, V3D_CTL_L2TCACTL) &
 		       V3D_L2TCACTL_TMUWCF), 100)) {
-		DRM_ERROR("Timeout waiting for TMU write combiner flush\n");
+		drm_err(dev, "Timeout waiting for TMU write combiner flush\n");
 	}
 
 	mutex_lock(&v3d->cache_clean_lock);
@@ -226,7 +226,7 @@ v3d_clean_caches(struct v3d_dev *v3d)
 
 	if (wait_for(!(V3D_CORE_READ(core, V3D_CTL_L2TCACTL) &
 		       V3D_L2TCACTL_L2TFLS), 100)) {
-		DRM_ERROR("Timeout waiting for L2T clean\n");
+		drm_err(dev, "Timeout waiting for L2T clean\n");
 	}
 
 	mutex_unlock(&v3d->cache_clean_lock);
drivers/gpu/drm/v3d/v3d_irq.c +4 -4
index b55880fd6c508bd47a27c15db3fd8d21ded2dbd1..1249f6e64b979fe29cf2b9bfc43b39aa755f71ce 100644
@@ -50,7 +50,7 @@ v3d_overflow_mem_work(struct work_struct *work)
 	unsigned long irqflags;
 
 	if (IS_ERR(bo)) {
-		DRM_ERROR("Couldn't allocate binner overflow mem\n");
+		drm_err(dev, "Couldn't allocate binner overflow mem\n");
 		return;
 	}
 	obj = &bo->base.base;
@@ -140,7 +140,7 @@ v3d_irq(int irq, void *arg)
 	 * always-allowed mode.
 	 */
 	if (v3d->ver < V3D_GEN_71 && (intsts & V3D_INT_GMPV))
-		dev_err(v3d->drm.dev, "GMP violation\n");
+		drm_err(&v3d->drm, "GMP violation\n");
 
 	/* V3D 4.2 wires the hub and core IRQs together, so if we &
 	 * didn't see the common one then check hub for MMU IRQs.
@@ -226,7 +226,7 @@ v3d_hub_irq(int irq, void *arg)
 			}
 		}
 
-		dev_err(v3d->drm.dev, "MMU error from client %s (0x%x) at 0x%llx%s%s%s\n",
+		drm_dbg(&v3d->drm, "MMU error from client %s (0x%x) at 0x%llx%s%s%s\n",
 			client, axi_id, (long long)vio_addr,
 			((intsts & V3D_HUB_INT_MMU_WRV) ?
 			 ", write violation" : ""),
@@ -238,7 +238,7 @@ v3d_hub_irq(int irq, void *arg)
 	}
 
 	if (v3d->ver >= V3D_GEN_71 && (intsts & V3D_V7_HUB_INT_GMPV)) {
-		dev_err(v3d->drm.dev, "GMP Violation\n");
+		drm_err(&v3d->drm, "GMP Violation\n");
 		status = IRQ_HANDLED;
 	}
 
drivers/gpu/drm/v3d/v3d_mmu.c +4 -2
index a25d25a8ae617bf68e133e1793cd0bb930bb07f6..c513a393c0313772650fd6d7236127b2dc4101d9 100644
@@ -18,6 +18,8 @@
  * each client. This is not yet implemented.
  */
 
+#include <drm/drm_print.h>
+
 #include "v3d_drv.h"
 #include "v3d_regs.h"
 
@@ -125,7 +127,7 @@ void v3d_mmu_insert_ptes(struct v3d_bo *bo)
 		     shmem_obj->base.size >> V3D_MMU_PAGE_SHIFT);
 
 	if (v3d_mmu_flush_all(v3d))
-		dev_err(v3d->drm.dev, "MMU flush timeout\n");
+		drm_err(&v3d->drm, "MMU flush timeout\n");
 }
 
 void v3d_mmu_remove_ptes(struct v3d_bo *bo)
@@ -138,5 +140,5 @@ void v3d_mmu_remove_ptes(struct v3d_bo *bo)
 		v3d->pt[page] = 0;
 
 	if (v3d_mmu_flush_all(v3d))
-		dev_err(v3d->drm.dev, "MMU flush timeout\n");
+		drm_err(&v3d->drm, "MMU flush timeout\n");
 }
drivers/gpu/drm/v3d/v3d_sched.c +3 -3
index 0867250db7a64fb79c50c99aa46551343cdac249..6dc871fc9a62303da4fbc62b612c3a797fe762de 100644
@@ -585,7 +585,7 @@ v3d_reset_performance_queries(struct v3d_cpu_job *job)
 			perfmon = v3d_perfmon_find(v3d_priv,
 						   performance_query->queries[i].kperfmon_ids[j]);
 			if (!perfmon) {
-				DRM_DEBUG("Failed to find perfmon.");
+				drm_dbg(&v3d->drm, "Failed to find perfmon.");
 				continue;
 			}
 
@@ -620,7 +620,7 @@ v3d_write_performance_query_result(struct v3d_cpu_job *job, void *data,
 		perfmon = v3d_perfmon_find(v3d_priv,
 					   perf_query->kperfmon_ids[i]);
 		if (!perfmon) {
-			DRM_DEBUG("Failed to find perfmon.");
+			drm_dbg(&v3d->drm, "Failed to find perfmon.");
 			continue;
 		}
 
@@ -690,7 +690,7 @@ v3d_cpu_job_run(struct drm_sched_job *sched_job)
 	struct v3d_dev *v3d = job->base.v3d;
 
 	if (job->job_type >= ARRAY_SIZE(cpu_job_function)) {
-		DRM_DEBUG_DRIVER("Unknown CPU job: %d\n", job->job_type);
+		drm_dbg(&v3d->drm, "Unknown CPU job: %d\n", job->job_type);
 		return NULL;
 	}
 
drivers/gpu/drm/v3d/v3d_submit.c +36 -30

237 lines not on this page · raw message

Signature · 1 line
2.52.0
Reviewed-by on the v2 series
#3 lore raw
In reply to Maíra Canal

Thanks!

Quoted 41 lines · Maíra Canal

This small series intends to replace the legacy DRM_DEBUG/INFO/WARN/ERROR
logging with the corresponding device-based drm_dbg(), drm_info(), drm_warn()
and drm_err() helpers. I split the series in two patches to ease the reviewing process as the first one has a minor code-refactor.

Thanks for the review!

Best regards,
- Maíra

---
v1 -> v2:

- [1/2, 2/2] Use the ``struct drm_file *file_priv`` pointer instead of
  passing ``struct v3d_dev`` to functions (Iago Toral)
- [2/2] s/drm_warn/drm_err in ``v3d_reset()`` (Iago Toral)
- Link to v1:
https://lore.kernel.org/r/[email protected]

---
Maíra Canal (2):
      drm/v3d: Consolidate CPU job validation in a function drm/v3d: Convert v3d logging to device-based DRM helpers

 drivers/gpu/drm/v3d/v3d_bo.c     |   8 +--

 drivers/gpu/drm/v3d/v3d_drv.c    |   6 +-
 drivers/gpu/drm/v3d/v3d_gem.c    |  16 ++---
 drivers/gpu/drm/v3d/v3d_irq.c    |   8 +--
 drivers/gpu/drm/v3d/v3d_mmu.c    |   6 +-
 drivers/gpu/drm/v3d/v3d_sched.c  |   6 +-
 drivers/gpu/drm/v3d/v3d_submit.c | 140 +++++++++++++++++------------
----------
 7 files changed, 88 insertions(+), 102 deletions(-)

---
base-commit: 44e4c88951fa9c73bfbde8269e443ea5343dd2af
change-id: 20260109-v3d-drm-debug-412cec00a4ac

author maintainer Applied
#4 lore raw
In reply to Maíra Canal
Quoted 8 lines · Maíra Canal

This small series intends to replace the legacy DRM_DEBUG/INFO/WARN/ERROR logging with the corresponding device-based drm_dbg(), drm_info(), drm_warn() and drm_err() helpers. I split the series in two patches to ease the reviewing process as the first one has a minor code-refactor.

Thanks for the review!

[...]

Applied, thanks!

[1/2] drm/v3d: Consolidate CPU job validation in a function

      commit: eaba54b8a67bdec7f834d61ff6cf5f0f3f4ea5bc
[2/2] drm/v3d: Convert v3d logging to device-based DRM helpers
      commit: f5520a1a844342af7295a72c35cc9690b7a9fdd1

Best regards,
- Maíra