aboutsummaryrefslogtreecommitdiffstats
path: root/include/os/linux/cde.c
diff options
context:
space:
mode:
authorJoshua Bakita <bakitajoshua@gmail.com>2023-06-28 18:24:25 -0400
committerJoshua Bakita <bakitajoshua@gmail.com>2023-06-28 18:24:25 -0400
commit01e6fac4d61fdd7fff5433942ec93fc2ea1e4df1 (patch)
tree4ef34501728a087be24f4ba0af90f91486bf780b /include/os/linux/cde.c
parent306a03d18b305e4e573be3b2931978fa10679eb9 (diff)
Include nvgpu headers
These are needed to build on NVIDIA's Jetson boards for the time being. Only a couple structs are required, so it should be fairly easy to remove this dependency at some point in the future.
Diffstat (limited to 'include/os/linux/cde.c')
-rw-r--r--include/os/linux/cde.c1794
1 files changed, 1794 insertions, 0 deletions
diff --git a/include/os/linux/cde.c b/include/os/linux/cde.c
new file mode 100644
index 0000000..715513c
--- /dev/null
+++ b/include/os/linux/cde.c
@@ -0,0 +1,1794 @@
1/*
2 * Color decompression engine support
3 *
4 * Copyright (c) 2014-2018, NVIDIA Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/dma-mapping.h>
20#include <linux/fs.h>
21#include <linux/dma-buf.h>
22#include <uapi/linux/nvgpu.h>
23
24#include <trace/events/gk20a.h>
25
26#include <nvgpu/dma.h>
27#include <nvgpu/gmmu.h>
28#include <nvgpu/timers.h>
29#include <nvgpu/nvgpu_common.h>
30#include <nvgpu/kmem.h>
31#include <nvgpu/log.h>
32#include <nvgpu/bug.h>
33#include <nvgpu/firmware.h>
34#include <nvgpu/os_sched.h>
35#include <nvgpu/channel.h>
36#include <nvgpu/utils.h>
37#include <nvgpu/gk20a.h>
38
39#include <nvgpu/linux/vm.h>
40
41#include "gk20a/mm_gk20a.h"
42#include "gk20a/fence_gk20a.h"
43#include "gk20a/gr_gk20a.h"
44
45#include "cde.h"
46#include "os_linux.h"
47#include "dmabuf.h"
48#include "channel.h"
49#include "cde_gm20b.h"
50#include "cde_gp10b.h"
51
52#include <nvgpu/hw/gk20a/hw_ccsr_gk20a.h>
53#include <nvgpu/hw/gk20a/hw_pbdma_gk20a.h>
54
55static int gk20a_cde_load(struct gk20a_cde_ctx *cde_ctx);
56static struct gk20a_cde_ctx *gk20a_cde_allocate_context(struct nvgpu_os_linux *l);
57
58#define CTX_DELETE_TIME 1000
59
60#define MAX_CTX_USE_COUNT 42
61#define MAX_CTX_RETRY_TIME 2000
62
63static dma_addr_t gpuva_to_iova_base(struct vm_gk20a *vm, u64 gpu_vaddr)
64{
65 struct nvgpu_mapped_buf *buffer;
66 dma_addr_t addr = 0;
67 struct gk20a *g = gk20a_from_vm(vm);
68
69 nvgpu_mutex_acquire(&vm->update_gmmu_lock);
70 buffer = __nvgpu_vm_find_mapped_buf(vm, gpu_vaddr);
71 if (buffer)
72 addr = nvgpu_mem_get_addr_sgl(g, buffer->os_priv.sgt->sgl);
73 nvgpu_mutex_release(&vm->update_gmmu_lock);
74
75 return addr;
76}
77
78static void gk20a_deinit_cde_img(struct gk20a_cde_ctx *cde_ctx)
79{
80 unsigned int i;
81
82 for (i = 0; i < cde_ctx->num_bufs; i++) {
83 struct nvgpu_mem *mem = cde_ctx->mem + i;
84 nvgpu_dma_unmap_free(cde_ctx->vm, mem);
85 }
86
87 nvgpu_kfree(&cde_ctx->l->g, cde_ctx->init_convert_cmd);
88
89 cde_ctx->convert_cmd = NULL;
90 cde_ctx->init_convert_cmd = NULL;
91 cde_ctx->num_bufs = 0;
92 cde_ctx->num_params = 0;
93 cde_ctx->init_cmd_num_entries = 0;
94 cde_ctx->convert_cmd_num_entries = 0;
95 cde_ctx->init_cmd_executed = false;
96}
97
98static void gk20a_cde_remove_ctx(struct gk20a_cde_ctx *cde_ctx)
99__must_hold(&cde_app->mutex)
100{
101 struct nvgpu_os_linux *l = cde_ctx->l;
102 struct gk20a *g = &l->g;
103 struct channel_gk20a *ch = cde_ctx->ch;
104 struct vm_gk20a *vm = ch->vm;
105
106 trace_gk20a_cde_remove_ctx(cde_ctx);
107
108 /* release mapped memory */
109 gk20a_deinit_cde_img(cde_ctx);
110 nvgpu_gmmu_unmap(vm, &g->gr.compbit_store.mem,
111 cde_ctx->backing_store_vaddr);
112
113 /*
114 * free the channel
115 * gk20a_channel_close() will also unbind the channel from TSG
116 */
117 gk20a_channel_close(ch);
118 nvgpu_ref_put(&cde_ctx->tsg->refcount, gk20a_tsg_release);
119
120 /* housekeeping on app */
121 nvgpu_list_del(&cde_ctx->list);
122 l->cde_app.ctx_count--;
123 nvgpu_kfree(g, cde_ctx);
124}
125
126static void gk20a_cde_cancel_deleter(struct gk20a_cde_ctx *cde_ctx,
127 bool wait_finish)
128__releases(&cde_app->mutex)
129__acquires(&cde_app->mutex)
130{
131 struct gk20a_cde_app *cde_app = &cde_ctx->l->cde_app;
132
133 /* permanent contexts do not have deleter works */
134 if (!cde_ctx->is_temporary)
135 return;
136
137 if (wait_finish) {
138 nvgpu_mutex_release(&cde_app->mutex);
139 cancel_delayed_work_sync(&cde_ctx->ctx_deleter_work);
140 nvgpu_mutex_acquire(&cde_app->mutex);
141 } else {
142 cancel_delayed_work(&cde_ctx->ctx_deleter_work);
143 }
144}
145
146static void gk20a_cde_remove_contexts(struct nvgpu_os_linux *l)
147__must_hold(&l->cde_app->mutex)
148{
149 struct gk20a_cde_app *cde_app = &l->cde_app;
150 struct gk20a_cde_ctx *cde_ctx, *cde_ctx_save;
151
152 /* safe to go off the mutex in cancel_deleter since app is
153 * deinitialised; no new jobs are started. deleter works may be only at
154 * waiting for the mutex or before, going to abort */
155
156 nvgpu_list_for_each_entry_safe(cde_ctx, cde_ctx_save,
157 &cde_app->free_contexts, gk20a_cde_ctx, list) {
158 gk20a_cde_cancel_deleter(cde_ctx, true);
159 gk20a_cde_remove_ctx(cde_ctx);
160 }
161
162 nvgpu_list_for_each_entry_safe(cde_ctx, cde_ctx_save,
163 &cde_app->used_contexts, gk20a_cde_ctx, list) {
164 gk20a_cde_cancel_deleter(cde_ctx, true);
165 gk20a_cde_remove_ctx(cde_ctx);
166 }
167}
168
169static void gk20a_cde_stop(struct nvgpu_os_linux *l)
170__must_hold(&l->cde_app->mutex)
171{
172 struct gk20a_cde_app *cde_app = &l->cde_app;
173
174 /* prevent further conversions and delayed works from working */
175 cde_app->initialised = false;
176 /* free all data, empty the list */
177 gk20a_cde_remove_contexts(l);
178}
179
180void gk20a_cde_destroy(struct nvgpu_os_linux *l)
181__acquires(&l->cde_app->mutex)
182__releases(&l->cde_app->mutex)
183{
184 struct gk20a_cde_app *cde_app = &l->cde_app;
185
186 if (!cde_app->initialised)
187 return;
188
189 nvgpu_mutex_acquire(&cde_app->mutex);
190 gk20a_cde_stop(l);
191 nvgpu_mutex_release(&cde_app->mutex);
192
193 nvgpu_mutex_destroy(&cde_app->mutex);
194}
195
196void gk20a_cde_suspend(struct nvgpu_os_linux *l)
197__acquires(&l->cde_app->mutex)
198__releases(&l->cde_app->mutex)
199{
200 struct gk20a_cde_app *cde_app = &l->cde_app;
201 struct gk20a_cde_ctx *cde_ctx, *cde_ctx_save;
202
203 if (!cde_app->initialised)
204 return;
205
206 nvgpu_mutex_acquire(&cde_app->mutex);
207
208 nvgpu_list_for_each_entry_safe(cde_ctx, cde_ctx_save,
209 &cde_app->free_contexts, gk20a_cde_ctx, list) {
210 gk20a_cde_cancel_deleter(cde_ctx, false);
211 }
212
213 nvgpu_list_for_each_entry_safe(cde_ctx, cde_ctx_save,
214 &cde_app->used_contexts, gk20a_cde_ctx, list) {
215 gk20a_cde_cancel_deleter(cde_ctx, false);
216 }
217
218 nvgpu_mutex_release(&cde_app->mutex);
219
220}
221
222static int gk