xref: /rk3399_ARM-atf/include/lib/cpus/aarch32/cpu_macros.S (revision f21b9f6d6e6ddda6d92ec25b01f70c30bcc82d57)
1e33b78a6SSoby Mathew/*
210bcd761SJeenu Viswambharan * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
3e33b78a6SSoby Mathew *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
5e33b78a6SSoby Mathew */
6e33b78a6SSoby Mathew#ifndef __CPU_MACROS_S__
7e33b78a6SSoby Mathew#define __CPU_MACROS_S__
8e33b78a6SSoby Mathew
9e33b78a6SSoby Mathew#include <arch.h>
1010bcd761SJeenu Viswambharan#include <errata_report.h>
11e33b78a6SSoby Mathew
12b1d27b48SRoberto Vargas#if defined(IMAGE_BL1) || defined(IMAGE_BL32)  || (defined(IMAGE_BL2) && BL2_AT_EL3)
13b1d27b48SRoberto Vargas#define IMAGE_AT_EL3
14b1d27b48SRoberto Vargas#endif
15b1d27b48SRoberto Vargas
16e33b78a6SSoby Mathew#define CPU_IMPL_PN_MASK	(MIDR_IMPL_MASK << MIDR_IMPL_SHIFT) | \
17e33b78a6SSoby Mathew				(MIDR_PN_MASK << MIDR_PN_SHIFT)
18e33b78a6SSoby Mathew
195dd9dbb5SJeenu Viswambharan/* The number of CPU operations allowed */
205dd9dbb5SJeenu Viswambharan#define CPU_MAX_PWR_DWN_OPS		2
215dd9dbb5SJeenu Viswambharan
225dd9dbb5SJeenu Viswambharan/* Special constant to specify that CPU has no reset function */
235dd9dbb5SJeenu Viswambharan#define CPU_NO_RESET_FUNC		0
245dd9dbb5SJeenu Viswambharan
255dd9dbb5SJeenu Viswambharan/* Word size for 32-bit CPUs */
265dd9dbb5SJeenu Viswambharan#define CPU_WORD_SIZE			4
275dd9dbb5SJeenu Viswambharan
28e33b78a6SSoby Mathew/*
2910bcd761SJeenu Viswambharan * Whether errata status needs reporting. Errata status is printed in debug
3010bcd761SJeenu Viswambharan * builds for both BL1 and BL32 images.
3110bcd761SJeenu Viswambharan */
3210bcd761SJeenu Viswambharan#if (defined(IMAGE_BL1) || defined(IMAGE_BL32)) && DEBUG
3310bcd761SJeenu Viswambharan# define REPORT_ERRATA	1
3410bcd761SJeenu Viswambharan#else
3510bcd761SJeenu Viswambharan# define REPORT_ERRATA	0
3610bcd761SJeenu Viswambharan#endif
3710bcd761SJeenu Viswambharan
38*f21b9f6dSRoberto Vargas
39*f21b9f6dSRoberto Vargas	.equ	CPU_MIDR_SIZE, CPU_WORD_SIZE
40*f21b9f6dSRoberto Vargas	.equ	CPU_RESET_FUNC_SIZE, CPU_WORD_SIZE
41*f21b9f6dSRoberto Vargas	.equ	CPU_PWR_DWN_OPS_SIZE, CPU_WORD_SIZE * CPU_MAX_PWR_DWN_OPS
42*f21b9f6dSRoberto Vargas	.equ	CPU_ERRATA_FUNC_SIZE, CPU_WORD_SIZE
43*f21b9f6dSRoberto Vargas	.equ	CPU_ERRATA_LOCK_SIZE, CPU_WORD_SIZE
44*f21b9f6dSRoberto Vargas	.equ	CPU_ERRATA_PRINTED_SIZE, CPU_WORD_SIZE
45*f21b9f6dSRoberto Vargas
46*f21b9f6dSRoberto Vargas#ifndef IMAGE_AT_EL3
47*f21b9f6dSRoberto Vargas	.equ	CPU_RESET_FUNC_SIZE, 0
48*f21b9f6dSRoberto Vargas#endif
49*f21b9f6dSRoberto Vargas
50*f21b9f6dSRoberto Vargas/* The power down core and cluster is needed only in BL32 */
51*f21b9f6dSRoberto Vargas#ifndef IMAGE_BL32
52*f21b9f6dSRoberto Vargas	.equ	CPU_PWR_DWN_OPS_SIZE, 0
53*f21b9f6dSRoberto Vargas#endif
54*f21b9f6dSRoberto Vargas
55*f21b9f6dSRoberto Vargas/* Fields required to print errata status  */
56*f21b9f6dSRoberto Vargas#if !REPORT_ERRATA
57*f21b9f6dSRoberto Vargas	.equ	CPU_ERRATA_FUNC_SIZE, 0
58*f21b9f6dSRoberto Vargas#endif
59*f21b9f6dSRoberto Vargas
60*f21b9f6dSRoberto Vargas/* Only BL32 requires mutual exclusion and printed flag. */
61*f21b9f6dSRoberto Vargas#if !(REPORT_ERRATA && defined(IMAGE_BL32))
62*f21b9f6dSRoberto Vargas	.equ	CPU_ERRATA_LOCK_SIZE, 0
63*f21b9f6dSRoberto Vargas	.equ	CPU_ERRATA_PRINTED_SIZE, 0
64*f21b9f6dSRoberto Vargas#endif
65*f21b9f6dSRoberto Vargas
66*f21b9f6dSRoberto Vargas
6710bcd761SJeenu Viswambharan/*
68e33b78a6SSoby Mathew * Define the offsets to the fields in cpu_ops structure.
69*f21b9f6dSRoberto Vargas * Every offset is defined based on the offset and size of the previous
70*f21b9f6dSRoberto Vargas * field.
71e33b78a6SSoby Mathew */
72*f21b9f6dSRoberto Vargas	.equ	CPU_MIDR, 0
73*f21b9f6dSRoberto Vargas	.equ	CPU_RESET_FUNC, CPU_MIDR + CPU_MIDR_SIZE
74*f21b9f6dSRoberto Vargas	.equ	CPU_PWR_DWN_OPS, CPU_RESET_FUNC + CPU_RESET_FUNC_SIZE
75*f21b9f6dSRoberto Vargas	.equ	CPU_ERRATA_FUNC, CPU_PWR_DWN_OPS + CPU_PWR_DWN_OPS_SIZE
76*f21b9f6dSRoberto Vargas	.equ	CPU_ERRATA_LOCK, CPU_ERRATA_FUNC + CPU_ERRATA_FUNC_SIZE
77*f21b9f6dSRoberto Vargas	.equ	CPU_ERRATA_PRINTED, CPU_ERRATA_LOCK + CPU_ERRATA_LOCK_SIZE
78*f21b9f6dSRoberto Vargas	.equ	CPU_OPS_SIZE, CPU_ERRATA_PRINTED + CPU_ERRATA_PRINTED_SIZE
79e33b78a6SSoby Mathew
80e33b78a6SSoby Mathew	/*
815dd9dbb5SJeenu Viswambharan	 * Write given expressions as words
825dd9dbb5SJeenu Viswambharan	 *
835dd9dbb5SJeenu Viswambharan	 * _count:
845dd9dbb5SJeenu Viswambharan	 *	Write at least _count words. If the given number of expressions
855dd9dbb5SJeenu Viswambharan	 *	is less than _count, repeat the last expression to fill _count
865dd9dbb5SJeenu Viswambharan	 *	words in total
875dd9dbb5SJeenu Viswambharan	 * _rest:
885dd9dbb5SJeenu Viswambharan	 *	Optional list of expressions. _this is for parameter extraction
895dd9dbb5SJeenu Viswambharan	 *	only, and has no significance to the caller
905dd9dbb5SJeenu Viswambharan	 *
915dd9dbb5SJeenu Viswambharan	 * Invoked as:
925dd9dbb5SJeenu Viswambharan	 *	fill_constants 2, foo, bar, blah, ...
93e33b78a6SSoby Mathew	 */
945dd9dbb5SJeenu Viswambharan	.macro fill_constants _count:req, _this, _rest:vararg
955dd9dbb5SJeenu Viswambharan	  .ifgt \_count
965dd9dbb5SJeenu Viswambharan	    /* Write the current expression */
975dd9dbb5SJeenu Viswambharan	    .ifb \_this
985dd9dbb5SJeenu Viswambharan	      .error "Nothing to fill"
995dd9dbb5SJeenu Viswambharan	    .endif
1005dd9dbb5SJeenu Viswambharan	    .word \_this
1015dd9dbb5SJeenu Viswambharan
1025dd9dbb5SJeenu Viswambharan	    /* Invoke recursively for remaining expressions */
1035dd9dbb5SJeenu Viswambharan	    .ifnb \_rest
1045dd9dbb5SJeenu Viswambharan	      fill_constants \_count-1, \_rest
1055dd9dbb5SJeenu Viswambharan	    .else
1065dd9dbb5SJeenu Viswambharan	      fill_constants \_count-1, \_this
1075dd9dbb5SJeenu Viswambharan	    .endif
1085dd9dbb5SJeenu Viswambharan	  .endif
1095dd9dbb5SJeenu Viswambharan	.endm
1105dd9dbb5SJeenu Viswambharan
1115dd9dbb5SJeenu Viswambharan	/*
1125dd9dbb5SJeenu Viswambharan	 * Declare CPU operations
1135dd9dbb5SJeenu Viswambharan	 *
1145dd9dbb5SJeenu Viswambharan	 * _name:
1155dd9dbb5SJeenu Viswambharan	 *	Name of the CPU for which operations are being specified
1165dd9dbb5SJeenu Viswambharan	 * _midr:
1175dd9dbb5SJeenu Viswambharan	 *	Numeric value expected to read from CPU's MIDR
1185dd9dbb5SJeenu Viswambharan	 * _resetfunc:
1195dd9dbb5SJeenu Viswambharan	 *	Reset function for the CPU. If there's no CPU reset function,
1205dd9dbb5SJeenu Viswambharan	 *	specify CPU_NO_RESET_FUNC
1215dd9dbb5SJeenu Viswambharan	 * _power_down_ops:
1225dd9dbb5SJeenu Viswambharan	 *	Comma-separated list of functions to perform power-down
1235dd9dbb5SJeenu Viswambharan	 *	operatios on the CPU. At least one, and up to
1245dd9dbb5SJeenu Viswambharan	 *	CPU_MAX_PWR_DWN_OPS number of functions may be specified.
1255dd9dbb5SJeenu Viswambharan	 *	Starting at power level 0, these functions shall handle power
1265dd9dbb5SJeenu Viswambharan	 *	down at subsequent power levels. If there aren't exactly
1275dd9dbb5SJeenu Viswambharan	 *	CPU_MAX_PWR_DWN_OPS functions, the last specified one will be
1285dd9dbb5SJeenu Viswambharan	 *	used to handle power down at subsequent levels
1295dd9dbb5SJeenu Viswambharan	 */
1305dd9dbb5SJeenu Viswambharan	.macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \
1315dd9dbb5SJeenu Viswambharan		_power_down_ops:vararg
132e33b78a6SSoby Mathew	.section cpu_ops, "a"
133e33b78a6SSoby Mathew	.align 2
134e33b78a6SSoby Mathew	.type cpu_ops_\_name, %object
135e33b78a6SSoby Mathew	.word \_midr
136b1d27b48SRoberto Vargas#if defined(IMAGE_AT_EL3)
1375dd9dbb5SJeenu Viswambharan	.word \_resetfunc
1381a0a3f06SYatharth Kochar#endif
1393d8256b2SMasahiro Yamada#ifdef IMAGE_BL32
1405dd9dbb5SJeenu Viswambharan1:
1415dd9dbb5SJeenu Viswambharan	/* Insert list of functions */
1425dd9dbb5SJeenu Viswambharan	fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops
1435dd9dbb5SJeenu Viswambharan2:
1445dd9dbb5SJeenu Viswambharan	/*
1455dd9dbb5SJeenu Viswambharan	 * Error if no or more than CPU_MAX_PWR_DWN_OPS were specified in the
1465dd9dbb5SJeenu Viswambharan	 * list
1475dd9dbb5SJeenu Viswambharan	 */
1485dd9dbb5SJeenu Viswambharan	.ifeq 2b - 1b
1495dd9dbb5SJeenu Viswambharan	  .error "At least one power down function must be specified"
1505dd9dbb5SJeenu Viswambharan	.else
1515dd9dbb5SJeenu Viswambharan	  .iflt 2b - 1b - (CPU_MAX_PWR_DWN_OPS * CPU_WORD_SIZE)
1525dd9dbb5SJeenu Viswambharan	    .error "More than CPU_MAX_PWR_DWN_OPS functions specified"
1535dd9dbb5SJeenu Viswambharan	  .endif
1545dd9dbb5SJeenu Viswambharan	.endif
1551a0a3f06SYatharth Kochar#endif
15610bcd761SJeenu Viswambharan
15710bcd761SJeenu Viswambharan#if REPORT_ERRATA
15810bcd761SJeenu Viswambharan	.ifndef \_name\()_cpu_str
15910bcd761SJeenu Viswambharan	  /*
16010bcd761SJeenu Viswambharan	   * Place errata reported flag, and the spinlock to arbitrate access to
16110bcd761SJeenu Viswambharan	   * it in the data section.
16210bcd761SJeenu Viswambharan	   */
16310bcd761SJeenu Viswambharan	  .pushsection .data
16410bcd761SJeenu Viswambharan	  define_asm_spinlock \_name\()_errata_lock
16510bcd761SJeenu Viswambharan	  \_name\()_errata_reported:
16610bcd761SJeenu Viswambharan	  .word	0
16710bcd761SJeenu Viswambharan	  .popsection
16810bcd761SJeenu Viswambharan
16910bcd761SJeenu Viswambharan	  /* Place CPU string in rodata */
17010bcd761SJeenu Viswambharan	  .pushsection .rodata
17110bcd761SJeenu Viswambharan	  \_name\()_cpu_str:
17210bcd761SJeenu Viswambharan	  .asciz "\_name"
17310bcd761SJeenu Viswambharan	  .popsection
17410bcd761SJeenu Viswambharan	.endif
17510bcd761SJeenu Viswambharan
17610bcd761SJeenu Viswambharan	/*
17710bcd761SJeenu Viswambharan	 * Weakly-bound, optional errata status printing function for CPUs of
17810bcd761SJeenu Viswambharan	 * this class.
17910bcd761SJeenu Viswambharan	 */
18010bcd761SJeenu Viswambharan	.weak \_name\()_errata_report
18110bcd761SJeenu Viswambharan	.word \_name\()_errata_report
18210bcd761SJeenu Viswambharan
18310bcd761SJeenu Viswambharan#ifdef IMAGE_BL32
18410bcd761SJeenu Viswambharan	/* Pointers to errata lock and reported flag */
18510bcd761SJeenu Viswambharan	.word \_name\()_errata_lock
18610bcd761SJeenu Viswambharan	.word \_name\()_errata_reported
18710bcd761SJeenu Viswambharan#endif
18810bcd761SJeenu Viswambharan#endif
189e33b78a6SSoby Mathew	.endm
190e33b78a6SSoby Mathew
19110bcd761SJeenu Viswambharan#if REPORT_ERRATA
19210bcd761SJeenu Viswambharan	/*
19310bcd761SJeenu Viswambharan	 * Print status of a CPU errata
19410bcd761SJeenu Viswambharan	 *
19510bcd761SJeenu Viswambharan	 * _chosen:
19610bcd761SJeenu Viswambharan	 *	Identifier indicating whether or not a CPU errata has been
19710bcd761SJeenu Viswambharan	 *	compiled in.
19810bcd761SJeenu Viswambharan	 * _cpu:
19910bcd761SJeenu Viswambharan	 *	Name of the CPU
20010bcd761SJeenu Viswambharan	 * _id:
20110bcd761SJeenu Viswambharan	 *	Errata identifier
20210bcd761SJeenu Viswambharan	 * _rev_var:
20310bcd761SJeenu Viswambharan	 *	Register containing the combined value CPU revision and variant
20410bcd761SJeenu Viswambharan	 *	- typically the return value of cpu_get_rev_var
20510bcd761SJeenu Viswambharan	 */
20610bcd761SJeenu Viswambharan	.macro report_errata _chosen, _cpu, _id, _rev_var=r4
20710bcd761SJeenu Viswambharan	/* Stash a string with errata ID */
20810bcd761SJeenu Viswambharan	.pushsection .rodata
20910bcd761SJeenu Viswambharan	\_cpu\()_errata_\_id\()_str:
21010bcd761SJeenu Viswambharan	.asciz	"\_id"
21110bcd761SJeenu Viswambharan	.popsection
21210bcd761SJeenu Viswambharan
21310bcd761SJeenu Viswambharan	/* Check whether errata applies */
21410bcd761SJeenu Viswambharan	mov	r0, \_rev_var
21510bcd761SJeenu Viswambharan	bl	check_errata_\_id
21610bcd761SJeenu Viswambharan
21710bcd761SJeenu Viswambharan	.ifeq \_chosen
21810bcd761SJeenu Viswambharan	/*
21910bcd761SJeenu Viswambharan	 * Errata workaround has not been compiled in. If the errata would have
22010bcd761SJeenu Viswambharan	 * applied had it been compiled in, print its status as missing.
22110bcd761SJeenu Viswambharan	 */
22210bcd761SJeenu Viswambharan	cmp	r0, #0
22310bcd761SJeenu Viswambharan	movne	r0, #ERRATA_MISSING
22410bcd761SJeenu Viswambharan	.endif
22510bcd761SJeenu Viswambharan	ldr	r1, =\_cpu\()_cpu_str
22610bcd761SJeenu Viswambharan	ldr	r2, =\_cpu\()_errata_\_id\()_str
22710bcd761SJeenu Viswambharan	bl	errata_print_msg
22810bcd761SJeenu Viswambharan	.endm
22910bcd761SJeenu Viswambharan#endif
23010bcd761SJeenu Viswambharan
231e33b78a6SSoby Mathew#endif /* __CPU_MACROS_S__ */
232