From 708a3802824358c1770d5ad0b3c2e24fae114eb8 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Rasmusson Date: Mon, 5 Oct 2026 12:25:05 -0400 Subject: vgsp: per-mdev emulated VRAM size (1.0 multiple mediate sizes) - nv_vgpu_type_info/ioctl gain vram_mb; nv_vgpu_device gains fb_emul_size bound from the mdev type at create (default 512 MiB). - New nvidia-vgpu-turing-1g type (1024 MiB); turing max_instances 1 -> 2; show_description reports the per-type framebuffer and max_instance. - Thread fb_emul_size through GSCI fb_length/region/frtsOffset, WPR2, NV_PFB_PRI_MMU_LOCAL_MEMORY_RANGE, the vidmem allocator bound and the BAR1 shadow; bar_info callback uses the per-device size. - UNTESTED at commit time: builds clean; validation blocked by the Xid 140 incident (reboot pending). See Handoff-vGPU-IO.md ADDENDUM 48. --- kernel/bar_emulation.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'kernel/bar_emulation.c') diff --git a/kernel/bar_emulation.c b/kernel/bar_emulation.c index e095d8b..8e3f8cf 100644 --- a/kernel/bar_emulation.c +++ b/kernel/bar_emulation.c @@ -279,7 +279,25 @@ int nv_vgpu_bar_emul_init(struct nv_vgpu_device *vgpu) * "WPR2 initialized at an unexpected location". Must stay in * lockstep with GSCI fb_length/frtsOffset and wpr2_addr_lo. */ - *(u32 *)((u8 *)ctx->bar0_shadow + 0x100ce0) = 0x00000019; + { + /* + * Derive the encoding from the mdev's emulated FB size: + * fbSize = MAG << (SCALE + 20), SCALE bits 3:0, MAG bits 9:4. + * 512 MiB -> mag=1 scale=9 -> 0x19 (the historical value); + * 1 GiB -> 0x1a; 2 GiB -> 0x1b. Sizes that are not exactly + * representable round down; the emulation keeps GSCI + * fb_length/frtsOffset derived from the same value, so the + * guest's fbSize - reserved arithmetic stays consistent. + */ + u64 fb = nv_vgpu_fb_emul_size(ctx->vgpu); + u32 scale = 0; + + while (scale < 15 && (fb >> (scale + 20)) > 0x3f) + scale++; + *(u32 *)((u8 *)ctx->bar0_shadow + 0x100ce0) = + ((((u32)(fb >> (scale + 20))) & 0x3f) << 4) | + (scale & 0xf); + } /* * NV_PCFG (BAR0+0x88000) - PCI config space mirror the driver reads -- cgit v1.2.3