Commit Graph

709162 Commits

Author SHA1 Message Date
Ben Skeggs
e9a8b21804 drm/nouveau/fb/ram: add interface to allocate vram as an nvkm_memory object
Upcoming MMU changes use nvkm_memory as its basic representation of memory,
so we need to be able to allocate VRAM like this.

The code is basically identical to the current chipset-specific allocators,
minus support for compression tags (which will be handled elsewhere anyway).

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:23 +10:00
Ben Skeggs
c09597f083 drm/nouveau/core/memory: add some useful accessor macros
Adds support for 64-bit writes, and optimised filling of buffers with
fixed 32/64-bit values.

These will all be used by the upcoming MMU changes.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:22 +10:00
Ben Skeggs
997a89003c drm/nouveau/core/memory: add reference counting
We need to be able to prevent memory from being freed while it's still
mapped in a GPU's address-space.

Will be used by upcoming MMU changes.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:22 +10:00
Ben Skeggs
2c9c4910f8 drm/nouveau/core/memory: add mechanism to retrieve allocation granularity
Needed by VMM code to determine whether an allocation is compatible with
a given page size (ie. you can't map 4KiB system memory pages into 64KiB
GPU pages).

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:22 +10:00
Ben Skeggs
19a82e492c drm/nouveau/core/memory: change map interface to support upcoming mmu changes
Map flags (access, kind, etc) are currently defined in either the VMA,
or the memory object, which turns out to not be ideal for things like
suballocated buffers, etc.

These will become per-map flags instead, so we need to support passing
these arguments in nvkm_memory_map().

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:22 +10:00
Ben Skeggs
7f53d6dc9a drm/nouveau/core/memory: comptag allocation
nvkm_memory is going to be used by the upcoming mmu rework for the basic
representation of a memory allocation, as such, this commit adds support
for comptag allocation to nvkm_memory.

This is very simple for now, in that it requires comptags for the entire
memory allocation even if only certain ranges are compressed.

Support for tracking ranges will be added at a later date.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:22 +10:00
Ben Skeggs
6cd7670c1e drm/nouveau/ltc: init comptag mm in fb subdev
A single location for the MM allows us to share allocation logic.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:22 +10:00
Ben Skeggs
b1e839f3b3 drm/nouveau/fb/gf100: clear comptags at allocation time rather than mmu map
We probably don't want to destroy compression data when doing multiple
mappings of a memory object.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:22 +10:00
Ben Skeggs
af793b8cd9 drm/nouveau/fb: move comptag init out of ram submodule
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:22 +10:00
Ben Skeggs
7ef44bee64 drm/nouveau/fb: move comptags mm into nvkm_fb
We're moving towards having a central place to handle comptag allocation,
and as some GPUs don't have a ram submodule (ie. Tegra), we need to move
the mm somewhere else.

