nouveau/instmem: use iomapping interface for instmem handling

This avoids constant need to ioremap when instobjs move at least on
64-bit systems.

This create the io mapping on first use, because creating it at init
time causes a resource mapping error, because nouveau hasn't kicked
simpledrm off the hardware yet, but ioremap_wc the whole BAR causes an
overlap with BOOTFB/simpledrm. I think the resource system could do
better here, but it's easier to just delay creating the mapping until
first use.

Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patch.msgid.link/20260706030520.857104-1-airlied@gmail.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
Dave Airlie 2026-07-06 13:05:20 +10:00 committed by Danilo Krummrich
parent a284476db2
commit 34e27b9055
3 changed files with 32 additions and 9 deletions

View File

@ -297,6 +297,7 @@ r535_fbsr = {
static void * static void *
r535_instmem_dtor(struct nvkm_instmem *imem) r535_instmem_dtor(struct nvkm_instmem *imem)
{ {
nv50_instmem_dtor(imem);
kfree(imem->func); kfree(imem->func);
return imem; return imem;
} }

View File

@ -30,10 +30,14 @@
#include <subdev/gsp.h> #include <subdev/gsp.h>
#include <subdev/mmu.h> #include <subdev/mmu.h>
#include <linux/io-mapping.h>
struct nv50_instmem { struct nv50_instmem {
struct nvkm_instmem base; struct nvkm_instmem base;
u64 addr; u64 addr;
struct io_mapping iomap;
/* Mappings that can be evicted when BAR2 space has been exhausted. */ /* Mappings that can be evicted when BAR2 space has been exhausted. */
struct list_head lru; struct list_head lru;
}; };
@ -124,7 +128,6 @@ nv50_instobj_kmap(struct nv50_instobj *iobj, struct nvkm_vmm *vmm)
struct nv50_instobj *eobj; struct nv50_instobj *eobj;
struct nvkm_memory *memory = &iobj->base.memory; struct nvkm_memory *memory = &iobj->base.memory;
struct nvkm_subdev *subdev = &imem->base.subdev; struct nvkm_subdev *subdev = &imem->base.subdev;
struct nvkm_device *device = subdev->device;
struct nvkm_vma *bar = NULL, *ebar; struct nvkm_vma *bar = NULL, *ebar;
u64 size = nvkm_memory_size(memory); u64 size = nvkm_memory_size(memory);
void *emap; void *emap;
@ -155,7 +158,7 @@ nv50_instobj_kmap(struct nv50_instobj *iobj, struct nvkm_vmm *vmm)
mutex_unlock(&imem->base.mutex); mutex_unlock(&imem->base.mutex);
if (!eobj) if (!eobj)
break; break;
iounmap(emap); io_mapping_unmap(emap);
nvkm_vmm_put(vmm, &ebar); nvkm_vmm_put(vmm, &ebar);
} }
@ -172,8 +175,7 @@ nv50_instobj_kmap(struct nv50_instobj *iobj, struct nvkm_vmm *vmm)
/* Make the mapping visible to the host. */ /* Make the mapping visible to the host. */
iobj->bar = bar; iobj->bar = bar;
iobj->map = ioremap_wc(device->func->resource_addr(device, NVKM_BAR2_INST) + iobj->map = io_mapping_map_wc(&imem->iomap, (u32)iobj->bar->addr, size);
(u32)iobj->bar->addr, size);
if (!iobj->map) { if (!iobj->map) {
nvkm_warn(subdev, "PRAMIN ioremap failed\n"); nvkm_warn(subdev, "PRAMIN ioremap failed\n");
nvkm_vmm_put(vmm, &iobj->bar); nvkm_vmm_put(vmm, &iobj->bar);
@ -188,6 +190,16 @@ nv50_instobj_map(struct nvkm_memory *memory, u64 offset, struct nvkm_vmm *vmm,
return nvkm_memory_map(memory, offset, vmm, vma, argv, argc); return nvkm_memory_map(memory, offset, vmm, vma, argv, argc);
} }
static bool
check_io_mapping(struct nv50_instmem *imem)
{
struct nvkm_device *device = imem->base.subdev.device;
return io_mapping_init_wc(&imem->iomap,
device->func->resource_addr(device, NVKM_BAR2_INST),
device->func->resource_size(device, NVKM_BAR2_INST)) != NULL;
}
static void static void
nv50_instobj_release(struct nvkm_memory *memory) nv50_instobj_release(struct nvkm_memory *memory)
{ {
@ -239,7 +251,7 @@ nv50_instobj_acquire(struct nvkm_memory *memory)
/* Attempt to get a direct CPU mapping of the object. */ /* Attempt to get a direct CPU mapping of the object. */
if ((vmm = nvkm_bar_bar2_vmm(imem->subdev.device))) { if ((vmm = nvkm_bar_bar2_vmm(imem->subdev.device))) {
if (!iobj->map) if (!iobj->map && iobj->imem->iomap.size)
nv50_instobj_kmap(iobj, vmm); nv50_instobj_kmap(iobj, vmm);
map = iobj->map; map = iobj->map;
} }
@ -277,7 +289,12 @@ nv50_instobj_boot(struct nvkm_memory *memory, struct nvkm_vmm *vmm)
iobj->lru.next = NULL; iobj->lru.next = NULL;
} }
nv50_instobj_kmap(iobj, vmm); /*
* boot is only called on BAR2, if we can't remap the complete
* BAR it's unlikely things are functioning well.
*/
if (check_io_mapping(iobj->imem))
nv50_instobj_kmap(iobj, vmm);
nvkm_instmem_boot(imem); nvkm_instmem_boot(imem);
mutex_unlock(&imem->mutex); mutex_unlock(&imem->mutex);
} }
@ -330,7 +347,7 @@ nv50_instobj_dtor(struct nvkm_memory *memory)
if (map) { if (map) {
struct nvkm_vmm *vmm = nvkm_bar_bar2_vmm(imem->subdev.device); struct nvkm_vmm *vmm = nvkm_bar_bar2_vmm(imem->subdev.device);
iounmap(map); io_mapping_unmap(map);
if (likely(vmm)) /* Can be NULL during BAR destructor. */ if (likely(vmm)) /* Can be NULL during BAR destructor. */
nvkm_vmm_put(vmm, &bar); nvkm_vmm_put(vmm, &bar);
} }
@ -406,10 +423,14 @@ nv50_instmem_fini(struct nvkm_instmem *base)
nv50_instmem(base)->addr = ~0ULL; nv50_instmem(base)->addr = ~0ULL;
} }
static void * void *
nv50_instmem_dtor(struct nvkm_instmem *base) nv50_instmem_dtor(struct nvkm_instmem *base)
{ {
return nv50_instmem(base); struct nv50_instmem *imem = nv50_instmem(base);
if (imem->iomap.size)
io_mapping_fini(&imem->iomap);
return imem;
} }
static const struct nvkm_instmem_func static const struct nvkm_instmem_func

View File

@ -26,6 +26,7 @@ int nv50_instobj_new(struct nvkm_instmem *, u32 size, u32 align, bool zero,
struct nvkm_memory **); struct nvkm_memory **);
int nv50_instobj_wrap(struct nvkm_instmem *, struct nvkm_memory *vram, int nv50_instobj_wrap(struct nvkm_instmem *, struct nvkm_memory *vram,
struct nvkm_memory **bar2); struct nvkm_memory **bar2);
void *nv50_instmem_dtor(struct nvkm_instmem *base);
void nvkm_instmem_ctor(const struct nvkm_instmem_func *, struct nvkm_device *, void nvkm_instmem_ctor(const struct nvkm_instmem_func *, struct nvkm_device *,
enum nvkm_subdev_type, int, struct nvkm_instmem *); enum nvkm_subdev_type, int, struct nvkm_instmem *);