From d0ab12f3228fd9668aca6df092702358906b1313 Mon Sep 17 00:00:00 2001 From: Anvesh Salveru Date: Mon, 4 Apr 2022 09:09:01 +0000 Subject: [PATCH] tegra_bootloader_debug: api to add profiling point This change exports an api to add a new profiling record in bootloader profiler memory. Bug 3512531 Change-Id: I60fe25ab33bf607632c99a15acc24647956d4138 Signed-off-by: Anvesh Salveru Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2692037 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2864626 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: svcacv Reviewed-by: Bharat Nihalani Tested-by: Bharat Nihalani GVS: Gerrit_Virtual_Submit --- .../platform/tegra/tegra_bootloader_debug.c | 68 +++++++++++++++++++ .../platform/tegra/tegra_bootloader_debug.h | 5 +- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/drivers/platform/tegra/tegra_bootloader_debug.c b/drivers/platform/tegra/tegra_bootloader_debug.c index 9c36acad..10390efa 100644 --- a/drivers/platform/tegra/tegra_bootloader_debug.c +++ b/drivers/platform/tegra/tegra_bootloader_debug.c @@ -18,6 +18,7 @@ static const char *module_name = "tegra_bootloader_debug"; static const char *dir_name = "tegra_bootloader"; +void __iomem *usc; #ifdef CONFIG_DEBUG_FS static const char *gr_file_mb1 = "gr_mb1"; @@ -70,6 +71,7 @@ struct spi_boot_rx_frame_full { uint8_t data[8200 - sizeof(struct spi_boot_header)]; }; +static spinlock_t tegra_bl_lock; static struct kobject *boot_profiler_kobj; static void *tegra_bl_mapped_prof_start; @@ -122,6 +124,10 @@ static const struct file_operations boot_cfg_fops = { #endif /* CONFIG_DEBUG_FS */ #define MAX_PROFILE_STRLEN 55 +/* This address corresponds to T234 + * TBD - get this information from DT node + */ +#define TEGRA_US_COUNTER_REG 0x0C6B0000 struct profiler_record { char str[MAX_PROFILE_STRLEN + 1]; @@ -171,6 +177,56 @@ static ssize_t profiler_show(struct kobject *kobj, static struct kobj_attribute profiler_attribute = __ATTR(profiler, 0400, profiler_show, NULL); +/** + * tegra_bl_add_profiler_entry - add a new profiling point + * @buf: string to add as a profiling marker + * @len: length of the string + * + * Return: 0 on success or error code in case of failure. + */ +size_t tegra_bl_add_profiler_entry(const char *buf, size_t len) +{ + int count = 0; + int i = 0; + struct profiler_record *profiler_data; + + if (len > MAX_PROFILE_STRLEN) { + pr_err("%s: Failed to add record, invalid length: %ld\n", + module_name, len); + return -EINVAL; + } + + if (!tegra_bl_mapped_prof_start || !tegra_bl_prof_size) { + pr_err("Error mapping profiling data\n"); + return -EINVAL; + } + + spin_lock(&tegra_bl_lock); + + profiler_data = (struct profiler_record *)tegra_bl_mapped_prof_start; + count = tegra_bl_prof_size / sizeof(struct profiler_record); + while (i < count) { + if (!profiler_data[i].timestamp) + break; + i++; + } + + if (i == count) { + pr_err("Error profiling data buffer full\n"); + spin_unlock(&tegra_bl_lock); + return -ENOMEM; + } + + profiler_data[i].timestamp = readl(usc); + spin_unlock(&tegra_bl_lock); + + strncpy(profiler_data[i].str, buf, len); + + return 0; +} +EXPORT_SYMBOL(tegra_bl_add_profiler_entry); + + #ifdef CONFIG_DEBUG_FS static int dbg_golden_register_show(struct seq_file *s, void *unused) { @@ -359,6 +415,15 @@ static int __init tegra_bootloader_debuginit(void) tegra_bl_mapped_prof_start = ptr_bl_prof_start; } + + usc = ioremap(TEGRA_US_COUNTER_REG, 4); + if (!usc) { + pr_err("Failed to map TEGRA_US_COUNTER_REG\n"); + goto out_err; + } + + spin_lock_init(&tegra_bl_lock); + return 0; out_err: @@ -456,6 +521,9 @@ static void __exit tegra_bl_debuginit_module_exit(void) kobject_put(boot_profiler_kobj); boot_profiler_kobj = NULL; } + + if (usc) + iounmap(usc); } module_init(tegra_bl_debuginit_module_init); diff --git a/drivers/platform/tegra/tegra_bootloader_debug.h b/drivers/platform/tegra/tegra_bootloader_debug.h index d571b9c0..bdda39bc 100644 --- a/drivers/platform/tegra/tegra_bootloader_debug.h +++ b/drivers/platform/tegra/tegra_bootloader_debug.h @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 -// Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. +// Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. #ifndef __TEGRA_BOOTLOADER_DEBUG_H #define __TEGRA_BOOTLOADER_DEBUG_H @@ -9,4 +9,7 @@ extern phys_addr_t tegra_bl_prof_start; extern phys_addr_t tegra_bl_prof_size; extern phys_addr_t tegra_bl_bcp_start; extern phys_addr_t tegra_bl_bcp_size; + +size_t tegra_bl_add_profiler_entry(const char *buf, size_t len); + #endif