[PATCH 4/6] drm/nouveau: Implement nvkm_memory_aperture()
Thierry Reding
thierry.reding at gmail.com
Mon Sep 16 15:17:55 UTC 2019
From: Thierry Reding <treding at nvidia.com>
The aperture of a buffer is always specific to where its memory was
allocated from. Furthermore, the encoding of the aperture is always
the same, regardless of GPU generation.
Implement the memory target to aperture conversion in one central
place and make the aperture independent of the VMM.
Note that we no longer return a negative error code for unsupported
apertures. First, this should never happen to begin with and is a
programming error, which is why we have a WARN already. Second, the
standard aperture (0, VRAM) should be correct for the vast majority
of memory objects. Lastly, the aperture also needs to be programmed
into many registers and instance blocks. Having to check for error
codes at every step of the way would make this very unwieldy. If in
any case there is ever a problem with the aperture being wrong, let
us rely on the WARN to tell us about it.
Signed-off-by: Thierry Reding <treding at nvidia.com>
---
.../drm/nouveau/include/nvkm/core/memory.h | 28 +++++++++++++++++++
.../drm/nouveau/nvkm/subdev/mmu/vmmgf100.c | 7 ++---
.../drm/nouveau/nvkm/subdev/mmu/vmmgp100.c | 7 ++---
3 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/include/nvkm/core/memory.h b/drivers/gpu/drm/nouveau/include/nvkm/core/memory.h
index b23bf6109f2d..29c60fbed167 100644
--- a/drivers/gpu/drm/nouveau/include/nvkm/core/memory.h
+++ b/drivers/gpu/drm/nouveau/include/nvkm/core/memory.h
@@ -64,6 +64,34 @@ void nvkm_memory_tags_put(struct nvkm_memory *, struct nvkm_device *,
#define nvkm_memory_map(p,o,vm,va,av,ac) \
(p)->func->map((p),(o),(vm),(va),(av),(ac))
+static inline u32
+nvkm_memory_aperture(struct nvkm_memory *mem)
+{
+ enum nvkm_memory_target target = nvkm_memory_target(mem);
+
+ switch (target) {
+ case NVKM_MEM_TARGET_VRAM:
+ return 0;
+
+ case NVKM_MEM_TARGET_HOST:
+ return 2;
+
+ case NVKM_MEM_TARGET_NCOH:
+ return 3;
+
+ default:
+ break;
+ }
+
+ /*
+ * This is invalid, so warn about this loudly. However, return 0 to
+ * avoid writing garbage into registers. 0 is the VRAM aperture and
+ * might still work in most cases.
+ */
+ WARN(1, "invalid memory target: %d\n", target);
+ return 0;
+}
+
/* accessor macros - kmap()/done() must bracket use of the other accessor
* macros to guarantee correct behaviour across all chipsets
*/
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgf100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgf100.c
index ab6424faf84c..ffa64c0d3eda 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgf100.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgf100.c
@@ -248,8 +248,9 @@ gf100_vmm_valid(struct nvkm_vmm *vmm, void *argv, u32 argc,
struct nvkm_device *device = vmm->mmu->subdev.device;
struct nvkm_memory *memory = map->memory;
u8 kind, priv, ro, vol;
- int kindn, aper, ret = -ENOSYS;
+ int kindn, ret = -ENOSYS;
const u8 *kindm;
+ u32 aper;
map->next = (1 << page->shift) >> 8;
map->type = map->ctag = 0;
@@ -270,9 +271,7 @@ gf100_vmm_valid(struct nvkm_vmm *vmm, void *argv, u32 argc,
return ret;
}
- aper = vmm->func->aper(target);
- if (WARN_ON(aper < 0))
- return aper;
+ aper = nvkm_memory_aperture(map->memory);
kindm = vmm->mmu->func->kind(vmm->mmu, &kindn);
if (kind >= kindn || kindm[kind] == 0xff) {
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgp100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgp100.c
index b4f519768d5e..4a1a658328e5 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgp100.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmgp100.c
@@ -321,8 +321,9 @@ gp100_vmm_valid(struct nvkm_vmm *vmm, void *argv, u32 argc,
struct nvkm_device *device = vmm->mmu->subdev.device;
struct nvkm_memory *memory = map->memory;
u8 kind, priv, ro, vol;
- int kindn, aper, ret = -ENOSYS;
+ int kindn, ret = -ENOSYS;
const u8 *kindm;
+ u32 aper;
map->next = (1ULL << page->shift) >> 4;
map->type = 0;
@@ -343,9 +344,7 @@ gp100_vmm_valid(struct nvkm_vmm *vmm, void *argv, u32 argc,
return ret;
}
- aper = vmm->func->aper(target);
- if (WARN_ON(aper < 0))
- return aper;
+ aper = nvkm_memory_aperture(map->memory);
kindm = vmm->mmu->func->kind(vmm->mmu, &kindn);
if (kind >= kindn || kindm[kind] == 0xff) {
--
2.23.0
More information about the dri-devel
mailing list