From 0c297ce7524bd029a6f8ebce6d6ff6a30eb4553a Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Thu, 11 Apr 2019 19:34:46 +0530 Subject: [PATCH] gpu: nvgpu: use API to get golden image size Use API nvgpu_gr_obj_ctx_get/set_golden_image_size() exposed by gr.obj_ctx unit to get/set size of golden image Call nvgpu_gr_obj_ctx_init() from vgpu_gr_init_gr_setup_sw() to initialize golden image size in gr.obj_ctx unit even on vGPU Move g->ops.gr.falcon.init_ctx_state() call early in vgpu_gr_init_gr_setup_sw() so that gr.ctx_vars struct is prepared before fields in it accessed during rest of GR initialization Jira NVGPU-3112 Change-Id: Ie827ad6f30cc3d931519a1f9a709861d26f8da26 Signed-off-by: Deepak Nibade Reviewed-on: https://git-master.nvidia.com/r/2096162 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/vgpu/gr/ctx_vgpu.c | 10 +++++++--- drivers/gpu/nvgpu/common/vgpu/gr/gr_vgpu.c | 17 ++++++++++++----- drivers/gpu/nvgpu/gk20a/gr_gk20a.c | 7 +++++-- drivers/gpu/nvgpu/os/linux/sysfs.c | 4 ++-- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/nvgpu/common/vgpu/gr/ctx_vgpu.c b/drivers/gpu/nvgpu/common/vgpu/gr/ctx_vgpu.c index 351efd509..aed7bff4c 100644 --- a/drivers/gpu/nvgpu/common/vgpu/gr/ctx_vgpu.c +++ b/drivers/gpu/nvgpu/common/vgpu/gr/ctx_vgpu.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "common/gr/ctx_priv.h" @@ -45,22 +46,25 @@ int vgpu_gr_alloc_gr_ctx(struct gk20a *g, struct tegra_vgpu_cmd_msg msg = {0}; struct tegra_vgpu_gr_ctx_params *p = &msg.params.gr_ctx; struct gr_gk20a *gr = &g->gr; + u32 golden_image_size; int err; nvgpu_log_fn(g, " "); - if (gr->ctx_vars.golden_image_size == 0) { + golden_image_size = + nvgpu_gr_obj_ctx_get_golden_image_size(gr->golden_image); + if (golden_image_size == 0) { return -EINVAL; } gr_ctx->mem.gpu_va = nvgpu_vm_alloc_va(vm, - gr->ctx_vars.golden_image_size, + golden_image_size, GMMU_PAGE_SIZE_KERNEL); if (!gr_ctx->mem.gpu_va) { return -ENOMEM; } - gr_ctx->mem.size = gr->ctx_vars.golden_image_size; + gr_ctx->mem.size = golden_image_size; gr_ctx->mem.aperture = APERTURE_SYSMEM; msg.cmd = TEGRA_VGPU_CMD_GR_CTX_ALLOC; diff --git a/drivers/gpu/nvgpu/common/vgpu/gr/gr_vgpu.c b/drivers/gpu/nvgpu/common/vgpu/gr/gr_vgpu.c index 450abbafb..f4a55e520 100644 --- a/drivers/gpu/nvgpu/common/vgpu/gr/gr_vgpu.c +++ b/drivers/gpu/nvgpu/common/vgpu/gr/gr_vgpu.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -706,11 +707,22 @@ static int vgpu_gr_init_gr_setup_sw(struct gk20a *g) nvgpu_mutex_init(&g->gr.cs_lock); #endif + err = g->ops.gr.falcon.init_ctx_state(g); + if (err) { + goto clean_up; + } + err = vgpu_gr_init_gr_config(g, gr); if (err) { goto clean_up; } + err = nvgpu_gr_obj_ctx_init(g, &gr->golden_image, + g->gr.ctx_vars.golden_image_size); + if (err != 0) { + goto clean_up; + } + err = nvgpu_gr_hwpm_map_init(g, &g->gr.hwpm_map, g->gr.ctx_vars.pm_ctxsw_image_size); if (err != 0) { @@ -723,11 +735,6 @@ static int vgpu_gr_init_gr_setup_sw(struct gk20a *g) goto clean_up; } - err = g->ops.gr.falcon.init_ctx_state(g); - if (err) { - goto clean_up; - } - err = vgpu_gr_alloc_global_ctx_buffers(g); if (err) { goto clean_up; diff --git a/drivers/gpu/nvgpu/gk20a/gr_gk20a.c b/drivers/gpu/nvgpu/gk20a/gr_gk20a.c index 717c46a97..42f233a8d 100644 --- a/drivers/gpu/nvgpu/gk20a/gr_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/gr_gk20a.c @@ -1195,7 +1195,8 @@ int gr_gk20a_get_ctx_buffer_offsets(struct gk20a *g, is_quad, quad, nvgpu_gr_obj_ctx_get_local_golden_image_ptr( g->gr.golden_image), - g->gr.ctx_vars.golden_image_size, + nvgpu_gr_obj_ctx_get_golden_image_size( + g->gr.golden_image), &priv_offset); if (err != 0) { nvgpu_log_fn(g, "Could not determine priv_offset for addr:0x%x", @@ -2247,7 +2248,9 @@ int __gr_gk20a_exec_ctx_ops(struct channel_gk20a *ch, * don't write outside, worst case */ if ((current_mem == nvgpu_gr_ctx_get_ctx_mem(gr_ctx)) && - (offsets[j] >= g->gr.ctx_vars.golden_image_size)) { + (offsets[j] >= + nvgpu_gr_obj_ctx_get_golden_image_size( + g->gr.golden_image))) { continue; } if (pass == 0) { /* write pass */ diff --git a/drivers/gpu/nvgpu/os/linux/sysfs.c b/drivers/gpu/nvgpu/os/linux/sysfs.c index 3ef9aa2ff..7cbfed498 100644 --- a/drivers/gpu/nvgpu/os/linux/sysfs.c +++ b/drivers/gpu/nvgpu/os/linux/sysfs.c @@ -846,7 +846,7 @@ static ssize_t tpc_pg_mask_store(struct device *dev, goto exit; } - if (gr->ctx_vars.golden_image_size) { + if (nvgpu_gr_obj_ctx_get_golden_image_size(gr->golden_image) != 0) { nvgpu_err(g, "golden image size already initialized"); nvgpu_mutex_release(&g->tpc_pg_lock); return -ENODEV; @@ -890,7 +890,7 @@ static ssize_t tpc_fs_mask_store(struct device *dev, nvgpu_gr_obj_ctx_deinit(g, g->gr.golden_image); g->gr.ctx_vars.golden_image_initialized = false; - g->gr.ctx_vars.golden_image_size = 0; + nvgpu_gr_obj_ctx_set_golden_image_size(g->gr.golden_image, 0); nvgpu_gr_config_deinit(g, g->gr.config); /* Cause next poweron to reinit just gr */