Timur Tabi
2024-Feb-26 21:04 UTC
[PATCH] drm/nouveau: retain device pointer in nvkm_gsp_mem object
Store the struct device pointer used to allocate the DMA buffer in the nvkm_gsp_mem object. This allows nvkm_gsp_mem_dtor() to release the buffer without needing the nvkm_gsp. This is needed so that we can retain DMA buffers even after the nvkm_gsp object is deleted. Signed-off-by: Timur Tabi <ttabi at nvidia.com> --- .../gpu/drm/nouveau/include/nvkm/subdev/gsp.h | 1 + .../gpu/drm/nouveau/nvkm/subdev/gsp/r535.c | 30 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h index 3fbc57b16a05..a9be0d86e412 100644 --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h @@ -9,6 +9,7 @@ #define GSP_PAGE_SIZE BIT(GSP_PAGE_SHIFT) struct nvkm_gsp_mem { + struct device *dev; size_t size; void *data; dma_addr_t addr; diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c index 40757a21e150..1eb1bc5df39a 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c @@ -1000,7 +1000,7 @@ r535_gsp_rpc_get_gsp_static_info(struct nvkm_gsp *gsp) } static void -nvkm_gsp_mem_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_mem *mem) +nvkm_gsp_mem_dtor(struct nvkm_gsp_mem *mem) { if (mem->data) { /* @@ -1009,7 +1009,7 @@ nvkm_gsp_mem_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_mem *mem) */ memset(mem->data, 0xFF, mem->size); - dma_free_coherent(gsp->subdev.device->dev, mem->size, mem->data, mem->addr); + dma_free_coherent(mem->dev, mem->size, mem->data, mem->addr); memset(mem, 0, sizeof(*mem)); } } @@ -1017,11 +1017,13 @@ nvkm_gsp_mem_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_mem *mem) static int nvkm_gsp_mem_ctor(struct nvkm_gsp *gsp, size_t size, struct nvkm_gsp_mem *mem) { - mem->size = size; mem->data = dma_alloc_coherent(gsp->subdev.device->dev, size, &mem->addr, GFP_KERNEL); if (WARN_ON(!mem->data)) return -ENOMEM; + mem->size = size; + mem->dev = gsp->subdev.device->dev; + return 0; } @@ -1054,10 +1056,10 @@ r535_gsp_postinit(struct nvkm_gsp *gsp) nvkm_wr32(device, 0x110004, 0x00000040); /* Release the DMA buffers that were needed only for boot and init */ - nvkm_gsp_mem_dtor(gsp, &gsp->boot.fw); - nvkm_gsp_mem_dtor(gsp, &gsp->libos); - nvkm_gsp_mem_dtor(gsp, &gsp->rmargs); - nvkm_gsp_mem_dtor(gsp, &gsp->wpr_meta); + nvkm_gsp_mem_dtor(&gsp->boot.fw); + nvkm_gsp_mem_dtor(&gsp->libos); + nvkm_gsp_mem_dtor(&gsp->rmargs); + nvkm_gsp_mem_dtor(&gsp->wpr_meta); return ret; } @@ -2249,7 +2251,7 @@ static void nvkm_gsp_radix3_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_radix3 *rx3) { for (int i = ARRAY_SIZE(rx3->mem) - 1; i >= 0; i--) - nvkm_gsp_mem_dtor(gsp, &rx3->mem[i]); + nvkm_gsp_mem_dtor(&rx3->mem[i]); } /** @@ -2407,7 +2409,7 @@ r535_gsp_init(struct nvkm_gsp *gsp) done: if (gsp->sr.meta.data) { - nvkm_gsp_mem_dtor(gsp, &gsp->sr.meta); + nvkm_gsp_mem_dtor(&gsp->sr.meta); nvkm_gsp_radix3_dtor(gsp, &gsp->sr.radix3); nvkm_gsp_sg_free(gsp->subdev.device, &gsp->sr.sgt); return ret; @@ -2488,7 +2490,7 @@ r535_gsp_dtor(struct nvkm_gsp *gsp) mutex_destroy(&gsp->client_id.mutex); nvkm_gsp_radix3_dtor(gsp, &gsp->radix3); - nvkm_gsp_mem_dtor(gsp, &gsp->sig); + nvkm_gsp_mem_dtor(&gsp->sig); nvkm_firmware_dtor(&gsp->fw); nvkm_falcon_fw_dtor(&gsp->booter.unload); @@ -2499,10 +2501,10 @@ r535_gsp_dtor(struct nvkm_gsp *gsp) r535_gsp_dtor_fws(gsp); - nvkm_gsp_mem_dtor(gsp, &gsp->shm.mem); - nvkm_gsp_mem_dtor(gsp, &gsp->loginit); - nvkm_gsp_mem_dtor(gsp, &gsp->logintr); - nvkm_gsp_mem_dtor(gsp, &gsp->logrm); + nvkm_gsp_mem_dtor(&gsp->shm.mem); + nvkm_gsp_mem_dtor(&gsp->loginit); + nvkm_gsp_mem_dtor(&gsp->logintr); + nvkm_gsp_mem_dtor(&gsp->logrm); } int -- 2.34.1
Danilo Krummrich
2024-Feb-27 14:23 UTC
[PATCH] drm/nouveau: retain device pointer in nvkm_gsp_mem object
Hi Timur, On 2/26/24 22:04, Timur Tabi wrote:> Store the struct device pointer used to allocate the DMA buffer in > the nvkm_gsp_mem object. This allows nvkm_gsp_mem_dtor() to release > the buffer without needing the nvkm_gsp. This is needed so that > we can retain DMA buffers even after the nvkm_gsp object is deleted.Considering "[v4][RFC] drm/nouveau: expose GSP-RM logging buffers via debugfs", I don't see where this one is needed. Do I miss anything? - Danilo> > Signed-off-by: Timur Tabi <ttabi at nvidia.com> > --- > .../gpu/drm/nouveau/include/nvkm/subdev/gsp.h | 1 + > .../gpu/drm/nouveau/nvkm/subdev/gsp/r535.c | 30 ++++++++++--------- > 2 files changed, 17 insertions(+), 14 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h > index 3fbc57b16a05..a9be0d86e412 100644 > --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h > +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h > @@ -9,6 +9,7 @@ > #define GSP_PAGE_SIZE BIT(GSP_PAGE_SHIFT) > > struct nvkm_gsp_mem { > + struct device *dev; > size_t size; > void *data; > dma_addr_t addr; > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c > index 40757a21e150..1eb1bc5df39a 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c > @@ -1000,7 +1000,7 @@ r535_gsp_rpc_get_gsp_static_info(struct nvkm_gsp *gsp) > } > > static void > -nvkm_gsp_mem_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_mem *mem) > +nvkm_gsp_mem_dtor(struct nvkm_gsp_mem *mem) > { > if (mem->data) { > /* > @@ -1009,7 +1009,7 @@ nvkm_gsp_mem_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_mem *mem) > */ > memset(mem->data, 0xFF, mem->size); > > - dma_free_coherent(gsp->subdev.device->dev, mem->size, mem->data, mem->addr); > + dma_free_coherent(mem->dev, mem->size, mem->data, mem->addr); > memset(mem, 0, sizeof(*mem)); > } > } > @@ -1017,11 +1017,13 @@ nvkm_gsp_mem_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_mem *mem) > static int > nvkm_gsp_mem_ctor(struct nvkm_gsp *gsp, size_t size, struct nvkm_gsp_mem *mem) > { > - mem->size = size; > mem->data = dma_alloc_coherent(gsp->subdev.device->dev, size, &mem->addr, GFP_KERNEL); > if (WARN_ON(!mem->data)) > return -ENOMEM; > > + mem->size = size; > + mem->dev = gsp->subdev.device->dev; > + > return 0; > } > > @@ -1054,10 +1056,10 @@ r535_gsp_postinit(struct nvkm_gsp *gsp) > nvkm_wr32(device, 0x110004, 0x00000040); > > /* Release the DMA buffers that were needed only for boot and init */ > - nvkm_gsp_mem_dtor(gsp, &gsp->boot.fw); > - nvkm_gsp_mem_dtor(gsp, &gsp->libos); > - nvkm_gsp_mem_dtor(gsp, &gsp->rmargs); > - nvkm_gsp_mem_dtor(gsp, &gsp->wpr_meta); > + nvkm_gsp_mem_dtor(&gsp->boot.fw); > + nvkm_gsp_mem_dtor(&gsp->libos); > + nvkm_gsp_mem_dtor(&gsp->rmargs); > + nvkm_gsp_mem_dtor(&gsp->wpr_meta); > > return ret; > } > @@ -2249,7 +2251,7 @@ static void > nvkm_gsp_radix3_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_radix3 *rx3) > { > for (int i = ARRAY_SIZE(rx3->mem) - 1; i >= 0; i--) > - nvkm_gsp_mem_dtor(gsp, &rx3->mem[i]); > + nvkm_gsp_mem_dtor(&rx3->mem[i]); > } > > /** > @@ -2407,7 +2409,7 @@ r535_gsp_init(struct nvkm_gsp *gsp) > > done: > if (gsp->sr.meta.data) { > - nvkm_gsp_mem_dtor(gsp, &gsp->sr.meta); > + nvkm_gsp_mem_dtor(&gsp->sr.meta); > nvkm_gsp_radix3_dtor(gsp, &gsp->sr.radix3); > nvkm_gsp_sg_free(gsp->subdev.device, &gsp->sr.sgt); > return ret; > @@ -2488,7 +2490,7 @@ r535_gsp_dtor(struct nvkm_gsp *gsp) > mutex_destroy(&gsp->client_id.mutex); > > nvkm_gsp_radix3_dtor(gsp, &gsp->radix3); > - nvkm_gsp_mem_dtor(gsp, &gsp->sig); > + nvkm_gsp_mem_dtor(&gsp->sig); > nvkm_firmware_dtor(&gsp->fw); > > nvkm_falcon_fw_dtor(&gsp->booter.unload); > @@ -2499,10 +2501,10 @@ r535_gsp_dtor(struct nvkm_gsp *gsp) > > r535_gsp_dtor_fws(gsp); > > - nvkm_gsp_mem_dtor(gsp, &gsp->shm.mem); > - nvkm_gsp_mem_dtor(gsp, &gsp->loginit); > - nvkm_gsp_mem_dtor(gsp, &gsp->logintr); > - nvkm_gsp_mem_dtor(gsp, &gsp->logrm); > + nvkm_gsp_mem_dtor(&gsp->shm.mem); > + nvkm_gsp_mem_dtor(&gsp->loginit); > + nvkm_gsp_mem_dtor(&gsp->logintr); > + nvkm_gsp_mem_dtor(&gsp->logrm); > } > > int