From f1613a300b1a537b46bebcc871675f503dcbaa0c Mon Sep 17 00:00:00 2001 From: Rajesh Devaraj Date: Fri, 26 May 2023 17:46:27 +0000 Subject: [PATCH] gpu: nvgpu: add get_cbm_alpha_cb_size hal Add get_cbm_alpha_cb_size hal to avoid duplication of code to new chips. Bug 4134898 Change-Id: I59fe7065b142b3296bfa3b20cb3198ac1ec859ce Signed-off-by: Rajesh Devaraj Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2911335 Reviewed-by: svc-mobile-coverity Reviewed-by: svcacv Reviewed-by: Ramalingam C Reviewed-by: Martin Radev Reviewed-by: svc-mobile-cert Reviewed-by: Vijayakumar Subbu GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/hal/gr/gr/gr_gv11b.c | 32 +++++++++++++++++------ drivers/gpu/nvgpu/hal/gr/gr/gr_gv11b.h | 3 ++- drivers/gpu/nvgpu/hal/init/hal_ga100.c | 1 + drivers/gpu/nvgpu/hal/init/hal_ga10b.c | 1 + drivers/gpu/nvgpu/hal/init/hal_gv11b.c | 1 + drivers/gpu/nvgpu/hal/init/hal_tu104.c | 1 + drivers/gpu/nvgpu/include/nvgpu/gops/gr.h | 1 + 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/nvgpu/hal/gr/gr/gr_gv11b.c b/drivers/gpu/nvgpu/hal/gr/gr/gr_gv11b.c index 452efab1d..470bf7487 100644 --- a/drivers/gpu/nvgpu/hal/gr/gr/gr_gv11b.c +++ b/drivers/gpu/nvgpu/hal/gr/gr/gr_gv11b.c @@ -1,7 +1,7 @@ /* * GV11b GPU GR * - * Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-2023, 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"), @@ -64,6 +64,11 @@ #define PRI_BROADCAST_FLAGS_SMPC BIT32(17) +u32 gv11b_gr_gpc0_ppc0_cbm_alpha_cb_size(void) +{ + return gr_gpc0_ppc0_cbm_alpha_cb_size_r(); +} + void gr_gv11b_set_alpha_circular_buffer_size(struct gk20a *g, u32 data) { struct nvgpu_gr *gr = nvgpu_gr_get_cur_instance_ptr(g); @@ -81,7 +86,7 @@ void gr_gv11b_set_alpha_circular_buffer_size(struct gk20a *g, u32 data) alpha_cb_size = alpha_cb_size_max; } - gk20a_writel(g, gr_ds_tga_constraintlogic_alpha_r(), + nvgpu_writel(g, gr_ds_tga_constraintlogic_alpha_r(), (gk20a_readl(g, gr_ds_tga_constraintlogic_alpha_r()) & ~gr_ds_tga_constraintlogic_alpha_cbsize_f(~U32(0U))) | gr_ds_tga_constraintlogic_alpha_cbsize_f(alpha_cb_size)); @@ -90,7 +95,7 @@ void gr_gv11b_set_alpha_circular_buffer_size(struct gk20a *g, u32 data) gr_gpc0_ppc0_cbm_alpha_cb_size_v_granularity_v() / gr_pd_ab_dist_cfg1_max_output_granularity_v(); - gk20a_writel(g, gr_pd_ab_dist_cfg1_r(), + nvgpu_writel(g, gr_pd_ab_dist_cfg1_r(), gr_pd_ab_dist_cfg1_max_output_f(pd_ab_max_output) | gr_pd_ab_dist_cfg1_max_batches_init_f()); @@ -103,15 +108,26 @@ void gr_gv11b_set_alpha_circular_buffer_size(struct gk20a *g, u32 data) ppc_index < nvgpu_gr_config_get_gpc_ppc_count(gr->config, gpc_index); ppc_index++) { - val = gk20a_readl(g, gr_gpc0_ppc0_cbm_alpha_cb_size_r() + - stride + ppc_in_gpc_stride * ppc_index); + val = nvgpu_readl(g, nvgpu_safe_add_u32( + nvgpu_safe_add_u32( + g->ops.gr.get_cbm_alpha_cb_size(), + stride), + nvgpu_safe_mult_u32( + ppc_in_gpc_stride, + ppc_index))); val = set_field(val, gr_gpc0_ppc0_cbm_alpha_cb_size_v_m(), gr_gpc0_ppc0_cbm_alpha_cb_size_v_f(alpha_cb_size * - nvgpu_gr_config_get_pes_tpc_count(gr->config, gpc_index, ppc_index))); + nvgpu_gr_config_get_pes_tpc_count(gr->config, + gpc_index, ppc_index))); - gk20a_writel(g, gr_gpc0_ppc0_cbm_alpha_cb_size_r() + - stride + ppc_in_gpc_stride * ppc_index, val); + nvgpu_writel(g, nvgpu_safe_add_u32( + nvgpu_safe_add_u32( + g->ops.gr.get_cbm_alpha_cb_size(), + stride), + nvgpu_safe_mult_u32( + ppc_in_gpc_stride, + ppc_index)), val); } } } diff --git a/drivers/gpu/nvgpu/hal/gr/gr/gr_gv11b.h b/drivers/gpu/nvgpu/hal/gr/gr/gr_gv11b.h index c41160577..3174cd273 100644 --- a/drivers/gpu/nvgpu/hal/gr/gr/gr_gv11b.h +++ b/drivers/gpu/nvgpu/hal/gr/gr/gr_gv11b.h @@ -1,7 +1,7 @@ /* * GV11B GPU GR * - * Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-2023, 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"), @@ -31,6 +31,7 @@ struct gk20a; struct nvgpu_warpstate; struct nvgpu_debug_context; +u32 gv11b_gr_gpc0_ppc0_cbm_alpha_cb_size(void); void gr_gv11b_set_alpha_circular_buffer_size(struct gk20a *g, u32 data); void gr_gv11b_set_circular_buffer_size(struct gk20a *g, u32 data); int gr_gv11b_dump_gr_status_regs(struct gk20a *g, diff --git a/drivers/gpu/nvgpu/hal/init/hal_ga100.c b/drivers/gpu/nvgpu/hal/init/hal_ga100.c index b87eca190..3863a77f1 100644 --- a/drivers/gpu/nvgpu/hal/init/hal_ga100.c +++ b/drivers/gpu/nvgpu/hal/init/hal_ga100.c @@ -821,6 +821,7 @@ static const struct gops_gr ga100_ops_gr = { .gr_suspend = nvgpu_gr_suspend, #ifdef CONFIG_NVGPU_DEBUGGER .get_gr_status = gr_gm20b_get_gr_status, + .get_cbm_alpha_cb_size = gv11b_gr_gpc0_ppc0_cbm_alpha_cb_size, .set_alpha_circular_buffer_size = gr_gv11b_set_alpha_circular_buffer_size, .set_circular_buffer_size = gr_ga100_set_circular_buffer_size, .get_sm_dsm_perf_regs = gv11b_gr_get_sm_dsm_perf_regs, diff --git a/drivers/gpu/nvgpu/hal/init/hal_ga10b.c b/drivers/gpu/nvgpu/hal/init/hal_ga10b.c index 977dba790..4293fcc16 100644 --- a/drivers/gpu/nvgpu/hal/init/hal_ga10b.c +++ b/drivers/gpu/nvgpu/hal/init/hal_ga10b.c @@ -829,6 +829,7 @@ static const struct gops_gr ga10b_ops_gr = { #endif #ifdef CONFIG_NVGPU_DEBUGGER .get_gr_status = gr_gm20b_get_gr_status, + .get_cbm_alpha_cb_size = gv11b_gr_gpc0_ppc0_cbm_alpha_cb_size, .set_alpha_circular_buffer_size = gr_gv11b_set_alpha_circular_buffer_size, .set_circular_buffer_size = gr_ga10b_set_circular_buffer_size, .get_sm_dsm_perf_regs = gv11b_gr_get_sm_dsm_perf_regs, diff --git a/drivers/gpu/nvgpu/hal/init/hal_gv11b.c b/drivers/gpu/nvgpu/hal/init/hal_gv11b.c index f28e4e335..3754c03b6 100644 --- a/drivers/gpu/nvgpu/hal/init/hal_gv11b.c +++ b/drivers/gpu/nvgpu/hal/init/hal_gv11b.c @@ -683,6 +683,7 @@ static const struct gops_gr gv11b_ops_gr = { #ifdef CONFIG_NVGPU_DEBUGGER .get_gr_status = gr_gm20b_get_gr_status, .set_alpha_circular_buffer_size = gr_gv11b_set_alpha_circular_buffer_size, + .get_cbm_alpha_cb_size = gv11b_gr_gpc0_ppc0_cbm_alpha_cb_size, .set_circular_buffer_size = gr_gv11b_set_circular_buffer_size, .get_sm_dsm_perf_regs = gv11b_gr_get_sm_dsm_perf_regs, .get_sm_dsm_perf_ctrl_regs = gv11b_gr_get_sm_dsm_perf_ctrl_regs, diff --git a/drivers/gpu/nvgpu/hal/init/hal_tu104.c b/drivers/gpu/nvgpu/hal/init/hal_tu104.c index 1b413bd11..537cac278 100644 --- a/drivers/gpu/nvgpu/hal/init/hal_tu104.c +++ b/drivers/gpu/nvgpu/hal/init/hal_tu104.c @@ -720,6 +720,7 @@ static const struct gops_gr tu104_ops_gr = { #ifdef CONFIG_NVGPU_DEBUGGER .get_gr_status = gr_gm20b_get_gr_status, .set_alpha_circular_buffer_size = gr_gv11b_set_alpha_circular_buffer_size, + .get_cbm_alpha_cb_size = gv11b_gr_gpc0_ppc0_cbm_alpha_cb_size, .set_circular_buffer_size = gr_gv11b_set_circular_buffer_size, .get_sm_dsm_perf_regs = gv11b_gr_get_sm_dsm_perf_regs, .get_sm_dsm_perf_ctrl_regs = gr_tu104_get_sm_dsm_perf_ctrl_regs, diff --git a/drivers/gpu/nvgpu/include/nvgpu/gops/gr.h b/drivers/gpu/nvgpu/include/nvgpu/gops/gr.h index 1a27b3585..01f527279 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/gops/gr.h +++ b/drivers/gpu/nvgpu/include/nvgpu/gops/gr.h @@ -1245,6 +1245,7 @@ struct gops_gr { /** @cond DOXYGEN_SHOULD_SKIP_THIS */ #ifdef CONFIG_NVGPU_DEBUGGER u32 (*get_gr_status)(struct gk20a *g); + u32 (*get_cbm_alpha_cb_size)(void); void (*set_alpha_circular_buffer_size)(struct gk20a *g, u32 data); void (*set_circular_buffer_size)(struct gk20a *g, u32 data);