summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a/mm_gk20a.h
diff options
context:
space:
mode:
authorArto Merilainen <amerilainen@nvidia.com>2014-03-19 03:38:25 -0400
committerDan Willemsen <dwillemsen@nvidia.com>2015-03-18 15:08:53 -0400
commita9785995d5f22aaeb659285f8aeb64d8b56982e0 (patch)
treecc75f75bcf43db316a002a7a240b81f299bf6d7f /drivers/gpu/nvgpu/gk20a/mm_gk20a.h
parent61efaf843c22b85424036ec98015121c08f5f16c (diff)
gpu: nvgpu: Add NVIDIA GPU Driver
This patch moves the NVIDIA GPU driver to a new location. Bug 1482562 Change-Id: I24293810b9d0f1504fd9be00135e21dad656ccb6 Signed-off-by: Arto Merilainen <amerilainen@nvidia.com> Reviewed-on: http://git-master/r/383722 Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/mm_gk20a.h')
-rw-r--r--drivers/gpu/nvgpu/gk20a/mm_gk20a.h464
1 files changed, 464 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h
new file mode 100644
index 00000000..23d15c23
--- /dev/null
+++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h
@@ -0,0 +1,464 @@
1/*
2 * drivers/video/tegra/host/gk20a/mm_gk20a.h
3 *
4 * GK20A memory management
5 *
6 * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21#ifndef __MM_GK20A_H__
22#define __MM_GK20A_H__
23
24#include <linux/scatterlist.h>
25#include <linux/dma-attrs.h>
26#include <linux/iommu.h>
27#include <asm/dma-iommu.h>
28#include "gk20a_allocator.h"
29
30/* This "address bit" in the gmmu ptes (and other gk20a accesses)
31 * signals the address as presented should be translated by the SMMU.
32 * Without this bit present gk20a accesses are *not* translated.
33 */
34/* Hack, get this from manuals somehow... */
35#define NV_MC_SMMU_VADDR_TRANSLATION_BIT 34
36#define NV_MC_SMMU_VADDR_TRANSLATE(x) (x | \
37 (1ULL << NV_MC_SMMU_VADDR_TRANSLATION_BIT))
38
39/* For now keep the size relatively small-ish compared to the full
40 * 40b va. 32GB for now. It consists of two 16GB spaces. */
41#define NV_GMMU_VA_RANGE 35ULL
42#define NV_GMMU_VA_IS_UPPER(x) ((x) >= ((u64)0x1 << (NV_GMMU_VA_RANGE-1)))
43
44struct mem_desc {
45 struct dma_buf *ref;
46 struct sg_table *sgt;
47 u32 size;
48};
49
50struct mem_desc_sub {
51 u32 offset;
52 u32 size;
53};
54
55struct gpfifo_desc {
56 size_t size;
57 u32 entry_num;
58
59 u32 get;
60 u32 put;
61
62 bool wrap;
63
64 u64 iova;
65 struct gpfifo *cpu_va;
66 u64 gpu_va;
67};
68
69struct mmu_desc {
70 void *cpuva;
71 u64 iova;
72 size_t size;
73};
74
75struct inst_desc {
76 u64 iova;
77 void *cpuva;
78 phys_addr_t cpu_pa;
79 size_t size;
80};
81
82struct surface_mem_desc {
83 u64 iova;
84 void *cpuva;
85 struct sg_table *sgt;
86 size_t size;
87};
88
89struct userd_desc {
90 struct sg_table *sgt;
91 u64 iova;
92 void *cpuva;
93 size_t size;
94 u64 gpu_va;
95};
96
97struct runlist_mem_desc {
98 u64 iova;
99 void *cpuva;
100 size_t size;
101};
102
103struct patch_desc {
104 struct page **pages;
105 u64 iova;
106 size_t size;
107 void *cpu_va;
108 u64 gpu_va;
109 u32 data_count;
110};
111
112struct pmu_mem_desc {
113 void *cpuva;
114 u64 iova;
115 u64 pmu_va;
116 size_t size;
117};
118
119struct priv_cmd_queue_mem_desc {
120 u64 base_iova;
121 u32 *base_cpuva;
122 size_t size;
123};
124
125struct zcull_ctx_desc {
126 struct mem_desc mem;
127 u64 gpu_va;
128 u32 ctx_attr;
129 u32 ctx_sw_mode;
130};
131
132struct pm_ctx_desc {
133 struct mem_desc mem;
134 u64 gpu_va;
135 u32 ctx_attr;
136 u32 ctx_sw_mode;
137};
138
139struct gr_ctx_buffer_desc;
140struct platform_device;
141struct gr_ctx_buffer_desc {
142 void (*destroy)(struct platform_device *, struct gr_ctx_buffer_desc *);
143 struct sg_table *sgt;
144 struct page **pages;
145 size_t size;
146 u64 iova;
147 struct dma_attrs attrs;
148 void *priv;
149};
150
151struct gr_ctx_desc {
152 struct page **pages;
153 u64 iova;
154 size_t size;
155 u64 gpu_va;
156};
157
158struct compbit_store_desc {
159 struct pages **pages;
160 size_t size;
161 u64 base_iova;
162};
163
164struct page_table_gk20a {
165 /* backing for */
166 /* Either a *page or a *mem_handle */
167 void *ref;
168 /* track mapping cnt on this page table */
169 u32 ref_cnt;
170 struct sg_table *sgt;
171 size_t size;
172};
173
174#ifndef _NVHOST_MEM_MGR_H
175enum gk20a_mem_rw_flag {
176 gk20a_mem_flag_none = 0,
177 gk20a_mem_flag_read_only = 1,
178 gk20a_mem_flag_write_only = 2,
179};
180#endif
181
182enum gmmu_pgsz_gk20a {
183 gmmu_page_size_small = 0,
184 gmmu_page_size_big = 1,
185 gmmu_nr_page_sizes = 2
186};
187
188
189struct page_directory_gk20a {
190 /* backing for */
191 u32 num_pdes;
192 void *kv;
193 /* Either a *page or a *mem_handle */
194 void *ref;
195 struct sg_table *sgt;
196 size_t size;
197 struct page_table_gk20a *ptes[gmmu_nr_page_sizes];
198};
199
200struct priv_cmd_queue {
201 struct priv_cmd_queue_mem_desc mem;
202 u64 base_gpuva; /* gpu_va base */
203 u16 size; /* num of entries in words */
204 u16 put; /* put for priv cmd queue */
205 u16 get; /* get for priv cmd queue */
206 struct list_head free; /* list of pre-allocated free entries */
207 struct list_head head; /* list of used entries */
208};
209
210struct priv_cmd_entry {
211 u32 *ptr;
212 u64 gva;
213 u16 get; /* start of entry in queue */
214 u16 size; /* in words */
215 u32 gp_get; /* gp_get when submitting last priv cmd */
216 u32 gp_put; /* gp_put when submitting last priv cmd */
217 u32 gp_wrap; /* wrap when submitting last priv cmd */
218 bool pre_alloc; /* prealloc entry, free to free list */
219 struct list_head list; /* node for lists */
220};
221
222struct mapped_buffer_node {
223 struct vm_gk20a *vm;
224 struct rb_node node;
225 struct list_head unmap_list;
226 struct list_head va_buffers_list;
227 struct vm_reserved_va_node *va_node;
228 u64 addr;
229 u64 size;
230 struct dma_buf *dmabuf;
231 struct sg_table *sgt;
232 struct kref ref;
233 u32 user_mapped;
234 bool own_mem_ref;
235 u32 pgsz_idx;
236 u32 ctag_offset;
237 u32 ctag_lines;
238 u32 flags;
239 u32 kind;
240 bool va_allocated;
241};
242
243struct vm_reserved_va_node {
244 struct list_head reserved_va_list;
245 struct list_head va_buffers_list;
246 u32 pgsz_idx;
247 u64 vaddr_start;
248 u64 size;
249 bool sparse;
250};
251
252struct vm_gk20a {
253 struct mm_gk20a *mm;
254 struct gk20a_as_share *as_share; /* as_share this represents */
255
256 u64 va_start;
257 u64 va_limit;
258
259 int num_user_mapped_buffers;
260
261 bool big_pages; /* enable large page support */
262 bool enable_ctag;
263 bool tlb_dirty;
264 bool mapped;
265
266 struct kref ref;
267
268 struct mutex update_gmmu_lock;
269
270 struct page_directory_gk20a pdes;
271
272 struct gk20a_allocator vma[gmmu_nr_page_sizes];
273 struct rb_root mapped_buffers;
274
275 struct list_head reserved_va_list;
276
277 dma_addr_t zero_page_iova;
278 void *zero_page_cpuva;
279 struct sg_table *zero_page_sgt;
280};
281
282struct gk20a;
283struct channel_gk20a;
284
285int gk20a_init_mm_support(struct gk20a *g);
286int gk20a_init_mm_setup_sw(struct gk20a *g);
287int gk20a_init_bar1_vm(struct mm_gk20a *mm);
288int gk20a_init_pmu_vm(struct mm_gk20a *mm);
289
290void gk20a_mm_fb_flush(struct gk20a *g);
291void gk20a_mm_l2_flush(struct gk20a *g, bool invalidate);
292void gk20a_mm_l2_invalidate(struct gk20a *g);
293
294struct mm_gk20a {
295 struct gk20a *g;
296
297 u32 compression_page_size;
298 u32 big_page_size;
299 u32 pde_stride;
300 u32 pde_stride_shift;
301
302 struct {
303 u32 order;
304 u32 num_ptes;
305 } page_table_sizing[gmmu_nr_page_sizes];
306
307
308 struct {
309 u64 size;
310 } channel;
311
312 struct {
313 u32 aperture_size;
314 struct vm_gk20a vm;
315 struct inst_desc inst_block;
316 } bar1;
317
318 struct {
319 u32 aperture_size;
320 struct vm_gk20a vm;
321 struct inst_desc inst_block;
322 } pmu;
323
324 struct mutex tlb_lock;
325 struct mutex l2_op_lock;
326
327 void (*remove_support)(struct mm_gk20a *mm);
328 bool sw_ready;
329#ifdef CONFIG_DEBUG_FS
330 u32 ltc_enabled;
331 u32 ltc_enabled_debug;
332#endif
333};
334
335int gk20a_mm_init(struct mm_gk20a *mm);
336
337#define gk20a_from_mm(mm) ((mm)->g)
338#define gk20a_from_vm(vm) ((vm)->mm->g)
339
340#define dev_from_vm(vm) dev_from_gk20a(vm->mm->g)
341
342#define DEFAULT_ALLOC_ALIGNMENT (4*1024)
343
344static inline int bar1_aperture_size_mb_gk20a(void)
345{
346 return 128; /*TBD read this from fuses?*/
347}
348/* max address bits */
349static inline int max_physaddr_bits_gk20a(void)
350{
351 return 40;/*"old" sys physaddr, meaningful? */
352}
353static inline int max_vid_physaddr_bits_gk20a(void)
354{
355 /* "vid phys" is asid/smmu phys?,
356 * i.e. is this the real sys physaddr? */
357 return 37;
358}
359static inline int max_vaddr_bits_gk20a(void)
360{
361 return 40; /* chopped for area? */
362}
363
364#if 0 /*related to addr bits above, concern below TBD on which is accurate */
365#define bar1_instance_block_shift_gk20a() (max_physaddr_bits_gk20a() -\
366 bus_bar1_block_ptr_s())
367#else
368#define bar1_instance_block_shift_gk20a() bus_bar1_block_ptr_shift_v()
369#endif
370
371void gk20a_mm_dump_vm(struct vm_gk20a *vm,
372 u64 va_begin, u64 va_end, char *label);
373
374int gk20a_mm_suspend(struct gk20a *g);
375
376phys_addr_t gk20a_get_phys_from_iova(struct device *d,
377 u64 dma_addr);
378
379int gk20a_get_sgtable(struct device *d, struct sg_table **sgt,
380 void *cpuva, u64 iova,
381 size_t size);
382
383int gk20a_get_sgtable_from_pages(struct device *d, struct sg_table **sgt,
384 struct page **pages, u64 iova,
385 size_t size);
386
387void gk20a_free_sgtable(struct sg_table **sgt);
388
389u64 gk20a_mm_iova_addr(struct scatterlist *sgl);
390
391void gk20a_mm_ltc_isr(struct gk20a *g);
392
393bool gk20a_mm_mmu_debug_mode_enabled(struct gk20a *g);
394
395int gk20a_mm_mmu_vpr_info_fetch(struct gk20a *g);
396
397u64 gk20a_gmmu_map(struct vm_gk20a *vm,
398 struct sg_table **sgt,
399 u64 size,
400 u32 flags,
401 int rw_flag);
402
403void gk20a_gmmu_unmap(struct vm_gk20a *vm,
404 u64 vaddr,
405 u64 size,
406 int rw_flag);
407
408struct sg_table *gk20a_mm_pin(struct device *dev, struct dma_buf *dmabuf);
409void gk20a_mm_unpin(struct device *dev, struct dma_buf *dmabuf,
410 struct sg_table *sgt);
411
412u64 gk20a_vm_map(struct vm_gk20a *vm,
413 struct dma_buf *dmabuf,
414 u64 offset_align,
415 u32 flags /*NVHOST_AS_MAP_BUFFER_FLAGS_*/,
416 int kind,
417 struct sg_table **sgt,
418 bool user_mapped,
419 int rw_flag);
420
421/* unmap handle from kernel */
422void gk20a_vm_unmap(struct vm_gk20a *vm, u64 offset);
423
424/* get reference to all currently mapped buffers */
425int gk20a_vm_get_buffers(struct vm_gk20a *vm,
426 struct mapped_buffer_node ***mapped_buffers,
427 int *num_buffers);
428
429/* put references on the given buffers */
430void gk20a_vm_put_buffers(struct vm_gk20a *vm,
431 struct mapped_buffer_node **mapped_buffers,
432 int num_buffers);
433
434/* invalidate tlbs for the vm area */
435void gk20a_mm_tlb_invalidate(struct vm_gk20a *vm);
436
437/* find buffer corresponding to va */
438int gk20a_vm_find_buffer(struct vm_gk20a *vm, u64 gpu_va,
439 struct dma_buf **dmabuf,
440 u64 *offset);
441
442void gk20a_vm_get(struct vm_gk20a *vm);
443void gk20a_vm_put(struct vm_gk20a *vm);
444
445/* vm-as interface */
446struct nvhost_as_alloc_space_args;
447struct nvhost_as_free_space_args;
448int gk20a_vm_alloc_share(struct gk20a_as_share *as_share);
449int gk20a_vm_release_share(struct gk20a_as_share *as_share);
450int gk20a_vm_alloc_space(struct gk20a_as_share *as_share,
451 struct nvhost_as_alloc_space_args *args);
452int gk20a_vm_free_space(struct gk20a_as_share *as_share,
453 struct nvhost_as_free_space_args *args);
454int gk20a_vm_bind_channel(struct gk20a_as_share *as_share,
455 struct channel_gk20a *ch);
456int gk20a_vm_map_buffer(struct gk20a_as_share *as_share,
457 int dmabuf_fd,
458 u64 *offset_align,
459 u32 flags, /*NVHOST_AS_MAP_BUFFER_FLAGS_*/
460 int kind);
461int gk20a_vm_unmap_buffer(struct gk20a_as_share *, u64 offset);
462
463int gk20a_dmabuf_alloc_drvdata(struct dma_buf *dmabuf, struct device *dev);
464#endif /*_MM_GK20A_H_ */