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