diff options
author | Alex Waterman <alexw@nvidia.com> | 2016-07-21 21:26:20 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2016-08-30 13:04:10 -0400 |
commit | 448df6ed271a7b73a1a5e3dfbba826e745b82922 (patch) | |
tree | 284c4c4ede880629df1c342e2d5516c462d5ed56 /drivers/gpu/nvgpu/gk20a/page_allocator_priv.h | |
parent | 954258e121d2436097d5fc1abc6b7d73ddd784f6 (diff) |
gpu: nvgpu: Implement a vidmem allocator
Implement an allocator suitable for managing the video memory on dGPUs.
It works by allocating chunks from an underlying buddy allocator and
collating the chunks together (similar to what an sgt does in the
wider Linux kernel). This handles the ability to get large buffers in
potentially fragmented memory. The GMMU can then obviously map the
physical vidmem into contiguous GVA spaces.
Jira DNVGPU-96
Change-Id: Ic1d7800b033a170b77790aa23fad6858443d0e89
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: http://git-master/r/1197203
(cherry picked from commit fa44684a843956ae384fef6d7a79b9cbbd04f73e)
Reviewed-on: http://git-master/r/1185231
GVS: Gerrit_Virtual_Submit
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/page_allocator_priv.h')
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/page_allocator_priv.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/page_allocator_priv.h b/drivers/gpu/nvgpu/gk20a/page_allocator_priv.h new file mode 100644 index 00000000..bce5b75e --- /dev/null +++ b/drivers/gpu/nvgpu/gk20a/page_allocator_priv.h | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016, 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 PAGE_ALLOCATOR_PRIV_H | ||
18 | #define PAGE_ALLOCATOR_PRIV_H | ||
19 | |||
20 | #include <linux/list.h> | ||
21 | #include <linux/rbtree.h> | ||
22 | |||
23 | #include "gk20a_allocator.h" | ||
24 | |||
25 | struct gk20a_allocator; | ||
26 | |||
27 | struct page_alloc_chunk { | ||
28 | struct list_head list_entry; | ||
29 | |||
30 | u64 base; | ||
31 | u64 length; | ||
32 | }; | ||
33 | |||
34 | /* | ||
35 | * Struct to handle internal management of page allocation. It holds a list | ||
36 | * of the chunks of page that make up the overall allocation - much like a | ||
37 | * scatter gather table. | ||
38 | */ | ||
39 | struct gk20a_page_alloc { | ||
40 | struct list_head alloc_chunks; | ||
41 | |||
42 | int nr_chunks; | ||
43 | u64 length; | ||
44 | |||
45 | /* | ||
46 | * Only useful for the RB tree - since the alloc will have discontiguous | ||
47 | * pages the base is essentially irrelevant except for the fact that it | ||
48 | * is guarenteed to be unique. | ||
49 | */ | ||
50 | u64 base; | ||
51 | |||
52 | struct rb_node tree_entry; | ||
53 | }; | ||
54 | |||
55 | struct gk20a_page_allocator { | ||
56 | struct gk20a_allocator *owner; /* Owner of this allocator. */ | ||
57 | |||
58 | /* | ||
59 | * Use a buddy allocator to manage the allocation of the underlying | ||
60 | * pages. This lets us abstract the discontiguous allocation handling | ||
61 | * out of the annoyingly complicated buddy allocator. | ||
62 | */ | ||
63 | struct gk20a_allocator source_allocator; | ||
64 | |||
65 | /* | ||
66 | * Page params. | ||
67 | */ | ||
68 | u64 base; | ||
69 | u64 length; | ||
70 | u64 page_size; | ||
71 | u32 page_shift; | ||
72 | |||
73 | struct rb_root allocs; /* Outstanding allocations. */ | ||
74 | |||
75 | u64 flags; | ||
76 | |||
77 | /* | ||
78 | * Stat tracking. | ||
79 | */ | ||
80 | u64 nr_allocs; | ||
81 | u64 nr_frees; | ||
82 | u64 nr_fixed_allocs; | ||
83 | u64 nr_fixed_frees; | ||
84 | u64 pages_alloced; | ||
85 | u64 pages_freed; | ||
86 | }; | ||
87 | |||
88 | static inline struct gk20a_page_allocator *page_allocator( | ||
89 | struct gk20a_allocator *a) | ||
90 | { | ||
91 | return (struct gk20a_page_allocator *)(a)->priv; | ||
92 | } | ||
93 | |||
94 | static inline struct gk20a_allocator *palloc_owner( | ||
95 | struct gk20a_page_allocator *a) | ||
96 | { | ||
97 | return a->owner; | ||
98 | } | ||
99 | |||
100 | #endif | ||