1e33b78a6SSoby Mathew/* 210bcd761SJeenu Viswambharan * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved. 3e33b78a6SSoby Mathew * 482cb2c1aSdp-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 12*b1d27b48SRoberto Vargas#if defined(IMAGE_BL1) || defined(IMAGE_BL32) || (defined(IMAGE_BL2) && BL2_AT_EL3) 13*b1d27b48SRoberto Vargas#define IMAGE_AT_EL3 14*b1d27b48SRoberto Vargas#endif 15*b1d27b48SRoberto Vargas 16e33b78a6SSoby Mathew#define CPU_IMPL_PN_MASK (MIDR_IMPL_MASK << MIDR_IMPL_SHIFT) | \ 17e33b78a6SSoby Mathew (MIDR_PN_MASK << MIDR_PN_SHIFT) 18e33b78a6SSoby Mathew 195dd9dbb5SJeenu Viswambharan/* The number of CPU operations allowed */ 205dd9dbb5SJeenu Viswambharan#define CPU_MAX_PWR_DWN_OPS 2 215dd9dbb5SJeenu Viswambharan 225dd9dbb5SJeenu Viswambharan/* Special constant to specify that CPU has no reset function */ 235dd9dbb5SJeenu Viswambharan#define CPU_NO_RESET_FUNC 0 245dd9dbb5SJeenu Viswambharan 255dd9dbb5SJeenu Viswambharan/* Word size for 32-bit CPUs */ 265dd9dbb5SJeenu Viswambharan#define CPU_WORD_SIZE 4 275dd9dbb5SJeenu Viswambharan 28e33b78a6SSoby Mathew/* 2910bcd761SJeenu Viswambharan * Whether errata status needs reporting. Errata status is printed in debug 3010bcd761SJeenu Viswambharan * builds for both BL1 and BL32 images. 3110bcd761SJeenu Viswambharan */ 3210bcd761SJeenu Viswambharan#if (defined(IMAGE_BL1) || defined(IMAGE_BL32)) && DEBUG 3310bcd761SJeenu Viswambharan# define REPORT_ERRATA 1 3410bcd761SJeenu Viswambharan#else 3510bcd761SJeenu Viswambharan# define REPORT_ERRATA 0 3610bcd761SJeenu Viswambharan#endif 3710bcd761SJeenu Viswambharan 3810bcd761SJeenu Viswambharan /* 39e33b78a6SSoby Mathew * Define the offsets to the fields in cpu_ops structure. 40e33b78a6SSoby Mathew */ 41e33b78a6SSoby Mathew .struct 0 42e33b78a6SSoby MathewCPU_MIDR: /* cpu_ops midr */ 43e33b78a6SSoby Mathew .space 4 44e33b78a6SSoby Mathew/* Reset fn is needed during reset */ 45*b1d27b48SRoberto Vargas#if defined(IMAGE_AT_EL3) 46e33b78a6SSoby MathewCPU_RESET_FUNC: /* cpu_ops reset_func */ 47e33b78a6SSoby Mathew .space 4 481a0a3f06SYatharth Kochar#endif 493d8256b2SMasahiro Yamada#ifdef IMAGE_BL32 /* The power down core and cluster is needed only in BL32 */ 505dd9dbb5SJeenu ViswambharanCPU_PWR_DWN_OPS: /* cpu_ops power down functions */ 515dd9dbb5SJeenu Viswambharan .space (4 * CPU_MAX_PWR_DWN_OPS) 521a0a3f06SYatharth Kochar#endif 5310bcd761SJeenu Viswambharan 5410bcd761SJeenu Viswambharan/* 5510bcd761SJeenu Viswambharan * Fields required to print errata status. Only in BL32 that the printing 5610bcd761SJeenu Viswambharan * require mutual exclusion and printed flag. 5710bcd761SJeenu Viswambharan */ 5810bcd761SJeenu Viswambharan#if REPORT_ERRATA 5910bcd761SJeenu ViswambharanCPU_ERRATA_FUNC: /* CPU errata status printing function */ 6010bcd761SJeenu Viswambharan .space 4 61*b1d27b48SRoberto Vargas#if defined(IMAGE_BL32) 6210bcd761SJeenu ViswambharanCPU_ERRATA_LOCK: 6310bcd761SJeenu Viswambharan .space 4 6410bcd761SJeenu ViswambharanCPU_ERRATA_PRINTED: 6510bcd761SJeenu Viswambharan .space 4 6610bcd761SJeenu Viswambharan#endif 6710bcd761SJeenu Viswambharan#endif 6810bcd761SJeenu Viswambharan 69e33b78a6SSoby MathewCPU_OPS_SIZE = . 70e33b78a6SSoby Mathew 71e33b78a6SSoby Mathew /* 725dd9dbb5SJeenu Viswambharan * Write given expressions as words 735dd9dbb5SJeenu Viswambharan * 745dd9dbb5SJeenu Viswambharan * _count: 755dd9dbb5SJeenu Viswambharan * Write at least _count words. If the given number of expressions 765dd9dbb5SJeenu Viswambharan * is less than _count, repeat the last expression to fill _count 775dd9dbb5SJeenu Viswambharan * words in total 785dd9dbb5SJeenu Viswambharan * _rest: 795dd9dbb5SJeenu Viswambharan * Optional list of expressions. _this is for parameter extraction 805dd9dbb5SJeenu Viswambharan * only, and has no significance to the caller 815dd9dbb5SJeenu Viswambharan * 825dd9dbb5SJeenu Viswambharan * Invoked as: 835dd9dbb5SJeenu Viswambharan * fill_constants 2, foo, bar, blah, ... 84e33b78a6SSoby Mathew */ 855dd9dbb5SJeenu Viswambharan .macro fill_constants _count:req, _this, _rest:vararg 865dd9dbb5SJeenu Viswambharan .ifgt \_count 875dd9dbb5SJeenu Viswambharan /* Write the current expression */ 885dd9dbb5SJeenu Viswambharan .ifb \_this 895dd9dbb5SJeenu Viswambharan .error "Nothing to fill" 905dd9dbb5SJeenu Viswambharan .endif 915dd9dbb5SJeenu Viswambharan .word \_this 925dd9dbb5SJeenu Viswambharan 935dd9dbb5SJeenu Viswambharan /* Invoke recursively for remaining expressions */ 945dd9dbb5SJeenu Viswambharan .ifnb \_rest 955dd9dbb5SJeenu Viswambharan fill_constants \_count-1, \_rest 965dd9dbb5SJeenu Viswambharan .else 975dd9dbb5SJeenu Viswambharan fill_constants \_count-1, \_this 985dd9dbb5SJeenu Viswambharan .endif 995dd9dbb5SJeenu Viswambharan .endif 1005dd9dbb5SJeenu Viswambharan .endm 1015dd9dbb5SJeenu Viswambharan 1025dd9dbb5SJeenu Viswambharan /* 1035dd9dbb5SJeenu Viswambharan * Declare CPU operations 1045dd9dbb5SJeenu Viswambharan * 1055dd9dbb5SJeenu Viswambharan * _name: 1065dd9dbb5SJeenu Viswambharan * Name of the CPU for which operations are being specified 1075dd9dbb5SJeenu Viswambharan * _midr: 1085dd9dbb5SJeenu Viswambharan * Numeric value expected to read from CPU's MIDR 1095dd9dbb5SJeenu Viswambharan * _resetfunc: 1105dd9dbb5SJeenu Viswambharan * Reset function for the CPU. If there's no CPU reset function, 1115dd9dbb5SJeenu Viswambharan * specify CPU_NO_RESET_FUNC 1125dd9dbb5SJeenu Viswambharan * _power_down_ops: 1135dd9dbb5SJeenu Viswambharan * Comma-separated list of functions to perform power-down 1145dd9dbb5SJeenu Viswambharan * operatios on the CPU. At least one, and up to 1155dd9dbb5SJeenu Viswambharan * CPU_MAX_PWR_DWN_OPS number of functions may be specified. 1165dd9dbb5SJeenu Viswambharan * Starting at power level 0, these functions shall handle power 1175dd9dbb5SJeenu Viswambharan * down at subsequent power levels. If there aren't exactly 1185dd9dbb5SJeenu Viswambharan * CPU_MAX_PWR_DWN_OPS functions, the last specified one will be 1195dd9dbb5SJeenu Viswambharan * used to handle power down at subsequent levels 1205dd9dbb5SJeenu Viswambharan */ 1215dd9dbb5SJeenu Viswambharan .macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \ 1225dd9dbb5SJeenu Viswambharan _power_down_ops:vararg 123e33b78a6SSoby Mathew .section cpu_ops, "a" 124e33b78a6SSoby Mathew .align 2 125e33b78a6SSoby Mathew .type cpu_ops_\_name, %object 126e33b78a6SSoby Mathew .word \_midr 127*b1d27b48SRoberto Vargas#if defined(IMAGE_AT_EL3) 1285dd9dbb5SJeenu Viswambharan .word \_resetfunc 1291a0a3f06SYatharth Kochar#endif 1303d8256b2SMasahiro Yamada#ifdef IMAGE_BL32 1315dd9dbb5SJeenu Viswambharan1: 1325dd9dbb5SJeenu Viswambharan /* Insert list of functions */ 1335dd9dbb5SJeenu Viswambharan fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops 1345dd9dbb5SJeenu Viswambharan2: 1355dd9dbb5SJeenu Viswambharan /* 1365dd9dbb5SJeenu Viswambharan * Error if no or more than CPU_MAX_PWR_DWN_OPS were specified in the 1375dd9dbb5SJeenu Viswambharan * list 1385dd9dbb5SJeenu Viswambharan */ 1395dd9dbb5SJeenu Viswambharan .ifeq 2b - 1b 1405dd9dbb5SJeenu Viswambharan .error "At least one power down function must be specified" 1415dd9dbb5SJeenu Viswambharan .else 1425dd9dbb5SJeenu Viswambharan .iflt 2b - 1b - (CPU_MAX_PWR_DWN_OPS * CPU_WORD_SIZE) 1435dd9dbb5SJeenu Viswambharan .error "More than CPU_MAX_PWR_DWN_OPS functions specified" 1445dd9dbb5SJeenu Viswambharan .endif 1455dd9dbb5SJeenu Viswambharan .endif 1461a0a3f06SYatharth Kochar#endif 14710bcd761SJeenu Viswambharan 14810bcd761SJeenu Viswambharan#if REPORT_ERRATA 14910bcd761SJeenu Viswambharan .ifndef \_name\()_cpu_str 15010bcd761SJeenu Viswambharan /* 15110bcd761SJeenu Viswambharan * Place errata reported flag, and the spinlock to arbitrate access to 15210bcd761SJeenu Viswambharan * it in the data section. 15310bcd761SJeenu Viswambharan */ 15410bcd761SJeenu Viswambharan .pushsection .data 15510bcd761SJeenu Viswambharan define_asm_spinlock \_name\()_errata_lock 15610bcd761SJeenu Viswambharan \_name\()_errata_reported: 15710bcd761SJeenu Viswambharan .word 0 15810bcd761SJeenu Viswambharan .popsection 15910bcd761SJeenu Viswambharan 16010bcd761SJeenu Viswambharan /* Place CPU string in rodata */ 16110bcd761SJeenu Viswambharan .pushsection .rodata 16210bcd761SJeenu Viswambharan \_name\()_cpu_str: 16310bcd761SJeenu Viswambharan .asciz "\_name" 16410bcd761SJeenu Viswambharan .popsection 16510bcd761SJeenu Viswambharan .endif 16610bcd761SJeenu Viswambharan 16710bcd761SJeenu Viswambharan /* 16810bcd761SJeenu Viswambharan * Weakly-bound, optional errata status printing function for CPUs of 16910bcd761SJeenu Viswambharan * this class. 17010bcd761SJeenu Viswambharan */ 17110bcd761SJeenu Viswambharan .weak \_name\()_errata_report 17210bcd761SJeenu Viswambharan .word \_name\()_errata_report 17310bcd761SJeenu Viswambharan 17410bcd761SJeenu Viswambharan#ifdef IMAGE_BL32 17510bcd761SJeenu Viswambharan /* Pointers to errata lock and reported flag */ 17610bcd761SJeenu Viswambharan .word \_name\()_errata_lock 17710bcd761SJeenu Viswambharan .word \_name\()_errata_reported 17810bcd761SJeenu Viswambharan#endif 17910bcd761SJeenu Viswambharan#endif 180e33b78a6SSoby Mathew .endm 181e33b78a6SSoby Mathew 18210bcd761SJeenu Viswambharan#if REPORT_ERRATA 18310bcd761SJeenu Viswambharan /* 18410bcd761SJeenu Viswambharan * Print status of a CPU errata 18510bcd761SJeenu Viswambharan * 18610bcd761SJeenu Viswambharan * _chosen: 18710bcd761SJeenu Viswambharan * Identifier indicating whether or not a CPU errata has been 18810bcd761SJeenu Viswambharan * compiled in. 18910bcd761SJeenu Viswambharan * _cpu: 19010bcd761SJeenu Viswambharan * Name of the CPU 19110bcd761SJeenu Viswambharan * _id: 19210bcd761SJeenu Viswambharan * Errata identifier 19310bcd761SJeenu Viswambharan * _rev_var: 19410bcd761SJeenu Viswambharan * Register containing the combined value CPU revision and variant 19510bcd761SJeenu Viswambharan * - typically the return value of cpu_get_rev_var 19610bcd761SJeenu Viswambharan */ 19710bcd761SJeenu Viswambharan .macro report_errata _chosen, _cpu, _id, _rev_var=r4 19810bcd761SJeenu Viswambharan /* Stash a string with errata ID */ 19910bcd761SJeenu Viswambharan .pushsection .rodata 20010bcd761SJeenu Viswambharan \_cpu\()_errata_\_id\()_str: 20110bcd761SJeenu Viswambharan .asciz "\_id" 20210bcd761SJeenu Viswambharan .popsection 20310bcd761SJeenu Viswambharan 20410bcd761SJeenu Viswambharan /* Check whether errata applies */ 20510bcd761SJeenu Viswambharan mov r0, \_rev_var 20610bcd761SJeenu Viswambharan bl check_errata_\_id 20710bcd761SJeenu Viswambharan 20810bcd761SJeenu Viswambharan .ifeq \_chosen 20910bcd761SJeenu Viswambharan /* 21010bcd761SJeenu Viswambharan * Errata workaround has not been compiled in. If the errata would have 21110bcd761SJeenu Viswambharan * applied had it been compiled in, print its status as missing. 21210bcd761SJeenu Viswambharan */ 21310bcd761SJeenu Viswambharan cmp r0, #0 21410bcd761SJeenu Viswambharan movne r0, #ERRATA_MISSING 21510bcd761SJeenu Viswambharan .endif 21610bcd761SJeenu Viswambharan ldr r1, =\_cpu\()_cpu_str 21710bcd761SJeenu Viswambharan ldr r2, =\_cpu\()_errata_\_id\()_str 21810bcd761SJeenu Viswambharan bl errata_print_msg 21910bcd761SJeenu Viswambharan .endm 22010bcd761SJeenu Viswambharan#endif 22110bcd761SJeenu Viswambharan 222e33b78a6SSoby Mathew#endif /* __CPU_MACROS_S__ */ 223