On Fri, Nov 22, 2024 at 04:57:05AM -0800, Zhi Wang wrote: > To support the per-SKU GSP WPR2 heap initialization, first, factor out the > common routine for all the SKUs. > > Factor out nvkm_gsp_init_fw_heap(). Adjust some indent to make > checkpatch.pl happy. > > No functional change is intended. > > Cc: Milos Tijanic <mtijanic@xxxxxxxxxx> > Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx> > --- > .../gpu/drm/nouveau/nvkm/subdev/gsp/priv.h | 1 + > .../gpu/drm/nouveau/nvkm/subdev/gsp/r535.c | 69 +++++++++++-------- > 2 files changed, 40 insertions(+), 30 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/priv.h b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/priv.h > index 9f4a62375a27..579d83048164 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/priv.h > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/priv.h > @@ -58,6 +58,7 @@ int ga102_gsp_booter_ctor(struct nvkm_gsp *, const char *, const struct firmware > int ga102_gsp_reset(struct nvkm_gsp *); > > void r535_gsp_dtor(struct nvkm_gsp *); > +void nvkm_gsp_init_fw_heap(struct nvkm_gsp *gsp); > int r535_gsp_oneinit(struct nvkm_gsp *); > int r535_gsp_init(struct nvkm_gsp *); > int r535_gsp_fini(struct nvkm_gsp *, bool suspend); > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c > index cf58f9da9139..6f2319845322 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c > @@ -2517,6 +2517,44 @@ r535_gsp_dtor(struct nvkm_gsp *gsp) > nvkm_gsp_mem_dtor(gsp, &gsp->logrm); > } > > +void nvkm_gsp_init_fw_heap(struct nvkm_gsp *gsp) Is this really independent from the GSP version? Otherwise this should start with r535. > +{ > + /* Calculate FB layout. */ > + gsp->fb.wpr2.frts.size = 0x100000; > + gsp->fb.wpr2.frts.addr = ALIGN_DOWN(gsp->fb.bios.addr, 0x20000) - gsp->fb.wpr2.frts.size; > + > + gsp->fb.wpr2.boot.size = gsp->boot.fw.size; > + gsp->fb.wpr2.boot.addr = ALIGN_DOWN(gsp->fb.wpr2.frts.addr - gsp->fb.wpr2.boot.size, > + 0x1000); > + > + gsp->fb.wpr2.elf.size = gsp->fw.len; > + gsp->fb.wpr2.elf.addr = ALIGN_DOWN(gsp->fb.wpr2.boot.addr - gsp->fb.wpr2.elf.size, > + 0x10000); > + > + { > + u32 fb_size_gb = DIV_ROUND_UP_ULL(gsp->fb.size, 1 << 30); > + > + gsp->fb.wpr2.heap.size = > + gsp->func->wpr_heap.os_carveout_size + > + gsp->func->wpr_heap.base_size + > + ALIGN(GSP_FW_HEAP_PARAM_SIZE_PER_GB_FB * fb_size_gb, 1 << 20) + > + ALIGN(GSP_FW_HEAP_PARAM_CLIENT_ALLOC_SIZE, 1 << 20); > + > + gsp->fb.wpr2.heap.size = max(gsp->fb.wpr2.heap.size, gsp->func->wpr_heap.min_size); > + } > + > + gsp->fb.wpr2.heap.addr = ALIGN_DOWN(gsp->fb.wpr2.elf.addr - gsp->fb.wpr2.heap.size, > + 0x100000); > + gsp->fb.wpr2.heap.size = ALIGN_DOWN(gsp->fb.wpr2.elf.addr - gsp->fb.wpr2.heap.addr, > + 0x100000); > + > + gsp->fb.wpr2.addr = ALIGN_DOWN(gsp->fb.wpr2.heap.addr - sizeof(GspFwWprMeta), 0x100000); > + gsp->fb.wpr2.size = gsp->fb.wpr2.frts.addr + gsp->fb.wpr2.frts.size - gsp->fb.wpr2.addr; > + > + gsp->fb.heap.size = 0x100000; > + gsp->fb.heap.addr = gsp->fb.wpr2.addr - gsp->fb.heap.size; > +} > + > int > r535_gsp_oneinit(struct nvkm_gsp *gsp) > { > @@ -2581,36 +2619,7 @@ r535_gsp_oneinit(struct nvkm_gsp *gsp) > /* Release FW images - we've copied them to DMA buffers now. */ > r535_gsp_dtor_fws(gsp); > > - /* Calculate FB layout. */ > - gsp->fb.wpr2.frts.size = 0x100000; > - gsp->fb.wpr2.frts.addr = ALIGN_DOWN(gsp->fb.bios.addr, 0x20000) - gsp->fb.wpr2.frts.size; > - > - gsp->fb.wpr2.boot.size = gsp->boot.fw.size; > - gsp->fb.wpr2.boot.addr = ALIGN_DOWN(gsp->fb.wpr2.frts.addr - gsp->fb.wpr2.boot.size, 0x1000); > - > - gsp->fb.wpr2.elf.size = gsp->fw.len; > - gsp->fb.wpr2.elf.addr = ALIGN_DOWN(gsp->fb.wpr2.boot.addr - gsp->fb.wpr2.elf.size, 0x10000); > - > - { > - u32 fb_size_gb = DIV_ROUND_UP_ULL(gsp->fb.size, 1 << 30); > - > - gsp->fb.wpr2.heap.size = > - gsp->func->wpr_heap.os_carveout_size + > - gsp->func->wpr_heap.base_size + > - ALIGN(GSP_FW_HEAP_PARAM_SIZE_PER_GB_FB * fb_size_gb, 1 << 20) + > - ALIGN(GSP_FW_HEAP_PARAM_CLIENT_ALLOC_SIZE, 1 << 20); > - > - gsp->fb.wpr2.heap.size = max(gsp->fb.wpr2.heap.size, gsp->func->wpr_heap.min_size); > - } > - > - gsp->fb.wpr2.heap.addr = ALIGN_DOWN(gsp->fb.wpr2.elf.addr - gsp->fb.wpr2.heap.size, 0x100000); > - gsp->fb.wpr2.heap.size = ALIGN_DOWN(gsp->fb.wpr2.elf.addr - gsp->fb.wpr2.heap.addr, 0x100000); > - > - gsp->fb.wpr2.addr = ALIGN_DOWN(gsp->fb.wpr2.heap.addr - sizeof(GspFwWprMeta), 0x100000); > - gsp->fb.wpr2.size = gsp->fb.wpr2.frts.addr + gsp->fb.wpr2.frts.size - gsp->fb.wpr2.addr; > - > - gsp->fb.heap.size = 0x100000; > - gsp->fb.heap.addr = gsp->fb.wpr2.addr - gsp->fb.heap.size; > + nvkm_gsp_init_fw_heap(gsp); > > ret = nvkm_gsp_fwsec_frts(gsp); > if (WARN_ON(ret)) > -- > 2.34.1 >