From 5025350b80f4ded30d6ab2ed3590c6a61937eef7 Mon Sep 17 00:00:00 2001 From: Richard Zhao Date: Fri, 26 Jan 2018 17:56:34 -0800 Subject: gpu: nvgpu: vgpu: add ivm wrappers Added vgpu_ivm_*() functions to be used by os agnostic code. Jira EVLR-2364 Change-Id: I4a2baebcff9723950c4fba99d0879a0c61e3e3a2 Signed-off-by: Richard Zhao Reviewed-on: https://git-master.nvidia.com/r/1649935 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c | 32 +++++++++--------- .../gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c | 17 +++++----- drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c | 38 ++++++++++++++++++++++ 3 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c (limited to 'drivers/gpu/nvgpu/common/linux') diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c b/drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c index ba13c54e..e0798475 100644 --- a/drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c +++ b/drivers/gpu/nvgpu/common/linux/vgpu/css_vgpu.c @@ -15,7 +15,7 @@ */ #if defined(CONFIG_GK20A_CYCLE_STATS) -#include +#include #include #include @@ -45,7 +45,7 @@ static struct tegra_hv_ivm_cookie *vgpu_css_reserve_mempool(struct gk20a *g) } mempool = args.args[0]; - cookie = tegra_hv_mempool_reserve(mempool); + cookie = vgpu_ivm_mempool_reserve(mempool); if (IS_ERR_OR_NULL(cookie)) { nvgpu_err(g, "mempool %u reserve failed", mempool); return ERR_PTR(-EINVAL); @@ -61,18 +61,19 @@ u32 vgpu_css_get_buffer_size(struct gk20a *g) nvgpu_log_fn(g, " "); if (css_cookie) { - nvgpu_log_info(g, "buffer size = %llu", css_cookie->size); - return (u32)css_cookie->size; + size = (u32)vgpu_ivm_get_size(css_cookie); + nvgpu_log_info(g, "buffer size = 0x%08x", size); + return size; } cookie = vgpu_css_reserve_mempool(g); if (IS_ERR(cookie)) return 0; - size = cookie->size; + size = vgpu_ivm_get_size(cookie); - tegra_hv_mempool_unreserve(cookie); - nvgpu_log_info(g, "buffer size = %u", size); + vgpu_ivm_mempool_unreserve(cookie); + nvgpu_log_info(g, "buffer size = 0x%08x", size); return size; } @@ -82,6 +83,7 @@ static int vgpu_css_init_snapshot_buffer(struct gr_gk20a *gr) struct gk20a_cs_snapshot *data = gr->cs_data; void *buf = NULL; int err; + u64 size; gk20a_dbg_fn(""); @@ -92,15 +94,15 @@ static int vgpu_css_init_snapshot_buffer(struct gr_gk20a *gr) if (IS_ERR(css_cookie)) return PTR_ERR(css_cookie); + size = vgpu_ivm_get_size(css_cookie); /* Make sure buffer size is large enough */ - if (css_cookie->size < CSS_MIN_HW_SNAPSHOT_SIZE) { - nvgpu_info(g, "mempool size %lld too small", - css_cookie->size); + if (size < CSS_MIN_HW_SNAPSHOT_SIZE) { + nvgpu_info(g, "mempool size 0x%llx too small", size); err = -ENOMEM; goto fail; } - buf = ioremap_cache(css_cookie->ipa, css_cookie->size); + buf = ioremap_cache(vgpu_ivm_get_ipa(css_cookie), size); if (!buf) { nvgpu_info(g, "ioremap_cache failed"); err = -EINVAL; @@ -109,12 +111,12 @@ static int vgpu_css_init_snapshot_buffer(struct gr_gk20a *gr) data->hw_snapshot = buf; data->hw_end = data->hw_snapshot + - css_cookie->size / sizeof(struct gk20a_cs_snapshot_fifo_entry); + size / sizeof(struct gk20a_cs_snapshot_fifo_entry); data->hw_get = data->hw_snapshot; - memset(data->hw_snapshot, 0xff, css_cookie->size); + memset(data->hw_snapshot, 0xff, size); return 0; fail: - tegra_hv_mempool_unreserve(css_cookie); + vgpu_ivm_mempool_unreserve(css_cookie); css_cookie = NULL; return err; } @@ -129,7 +131,7 @@ void vgpu_css_release_snapshot_buffer(struct gr_gk20a *gr) iounmap(data->hw_snapshot); data->hw_snapshot = NULL; - tegra_hv_mempool_unreserve(css_cookie); + vgpu_ivm_mempool_unreserve(css_cookie); css_cookie = NULL; gk20a_dbg_info("cyclestats(vgpu): buffer for snapshots released\n"); diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c b/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c index bf692c4d..67a00c36 100644 --- a/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c +++ b/drivers/gpu/nvgpu/common/linux/vgpu/fecs_trace_vgpu.c @@ -15,7 +15,6 @@ */ #include -#include #include #include @@ -24,6 +23,7 @@ #include #include #include +#include #include "gk20a/gk20a.h" #include "vgpu.h" @@ -62,7 +62,7 @@ int vgpu_fecs_trace_init(struct gk20a *g) __nvgpu_set_enabled(g, NVGPU_SUPPORT_FECS_CTXSW_TRACE, true); mempool = args.args[0]; - vcst->cookie = tegra_hv_mempool_reserve(mempool); + vcst->cookie = vgpu_ivm_mempool_reserve(mempool); if (IS_ERR(vcst->cookie)) { dev_info(dev_from_gk20a(g), "mempool %u reserve failed\n", mempool); @@ -71,7 +71,8 @@ int vgpu_fecs_trace_init(struct gk20a *g) goto fail; } - vcst->buf = ioremap_cache(vcst->cookie->ipa, vcst->cookie->size); + vcst->buf = ioremap_cache(vgpu_ivm_get_ipa(vcst->cookie), + vgpu_ivm_get_size(vcst->cookie)); if (!vcst->buf) { dev_info(dev_from_gk20a(g), "ioremap_cache failed\n"); err = -EINVAL; @@ -91,7 +92,7 @@ int vgpu_fecs_trace_init(struct gk20a *g) fail: iounmap(vcst->buf); if (vcst->cookie) - tegra_hv_mempool_unreserve(vcst->cookie); + vgpu_ivm_mempool_unreserve(vcst->cookie); nvgpu_kfree(g, vcst); return err; } @@ -101,7 +102,7 @@ int vgpu_fecs_trace_deinit(struct gk20a *g) struct vgpu_fecs_trace *vcst = (struct vgpu_fecs_trace *)g->fecs_trace; iounmap(vcst->buf); - tegra_hv_mempool_unreserve(vcst->cookie); + vgpu_ivm_mempool_unreserve(vcst->cookie); nvgpu_kfree(g, vcst); return 0; } @@ -164,7 +165,7 @@ 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 = vcst->cookie->size; + *size = vgpu_ivm_get_size(vcst->cookie); return 0; } @@ -176,14 +177,14 @@ int vgpu_free_user_buffer(struct gk20a *g) 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 = vcst->cookie->size; + 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, - vcst->cookie->ipa >> PAGE_SHIFT, + vgpu_ivm_get_ipa(vcst->cookie) >> PAGE_SHIFT, size, vma->vm_page_prot); } diff --git a/drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c b/drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c new file mode 100644 index 00000000..82475cac --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c @@ -0,0 +1,38 @@ +/* + * 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 + +struct tegra_hv_ivm_cookie *vgpu_ivm_mempool_reserve(unsigned int id) +{ + return tegra_hv_mempool_reserve(id); +} + +int vgpu_ivm_mempool_unreserve(struct tegra_hv_ivm_cookie *cookie) +{ + return tegra_hv_mempool_unreserve(cookie); +} + +u64 vgpu_ivm_get_ipa(struct tegra_hv_ivm_cookie *cookie) +{ + return cookie->ipa; +} + +u64 vgpu_ivm_get_size(struct tegra_hv_ivm_cookie *cookie) +{ + return cookie->size; +} -- cgit v1.2.2