From 5c8a07022f82a37a6bd85ca9504a80e33b0f9c2d Mon Sep 17 00:00:00 2001 From: Vedashree Vidwans Date: Tue, 24 May 2022 22:37:47 -0700 Subject: [PATCH] tegra: hwpm: add dt property, update devnode perm HWPM is a profiling device. Device node property support-soc-tools indicates if soc profiling tools should be enabled or disabled. Add logic to HWPM probe to read device node and probe HWPM device only if support-soc-tools property is present. Implement devnode API to disclose device node permissions for HWPM. Set HWPM device node permissions to allow access for root and group. Bug 3435136 Bug 3583956 Change-Id: I988de3b21cd00ef9402ca03408d2b0141e7155d8 Signed-off-by: Vedashree Vidwans Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2717982 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: Seema Khowala Reviewed-by: svc_kernel_abi GVS: Gerrit_Virtual_Submit --- os/linux/tegra_hwpm_linux.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/os/linux/tegra_hwpm_linux.c b/os/linux/tegra_hwpm_linux.c index 859d535..4e3be65 100644 --- a/os/linux/tegra_hwpm_linux.c +++ b/os/linux/tegra_hwpm_linux.c @@ -36,6 +36,30 @@ static const struct of_device_id tegra_soc_hwpm_of_match[] = { }; MODULE_DEVICE_TABLE(of, tegra_soc_hwpm_of_match); +static char *tegra_hwpm_get_devnode(struct device *dev, umode_t *mode) +{ + if (!mode) { + return NULL; + } + + /* Allow root:debug ownership */ + *mode = 0660; + + return NULL; +} + +static bool tegra_hwpm_read_support_soc_tools_prop(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + bool allow_node = of_property_read_bool(np, "support-soc-tools"); + + if (!allow_node) { + tegra_hwpm_err(NULL, "support-soc-tools is absent"); + } + + return allow_node; +} + static int tegra_hwpm_probe(struct platform_device *pdev) { int ret = 0; @@ -48,6 +72,12 @@ static int tegra_hwpm_probe(struct platform_device *pdev) goto fail; } + if (!tegra_hwpm_read_support_soc_tools_prop(pdev)) { + tegra_hwpm_err(NULL, "SOC HWPM not supported in this config"); + ret = -ENODEV; + goto fail; + } + hwpm = kzalloc(sizeof(struct tegra_soc_hwpm), GFP_KERNEL); if (!hwpm) { tegra_hwpm_err(hwpm, "Couldn't allocate memory for hwpm struct"); @@ -67,6 +97,9 @@ static int tegra_hwpm_probe(struct platform_device *pdev) goto class_register; } + /* Set devnode to retrieve device permissions */ + hwpm->class.devnode = tegra_hwpm_get_devnode; + ret = alloc_chrdev_region(&hwpm->dev_t, 0, 1, dev_name(hwpm->dev)); if (ret) { tegra_hwpm_err(hwpm, "Failed to allocate device region");