From 83dbb711bbff691ca010a62f80e4971fb61e7df6 Mon Sep 17 00:00:00 2001 From: Sagar Kamble Date: Thu, 21 Oct 2021 15:37:06 +0530 Subject: [PATCH] gpu: nvgpu: make buffer metadata support independent of compression Earlier, buffer metadata support was made dependent on compression. However that is not required. Update the enabled flag NVGPU_SUPPORT_BUFFER_METADATA setup for various hals. Enable it for all from linux characteristics init. Update REGISTER_BUFFER and GET_BUFFER_INFO ioctls to seggregate the compile/runtime compression functionality. If compression is disabled, return error in case comptags are required else don't fail the REGISTER_BUFFER ioctl. Bug 200767700 Change-Id: I3850ccc879f180c97b830fb3d652c094b9d28a5b Signed-off-by: Sagar Kamble Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2614378 Tested-by: mobile promotions Reviewed-by: mobile promotions --- drivers/gpu/nvgpu/hal/init/hal_ga100.c | 1 - drivers/gpu/nvgpu/hal/init/hal_ga10b.c | 1 - drivers/gpu/nvgpu/hal/init/hal_gm20b.c | 4 +-- drivers/gpu/nvgpu/hal/init/hal_gp10b.c | 4 +-- drivers/gpu/nvgpu/hal/init/hal_gv11b.c | 4 +-- drivers/gpu/nvgpu/hal/init/hal_tu104.c | 4 +-- .../gpu/nvgpu/hal/vgpu/init/vgpu_hal_ga10b.c | 1 - .../gpu/nvgpu/hal/vgpu/init/vgpu_hal_gv11b.c | 1 - drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c | 27 ++++++++++++++----- drivers/gpu/nvgpu/os/linux/module.c | 1 + include/uapi/linux/nvgpu-ctrl.h | 2 ++ 11 files changed, 28 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/nvgpu/hal/init/hal_ga100.c b/drivers/gpu/nvgpu/hal/init/hal_ga100.c index 5b3defa5c..43019500c 100644 --- a/drivers/gpu/nvgpu/hal/init/hal_ga100.c +++ b/drivers/gpu/nvgpu/hal/init/hal_ga100.c @@ -1928,7 +1928,6 @@ int ga100_init_hal(struct gk20a *g) if (nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION)) { nvgpu_set_enabled(g, NVGPU_SUPPORT_POST_L2_COMPRESSION, false); - nvgpu_set_enabled(g, NVGPU_SUPPORT_BUFFER_METADATA, true); } else { gops->cbc.init = NULL; gops->cbc.ctrl = NULL; diff --git a/drivers/gpu/nvgpu/hal/init/hal_ga10b.c b/drivers/gpu/nvgpu/hal/init/hal_ga10b.c index 2c369291d..0dcb8c4b6 100644 --- a/drivers/gpu/nvgpu/hal/init/hal_ga10b.c +++ b/drivers/gpu/nvgpu/hal/init/hal_ga10b.c @@ -1898,7 +1898,6 @@ int ga10b_init_hal(struct gk20a *g) if (nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION)) { nvgpu_set_enabled(g, NVGPU_SUPPORT_POST_L2_COMPRESSION, true); - nvgpu_set_enabled(g, NVGPU_SUPPORT_BUFFER_METADATA, true); } else { gops->cbc.init = NULL; gops->cbc.ctrl = NULL; diff --git a/drivers/gpu/nvgpu/hal/init/hal_gm20b.c b/drivers/gpu/nvgpu/hal/init/hal_gm20b.c index 03858ddc2..ec77fe218 100644 --- a/drivers/gpu/nvgpu/hal/init/hal_gm20b.c +++ b/drivers/gpu/nvgpu/hal/init/hal_gm20b.c @@ -1225,9 +1225,7 @@ int gm20b_init_hal(struct gk20a *g) #ifdef CONFIG_NVGPU_COMPRESSION nvgpu_set_enabled(g, NVGPU_SUPPORT_COMPRESSION, true); - if (nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION)) { - nvgpu_set_enabled(g, NVGPU_SUPPORT_BUFFER_METADATA, true); - } else { + if (!nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION)) { gops->cbc.init = NULL; gops->cbc.ctrl = NULL; gops->cbc.alloc_comptags = NULL; diff --git a/drivers/gpu/nvgpu/hal/init/hal_gp10b.c b/drivers/gpu/nvgpu/hal/init/hal_gp10b.c index b040b53d2..41d249f36 100644 --- a/drivers/gpu/nvgpu/hal/init/hal_gp10b.c +++ b/drivers/gpu/nvgpu/hal/init/hal_gp10b.c @@ -1318,9 +1318,7 @@ int gp10b_init_hal(struct gk20a *g) #ifdef CONFIG_NVGPU_COMPRESSION nvgpu_set_enabled(g, NVGPU_SUPPORT_COMPRESSION, true); - if (nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION)) { - nvgpu_set_enabled(g, NVGPU_SUPPORT_BUFFER_METADATA, true); - } else { + if (!nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION)) { gops->cbc.init = NULL; gops->cbc.ctrl = NULL; gops->cbc.alloc_comptags = NULL; diff --git a/drivers/gpu/nvgpu/hal/init/hal_gv11b.c b/drivers/gpu/nvgpu/hal/init/hal_gv11b.c index ae970a336..31b10968d 100644 --- a/drivers/gpu/nvgpu/hal/init/hal_gv11b.c +++ b/drivers/gpu/nvgpu/hal/init/hal_gv11b.c @@ -1596,9 +1596,7 @@ int gv11b_init_hal(struct gk20a *g) #ifdef CONFIG_NVGPU_COMPRESSION nvgpu_set_enabled(g, NVGPU_SUPPORT_COMPRESSION, true); - if (nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION)) { - nvgpu_set_enabled(g, NVGPU_SUPPORT_BUFFER_METADATA, true); - } else { + if (!nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION)) { gops->cbc.init = NULL; gops->cbc.ctrl = NULL; gops->cbc.alloc_comptags = NULL; diff --git a/drivers/gpu/nvgpu/hal/init/hal_tu104.c b/drivers/gpu/nvgpu/hal/init/hal_tu104.c index 8cb4813b9..bcf40d40c 100644 --- a/drivers/gpu/nvgpu/hal/init/hal_tu104.c +++ b/drivers/gpu/nvgpu/hal/init/hal_tu104.c @@ -1853,9 +1853,7 @@ int tu104_init_hal(struct gk20a *g) nvgpu_set_enabled(g, NVGPU_SUPPORT_COMPRESSION, true); } - if (nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION)) { - nvgpu_set_enabled(g, NVGPU_SUPPORT_BUFFER_METADATA, true); - } else { + if (!nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION)) { gops->cbc.init = NULL; gops->cbc.ctrl = NULL; gops->cbc.alloc_comptags = NULL; diff --git a/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_ga10b.c b/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_ga10b.c index a1684bca0..8be8e89dd 100644 --- a/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_ga10b.c +++ b/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_ga10b.c @@ -1208,7 +1208,6 @@ int vgpu_ga10b_init_hal(struct gk20a *g) #ifdef CONFIG_NVGPU_COMPRESSION nvgpu_set_enabled(g, NVGPU_SUPPORT_COMPRESSION, false); nvgpu_set_enabled(g, NVGPU_SUPPORT_POST_L2_COMPRESSION, false); - nvgpu_set_enabled(g, NVGPU_SUPPORT_BUFFER_METADATA, false); #endif #ifdef CONFIG_NVGPU_RECOVERY diff --git a/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_gv11b.c b/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_gv11b.c index d82b3bfc3..5335c1263 100644 --- a/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_gv11b.c +++ b/drivers/gpu/nvgpu/hal/vgpu/init/vgpu_hal_gv11b.c @@ -1175,7 +1175,6 @@ int vgpu_gv11b_init_hal(struct gk20a *g) #ifdef CONFIG_NVGPU_COMPRESSION nvgpu_set_enabled(g, NVGPU_SUPPORT_COMPRESSION, true); - nvgpu_set_enabled(g, NVGPU_SUPPORT_BUFFER_METADATA, true); #endif #ifdef CONFIG_NVGPU_RECOVERY diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c index 793a266b6..333f56583 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c @@ -1917,7 +1917,6 @@ out: } #endif -#ifdef CONFIG_NVGPU_COMPRESSION static int nvgpu_gpu_ioctl_get_buffer_info(struct gk20a *g, struct nvgpu_gpu_get_buffer_info_args *args) { @@ -1981,10 +1980,13 @@ static int nvgpu_gpu_ioctl_get_buffer_info(struct gk20a *g, NVGPU_GPU_BUFFER_INFO_FLAGS_METADATA_REGISTERED; } - if (priv->comptags.enabled) { +#ifdef CONFIG_NVGPU_COMPRESSION + if (nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION) && + priv->comptags.enabled) { args->out.flags |= NVGPU_GPU_BUFFER_INFO_FLAGS_COMPTAGS_ALLOCATED; } +#endif if (priv->mutable_metadata) { args->out.flags |= @@ -2001,6 +2003,7 @@ out: return err; } +#ifdef CONFIG_NVGPU_COMPRESSION static int nvgpu_handle_comptags_control(struct gk20a *g, struct dma_buf *dmabuf, struct gk20a_dmabuf_priv *priv, @@ -2009,6 +2012,14 @@ static int nvgpu_handle_comptags_control(struct gk20a *g, struct nvgpu_os_buffer os_buf = {0}; int err = 0; + if (!nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION)) { + if (comptags_alloc_control == NVGPU_GPU_COMPTAGS_ALLOC_REQUIRED) { + nvgpu_err(g, "Comptags allocation (required) failed. Compression disabled."); + return -EINVAL; + } + return 0; + } + if (comptags_alloc_control == NVGPU_GPU_COMPTAGS_ALLOC_NONE) { if (priv->comptags.allocated) { /* @@ -2060,6 +2071,7 @@ static int nvgpu_handle_comptags_control(struct gk20a *g, return err; } +#endif static int nvgpu_gpu_ioctl_register_buffer(struct gk20a *g, struct nvgpu_gpu_register_buffer_args *args) @@ -2144,6 +2156,7 @@ static int nvgpu_gpu_ioctl_register_buffer(struct gk20a *g, goto out_priv_unlock; } +#ifdef CONFIG_NVGPU_COMPRESSION /* Comptags allocation */ err = nvgpu_handle_comptags_control(g, dmabuf, priv, args->comptags_alloc_control); @@ -2151,6 +2164,7 @@ static int nvgpu_gpu_ioctl_register_buffer(struct gk20a *g, nvgpu_err(g, "Comptags alloc control failed %d", err); goto out_priv_unlock; } +#endif /* All done, update metadata blob */ nvgpu_kfree(g, priv->metadata_blob); @@ -2165,10 +2179,14 @@ static int nvgpu_gpu_ioctl_register_buffer(struct gk20a *g, /* Output variables */ args->flags = 0; - if (priv->comptags.enabled) { + +#ifdef CONFIG_NVGPU_COMPRESSION + if (nvgpu_is_enabled(g, NVGPU_SUPPORT_COMPRESSION) && + priv->comptags.enabled) { args->flags |= NVGPU_GPU_REGISTER_BUFFER_FLAGS_COMPTAGS_ALLOCATED; } +#endif nvgpu_log_info(g, "buffer registered: mutable: %s, metadata size: %u, flags: 0x%8x", priv->mutable_metadata ? "yes" : "no", priv->metadata_blob_size, @@ -2182,7 +2200,6 @@ out: return err; } -#endif long gk20a_ctrl_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { @@ -2548,7 +2565,6 @@ long gk20a_ctrl_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg (struct nvgpu_gpu_set_deterministic_opts_args *)buf); break; -#ifdef CONFIG_NVGPU_COMPRESSION case NVGPU_GPU_IOCTL_REGISTER_BUFFER: err = nvgpu_gpu_ioctl_register_buffer(g, (struct nvgpu_gpu_register_buffer_args *)buf); @@ -2558,7 +2574,6 @@ long gk20a_ctrl_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg err = nvgpu_gpu_ioctl_get_buffer_info(g, (struct nvgpu_gpu_get_buffer_info_args *)buf); break; -#endif default: nvgpu_log_info(g, "unrecognized gpu ioctl cmd: 0x%x", cmd); diff --git a/drivers/gpu/nvgpu/os/linux/module.c b/drivers/gpu/nvgpu/os/linux/module.c index 97153fac9..72b646d86 100644 --- a/drivers/gpu/nvgpu/os/linux/module.c +++ b/drivers/gpu/nvgpu/os/linux/module.c @@ -330,6 +330,7 @@ void gk20a_init_linux_characteristics(struct gk20a *g) nvgpu_set_enabled(g, NVGPU_SUPPORT_DETERMINISTIC_OPTS, true); nvgpu_set_enabled(g, NVGPU_SUPPORT_USERSPACE_MANAGED_AS, true); nvgpu_set_enabled(g, NVGPU_SUPPORT_REMAP, true); + nvgpu_set_enabled(g, NVGPU_SUPPORT_BUFFER_METADATA, true); if (!IS_ENABLED(CONFIG_NVGPU_SYNCFD_NONE)) { nvgpu_set_enabled(g, NVGPU_SUPPORT_SYNC_FENCE_FDS, true); diff --git a/include/uapi/linux/nvgpu-ctrl.h b/include/uapi/linux/nvgpu-ctrl.h index efb4d437b..120f03c9c 100644 --- a/include/uapi/linux/nvgpu-ctrl.h +++ b/include/uapi/linux/nvgpu-ctrl.h @@ -995,6 +995,8 @@ struct nvgpu_gpu_set_deterministic_opts_args { * return 0 on success, < 0 in case of failure. * retval -EINVAL if the enabled flag NVGPU_SUPPORT_BUFFER_METADATA * isn't set or invalid params. + * retval -EINVAL if the enabled flag NVGPU_SUPPORT_COMPRESSION + * isn't set and comptags are required. * retval -ENOMEM in case of sufficient memory is not available for * privdata or comptags. * retval -EFAULT if the metadata blob copy fails.