xref: /rk3399_ARM-atf/include/lib/cpus/aarch32/cpu_macros.S (revision 3d8256b2a1ef1195aed86bef7378e83d0a61a91b)
1e33b78a6SSoby Mathew/*
2e33b78a6SSoby Mathew * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3e33b78a6SSoby Mathew *
4e33b78a6SSoby Mathew * Redistribution and use in source and binary forms, with or without
5e33b78a6SSoby Mathew * modification, are permitted provided that the following conditions are met:
6e33b78a6SSoby Mathew *
7e33b78a6SSoby Mathew * Redistributions of source code must retain the above copyright notice, this
8e33b78a6SSoby Mathew * list of conditions and the following disclaimer.
9e33b78a6SSoby Mathew *
10e33b78a6SSoby Mathew * Redistributions in binary form must reproduce the above copyright notice,
11e33b78a6SSoby Mathew * this list of conditions and the following disclaimer in the documentation
12e33b78a6SSoby Mathew * and/or other materials provided with the distribution.
13e33b78a6SSoby Mathew *
14e33b78a6SSoby Mathew * Neither the name of ARM nor the names of its contributors may be used
15e33b78a6SSoby Mathew * to endorse or promote products derived from this software without specific
16e33b78a6SSoby Mathew * prior written permission.
17e33b78a6SSoby Mathew *
18e33b78a6SSoby Mathew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19e33b78a6SSoby Mathew * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20e33b78a6SSoby Mathew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21e33b78a6SSoby Mathew * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22e33b78a6SSoby Mathew * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23e33b78a6SSoby Mathew * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24e33b78a6SSoby Mathew * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25e33b78a6SSoby Mathew * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26e33b78a6SSoby Mathew * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27e33b78a6SSoby Mathew * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28e33b78a6SSoby Mathew * POSSIBILITY OF SUCH DAMAGE.
29e33b78a6SSoby Mathew */
30e33b78a6SSoby Mathew#ifndef __CPU_MACROS_S__
31e33b78a6SSoby Mathew#define __CPU_MACROS_S__
32e33b78a6SSoby Mathew
33e33b78a6SSoby Mathew#include <arch.h>
34e33b78a6SSoby Mathew
35e33b78a6SSoby Mathew#define CPU_IMPL_PN_MASK	(MIDR_IMPL_MASK << MIDR_IMPL_SHIFT) | \
36e33b78a6SSoby Mathew				(MIDR_PN_MASK << MIDR_PN_SHIFT)
37e33b78a6SSoby Mathew
385dd9dbb5SJeenu Viswambharan/* The number of CPU operations allowed */
395dd9dbb5SJeenu Viswambharan#define CPU_MAX_PWR_DWN_OPS		2
405dd9dbb5SJeenu Viswambharan
415dd9dbb5SJeenu Viswambharan/* Special constant to specify that CPU has no reset function */
425dd9dbb5SJeenu Viswambharan#define CPU_NO_RESET_FUNC		0
435dd9dbb5SJeenu Viswambharan
445dd9dbb5SJeenu Viswambharan/* Word size for 32-bit CPUs */
455dd9dbb5SJeenu Viswambharan#define CPU_WORD_SIZE			4
465dd9dbb5SJeenu Viswambharan
47e33b78a6SSoby Mathew	/*
48e33b78a6SSoby Mathew	 * Define the offsets to the fields in cpu_ops structure.
49e33b78a6SSoby Mathew	 */
50e33b78a6SSoby Mathew	.struct 0
51e33b78a6SSoby MathewCPU_MIDR: /* cpu_ops midr */
52e33b78a6SSoby Mathew	.space  4
53e33b78a6SSoby Mathew/* Reset fn is needed during reset */
54*3d8256b2SMasahiro Yamada#if defined(IMAGE_BL1) || defined(IMAGE_BL32)
55e33b78a6SSoby MathewCPU_RESET_FUNC: /* cpu_ops reset_func */
56e33b78a6SSoby Mathew	.space  4
571a0a3f06SYatharth Kochar#endif
58*3d8256b2SMasahiro Yamada#ifdef IMAGE_BL32 /* The power down core and cluster is needed only in BL32 */
595dd9dbb5SJeenu ViswambharanCPU_PWR_DWN_OPS: /* cpu_ops power down functions */
605dd9dbb5SJeenu Viswambharan	.space  (4 * CPU_MAX_PWR_DWN_OPS)
611a0a3f06SYatharth Kochar#endif
62e33b78a6SSoby MathewCPU_OPS_SIZE = .
63e33b78a6SSoby Mathew
64e33b78a6SSoby Mathew	/*
655dd9dbb5SJeenu Viswambharan	 * Write given expressions as words
665dd9dbb5SJeenu Viswambharan	 *
675dd9dbb5SJeenu Viswambharan	 * _count:
685dd9dbb5SJeenu Viswambharan	 *	Write at least _count words. If the given number of expressions
695dd9dbb5SJeenu Viswambharan	 *	is less than _count, repeat the last expression to fill _count
705dd9dbb5SJeenu Viswambharan	 *	words in total
715dd9dbb5SJeenu Viswambharan	 * _rest:
725dd9dbb5SJeenu Viswambharan	 *	Optional list of expressions. _this is for parameter extraction
735dd9dbb5SJeenu Viswambharan	 *	only, and has no significance to the caller
745dd9dbb5SJeenu Viswambharan	 *
755dd9dbb5SJeenu Viswambharan	 * Invoked as:
765dd9dbb5SJeenu Viswambharan	 *	fill_constants 2, foo, bar, blah, ...
77e33b78a6SSoby Mathew	 */
785dd9dbb5SJeenu Viswambharan	.macro fill_constants _count:req, _this, _rest:vararg
795dd9dbb5SJeenu Viswambharan	  .ifgt \_count
805dd9dbb5SJeenu Viswambharan	    /* Write the current expression */
815dd9dbb5SJeenu Viswambharan	    .ifb \_this
825dd9dbb5SJeenu Viswambharan	      .error "Nothing to fill"
835dd9dbb5SJeenu Viswambharan	    .endif
845dd9dbb5SJeenu Viswambharan	    .word \_this
855dd9dbb5SJeenu Viswambharan
865dd9dbb5SJeenu Viswambharan	    /* Invoke recursively for remaining expressions */
875dd9dbb5SJeenu Viswambharan	    .ifnb \_rest
885dd9dbb5SJeenu Viswambharan	      fill_constants \_count-1, \_rest
895dd9dbb5SJeenu Viswambharan	    .else
905dd9dbb5SJeenu Viswambharan	      fill_constants \_count-1, \_this
915dd9dbb5SJeenu Viswambharan	    .endif
925dd9dbb5SJeenu Viswambharan	  .endif
935dd9dbb5SJeenu Viswambharan	.endm
945dd9dbb5SJeenu Viswambharan
955dd9dbb5SJeenu Viswambharan	/*
965dd9dbb5SJeenu Viswambharan	 * Declare CPU operations
975dd9dbb5SJeenu Viswambharan	 *
985dd9dbb5SJeenu Viswambharan	 * _name:
995dd9dbb5SJeenu Viswambharan	 *	Name of the CPU for which operations are being specified
1005dd9dbb5SJeenu Viswambharan	 * _midr:
1015dd9dbb5SJeenu Viswambharan	 *	Numeric value expected to read from CPU's MIDR
1025dd9dbb5SJeenu Viswambharan	 * _resetfunc:
1035dd9dbb5SJeenu Viswambharan	 *	Reset function for the CPU. If there's no CPU reset function,
1045dd9dbb5SJeenu Viswambharan	 *	specify CPU_NO_RESET_FUNC
1055dd9dbb5SJeenu Viswambharan	 * _power_down_ops:
1065dd9dbb5SJeenu Viswambharan	 *	Comma-separated list of functions to perform power-down
1075dd9dbb5SJeenu Viswambharan	 *	operatios on the CPU. At least one, and up to
1085dd9dbb5SJeenu Viswambharan	 *	CPU_MAX_PWR_DWN_OPS number of functions may be specified.
1095dd9dbb5SJeenu Viswambharan	 *	Starting at power level 0, these functions shall handle power
1105dd9dbb5SJeenu Viswambharan	 *	down at subsequent power levels. If there aren't exactly
1115dd9dbb5SJeenu Viswambharan	 *	CPU_MAX_PWR_DWN_OPS functions, the last specified one will be
1125dd9dbb5SJeenu Viswambharan	 *	used to handle power down at subsequent levels
1135dd9dbb5SJeenu Viswambharan	 */
1145dd9dbb5SJeenu Viswambharan	.macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \
1155dd9dbb5SJeenu Viswambharan		_power_down_ops:vararg
116e33b78a6SSoby Mathew	.section cpu_ops, "a"
117e33b78a6SSoby Mathew	.align 2
118e33b78a6SSoby Mathew	.type cpu_ops_\_name, %object
119e33b78a6SSoby Mathew	.word \_midr
120*3d8256b2SMasahiro Yamada#if defined(IMAGE_BL1) || defined(IMAGE_BL32)
1215dd9dbb5SJeenu Viswambharan	.word \_resetfunc
1221a0a3f06SYatharth Kochar#endif
123*3d8256b2SMasahiro Yamada#ifdef IMAGE_BL32
1245dd9dbb5SJeenu Viswambharan1:
1255dd9dbb5SJeenu Viswambharan	/* Insert list of functions */
1265dd9dbb5SJeenu Viswambharan	fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops
1275dd9dbb5SJeenu Viswambharan2:
1285dd9dbb5SJeenu Viswambharan	/*
1295dd9dbb5SJeenu Viswambharan	 * Error if no or more than CPU_MAX_PWR_DWN_OPS were specified in the
1305dd9dbb5SJeenu Viswambharan	 * list
1315dd9dbb5SJeenu Viswambharan	 */
1325dd9dbb5SJeenu Viswambharan	.ifeq 2b - 1b
1335dd9dbb5SJeenu Viswambharan	  .error "At least one power down function must be specified"
1345dd9dbb5SJeenu Viswambharan	.else
1355dd9dbb5SJeenu Viswambharan	  .iflt 2b - 1b - (CPU_MAX_PWR_DWN_OPS * CPU_WORD_SIZE)
1365dd9dbb5SJeenu Viswambharan	    .error "More than CPU_MAX_PWR_DWN_OPS functions specified"
1375dd9dbb5SJeenu Viswambharan	  .endif
1385dd9dbb5SJeenu Viswambharan	.endif
1391a0a3f06SYatharth Kochar#endif
140e33b78a6SSoby Mathew	.endm
141e33b78a6SSoby Mathew
142e33b78a6SSoby Mathew#endif /* __CPU_MACROS_S__ */
143