diff options
author | Alex Waterman <alexw@nvidia.com> | 2017-10-12 19:19:55 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-10-24 18:16:50 -0400 |
commit | 0c5d0c6a9ef0e33f01ce1485674bb2271e4bb580 (patch) | |
tree | 15ce6b6d41decce809e62c996be94492263daede /drivers/gpu/nvgpu/include | |
parent | 2a285d0607a20694476399f5719e74dbc26fcd58 (diff) |
gpu: nvgpu: Begin reorganizing VM mapping/unmapping
Move vm_priv.h to <nvgpu/linux/vm.h> and rename nvgpu_vm_map()
to nvgpu_vm_map_linux(). Also remove a redundant unmap function
from the unmap path. These changes are the beginning of reworking
the nvgpu Linux mapping and unmapping code.
The rest of this patch is just the necessary changes to use the
new map function naming and the new path to the Linux vm header.
Patch Series Goal
-----------------
There's two major goals for this patch series. Note that these
goals are not achieved in this patch. There will be subsequent
patches.
1. Remove all last vestiges of Linux code from common/mm/vm.c
2. Implement map caching in the common/mm/vm.c code
To accomplish this firstly the VM mapping code needs to have the
struct nvgpu_mapped_buf data struct be completely Linux free. That
means implementing an abstraction for this to hold the Linux stuff
that mapped buffers carry about (SGT, dma_buf). This is why the
vm_priv.h code has been moved: it will need to be included by the
<nvgpu/vm.h> header so that the OS specific struct can be pulled
into struct nvgpu_mapped_buf.
Next renaming the nvgpu_vm_map() to nvgpu_vm_map_linux() is in
preparation for adding a new nvgpu_vm_map() that handles the
map caching with nvgpu_mapped_buf. The mapping code is fairly
straight forward: nvgpu_vm_map does OS generic stuff; each OS
then calls this function from an nvgpu_vm_map_<OS>() or the like
that does any OS specific adjustments/management.
Freeing buffers is much more tricky however. The maps are all
reference counted since userspace does not track buffers and
expects us to handle this instead. Ugh! Since there's ref-counts
the free code will require a callback into the OS specific code
since the OS specific code cannot free a buffer directly. THis
make's the path for freeing a buffer quite convoluted.
JIRA NVGPU-30
JIRA NVGPU-71
Change-Id: I5e0975f60663a0d6cf0a6bd90e099f51e02c2395
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1578896
GVS: Gerrit_Virtual_Submit
Reviewed-by: David Martinez Nieto <dmartineznie@nvidia.com>
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/linux/vm.h | 105 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/vm.h | 6 |
2 files changed, 107 insertions, 4 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h b/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h new file mode 100644 index 00000000..91f0cf09 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/vm.h | |||
@@ -0,0 +1,105 @@ | |||
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 __COMMON_LINUX_VM_PRIV_H__ | ||
18 | #define __COMMON_LINUX_VM_PRIV_H__ | ||
19 | |||
20 | #include <nvgpu/types.h> | ||
21 | |||
22 | struct sg_table; | ||
23 | struct dma_buf; | ||
24 | |||
25 | struct vm_gk20a; | ||
26 | struct vm_gk20a_mapping_batch; | ||
27 | struct nvgpu_vm_area; | ||
28 | |||
29 | struct buffer_attrs { | ||
30 | struct sg_table *sgt; | ||
31 | u64 size; | ||
32 | u64 align; | ||
33 | u32 ctag_offset; | ||
34 | u32 ctag_lines; | ||
35 | u32 ctag_allocated_lines; | ||
36 | int pgsz_idx; | ||
37 | u8 kind_v; | ||
38 | bool use_kind_v; | ||
39 | u8 uc_kind_v; | ||
40 | bool use_uc_kind_v; | ||
41 | bool ctag_user_mappable; | ||
42 | }; | ||
43 | |||
44 | u64 nvgpu_vm_map_linux(struct vm_gk20a *vm, | ||
45 | struct dma_buf *dmabuf, | ||
46 | u64 offset_align, | ||
47 | u32 flags, | ||
48 | |||
49 | /* | ||
50 | * compressible kind if | ||
51 | * NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL is | ||
52 | * specified, otherwise just the kind | ||
53 | */ | ||
54 | s16 compr_kind, | ||
55 | |||
56 | /* | ||
57 | * incompressible kind if | ||
58 | * NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL is | ||
59 | * specified, otherwise ignored | ||
60 | */ | ||
61 | s16 incompr_kind, | ||
62 | |||
63 | bool user_mapped, | ||
64 | int rw_flag, | ||
65 | u64 buffer_offset, | ||
66 | u64 mapping_size, | ||
67 | struct vm_gk20a_mapping_batch *mapping_batch); | ||
68 | |||
69 | /* | ||
70 | * Notes: | ||
71 | * - Batch may be NULL if map op is not part of a batch. | ||
72 | * - If NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL is set, | ||
73 | * compr_kind and incompr_kind work as explained in nvgpu.h. | ||
74 | * - If NVGPU_AS_MAP_BUFFER_FLAGS_DIRECT_KIND_CTRL is NOT set, | ||
75 | * compr_kind holds the kind and kernel will figure out whether | ||
76 | * it is a compressible or incompressible kind. If compressible, kernel will | ||
77 | * also figure out the incompressible counterpart or return an error. | ||
78 | */ | ||
79 | int nvgpu_vm_map_buffer(struct vm_gk20a *vm, | ||
80 | int dmabuf_fd, | ||
81 | u64 *offset_align, | ||
82 | u32 flags, /* NVGPU_AS_MAP_BUFFER_FLAGS_ */ | ||
83 | s16 compr_kind, | ||
84 | s16 incompr_kind, | ||
85 | u64 buffer_offset, | ||
86 | u64 mapping_size, | ||
87 | struct vm_gk20a_mapping_batch *batch); | ||
88 | |||
89 | /* Note: batch may be NULL if unmap op is not part of a batch */ | ||
90 | int nvgpu_vm_unmap_buffer(struct vm_gk20a *vm, u64 offset, | ||
91 | struct vm_gk20a_mapping_batch *batch); | ||
92 | |||
93 | /* find buffer corresponding to va */ | ||
94 | int nvgpu_vm_find_buf(struct vm_gk20a *vm, u64 gpu_va, | ||
95 | struct dma_buf **dmabuf, | ||
96 | u64 *offset); | ||
97 | |||
98 | enum nvgpu_aperture gk20a_dmabuf_aperture(struct gk20a *g, | ||
99 | struct dma_buf *dmabuf); | ||
100 | int validate_fixed_buffer(struct vm_gk20a *vm, | ||
101 | struct buffer_attrs *bfr, | ||
102 | u64 map_offset, u64 map_size, | ||
103 | struct nvgpu_vm_area **pva_node); | ||
104 | |||
105 | #endif | ||
diff --git a/drivers/gpu/nvgpu/include/nvgpu/vm.h b/drivers/gpu/nvgpu/include/nvgpu/vm.h index 8c56461c..e529512b 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/vm.h +++ b/drivers/gpu/nvgpu/include/nvgpu/vm.h | |||
@@ -207,14 +207,12 @@ void nvgpu_vm_put_buffers(struct vm_gk20a *vm, | |||
207 | struct nvgpu_mapped_buf **mapped_buffers, | 207 | struct nvgpu_mapped_buf **mapped_buffers, |
208 | int num_buffers); | 208 | int num_buffers); |
209 | 209 | ||
210 | /* Note: batch may be NULL if unmap op is not part of a batch */ | ||
211 | int nvgpu_vm_unmap_buffer(struct vm_gk20a *vm, u64 offset, | ||
212 | struct vm_gk20a_mapping_batch *batch); | ||
213 | |||
214 | void nvgpu_vm_unmap_locked(struct nvgpu_mapped_buf *mapped_buffer, | 210 | void nvgpu_vm_unmap_locked(struct nvgpu_mapped_buf *mapped_buffer, |
215 | struct vm_gk20a_mapping_batch *batch); | 211 | struct vm_gk20a_mapping_batch *batch); |
216 | void nvgpu_vm_unmap_locked_ref(struct nvgpu_ref *ref); | 212 | void nvgpu_vm_unmap_locked_ref(struct nvgpu_ref *ref); |
217 | 213 | ||
214 | void nvgpu_vm_unmap(struct vm_gk20a *vm, u64 offset); | ||
215 | |||
218 | /* | 216 | /* |
219 | * These all require the VM update lock to be held. | 217 | * These all require the VM update lock to be held. |
220 | */ | 218 | */ |