From a0571a42ae11f11958d2e1b1c74b880035335ee6 Mon Sep 17 00:00:00 2001 From: Anvesh Salveru Date: Tue, 5 Apr 2022 08:48:19 +0530 Subject: [PATCH] tegra_bootloader_debug: dump full carvedout region This change dumps the bootloader profiling data from the complete 64KB carvedout memory which include MB1, MB2 and HYP profiling data. Bug 3512531 Change-Id: I22726ec25d61900ecc7a47b6973d069959846fb7 Signed-off-by: Anvesh Salveru Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2692615 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: svc_kernel_abi Reviewed-by: Bharat Nihalani GVS: Gerrit_Virtual_Submit Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2864628 Tested-by: Bharat Nihalani GVS: Gerrit_Virtual_Submit --- .../platform/tegra/tegra_bootloader_debug.c | 73 ++++++++++++------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/drivers/platform/tegra/tegra_bootloader_debug.c b/drivers/platform/tegra/tegra_bootloader_debug.c index 3c2c426d..0122f0cf 100644 --- a/drivers/platform/tegra/tegra_bootloader_debug.c +++ b/drivers/platform/tegra/tegra_bootloader_debug.c @@ -74,6 +74,7 @@ struct spi_boot_rx_frame_full { static spinlock_t tegra_bl_lock; static struct kobject *boot_profiler_kobj; static void *tegra_bl_mapped_prof_start; +static void *tegra_bl_mapped_full_carveout; #ifdef CONFIG_DEBUG_FS const uint32_t gr_mb1 = enum_gr_mb1; @@ -128,6 +129,10 @@ static const struct file_operations boot_cfg_fops = { * TBD - get this information from DT node */ #define TEGRA_US_COUNTER_REG 0x0C6B0000 +/* Size is currently hardcoded to 64k + * as QB is using the same size. + */ +#define SIZE_OF_FULL_CARVEOUT (64*1024) struct profiler_record { char str[MAX_PROFILE_STRLEN + 1]; @@ -138,40 +143,39 @@ static ssize_t profiler_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - ssize_t ret = 0; struct profiler_record *profiler_data; int count = 0; int i = 0; int prof_data_section_valid = 0; - if (!tegra_bl_mapped_prof_start || !tegra_bl_prof_size) { - ret += sprintf(buf + ret, "%s\n", "Error mapping profiling data\n"); + if (!tegra_bl_mapped_full_carveout) { + pr_err("%s\n", "Error mapping profiling data\n"); return 0; } - profiler_data = (struct profiler_record *)tegra_bl_mapped_prof_start; - count = tegra_bl_prof_size / sizeof(struct profiler_record); + profiler_data = (struct profiler_record *)tegra_bl_mapped_full_carveout; + count = SIZE_OF_FULL_CARVEOUT / sizeof(struct profiler_record); i = -1; + pr_info("\n"); while (count--) { i++; if (!profiler_data[i].timestamp) { if (prof_data_section_valid) { - ret += sprintf(buf + ret, "\n"); + pr_info("\n"); prof_data_section_valid = 0; } continue; } - ret += sprintf(buf + ret, "%-54s\t%16lld", + pr_info("%-54s\t%16lld", profiler_data[i].str, profiler_data[i].timestamp); if (i > 0 && profiler_data[i - 1].timestamp) { - ret += sprintf(buf + ret, "\t%16lld", - profiler_data[i].timestamp - profiler_data[i - 1].timestamp); + pr_cont("\t%16lld", + profiler_data[i].timestamp - profiler_data[i - 1].timestamp); } - ret += sprintf(buf + ret, "\n"); prof_data_section_valid = 1; } - return ret; + return 0; } static struct kobj_attribute profiler_attribute = @@ -300,8 +304,9 @@ static int dbg_golden_register_open_cpu_bl( __attribute((unused))struct inode *i static int __init tegra_bootloader_debuginit(void) { - void __iomem *ptr_bl_prof_start = NULL; + void __iomem *ptr_bl_full_carveout = NULL; int bl_debug_verify_file_entry; + phys_addr_t tegra_bl_full_carveout; #ifdef CONFIG_DEBUG_FS void __iomem *ptr_bl_debug_data_start = NULL; void __iomem *ptr_bl_boot_cfg_start = NULL; @@ -417,25 +422,37 @@ static int __init tegra_bootloader_debuginit(void) goto out_err; } - if (tegra_bl_prof_start != 0 - && !pfn_valid(__phys_to_pfn(tegra_bl_prof_start))) { - ptr_bl_prof_start = ioremap(tegra_bl_prof_start, tegra_bl_prof_size); + /* MB1 guarantees 64kb alignment during allocation, + * below arithmetic gives address of full carveout + */ + tegra_bl_full_carveout = + tegra_bl_prof_start & (~(SIZE_OF_FULL_CARVEOUT - 1)); + if (tegra_bl_full_carveout != 0 + && !pfn_valid(__phys_to_pfn(tegra_bl_full_carveout))) { + ptr_bl_full_carveout = ioremap(tegra_bl_full_carveout, + SIZE_OF_FULL_CARVEOUT); - WARN_ON(!ptr_bl_prof_start); - if (!ptr_bl_prof_start) { - pr_err("%s: Failed to map tegra_bl_prof_start%08x\n", - __func__, (unsigned int)tegra_bl_prof_start); + WARN_ON(!ptr_bl_full_carveout); + if (!ptr_bl_full_carveout) { + pr_err("%s: Failed to map tegra_bl_full_carveout%08x\n", + __func__, (unsigned int)tegra_bl_full_carveout); goto out_err; } - pr_info("Remapped tegra_bl_prof_start(0x%llx) " + pr_info("Remapped tegra_bl_full_carveout(0x%llx) " "to address 0x%llx, size(0x%llx)\n", - (u64)tegra_bl_prof_start, - (u64)ptr_bl_prof_start, - (u64)tegra_bl_prof_size); + (u64)tegra_bl_full_carveout, + (u64)ptr_bl_full_carveout, + (u64)SIZE_OF_FULL_CARVEOUT); - tegra_bl_mapped_prof_start = ptr_bl_prof_start; + tegra_bl_mapped_full_carveout = ptr_bl_full_carveout; } + tegra_bl_mapped_prof_start = tegra_bl_mapped_full_carveout + + (tegra_bl_prof_start - tegra_bl_full_carveout); + pr_info("tegra_bl_prof_start(0x%llx) size(0x%llx)\n", + (u64)tegra_bl_prof_start, + (u64)tegra_bl_prof_size); + usc = ioremap(TEGRA_US_COUNTER_REG, 4); if (!usc) { pr_err("Failed to map TEGRA_US_COUNTER_REG\n"); @@ -455,8 +472,8 @@ out_err: if (ptr_bl_boot_cfg_start) iounmap(ptr_bl_boot_cfg_start); #endif - if (ptr_bl_prof_start) - iounmap(ptr_bl_prof_start); + if (ptr_bl_full_carveout) + iounmap(ptr_bl_full_carveout); if (boot_profiler_kobj) { sysfs_remove_file(boot_profiler_kobj, @@ -534,8 +551,8 @@ static void __exit tegra_bl_debuginit_module_exit(void) if (tegra_bl_mapped_boot_cfg_start) iounmap(tegra_bl_mapped_boot_cfg_start); #endif - if (tegra_bl_mapped_prof_start) - iounmap(tegra_bl_mapped_prof_start); + if (tegra_bl_mapped_full_carveout) + iounmap(tegra_bl_mapped_full_carveout); if (boot_profiler_kobj) { sysfs_remove_file(boot_profiler_kobj,