diff options
author | Alex Waterman <alexw@nvidia.com> | 2017-04-10 16:27:47 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-04-25 17:25:54 -0400 |
commit | 6a14d980cfdce5609c0eb7b20e2da3d98fbbccb8 (patch) | |
tree | ca04bbb2a27f28958bd7f884fef0327063b9152e /drivers/gpu/nvgpu/include | |
parent | 39524b094180ab747287bc893e217dcbe5029e64 (diff) |
gpu: nvgpu: Add sub-nvgpu_mem
Add an API for creating a special sub-nvgpu_mem struct. This struct
comes with some fairly important caveats but is very useful for the
semaphore code.
Also, make sure that in nvgpu_mem_begin() and nvgpu_mem_end() no
additional mappings are made if not necessary. More importantly during
nvgpu_mem_end() it would be possible to vunmap() a CPU mapping of a
DMA allocation that does not expect this to happen.
JIRA NVGPU-12
JIRA NVGPU-30
Change-Id: I579429da9ff7288488753a113bafc558e0f17a0f
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: http://git-master/r/1464077
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h index 1590ee7a..397e9ab1 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h +++ b/drivers/gpu/nvgpu/include/nvgpu/nvgpu_mem.h | |||
@@ -49,6 +49,13 @@ struct nvgpu_mem { | |||
49 | bool skip_wmb; | 49 | bool skip_wmb; |
50 | 50 | ||
51 | /* | 51 | /* |
52 | * Set when a nvgpu_mem struct is not a "real" nvgpu_mem struct. Instead | ||
53 | * the struct is just a copy of another nvgpu_mem struct. | ||
54 | */ | ||
55 | #define NVGPU_MEM_FLAG_SHADOW_COPY (1 << 0) | ||
56 | unsigned long mem_flags; | ||
57 | |||
58 | /* | ||
52 | * Only populated for a sysmem allocation. | 59 | * Only populated for a sysmem allocation. |
53 | */ | 60 | */ |
54 | void *cpu_va; | 61 | void *cpu_va; |
@@ -86,6 +93,42 @@ static inline const char *nvgpu_aperture_str(enum nvgpu_aperture aperture) | |||
86 | return "UNKNOWN"; | 93 | return "UNKNOWN"; |
87 | } | 94 | } |
88 | 95 | ||
96 | /** | ||
97 | * nvgpu_mem_create_from_mem - Create a new nvgpu_mem struct from an old one. | ||
98 | * | ||
99 | * @g - The GPU. | ||
100 | * @dest - Destination nvgpu_mem to hold resulting memory description. | ||
101 | * @src - Source memory. Must be valid. | ||
102 | * @start_page - Starting page to use. | ||
103 | * @nr_pages - Number of pages to place in the new nvgpu_mem. | ||
104 | * | ||
105 | * Create a new nvgpu_mem struct describing a subsection of the @src nvgpu_mem. | ||
106 | * This will create an nvpgu_mem object starting at @start_page and is @nr_pages | ||
107 | * long. This currently only works on SYSMEM nvgpu_mems. If this is called on a | ||
108 | * VIDMEM nvgpu_mem then this will return an error. | ||
109 | * | ||
110 | * There is a _major_ caveat to this API: if the source buffer is freed before | ||
111 | * the copy is freed then the copy will become invalid. This is a result from | ||
112 | * how typical DMA APIs work: we can't call free on the buffer multiple times. | ||
113 | * Nor can we call free on parts of a buffer. Thus the only way to ensure that | ||
114 | * the entire buffer is actually freed is to call free once on the source | ||
115 | * buffer. Since these nvgpu_mem structs are not ref-counted in anyway it is up | ||
116 | * to the caller of this API to _ensure_ that the resulting nvgpu_mem buffer | ||
117 | * from this API is freed before the source buffer. Otherwise there can and will | ||
118 | * be memory corruption. | ||
119 | * | ||
120 | * The resulting nvgpu_mem should be released with the nvgpu_dma_free() or the | ||
121 | * nvgpu_dma_unmap_free() function depending on whether or not the resulting | ||
122 | * nvgpu_mem has been mapped. | ||
123 | * | ||
124 | * This will return 0 on success. An error is returned if the resulting | ||
125 | * nvgpu_mem would not make sense or if a new scatter gather table cannot be | ||
126 | * created. | ||
127 | */ | ||
128 | int nvgpu_mem_create_from_mem(struct gk20a *g, | ||
129 | struct nvgpu_mem *dest, struct nvgpu_mem *src, | ||
130 | int start_page, int nr_pages); | ||
131 | |||
89 | /* | 132 | /* |
90 | * Buffer accessors - wrap between begin() and end() if there is no permanent | 133 | * Buffer accessors - wrap between begin() and end() if there is no permanent |
91 | * kernel mapping for this buffer. | 134 | * kernel mapping for this buffer. |