1add40351SSoby Mathew/* 2*10bcd761SJeenu Viswambharan * Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved. 3add40351SSoby Mathew * 4add40351SSoby Mathew * Redistribution and use in source and binary forms, with or without 5add40351SSoby Mathew * modification, are permitted provided that the following conditions are met: 6add40351SSoby Mathew * 7add40351SSoby Mathew * Redistributions of source code must retain the above copyright notice, this 8add40351SSoby Mathew * list of conditions and the following disclaimer. 9add40351SSoby Mathew * 10add40351SSoby Mathew * Redistributions in binary form must reproduce the above copyright notice, 11add40351SSoby Mathew * this list of conditions and the following disclaimer in the documentation 12add40351SSoby Mathew * and/or other materials provided with the distribution. 13add40351SSoby Mathew * 14add40351SSoby Mathew * Neither the name of ARM nor the names of its contributors may be used 15add40351SSoby Mathew * to endorse or promote products derived from this software without specific 16add40351SSoby Mathew * prior written permission. 17add40351SSoby Mathew * 18add40351SSoby Mathew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19add40351SSoby Mathew * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20add40351SSoby Mathew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21add40351SSoby Mathew * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22add40351SSoby Mathew * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23add40351SSoby Mathew * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24add40351SSoby Mathew * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25add40351SSoby Mathew * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26add40351SSoby Mathew * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27add40351SSoby Mathew * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28add40351SSoby Mathew * POSSIBILITY OF SUCH DAMAGE. 29add40351SSoby Mathew */ 30e2bf57f8SDan Handley#ifndef __CPU_MACROS_S__ 31e2bf57f8SDan Handley#define __CPU_MACROS_S__ 32add40351SSoby Mathew 33add40351SSoby Mathew#include <arch.h> 34*10bcd761SJeenu Viswambharan#include <errata_report.h> 35add40351SSoby Mathew 36add40351SSoby Mathew#define CPU_IMPL_PN_MASK (MIDR_IMPL_MASK << MIDR_IMPL_SHIFT) | \ 37add40351SSoby Mathew (MIDR_PN_MASK << MIDR_PN_SHIFT) 38add40351SSoby Mathew 395dd9dbb5SJeenu Viswambharan/* The number of CPU operations allowed */ 405dd9dbb5SJeenu Viswambharan#define CPU_MAX_PWR_DWN_OPS 2 415dd9dbb5SJeenu Viswambharan 425dd9dbb5SJeenu Viswambharan/* Special constant to specify that CPU has no reset function */ 435dd9dbb5SJeenu Viswambharan#define CPU_NO_RESET_FUNC 0 445dd9dbb5SJeenu Viswambharan 455dd9dbb5SJeenu Viswambharan/* Word size for 64-bit CPUs */ 465dd9dbb5SJeenu Viswambharan#define CPU_WORD_SIZE 8 475dd9dbb5SJeenu Viswambharan 48add40351SSoby Mathew/* 49*10bcd761SJeenu Viswambharan * Whether errata status needs reporting. Errata status is printed in debug 50*10bcd761SJeenu Viswambharan * builds for both BL1 and BL31 images. 51*10bcd761SJeenu Viswambharan */ 52*10bcd761SJeenu Viswambharan#if (defined(IMAGE_BL1) || defined(IMAGE_BL31)) && DEBUG 53*10bcd761SJeenu Viswambharan# define REPORT_ERRATA 1 54*10bcd761SJeenu Viswambharan#else 55*10bcd761SJeenu Viswambharan# define REPORT_ERRATA 0 56*10bcd761SJeenu Viswambharan#endif 57*10bcd761SJeenu Viswambharan 58*10bcd761SJeenu Viswambharan /* 59add40351SSoby Mathew * Define the offsets to the fields in cpu_ops structure. 60add40351SSoby Mathew */ 61add40351SSoby Mathew .struct 0 62add40351SSoby MathewCPU_MIDR: /* cpu_ops midr */ 63add40351SSoby Mathew .space 8 64add40351SSoby Mathew/* Reset fn is needed in BL at reset vector */ 653d8256b2SMasahiro Yamada#if defined(IMAGE_BL1) || defined(IMAGE_BL31) 66add40351SSoby MathewCPU_RESET_FUNC: /* cpu_ops reset_func */ 67add40351SSoby Mathew .space 8 68add40351SSoby Mathew#endif 693d8256b2SMasahiro Yamada#ifdef IMAGE_BL31 /* The power down core and cluster is needed only in BL31 */ 705dd9dbb5SJeenu ViswambharanCPU_PWR_DWN_OPS: /* cpu_ops power down functions */ 715dd9dbb5SJeenu Viswambharan .space (8 * CPU_MAX_PWR_DWN_OPS) 72add40351SSoby Mathew#endif 73*10bcd761SJeenu Viswambharan 74*10bcd761SJeenu Viswambharan/* 75*10bcd761SJeenu Viswambharan * Fields required to print errata status. Only in BL31 that the printing 76*10bcd761SJeenu Viswambharan * require mutual exclusion and printed flag. 77*10bcd761SJeenu Viswambharan */ 78*10bcd761SJeenu Viswambharan#if REPORT_ERRATA 79*10bcd761SJeenu ViswambharanCPU_ERRATA_FUNC: 80*10bcd761SJeenu Viswambharan .space 8 81*10bcd761SJeenu Viswambharan#ifdef IMAGE_BL31 82*10bcd761SJeenu ViswambharanCPU_ERRATA_LOCK: 83*10bcd761SJeenu Viswambharan .space 8 84*10bcd761SJeenu ViswambharanCPU_ERRATA_PRINTED: 85*10bcd761SJeenu Viswambharan .space 8 86*10bcd761SJeenu Viswambharan#endif 87*10bcd761SJeenu Viswambharan#endif 88*10bcd761SJeenu Viswambharan 893d8256b2SMasahiro Yamada#if defined(IMAGE_BL31) && CRASH_REPORTING 90d3f70af6SSoby MathewCPU_REG_DUMP: /* cpu specific register dump for crash reporting */ 91d3f70af6SSoby Mathew .space 8 92d3f70af6SSoby Mathew#endif 93add40351SSoby MathewCPU_OPS_SIZE = . 94add40351SSoby Mathew 95add40351SSoby Mathew /* 965dd9dbb5SJeenu Viswambharan * Write given expressions as quad words 975dd9dbb5SJeenu Viswambharan * 985dd9dbb5SJeenu Viswambharan * _count: 995dd9dbb5SJeenu Viswambharan * Write at least _count quad words. If the given number of 1005dd9dbb5SJeenu Viswambharan * expressions is less than _count, repeat the last expression to 1015dd9dbb5SJeenu Viswambharan * fill _count quad words in total 1025dd9dbb5SJeenu Viswambharan * _rest: 1035dd9dbb5SJeenu Viswambharan * Optional list of expressions. _this is for parameter extraction 1045dd9dbb5SJeenu Viswambharan * only, and has no significance to the caller 1055dd9dbb5SJeenu Viswambharan * 1065dd9dbb5SJeenu Viswambharan * Invoked as: 1075dd9dbb5SJeenu Viswambharan * fill_constants 2, foo, bar, blah, ... 108add40351SSoby Mathew */ 1095dd9dbb5SJeenu Viswambharan .macro fill_constants _count:req, _this, _rest:vararg 1105dd9dbb5SJeenu Viswambharan .ifgt \_count 1115dd9dbb5SJeenu Viswambharan /* Write the current expression */ 1125dd9dbb5SJeenu Viswambharan .ifb \_this 1135dd9dbb5SJeenu Viswambharan .error "Nothing to fill" 1145dd9dbb5SJeenu Viswambharan .endif 1155dd9dbb5SJeenu Viswambharan .quad \_this 1165dd9dbb5SJeenu Viswambharan 1175dd9dbb5SJeenu Viswambharan /* Invoke recursively for remaining expressions */ 1185dd9dbb5SJeenu Viswambharan .ifnb \_rest 1195dd9dbb5SJeenu Viswambharan fill_constants \_count-1, \_rest 1205dd9dbb5SJeenu Viswambharan .else 1215dd9dbb5SJeenu Viswambharan fill_constants \_count-1, \_this 1225dd9dbb5SJeenu Viswambharan .endif 1235dd9dbb5SJeenu Viswambharan .endif 1245dd9dbb5SJeenu Viswambharan .endm 1255dd9dbb5SJeenu Viswambharan 1265dd9dbb5SJeenu Viswambharan /* 1275dd9dbb5SJeenu Viswambharan * Declare CPU operations 1285dd9dbb5SJeenu Viswambharan * 1295dd9dbb5SJeenu Viswambharan * _name: 1305dd9dbb5SJeenu Viswambharan * Name of the CPU for which operations are being specified 1315dd9dbb5SJeenu Viswambharan * _midr: 1325dd9dbb5SJeenu Viswambharan * Numeric value expected to read from CPU's MIDR 1335dd9dbb5SJeenu Viswambharan * _resetfunc: 1345dd9dbb5SJeenu Viswambharan * Reset function for the CPU. If there's no CPU reset function, 1355dd9dbb5SJeenu Viswambharan * specify CPU_NO_RESET_FUNC 1365dd9dbb5SJeenu Viswambharan * _power_down_ops: 1375dd9dbb5SJeenu Viswambharan * Comma-separated list of functions to perform power-down 1385dd9dbb5SJeenu Viswambharan * operatios on the CPU. At least one, and up to 1395dd9dbb5SJeenu Viswambharan * CPU_MAX_PWR_DWN_OPS number of functions may be specified. 1405dd9dbb5SJeenu Viswambharan * Starting at power level 0, these functions shall handle power 1415dd9dbb5SJeenu Viswambharan * down at subsequent power levels. If there aren't exactly 1425dd9dbb5SJeenu Viswambharan * CPU_MAX_PWR_DWN_OPS functions, the last specified one will be 1435dd9dbb5SJeenu Viswambharan * used to handle power down at subsequent levels 1445dd9dbb5SJeenu Viswambharan */ 1455dd9dbb5SJeenu Viswambharan .macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \ 1465dd9dbb5SJeenu Viswambharan _power_down_ops:vararg 1475dd9dbb5SJeenu Viswambharan .section cpu_ops, "a" 1485dd9dbb5SJeenu Viswambharan .align 3 149add40351SSoby Mathew .type cpu_ops_\_name, %object 150add40351SSoby Mathew .quad \_midr 1513d8256b2SMasahiro Yamada#if defined(IMAGE_BL1) || defined(IMAGE_BL31) 1525dd9dbb5SJeenu Viswambharan .quad \_resetfunc 153add40351SSoby Mathew#endif 1543d8256b2SMasahiro Yamada#ifdef IMAGE_BL31 1555dd9dbb5SJeenu Viswambharan1: 1565dd9dbb5SJeenu Viswambharan /* Insert list of functions */ 1575dd9dbb5SJeenu Viswambharan fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops 1585dd9dbb5SJeenu Viswambharan2: 1595dd9dbb5SJeenu Viswambharan /* 1605dd9dbb5SJeenu Viswambharan * Error if no or more than CPU_MAX_PWR_DWN_OPS were specified in the 1615dd9dbb5SJeenu Viswambharan * list 1625dd9dbb5SJeenu Viswambharan */ 1635dd9dbb5SJeenu Viswambharan .ifeq 2b - 1b 1645dd9dbb5SJeenu Viswambharan .error "At least one power down function must be specified" 1655dd9dbb5SJeenu Viswambharan .else 1665dd9dbb5SJeenu Viswambharan .iflt 2b - 1b - (CPU_MAX_PWR_DWN_OPS * CPU_WORD_SIZE) 1675dd9dbb5SJeenu Viswambharan .error "More than CPU_MAX_PWR_DWN_OPS functions specified" 1685dd9dbb5SJeenu Viswambharan .endif 1695dd9dbb5SJeenu Viswambharan .endif 170add40351SSoby Mathew#endif 171*10bcd761SJeenu Viswambharan 172*10bcd761SJeenu Viswambharan#if REPORT_ERRATA 173*10bcd761SJeenu Viswambharan .ifndef \_name\()_cpu_str 174*10bcd761SJeenu Viswambharan /* 175*10bcd761SJeenu Viswambharan * Place errata reported flag, and the spinlock to arbitrate access to 176*10bcd761SJeenu Viswambharan * it in the data section. 177*10bcd761SJeenu Viswambharan */ 178*10bcd761SJeenu Viswambharan .pushsection .data 179*10bcd761SJeenu Viswambharan define_asm_spinlock \_name\()_errata_lock 180*10bcd761SJeenu Viswambharan \_name\()_errata_reported: 181*10bcd761SJeenu Viswambharan .word 0 182*10bcd761SJeenu Viswambharan .popsection 183*10bcd761SJeenu Viswambharan 184*10bcd761SJeenu Viswambharan /* Place CPU string in rodata */ 185*10bcd761SJeenu Viswambharan .pushsection .rodata 186*10bcd761SJeenu Viswambharan \_name\()_cpu_str: 187*10bcd761SJeenu Viswambharan .asciz "\_name" 188*10bcd761SJeenu Viswambharan .popsection 189*10bcd761SJeenu Viswambharan .endif 190*10bcd761SJeenu Viswambharan 191*10bcd761SJeenu Viswambharan /* 192*10bcd761SJeenu Viswambharan * Weakly-bound, optional errata status printing function for CPUs of 193*10bcd761SJeenu Viswambharan * this class. 194*10bcd761SJeenu Viswambharan */ 195*10bcd761SJeenu Viswambharan .weak \_name\()_errata_report 196*10bcd761SJeenu Viswambharan .quad \_name\()_errata_report 197*10bcd761SJeenu Viswambharan 198*10bcd761SJeenu Viswambharan#ifdef IMAGE_BL31 199*10bcd761SJeenu Viswambharan /* Pointers to errata lock and reported flag */ 200*10bcd761SJeenu Viswambharan .quad \_name\()_errata_lock 201*10bcd761SJeenu Viswambharan .quad \_name\()_errata_reported 202*10bcd761SJeenu Viswambharan#endif 203*10bcd761SJeenu Viswambharan#endif 204*10bcd761SJeenu Viswambharan 2053d8256b2SMasahiro Yamada#if defined(IMAGE_BL31) && CRASH_REPORTING 206d3f70af6SSoby Mathew .quad \_name\()_cpu_reg_dump 207d3f70af6SSoby Mathew#endif 208add40351SSoby Mathew .endm 209e2bf57f8SDan Handley 210*10bcd761SJeenu Viswambharan#if REPORT_ERRATA 211*10bcd761SJeenu Viswambharan /* 212*10bcd761SJeenu Viswambharan * Print status of a CPU errata 213*10bcd761SJeenu Viswambharan * 214*10bcd761SJeenu Viswambharan * _chosen: 215*10bcd761SJeenu Viswambharan * Identifier indicating whether or not a CPU errata has been 216*10bcd761SJeenu Viswambharan * compiled in. 217*10bcd761SJeenu Viswambharan * _cpu: 218*10bcd761SJeenu Viswambharan * Name of the CPU 219*10bcd761SJeenu Viswambharan * _id: 220*10bcd761SJeenu Viswambharan * Errata identifier 221*10bcd761SJeenu Viswambharan * _rev_var: 222*10bcd761SJeenu Viswambharan * Register containing the combined value CPU revision and variant 223*10bcd761SJeenu Viswambharan * - typically the return value of cpu_get_rev_var 224*10bcd761SJeenu Viswambharan */ 225*10bcd761SJeenu Viswambharan .macro report_errata _chosen, _cpu, _id, _rev_var=x8 226*10bcd761SJeenu Viswambharan /* Stash a string with errata ID */ 227*10bcd761SJeenu Viswambharan .pushsection .rodata 228*10bcd761SJeenu Viswambharan \_cpu\()_errata_\_id\()_str: 229*10bcd761SJeenu Viswambharan .asciz "\_id" 230*10bcd761SJeenu Viswambharan .popsection 231*10bcd761SJeenu Viswambharan 232*10bcd761SJeenu Viswambharan /* Check whether errata applies */ 233*10bcd761SJeenu Viswambharan mov x0, \_rev_var 234*10bcd761SJeenu Viswambharan bl check_errata_\_id 235*10bcd761SJeenu Viswambharan 236*10bcd761SJeenu Viswambharan .ifeq \_chosen 237*10bcd761SJeenu Viswambharan /* 238*10bcd761SJeenu Viswambharan * Errata workaround has not been compiled in. If the errata would have 239*10bcd761SJeenu Viswambharan * applied had it been compiled in, print its status as missing. 240*10bcd761SJeenu Viswambharan */ 241*10bcd761SJeenu Viswambharan cbz x0, 900f 242*10bcd761SJeenu Viswambharan mov x0, #ERRATA_MISSING 243*10bcd761SJeenu Viswambharan .endif 244*10bcd761SJeenu Viswambharan900: 245*10bcd761SJeenu Viswambharan adr x1, \_cpu\()_cpu_str 246*10bcd761SJeenu Viswambharan adr x2, \_cpu\()_errata_\_id\()_str 247*10bcd761SJeenu Viswambharan bl errata_print_msg 248*10bcd761SJeenu Viswambharan .endm 249*10bcd761SJeenu Viswambharan#endif 250*10bcd761SJeenu Viswambharan 251e2bf57f8SDan Handley#endif /* __CPU_MACROS_S__ */ 252