xref: /rk3399_ARM-atf/include/lib/per_cpu/per_cpu_macros.S (revision 962958d309f6c0b7c1490ab1bec67804c58589f5)
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#ifndef PER_CPU_MACROS_S
8*962958d3SRohit Mathew#define PER_CPU_MACROS_S
9*962958d3SRohit Mathew
10*962958d3SRohit Mathew#include <arch.h>
11*962958d3SRohit Mathew#include <asm_macros.S>
12*962958d3SRohit Mathew#include <lib/per_cpu/per_cpu_defs.h>
13*962958d3SRohit Mathew
14*962958d3SRohit Mathew/* -----------------------------------------------------------------
15*962958d3SRohit Mathew * per_cpu_cur <label>, <dst>, <clobber>
16*962958d3SRohit Mathew * Returns: <dst> = per-CPU address of <label>
17*962958d3SRohit Mathew * Clobbers: <dst> and <clobber>
18*962958d3SRohit Mathew *
19*962958d3SRohit Mathew * Defaults: dst=x0, clobber=x1
20*962958d3SRohit Mathew * ----------------------------------------------------------------- */
21*962958d3SRohit Mathew.macro  per_cpu_cur label, dst=x0, clobber=x1
22*962958d3SRohit Mathew	/* Safety checks */
23*962958d3SRohit Mathew	.ifc \dst,\clobber
24*962958d3SRohit Mathew	.error "per_cpu_cur: dst and clobber must be different"
25*962958d3SRohit Mathew	.endif
26*962958d3SRohit Mathew
27*962958d3SRohit Mathew	/* dst = absolute address of label */
28*962958d3SRohit Mathew	adr_l	\dst, \label
29*962958d3SRohit Mathew
30*962958d3SRohit Mathew	/* clobber = absolute address of __PER_CPU_START__ */
31*962958d3SRohit Mathew	adr_l	\clobber, __PER_CPU_START__
32*962958d3SRohit Mathew
33*962958d3SRohit Mathew	/* dst = (label - __PER_CPU_START__) */
34*962958d3SRohit Mathew	sub	\dst, \dst, \clobber
35*962958d3SRohit Mathew
36*962958d3SRohit Mathew	/* clobber = per-cpu base (TPIDR_EL3) */
37*962958d3SRohit Mathew	mrs	\clobber, tpidr_el3
38*962958d3SRohit Mathew
39*962958d3SRohit Mathew	/* dst = base + offset */
40*962958d3SRohit Mathew	add	\dst, \clobber, \dst
41*962958d3SRohit Mathew.endm
42*962958d3SRohit Mathew
43*962958d3SRohit Mathew#endif /* PER_CPU_MACROS_S */
44