summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a/page_allocator_priv.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/page_allocator_priv.h')
-rw-r--r--drivers/gpu/nvgpu/gk20a/page_allocator_priv.h100
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
25struct gk20a_allocator;
26
27struct 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 */
39struct 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
55struct 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
88static inline struct gk20a_page_allocator *page_allocator(
89 struct gk20a_allocator *a)
90{
91 return (struct gk20a_page_allocator *)(a)->priv;
92}
93
94static inline struct gk20a_allocator *palloc_owner(
95 struct gk20a_page_allocator *a)
96{
97 return a->owner;
98}
99
100#endif