blob: 1f03f0992ef7b186249876f083f02c6fb7bb819e [file] [log] [blame]
Soby Mathew748be1d2016-05-05 14:10:46 +01001/*
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00002 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathew748be1d2016-05-05 14:10:46 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew748be1d2016-05-05 14:10:46 +01005 */
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00006#ifndef CPU_MACROS_S
7#define CPU_MACROS_S
Soby Mathew748be1d2016-05-05 14:10:46 +01008
9#include <arch.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <lib/cpus/errata_report.h>
Soby Mathew748be1d2016-05-05 14:10:46 +010011
Roberto Vargase0e99462017-10-30 14:43:43 +000012#if defined(IMAGE_BL1) || defined(IMAGE_BL32) || (defined(IMAGE_BL2) && BL2_AT_EL3)
13#define IMAGE_AT_EL3
14#endif
15
Soby Mathew748be1d2016-05-05 14:10:46 +010016#define CPU_IMPL_PN_MASK (MIDR_IMPL_MASK << MIDR_IMPL_SHIFT) | \
17 (MIDR_PN_MASK << MIDR_PN_SHIFT)
18
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +000019/* The number of CPU operations allowed */
20#define CPU_MAX_PWR_DWN_OPS 2
21
22/* Special constant to specify that CPU has no reset function */
23#define CPU_NO_RESET_FUNC 0
24
25/* Word size for 32-bit CPUs */
26#define CPU_WORD_SIZE 4
27
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000028/*
29 * Whether errata status needs reporting. Errata status is printed in debug
30 * builds for both BL1 and BL32 images.
31 */
32#if (defined(IMAGE_BL1) || defined(IMAGE_BL32)) && DEBUG
33# define REPORT_ERRATA 1
34#else
35# define REPORT_ERRATA 0
36#endif
37
Roberto Vargas67762d92018-05-01 09:54:54 +010038
39 .equ CPU_MIDR_SIZE, CPU_WORD_SIZE
40 .equ CPU_RESET_FUNC_SIZE, CPU_WORD_SIZE
41 .equ CPU_PWR_DWN_OPS_SIZE, CPU_WORD_SIZE * CPU_MAX_PWR_DWN_OPS
42 .equ CPU_ERRATA_FUNC_SIZE, CPU_WORD_SIZE
43 .equ CPU_ERRATA_LOCK_SIZE, CPU_WORD_SIZE
44 .equ CPU_ERRATA_PRINTED_SIZE, CPU_WORD_SIZE
45
46#ifndef IMAGE_AT_EL3
47 .equ CPU_RESET_FUNC_SIZE, 0
Yatharth Kocharf528faf2016-06-28 16:58:26 +010048#endif
Roberto Vargas67762d92018-05-01 09:54:54 +010049
50/* The power down core and cluster is needed only in BL32 */
51#ifndef IMAGE_BL32
52 .equ CPU_PWR_DWN_OPS_SIZE, 0
Yatharth Kocharf528faf2016-06-28 16:58:26 +010053#endif
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000054
Roberto Vargas67762d92018-05-01 09:54:54 +010055/* Fields required to print errata status */
56#if !REPORT_ERRATA
57 .equ CPU_ERRATA_FUNC_SIZE, 0
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000058#endif
Roberto Vargas67762d92018-05-01 09:54:54 +010059
60/* Only BL32 requires mutual exclusion and printed flag. */
61#if !(REPORT_ERRATA && defined(IMAGE_BL32))
62 .equ CPU_ERRATA_LOCK_SIZE, 0
63 .equ CPU_ERRATA_PRINTED_SIZE, 0
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000064#endif
65
Roberto Vargas67762d92018-05-01 09:54:54 +010066
67/*
68 * Define the offsets to the fields in cpu_ops structure.
69 * Every offset is defined based on the offset and size of the previous
70 * field.
71 */
72 .equ CPU_MIDR, 0
73 .equ CPU_RESET_FUNC, CPU_MIDR + CPU_MIDR_SIZE
74 .equ CPU_PWR_DWN_OPS, CPU_RESET_FUNC + CPU_RESET_FUNC_SIZE
75 .equ CPU_ERRATA_FUNC, CPU_PWR_DWN_OPS + CPU_PWR_DWN_OPS_SIZE
76 .equ CPU_ERRATA_LOCK, CPU_ERRATA_FUNC + CPU_ERRATA_FUNC_SIZE
77 .equ CPU_ERRATA_PRINTED, CPU_ERRATA_LOCK + CPU_ERRATA_LOCK_SIZE
78 .equ CPU_OPS_SIZE, CPU_ERRATA_PRINTED + CPU_ERRATA_PRINTED_SIZE
Soby Mathew748be1d2016-05-05 14:10:46 +010079
80 /*
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +000081 * Write given expressions as words
82 *
83 * _count:
84 * Write at least _count words. If the given number of expressions
85 * is less than _count, repeat the last expression to fill _count
86 * words in total
87 * _rest:
88 * Optional list of expressions. _this is for parameter extraction
89 * only, and has no significance to the caller
90 *
91 * Invoked as:
92 * fill_constants 2, foo, bar, blah, ...
Soby Mathew748be1d2016-05-05 14:10:46 +010093 */
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +000094 .macro fill_constants _count:req, _this, _rest:vararg
95 .ifgt \_count
96 /* Write the current expression */
97 .ifb \_this
98 .error "Nothing to fill"
99 .endif
100 .word \_this
101
102 /* Invoke recursively for remaining expressions */
103 .ifnb \_rest
104 fill_constants \_count-1, \_rest
105 .else
106 fill_constants \_count-1, \_this
107 .endif
108 .endif
109 .endm
110
111 /*
112 * Declare CPU operations
113 *
114 * _name:
115 * Name of the CPU for which operations are being specified
116 * _midr:
117 * Numeric value expected to read from CPU's MIDR
118 * _resetfunc:
119 * Reset function for the CPU. If there's no CPU reset function,
120 * specify CPU_NO_RESET_FUNC
121 * _power_down_ops:
122 * Comma-separated list of functions to perform power-down
123 * operatios on the CPU. At least one, and up to
124 * CPU_MAX_PWR_DWN_OPS number of functions may be specified.
125 * Starting at power level 0, these functions shall handle power
126 * down at subsequent power levels. If there aren't exactly
127 * CPU_MAX_PWR_DWN_OPS functions, the last specified one will be
128 * used to handle power down at subsequent levels
129 */
130 .macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \
131 _power_down_ops:vararg
Chris Kay33bfc5e2023-02-14 11:30:04 +0000132 .section .cpu_ops, "a"
Soby Mathew748be1d2016-05-05 14:10:46 +0100133 .align 2
134 .type cpu_ops_\_name, %object
135 .word \_midr
Roberto Vargase0e99462017-10-30 14:43:43 +0000136#if defined(IMAGE_AT_EL3)
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000137 .word \_resetfunc
Yatharth Kocharf528faf2016-06-28 16:58:26 +0100138#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +0900139#ifdef IMAGE_BL32
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000140 /* Insert list of functions */
141 fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops
Yatharth Kocharf528faf2016-06-28 16:58:26 +0100142#endif
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000143
144#if REPORT_ERRATA
145 .ifndef \_name\()_cpu_str
146 /*
147 * Place errata reported flag, and the spinlock to arbitrate access to
148 * it in the data section.
149 */
150 .pushsection .data
151 define_asm_spinlock \_name\()_errata_lock
152 \_name\()_errata_reported:
153 .word 0
154 .popsection
155
156 /* Place CPU string in rodata */
157 .pushsection .rodata
158 \_name\()_cpu_str:
159 .asciz "\_name"
160 .popsection
161 .endif
162
163 /*
Soby Mathew0980dce2018-09-17 04:34:35 +0100164 * Mandatory errata status printing function for CPUs of
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000165 * this class.
166 */
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000167 .word \_name\()_errata_report
168
169#ifdef IMAGE_BL32
170 /* Pointers to errata lock and reported flag */
171 .word \_name\()_errata_lock
172 .word \_name\()_errata_reported
173#endif
174#endif
Soby Mathew748be1d2016-05-05 14:10:46 +0100175 .endm
176
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000177#if REPORT_ERRATA
178 /*
179 * Print status of a CPU errata
180 *
181 * _chosen:
182 * Identifier indicating whether or not a CPU errata has been
183 * compiled in.
184 * _cpu:
185 * Name of the CPU
186 * _id:
187 * Errata identifier
188 * _rev_var:
189 * Register containing the combined value CPU revision and variant
190 * - typically the return value of cpu_get_rev_var
191 */
192 .macro report_errata _chosen, _cpu, _id, _rev_var=r4
193 /* Stash a string with errata ID */
194 .pushsection .rodata
195 \_cpu\()_errata_\_id\()_str:
196 .asciz "\_id"
197 .popsection
198
199 /* Check whether errata applies */
200 mov r0, \_rev_var
201 bl check_errata_\_id
202
203 .ifeq \_chosen
204 /*
205 * Errata workaround has not been compiled in. If the errata would have
206 * applied had it been compiled in, print its status as missing.
207 */
208 cmp r0, #0
209 movne r0, #ERRATA_MISSING
210 .endif
211 ldr r1, =\_cpu\()_cpu_str
212 ldr r2, =\_cpu\()_errata_\_id\()_str
213 bl errata_print_msg
214 .endm
215#endif
Deepak Pandeyb5615362018-10-11 13:44:43 +0530216 /*
217 * Helper macro that reads the part number of the current CPU and jumps
218 * to the given label if it matches the CPU MIDR provided.
219 *
220 * Clobbers: r0-r1
221 */
222 .macro jump_if_cpu_midr _cpu_midr, _label
223 ldcopr r0, MIDR
224 ubfx r0, r0, #MIDR_PN_SHIFT, #12
225 ldr r1, =((\_cpu_midr >> MIDR_PN_SHIFT) & MIDR_PN_MASK)
226 cmp r0, r1
227 beq \_label
228 .endm
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000229
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000230#endif /* CPU_MACROS_S */