diff --git a/drivers/gpu/nvgpu/Makefile b/drivers/gpu/nvgpu/Makefile
index 6ce6afe43..d1536395a 100644
--- a/drivers/gpu/nvgpu/Makefile
+++ b/drivers/gpu/nvgpu/Makefile
@@ -186,11 +186,11 @@ nvgpu-$(CONFIG_TEGRA_GK20A_NVHOST) += \
nvgpu-$(CONFIG_TEGRA_GR_VIRTUALIZATION) += \
os/linux/vgpu/platform_vgpu_tegra.o \
- os/linux/vgpu/fecs_trace_vgpu.o \
os/linux/vgpu/sysfs_vgpu.o \
os/linux/vgpu/vgpu_ivc.o \
os/linux/vgpu/vgpu_ivm.o \
os/linux/vgpu/vgpu_linux.o \
+ os/linux/vgpu/fecs_trace_vgpu_linux.o \
os/linux/vgpu/gv11b/platform_gv11b_vgpu_tegra.o
nvgpu-$(CONFIG_COMMON_CLK) += \
@@ -297,6 +297,7 @@ nvgpu-$(CONFIG_TEGRA_GR_VIRTUALIZATION) += \
vgpu/css_vgpu.o \
vgpu/ecc_vgpu.o \
vgpu/clk_vgpu.o \
+ vgpu/fecs_trace_vgpu.o \
vgpu/gm20b/vgpu_gr_gm20b.o \
vgpu/gp10b/vgpu_hal_gp10b.o \
vgpu/gp10b/vgpu_gr_gp10b.o \
diff --git a/drivers/gpu/nvgpu/include/nvgpu/ctxsw_trace.h b/drivers/gpu/nvgpu/include/nvgpu/ctxsw_trace.h
index 2da6b8370..8706be796 100644
--- a/drivers/gpu/nvgpu/include/nvgpu/ctxsw_trace.h
+++ b/drivers/gpu/nvgpu/include/nvgpu/ctxsw_trace.h
@@ -53,6 +53,18 @@ struct nvgpu_gpu_ctxsw_trace_filter {
u64 tag_bits[(NVGPU_GPU_CTXSW_FILTER_SIZE + 63) / 64];
};
+/* must be consistent with nvgpu_ctxsw_ring_header */
+struct nvgpu_ctxsw_ring_header_internal {
+ u32 magic;
+ u32 version;
+ u32 num_ents;
+ u32 ent_size;
+ u32 drop_count; /* excluding filtered out events */
+ u32 write_seqno;
+ u32 write_idx;
+ u32 read_idx;
+};
+
/*
* The binary format of 'struct nvgpu_gpu_ctxsw_trace_entry' introduced here
* should match that of 'struct nvgpu_ctxsw_trace_entry' defined in uapi
diff --git a/drivers/gpu/nvgpu/os/linux/vgpu/fecs_trace_vgpu_linux.c b/drivers/gpu/nvgpu/os/linux/vgpu/fecs_trace_vgpu_linux.c
new file mode 100644
index 000000000..a555e5de8
--- /dev/null
+++ b/drivers/gpu/nvgpu/os/linux/vgpu/fecs_trace_vgpu_linux.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include
+#include
+#include
+#include
+
+#include
+
+#include "vgpu/fecs_trace_vgpu.h"
+
+void vgpu_fecs_trace_data_update(struct gk20a *g)
+{
+ gk20a_ctxsw_trace_wake_up(g, 0);
+}
+
+int vgpu_alloc_user_buffer(struct gk20a *g, void **buf, size_t *size)
+{
+ struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
+
+ *buf = vcst->buf;
+ *size = vgpu_ivm_get_size(vcst->cookie);
+ return 0;
+}
+
+int vgpu_mmap_user_buffer(struct gk20a *g, struct vm_area_struct *vma)
+{
+ struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
+ unsigned long size = vgpu_ivm_get_size(vcst->cookie);
+ unsigned long vsize = vma->vm_end - vma->vm_start;
+
+ size = min(size, vsize);
+ size = round_up(size, PAGE_SIZE);
+
+ return remap_pfn_range(vma, vma->vm_start,
+ vgpu_ivm_get_ipa(vcst->cookie) >> PAGE_SHIFT,
+ size,
+ vma->vm_page_prot);
+}
diff --git a/drivers/gpu/nvgpu/os/linux/vgpu/fecs_trace_vgpu.c b/drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.c
similarity index 73%
rename from drivers/gpu/nvgpu/os/linux/vgpu/fecs_trace_vgpu.c
rename to drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.c
index 05ec208bb..c7596d11e 100644
--- a/drivers/gpu/nvgpu/os/linux/vgpu/fecs_trace_vgpu.c
+++ b/drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.c
@@ -14,54 +14,43 @@
* along with this program. If not, see .
*/
-#include
-
#include
#include
#include
#include
+#include
+#include
#include
#include
#include
#include
-#include "os/linux/os_linux.h"
#include "gk20a/fecs_trace_gk20a.h"
#include "vgpu/fecs_trace_vgpu.h"
-struct vgpu_fecs_trace {
- struct tegra_hv_ivm_cookie *cookie;
- struct nvgpu_ctxsw_ring_header *header;
- struct nvgpu_gpu_ctxsw_trace_entry *entries;
- int num_entries;
- bool enabled;
- void *buf;
-};
int vgpu_fecs_trace_init(struct gk20a *g)
{
- struct device *dev = dev_from_gk20a(g);
- struct device_node *np = dev->of_node;
- struct of_phandle_args args;
struct vgpu_fecs_trace *vcst;
u32 mempool;
int err;
nvgpu_log_fn(g, " ");
+ if (g->fecs_trace)
+ return 0;
+
vcst = nvgpu_kzalloc(g, sizeof(*vcst));
if (!vcst)
return -ENOMEM;
- err = of_parse_phandle_with_fixed_args(np,
- "mempool-fecs-trace", 1, 0, &args);
+ err = nvgpu_dt_read_u32_index(g, "mempool-fecs-trace", 1, &mempool);
if (err) {
nvgpu_info(g, "does not support fecs trace");
goto fail;
}
__nvgpu_set_enabled(g, NVGPU_SUPPORT_FECS_CTXSW_TRACE, true);
- mempool = args.args[0];
vcst->cookie = vgpu_ivm_mempool_reserve(mempool);
if (IS_ERR(vcst->cookie)) {
nvgpu_info(g,
@@ -71,8 +60,7 @@ int vgpu_fecs_trace_init(struct gk20a *g)
goto fail;
}
- vcst->buf = ioremap_cache(vgpu_ivm_get_ipa(vcst->cookie),
- vgpu_ivm_get_size(vcst->cookie));
+ vcst->buf = vgpu_ivm_mempool_map(vcst->cookie);
if (!vcst->buf) {
nvgpu_info(g, "ioremap_cache failed");
err = -EINVAL;
@@ -84,12 +72,15 @@ int vgpu_fecs_trace_init(struct gk20a *g)
nvgpu_err(g, "entry size mismatch");
goto fail;
}
- vcst->entries = vcst->buf + sizeof(*vcst->header);
+ vcst->entries = (struct nvgpu_gpu_ctxsw_trace_entry *)(
+ (char *)vcst->buf + sizeof(*vcst->header));
g->fecs_trace = (struct gk20a_fecs_trace *)vcst;
return 0;
fail:
- iounmap(vcst->buf);
+ if (vcst->cookie != NULL && vcst->buf != NULL) {
+ vgpu_ivm_mempool_unmap(vcst->cookie, vcst->buf);
+ }
if (vcst->cookie)
vgpu_ivm_mempool_unreserve(vcst->cookie);
nvgpu_kfree(g, vcst);
@@ -100,7 +91,7 @@ int vgpu_fecs_trace_deinit(struct gk20a *g)
{
struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
- iounmap(vcst->buf);
+ vgpu_ivm_mempool_unmap(vcst->cookie, vcst->buf);
vgpu_ivm_mempool_unreserve(vcst->cookie);
nvgpu_kfree(g, vcst);
return 0;
@@ -159,34 +150,11 @@ int vgpu_fecs_trace_poll(struct gk20a *g)
return err;
}
-int vgpu_alloc_user_buffer(struct gk20a *g, void **buf, size_t *size)
-{
- struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
-
- *buf = vcst->buf;
- *size = vgpu_ivm_get_size(vcst->cookie);
- return 0;
-}
-
int vgpu_free_user_buffer(struct gk20a *g)
{
return 0;
}
-int vgpu_mmap_user_buffer(struct gk20a *g, struct vm_area_struct *vma)
-{
- struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace;
- unsigned long size = vgpu_ivm_get_size(vcst->cookie);
- unsigned long vsize = vma->vm_end - vma->vm_start;
-
- size = min(size, vsize);
- size = round_up(size, PAGE_SIZE);
-
- return remap_pfn_range(vma, vma->vm_start,
- vgpu_ivm_get_ipa(vcst->cookie) >> PAGE_SHIFT,
- size,
- vma->vm_page_prot);
-}
#ifdef CONFIG_GK20A_CTXSW_TRACE
int vgpu_fecs_trace_max_entries(struct gk20a *g,
@@ -197,10 +165,6 @@ int vgpu_fecs_trace_max_entries(struct gk20a *g,
return vcst->header->num_ents;
}
-#if NVGPU_CTXSW_FILTER_SIZE != TEGRA_VGPU_FECS_TRACE_FILTER_SIZE
-#error "FECS trace filter size mismatch!"
-#endif
-
int vgpu_fecs_trace_set_filter(struct gk20a *g,
struct nvgpu_gpu_ctxsw_trace_filter *filter)
{
@@ -218,8 +182,4 @@ int vgpu_fecs_trace_set_filter(struct gk20a *g,
return err;
}
-void vgpu_fecs_trace_data_update(struct gk20a *g)
-{
- gk20a_ctxsw_trace_wake_up(g, 0);
-}
#endif /* CONFIG_GK20A_CTXSW_TRACE */
diff --git a/drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.h b/drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.h
index 496e18927..8d730bab1 100644
--- a/drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.h
+++ b/drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.h
@@ -28,6 +28,18 @@
struct gk20a;
struct vm_area_struct;
struct nvgpu_gpu_ctxsw_trace_filter;
+struct tegra_hv_ivm_cookie;
+struct nvgpu_gpu_ctxsw_trace_entry;
+struct nvgpu_ctxsw_ring_header_internal;
+
+struct vgpu_fecs_trace {
+ struct tegra_hv_ivm_cookie *cookie;
+ struct nvgpu_ctxsw_ring_header_internal *header;
+ struct nvgpu_gpu_ctxsw_trace_entry *entries;
+ int num_entries;
+ bool enabled;
+ void *buf;
+};
void vgpu_fecs_trace_data_update(struct gk20a *g);
int vgpu_fecs_trace_init(struct gk20a *g);
@@ -43,5 +55,6 @@ int vgpu_fecs_trace_max_entries(struct gk20a *g,
struct nvgpu_gpu_ctxsw_trace_filter *filter);
int vgpu_fecs_trace_set_filter(struct gk20a *g,
struct nvgpu_gpu_ctxsw_trace_filter *filter);
+struct tegra_hv_ivm_cookie *vgpu_fecs_trace_get_ivm(struct gk20a *g);
#endif /* __FECS_TRACE_VGPU_H */