It probably never belonged in ram anyways.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:22 +10:00
Ben Skeggs
b7e1f3f1ba drm/nouveau/core/mm: introduce functions to access info about a given allocation
These will be used in upcoming patches.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:22 +10:00
Ben Skeggs
4d058fab63 drm/nouveau/core/mm: have users explicitly define heap identifiers
Different sections of VRAM may have different properties (ie. can't be used
for compression/display, can't be mapped, etc).

We currently already support this, but it's a bit magic.  This change makes
it more obvious where we're allocating from.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:22 +10:00
Ben Skeggs
24e8375b1b drm/nouveau: separate constant-va tracking from nvkm vma structure
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:21 +10:00
Ben Skeggs
9ce523cc3b drm/nouveau: separate buffer object backing memory from nvkm structures
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:21 +10:00
Ben Skeggs
cb7e88e70f drm/nouveau: hang drm client of a master
TTM memory allocations will be hanging off the DRM's client, but the
locking needed to do so gets really tricky with all the other use of
the DRM's object tree.

To solve this, we make the normal DRM client a child of a new master,
where the memory allocations will be done from instead.

This also solves a potential race with client creation.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:21 +10:00
Ben Skeggs
6be4421a9f drm/nouveau: consolidate identical functions in nouveau_ttm.c
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:21 +10:00
Ben Skeggs
792067e00b drm/nouveau: remove unnecessary use of ttm_mem_type_manager::priv
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:21 +10:00
Ben Skeggs
a48296ab9d drm/nouveau: swap loop order in move_notify() hook
The conditional is the same for every mapping.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:21 +10:00
Ben Skeggs
425b34f7df drm/nouveau: simplify const-va map condition
We don't really care about where the memory is, just that it's compatible
with a VMA allocated for a given page size.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:21 +10:00
Ben Skeggs
7760a2e38a drm/nouveau: split various bo flags out into their own members
It's far more convenient to deal with like this.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:20 +10:00
Ben Skeggs
bc3b0c7aff drm/nouveau: remove unused sysmem fence code
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:20 +10:00
Ben Skeggs
e75c091baf drm/nouveau: store nouveau_drm in nouveau_cli, as opposed to drm_device
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:20 +10:00
Ben Skeggs
b6838c14a2 drm/nouveau/gr/gf100-gk208: copy big page size setting from fb
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:20 +10:00
Ben Skeggs
223eaf4bf8 drm/nouveau/gr/gf100-gk208: make use of init_gpc_mmu() hook to share setup
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:20 +10:00
Ben Skeggs
2854ab8dd8 drm/nouveau/fb: finalise big page size selection in constructor
MMU will need to know this during its constructor, so we can't delay
deciding this until init-time.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:20 +10:00
Ben Skeggs
0b11b30de9 drm/nouveau/mmu/nv04-nv4x: move global vmm to nvkm_mmu
In a future commit, this will be constructed by common code.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:20 +10:00
Ben Skeggs
ffd937bbd2 drm/nouveau/imem: use fast-path for resume restore
Before: "imem: init completed in 299277us"
 After: "imem: init completed in  11574us"

Suspend from Fedora 26 gnome desktop on GP102.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:20 +10:00
Ben Skeggs
e9be3c7d7a drm/nouveau/imem: use fast-path for suspend backup
Before: "imem: suspend completed in 5540487us"
 After: "imem: suspend completed in 1871526us"

Suspend from Fedora 26 gnome desktop on GP102.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:20 +10:00
Ben Skeggs
b00b843046 drm/nouveau/imem: separate pre-BAR2-bootstrap objects from the rest
These will require slow-path access during suspend/resume.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:20 +10:00
Ben Skeggs
54c70e3ac6 drm/nouveau/imem: switch to kvmalloc/kvfree for suspend/resume backup
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:20 +10:00
Ben Skeggs
d52ddc953e drm/nouveau/imem: separate suspend/resume backup handling into their own functions
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:19 +10:00
Ben Skeggs
71370e620a drm/nouveau/imem: remove now-unused wrapper for backend objects
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:19 +10:00
Ben Skeggs
03edf1b31a drm/nouveau/imem/nv50: support eviction of BAR2 mappings
A good deal of the structures we map into here aren't accessed very often
at all, and Fedora 26 has exposed an issue where after creating a heap of
channels, BAR2 space would run out, and we'd need to make use of the slow
path while accessing important structures like page tables.

This implements an LRU on BAR2 space, which allows eviction of mappings
that aren't currently needed, to make space for other objects.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:19 +10:00
Ben Skeggs
69b136f200 drm/nouveau/imem/nv50: prevent fast-path for mapped objects when BAR isn't ready
Another piece of solving the "GP100 BAR2 VMM bootstrap" puzzle.

Without doing this, we'd attempt to write PDEs for the lower page table
levels through BAR2 before BAR2 access has been fully initialised.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:19 +10:00
Ben Skeggs
dfcbd55068 drm/nouveau/imem/nv50: map bar2 write-combined
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:19 +10:00
Ben Skeggs
be55287aa5 drm/nouveau/imem/nv50: embed nvkm_instobj directly into nv04_instobj
This is not as simple as it was for earlier GPUs, due to the need to swap
accessor functions depending on whether BAR2 is usable or not.

We were previously protected by nvkm_instobj's accessor functions keeping
an object mapped permanently, with some unclear magic that managed to hit
the slow-path where needed even if an object was marked as mapped.

That's been replaced here by reference counting maps (some objects, like
page tables can be accessed concurrently), and swapping the functions as
necessary.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:19 +10:00
Ben Skeggs
af515ec8d3 drm/nouveau/imem/nv50: move slow-path locking into rd/wr functions
This is to simplify upcoming changes.  The slow-path is something that
currently occurs during bootstrap of the BAR2 VMM, while backing up an
object during suspend/resume, or when BAR2 address space runs out.

