1add40351SSoby Mathew/* 2*5dd9dbb5SJeenu Viswambharan * Copyright (c) 2014-2016, 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> 34add40351SSoby Mathew 35add40351SSoby Mathew#define CPU_IMPL_PN_MASK (MIDR_IMPL_MASK << MIDR_IMPL_SHIFT) | \ 36add40351SSoby Mathew (MIDR_PN_MASK << MIDR_PN_SHIFT) 37add40351SSoby Mathew 38*5dd9dbb5SJeenu Viswambharan/* The number of CPU operations allowed */ 39*5dd9dbb5SJeenu Viswambharan#define CPU_MAX_PWR_DWN_OPS 2 40*5dd9dbb5SJeenu Viswambharan 41*5dd9dbb5SJeenu Viswambharan/* Special constant to specify that CPU has no reset function */ 42*5dd9dbb5SJeenu Viswambharan#define CPU_NO_RESET_FUNC 0 43*5dd9dbb5SJeenu Viswambharan 44*5dd9dbb5SJeenu Viswambharan/* Word size for 64-bit CPUs */ 45*5dd9dbb5SJeenu Viswambharan#define CPU_WORD_SIZE 8 46*5dd9dbb5SJeenu Viswambharan 47add40351SSoby Mathew /* 48add40351SSoby Mathew * Define the offsets to the fields in cpu_ops structure. 49add40351SSoby Mathew */ 50add40351SSoby Mathew .struct 0 51add40351SSoby MathewCPU_MIDR: /* cpu_ops midr */ 52add40351SSoby Mathew .space 8 53add40351SSoby Mathew/* Reset fn is needed in BL at reset vector */ 5479a97b2eSYatharth Kochar#if IMAGE_BL1 || IMAGE_BL31 55add40351SSoby MathewCPU_RESET_FUNC: /* cpu_ops reset_func */ 56add40351SSoby Mathew .space 8 57add40351SSoby Mathew#endif 58d178637dSJuan Castillo#if IMAGE_BL31 /* The power down core and cluster is needed only in BL31 */ 59*5dd9dbb5SJeenu ViswambharanCPU_PWR_DWN_OPS: /* cpu_ops power down functions */ 60*5dd9dbb5SJeenu Viswambharan .space (8 * CPU_MAX_PWR_DWN_OPS) 61add40351SSoby Mathew#endif 62d3f70af6SSoby Mathew#if (IMAGE_BL31 && CRASH_REPORTING) 63d3f70af6SSoby MathewCPU_REG_DUMP: /* cpu specific register dump for crash reporting */ 64d3f70af6SSoby Mathew .space 8 65d3f70af6SSoby Mathew#endif 66add40351SSoby MathewCPU_OPS_SIZE = . 67add40351SSoby Mathew 68add40351SSoby Mathew /* 69*5dd9dbb5SJeenu Viswambharan * Write given expressions as quad words 70*5dd9dbb5SJeenu Viswambharan * 71*5dd9dbb5SJeenu Viswambharan * _count: 72*5dd9dbb5SJeenu Viswambharan * Write at least _count quad words. If the given number of 73*5dd9dbb5SJeenu Viswambharan * expressions is less than _count, repeat the last expression to 74*5dd9dbb5SJeenu Viswambharan * fill _count quad words in total 75*5dd9dbb5SJeenu Viswambharan * _rest: 76*5dd9dbb5SJeenu Viswambharan * Optional list of expressions. _this is for parameter extraction 77*5dd9dbb5SJeenu Viswambharan * only, and has no significance to the caller 78*5dd9dbb5SJeenu Viswambharan * 79*5dd9dbb5SJeenu Viswambharan * Invoked as: 80*5dd9dbb5SJeenu Viswambharan * fill_constants 2, foo, bar, blah, ... 81add40351SSoby Mathew */ 82*5dd9dbb5SJeenu Viswambharan .macro fill_constants _count:req, _this, _rest:vararg 83*5dd9dbb5SJeenu Viswambharan .ifgt \_count 84*5dd9dbb5SJeenu Viswambharan /* Write the current expression */ 85*5dd9dbb5SJeenu Viswambharan .ifb \_this 86*5dd9dbb5SJeenu Viswambharan .error "Nothing to fill" 87*5dd9dbb5SJeenu Viswambharan .endif 88*5dd9dbb5SJeenu Viswambharan .quad \_this 89*5dd9dbb5SJeenu Viswambharan 90*5dd9dbb5SJeenu Viswambharan /* Invoke recursively for remaining expressions */ 91*5dd9dbb5SJeenu Viswambharan .ifnb \_rest 92*5dd9dbb5SJeenu Viswambharan fill_constants \_count-1, \_rest 93*5dd9dbb5SJeenu Viswambharan .else 94*5dd9dbb5SJeenu Viswambharan fill_constants \_count-1, \_this 95*5dd9dbb5SJeenu Viswambharan .endif 96*5dd9dbb5SJeenu Viswambharan .endif 97*5dd9dbb5SJeenu Viswambharan .endm 98*5dd9dbb5SJeenu Viswambharan 99*5dd9dbb5SJeenu Viswambharan /* 100*5dd9dbb5SJeenu Viswambharan * Declare CPU operations 101*5dd9dbb5SJeenu Viswambharan * 102*5dd9dbb5SJeenu Viswambharan * _name: 103*5dd9dbb5SJeenu Viswambharan * Name of the CPU for which operations are being specified 104*5dd9dbb5SJeenu Viswambharan * _midr: 105*5dd9dbb5SJeenu Viswambharan * Numeric value expected to read from CPU's MIDR 106*5dd9dbb5SJeenu Viswambharan * _resetfunc: 107*5dd9dbb5SJeenu Viswambharan * Reset function for the CPU. If there's no CPU reset function, 108*5dd9dbb5SJeenu Viswambharan * specify CPU_NO_RESET_FUNC 109*5dd9dbb5SJeenu Viswambharan * _power_down_ops: 110*5dd9dbb5SJeenu Viswambharan * Comma-separated list of functions to perform power-down 111*5dd9dbb5SJeenu Viswambharan * operatios on the CPU. At least one, and up to 112*5dd9dbb5SJeenu Viswambharan * CPU_MAX_PWR_DWN_OPS number of functions may be specified. 113*5dd9dbb5SJeenu Viswambharan * Starting at power level 0, these functions shall handle power 114*5dd9dbb5SJeenu Viswambharan * down at subsequent power levels. If there aren't exactly 115*5dd9dbb5SJeenu Viswambharan * CPU_MAX_PWR_DWN_OPS functions, the last specified one will be 116*5dd9dbb5SJeenu Viswambharan * used to handle power down at subsequent levels 117*5dd9dbb5SJeenu Viswambharan */ 118*5dd9dbb5SJeenu Viswambharan .macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \ 119*5dd9dbb5SJeenu Viswambharan _power_down_ops:vararg 120*5dd9dbb5SJeenu Viswambharan .section cpu_ops, "a" 121*5dd9dbb5SJeenu Viswambharan .align 3 122add40351SSoby Mathew .type cpu_ops_\_name, %object 123add40351SSoby Mathew .quad \_midr 12479a97b2eSYatharth Kochar#if IMAGE_BL1 || IMAGE_BL31 125*5dd9dbb5SJeenu Viswambharan .quad \_resetfunc 126add40351SSoby Mathew#endif 127add40351SSoby Mathew#if IMAGE_BL31 128*5dd9dbb5SJeenu Viswambharan1: 129*5dd9dbb5SJeenu Viswambharan /* Insert list of functions */ 130*5dd9dbb5SJeenu Viswambharan fill_constants CPU_MAX_PWR_DWN_OPS, \_power_down_ops 131*5dd9dbb5SJeenu Viswambharan2: 132*5dd9dbb5SJeenu Viswambharan /* 133*5dd9dbb5SJeenu Viswambharan * Error if no or more than CPU_MAX_PWR_DWN_OPS were specified in the 134*5dd9dbb5SJeenu Viswambharan * list 135*5dd9dbb5SJeenu Viswambharan */ 136*5dd9dbb5SJeenu Viswambharan .ifeq 2b - 1b 137*5dd9dbb5SJeenu Viswambharan .error "At least one power down function must be specified" 138*5dd9dbb5SJeenu Viswambharan .else 139*5dd9dbb5SJeenu Viswambharan .iflt 2b - 1b - (CPU_MAX_PWR_DWN_OPS * CPU_WORD_SIZE) 140*5dd9dbb5SJeenu Viswambharan .error "More than CPU_MAX_PWR_DWN_OPS functions specified" 141*5dd9dbb5SJeenu Viswambharan .endif 142*5dd9dbb5SJeenu Viswambharan .endif 143add40351SSoby Mathew#endif 144d3f70af6SSoby Mathew#if (IMAGE_BL31 && CRASH_REPORTING) 145d3f70af6SSoby Mathew .quad \_name\()_cpu_reg_dump 146d3f70af6SSoby Mathew#endif 147add40351SSoby Mathew .endm 148e2bf57f8SDan Handley 149e2bf57f8SDan Handley#endif /* __CPU_MACROS_S__ */ 150