diff options
Diffstat (limited to 'drivers/gpu/nvgpu/vgpu/gv11b/vgpu_subctx_gv11b.c')
-rw-r--r-- | drivers/gpu/nvgpu/vgpu/gv11b/vgpu_subctx_gv11b.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/vgpu/gv11b/vgpu_subctx_gv11b.c b/drivers/gpu/nvgpu/vgpu/gv11b/vgpu_subctx_gv11b.c new file mode 100644 index 00000000..ba92c8d5 --- /dev/null +++ b/drivers/gpu/nvgpu/vgpu/gv11b/vgpu_subctx_gv11b.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | * copy of this software and associated documentation files (the "Software"), | ||
6 | * to deal in the Software without restriction, including without limitation | ||
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | * and/or sell copies of the Software, and to permit persons to whom the | ||
9 | * Software is furnished to do so, subject to the following conditions: | ||
10 | * | ||
11 | * The above copyright notice and this permission notice shall be included in | ||
12 | * all copies or substantial portions of the Software. | ||
13 | * | ||
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | * DEALINGS IN THE SOFTWARE. | ||
21 | */ | ||
22 | |||
23 | #include "gk20a/gk20a.h" | ||
24 | |||
25 | #include <nvgpu/vgpu/vgpu.h> | ||
26 | #include <nvgpu/vgpu/tegra_vgpu.h> | ||
27 | #include <nvgpu/hw/gv11b/hw_ctxsw_prog_gv11b.h> | ||
28 | |||
29 | int vgpu_gv11b_alloc_subctx_header(struct channel_gk20a *c) | ||
30 | { | ||
31 | struct ctx_header_desc *ctx = &c->ctx_header; | ||
32 | struct tegra_vgpu_cmd_msg msg = {}; | ||
33 | struct tegra_vgpu_alloc_ctx_header_params *p = | ||
34 | &msg.params.alloc_ctx_header; | ||
35 | int err; | ||
36 | |||
37 | msg.cmd = TEGRA_VGPU_CMD_ALLOC_CTX_HEADER; | ||
38 | msg.handle = vgpu_get_handle(c->g); | ||
39 | p->ch_handle = c->virt_ctx; | ||
40 | p->ctx_header_va = __nvgpu_vm_alloc_va(c->vm, | ||
41 | ctxsw_prog_fecs_header_v(), | ||
42 | gmmu_page_size_kernel); | ||
43 | if (!p->ctx_header_va) { | ||
44 | nvgpu_err(c->g, "alloc va failed for ctx_header"); | ||
45 | return -ENOMEM; | ||
46 | } | ||
47 | err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg)); | ||
48 | err = err ? err : msg.ret; | ||
49 | if (unlikely(err)) { | ||
50 | nvgpu_err(c->g, "alloc ctx_header failed err %d", err); | ||
51 | __nvgpu_vm_free_va(c->vm, p->ctx_header_va, | ||
52 | gmmu_page_size_kernel); | ||
53 | return err; | ||
54 | } | ||
55 | ctx->mem.gpu_va = p->ctx_header_va; | ||
56 | |||
57 | return err; | ||
58 | } | ||
59 | |||
60 | void vgpu_gv11b_free_subctx_header(struct channel_gk20a *c) | ||
61 | { | ||
62 | struct ctx_header_desc *ctx = &c->ctx_header; | ||
63 | struct tegra_vgpu_cmd_msg msg = {}; | ||
64 | struct tegra_vgpu_free_ctx_header_params *p = | ||
65 | &msg.params.free_ctx_header; | ||
66 | int err; | ||
67 | |||
68 | if (ctx->mem.gpu_va) { | ||
69 | msg.cmd = TEGRA_VGPU_CMD_FREE_CTX_HEADER; | ||
70 | msg.handle = vgpu_get_handle(c->g); | ||
71 | p->ch_handle = c->virt_ctx; | ||
72 | err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg)); | ||
73 | err = err ? err : msg.ret; | ||
74 | if (unlikely(err)) | ||
75 | nvgpu_err(c->g, "free ctx_header failed err %d", err); | ||
76 | __nvgpu_vm_free_va(c->vm, ctx->mem.gpu_va, | ||
77 | gmmu_page_size_kernel); | ||
78 | ctx->mem.gpu_va = 0; | ||
79 | } | ||
80 | } | ||