From 2e15a2d1accb8303c2363122c638e08ae7b70a50 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Wed, 8 Mar 2017 16:58:25 -0800 Subject: gpu: nvgpu: Use new kmem API functions (vgpu/*) Use the new kmem API functions in vgpu/*. Also reshuffle the order of some allocs in the vgpu init code to allow usage of the nvgpu kmem APIs. Bug 1799159 Bug 1823380 Change-Id: I6c6dcff03b406a260dffbf89a59b368d31a4cb2c Signed-off-by: Alex Waterman Reviewed-on: http://git-master/r/1318318 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.c | 8 +++--- drivers/gpu/nvgpu/vgpu/fifo_vgpu.c | 40 +++++++++++++++------------- drivers/gpu/nvgpu/vgpu/gp10b/vgpu_gr_gp10b.c | 4 ++- drivers/gpu/nvgpu/vgpu/gr_vgpu.c | 35 +++++++++++++----------- drivers/gpu/nvgpu/vgpu/mm_vgpu.c | 11 +++++--- drivers/gpu/nvgpu/vgpu/vgpu.c | 23 +++++++++------- 6 files changed, 68 insertions(+), 53 deletions(-) (limited to 'drivers/gpu/nvgpu') diff --git a/drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.c b/drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.c index 6396ee4c..398e26b2 100644 --- a/drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.c +++ b/drivers/gpu/nvgpu/vgpu/fecs_trace_vgpu.c @@ -16,6 +16,8 @@ #include #include +#include + #include "gk20a/gk20a.h" #include "gk20a/ctxsw_trace_gk20a.h" #include "vgpu.h" @@ -42,7 +44,7 @@ static int vgpu_fecs_trace_init(struct gk20a *g) gk20a_dbg_fn(""); - vcst = kzalloc(sizeof(*vcst), GFP_KERNEL); + vcst = nvgpu_kzalloc(g, sizeof(*vcst)); if (!vcst) return -ENOMEM; @@ -91,7 +93,7 @@ fail: iounmap(vcst->buf); if (vcst->cookie) tegra_hv_mempool_unreserve(vcst->cookie); - kfree(vcst); + nvgpu_kfree(g, vcst); return err; } @@ -101,7 +103,7 @@ static int vgpu_fecs_trace_deinit(struct gk20a *g) iounmap(vcst->buf); tegra_hv_mempool_unreserve(vcst->cookie); - kfree(vcst); + nvgpu_kfree(g, vcst); return 0; } diff --git a/drivers/gpu/nvgpu/vgpu/fifo_vgpu.c b/drivers/gpu/nvgpu/vgpu/fifo_vgpu.c index 0655ea15..0c93a2ed 100644 --- a/drivers/gpu/nvgpu/vgpu/fifo_vgpu.c +++ b/drivers/gpu/nvgpu/vgpu/fifo_vgpu.c @@ -16,6 +16,8 @@ #include #include +#include + #include "vgpu/vgpu.h" #include "gk20a/ctxsw_trace_gk20a.h" @@ -192,8 +194,9 @@ static int init_runlist(struct gk20a *g, struct fifo_gk20a *f) gk20a_dbg_fn(""); f->max_runlists = g->ops.fifo.eng_runlist_base_size(); - f->runlist_info = kzalloc(sizeof(struct fifo_runlist_info_gk20a) * - f->max_runlists, GFP_KERNEL); + f->runlist_info = nvgpu_kzalloc(g, + sizeof(struct fifo_runlist_info_gk20a) * + f->max_runlists); if (!f->runlist_info) goto clean_up_runlist; @@ -204,8 +207,8 @@ static int init_runlist(struct gk20a *g, struct fifo_gk20a *f) runlist = &f->runlist_info[runlist_id]; runlist->active_channels = - kzalloc(DIV_ROUND_UP(f->num_channels, BITS_PER_BYTE), - GFP_KERNEL); + nvgpu_kzalloc(g, DIV_ROUND_UP(f->num_channels, + BITS_PER_BYTE)); if (!runlist->active_channels) goto clean_up_runlist; @@ -276,12 +279,11 @@ static int vgpu_init_fifo_setup_sw(struct gk20a *g) gk20a_dbg(gpu_dbg_map_v, "userd bar1 va = 0x%llx", f->userd.gpu_va); - f->channel = vzalloc(f->num_channels * sizeof(*f->channel)); - f->tsg = vzalloc(f->num_channels * sizeof(*f->tsg)); - f->engine_info = kzalloc(f->max_engines * sizeof(*f->engine_info), - GFP_KERNEL); - f->active_engines_list = kzalloc(f->max_engines * sizeof(u32), - GFP_KERNEL); + f->channel = nvgpu_vzalloc(g, f->num_channels * sizeof(*f->channel)); + f->tsg = nvgpu_vzalloc(g, f->num_channels * sizeof(*f->tsg)); + f->engine_info = nvgpu_kzalloc(g, f->max_engines * + sizeof(*f->engine_info)); + f->active_engines_list = nvgpu_kzalloc(g, f->max_engines * sizeof(u32)); if (!(f->channel && f->tsg && f->engine_info && f->active_engines_list)) { err = -ENOMEM; @@ -327,13 +329,13 @@ clean_up: memset(&f->userd, 0, sizeof(f->userd)); - vfree(f->channel); + nvgpu_vfree(g, f->channel); f->channel = NULL; - vfree(f->tsg); + nvgpu_vfree(g, f->tsg); f->tsg = NULL; - kfree(f->engine_info); + nvgpu_kfree(g, f->engine_info); f->engine_info = NULL; - kfree(f->active_engines_list); + nvgpu_kfree(g, f->active_engines_list); f->active_engines_list = NULL; return err; @@ -453,8 +455,8 @@ static int vgpu_fifo_preempt_tsg(struct gk20a *g, u32 tsgid) return err; } -static int vgpu_submit_runlist(u64 handle, u8 runlist_id, u16 *runlist, - u32 num_entries) +static int vgpu_submit_runlist(struct gk20a *g, u64 handle, u8 runlist_id, + u16 *runlist, u32 num_entries) { struct tegra_vgpu_cmd_msg *msg; struct tegra_vgpu_runlist_params *p; @@ -462,7 +464,7 @@ static int vgpu_submit_runlist(u64 handle, u8 runlist_id, u16 *runlist, char *ptr; int err; - msg = kmalloc(size, GFP_KERNEL); + msg = nvgpu_kmalloc(g, size); if (!msg) return -1; @@ -477,7 +479,7 @@ static int vgpu_submit_runlist(u64 handle, u8 runlist_id, u16 *runlist, err = vgpu_comm_sendrecv(msg, size, sizeof(*msg)); err = (err || msg->ret) ? -1 : 0; - kfree(msg); + nvgpu_kfree(g, msg); return err; } @@ -523,7 +525,7 @@ static int vgpu_fifo_update_runlist_locked(struct gk20a *g, u32 runlist_id, } else /* suspend to remove all channels */ count = 0; - return vgpu_submit_runlist(vgpu_get_handle(g), runlist_id, + return vgpu_submit_runlist(g, vgpu_get_handle(g), runlist_id, runlist->mem[0].cpu_va, count); } diff --git a/drivers/gpu/nvgpu/vgpu/gp10b/vgpu_gr_gp10b.c b/drivers/gpu/nvgpu/vgpu/gp10b/vgpu_gr_gp10b.c index 749d6a15..91e06138 100644 --- a/drivers/gpu/nvgpu/vgpu/gp10b/vgpu_gr_gp10b.c +++ b/drivers/gpu/nvgpu/vgpu/gp10b/vgpu_gr_gp10b.c @@ -11,6 +11,8 @@ * more details. */ +#include + #include "vgpu/vgpu.h" #include "vgpu/gm20b/vgpu_gr_gm20b.h" @@ -44,7 +46,7 @@ static void vgpu_gr_gp10b_free_gr_ctx(struct gk20a *g, struct vm_gk20a *vm, gk20a_gmmu_unmap_free(vm, &gr_ctx->t18x.spill_ctxsw_buffer); gk20a_gmmu_unmap_free(vm, &gr_ctx->t18x.preempt_ctxsw_buffer); - kfree(gr_ctx); + nvgpu_kfree(g, gr_ctx); } static int vgpu_gr_gp10b_alloc_gr_ctx(struct gk20a *g, diff --git a/drivers/gpu/nvgpu/vgpu/gr_vgpu.c b/drivers/gpu/nvgpu/vgpu/gr_vgpu.c index a98c9d38..c6a51719 100644 --- a/drivers/gpu/nvgpu/vgpu/gr_vgpu.c +++ b/drivers/gpu/nvgpu/vgpu/gr_vgpu.c @@ -13,6 +13,8 @@ * more details. */ +#include + #include "vgpu/vgpu.h" #include "gk20a/dbg_gpu_gk20a.h" @@ -269,7 +271,7 @@ int vgpu_gr_alloc_gr_ctx(struct gk20a *g, gr->ctx_vars.buffer_size = gr->ctx_vars.golden_image_size; gr->ctx_vars.buffer_total_size = gr->ctx_vars.golden_image_size; - gr_ctx = kzalloc(sizeof(*gr_ctx), GFP_KERNEL); + gr_ctx = nvgpu_kzalloc(g, sizeof(*gr_ctx)); if (!gr_ctx) return -ENOMEM; @@ -279,7 +281,7 @@ int vgpu_gr_alloc_gr_ctx(struct gk20a *g, gmmu_page_size_kernel); if (!gr_ctx->mem.gpu_va) { - kfree(gr_ctx); + nvgpu_kfree(g, gr_ctx); return -ENOMEM; } @@ -295,7 +297,7 @@ int vgpu_gr_alloc_gr_ctx(struct gk20a *g, gk20a_err(dev_from_gk20a(g), "fail to alloc gr_ctx"); gk20a_vm_free_va(vm, gr_ctx->mem.gpu_va, gr_ctx->mem.size, gmmu_page_size_kernel); - kfree(gr_ctx); + nvgpu_kfree(g, gr_ctx); } else { gr_ctx->virt_ctx = p->gr_ctx_handle; *__gr_ctx = gr_ctx; @@ -322,7 +324,7 @@ void vgpu_gr_free_gr_ctx(struct gk20a *g, struct vm_gk20a *vm, gk20a_vm_free_va(vm, gr_ctx->mem.gpu_va, gr_ctx->mem.size, gmmu_page_size_kernel); - kfree(gr_ctx); + nvgpu_kfree(g, gr_ctx); } } @@ -617,16 +619,17 @@ static int vgpu_gr_init_gr_config(struct gk20a *g, struct gr_gk20a *gr) gr->max_tpc_count = gr->max_gpc_count * gr->max_tpc_per_gpc_count; - gr->gpc_tpc_count = kzalloc(gr->gpc_count * sizeof(u32), GFP_KERNEL); + gr->gpc_tpc_count = nvgpu_kzalloc(g, gr->gpc_count * sizeof(u32)); if (!gr->gpc_tpc_count) goto cleanup; - gr->gpc_tpc_mask = kzalloc(gr->gpc_count * sizeof(u32), GFP_KERNEL); + gr->gpc_tpc_mask = nvgpu_kzalloc(g, gr->gpc_count * sizeof(u32)); if (!gr->gpc_tpc_mask) goto cleanup; - gr->sm_to_cluster = kzalloc(gr->gpc_count * gr->max_tpc_per_gpc_count * - sizeof(struct sm_info), GFP_KERNEL); + gr->sm_to_cluster = nvgpu_kzalloc(g, gr->gpc_count * + gr->max_tpc_per_gpc_count * + sizeof(struct sm_info)); if (!gr->sm_to_cluster) goto cleanup; @@ -650,10 +653,10 @@ static int vgpu_gr_init_gr_config(struct gk20a *g, struct gr_gk20a *gr) cleanup: gk20a_err(dev_from_gk20a(g), "%s: out of memory", __func__); - kfree(gr->gpc_tpc_count); + nvgpu_kfree(g, gr->gpc_tpc_count); gr->gpc_tpc_count = NULL; - kfree(gr->gpc_tpc_mask); + nvgpu_kfree(g, gr->gpc_tpc_mask); gr->gpc_tpc_mask = NULL; return -ENOMEM; @@ -838,16 +841,16 @@ static void vgpu_remove_gr_support(struct gr_gk20a *gr) gk20a_comptag_allocator_destroy(&gr->comp_tags); - kfree(gr->sm_error_states); + nvgpu_kfree(gr->g, gr->sm_error_states); gr->sm_error_states = NULL; - kfree(gr->gpc_tpc_mask); + nvgpu_kfree(gr->g, gr->gpc_tpc_mask); gr->gpc_tpc_mask = NULL; - kfree(gr->sm_to_cluster); + nvgpu_kfree(gr->g, gr->sm_to_cluster); gr->sm_to_cluster = NULL; - kfree(gr->gpc_tpc_count); + nvgpu_kfree(gr->g, gr->gpc_tpc_count); gr->gpc_tpc_count = NULL; } @@ -887,9 +890,9 @@ static int vgpu_gr_init_gr_setup_sw(struct gk20a *g) nvgpu_mutex_init(&gr->ctx_mutex); - gr->sm_error_states = kzalloc( + gr->sm_error_states = nvgpu_kzalloc(g, sizeof(struct nvgpu_dbg_gpu_sm_error_state_record) * - gr->no_of_sm, GFP_KERNEL); + gr->no_of_sm); if (!gr->sm_error_states) { err = -ENOMEM; goto clean_up; diff --git a/drivers/gpu/nvgpu/vgpu/mm_vgpu.c b/drivers/gpu/nvgpu/vgpu/mm_vgpu.c index 1bcdc17b..494bbe66 100644 --- a/drivers/gpu/nvgpu/vgpu/mm_vgpu.c +++ b/drivers/gpu/nvgpu/vgpu/mm_vgpu.c @@ -14,6 +14,9 @@ */ #include + +#include + #include "vgpu/vgpu.h" #include "gk20a/mm_gk20a.h" @@ -220,7 +223,7 @@ static void vgpu_vm_remove_support(struct vm_gk20a *vm) list_for_each_entry_safe(va_node, va_node_tmp, &vm->reserved_va_list, reserved_va_list) { list_del(&va_node->reserved_va_list); - kfree(va_node); + nvgpu_kfree(g, va_node); } msg.cmd = TEGRA_VGPU_CMD_AS_FREE_SHARE; @@ -237,7 +240,7 @@ static void vgpu_vm_remove_support(struct vm_gk20a *vm) nvgpu_mutex_release(&vm->update_gmmu_lock); /* vm is not used anymore. release it. */ - kfree(vm); + nvgpu_kfree(g, vm); } u64 vgpu_bar1_map(struct gk20a *g, struct sg_table **sgt, u64 size) @@ -297,7 +300,7 @@ static int vgpu_vm_alloc_share(struct gk20a_as_share *as_share, big_page_size = gmmu_page_sizes[gmmu_page_size_big]; - vm = kzalloc(sizeof(*vm), GFP_KERNEL); + vm = nvgpu_kzalloc(g, sizeof(*vm)); if (!vm) return -ENOMEM; @@ -421,7 +424,7 @@ clean_up_share: p->handle = vm->handle; WARN_ON(vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg)) || msg.ret); clean_up: - kfree(vm); + nvgpu_kfree(g, vm); as_share->vm = NULL; return err; } diff --git a/drivers/gpu/nvgpu/vgpu/vgpu.c b/drivers/gpu/nvgpu/vgpu/vgpu.c index df793be7..49f0fb39 100644 --- a/drivers/gpu/nvgpu/vgpu/vgpu.c +++ b/drivers/gpu/nvgpu/vgpu/vgpu.c @@ -198,7 +198,7 @@ static void vgpu_remove_support(struct gk20a *g) int err; if (g->dbg_regops_tmp_buf) - kfree(g->dbg_regops_tmp_buf); + nvgpu_kfree(g, g->dbg_regops_tmp_buf); if (g->pmu.remove_support) g->pmu.remove_support(&g->pmu); @@ -252,7 +252,7 @@ static int vgpu_init_support(struct platform_device *pdev) INIT_LIST_HEAD(&g->profiler_objects); - g->dbg_regops_tmp_buf = kzalloc(SZ_4K, GFP_KERNEL); + g->dbg_regops_tmp_buf = nvgpu_kzalloc(g, SZ_4K); if (!g->dbg_regops_tmp_buf) { dev_err(g->dev, "couldn't allocate regops tmp buf"); return -ENOMEM; @@ -474,7 +474,7 @@ static int vgpu_pm_qos_init(struct device *dev) struct gk20a *g = get_gk20a(dev); struct gk20a_scale_profile *profile; - profile = kzalloc(sizeof(*profile), GFP_KERNEL); + profile = nvgpu_kzalloc(g, sizeof(*profile)); if (!profile) return -ENOMEM; @@ -493,7 +493,7 @@ static void vgpu_pm_qos_remove(struct device *dev) pm_qos_remove_max_notifier(PM_QOS_GPU_FREQ_BOUNDS, &g->scale_profile->qos_notify_block); - kfree(g->scale_profile); + nvgpu_kfree(g, g->scale_profile); g->scale_profile = NULL; } @@ -556,24 +556,27 @@ int vgpu_probe(struct platform_device *pdev) gk20a_dbg_fn(""); - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - gk20a = kzalloc(sizeof(struct gk20a), GFP_KERNEL); if (!gk20a) { dev_err(dev, "couldn't allocate gk20a support"); return -ENOMEM; } - platform->g = gk20a; - platform->vgpu_priv = priv; gk20a->dev = dev; gk20a->is_fmodel = platform->is_fmodel; nvgpu_kmem_init(gk20a); + priv = nvgpu_kzalloc(gk20a, sizeof(*priv)); + if (!priv) { + kfree(gk20a); + return -ENOMEM; + } + + platform->g = gk20a; + platform->vgpu_priv = priv; + err = gk20a_user_init(dev, INTERFACE_NAME, &nvgpu_class); if (err) return err; -- cgit v1.2.2