[PATCH 2/3] drm/nouveau/bar: take the GSP-RM flush pointer from the BAR2 io_mapping
From: Mohamed Ahmed
Date: Tue Nov 17 2026 - 16:44:44 EST
r535_bar_new_() maps the first page of BAR2 with ioremap(), to flush
BAR2 writes with a read while flushFBZero is not mapped. On x86 with
PAT, a mapping that overlaps an existing one gets its type. The instmem
io_mapping is created later, so with GSP-RM it is also mapped UC- and
its writes are not write-combined.
Take the flush pointer from the io_mapping. A new bar2.oneinit hook
sets it up once the BAR2 page tables are bootstrapped and the
io_mapping exists.
Fixes: 34e27b90552a ("nouveau/instmem: use iomapping interface for instmem handling")
Signed-off-by: Mohamed Ahmed <mohamedahmedegypt2001@xxxxxxxxx>
Tested-by: Thomas Andersen <phomes@xxxxxxxxx>
---
.../gpu/drm/nouveau/nvkm/subdev/bar/gf100.c | 6 ++++
.../gpu/drm/nouveau/nvkm/subdev/bar/priv.h | 1 +
.../drm/nouveau/nvkm/subdev/gsp/rm/r535/bar.c | 32 ++++++++++++++-----
.../drm/nouveau/nvkm/subdev/instmem/nv50.c | 8 +++++
.../drm/nouveau/nvkm/subdev/instmem/priv.h | 3 ++
5 files changed, 42 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bar/gf100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/bar/gf100.c
index a1fa1b0c8954..6950801d2e03 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/bar/gf100.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bar/gf100.c
@@ -133,6 +133,12 @@ gf100_bar_oneinit(struct nvkm_bar *base)
if (ret)
return ret;
+ if (bar->base.func->bar2.oneinit) {
+ ret = bar->base.func->bar2.oneinit(&bar->base);
+ if (ret)
+ return ret;
+ }
+
bar->base.subdev.oneinit = true;
nvkm_bar_bar2_init(bar->base.subdev.device);
}
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/bar/priv.h b/drivers/gpu/drm/nouveau/nvkm/subdev/bar/priv.h
index d0168e0b78fb..5774bfa8d96d 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/bar/priv.h
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/bar/priv.h
@@ -16,6 +16,7 @@ struct nvkm_bar_func {
void (*init)(struct nvkm_bar *);
struct {
+ int (*oneinit)(struct nvkm_bar *);
void (*init)(struct nvkm_bar *);
void (*fini)(struct nvkm_bar *);
void (*wait)(struct nvkm_bar *);
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/bar.c b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/bar.c
index fae08ac3b18c..9b907d9e80af 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/bar.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/bar.c
@@ -24,9 +24,11 @@
#include <core/mm.h>
#include <subdev/fb.h>
#include <subdev/gsp.h>
-#include <subdev/instmem.h>
+#include <subdev/instmem/priv.h>
#include <subdev/mmu/vmm.h>
+#include <linux/io-mapping.h>
+
#include "nvrm/bar.h"
#include "nvrm/rpcfn.h"
@@ -65,6 +67,25 @@ r535_bar_bar2_update_pde(struct nvkm_gsp *gsp, u8 page_shift, u64 pdbe)
return nvkm_gsp_rpc_wr(gsp, rpc, NVKM_GSP_RPC_REPLY_RECV);
}
+static int
+r535_bar_bar2_oneinit(struct nvkm_bar *bar)
+{
+ struct io_mapping *iomap = nv50_instmem_bar2_iomap(bar->subdev.device->imem);
+
+ if (!iomap)
+ return -ENOMEM;
+
+ /* BAR2 writes are flushed by a read. While flushFBZero is not mapped,
+ * read the first page of the BAR2 io_mapping.
+ */
+ bar->flushBAR2PhysMode = io_mapping_map_wc(iomap, 0, PAGE_SIZE);
+ if (!bar->flushBAR2PhysMode)
+ return -ENOMEM;
+
+ bar->flushBAR2 = bar->flushBAR2PhysMode;
+ return 0;
+}
+
static void
r535_bar_bar2_fini(struct nvkm_bar *bar)
{
@@ -155,7 +176,7 @@ r535_bar_dtor(struct nvkm_bar *bar)
nvkm_memory_unref(&bar->flushFBZero);
if (bar->flushBAR2PhysMode)
- iounmap(bar->flushBAR2PhysMode);
+ io_mapping_unmap(bar->flushBAR2PhysMode);
kfree(bar->func);
return data;
@@ -178,6 +199,7 @@ r535_bar_new_(const struct nvkm_bar_func *hw, struct nvkm_device *device,
rm->bar1.fini = r535_bar_bar1_fini;
rm->bar1.wait = r535_bar_bar1_wait;
rm->bar1.vmm = hw->bar1.vmm;
+ rm->bar2.oneinit = r535_bar_bar2_oneinit;
rm->bar2.init = r535_bar_bar2_init;
rm->bar2.fini = r535_bar_bar2_fini;
rm->bar2.wait = r535_bar_bar2_wait;
@@ -191,12 +213,6 @@ r535_bar_new_(const struct nvkm_bar_func *hw, struct nvkm_device *device,
}
*pbar = bar;
- bar->flushBAR2PhysMode = ioremap(device->func->resource_addr(device, NVKM_BAR2_INST), PAGE_SIZE);
- if (!bar->flushBAR2PhysMode)
- return -ENOMEM;
-
- bar->flushBAR2 = bar->flushBAR2PhysMode;
-
gf100_bar(*pbar)->bar2_halve = true;
return 0;
}
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/nv50.c b/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/nv50.c
index 22b0fde6ba34..1b4be4b1f0bb 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/nv50.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/nv50.c
@@ -436,6 +436,14 @@ nv50_instmem_dtor(struct nvkm_instmem *base)
return imem;
}
+struct io_mapping *
+nv50_instmem_bar2_iomap(struct nvkm_instmem *base)
+{
+ struct nv50_instmem *imem = nv50_instmem(base);
+
+ return imem->iomap.size ? &imem->iomap : NULL;
+}
+
static const struct nvkm_instmem_func
nv50_instmem = {
.dtor = nv50_instmem_dtor,
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/priv.h b/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/priv.h
index b423f01f5fcd..88990adda766 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/priv.h
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/priv.h
@@ -4,6 +4,8 @@
#define nvkm_instmem(p) container_of((p), struct nvkm_instmem, subdev)
#include <subdev/instmem.h>
+struct io_mapping;
+
struct nvkm_instmem_func {
void *(*dtor)(struct nvkm_instmem *);
int (*oneinit)(struct nvkm_instmem *);
@@ -27,6 +29,7 @@ int nv50_instobj_new(struct nvkm_instmem *, u32 size, u32 align, bool zero,
int nv50_instobj_wrap(struct nvkm_instmem *, struct nvkm_memory *vram,
struct nvkm_memory **bar2);
void *nv50_instmem_dtor(struct nvkm_instmem *base);
+struct io_mapping *nv50_instmem_bar2_iomap(struct nvkm_instmem *base);
void nvkm_instmem_ctor(const struct nvkm_instmem_func *, struct nvkm_device *,
enum nvkm_subdev_type, int, struct nvkm_instmem *);
--
2.56.1