1e33b78a6SSoby Mathew/* 210bcd761SJeenu Viswambharan * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. 3e33b78a6SSoby Mathew * 4*82cb2c1aSdp-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 12e33b78a6SSoby Mathew#define CPU_IMPL_PN_MASK (MIDR_IMPL_MASK << MIDR_IMPL_SHIFT) | \ 13e33b78a6SSoby Mathew (MIDR_PN_MASK << MIDR_PN_SHIFT) 14e33b78a6SSoby Mathew 155dd9dbb5SJeenu Viswambharan/* The number of CPU operations allowed */ 165dd9dbb5SJeenu Viswambharan#define CPU_MAX_PWR_DWN_OPS 2 175dd9dbb5SJeenu Viswambharan 185dd9dbb5SJeenu Viswambharan/* Special constant to specify that CPU has no reset function */ 195dd9dbb5SJeenu Viswambharan#define CPU_NO_RESET_FUNC 0 205dd9dbb5SJeenu Viswambharan 215dd9dbb5SJeenu Viswambharan/* Word size for 32-bit CPUs */ 225dd9dbb5SJeenu Viswambharan#define CPU_WORD_SIZE 4 235dd9dbb5SJeenu Viswambharan 24e33b78a6SSoby Mathew/* 2510bcd761SJeenu Viswambharan * Whether errata status needs reporting. Errata status is printed in debug 2610bcd761SJeenu Viswambharan * builds for both BL1 and BL32 images. 2710bcd761SJeenu Viswambharan */ 2810bcd761SJeenu Viswambharan#if (defined(IMAGE_BL1) || defined(IMAGE_BL32)) && DEBUG 2910bcd761SJeenu Viswambharan# define REPORT_ERRATA 1 3010bcd761SJeenu Viswambharan#else 3110bcd761SJeenu Viswambharan# define REPORT_ERRATA 0 3210bcd761SJeenu Viswambharan#endif 3310bcd761SJeenu Viswambharan 3410bcd761SJeenu Viswambharan /* 35e33b78a6SSoby Mathew * Define the offsets to the fields in cpu_ops structure. 36e33b78a6SSoby Mathew */ 37e33b78a6SSoby Mathew .struct 0 38e33b78a6SSoby MathewCPU_MIDR: /* cpu_ops midr */ 39e33b78a6SSoby Mathew .space 4 40e33b78a6SSoby Mathew/* Reset fn is needed during reset */ 413d8256b2SMasahiro Yamada#if defined(IMAGE_BL1) || defined(IMAGE_BL32) 42e33b78a6SSoby MathewCPU_RESET_FUNC: /* cpu_ops reset_func */ 43e33b78a6SSoby Mathew .space 4 441a0a3f06SYatharth Kochar#endif 453d8256b2SMasahiro Yamada#ifdef IMAGE_BL32 /* The power down core and cluster is needed only in BL32 */ 465dd9dbb5SJeenu ViswambharanCPU_PWR_DWN_OPS: /* cpu_ops power down functions */ 475dd9dbb5SJeenu Viswambharan .space (4 * CPU_MAX_PWR_DWN_OPS) 481a0a3f06SYatharth Kochar#endif 4910bcd761SJeenu Viswambharan 5010bcd761SJeenu Viswambharan/* 5110bcd761SJeenu Viswambharan * Fields required to print errata status. Only in BL32 that the printing 5210bcd761SJeenu Viswambharan * require mutual exclusion and printed flag. 5310bcd761SJeenu Viswambharan */ 5410bcd761SJeenu Viswambharan#if REPORT_ERRATA 5510bcd761SJeenu ViswambharanCPU_ERRATA_FUNC: /* CPU errata status printing function */ 5610bcd761SJeenu Viswambharan .space 4 5710bcd761SJeenu Viswambharan#ifdef IMAGE_BL32 5810bcd761SJeenu ViswambharanCPU_ERRATA_LOCK: 5910bcd761SJeenu Viswambharan .space 4 6010bcd761SJeenu ViswambharanCPU_ERRATA_PRINTED: 6110bcd761SJeenu Viswambharan .space 4 6210bcd761SJeenu Viswambharan#endif 6310bcd761SJeenu Viswambharan#endif 6410bcd761SJeenu Viswambharan 65e33b78a6SSoby MathewCPU_OPS_SIZE = . 66e33b78a6SSoby Mathew 67e33b78a6SSoby Mathew /* 685dd9dbb5SJeenu Viswambharan * Write given expressions as words 695dd9dbb5SJeenu Viswambharan * 705dd9dbb5SJeenu Viswambharan * _count: 715dd9dbb5SJeenu Viswambharan * Write at least _count words. If the given number of expressions 725dd9dbb5SJeenu Viswambharan * is less than _count, repeat the last expression to fill _count 735dd9dbb5SJeenu Viswambharan * words in total 745dd9dbb5SJeenu Viswambharan * _rest: 755dd9dbb5SJeenu Viswambharan * Optional list of expressions. _this is for parameter extraction 765dd9dbb5SJeenu Viswambharan * only, and has no significance to the caller 775dd9dbb5SJeenu Viswambharan * 785dd9dbb5SJeenu Viswambharan * Invoked as: 795dd9dbb5SJeenu Viswambharan * fill_constants 2, foo, bar, blah, ... 80e33b78a6SSoby Mathew */ 815dd9dbb5SJeenu Viswambharan .macro fill_constants _count:req, _this, _rest:vararg 825dd9dbb5SJeenu Viswambharan .ifgt \_count 835dd9dbb5SJeenu Viswambharan /* Write the current expression */ 845dd9dbb5SJeenu Viswambharan .ifb \_this 855dd9dbb5SJeenu Viswambharan .error "Nothing to fill" 865dd9dbb5SJeenu Viswambharan .endif 875dd9dbb5SJeenu Viswambharan .word \_this 885dd9dbb5SJeenu Viswambharan 895dd9dbb5SJeenu Viswambharan /* Invoke recursively for remaining expressions */ 905dd9dbb5SJeenu Viswambharan .ifnb \_rest 915dd9dbb5SJeenu Viswambharan fill_constants \_count-1, \_rest 925dd9dbb5SJeenu Viswambharan .else 935dd9dbb5SJeenu Viswambharan fill_constants \_count-1, \_this 945dd9dbb5SJeenu Viswambharan .endif 955dd9dbb5SJeenu Viswambharan .endif 965dd9dbb5SJeenu Viswambharan .endm 975dd9dbb5SJeenu Viswambharan 985dd9dbb5SJeenu Viswambharan /* 995dd9dbb5SJeenu Viswambharan * Declare CPU operations 1005dd9dbb5SJeenu Viswambharan * 1015dd9dbb5SJeenu Viswambharan * _name: 1025dd9dbb5SJeenu Viswambharan * Name of the CPU for which operations are being specified 1035dd9dbb5SJeenu Viswambharan * _midr: 1045dd9dbb5SJeenu Viswambharan * Numeric value expected to read from CPU's MIDR 1055dd9dbb5SJeenu Viswambharan * _resetfunc: 1065dd9dbb5SJeenu Viswambharan * Reset function for the CPU. If there's no CPU reset function, 1075dd9dbb5SJeenu Viswambharan * specify CPU_NO_RESET_FUNC 1085dd9dbb5SJeenu Viswambharan * _power_down_ops: 1095dd9dbb5SJeenu Viswambharan * Comma-separated list of functions to perform power-down 1105dd9dbb5SJeenu Viswambharan * operatios on the CPU. At least one, and up to 1115dd9dbb5SJeenu Viswambharan * CPU_MAX_PWR_DWN_OPS number of functions may be specified. 1125dd9dbb5SJeenu Viswambharan * Starting at power level 0, these functions shall handle power 1135dd9dbb5SJeenu Viswambharan * down at subsequent power levels. If there aren't exactly 1145dd9dbb5SJeenu Viswambharan * CPU_MAX_PWR_DWN_OPS functions, the last specified one will be 1155dd9dbb5SJeenu Viswambharan * used to handle power down at subsequent levels 1165dd9dbb5SJeenu Viswambharan */ 1175dd9dbb5SJeenu Viswambharan .macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \ 1185dd9dbb5SJeenu Viswambharan _power_down_ops:vararg 119e33b78a6SSoby Mathew .section cpu_ops, "a" 120e33b78a6SSoby Mathew .align 2 121e33b78a6SSoby Mathew .type cpu_ops_\_name, %object 122e33b78a6SSoby Mathew .word \_midr 1233d8256b2SMasahiro Yamada#if defined(IMAGE_BL1) || defined(IMAGE_BL32) 1245dd9dbb5SJeenu Viswambharan .word \_resetfunc 1251a0a3f06SYatharth Kochar#endif 1263d8256b2SMasahiro Yamada#ifdef IMAGE_BL32 1275dd9dbb5SJeenu Viswambharan1: 1285dd9dbb5SJeenu Viswambharan /* Insert list of functions */ 1295dd9dbb5SJeenu Viswambharan fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops 1305dd9dbb5SJeenu Viswambharan2: 1315dd9dbb5SJeenu Viswambharan /* 1325dd9dbb5SJeenu Viswambharan * Error if no or more than CPU_MAX_PWR_DWN_OPS were specified in the 1335dd9dbb5SJeenu Viswambharan * list 1345dd9dbb5SJeenu Viswambharan */ 1355dd9dbb5SJeenu Viswambharan .ifeq 2b - 1b 1365dd9dbb5SJeenu Viswambharan .error "At least one power down function must be specified" 1375dd9dbb5SJeenu Viswambharan .else 1385dd9dbb5SJeenu Viswambharan .iflt 2b - 1b - (CPU_MAX_PWR_DWN_OPS * CPU_WORD_SIZE) 1395dd9dbb5SJeenu Viswambharan .error "More than CPU_MAX_PWR_DWN_OPS functions specified" 1405dd9dbb5SJeenu Viswambharan .endif 1415dd9dbb5SJeenu Viswambharan .endif 1421a0a3f06SYatharth Kochar#endif 14310bcd761SJeenu Viswambharan 14410bcd761SJeenu Viswambharan#if REPORT_ERRATA 14510bcd761SJeenu Viswambharan .ifndef \_name\()_cpu_str 14610bcd761SJeenu Viswambharan /* 14710bcd761SJeenu Viswambharan * Place errata reported flag, and the spinlock to arbitrate access to 14810bcd761SJeenu Viswambharan * it in the data section. 14910bcd761SJeenu Viswambharan */ 15010bcd761SJeenu Viswambharan .pushsection .data 15110bcd761SJeenu Viswambharan define_asm_spinlock \_name\()_errata_lock 15210bcd761SJeenu Viswambharan \_name\()_errata_reported: 15310bcd761SJeenu Viswambharan .word 0 15410bcd761SJeenu Viswambharan .popsection 15510bcd761SJeenu Viswambharan 15610bcd761SJeenu Viswambharan /* Place CPU string in rodata */ 15710bcd761SJeenu Viswambharan .pushsection .rodata 15810bcd761SJeenu Viswambharan \_name\()_cpu_str: 15910bcd761SJeenu Viswambharan .asciz "\_name" 16010bcd761SJeenu Viswambharan .popsection 16110bcd761SJeenu Viswambharan .endif 16210bcd761SJeenu Viswambharan 16310bcd761SJeenu Viswambharan /* 16410bcd761SJeenu Viswambharan * Weakly-bound, optional errata status printing function for CPUs of 16510bcd761SJeenu Viswambharan * this class. 16610bcd761SJeenu Viswambharan */ 16710bcd761SJeenu Viswambharan .weak \_name\()_errata_report 16810bcd761SJeenu Viswambharan .word \_name\()_errata_report 16910bcd761SJeenu Viswambharan 17010bcd761SJeenu Viswambharan#ifdef IMAGE_BL32 17110bcd761SJeenu Viswambharan /* Pointers to errata lock and reported flag */ 17210bcd761SJeenu Viswambharan .word \_name\()_errata_lock 17310bcd761SJeenu Viswambharan .word \_name\()_errata_reported 17410bcd761SJeenu Viswambharan#endif 17510bcd761SJeenu Viswambharan#endif 176e33b78a6SSoby Mathew .endm 177e33b78a6SSoby Mathew 17810bcd761SJeenu Viswambharan#if REPORT_ERRATA 17910bcd761SJeenu Viswambharan /* 18010bcd761SJeenu Viswambharan * Print status of a CPU errata 18110bcd761SJeenu Viswambharan * 18210bcd761SJeenu Viswambharan * _chosen: 18310bcd761SJeenu Viswambharan * Identifier indicating whether or not a CPU errata has been 18410bcd761SJeenu Viswambharan * compiled in. 18510bcd761SJeenu Viswambharan * _cpu: 18610bcd761SJeenu Viswambharan * Name of the CPU 18710bcd761SJeenu Viswambharan * _id: 18810bcd761SJeenu Viswambharan * Errata identifier 18910bcd761SJeenu Viswambharan * _rev_var: 19010bcd761SJeenu Viswambharan * Register containing the combined value CPU revision and variant 19110bcd761SJeenu Viswambharan * - typically the return value of cpu_get_rev_var 19210bcd761SJeenu Viswambharan */ 19310bcd761SJeenu Viswambharan .macro report_errata _chosen, _cpu, _id, _rev_var=r4 19410bcd761SJeenu Viswambharan /* Stash a string with errata ID */ 19510bcd761SJeenu Viswambharan .pushsection .rodata 19610bcd761SJeenu Viswambharan \_cpu\()_errata_\_id\()_str: 19710bcd761SJeenu Viswambharan .asciz "\_id" 19810bcd761SJeenu Viswambharan .popsection 19910bcd761SJeenu Viswambharan 20010bcd761SJeenu Viswambharan /* Check whether errata applies */ 20110bcd761SJeenu Viswambharan mov r0, \_rev_var 20210bcd761SJeenu Viswambharan bl check_errata_\_id 20310bcd761SJeenu Viswambharan 20410bcd761SJeenu Viswambharan .ifeq \_chosen 20510bcd761SJeenu Viswambharan /* 20610bcd761SJeenu Viswambharan * Errata workaround has not been compiled in. If the errata would have 20710bcd761SJeenu Viswambharan * applied had it been compiled in, print its status as missing. 20810bcd761SJeenu Viswambharan */ 20910bcd761SJeenu Viswambharan cmp r0, #0 21010bcd761SJeenu Viswambharan movne r0, #ERRATA_MISSING 21110bcd761SJeenu Viswambharan .endif 21210bcd761SJeenu Viswambharan ldr r1, =\_cpu\()_cpu_str 21310bcd761SJeenu Viswambharan ldr r2, =\_cpu\()_errata_\_id\()_str 21410bcd761SJeenu Viswambharan bl errata_print_msg 21510bcd761SJeenu Viswambharan .endm 21610bcd761SJeenu Viswambharan#endif 21710bcd761SJeenu Viswambharan 218e33b78a6SSoby Mathew#endif /* __CPU_MACROS_S__ */ 219