mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-23 18:16:01 +03:00
Add new unit gr/config to initialize GR configuration like GPC/TPC count, MAX count and mask Create new structure nvgpu_gr_config that stores all the configuration and that is owned by the new unit Move below fields from struct gr_gk20a to nvgpu_gr_config in gr/config.h Struct gr_gk20a now only holds the pointer to struct nvgpu_gr_config u32 max_gpc_count; u32 max_tpc_per_gpc_count; u32 max_zcull_per_gpc_count; u32 max_tpc_count; u32 gpc_count; u32 tpc_count; u32 ppc_count; u32 zcb_count; u32 pe_count_per_gpc; u32 *gpc_tpc_count; u32 *gpc_ppc_count; u32 *gpc_zcb_count; u32 *pes_tpc_count[GK20A_GR_MAX_PES_PER_GPC]; u32 *gpc_tpc_mask; u32 *pes_tpc_mask[GK20A_GR_MAX_PES_PER_GPC]; u32 *gpc_skip_mask; u8 *map_tiles; u32 map_tile_count; u32 map_row_offset; Remove gr->sys_count since it was already no longer used common/gr/config/gr_config.c unit now exposes the APIs to initialize the configuration and also to query the configuration values nvgpu_gr_config_init() is called to initialize GR configuration from gr_gk20a_init_gr_config() and gr_gk20a_init_map_tiles() is simply renamed as nvgpu_gr_config_init_map_tiles() Expose new API nvgpu_gr_config_deinit() to deinit the configuration Expose nvgpu_gr_config_get_*() APIs to query above configuration fields stored in nvgpu_gr_config structure Update vgpu_gr_init_gr_config() to initialize the configuration from gr->config structure Chip specific HALs that access GR register for initialization are implemented in common/gr/config/gr_config_gm20b.c Set these HALs for all GPUs Jira NVGPU-1879 Change-Id: Ided658b43124ea61b9f273b82b73fdde4ed3c8f0 Signed-off-by: Deepak Nibade <dnibade@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/2012167 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
307 lines
8.6 KiB
C
307 lines
8.6 KiB
C
/*
|
|
* Copyright (c) 2015-2019, 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.
|
|
*/
|
|
|
|
#include <nvgpu/kmem.h>
|
|
#include <nvgpu/dma.h>
|
|
#include <nvgpu/bug.h>
|
|
#include <nvgpu/vgpu/vgpu.h>
|
|
#include <nvgpu/gk20a.h>
|
|
#include <nvgpu/channel.h>
|
|
#include <nvgpu/gr/ctx.h>
|
|
#include <nvgpu/gr/config.h>
|
|
#include <nvgpu/log.h>
|
|
|
|
#include "vgpu/gm20b/vgpu_gr_gm20b.h"
|
|
|
|
#include "gp10b/gr_gp10b.h"
|
|
#include "vgpu_gr_gp10b.h"
|
|
|
|
#include <nvgpu/hw/gp10b/hw_gr_gp10b.h>
|
|
|
|
int vgpu_gr_gp10b_init_ctxsw_preemption_mode(struct gk20a *g,
|
|
struct nvgpu_gr_ctx *gr_ctx,
|
|
struct vm_gk20a *vm,
|
|
u32 class,
|
|
u32 flags)
|
|
{
|
|
u32 graphics_preempt_mode = 0;
|
|
u32 compute_preempt_mode = 0;
|
|
struct vgpu_priv_data *priv = vgpu_get_priv_data(g);
|
|
int err;
|
|
|
|
nvgpu_log_fn(g, " ");
|
|
|
|
if (flags & NVGPU_OBJ_CTX_FLAGS_SUPPORT_GFXP) {
|
|
graphics_preempt_mode = NVGPU_PREEMPTION_MODE_GRAPHICS_GFXP;
|
|
}
|
|
if (flags & NVGPU_OBJ_CTX_FLAGS_SUPPORT_CILP) {
|
|
compute_preempt_mode = NVGPU_PREEMPTION_MODE_COMPUTE_CILP;
|
|
}
|
|
|
|
if (priv->constants.force_preempt_mode && !graphics_preempt_mode &&
|
|
!compute_preempt_mode) {
|
|
graphics_preempt_mode = g->ops.gr.is_valid_gfx_class(g, class) ?
|
|
NVGPU_PREEMPTION_MODE_GRAPHICS_GFXP : 0;
|
|
compute_preempt_mode =
|
|
g->ops.gr.is_valid_compute_class(g, class) ?
|
|
NVGPU_PREEMPTION_MODE_COMPUTE_CTA : 0;
|
|
}
|
|
|
|
if (graphics_preempt_mode || compute_preempt_mode) {
|
|
if (g->ops.gr.set_ctxsw_preemption_mode) {
|
|
err = g->ops.gr.set_ctxsw_preemption_mode(g, gr_ctx, vm,
|
|
class, graphics_preempt_mode, compute_preempt_mode);
|
|
if (err) {
|
|
nvgpu_err(g,
|
|
"set_ctxsw_preemption_mode failed");
|
|
return err;
|
|
}
|
|
} else {
|
|
return -ENOSYS;
|
|
}
|
|
}
|
|
|
|
nvgpu_log_fn(g, "done");
|
|
return 0;
|
|
}
|
|
|
|
int vgpu_gr_gp10b_set_ctxsw_preemption_mode(struct gk20a *g,
|
|
struct nvgpu_gr_ctx *gr_ctx,
|
|
struct vm_gk20a *vm, u32 class,
|
|
u32 graphics_preempt_mode,
|
|
u32 compute_preempt_mode)
|
|
{
|
|
struct tegra_vgpu_cmd_msg msg = {};
|
|
struct tegra_vgpu_gr_bind_ctxsw_buffers_params *p =
|
|
&msg.params.gr_bind_ctxsw_buffers;
|
|
int err = 0;
|
|
|
|
if (g->ops.gr.is_valid_gfx_class(g, class) &&
|
|
g->gr.ctx_vars.force_preemption_gfxp) {
|
|
graphics_preempt_mode = NVGPU_PREEMPTION_MODE_GRAPHICS_GFXP;
|
|
}
|
|
|
|
if (g->ops.gr.is_valid_compute_class(g, class) &&
|
|
g->gr.ctx_vars.force_preemption_cilp) {
|
|
compute_preempt_mode = NVGPU_PREEMPTION_MODE_COMPUTE_CILP;
|
|
}
|
|
|
|
/* check for invalid combinations */
|
|
if ((graphics_preempt_mode == 0) && (compute_preempt_mode == 0)) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
if ((graphics_preempt_mode == NVGPU_PREEMPTION_MODE_GRAPHICS_GFXP) &&
|
|
(compute_preempt_mode == NVGPU_PREEMPTION_MODE_COMPUTE_CILP)) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* set preemption modes */
|
|
switch (graphics_preempt_mode) {
|
|
case NVGPU_PREEMPTION_MODE_GRAPHICS_GFXP:
|
|
{
|
|
u32 spill_size =
|
|
gr_gpc0_swdx_rm_spill_buffer_size_256b_default_v() *
|
|
gr_gpc0_swdx_rm_spill_buffer_size_256b_byte_granularity_v();
|
|
u32 pagepool_size = g->ops.gr.pagepool_default_size(g) *
|
|
gr_scc_pagepool_total_pages_byte_granularity_v();
|
|
u32 betacb_size = g->gr.attrib_cb_default_size +
|
|
(gr_gpc0_ppc0_cbm_beta_cb_size_v_gfxp_v() -
|
|
gr_gpc0_ppc0_cbm_beta_cb_size_v_default_v());
|
|
u32 attrib_cb_size = (betacb_size + g->gr.alpha_cb_size) *
|
|
gr_gpc0_ppc0_cbm_beta_cb_size_v_granularity_v() *
|
|
nvgpu_gr_config_get_max_tpc_count(g->gr.config);
|
|
struct nvgpu_mem *desc;
|
|
|
|
attrib_cb_size = ALIGN(attrib_cb_size, 128);
|
|
|
|
nvgpu_log_info(g, "gfxp context preempt size=%d",
|
|
g->gr.ctx_vars.preempt_image_size);
|
|
nvgpu_log_info(g, "gfxp context spill size=%d", spill_size);
|
|
nvgpu_log_info(g, "gfxp context pagepool size=%d", pagepool_size);
|
|
nvgpu_log_info(g, "gfxp context attrib cb size=%d",
|
|
attrib_cb_size);
|
|
|
|
nvgpu_gr_ctx_set_size(g->gr.gr_ctx_desc,
|
|
NVGPU_GR_CTX_PREEMPT_CTXSW,
|
|
g->gr.ctx_vars.preempt_image_size);
|
|
nvgpu_gr_ctx_set_size(g->gr.gr_ctx_desc,
|
|
NVGPU_GR_CTX_SPILL_CTXSW, spill_size);
|
|
nvgpu_gr_ctx_set_size(g->gr.gr_ctx_desc,
|
|
NVGPU_GR_CTX_BETACB_CTXSW, attrib_cb_size);
|
|
nvgpu_gr_ctx_set_size(g->gr.gr_ctx_desc,
|
|
NVGPU_GR_CTX_PAGEPOOL_CTXSW, pagepool_size);
|
|
|
|
err = nvgpu_gr_ctx_alloc_ctxsw_buffers(g, gr_ctx,
|
|
g->gr.gr_ctx_desc, vm);
|
|
if (err != 0) {
|
|
nvgpu_err(g, "cannot allocate ctxsw buffers");
|
|
goto fail;
|
|
}
|
|
|
|
desc = &gr_ctx->preempt_ctxsw_buffer;
|
|
p->gpu_va[TEGRA_VGPU_GR_BIND_CTXSW_BUFFER_MAIN] = desc->gpu_va;
|
|
p->size[TEGRA_VGPU_GR_BIND_CTXSW_BUFFER_MAIN] = desc->size;
|
|
|
|
desc = &gr_ctx->spill_ctxsw_buffer;
|
|
p->gpu_va[TEGRA_VGPU_GR_BIND_CTXSW_BUFFER_SPILL] = desc->gpu_va;
|
|
p->size[TEGRA_VGPU_GR_BIND_CTXSW_BUFFER_SPILL] = desc->size;
|
|
|
|
desc = &gr_ctx->pagepool_ctxsw_buffer;
|
|
p->gpu_va[TEGRA_VGPU_GR_BIND_CTXSW_BUFFER_PAGEPOOL] =
|
|
desc->gpu_va;
|
|
p->size[TEGRA_VGPU_GR_BIND_CTXSW_BUFFER_PAGEPOOL] = desc->size;
|
|
|
|
desc = &gr_ctx->betacb_ctxsw_buffer;
|
|
p->gpu_va[TEGRA_VGPU_GR_BIND_CTXSW_BUFFER_BETACB] =
|
|
desc->gpu_va;
|
|
p->size[TEGRA_VGPU_GR_BIND_CTXSW_BUFFER_BETACB] = desc->size;
|
|
|
|
gr_ctx->graphics_preempt_mode = NVGPU_PREEMPTION_MODE_GRAPHICS_GFXP;
|
|
p->mode = TEGRA_VGPU_GR_CTXSW_PREEMPTION_MODE_GFX_GFXP;
|
|
break;
|
|
}
|
|
case NVGPU_PREEMPTION_MODE_GRAPHICS_WFI:
|
|
gr_ctx->graphics_preempt_mode = graphics_preempt_mode;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (g->ops.gr.is_valid_compute_class(g, class)) {
|
|
switch (compute_preempt_mode) {
|
|
case NVGPU_PREEMPTION_MODE_COMPUTE_WFI:
|
|
gr_ctx->compute_preempt_mode =
|
|
NVGPU_PREEMPTION_MODE_COMPUTE_WFI;
|
|
p->mode = TEGRA_VGPU_GR_CTXSW_PREEMPTION_MODE_WFI;
|
|
break;
|
|
case NVGPU_PREEMPTION_MODE_COMPUTE_CTA:
|
|
gr_ctx->compute_preempt_mode =
|
|
NVGPU_PREEMPTION_MODE_COMPUTE_CTA;
|
|
p->mode =
|
|
TEGRA_VGPU_GR_CTXSW_PREEMPTION_MODE_COMPUTE_CTA;
|
|
break;
|
|
case NVGPU_PREEMPTION_MODE_COMPUTE_CILP:
|
|
gr_ctx->compute_preempt_mode =
|
|
NVGPU_PREEMPTION_MODE_COMPUTE_CILP;
|
|
p->mode =
|
|
TEGRA_VGPU_GR_CTXSW_PREEMPTION_MODE_COMPUTE_CILP;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (gr_ctx->graphics_preempt_mode || gr_ctx->compute_preempt_mode) {
|
|
msg.cmd = TEGRA_VGPU_CMD_BIND_GR_CTXSW_BUFFERS;
|
|
msg.handle = vgpu_get_handle(g);
|
|
p->tsg_id = gr_ctx->tsgid;
|
|
err = vgpu_comm_sendrecv(&msg, sizeof(msg), sizeof(msg));
|
|
if (err || msg.ret) {
|
|
err = -ENOMEM;
|
|
goto fail;
|
|
}
|
|
}
|
|
|
|
return err;
|
|
|
|
fail:
|
|
nvgpu_err(g, "%s failed %d", __func__, err);
|
|
return err;
|
|
}
|
|
|
|
int vgpu_gr_gp10b_set_preemption_mode(struct channel_gk20a *ch,
|
|
u32 graphics_preempt_mode,
|
|
u32 compute_preempt_mode)
|
|
{
|
|
struct nvgpu_gr_ctx *gr_ctx;
|
|
struct gk20a *g = ch->g;
|
|
struct tsg_gk20a *tsg;
|
|
struct vm_gk20a *vm;
|
|
u32 class;
|
|
int err;
|
|
|
|
class = ch->obj_class;
|
|
if (!class) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
tsg = tsg_gk20a_from_ch(ch);
|
|
if (!tsg) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
vm = tsg->vm;
|
|
gr_ctx = tsg->gr_ctx;
|
|
|
|
/* skip setting anything if both modes are already set */
|
|
if (graphics_preempt_mode &&
|
|
(graphics_preempt_mode == gr_ctx->graphics_preempt_mode)) {
|
|
graphics_preempt_mode = 0;
|
|
}
|
|
|
|
if (compute_preempt_mode &&
|
|
(compute_preempt_mode == gr_ctx->compute_preempt_mode)) {
|
|
compute_preempt_mode = 0;
|
|
}
|
|
|
|
if (graphics_preempt_mode == 0 && compute_preempt_mode == 0) {
|
|
return 0;
|
|
}
|
|
|
|
if (g->ops.gr.set_ctxsw_preemption_mode) {
|
|
err = g->ops.gr.set_ctxsw_preemption_mode(g, gr_ctx, vm, class,
|
|
graphics_preempt_mode,
|
|
compute_preempt_mode);
|
|
if (err) {
|
|
nvgpu_err(g, "set_ctxsw_preemption_mode failed");
|
|
return err;
|
|
}
|
|
} else {
|
|
err = -ENOSYS;
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
int vgpu_gr_gp10b_init_ctx_state(struct gk20a *g)
|
|
{
|
|
struct vgpu_priv_data *priv = vgpu_get_priv_data(g);
|
|
int err;
|
|
|
|
nvgpu_log_fn(g, " ");
|
|
|
|
err = vgpu_gr_init_ctx_state(g);
|
|
if (err) {
|
|
return err;
|
|
}
|
|
|
|
g->gr.ctx_vars.preempt_image_size =
|
|
priv->constants.preempt_ctx_size;
|
|
if (!g->gr.ctx_vars.preempt_image_size) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|