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