Files
linux-hwpm/common/allowlist.c
Vedashree Vidwans 4cacfb709c tegra: hwpm: fix bugs and rearrange functions
Fix bugs for accessing uninitialized mem_mgmt and alist_map structures.
- Not initializing memory management functionality in HWPM is a valid
situation. Currently, tegra_hwpm_clear_mem_pipeline dereferences the
mem_mgmt pointer without validation, which can lead to failures. Check
if mem_mgmt struct pointer is valid before dereferencing.
- Alist_map structure is only required if user requests allowlist size
or list of allowlist registers. Currently, tegra_hwpm_sw_setup
dereferences alist_map pointer to set full_alist_size to 0. Add
alist_map allocation function and set full_alist_size to 0.
- Add PMA and CMD_ROUTER as valid cases for
tegra_hwpm_translate_soc_hwpm_resource() translation.
- Move logic to record IP function pointers to separate function. This
way changes to IP ops registration will be in single location.

Jira THWPM-41

Change-Id: I2c221bb13b6875b76a6fabee4c224d77ac72a6fc
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2770418
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: Vasuki Shankar <vasukis@nvidia.com>
Reviewed-by: Seema Khowala <seemaj@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
2022-09-16 07:51:45 -07:00

85 lines
2.1 KiB
C

/*
* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. 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.
*/
#include <tegra_hwpm.h>
#include <tegra_hwpm_log.h>
#include <tegra_hwpm_kmem.h>
#include <tegra_hwpm_common.h>
#include <tegra_hwpm_mem_mgmt.h>
#include <tegra_hwpm_static_analysis.h>
int tegra_hwpm_alloc_alist_map(struct tegra_soc_hwpm *hwpm)
{
tegra_hwpm_fn(hwpm, " ");
if (hwpm->alist_map == NULL) {
/* Allocate tegra_hwpm_allowlist_map */
hwpm->alist_map = tegra_hwpm_kzalloc(hwpm,
sizeof(struct tegra_hwpm_allowlist_map));
if (!hwpm->alist_map) {
return -ENOMEM;
}
hwpm->alist_map->full_alist_size = 0ULL;
}
return 0;
}
int tegra_hwpm_get_allowlist_size(struct tegra_soc_hwpm *hwpm)
{
int ret = 0;
tegra_hwpm_fn(hwpm, " ");
if (hwpm->alist_map->full_alist_size == 0) {
/* Full alist size is not computed yet */
ret = tegra_hwpm_func_all_ip(hwpm, NULL,
TEGRA_HWPM_GET_ALIST_SIZE);
if (ret != 0) {
tegra_hwpm_err(hwpm, "get_alist_size failed");
return ret;
}
}
return 0;
}
int tegra_hwpm_combine_alist(struct tegra_soc_hwpm *hwpm, u64 *alist)
{
struct tegra_hwpm_func_args func_args;
int err = 0;
tegra_hwpm_fn(hwpm, " ");
func_args.alist = alist;
func_args.full_alist_idx = 0ULL;
err = tegra_hwpm_func_all_ip(hwpm, &func_args,
TEGRA_HWPM_COMBINE_ALIST);
if (err != 0) {
tegra_hwpm_err(hwpm, "combine alist failed");
return err;
}
/* Check size of full alist with hwpm->alist_map->full_alist_size*/
if (func_args.full_alist_idx != hwpm->alist_map->full_alist_size) {
tegra_hwpm_err(hwpm, "full_alist_size 0x%llx doesn't match "
"max full_alist_idx 0x%llx",
hwpm->alist_map->full_alist_size,
func_args.full_alist_idx);
err = -EINVAL;
}
return err;
}