From 490c9846622231a8fe7daf11a31557885b718a68 Mon Sep 17 00:00:00 2001 From: Mikko Perttunen Date: Wed, 13 Dec 2023 06:04:02 +0200 Subject: [PATCH] gpu: host1x: Handle CDMA wraparound when debug printing During channel debug information dump, when printing CDMA opcodes, the circular nature of the CDMA pushbuffer wasn't being taken into account, sometimes accessing past the end. Change the printing to take this into account. Bug 4398831 Bug 4386806 Signed-off-by: Mikko Perttunen Change-Id: I3a24da2c310e9414882f7cabbbda5158b6da00a2 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3033461 (cherry picked from commit 58568987a6e9733e3113b927c6fce454778b3a4d) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3155731 GVS: buildbot_gerritrpt Tested-by: Johnny Liu Reviewed-by: Johnny Liu --- drivers/gpu/host1x/hw/debug_hw.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/host1x/hw/debug_hw.c b/drivers/gpu/host1x/hw/debug_hw.c index 8e7bbd30..2cedc2cc 100644 --- a/drivers/gpu/host1x/hw/debug_hw.c +++ b/drivers/gpu/host1x/hw/debug_hw.c @@ -177,7 +177,14 @@ static void show_gather(struct output *o, dma_addr_t phys_addr, for (i = 0; i < words; i++) { dma_addr_t addr = phys_addr + i * 4; - u32 val = *(map_addr + offset / 4 + i); + u32 voffset = offset + i * 4; + u32 val; + + /* If we reach the RESTART opcode, continue at the beginning of pushbuffer */ + if (cdma && voffset >= cdma->push_buffer.size) + voffset -= cdma->push_buffer.size; + + val = *(map_addr + voffset / 4); if (!data_count) { host1x_debug_output(o, " %pad: %08x: ", &addr, val); @@ -203,7 +210,7 @@ static void show_channel_gathers(struct output *o, struct host1x_cdma *cdma) job->num_slots, job->num_unpins); show_gather(o, pb->dma + job->first_get, job->num_slots * 2, cdma, - pb->dma + job->first_get, pb->mapped + job->first_get); + pb->dma, pb->mapped); for (i = 0; i < job->num_cmds; i++) { struct host1x_job_gather *g; @@ -227,7 +234,7 @@ static void show_channel_gathers(struct output *o, struct host1x_cdma *cdma) host1x_debug_output(o, " GATHER at %pad+%#x, %d words\n", &g->base, g->offset, g->words); - show_gather(o, g->base + g->offset, g->words, cdma, + show_gather(o, g->base + g->offset, g->words, NULL, g->base, mapped); if (!job->gather_copy_mapped)