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