From: Thierry Reding <thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Ben Skeggs <bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH 4/6] drm/nouveau: Implement nvkm_memory_aperture()
Date: Mon, 16 Sep 2019 17:17:55 +0200 [thread overview]
Message-ID: <20190916151757.10953-5-thierry.reding@gmail.com> (raw)
In-Reply-To: <20190916151757.10953-1-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
From: Thierry Reding <treding@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@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
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau
next prev parent reply other threads:[~2019-09-16 15:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-16 15:17 [PATCH 0/6] drm/nouveau: Preparatory work for GV11B support Thierry Reding
[not found] ` <20190916151757.10953-1-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-09-16 15:17 ` [PATCH 1/6] drm/nouveau: fault: Store aperture in fault information Thierry Reding
[not found] ` <20190916151757.10953-2-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-09-17 3:47 ` Ben Skeggs
[not found] ` <CACAvsv70b1-LJoaP1ZL2hvy9xMcO1WXqh0ibGzNfpB81ybgrTg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-17 9:05 ` Thierry Reding
2019-09-16 15:17 ` [PATCH 2/6] drm/nouveau: fault: Widen engine field Thierry Reding
[not found] ` <20190916151757.10953-3-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-09-17 3:48 ` Ben Skeggs
2019-09-17 9:05 ` [Nouveau] " Thierry Reding
2019-09-16 15:17 ` [PATCH 3/6] drm/nouveau: Remove bogus gk20a aperture callback Thierry Reding
2019-09-17 3:43 ` [Nouveau] " Ben Skeggs
[not found] ` <CACAvsv6AzWvpPLaOKahpJErTAMCJet4_4mBvRC8Z+e4+bwaD4w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-09-17 9:02 ` Thierry Reding
2019-09-20 15:55 ` [Nouveau] " Thierry Reding
2019-09-16 15:17 ` Thierry Reding [this message]
2019-09-16 15:17 ` [PATCH 5/6] drm/nouveau: Remove unused nvkm_vmm_func->aper() implementations Thierry Reding
2019-09-16 15:17 ` [PATCH 6/6] drm/nouveau: Program aperture field where necessary Thierry Reding
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190916151757.10953-5-thierry.reding@gmail.com \
--to=thierry.reding-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox