1*962958d3SRohit Mathew /* 2*962958d3SRohit Mathew * Copyright (c) 2025, Arm Limited and Contributors. All rights reserved. 3*962958d3SRohit Mathew * 4*962958d3SRohit Mathew * SPDX-License-Identifier: BSD-3-Clause 5*962958d3SRohit Mathew */ 6*962958d3SRohit Mathew 7*962958d3SRohit Mathew #include <arch_helpers.h> 8*962958d3SRohit Mathew #include <lib/per_cpu/per_cpu.h> 9*962958d3SRohit Mathew per_cpu_by_index_compute(uint32_t cpu,const void * addr)10*962958d3SRohit Mathew__pure void *per_cpu_by_index_compute(uint32_t cpu, const void *addr) 11*962958d3SRohit Mathew { 12*962958d3SRohit Mathew const char *cpu_base; 13*962958d3SRohit Mathew #ifndef __aarch64__ 14*962958d3SRohit Mathew cpu_base = ((const char *)PER_CPU_START + 15*962958d3SRohit Mathew ((cpu) * (PER_CPU_UNIT_SIZE))); 16*962958d3SRohit Mathew 17*962958d3SRohit Mathew #else 18*962958d3SRohit Mathew cpu_base = per_cpu_base(cpu); 19*962958d3SRohit Mathew #endif 20*962958d3SRohit Mathew return (void *)(cpu_base + PER_CPU_OFFSET(addr)); 21*962958d3SRohit Mathew } 22*962958d3SRohit Mathew per_cpu_cur_compute(const void * addr)23*962958d3SRohit Mathew__pure void *per_cpu_cur_compute(const void *addr) 24*962958d3SRohit Mathew { 25*962958d3SRohit Mathew #ifndef __aarch64__ 26*962958d3SRohit Mathew return (per_cpu_by_index_compute(plat_my_core_pos(), addr)); 27*962958d3SRohit Mathew #else 28*962958d3SRohit Mathew return (void *)((read_tpidr_el3() + PER_CPU_OFFSET(addr))); 29*962958d3SRohit Mathew #endif 30*962958d3SRohit Mathew } 31*962958d3SRohit Mathew 32