diff options
Diffstat (limited to 'drivers/gpu/nvgpu/os/linux/comptags.c')
-rw-r--r-- | drivers/gpu/nvgpu/os/linux/comptags.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/os/linux/comptags.c b/drivers/gpu/nvgpu/os/linux/comptags.c new file mode 100644 index 00000000..353f6363 --- /dev/null +++ b/drivers/gpu/nvgpu/os/linux/comptags.c | |||
@@ -0,0 +1,140 @@ | |||
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 | #include <linux/dma-buf.h> | ||
18 | |||
19 | #include <nvgpu/comptags.h> | ||
20 | |||
21 | #include <nvgpu/linux/vm.h> | ||
22 | |||
23 | #include "gk20a/gk20a.h" | ||
24 | #include "dmabuf.h" | ||
25 | |||
26 | void gk20a_get_comptags(struct nvgpu_os_buffer *buf, | ||
27 | struct gk20a_comptags *comptags) | ||
28 | { | ||
29 | struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(buf->dmabuf, | ||
30 | buf->dev); | ||
31 | |||
32 | if (!comptags) | ||
33 | return; | ||
34 | |||
35 | if (!priv) { | ||
36 | memset(comptags, 0, sizeof(*comptags)); | ||
37 | return; | ||
38 | } | ||
39 | |||
40 | nvgpu_mutex_acquire(&priv->lock); | ||
41 | *comptags = priv->comptags; | ||
42 | nvgpu_mutex_release(&priv->lock); | ||
43 | } | ||
44 | |||
45 | int gk20a_alloc_or_get_comptags(struct gk20a *g, | ||
46 | struct nvgpu_os_buffer *buf, | ||
47 | struct gk20a_comptag_allocator *allocator, | ||
48 | struct gk20a_comptags *comptags) | ||
49 | { | ||
50 | struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(buf->dmabuf, | ||
51 | buf->dev); | ||
52 | u32 offset; | ||
53 | int err; | ||
54 | unsigned int ctag_granularity; | ||
55 | u32 lines; | ||
56 | |||
57 | if (!priv) | ||
58 | return -ENOSYS; | ||
59 | |||
60 | nvgpu_mutex_acquire(&priv->lock); | ||
61 | |||
62 | if (priv->comptags.allocated) { | ||
63 | /* | ||
64 | * already allocated | ||
65 | */ | ||
66 | *comptags = priv->comptags; | ||
67 | |||
68 | err = 0; | ||
69 | goto exit_locked; | ||
70 | } | ||
71 | |||
72 | ctag_granularity = g->ops.fb.compression_page_size(g); | ||
73 | lines = DIV_ROUND_UP_ULL(buf->dmabuf->size, ctag_granularity); | ||
74 | |||
75 | /* 0-sized buffer? Shouldn't occur, but let's check anyways. */ | ||
76 | if (lines < 1) { | ||
77 | err = -EINVAL; | ||
78 | goto exit_locked; | ||
79 | } | ||
80 | |||
81 | /* store the allocator so we can use it when we free the ctags */ | ||
82 | priv->comptag_allocator = allocator; | ||
83 | err = gk20a_comptaglines_alloc(allocator, &offset, lines); | ||
84 | if (!err) { | ||
85 | priv->comptags.offset = offset; | ||
86 | priv->comptags.lines = lines; | ||
87 | priv->comptags.needs_clear = true; | ||
88 | } else { | ||
89 | priv->comptags.offset = 0; | ||
90 | priv->comptags.lines = 0; | ||
91 | priv->comptags.needs_clear = false; | ||
92 | } | ||
93 | |||
94 | /* | ||
95 | * We don't report an error here if comptag alloc failed. The | ||
96 | * caller will simply fallback to incompressible kinds. It | ||
97 | * would not be safe to re-allocate comptags anyways on | ||
98 | * successive calls, as that would break map aliasing. | ||
99 | */ | ||
100 | err = 0; | ||
101 | priv->comptags.allocated = true; | ||
102 | |||
103 | *comptags = priv->comptags; | ||
104 | |||
105 | exit_locked: | ||
106 | nvgpu_mutex_release(&priv->lock); | ||
107 | |||
108 | return err; | ||
109 | } | ||
110 | |||
111 | bool gk20a_comptags_start_clear(struct nvgpu_os_buffer *buf) | ||
112 | { | ||
113 | struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(buf->dmabuf, | ||
114 | buf->dev); | ||
115 | bool clear_started = false; | ||
116 | |||
117 | if (priv) { | ||
118 | nvgpu_mutex_acquire(&priv->lock); | ||
119 | |||
120 | clear_started = priv->comptags.needs_clear; | ||
121 | |||
122 | if (!clear_started) | ||
123 | nvgpu_mutex_release(&priv->lock); | ||
124 | } | ||
125 | |||
126 | return clear_started; | ||
127 | } | ||
128 | |||
129 | void gk20a_comptags_finish_clear(struct nvgpu_os_buffer *buf, | ||
130 | bool clear_successful) | ||
131 | { | ||
132 | struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(buf->dmabuf, | ||
133 | buf->dev); | ||
134 | if (priv) { | ||
135 | if (clear_successful) | ||
136 | priv->comptags.needs_clear = false; | ||
137 | |||
138 | nvgpu_mutex_release(&priv->lock); | ||
139 | } | ||
140 | } | ||