Files
linux-hwpm/tegra-soc-hwpm-ip.c
Seshendra Gadagottu 579bc23ee6 tegra: hwpm: add support for SOC HWPM <-> IP interface
Add support for IP registering mechanism for runtime
callback and perfmux read/writes.
void tegra_soc_hwpm_ip_register(struct tegra_soc_hwpm_ip_ops *hwpm_ip_ops);

IP's callback are called to disable and enable IP runtime pm.
At this moment, only VIC/NVENC/OFA driver registration is supported.
Also will take-up perfmux register read/write in follow-up patch.

Bug 3333031
Bug 3333042

Change-Id: If559cae73be1edbdb7139b4183ce3e1dc0943053
Signed-off-by: Seshendra Gadagottu <sgadagottu@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2607267
Reviewed-by: svc_kernel_abi <svc_kernel_abi@nvidia.com>
Reviewed-by: Seema Khowala <seemaj@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
GVS: Gerrit_Virtual_Submit
2021-10-14 17:03:53 -07:00

90 lines
2.8 KiB
C

/*
* 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/>.
*
* tegra-soc-hwpm-ip.c:
* This file contains functions for SOC HWPM <-> IPC communication.
*/
#include <uapi/linux/tegra-soc-hwpm-uapi.h>
#include "tegra-soc-hwpm.h"
struct platform_device *tegra_soc_hwpm_pdev;
static enum tegra_soc_hwpm_dt_aperture tegra_soc_hwpm_get_apeture(
struct tegra_soc_hwpm *hwpm, u64 ip_base_address)
{
enum tegra_soc_hwpm_dt_aperture aperture =
TEGRA_SOC_HWPM_NUM_DT_APERTURES;
/* TODO chip speciifc implementation for finding aperture */
if (ip_base_address == addr_map_vic_base_r()) {
aperture = TEGRA_SOC_HWPM_VICA0_PERFMON_DT;
} else if (ip_base_address == addr_map_nvenc_base_r()) {
aperture = TEGRA_SOC_HWPM_NVENCA0_PERFMON_DT;
} else if (ip_base_address == addr_map_ofa_base_r()) {
aperture = TEGRA_SOC_HWPM_OFAA0_PERFMON_DT;
}
return aperture;
}
void tegra_soc_hwpm_ip_register(struct tegra_soc_hwpm_ip_ops *hwpm_ip_ops)
{
struct tegra_soc_hwpm *hwpm = NULL;
enum tegra_soc_hwpm_dt_aperture dt_aperture;
tegra_soc_hwpm_dbg("HWPM Registered IP 0x%llx",
hwpm_ip_ops->ip_base_address);
if (tegra_soc_hwpm_pdev == NULL) {
tegra_soc_hwpm_err(
"IP trying to register before SOC HWPM 0x%llx",
hwpm_ip_ops->ip_base_address);
} else {
hwpm = platform_get_drvdata(tegra_soc_hwpm_pdev);
dt_aperture = tegra_soc_hwpm_get_apeture(hwpm,
hwpm_ip_ops->ip_base_address);
if (dt_aperture != TEGRA_SOC_HWPM_NUM_DT_APERTURES) {
memcpy(&hwpm->ip_info[dt_aperture], hwpm_ip_ops,
sizeof(struct tegra_soc_hwpm_ip_ops));
} else {
tegra_soc_hwpm_err(
"SOC HWPM has no support for 0x%llx",
hwpm_ip_ops->ip_base_address);
}
}
}
void tegra_soc_hwpm_ip_unregister(struct tegra_soc_hwpm_ip_ops *hwpm_ip_ops)
{
struct tegra_soc_hwpm *hwpm = NULL;
enum tegra_soc_hwpm_dt_aperture dt_aperture;
if (tegra_soc_hwpm_pdev == NULL) {
tegra_soc_hwpm_err("IP unregister before SOC HWPM 0x%llx",
hwpm_ip_ops->ip_base_address);
} else {
hwpm = platform_get_drvdata(tegra_soc_hwpm_pdev);
dt_aperture = tegra_soc_hwpm_get_apeture(hwpm,
hwpm_ip_ops->ip_base_address);
if (dt_aperture != TEGRA_SOC_HWPM_NUM_DT_APERTURES) {
memset(&hwpm->ip_info[dt_aperture], 0,
sizeof(struct tegra_soc_hwpm_ip_ops));
}
}
}