From 268a87ecfa8162efe0261d60b962a7234d38ec2a Mon Sep 17 00:00:00 2001 From: Ketan Patil Date: Fri, 24 Jan 2025 17:05:42 +0000 Subject: [PATCH] video: tegra: nvmap: Add DT based API disabling support There are debug/duplicate APIs like NvRmMemGetIVCId, NvRmMemHandleFromIVCId, NvRmMemWrite etc. which don't have corresponding requirements in DriveOS 7.0 Linux NSR. We have taken sign-off from the stakeholders to confirm that they are not using these APIs in T264 Linux Prod NSR variant. But some of them are using these APIs in dev-nsr and did not agree to remove it from dev-nsr, L4T, HOS etc. Hence we need to make sure that they do not accidentally start using these APIs. Hence add following DT based disabling support. - Add disable-debug-support property in tegra-carveouts DT node in T264 prod nsr dts. - Parse this DT node in nvmap and if the above property is present then BUG_ON in the ioctl functions corresponding to these APIs. Bug 4980348 Change-Id: Icdd5aadf3197d0649b61d285f433fa65ea69e806 Signed-off-by: Ketan Patil Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3298507 Reviewed-by: Pritesh Raithatha Reviewed-by: Ashish Mhetre GVS: buildbot_gerritrpt Reviewed-by: Sachin Nikam --- drivers/video/tegra/nvmap/nvmap_dev.c | 19 +++++++++++++++++++ drivers/video/tegra/nvmap/nvmap_dev.h | 3 ++- drivers/video/tegra/nvmap/nvmap_ioctl.c | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/video/tegra/nvmap/nvmap_dev.c b/drivers/video/tegra/nvmap/nvmap_dev.c index da511c18..9b03e1dd 100644 --- a/drivers/video/tegra/nvmap/nvmap_dev.c +++ b/drivers/video/tegra/nvmap/nvmap_dev.c @@ -549,6 +549,23 @@ exit: return memory_available; } +/* + * Read disable-debug-support property from tegra-carveouts DT node. + * If the property is present then don't support any extra APIs other than + * the APIs mentioned in ICD, by doing BUG_ON in the corresponding ioctls. + * So it is necessary to be present in the DT of the respective builds + * (e.g. Prod NSR Build). + */ +static void nvmap_support_debug_apis(struct platform_device *pdev, struct nvmap_device *dev) +{ + struct device_node *np = pdev->dev.of_node; + + if (of_property_read_bool(np, "disable-debug-support")) + dev->support_debug_features = 0; + else + dev->support_debug_features = 1; +} + int __init nvmap_probe(struct platform_device *pdev) { struct nvmap_platform_data *plat; @@ -653,6 +670,8 @@ int __init nvmap_probe(struct platform_device *pdev) dev->dev_user.name); goto fail_sci_ipc; } + + (void)nvmap_support_debug_apis(pdev, dev); goto finish; fail_sci_ipc: nvmap_sci_ipc_exit(); diff --git a/drivers/video/tegra/nvmap/nvmap_dev.h b/drivers/video/tegra/nvmap/nvmap_dev.h index 29e4f5a8..aa2ccc4f 100644 --- a/drivers/video/tegra/nvmap/nvmap_dev.h +++ b/drivers/video/tegra/nvmap/nvmap_dev.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -/* SPDX-FileCopyrightText: Copyright (c) 2009-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ +/* SPDX-FileCopyrightText: Copyright (c) 2009-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ #ifndef __NVMAP_DEV_H #define __NVMAP_DEV_H @@ -109,6 +109,7 @@ struct nvmap_device { struct rb_root device_names; #endif /* NVMAP_CONFIG_DEBUG_MAPS */ u64 serial_id_counter; /* This is global counter common across different client processes */ + bool support_debug_features; }; #define NVMAP_TAG_TRACE(x, ...) \ diff --git a/drivers/video/tegra/nvmap/nvmap_ioctl.c b/drivers/video/tegra/nvmap/nvmap_ioctl.c index a750ec6e..78bfcfc9 100644 --- a/drivers/video/tegra/nvmap/nvmap_ioctl.c +++ b/drivers/video/tegra/nvmap/nvmap_ioctl.c @@ -658,6 +658,8 @@ int nvmap_ioctl_get_ivcid(struct file *filp, void __user *arg) struct nvmap_create_handle op; struct nvmap_handle *h = NULL; + BUG_ON(nvmap_dev->support_debug_features == 0); + if (copy_from_user(&op, arg, sizeof(op))) return -EFAULT; @@ -712,6 +714,8 @@ int nvmap_ioctl_create_from_ivc(struct file *filp, void __user *arg) unsigned int peer; struct nvmap_heap_block *block = NULL; + BUG_ON(nvmap_dev->support_debug_features == 0); + /* First create a new handle and then fake carveout allocation */ if (copy_from_user(&op, arg, sizeof(op))) return -EFAULT;