The latter is a real problem that can happen at runtime, and occurs in
Fedora 26 already (due to some change that causes a lot of channels to
be created at login), so ideally we'd prefer not to make it any slower.

We'd also like suspend/resume speed to not suffer.

Upcoming commits will solve those problems in a better way, making the
extra overhead of moving the locking here a non-issue.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:19 +10:00
Ben Skeggs
f584bde609 drm/nouveau/imem/nv50: split object map out from api functions
acquire()/boot() will need different logic in addition to performing
the actual mapping.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:19 +10:00
Ben Skeggs
b807270cbd drm/nouveau/imem/nv40: map bar2 write-combined
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:19 +10:00
Ben Skeggs
62465ac518 drm/nouveau/imem/nv40: embed nvkm_instobj directly into nv04_instobj
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:18 +10:00
Ben Skeggs
87717e7f28 drm/nouveau/imem/nv04: directly embed nvkm_instobj into nv04_instobj
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:18 +10:00
Ben Skeggs
49814f62a2 drm/nouveau/imem: allow nvkm_instobj to be directly embedded in backend object
This will eliminate a step through the call chain, and give backends
more flexibility.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:18 +10:00
Ben Skeggs
07bbc1c5f4 drm/nouveau/core/memory: split info pointers from accessor pointers
The accessor functions can change as a result of acquire()/release() calls,
and are protected by any refcounting done there.

Other functions must remain constant, as they can be called any time.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:18 +10:00
Ben Skeggs
dde59b9c34 drm/nouveau/imem: add some useful debug output
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:18 +10:00
Ben Skeggs
70433b904a drm/nouveau/bar/gm107-: wait for instance block binding to complete
Discovered by accident while working to use BAR2 access to instmem objects
on more paths.

We've apparently been relying on luck up until now!

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:18 +10:00
Ben Skeggs
8e644cb29c drm/nouveau/bar: initialise bar2 during oneinit
If we initialise BAR2 earlier, we're able to complete BAR1 setup using
the instmem fast-path.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:18 +10:00
Ben Skeggs
bb7e501a66 drm/nouveau/bar: prevent BAR2 mapping of objects during destructor
GP100's page table nests a lot more deeply than the GF100-compatible
layout we're currently using, which means our hackish-but-simple way
of dealing with BAR2 VMM teardown won't work anymore.

In order to sanely handle the chicken-and-egg (BAR2's PTs get mapped
into themselves) problem, we need prevent page tables getting mapped
back into BAR2 during the destruction of its VMM.

To do this, we simply key off the state that's now maintained by the
BAR2 init/fini functions.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:18 +10:00
Ben Skeggs
a78dbce9a1 drm/nouveau/bar: modify interface to bar2 vmm mapping
Match API with the BAR1 version.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:18 +10:00
Ben Skeggs
570889dc50 drm/nouveau/bar: modify interface to bar1 vmm mapping
Upcoming changes will remove the nvkm_vmm pointer from nvkm_vma, instead
requiring it to be explicitly specified on each operation.

It's not currently possible to get this information for BAR1 mappings,
so let's fix that ahead of time.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:18 +10:00
Ben Skeggs
e988952eef drm/nouveau/bar: expose interface to bar2 teardown
Will prevent spurious MMU fault interrupts if something decides to touch
BAR1 after we've unloaded the driver.

Exposed external to BAR so that INSTMEM can use it to better control the
suspend/resume fast-path access.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
2017-11-02 13:32:18 +10:00