xref: /rk3399_ARM-atf/include/lib/cpus/aarch32/cpu_macros.S (revision 5dd9dbb5bfe64b1eb2e78648f3a2e900678ef433)
1/*
2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30#ifndef __CPU_MACROS_S__
31#define __CPU_MACROS_S__
32
33#include <arch.h>
34
35#define CPU_IMPL_PN_MASK	(MIDR_IMPL_MASK << MIDR_IMPL_SHIFT) | \
36				(MIDR_PN_MASK << MIDR_PN_SHIFT)
37
38/* The number of CPU operations allowed */
39#define CPU_MAX_PWR_DWN_OPS		2
40
41/* Special constant to specify that CPU has no reset function */
42#define CPU_NO_RESET_FUNC		0
43
44/* Word size for 32-bit CPUs */
45#define CPU_WORD_SIZE			4
46
47	/*
48	 * Define the offsets to the fields in cpu_ops structure.
49	 */
50	.struct 0
51CPU_MIDR: /* cpu_ops midr */
52	.space  4
53/* Reset fn is needed during reset */
54#if IMAGE_BL1 || IMAGE_BL32
55CPU_RESET_FUNC: /* cpu_ops reset_func */
56	.space  4
57#endif
58#if IMAGE_BL32 /* The power down core and cluster is needed only in BL32 */
59CPU_PWR_DWN_OPS: /* cpu_ops power down functions */
60	.space  (4 * CPU_MAX_PWR_DWN_OPS)
61#endif
62CPU_OPS_SIZE = .
63
64	/*
65	 * Write given expressions as words
66	 *
67	 * _count:
68	 *	Write at least _count words. If the given number of expressions
69	 *	is less than _count, repeat the last expression to fill _count
70	 *	words in total
71	 * _rest:
72	 *	Optional list of expressions. _this is for parameter extraction
73	 *	only, and has no significance to the caller
74	 *
75	 * Invoked as:
76	 *	fill_constants 2, foo, bar, blah, ...
77	 */
78	.macro fill_constants _count:req, _this, _rest:vararg
79	  .ifgt \_count
80	    /* Write the current expression */
81	    .ifb \_this
82	      .error "Nothing to fill"
83	    .endif
84	    .word \_this
85
86	    /* Invoke recursively for remaining expressions */
87	    .ifnb \_rest
88	      fill_constants \_count-1, \_rest
89	    .else
90	      fill_constants \_count-1, \_this
91	    .endif
92	  .endif
93	.endm
94
95	/*
96	 * Declare CPU operations
97	 *
98	 * _name:
99	 *	Name of the CPU for which operations are being specified
100	 * _midr:
101	 *	Numeric value expected to read from CPU's MIDR
102	 * _resetfunc:
103	 *	Reset function for the CPU. If there's no CPU reset function,
104	 *	specify CPU_NO_RESET_FUNC
105	 * _power_down_ops:
106	 *	Comma-separated list of functions to perform power-down
107	 *	operatios on the CPU. At least one, and up to
108	 *	CPU_MAX_PWR_DWN_OPS number of functions may be specified.
109	 *	Starting at power level 0, these functions shall handle power
110	 *	down at subsequent power levels. If there aren't exactly
111	 *	CPU_MAX_PWR_DWN_OPS functions, the last specified one will be
112	 *	used to handle power down at subsequent levels
113	 */
114	.macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \
115		_power_down_ops:vararg
116	.section cpu_ops, "a"
117	.align 2
118	.type cpu_ops_\_name, %object
119	.word \_midr
120#if IMAGE_BL1 || IMAGE_BL32
121	.word \_resetfunc
122#endif
123#if IMAGE_BL32
1241:
125	/* Insert list of functions */
126	fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops
1272:
128	/*
129	 * Error if no or more than CPU_MAX_PWR_DWN_OPS were specified in the
130	 * list
131	 */
132	.ifeq 2b - 1b
133	  .error "At least one power down function must be specified"
134	.else
135	  .iflt 2b - 1b - (CPU_MAX_PWR_DWN_OPS * CPU_WORD_SIZE)
136	    .error "More than CPU_MAX_PWR_DWN_OPS functions specified"
137	  .endif
138	.endif
139#endif
140	.endm
141
142#endif /* __CPU_MACROS_S__ */
143