summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/include
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2017-04-17 19:26:28 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2017-05-19 18:34:01 -0400
commitd37e8f7dcf190f31f9c0c12583db2bb0c0d313c0 (patch)
tree4807c89bf40954c54804c3a8dd88c16849181f29 /drivers/gpu/nvgpu/include
parentdcb744acfbbc11e66cac2d0a674a42e62d908b9d (diff)
gpu: nvgpu: Split VM interface out
This patch begins the major rework of the GPU's virtual memory manager (VMM). The VMM is the piece of code that handles the userspace interface to buffers and their mappings into the GMMU. The core data structure is the VM - for now still known as 'struct vm_gk20a'. Each one of these structs represents one addres space to which channels or TSGs may bind themselves to. The VMM splits the interface up into two broad categories. First there's the common, OS independent interfaces; and second there's the OS specific interfaces. OS independent -------------- This is the code that manages the lifetime of VMs, the buffers inside VMs (search, batch mapping) creation, destruction, etc. OS Specific ----------- This handles mapping of buffers represented as they are represented by the OS (dma_buf's for example on Linux). This patch is by no means complete. There's still Linux specific functions scattered in ostensibly OS independent code. This is the first step. A patch that rewrites everything in one go would simply be too big to effectively review. Instead the goal of this change is to simply separate out the basic OS specific and OS agnostic interfaces into their own header files. The next series of patches will start to pull the relevant implementations into OS specific C files and common C files. JIRA NVGPU-12 JIRA NVGPU-30 Change-Id: I242c7206047b6c769296226d855b7e44d5c4bfa8 Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: http://git-master/r/1464939 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/gmmu.h35
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/vm.h144
2 files changed, 178 insertions, 1 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/gmmu.h b/drivers/gpu/nvgpu/include/nvgpu/gmmu.h
index 7fb0147e..6d8aa025 100644
--- a/drivers/gpu/nvgpu/include/nvgpu/gmmu.h
+++ b/drivers/gpu/nvgpu/include/nvgpu/gmmu.h
@@ -18,6 +18,9 @@
18#define __NVGPU_GMMU_H__ 18#define __NVGPU_GMMU_H__
19 19
20#include <nvgpu/types.h> 20#include <nvgpu/types.h>
21#include <nvgpu/nvgpu_mem.h>
22
23struct scatterlist;
21 24
22/* 25/*
23 * This is the GMMU API visible to blocks outside of the GMMU. Basically this 26 * This is the GMMU API visible to blocks outside of the GMMU. Basically this
@@ -28,7 +31,37 @@
28struct vm_gk20a; 31struct vm_gk20a;
29struct nvgpu_mem; 32struct nvgpu_mem;
30 33
31enum nvgpu_aperture; 34enum gmmu_pgsz_gk20a {
35 gmmu_page_size_small = 0,
36 gmmu_page_size_big = 1,
37 gmmu_page_size_kernel = 2,
38 gmmu_nr_page_sizes = 3,
39};
40
41struct gk20a_mm_entry {
42 /* backing for */
43 struct nvgpu_mem mem;
44 u32 woffset; /* if >0, mem is a shadow copy, owned by another entry */
45 int pgsz;
46 struct gk20a_mm_entry *entries;
47 int num_entries;
48};
49
50struct gk20a_mmu_level {
51 int hi_bit[2];
52 int lo_bit[2];
53 int (*update_entry)(struct vm_gk20a *vm,
54 struct gk20a_mm_entry *pte,
55 u32 i, u32 gmmu_pgsz_idx,
56 struct scatterlist **sgl,
57 u64 *offset,
58 u64 *iova,
59 u32 kind_v, u64 *ctag,
60 bool cacheable, bool unmapped_pte,
61 int rw_flag, bool sparse, bool priv,
62 enum nvgpu_aperture aperture);
63 size_t entry_size;
64};
32 65
33/** 66/**
34 * nvgpu_gmmu_map - Map memory into the GMMU. 67 * nvgpu_gmmu_map - Map memory into the GMMU.
diff --git a/drivers/gpu/nvgpu/include/nvgpu/vm.h b/drivers/gpu/nvgpu/include/nvgpu/vm.h
new file mode 100644
index 00000000..1fb772d5
--- /dev/null
+++ b/drivers/gpu/nvgpu/include/nvgpu/vm.h
@@ -0,0 +1,144 @@
1/*
2 * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __NVGPU_VM_H__
18#define __NVGPU_VM_H__
19
20#include <nvgpu/kref.h>
21#include <nvgpu/list.h>
22#include <nvgpu/rbtree.h>
23#include <nvgpu/types.h>
24#include <nvgpu/gmmu.h>
25#include <nvgpu/nvgpu_mem.h>
26#include <nvgpu/allocator.h>
27
28struct vm_gk20a;
29struct mapped_buffer_node;
30
31/**
32 * This header contains the OS agnostic APIs for dealing with VMs. Most of the
33 * VM implementation is system specific - it must translate from a platform's
34 * representation of DMA'able memory to our nvgpu_mem notion.
35 *
36 * However, some stuff is platform agnostic. VM ref-counting and the VM struct
37 * itself are platform agnostic. Also, the initialization and destruction of
38 * VMs is the same across all platforms (for now).
39 */
40
41/* map/unmap batch state */
42struct vm_gk20a_mapping_batch {
43 bool gpu_l2_flushed;
44 bool need_tlb_invalidate;
45};
46
47struct vm_gk20a {
48 struct mm_gk20a *mm;
49 struct gk20a_as_share *as_share; /* as_share this represents */
50
51 u64 va_start;
52 u64 va_limit;
53
54 int num_user_mapped_buffers;
55
56 bool big_pages; /* enable large page support */
57 bool enable_ctag;
58 bool mapped;
59
60 u32 big_page_size;
61
62 bool userspace_managed;
63
64 const struct gk20a_mmu_level *mmu_levels;
65
66 struct kref ref;
67
68 struct nvgpu_mutex update_gmmu_lock;
69
70 struct gk20a_mm_entry pdb;
71
72 /*
73 * These structs define the address spaces. In some cases it's possible
74 * to merge address spaces (user and user_lp) and in other cases it's
75 * not. vma[] allows the code to be agnostic to this by always using
76 * address spaces through this pointer array.
77 */
78 struct nvgpu_allocator *vma[gmmu_nr_page_sizes];
79 struct nvgpu_allocator kernel;
80 struct nvgpu_allocator user;
81 struct nvgpu_allocator user_lp;
82
83 struct nvgpu_rbtree_node *mapped_buffers;
84
85 struct nvgpu_list_node reserved_va_list;
86
87#ifdef CONFIG_TEGRA_GR_VIRTUALIZATION
88 u64 handle;
89#endif
90 u32 gmmu_page_sizes[gmmu_nr_page_sizes];
91
92 /* if non-NULL, kref_put will use this batch when
93 unmapping. Must hold vm->update_gmmu_lock. */
94 struct vm_gk20a_mapping_batch *kref_put_batch;
95
96 /*
97 * Each address space needs to have a semaphore pool.
98 */
99 struct nvgpu_semaphore_pool *sema_pool;
100};
101
102void nvgpu_vm_get(struct vm_gk20a *vm);
103void nvgpu_vm_put(struct vm_gk20a *vm);
104
105/* batching eliminates redundant cache flushes and invalidates */
106void nvgpu_vm_mapping_batch_start(struct vm_gk20a_mapping_batch *batch);
107void nvgpu_vm_mapping_batch_finish(
108 struct vm_gk20a *vm, struct vm_gk20a_mapping_batch *batch);
109/* called when holding vm->update_gmmu_lock */
110void nvgpu_vm_mapping_batch_finish_locked(
111 struct vm_gk20a *vm, struct vm_gk20a_mapping_batch *batch);
112
113/* get reference to all currently mapped buffers */
114int nvgpu_vm_get_buffers(struct vm_gk20a *vm,
115 struct mapped_buffer_node ***mapped_buffers,
116 int *num_buffers);
117
118/* put references on the given buffers */
119void nvgpu_vm_put_buffers(struct vm_gk20a *vm,
120 struct mapped_buffer_node **mapped_buffers,
121 int num_buffers);
122
123/* Note: batch may be NULL if unmap op is not part of a batch */
124int nvgpu_vm_unmap_buffer(struct vm_gk20a *vm, u64 offset,
125 struct vm_gk20a_mapping_batch *batch);
126
127void nvgpu_vm_unmap_locked(struct mapped_buffer_node *mapped_buffer,
128 struct vm_gk20a_mapping_batch *batch);
129
130void nvgpu_vm_remove_support_nofree(struct vm_gk20a *vm);
131void nvgpu_vm_remove_support(struct vm_gk20a *vm);
132
133int nvgpu_init_vm(struct mm_gk20a *mm,
134 struct vm_gk20a *vm,
135 u32 big_page_size,
136 u64 low_hole,
137 u64 kernel_reserved,
138 u64 aperture_size,
139 bool big_pages,
140 bool userspace_managed,
141 char *name);
142void nvgpu_deinit_vm(struct vm_gk20a *vm);
143
144#endif