Files
linux-hwpm/tegra-soc-hwpm.c
Adeel Raza 70941decf9 tegra: hwpm: add SOC HWPM driver
Add a driver for programming the Tegra SOC HWPM path. SOC HWPM allows
performance monitoring of various Tegra IPs.

The profiling tests cases are configured through IOCTLs sent by a
userspace profiling app. The IOCTLs provide the following features:
  - IP discovery and reservation
  - Buffer management
  - Whitelist query
  - Register read/write ops

Bug 200702306
Bug 3305495

Change-Id: I65003b126e01bd03d856767c55aa2424bcfd11fb
Signed-off-by: Adeel Raza <araza@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-t23x/+/2515148
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
GVS: Gerrit_Virtual_Submit
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
2021-05-19 00:33:31 -07:00

231 lines
5.3 KiB
C

/*
* tegra-soc-hwpm.c:
* This is Tegra's driver for programming the SOC HWPM path.
*
* Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/module.h>
#include <linux/io.h>
#include <linux/slab.h>
#include <soc/tegra/fuse.h>
#include "tegra-soc-hwpm.h"
static const struct of_device_id tegra_soc_hwpm_of_match[] = {
{
.compatible = "nvidia,t23x-soc-hwpm",
}, {
},
};
MODULE_DEVICE_TABLE(of, tegra_soc_hwpm_of_match);
static int tegra_soc_hwpm_probe(struct platform_device *pdev)
{
int ret = 0;
struct device *dev = NULL;
struct tegra_soc_hwpm *hwpm = NULL;
if (!pdev) {
tegra_soc_hwpm_err("Invalid platform device");
ret = -ENODEV;
goto fail;
}
hwpm = kzalloc(sizeof(struct tegra_soc_hwpm), GFP_KERNEL);
if (!hwpm) {
tegra_soc_hwpm_err("Couldn't allocate memory for hwpm struct");
ret = -ENOMEM;
goto fail;
}
hwpm->pdev = pdev;
hwpm->dev = &pdev->dev;
hwpm->np = pdev->dev.of_node;
hwpm->class.owner = THIS_MODULE;
hwpm->class.name = TEGRA_SOC_HWPM_MODULE_NAME;
/* Create device node */
ret = class_register(&hwpm->class);
if (ret) {
tegra_soc_hwpm_err("Failed to register class");
goto class_register;
}
ret = alloc_chrdev_region(&hwpm->dev_t, 0, 1, dev_name(hwpm->dev));
if (ret) {
tegra_soc_hwpm_err("Failed to allocate device region");
goto alloc_chrdev_region;
}
cdev_init(&hwpm->cdev, &tegra_soc_hwpm_ops);
hwpm->cdev.owner = THIS_MODULE;
ret = cdev_add(&hwpm->cdev, hwpm->dev_t, 1);
if (ret) {
tegra_soc_hwpm_err("Failed to add cdev");
goto cdev_add;
}
dev = device_create(&hwpm->class,
NULL,
hwpm->dev_t,
NULL,
TEGRA_SOC_HWPM_MODULE_NAME);
if (IS_ERR(dev)) {
tegra_soc_hwpm_err("Failed to create device");
ret = PTR_ERR(dev);
goto device_create;
}
/* FIXME: Enable clock and reset programming */
#if 0
hwpm->la_clk = devm_clk_get(hwpm->dev, "la");
if (IS_ERR(hwpm->la_clk)) {
tegra_soc_hwpm_err("Missing la clock");
ret = PTR_ERR(hwpm->la_clk);
goto fail;
}
hwpm->la_rst = devm_reset_control_get(hwpm->dev, "la");
if (IS_ERR(hwpm->la_rst)) {
tegra_soc_hwpm_err("Missing la reset");
ret = PTR_ERR(hwpm->la_rst);
goto fail;
}
hwpm->hwpm_rst = devm_reset_control_get(hwpm->dev, "hwpm");
if (IS_ERR(hwpm->hwpm_rst)) {
tegra_soc_hwpm_err("Missing hwpm reset");
ret = PTR_ERR(hwpm->hwpm_rst);
goto fail;
}
*/
#endif
tegra_soc_hwpm_debugfs_init(hwpm);
/*
* Currently VDK doesn't have a fmodel for SOC HWPM. Therefore, we
* enable fake registers on VDK for minimal testing.
*/
if (tegra_platform_is_vdk())
hwpm->fake_registers_enabled = true;
else
hwpm->fake_registers_enabled = false;
platform_set_drvdata(pdev, hwpm);
tegra_soc_hwpm_dbg("Probe successful!");
goto success;
device_create:
cdev_del(&hwpm->cdev);
cdev_add:
unregister_chrdev_region(hwpm->dev_t, 1);
alloc_chrdev_region:
class_unregister(&hwpm->class);
class_register:
kfree(hwpm);
/* FIXME: Enable clock and reset programming */
#if 0
if (hwpm->la_clk)
devm_clk_put(hwpm->dev, hwpm->la_clk);
if (hwpm->la_rst)
reset_control_assert(hwpm->la_rst);
if (hwpm->hwpm_rst)
reset_control_assert(hwpm->hwpm_rst);
*/
#endif
fail:
tegra_soc_hwpm_err("Probe failed!");
success:
return ret;
}
static int tegra_soc_hwpm_remove(struct platform_device *pdev)
{
struct tegra_soc_hwpm *hwpm = NULL;
if (!pdev) {
tegra_soc_hwpm_err("Invalid platform device");
return -ENODEV;
}
hwpm = platform_get_drvdata(pdev);
if (!hwpm) {
tegra_soc_hwpm_err("Invalid hwpm struct");
return -ENODEV;
}
tegra_soc_hwpm_debugfs_deinit(hwpm);
/* FIXME: Enable clock and reset programming */
#if 0
if (hwpm->la_clk)
devm_clk_put(hwpm->dev, hwpm->la_clk);
if (hwpm->la_rst)
reset_control_assert(hwpm->la_rst);
if (hwpm->hwpm_rst)
reset_control_assert(hwpm->hwpm_rst);
*/
#endif
device_destroy(&hwpm->class, hwpm->dev_t);
cdev_del(&hwpm->cdev);
unregister_chrdev_region(hwpm->dev_t, 1);
class_unregister(&hwpm->class);
kfree(hwpm);
return 0;
}
static struct platform_driver tegra_soc_hwpm_pdrv = {
.probe = tegra_soc_hwpm_probe,
.remove = tegra_soc_hwpm_remove,
.driver = {
.name = TEGRA_SOC_HWPM_MODULE_NAME,
.of_match_table = of_match_ptr(tegra_soc_hwpm_of_match),
},
};
static int __init tegra_soc_hwpm_init(void)
{
int ret = 0;
ret = platform_driver_register(&tegra_soc_hwpm_pdrv);
if (ret < 0)
tegra_soc_hwpm_err("Platform driver register failed");
return ret;
}
static void __exit tegra_soc_hwpm_exit(void)
{
tegra_soc_hwpm_dbg("Unloading the Tegra SOC HWPM driver");
platform_driver_unregister(&tegra_soc_hwpm_pdrv);
}
module_init(tegra_soc_hwpm_init);
module_exit(tegra_soc_hwpm_exit);
MODULE_ALIAS(TEGRA_SOC_HWPM_MODULE_NAME);
MODULE_DESCRIPTION("Tegra SOC HWPM Driver");
MODULE_LICENSE("GPL v2");