mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-24 10:34:43 +03:00
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 <rizhao@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1649935 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
649ba2a4b3
commit
5025350b80
@@ -177,7 +177,8 @@ nvgpu-$(CONFIG_TEGRA_GR_VIRTUALIZATION) += \
|
||||
common/linux/vgpu/css_vgpu.o \
|
||||
common/linux/vgpu/gm20b/vgpu_gr_gm20b.o \
|
||||
common/linux/vgpu/sysfs_vgpu.o \
|
||||
common/linux/vgpu/vgpu_ivc.o
|
||||
common/linux/vgpu/vgpu_ivc.o \
|
||||
common/linux/vgpu/vgpu_ivm.o
|
||||
|
||||
nvgpu-$(CONFIG_COMMON_CLK) += \
|
||||
common/linux/clk.o
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
#if defined(CONFIG_GK20A_CYCLE_STATS)
|
||||
|
||||
#include <linux/tegra-ivc.h>
|
||||
#include <nvgpu/vgpu/vgpu_ivm.h>
|
||||
#include <linux/tegra_vgpu.h>
|
||||
#include <uapi/linux/nvgpu.h>
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
#include <linux/string.h>
|
||||
#include <linux/tegra-ivc.h>
|
||||
#include <linux/tegra_vgpu.h>
|
||||
|
||||
#include <uapi/linux/nvgpu.h>
|
||||
@@ -24,6 +23,7 @@
|
||||
#include <nvgpu/bug.h>
|
||||
#include <nvgpu/enabled.h>
|
||||
#include <nvgpu/ctxsw_trace.h>
|
||||
#include <nvgpu/vgpu/vgpu_ivm.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
38
drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c
Normal file
38
drivers/gpu/nvgpu/common/linux/vgpu/vgpu_ivm.c
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <nvgpu/vgpu/vgpu_ivm.h>
|
||||
#include <linux/tegra-ivc.h>
|
||||
|
||||
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;
|
||||
}
|
||||
35
drivers/gpu/nvgpu/include/nvgpu/vgpu/vgpu_ivm.h
Normal file
35
drivers/gpu/nvgpu/include/nvgpu/vgpu/vgpu_ivm.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __VGPU_IVM_H__
|
||||
#define __VGPU_IVM_H__
|
||||
|
||||
#include <nvgpu/types.h>
|
||||
|
||||
struct tegra_hv_ivm_cookie;
|
||||
|
||||
struct tegra_hv_ivm_cookie *vgpu_ivm_mempool_reserve(unsigned int id);
|
||||
int vgpu_ivm_mempool_unreserve(struct tegra_hv_ivm_cookie *cookie);
|
||||
u64 vgpu_ivm_get_ipa(struct tegra_hv_ivm_cookie *cookie);
|
||||
u64 vgpu_ivm_get_size(struct tegra_hv_ivm_cookie *cookie);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user