Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 2 | * Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 5 | */ |
Dan Handley | ea59668 | 2015-04-01 17:34:24 +0100 | [diff] [blame] | 6 | #ifndef __CPU_MACROS_S__ |
| 7 | #define __CPU_MACROS_S__ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 8 | |
| 9 | #include <arch.h> |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 10 | #include <errata_report.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 11 | |
Soby Mathew | c704cbc | 2014-08-14 11:33:56 +0100 | [diff] [blame] | 12 | #define CPU_IMPL_PN_MASK (MIDR_IMPL_MASK << MIDR_IMPL_SHIFT) | \ |
| 13 | (MIDR_PN_MASK << MIDR_PN_SHIFT) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 14 | |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 15 | /* The number of CPU operations allowed */ |
| 16 | #define CPU_MAX_PWR_DWN_OPS 2 |
| 17 | |
| 18 | /* Special constant to specify that CPU has no reset function */ |
| 19 | #define CPU_NO_RESET_FUNC 0 |
| 20 | |
| 21 | /* Word size for 64-bit CPUs */ |
| 22 | #define CPU_WORD_SIZE 8 |
| 23 | |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 24 | #if defined(IMAGE_BL1) || defined(IMAGE_BL31) ||(defined(IMAGE_BL2) && BL2_AT_EL3) |
| 25 | #define IMAGE_AT_EL3 |
| 26 | #endif |
| 27 | |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 28 | /* |
| 29 | * Whether errata status needs reporting. Errata status is printed in debug |
| 30 | * builds for both BL1 and BL31 images. |
| 31 | */ |
| 32 | #if (defined(IMAGE_BL1) || defined(IMAGE_BL31)) && DEBUG |
| 33 | # define REPORT_ERRATA 1 |
| 34 | #else |
| 35 | # define REPORT_ERRATA 0 |
| 36 | #endif |
| 37 | |
Soby Mathew | c704cbc | 2014-08-14 11:33:56 +0100 | [diff] [blame] | 38 | /* |
| 39 | * Define the offsets to the fields in cpu_ops structure. |
| 40 | */ |
| 41 | .struct 0 |
| 42 | CPU_MIDR: /* cpu_ops midr */ |
| 43 | .space 8 |
| 44 | /* Reset fn is needed in BL at reset vector */ |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 45 | #if defined(IMAGE_AT_EL3) |
Soby Mathew | c704cbc | 2014-08-14 11:33:56 +0100 | [diff] [blame] | 46 | CPU_RESET_FUNC: /* cpu_ops reset_func */ |
| 47 | .space 8 |
| 48 | #endif |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 49 | #ifdef IMAGE_BL31 /* The power down core and cluster is needed only in BL31 */ |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 50 | CPU_PWR_DWN_OPS: /* cpu_ops power down functions */ |
| 51 | .space (8 * CPU_MAX_PWR_DWN_OPS) |
Soby Mathew | 8e2f287 | 2014-08-14 12:49:05 +0100 | [diff] [blame] | 52 | #endif |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * Fields required to print errata status. Only in BL31 that the printing |
| 56 | * require mutual exclusion and printed flag. |
| 57 | */ |
| 58 | #if REPORT_ERRATA |
| 59 | CPU_ERRATA_FUNC: |
| 60 | .space 8 |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 61 | #if defined(IMAGE_BL31) |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 62 | CPU_ERRATA_LOCK: |
| 63 | .space 8 |
| 64 | CPU_ERRATA_PRINTED: |
| 65 | .space 8 |
| 66 | #endif |
| 67 | #endif |
| 68 | |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 69 | #if defined(IMAGE_BL31) && CRASH_REPORTING |
Soby Mathew | 38b4bc9 | 2014-08-14 13:36:41 +0100 | [diff] [blame] | 70 | CPU_REG_DUMP: /* cpu specific register dump for crash reporting */ |
| 71 | .space 8 |
| 72 | #endif |
Soby Mathew | c704cbc | 2014-08-14 11:33:56 +0100 | [diff] [blame] | 73 | CPU_OPS_SIZE = . |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 74 | |
Soby Mathew | c704cbc | 2014-08-14 11:33:56 +0100 | [diff] [blame] | 75 | /* |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 76 | * Write given expressions as quad words |
| 77 | * |
| 78 | * _count: |
| 79 | * Write at least _count quad words. If the given number of |
| 80 | * expressions is less than _count, repeat the last expression to |
| 81 | * fill _count quad words in total |
| 82 | * _rest: |
| 83 | * Optional list of expressions. _this is for parameter extraction |
| 84 | * only, and has no significance to the caller |
| 85 | * |
| 86 | * Invoked as: |
| 87 | * fill_constants 2, foo, bar, blah, ... |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 88 | */ |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 89 | .macro fill_constants _count:req, _this, _rest:vararg |
| 90 | .ifgt \_count |
| 91 | /* Write the current expression */ |
| 92 | .ifb \_this |
| 93 | .error "Nothing to fill" |
| 94 | .endif |
| 95 | .quad \_this |
| 96 | |
| 97 | /* Invoke recursively for remaining expressions */ |
| 98 | .ifnb \_rest |
| 99 | fill_constants \_count-1, \_rest |
| 100 | .else |
| 101 | fill_constants \_count-1, \_this |
| 102 | .endif |
| 103 | .endif |
| 104 | .endm |
| 105 | |
| 106 | /* |
| 107 | * Declare CPU operations |
| 108 | * |
| 109 | * _name: |
| 110 | * Name of the CPU for which operations are being specified |
| 111 | * _midr: |
| 112 | * Numeric value expected to read from CPU's MIDR |
| 113 | * _resetfunc: |
| 114 | * Reset function for the CPU. If there's no CPU reset function, |
| 115 | * specify CPU_NO_RESET_FUNC |
| 116 | * _power_down_ops: |
| 117 | * Comma-separated list of functions to perform power-down |
| 118 | * operatios on the CPU. At least one, and up to |
| 119 | * CPU_MAX_PWR_DWN_OPS number of functions may be specified. |
| 120 | * Starting at power level 0, these functions shall handle power |
| 121 | * down at subsequent power levels. If there aren't exactly |
| 122 | * CPU_MAX_PWR_DWN_OPS functions, the last specified one will be |
| 123 | * used to handle power down at subsequent levels |
| 124 | */ |
| 125 | .macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \ |
| 126 | _power_down_ops:vararg |
| 127 | .section cpu_ops, "a" |
| 128 | .align 3 |
Soby Mathew | c704cbc | 2014-08-14 11:33:56 +0100 | [diff] [blame] | 129 | .type cpu_ops_\_name, %object |
| 130 | .quad \_midr |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 131 | #if defined(IMAGE_AT_EL3) |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 132 | .quad \_resetfunc |
Soby Mathew | c704cbc | 2014-08-14 11:33:56 +0100 | [diff] [blame] | 133 | #endif |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 134 | #ifdef IMAGE_BL31 |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 135 | 1: |
| 136 | /* Insert list of functions */ |
| 137 | fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops |
| 138 | 2: |
| 139 | /* |
| 140 | * Error if no or more than CPU_MAX_PWR_DWN_OPS were specified in the |
| 141 | * list |
| 142 | */ |
| 143 | .ifeq 2b - 1b |
| 144 | .error "At least one power down function must be specified" |
| 145 | .else |
| 146 | .iflt 2b - 1b - (CPU_MAX_PWR_DWN_OPS * CPU_WORD_SIZE) |
| 147 | .error "More than CPU_MAX_PWR_DWN_OPS functions specified" |
| 148 | .endif |
| 149 | .endif |
Soby Mathew | 8e2f287 | 2014-08-14 12:49:05 +0100 | [diff] [blame] | 150 | #endif |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 151 | |
| 152 | #if REPORT_ERRATA |
| 153 | .ifndef \_name\()_cpu_str |
| 154 | /* |
| 155 | * Place errata reported flag, and the spinlock to arbitrate access to |
| 156 | * it in the data section. |
| 157 | */ |
| 158 | .pushsection .data |
| 159 | define_asm_spinlock \_name\()_errata_lock |
| 160 | \_name\()_errata_reported: |
| 161 | .word 0 |
| 162 | .popsection |
| 163 | |
| 164 | /* Place CPU string in rodata */ |
| 165 | .pushsection .rodata |
| 166 | \_name\()_cpu_str: |
| 167 | .asciz "\_name" |
| 168 | .popsection |
| 169 | .endif |
| 170 | |
| 171 | /* |
| 172 | * Weakly-bound, optional errata status printing function for CPUs of |
| 173 | * this class. |
| 174 | */ |
| 175 | .weak \_name\()_errata_report |
| 176 | .quad \_name\()_errata_report |
| 177 | |
| 178 | #ifdef IMAGE_BL31 |
| 179 | /* Pointers to errata lock and reported flag */ |
| 180 | .quad \_name\()_errata_lock |
| 181 | .quad \_name\()_errata_reported |
| 182 | #endif |
| 183 | #endif |
| 184 | |
Masahiro Yamada | 441bfdd | 2016-12-25 23:36:24 +0900 | [diff] [blame] | 185 | #if defined(IMAGE_BL31) && CRASH_REPORTING |
Soby Mathew | 38b4bc9 | 2014-08-14 13:36:41 +0100 | [diff] [blame] | 186 | .quad \_name\()_cpu_reg_dump |
| 187 | #endif |
Soby Mathew | c704cbc | 2014-08-14 11:33:56 +0100 | [diff] [blame] | 188 | .endm |
Dan Handley | ea59668 | 2015-04-01 17:34:24 +0100 | [diff] [blame] | 189 | |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 190 | #if REPORT_ERRATA |
| 191 | /* |
| 192 | * Print status of a CPU errata |
| 193 | * |
| 194 | * _chosen: |
| 195 | * Identifier indicating whether or not a CPU errata has been |
| 196 | * compiled in. |
| 197 | * _cpu: |
| 198 | * Name of the CPU |
| 199 | * _id: |
| 200 | * Errata identifier |
| 201 | * _rev_var: |
| 202 | * Register containing the combined value CPU revision and variant |
| 203 | * - typically the return value of cpu_get_rev_var |
| 204 | */ |
| 205 | .macro report_errata _chosen, _cpu, _id, _rev_var=x8 |
| 206 | /* Stash a string with errata ID */ |
| 207 | .pushsection .rodata |
| 208 | \_cpu\()_errata_\_id\()_str: |
| 209 | .asciz "\_id" |
| 210 | .popsection |
| 211 | |
| 212 | /* Check whether errata applies */ |
| 213 | mov x0, \_rev_var |
| 214 | bl check_errata_\_id |
| 215 | |
| 216 | .ifeq \_chosen |
| 217 | /* |
| 218 | * Errata workaround has not been compiled in. If the errata would have |
| 219 | * applied had it been compiled in, print its status as missing. |
| 220 | */ |
| 221 | cbz x0, 900f |
| 222 | mov x0, #ERRATA_MISSING |
| 223 | .endif |
| 224 | 900: |
| 225 | adr x1, \_cpu\()_cpu_str |
| 226 | adr x2, \_cpu\()_errata_\_id\()_str |
| 227 | bl errata_print_msg |
| 228 | .endm |
| 229 | #endif |
| 230 | |
Dan Handley | ea59668 | 2015-04-01 17:34:24 +0100 | [diff] [blame] | 231 | #endif /* __CPU_MACROS_S__ */ |