Add qcom_get_socinfo() function to provide cached access to the socinfo structure from SMEM. This eliminates redundant SMEM device initialization and socinfo retrieval across multiple callers.
The implementation uses a static cache that initializes on first access and returns the cached pointer on subsequent calls. This improves performance and reduces code duplication in components that need to access SoC information. Signed-off-by: Aswin Murugan <[email protected]> --- arch/arm/mach-snapdragon/board.c | 43 ++++++++++++++++++++++++++++ arch/arm/mach-snapdragon/qcom-priv.h | 5 ++++ 2 files changed, 48 insertions(+) diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c index 5fb3240acc5..ccdb22d5429 100644 --- a/arch/arm/mach-snapdragon/board.c +++ b/arch/arm/mach-snapdragon/board.c @@ -32,11 +32,19 @@ #include <usb.h> #include <sort.h> #include <time.h> +#include <smem.h> #include "qcom-priv.h" DECLARE_GLOBAL_DATA_PTR; +/* SMEM cache structure */ +static struct { + struct udevice *smem_dev; + struct socinfo *soc_info; + bool initialized; +} smem_cache; + enum qcom_boot_source qcom_boot_source __section(".data") = 0; static struct mm_region rbx_mem_map[CONFIG_NR_DRAM_BANKS + 2] = { { 0 } }; @@ -749,3 +757,38 @@ void enable_caches(void) } dcache_enable(); } + +/** + * qcom_get_socinfo() - Get cached socinfo from SMEM + * + * This function provides cached access to the socinfo structure from SMEM. + * On first call, it initializes the SMEM device and retrieves the socinfo. + * Subsequent calls return the cached pointer. + * + * Return: Pointer to socinfo structure on success, NULL on failure + */ +struct socinfo *qcom_get_socinfo(void) +{ + size_t size; + + /* Return cached value if already initialized */ + if (smem_cache.initialized) + return smem_cache.soc_info; + + /* Get SMEM device */ + if (uclass_get_device(UCLASS_SMEM, 0, &smem_cache.smem_dev)) { + log_err("Failed to get SMEM device\n"); + return NULL; + } + + /* Get socinfo from SMEM */ + smem_cache.soc_info = smem_get(smem_cache.smem_dev, 0, + SMEM_HW_SW_BUILD_ID, &size); + if (!smem_cache.soc_info) { + log_err("Failed to get socinfo from SMEM\n"); + return NULL; + } + + smem_cache.initialized = true; + return smem_cache.soc_info; +} diff --git a/arch/arm/mach-snapdragon/qcom-priv.h b/arch/arm/mach-snapdragon/qcom-priv.h index b8bf574e8bb..d5ec210faf5 100644 --- a/arch/arm/mach-snapdragon/qcom-priv.h +++ b/arch/arm/mach-snapdragon/qcom-priv.h @@ -3,6 +3,8 @@ #ifndef __QCOM_PRIV_H__ #define __QCOM_PRIV_H__ +#include <soc/qcom/socinfo.h> + /** * enum qcom_boot_source - Track where we got loaded from. * Used for capsule update logic. @@ -17,6 +19,9 @@ enum qcom_boot_source { extern enum qcom_boot_source qcom_boot_source; +/* SMEM socinfo cache accessor */ +struct socinfo *qcom_get_socinfo(void); + #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) void qcom_configure_capsule_updates(void); #else -- 2.34.1

