blob: f651040f9e2cd5ad714707be136e89bff7ad7388 [file] [log] [blame]
Soby Mathew748be1d2016-05-05 14:10:46 +01001/*
Ryan Everettd34d7fd2024-05-10 14:56:02 +01002 * Copyright (c) 2016-2024, 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
Boyan Karatoteve7d7c272023-01-25 16:55:18 +00009#include <lib/cpus/cpu_ops.h>
Boyan Karatotev5d38cb32023-01-27 09:37:07 +000010#include <lib/cpus/errata.h>
Soby Mathew748be1d2016-05-05 14:10:46 +010011
Soby Mathew748be1d2016-05-05 14:10:46 +010012 /*
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +000013 * Write given expressions as words
14 *
15 * _count:
16 * Write at least _count words. If the given number of expressions
17 * is less than _count, repeat the last expression to fill _count
18 * words in total
19 * _rest:
20 * Optional list of expressions. _this is for parameter extraction
21 * only, and has no significance to the caller
22 *
23 * Invoked as:
24 * fill_constants 2, foo, bar, blah, ...
Soby Mathew748be1d2016-05-05 14:10:46 +010025 */
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +000026 .macro fill_constants _count:req, _this, _rest:vararg
27 .ifgt \_count
28 /* Write the current expression */
29 .ifb \_this
30 .error "Nothing to fill"
31 .endif
32 .word \_this
33
34 /* Invoke recursively for remaining expressions */
35 .ifnb \_rest
36 fill_constants \_count-1, \_rest
37 .else
38 fill_constants \_count-1, \_this
39 .endif
40 .endif
41 .endm
42
43 /*
44 * Declare CPU operations
45 *
46 * _name:
47 * Name of the CPU for which operations are being specified
48 * _midr:
49 * Numeric value expected to read from CPU's MIDR
50 * _resetfunc:
51 * Reset function for the CPU. If there's no CPU reset function,
52 * specify CPU_NO_RESET_FUNC
53 * _power_down_ops:
54 * Comma-separated list of functions to perform power-down
55 * operatios on the CPU. At least one, and up to
56 * CPU_MAX_PWR_DWN_OPS number of functions may be specified.
57 * Starting at power level 0, these functions shall handle power
58 * down at subsequent power levels. If there aren't exactly
59 * CPU_MAX_PWR_DWN_OPS functions, the last specified one will be
60 * used to handle power down at subsequent levels
61 */
62 .macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \
63 _power_down_ops:vararg
Chris Kay33bfc5e2023-02-14 11:30:04 +000064 .section .cpu_ops, "a"
Soby Mathew748be1d2016-05-05 14:10:46 +010065 .align 2
66 .type cpu_ops_\_name, %object
67 .word \_midr
Roberto Vargase0e99462017-10-30 14:43:43 +000068#if defined(IMAGE_AT_EL3)
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +000069 .word \_resetfunc
Yatharth Kocharf528faf2016-06-28 16:58:26 +010070#endif
Masahiro Yamada441bfdd2016-12-25 23:36:24 +090071#ifdef IMAGE_BL32
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +000072 /* Insert list of functions */
73 fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops
Yatharth Kocharf528faf2016-06-28 16:58:26 +010074#endif
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000075
Boyan Karatoteve7807d22023-01-26 17:29:35 +000076 /*
77 * It is possible (although unlikely) that a cpu may have no errata in
78 * code. In that case the start label will not be defined. The list is
79 * inteded to be used in a loop, so define it as zero-length for
80 * predictable behaviour. Since this macro is always called at the end
81 * of the cpu file (after all errata have been parsed) we can be sure
82 * that we are at the end of the list. Some cpus call the macro twice,
83 * so only do this once.
84 */
85 .pushsection .rodata.errata_entries
86 .ifndef \_name\()_errata_list_start
87 \_name\()_errata_list_start:
88 .endif
89 /* some call this multiple times, so only do this once */
90 .ifndef \_name\()_errata_list_end
91 \_name\()_errata_list_end:
92 .endif
93 .popsection
94
95 /* and now put them in cpu_ops */
96 .word \_name\()_errata_list_start
97 .word \_name\()_errata_list_end
98
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000099#if REPORT_ERRATA
100 .ifndef \_name\()_cpu_str
101 /*
102 * Place errata reported flag, and the spinlock to arbitrate access to
103 * it in the data section.
104 */
105 .pushsection .data
106 define_asm_spinlock \_name\()_errata_lock
107 \_name\()_errata_reported:
108 .word 0
109 .popsection
110
111 /* Place CPU string in rodata */
112 .pushsection .rodata
113 \_name\()_cpu_str:
114 .asciz "\_name"
115 .popsection
116 .endif
117
118 /*
Soby Mathew0980dce2018-09-17 04:34:35 +0100119 * Mandatory errata status printing function for CPUs of
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000120 * this class.
121 */
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000122 .word \_name\()_errata_report
Boyan Karatoteve7807d22023-01-26 17:29:35 +0000123 .word \_name\()_cpu_str
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000124
125#ifdef IMAGE_BL32
126 /* Pointers to errata lock and reported flag */
127 .word \_name\()_errata_lock
128 .word \_name\()_errata_reported
129#endif
130#endif
Soby Mathew748be1d2016-05-05 14:10:46 +0100131 .endm
132
Deepak Pandeyb5615362018-10-11 13:44:43 +0530133 /*
134 * Helper macro that reads the part number of the current CPU and jumps
135 * to the given label if it matches the CPU MIDR provided.
136 *
137 * Clobbers: r0-r1
138 */
139 .macro jump_if_cpu_midr _cpu_midr, _label
140 ldcopr r0, MIDR
141 ubfx r0, r0, #MIDR_PN_SHIFT, #12
142 ldr r1, =((\_cpu_midr >> MIDR_PN_SHIFT) & MIDR_PN_MASK)
143 cmp r0, r1
144 beq \_label
145 .endm
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000146
Boyan Karatoteve7807d22023-01-26 17:29:35 +0000147/*
148 * NOTE an erratum and CVE id could clash. However, both numbers are very large
149 * and the probablity is minuscule. Working around this makes code very
150 * complicated and extremely difficult to read so it is not considered. In the
151 * unlikely event that this does happen, prepending the CVE id with a 0 should
152 * resolve the conflict
153 */
154
155/*
156 * Add an entry for this erratum to the errata framework
157 *
158 * _cpu:
159 * Name of cpu as given to declare_cpu_ops
160 *
161 * _cve:
162 * Whether erratum is a CVE. CVE year if yes, 0 otherwise
163 *
164 * _id:
165 * Erratum or CVE number. Please combine with the previous field with the
166 * ERRATUM or CVE macros
167 *
168 * _chosen:
169 * Compile time flag on whether the erratum is included
170 *
171 * _special:
172 * The special non-standard name of an erratum
173 */
174.macro add_erratum_entry _cpu:req, _cve:req, _id:req, _chosen:req, _special
175 .pushsection .rodata.errata_entries
176 .align 2
177 .ifndef \_cpu\()_errata_list_start
178 \_cpu\()_errata_list_start:
179 .endif
180
181 /* unused on AArch32, maintain for portability */
182 .word 0
183 /* TODO(errata ABI): this prevents all checker functions from
184 * being optimised away. Can be done away with unless the ABI
185 * needs them */
186 .ifnb \_special
187 .word check_errata_\_special
188 .elseif \_cve
189 .word check_errata_cve_\_cve\()_\_id
190 .else
191 .word check_errata_\_id
192 .endif
193 /* Will fit CVEs with up to 10 character in the ID field */
194 .word \_id
195 .hword \_cve
196 .byte \_chosen
197 /* TODO(errata ABI): mitigated field for known but unmitigated
198 * errata*/
199 .byte 0x1
200 .popsection
201.endm
202
203/*
204 * Maintain compatibility with the old scheme of "each cpu has its own reporter".
205 * TODO remove entirely once all cpus have been converted. This includes the
206 * cpu_ops entry, as print_errata_status can call this directly for all cpus
207 */
208.macro errata_report_shim _cpu:req
209 #if REPORT_ERRATA
210 func \_cpu\()_errata_report
211 push {r12, lr}
212
213 bl generic_errata_report
214
215 pop {r12, lr}
216 bx lr
217 endfunc \_cpu\()_errata_report
218 #endif
219.endm
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000220#endif /* CPU_MACROS_S */