summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c')
-rw-r--r--drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c225
1 files changed, 225 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c b/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c
new file mode 100644
index 00000000..5007de36
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c
@@ -0,0 +1,225 @@
1/*
2 * Copyright (c) 2016-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/string.h>
18#include <linux/tegra-ivc.h>
19#include <linux/tegra_vgpu.h>
20
21#include <uapi/linux/nvgpu.h>
22
23#include <nvgpu/kmem.h>
24#include <nvgpu/bug.h>
25#include <nvgpu/enabled.h>
26#include <nvgpu/ctxsw_trace.h>
27
28#include "gk20a/gk20a.h"
29#include "vgpu.h"
30#include "fecs_trace_vgpu.h"
31
32struct vgpu_fecs_trace {
33 struct tegra_hv_ivm_cookie *cookie;
34 struct nvgpu_ctxsw_ring_header *header;
35 struct nvgpu_ctxsw_trace_entry *entries;
36 int num_entries;
37 bool enabled;
38 void *buf;
39};
40
41int vgpu_fecs_trace_init(struct gk20a *g)
42{
43 struct device *dev = dev_from_gk20a(g);
44 struct device_node *np = dev->of_node;
45 struct of_phandle_args args;
46 struct device_node *hv_np;
47 struct vgpu_fecs_trace *vcst;
48 u32 mempool;
49 int err;
50
51 gk20a_dbg_fn("");
52
53 vcst = nvgpu_kzalloc(g, sizeof(*vcst));
54 if (!vcst)
55 return -ENOMEM;
56
57 err = of_parse_phandle_with_fixed_args(np,
58 "mempool-fecs-trace", 1, 0, &args);
59 if (err) {
60 dev_info(dev_from_gk20a(g), "does not support fecs trace\n");
61 goto fail;
62 }
63 __nvgpu_set_enabled(g, NVGPU_SUPPORT_FECS_CTXSW_TRACE, true);
64
65 hv_np = args.np;
66 mempool = args.args[0];
67 vcst->cookie = tegra_hv_mempool_reserve(hv_np, mempool);
68 if (IS_ERR(vcst->cookie)) {
69 dev_info(dev_from_gk20a(g),
70 "mempool %u reserve failed\n", mempool);
71 vcst->cookie = NULL;
72 err = -EINVAL;
73 goto fail;
74 }
75
76 vcst->buf = ioremap_cache(vcst->cookie->ipa, vcst->cookie->size);
77 if (!vcst->buf) {
78 dev_info(dev_from_gk20a(g), "ioremap_cache failed\n");
79 err = -EINVAL;
80 goto fail;
81 }
82 vcst->header = vcst->buf;
83 vcst->num_entries = vcst->header->num_ents;
84 if (unlikely(vcst->header->ent_size != sizeof(*vcst->entries))) {
85 dev_err(dev_from_gk20a(g),
86 "entry size mismatch\n");
87 goto fail;
88 }
89 vcst->entries = vcst->buf + sizeof(*vcst->header);
90 g->fecs_trace = (struct gk20a_fecs_trace *)vcst;
91
92 return 0;
93fail:
94 iounmap(vcst->buf);
95 if (vcst->cookie)
96 tegra_hv_mempool_unreserve(vcst->cookie);
97 nvgpu_kfree(g, vcst);
98 return err;
99}
100
101int vgpu_fecs_trace_deinit(struct gk20a *g)
102{
103 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
104
105 iounmap(vcst->buf);
106 tegra_hv_mempool_unreserve(vcst->cookie);
107 nvgpu_kfree(g, vcst);
108 return 0;
109}
110
111int vgpu_fecs_trace_enable(struct gk20a *g)
112{
113 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
114 struct tegra_vgpu_cmd_msg msg = {
115 .cmd = TEGRA_VGPU_CMD_FECS_TRACE_ENABLE,
116 .handle = vgpu_get_handle(g),
117 };
118 int err;
119
120 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
121 err = err ? err : msg.ret;
122 WARN_ON(err);
123 vcst->enabled = !err;
124 return err;
125}
126
127int vgpu_fecs_trace_disable(struct gk20a *g)
128{
129 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
130 struct tegra_vgpu_cmd_msg msg = {
131 .cmd = TEGRA_VGPU_CMD_FECS_TRACE_DISABLE,
132 .handle = vgpu_get_handle(g),
133 };
134 int err;
135
136 vcst->enabled = false;
137 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
138 err = err ? err : msg.ret;
139 WARN_ON(err);
140 return err;
141}
142
143bool vgpu_fecs_trace_is_enabled(struct gk20a *g)
144{
145 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
146
147 return (vcst && vcst->enabled);
148}
149
150int vgpu_fecs_trace_poll(struct gk20a *g)
151{
152 struct tegra_vgpu_cmd_msg msg = {
153 .cmd = TEGRA_VGPU_CMD_FECS_TRACE_POLL,
154 .handle = vgpu_get_handle(g),
155 };
156 int err;
157
158 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
159 err = err ? err : msg.ret;
160 WARN_ON(err);
161 return err;
162}
163
164int vgpu_alloc_user_buffer(struct gk20a *g, void **buf, size_t *size)
165{
166 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
167
168 *buf = vcst->buf;
169 *size = vcst->cookie->size;
170 return 0;
171}
172
173int vgpu_free_user_buffer(struct gk20a *g)
174{
175 return 0;
176}
177
178int vgpu_mmap_user_buffer(struct gk20a *g, struct vm_area_struct *vma)
179{
180 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
181 unsigned long size = vcst->cookie->size;
182 unsigned long vsize = vma->vm_end - vma->vm_start;
183
184 size = min(size, vsize);
185 size = round_up(size, PAGE_SIZE);
186
187 return remap_pfn_range(vma, vma->vm_start,
188 vcst->cookie->ipa >> PAGE_SHIFT,
189 size,
190 vma->vm_page_prot);
191}
192
193int vgpu_fecs_trace_max_entries(struct gk20a *g,
194 struct nvgpu_ctxsw_trace_filter *filter)
195{
196 struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
197
198 return vcst->header->num_ents;
199}
200
201#if NVGPU_CTXSW_FILTER_SIZE != TEGRA_VGPU_FECS_TRACE_FILTER_SIZE
202#error "FECS trace filter size mismatch!"
203#endif
204
205int vgpu_fecs_trace_set_filter(struct gk20a *g,
206 struct nvgpu_ctxsw_trace_filter *filter)
207{
208 struct tegra_vgpu_cmd_msg msg = {
209 .cmd = TEGRA_VGPU_CMD_FECS_TRACE_SET_FILTER,
210 .handle = vgpu_get_handle(g),
211 };
212 struct tegra_vgpu_fecs_trace_filter *p = &msg.params.fecs_trace_filter;
213 int err;
214
215 memcpy(&p->tag_bits, &filter->tag_bits, sizeof(p->tag_bits));
216 err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
217 err = err ? err : msg.ret;
218 WARN_ON(err);
219 return err;
220}
221
222void vgpu_fecs_trace_data_update(struct gk20a *g)
223{
224 gk20a_ctxsw_trace_wake_up(g, 0);
225}