On Thu, May 25, 2023 at 2:31 AM Ben Skeggs <skeggsb@xxxxxxxxx> wrote: > > From: Ben Skeggs <bskeggs@xxxxxxxxxx> > > Also exposes this for use by upcoming GSP-RM initialisation code. > > Signed-off-by: Ben Skeggs <bskeggs@xxxxxxxxxx> > --- > .../gpu/drm/nouveau/include/nvkm/subdev/fb.h | 1 + > drivers/gpu/drm/nouveau/nvkm/subdev/fb/Kbuild | 1 + > drivers/gpu/drm/nouveau/nvkm/subdev/fb/base.c | 12 +++++ > .../gpu/drm/nouveau/nvkm/subdev/fb/ga100.c | 3 +- > .../gpu/drm/nouveau/nvkm/subdev/fb/gp102.c | 17 ++++++- > .../gpu/drm/nouveau/nvkm/subdev/fb/gv100.c | 3 +- > drivers/gpu/drm/nouveau/nvkm/subdev/fb/priv.h | 5 ++ > drivers/gpu/drm/nouveau/nvkm/subdev/fb/ram.h | 1 + > .../gpu/drm/nouveau/nvkm/subdev/fb/ramgp102.c | 50 +++++++++++++++++++ > .../gpu/drm/nouveau/nvkm/subdev/fb/tu102.c | 3 +- > 10 files changed, 92 insertions(+), 4 deletions(-) > create mode 100644 drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgp102.c > > diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/fb.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/fb.h > index 01a22a13b452..1755b0df3cc1 100644 > --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/fb.h > +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/fb.h > @@ -59,6 +59,7 @@ struct nvkm_fb { > struct nvkm_memory *mmu_wr; > }; > > +u64 nvkm_fb_vidmem_size(struct nvkm_device *); > int nvkm_fb_mem_unlock(struct nvkm_fb *); > > void nvkm_fb_tile_init(struct nvkm_fb *, int region, u32 addr, u32 size, > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/Kbuild b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/Kbuild > index 6ba5120a2ebe..11dbfc4a381a 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/Kbuild > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/Kbuild > @@ -55,6 +55,7 @@ nvkm-y += nvkm/subdev/fb/ramgk104.o > nvkm-y += nvkm/subdev/fb/ramgm107.o > nvkm-y += nvkm/subdev/fb/ramgm200.o > nvkm-y += nvkm/subdev/fb/ramgp100.o > +nvkm-y += nvkm/subdev/fb/ramgp102.o > nvkm-y += nvkm/subdev/fb/ramga102.o > nvkm-y += nvkm/subdev/fb/sddr2.o > nvkm-y += nvkm/subdev/fb/sddr3.o > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/base.c > index 0955340cc421..8a286a9349ac 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/base.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/base.c > @@ -174,6 +174,18 @@ nvkm_fb_mem_unlock(struct nvkm_fb *fb) > return 0; > } > > +u64 > +nvkm_fb_vidmem_size(struct nvkm_device *device) > +{ > + struct nvkm_fb *fb = device->fb; > + > + if (fb && fb->func->vidmem.size) > + return fb->func->vidmem.size(fb); > + > + WARN_ON(1); > + return 0; > +} > + > static int > nvkm_fb_init(struct nvkm_subdev *subdev) > { > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ga100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ga100.c > index a7456e786463..12037fd4fdf2 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ga100.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ga100.c > @@ -30,7 +30,8 @@ ga100_fb = { > .init_page = gv100_fb_init_page, > .init_unkn = gp100_fb_init_unkn, > .sysmem.flush_page_init = gf100_fb_sysmem_flush_page_init, > - .ram_new = gp100_ram_new, > + .vidmem.size = gp102_fb_vidmem_size, > + .ram_new = gp102_ram_new, > .default_bigpage = 16, > }; > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gp102.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gp102.c > index 14d942e8b857..534553c64805 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gp102.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gp102.c > @@ -40,6 +40,20 @@ gp102_fb_vpr_scrub_required(struct nvkm_fb *fb) > return (nvkm_rd32(device, 0x100cd0) & 0x00000010) != 0; > } > > +u64 > +gp102_fb_vidmem_size(struct nvkm_fb *fb) > +{ > + const u32 data = nvkm_rd32(fb->subdev.device, 0x100ce0); Do we have any kind of documentation for this register? > + const u32 lmag = (data & 0x000003f0) >> 4; > + const u32 lsca = (data & 0x0000000f); > + const u64 size = (u64)lmag << (lsca + 20); > + > + if (data & 0x40000000) > + return size / 16 * 15; > + > + return size; > +} > + > int > gp102_fb_oneinit(struct nvkm_fb *fb) > { > @@ -59,9 +73,10 @@ gp102_fb = { > .init_remapper = gp100_fb_init_remapper, > .init_page = gm200_fb_init_page, > .sysmem.flush_page_init = gf100_fb_sysmem_flush_page_init, > + .vidmem.size = gp102_fb_vidmem_size, > .vpr.scrub_required = gp102_fb_vpr_scrub_required, > .vpr.scrub = gp102_fb_vpr_scrub, > - .ram_new = gp100_ram_new, > + .ram_new = gp102_ram_new, > }; > > int > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gv100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gv100.c > index 4d8a286a7a34..f422564bee5b 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gv100.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/gv100.c > @@ -36,9 +36,10 @@ gv100_fb = { > .init_page = gv100_fb_init_page, > .init_unkn = gp100_fb_init_unkn, > .sysmem.flush_page_init = gf100_fb_sysmem_flush_page_init, > + .vidmem.size = gp102_fb_vidmem_size, > .vpr.scrub_required = gp102_fb_vpr_scrub_required, > .vpr.scrub = gp102_fb_vpr_scrub, > - .ram_new = gp100_ram_new, > + .ram_new = gp102_ram_new, > .default_bigpage = 16, > }; > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/priv.h b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/priv.h > index 726c30c8bf95..77d6a8c10829 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/priv.h > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/priv.h > @@ -20,6 +20,10 @@ struct nvkm_fb_func { > void (*flush_page_init)(struct nvkm_fb *); > } sysmem; > > + struct nvkm_fb_func_vidmem { > + u64 (*size)(struct nvkm_fb *); > + } vidmem; > + > struct { > bool (*scrub_required)(struct nvkm_fb *); > int (*scrub)(struct nvkm_fb *); > @@ -84,6 +88,7 @@ void gp100_fb_init_remapper(struct nvkm_fb *); > void gp100_fb_init_unkn(struct nvkm_fb *); > > int gp102_fb_oneinit(struct nvkm_fb *); > +u64 gp102_fb_vidmem_size(struct nvkm_fb *); > bool gp102_fb_vpr_scrub_required(struct nvkm_fb *); > int gp102_fb_vpr_scrub(struct nvkm_fb *); > > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ram.h b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ram.h > index ea7d66f3dd82..33d4ab8d92e6 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ram.h > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ram.h > @@ -70,5 +70,6 @@ int gk104_ram_new(struct nvkm_fb *, struct nvkm_ram **); > int gm107_ram_new(struct nvkm_fb *, struct nvkm_ram **); > int gm200_ram_new(struct nvkm_fb *, struct nvkm_ram **); > int gp100_ram_new(struct nvkm_fb *, struct nvkm_ram **); > +int gp102_ram_new(struct nvkm_fb *, struct nvkm_ram **); > int ga102_ram_new(struct nvkm_fb *, struct nvkm_ram **); > #endif > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgp102.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgp102.c > new file mode 100644 > index 000000000000..ee541b049fc5 > --- /dev/null > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramgp102.c > @@ -0,0 +1,50 @@ > +/* > + * Copyright 2023 Red Hat Inc. > + * > + * Permission is hereby granted, free of charge, to any person obtaining a > + * copy of this software and associated documentation files (the "Software"), > + * to deal in the Software without restriction, including without limitation > + * the rights to use, copy, modify, merge, publish, distribute, sublicense, > + * and/or sell copies of the Software, and to permit persons to whom the > + * Software is furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR > + * OTHER DEALINGS IN THE SOFTWARE. > + */ > +#include "ram.h" > + > +#include <subdev/bios.h> > + > +static const struct nvkm_ram_func > +gp102_ram = { > +}; > + > +int > +gp102_ram_new(struct nvkm_fb *fb, struct nvkm_ram **pram) > +{ > + enum nvkm_ram_type type = nvkm_fb_bios_memtype(fb->subdev.device->bios); > + const u32 rsvd_head = ( 256 * 1024); /* vga memory */ > + const u32 rsvd_tail = (1024 * 1024); /* vbios etc */ > + u64 size = fb->func->vidmem.size(fb); > + int ret; > + > + ret = nvkm_ram_new_(&gp102_ram, fb, type, size, pram); > + if (ret) > + return ret; > + > + nvkm_mm_fini(&(*pram)->vram); > + > + return nvkm_mm_init(&(*pram)->vram, NVKM_RAM_MM_NORMAL, > + rsvd_head >> NVKM_RAM_MM_SHIFT, > + (size - rsvd_head - rsvd_tail) >> NVKM_RAM_MM_SHIFT, > + 1); > + > +} > diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/tu102.c b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/tu102.c > index b8803c124c3b..bcc23d4c8115 100644 > --- a/drivers/gpu/drm/nouveau/nvkm/subdev/fb/tu102.c > +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/fb/tu102.c > @@ -36,9 +36,10 @@ tu102_fb = { > .init_page = gv100_fb_init_page, > .init_unkn = gp100_fb_init_unkn, > .sysmem.flush_page_init = gf100_fb_sysmem_flush_page_init, > + .vidmem.size = gp102_fb_vidmem_size, > .vpr.scrub_required = tu102_fb_vpr_scrub_required, > .vpr.scrub = gp102_fb_vpr_scrub, > - .ram_new = gp100_ram_new, > + .ram_new = gp102_ram_new, > .default_bigpage = 16, > }; > > -- > 2.40.1 >