xref: /rk3399_ARM-atf/include/lib/per_cpu/per_cpu.h (revision dcabf4fd95d1179739564a8670d8ca3bf0a473ae)
1962958d3SRohit Mathew /*
2962958d3SRohit Mathew  * Copyright (c) 2025, Arm Limited. All rights reserved.
3962958d3SRohit Mathew  *
4962958d3SRohit Mathew  * SPDX-License-Identifier: BSD-3-Clause
5962958d3SRohit Mathew  */
6962958d3SRohit Mathew 
7962958d3SRohit Mathew #ifndef PER_CPU_H
8962958d3SRohit Mathew #define PER_CPU_H
9962958d3SRohit Mathew 
10*f7ccf126SChris Kay #include <stddef.h>
11*f7ccf126SChris Kay 
12*f7ccf126SChris Kay #include <plat/common/platform.h>
13*f7ccf126SChris Kay 
14962958d3SRohit Mathew #include <common/bl_common.h>
15962958d3SRohit Mathew #include <lib/per_cpu/per_cpu_defs.h>
16962958d3SRohit Mathew 
17962958d3SRohit Mathew /* section where per-cpu objects using per-cpu framework would reside */
18962958d3SRohit Mathew #define PER_CPU_SECTION_NAME	".per_cpu"
19962958d3SRohit Mathew 
20962958d3SRohit Mathew /* per cpu section size for a single CPU/PE */
21*f7ccf126SChris Kay #define PER_CPU_UNIT_SIZE ((size_t)(PER_CPU_UNIT_END - PER_CPU_START))
22*f7ccf126SChris Kay #define PER_CPU_OFFSET(x) ((ptrdiff_t)((uintptr_t)(x) - PER_CPU_START))
23962958d3SRohit Mathew 
24962958d3SRohit Mathew /*******************************************************************************
25962958d3SRohit Mathew  * per-cpu definer and accessor interfaces
26962958d3SRohit Mathew  ******************************************************************************/
27962958d3SRohit Mathew 
28962958d3SRohit Mathew /* Declare a per-cpu object */
29962958d3SRohit Mathew #define PER_CPU_DECLARE(TYPE, NAME)				\
30962958d3SRohit Mathew 	extern typeof(TYPE) NAME
31962958d3SRohit Mathew 
32962958d3SRohit Mathew /* Define a per-cpu object */
33962958d3SRohit Mathew #define PER_CPU_DEFINE(TYPE, NAME)				\
34962958d3SRohit Mathew 	typeof(TYPE) NAME					\
35962958d3SRohit Mathew 	__section(PER_CPU_SECTION_NAME)
36962958d3SRohit Mathew 
37962958d3SRohit Mathew /* Get a pointer to a per-cpu object for a given CPU */
38962958d3SRohit Mathew #define PER_CPU_BY_INDEX(NAME, CPU)				\
39962958d3SRohit Mathew 	((__typeof__(&(NAME)))					\
40962958d3SRohit Mathew 	(per_cpu_by_index_compute((CPU), (const void *)&(NAME))))
41962958d3SRohit Mathew 
42962958d3SRohit Mathew /* Get a pointer to a per-cpu object for the current CPU */
43962958d3SRohit Mathew #define PER_CPU_CUR(NAME)					\
44962958d3SRohit Mathew 	((__typeof__(&(NAME)))					\
45962958d3SRohit Mathew 	(per_cpu_cur_compute((const void *)&(NAME))))
46962958d3SRohit Mathew 
47962958d3SRohit Mathew /*******************************************************************************
48962958d3SRohit Mathew  * Functions
49962958d3SRohit Mathew  ******************************************************************************/
50962958d3SRohit Mathew 
51962958d3SRohit Mathew __pure const char *per_cpu_base(uint32_t cpu);
52962958d3SRohit Mathew __pure void *per_cpu_by_index_compute(uint32_t cpu, const void *addr);
53962958d3SRohit Mathew __pure void *per_cpu_cur_compute(const void *addr);
54962958d3SRohit Mathew 
55962958d3SRohit Mathew #endif /* PER_CPU_H */
56