1*962958d3SRohit Mathew /* 2*962958d3SRohit Mathew * Copyright (c) 2025, Arm Limited. All rights reserved. 3*962958d3SRohit Mathew * 4*962958d3SRohit Mathew * SPDX-License-Identifier: BSD-3-Clause 5*962958d3SRohit Mathew */ 6*962958d3SRohit Mathew 7*962958d3SRohit Mathew #ifndef PER_CPU_H 8*962958d3SRohit Mathew #define PER_CPU_H 9*962958d3SRohit Mathew 10*962958d3SRohit Mathew #include <common/bl_common.h> 11*962958d3SRohit Mathew #include <lib/per_cpu/per_cpu_defs.h> 12*962958d3SRohit Mathew #include <plat/common/platform.h> 13*962958d3SRohit Mathew 14*962958d3SRohit Mathew /* section where per-cpu objects using per-cpu framework would reside */ 15*962958d3SRohit Mathew #define PER_CPU_SECTION_NAME ".per_cpu" 16*962958d3SRohit Mathew 17*962958d3SRohit Mathew /* per cpu section size for a single CPU/PE */ 18*962958d3SRohit Mathew #define PER_CPU_UNIT_SIZE ((size_t)((const char *)PER_CPU_UNIT_END - \ 19*962958d3SRohit Mathew (const char *)PER_CPU_START)) 20*962958d3SRohit Mathew #define PER_CPU_OFFSET(x) ((const char *)(x) - \ 21*962958d3SRohit Mathew (const char *)PER_CPU_START) 22*962958d3SRohit Mathew 23*962958d3SRohit Mathew /******************************************************************************* 24*962958d3SRohit Mathew * per-cpu definer and accessor interfaces 25*962958d3SRohit Mathew ******************************************************************************/ 26*962958d3SRohit Mathew 27*962958d3SRohit Mathew /* Declare a per-cpu object */ 28*962958d3SRohit Mathew #define PER_CPU_DECLARE(TYPE, NAME) \ 29*962958d3SRohit Mathew extern typeof(TYPE) NAME 30*962958d3SRohit Mathew 31*962958d3SRohit Mathew /* Define a per-cpu object */ 32*962958d3SRohit Mathew #define PER_CPU_DEFINE(TYPE, NAME) \ 33*962958d3SRohit Mathew typeof(TYPE) NAME \ 34*962958d3SRohit Mathew __section(PER_CPU_SECTION_NAME) 35*962958d3SRohit Mathew 36*962958d3SRohit Mathew /* Get a pointer to a per-cpu object for a given CPU */ 37*962958d3SRohit Mathew #define PER_CPU_BY_INDEX(NAME, CPU) \ 38*962958d3SRohit Mathew ((__typeof__(&(NAME))) \ 39*962958d3SRohit Mathew (per_cpu_by_index_compute((CPU), (const void *)&(NAME)))) 40*962958d3SRohit Mathew 41*962958d3SRohit Mathew /* Get a pointer to a per-cpu object for the current CPU */ 42*962958d3SRohit Mathew #define PER_CPU_CUR(NAME) \ 43*962958d3SRohit Mathew ((__typeof__(&(NAME))) \ 44*962958d3SRohit Mathew (per_cpu_cur_compute((const void *)&(NAME)))) 45*962958d3SRohit Mathew 46*962958d3SRohit Mathew /******************************************************************************* 47*962958d3SRohit Mathew * Functions 48*962958d3SRohit Mathew ******************************************************************************/ 49*962958d3SRohit Mathew 50*962958d3SRohit Mathew __pure const char *per_cpu_base(uint32_t cpu); 51*962958d3SRohit Mathew __pure void *per_cpu_by_index_compute(uint32_t cpu, const void *addr); 52*962958d3SRohit Mathew __pure void *per_cpu_cur_compute(const void *addr); 53*962958d3SRohit Mathew 54*962958d3SRohit Mathew #endif /* PER_CPU_H */ 55