summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux/vgpu/gv11b/vgpu_fifo_gv11b.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/vgpu/gv11b/vgpu_fifo_gv11b.c')
-rw-r--r--drivers/gpu/nvgpu/common/linux/vgpu/gv11b/vgpu_fifo_gv11b.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/gv11b/vgpu_fifo_gv11b.c b/drivers/gpu/nvgpu/common/linux/vgpu/gv11b/vgpu_fifo_gv11b.c
new file mode 100644
index 00000000..710e4b90
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/linux/vgpu/gv11b/vgpu_fifo_gv11b.c
@@ -0,0 +1,111 @@
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 <gk20a/gk20a.h>
18
19#include "common/linux/vgpu/vgpu.h"
20#include "gv11b/fifo_gv11b.h"
21#include <nvgpu/nvhost_t19x.h>
22
23#include <linux/tegra_vgpu.h>
24
25#ifdef CONFIG_TEGRA_GK20A_NVHOST
26int vgpu_gv11b_fifo_alloc_syncpt_buf(struct channel_gk20a *c,
27 u32 syncpt_id, struct nvgpu_mem *syncpt_buf)
28{
29 int err;
30 struct gk20a *g = c->g;
31 struct vm_gk20a *vm = c->vm;
32 struct tegra_vgpu_cmd_msg msg = {};
33 struct tegra_vgpu_map_syncpt_params *p = &msg.params.t19x.map_syncpt;
34
35 /*
36 * Add ro map for complete sync point shim range in vm.
37 * All channels sharing same vm will share same ro mapping.
38 * Create rw map for current channel sync point.
39 */
40 if (!vm->syncpt_ro_map_gpu_va) {
41 vm->syncpt_ro_map_gpu_va = __nvgpu_vm_alloc_va(vm,
42 g->syncpt_unit_size,
43 gmmu_page_size_kernel);
44 if (!vm->syncpt_ro_map_gpu_va) {
45 nvgpu_err(g, "allocating read-only va space failed");
46 return -ENOMEM;
47 }
48
49 msg.cmd = TEGRA_VGPU_CMD_MAP_SYNCPT;
50 msg.handle = vgpu_get_handle(g);
51 p->as_handle = c->vm->handle;
52 p->gpu_va = vm->syncpt_ro_map_gpu_va;
53 p->len = g->syncpt_unit_size;
54 p->offset = 0;
55 p->prot = TEGRA_VGPU_MAP_PROT_READ_ONLY;
56 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
57 err = err ? err : msg.ret;
58 if (err) {
59 nvgpu_err(g,
60 "mapping read-only va space failed err %d",
61 err);
62 __nvgpu_vm_free_va(c->vm, vm->syncpt_ro_map_gpu_va,
63 gmmu_page_size_kernel);
64 vm->syncpt_ro_map_gpu_va = 0;
65 return err;
66 }
67 }
68
69 syncpt_buf->gpu_va = __nvgpu_vm_alloc_va(c->vm, g->syncpt_size,
70 gmmu_page_size_kernel);
71 if (!syncpt_buf->gpu_va) {
72 nvgpu_err(g, "allocating syncpt va space failed");
73 return -ENOMEM;
74 }
75
76 msg.cmd = TEGRA_VGPU_CMD_MAP_SYNCPT;
77 msg.handle = vgpu_get_handle(g);
78 p->as_handle = c->vm->handle;
79 p->gpu_va = syncpt_buf->gpu_va;
80 p->len = g->syncpt_size;
81 p->offset =
82 nvgpu_nvhost_syncpt_unit_interface_get_byte_offset(syncpt_id);
83 p->prot = TEGRA_VGPU_MAP_PROT_NONE;
84 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
85 err = err ? err : msg.ret;
86 if (err) {
87 nvgpu_err(g, "mapping syncpt va space failed err %d", err);
88 __nvgpu_vm_free_va(c->vm, syncpt_buf->gpu_va,
89 gmmu_page_size_kernel);
90 return err;
91 }
92
93 return 0;
94}
95#endif /* CONFIG_TEGRA_GK20A_NVHOST */
96
97int vgpu_gv11b_init_fifo_setup_hw(struct gk20a *g)
98{
99 struct fifo_gk20a *f = &g->fifo;
100 int err;
101
102 err = vgpu_get_attribute(vgpu_get_handle(g),
103 TEGRA_VGPU_ATTRIB_MAX_SUBCTX_COUNT,
104 &f->t19x.max_subctx_count);
105 if (err) {
106 nvgpu_err(g, "get max_subctx_count failed %d", err);
107 return err;
108 }
109
110 return 0;
111}