diff options
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/gmmu.h | 35 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/vm.h | 144 |
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 | |||
23 | struct 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 @@ | |||
28 | struct vm_gk20a; | 31 | struct vm_gk20a; |
29 | struct nvgpu_mem; | 32 | struct nvgpu_mem; |
30 | 33 | ||
31 | enum nvgpu_aperture; | 34 | enum 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 | |||
41 | struct 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 | |||
50 | struct 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 | |||
28 | struct vm_gk20a; | ||
29 | struct 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 */ | ||
42 | struct vm_gk20a_mapping_batch { | ||
43 | bool gpu_l2_flushed; | ||
44 | bool need_tlb_invalidate; | ||
45 | }; | ||
46 | |||
47 | struct 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 | |||
102 | void nvgpu_vm_get(struct vm_gk20a *vm); | ||
103 | void nvgpu_vm_put(struct vm_gk20a *vm); | ||
104 | |||
105 | /* batching eliminates redundant cache flushes and invalidates */ | ||
106 | void nvgpu_vm_mapping_batch_start(struct vm_gk20a_mapping_batch *batch); | ||
107 | void nvgpu_vm_mapping_batch_finish( | ||
108 | struct vm_gk20a *vm, struct vm_gk20a_mapping_batch *batch); | ||
109 | /* called when holding vm->update_gmmu_lock */ | ||
110 | void 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 */ | ||
114 | int 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 */ | ||
119 | void 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 */ | ||
124 | int nvgpu_vm_unmap_buffer(struct vm_gk20a *vm, u64 offset, | ||
125 | struct vm_gk20a_mapping_batch *batch); | ||
126 | |||
127 | void nvgpu_vm_unmap_locked(struct mapped_buffer_node *mapped_buffer, | ||
128 | struct vm_gk20a_mapping_batch *batch); | ||
129 | |||
130 | void nvgpu_vm_remove_support_nofree(struct vm_gk20a *vm); | ||
131 | void nvgpu_vm_remove_support(struct vm_gk20a *vm); | ||
132 | |||
133 | int 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); | ||
142 | void nvgpu_deinit_vm(struct vm_gk20a *vm); | ||
143 | |||
144 | #endif | ||