1b4315306SDan Handley /* 2b4315306SDan Handley * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. 3b4315306SDan Handley * 4b4315306SDan Handley * Redistribution and use in source and binary forms, with or without 5b4315306SDan Handley * modification, are permitted provided that the following conditions are met: 6b4315306SDan Handley * 7b4315306SDan Handley * Redistributions of source code must retain the above copyright notice, this 8b4315306SDan Handley * list of conditions and the following disclaimer. 9b4315306SDan Handley * 10b4315306SDan Handley * Redistributions in binary form must reproduce the above copyright notice, 11b4315306SDan Handley * this list of conditions and the following disclaimer in the documentation 12b4315306SDan Handley * and/or other materials provided with the distribution. 13b4315306SDan Handley * 14b4315306SDan Handley * Neither the name of ARM nor the names of its contributors may be used 15b4315306SDan Handley * to endorse or promote products derived from this software without specific 16b4315306SDan Handley * prior written permission. 17b4315306SDan Handley * 18b4315306SDan Handley * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19b4315306SDan Handley * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20b4315306SDan Handley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21b4315306SDan Handley * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22b4315306SDan Handley * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23b4315306SDan Handley * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24b4315306SDan Handley * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25b4315306SDan Handley * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26b4315306SDan Handley * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27b4315306SDan Handley * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28b4315306SDan Handley * POSSIBILITY OF SUCH DAMAGE. 29b4315306SDan Handley */ 30b4315306SDan Handley #ifndef __PLAT_ARM_H__ 31b4315306SDan Handley #define __PLAT_ARM_H__ 32b4315306SDan Handley 33b4315306SDan Handley #include <bakery_lock.h> 34b4315306SDan Handley #include <bl_common.h> 35b4315306SDan Handley #include <cassert.h> 36b4315306SDan Handley #include <cpu_data.h> 37b4315306SDan Handley #include <stdint.h> 38b4315306SDan Handley 39b4315306SDan Handley 40b4315306SDan Handley /* 41b4315306SDan Handley * Extern declarations common to ARM standard platforms 42b4315306SDan Handley */ 43b4315306SDan Handley extern const mmap_region_t plat_arm_mmap[]; 44b4315306SDan Handley 45b4315306SDan Handley #define ARM_CASSERT_MMAP \ 46b4315306SDan Handley CASSERT((ARRAY_SIZE(plat_arm_mmap) + ARM_BL_REGIONS) \ 47b4315306SDan Handley <= MAX_MMAP_REGIONS, \ 48b4315306SDan Handley assert_max_mmap_regions); 49b4315306SDan Handley 50b4315306SDan Handley /* 51b4315306SDan Handley * Utility functions common to ARM standard platforms 52b4315306SDan Handley */ 53b4315306SDan Handley 54b4315306SDan Handley void arm_configure_mmu_el1(unsigned long total_base, 55b4315306SDan Handley unsigned long total_size, 56b4315306SDan Handley unsigned long ro_start, 57b4315306SDan Handley unsigned long ro_limit 58b4315306SDan Handley #if USE_COHERENT_MEM 59b4315306SDan Handley , unsigned long coh_start, 60b4315306SDan Handley unsigned long coh_limit 61b4315306SDan Handley #endif 62b4315306SDan Handley ); 63b4315306SDan Handley void arm_configure_mmu_el3(unsigned long total_base, 64b4315306SDan Handley unsigned long total_size, 65b4315306SDan Handley unsigned long ro_start, 66b4315306SDan Handley unsigned long ro_limit 67b4315306SDan Handley #if USE_COHERENT_MEM 68b4315306SDan Handley , unsigned long coh_start, 69b4315306SDan Handley unsigned long coh_limit 70b4315306SDan Handley #endif 71b4315306SDan Handley ); 72b4315306SDan Handley 73b4315306SDan Handley #if IMAGE_BL31 74b4315306SDan Handley #if USE_COHERENT_MEM 75b4315306SDan Handley 76b4315306SDan Handley /* 77b4315306SDan Handley * Use this macro to instantiate lock before it is used in below 78b4315306SDan Handley * arm_lock_xxx() macros 79b4315306SDan Handley */ 80b4315306SDan Handley #define ARM_INSTANTIATE_LOCK bakery_lock_t arm_lock \ 81b4315306SDan Handley __attribute__ ((section("tzfw_coherent_mem"))); 82b4315306SDan Handley 83b4315306SDan Handley /* 84b4315306SDan Handley * These are wrapper macros to the Coherent Memory Bakery Lock API. 85b4315306SDan Handley */ 86b4315306SDan Handley #define arm_lock_init() bakery_lock_init(&arm_lock) 87b4315306SDan Handley #define arm_lock_get() bakery_lock_get(&arm_lock) 88b4315306SDan Handley #define arm_lock_release() bakery_lock_release(&arm_lock) 89b4315306SDan Handley 90b4315306SDan Handley #else 91b4315306SDan Handley 92b4315306SDan Handley /******************************************************************************* 93b4315306SDan Handley * Constants to specify how many bakery locks this platform implements. These 94b4315306SDan Handley * are used if the platform chooses not to use coherent memory for bakery lock 95b4315306SDan Handley * data structures. 96b4315306SDan Handley ******************************************************************************/ 97b4315306SDan Handley #define ARM_MAX_BAKERIES 1 98b4315306SDan Handley #define ARM_PWRC_BAKERY_ID 0 99b4315306SDan Handley 100b4315306SDan Handley /* Empty definition */ 101b4315306SDan Handley #define ARM_INSTANTIATE_LOCK 102b4315306SDan Handley 103b4315306SDan Handley /******************************************************************************* 104b4315306SDan Handley * Definition of structure which holds platform specific per-cpu data. Currently 105b4315306SDan Handley * it holds only the bakery lock information for each cpu. 106b4315306SDan Handley ******************************************************************************/ 107b4315306SDan Handley typedef struct arm_cpu_data { 108b4315306SDan Handley bakery_info_t pcpu_bakery_info[ARM_MAX_BAKERIES]; 109b4315306SDan Handley } arm_cpu_data_t; 110b4315306SDan Handley 111b4315306SDan Handley /* Macro to define the offset of bakery_info_t in arm_cpu_data_t */ 112b4315306SDan Handley #define ARM_CPU_DATA_LOCK_OFFSET __builtin_offsetof\ 113b4315306SDan Handley (arm_cpu_data_t, pcpu_bakery_info) 114b4315306SDan Handley 115b4315306SDan Handley 116b4315306SDan Handley /******************************************************************************* 117b4315306SDan Handley * Helper macros for bakery lock api when using the above arm_cpu_data_t for 118b4315306SDan Handley * bakery lock data structures. It assumes that the bakery_info is at the 119b4315306SDan Handley * beginning of the platform specific per-cpu data. 120b4315306SDan Handley ******************************************************************************/ 121b4315306SDan Handley #define arm_lock_init() /* No init required */ 122b4315306SDan Handley #define arm_lock_get() bakery_lock_get(ARM_PWRC_BAKERY_ID, \ 123b4315306SDan Handley CPU_DATA_PLAT_PCPU_OFFSET + \ 124b4315306SDan Handley ARM_CPU_DATA_LOCK_OFFSET) 125b4315306SDan Handley #define arm_lock_release() bakery_lock_release(ARM_PWRC_BAKERY_ID, \ 126b4315306SDan Handley CPU_DATA_PLAT_PCPU_OFFSET + \ 127b4315306SDan Handley ARM_CPU_DATA_LOCK_OFFSET) 128b4315306SDan Handley 129b4315306SDan Handley /* 130b4315306SDan Handley * Ensure that the size of the platform specific per-cpu data structure and 131b4315306SDan Handley * the size of the memory allocated in generic per-cpu data for the platform 132b4315306SDan Handley * are the same. 133b4315306SDan Handley */ 134b4315306SDan Handley CASSERT(PLAT_PCPU_DATA_SIZE == sizeof(arm_cpu_data_t), 135b4315306SDan Handley arm_pcpu_data_size_mismatch); 136b4315306SDan Handley 137b4315306SDan Handley #endif /* USE_COHERENT_MEM */ 138b4315306SDan Handley 139b4315306SDan Handley #else 140b4315306SDan Handley 141b4315306SDan Handley /* 142b4315306SDan Handley * Dummy macros for all other BL stages other than BL3-1 143b4315306SDan Handley */ 144b4315306SDan Handley #define ARM_INSTANTIATE_LOCK 145b4315306SDan Handley #define arm_lock_init() 146b4315306SDan Handley #define arm_lock_get() 147b4315306SDan Handley #define arm_lock_release() 148b4315306SDan Handley 149b4315306SDan Handley #endif /* IMAGE_BL31 */ 150b4315306SDan Handley 1512204afdeSSoby Mathew #if ARM_RECOM_STATE_ID_ENC 1522204afdeSSoby Mathew /* 1532204afdeSSoby Mathew * Macros used to parse state information from State-ID if it is using the 1542204afdeSSoby Mathew * recommended encoding for State-ID. 1552204afdeSSoby Mathew */ 1562204afdeSSoby Mathew #define ARM_LOCAL_PSTATE_WIDTH 4 1572204afdeSSoby Mathew #define ARM_LOCAL_PSTATE_MASK ((1 << ARM_LOCAL_PSTATE_WIDTH) - 1) 1582204afdeSSoby Mathew 1592204afdeSSoby Mathew /* Macros to construct the composite power state */ 1602204afdeSSoby Mathew 1612204afdeSSoby Mathew /* Make composite power state parameter till power level 0 */ 1622204afdeSSoby Mathew #if PSCI_EXTENDED_STATE_ID 1632204afdeSSoby Mathew 1642204afdeSSoby Mathew #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \ 1652204afdeSSoby Mathew (((lvl0_state) << PSTATE_ID_SHIFT) | ((type) << PSTATE_TYPE_SHIFT)) 1662204afdeSSoby Mathew #else 1672204afdeSSoby Mathew #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \ 1682204afdeSSoby Mathew (((lvl0_state) << PSTATE_ID_SHIFT) | \ 1692204afdeSSoby Mathew ((pwr_lvl) << PSTATE_PWR_LVL_SHIFT) | \ 1702204afdeSSoby Mathew ((type) << PSTATE_TYPE_SHIFT)) 1712204afdeSSoby Mathew #endif /* __PSCI_EXTENDED_STATE_ID__ */ 1722204afdeSSoby Mathew 1732204afdeSSoby Mathew /* Make composite power state parameter till power level 1 */ 1742204afdeSSoby Mathew #define arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type) \ 1752204afdeSSoby Mathew (((lvl1_state) << ARM_LOCAL_PSTATE_WIDTH) | \ 1762204afdeSSoby Mathew arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type)) 1772204afdeSSoby Mathew 1782204afdeSSoby Mathew #endif /* __ARM_RECOM_STATE_ID_ENC__ */ 1792204afdeSSoby Mathew 180b4315306SDan Handley 181b4315306SDan Handley /* CCI utility functions */ 182b4315306SDan Handley void arm_cci_init(void); 183b4315306SDan Handley 184b4315306SDan Handley /* IO storage utility functions */ 185b4315306SDan Handley void arm_io_setup(void); 186b4315306SDan Handley 187b4315306SDan Handley /* Security utility functions */ 188b4315306SDan Handley void arm_tzc_setup(void); 189b4315306SDan Handley 190b4315306SDan Handley /* PM utility functions */ 19138dce70fSSoby Mathew int arm_validate_power_state(unsigned int power_state, 19238dce70fSSoby Mathew psci_power_state_t *req_state); 193*f9e858b1SSoby Mathew int arm_validate_ns_entrypoint(uintptr_t entrypoint); 19438dce70fSSoby Mathew 19538dce70fSSoby Mathew /* Topology utility function */ 19638dce70fSSoby Mathew int arm_check_mpidr(u_register_t mpidr); 197b4315306SDan Handley 198b4315306SDan Handley /* BL1 utility functions */ 199b4315306SDan Handley void arm_bl1_early_platform_setup(void); 200b4315306SDan Handley void arm_bl1_platform_setup(void); 201b4315306SDan Handley void arm_bl1_plat_arch_setup(void); 202b4315306SDan Handley 203b4315306SDan Handley /* BL2 utility functions */ 204b4315306SDan Handley void arm_bl2_early_platform_setup(meminfo_t *mem_layout); 205b4315306SDan Handley void arm_bl2_platform_setup(void); 206b4315306SDan Handley void arm_bl2_plat_arch_setup(void); 207b4315306SDan Handley uint32_t arm_get_spsr_for_bl32_entry(void); 208b4315306SDan Handley uint32_t arm_get_spsr_for_bl33_entry(void); 209b4315306SDan Handley 210b4315306SDan Handley /* BL3-1 utility functions */ 211b4315306SDan Handley void arm_bl31_early_platform_setup(bl31_params_t *from_bl2, 212b4315306SDan Handley void *plat_params_from_bl2); 213b4315306SDan Handley void arm_bl31_platform_setup(void); 214b4315306SDan Handley void arm_bl31_plat_arch_setup(void); 215b4315306SDan Handley 216b4315306SDan Handley /* TSP utility functions */ 217b4315306SDan Handley void arm_tsp_early_platform_setup(void); 218b4315306SDan Handley 219b4315306SDan Handley 220b4315306SDan Handley /* 221b4315306SDan Handley * Mandatory functions required in ARM standard platforms 222b4315306SDan Handley */ 223b4315306SDan Handley void plat_arm_gic_init(void); 224b4315306SDan Handley void plat_arm_security_setup(void); 225b4315306SDan Handley void plat_arm_pwrc_setup(void); 226b4315306SDan Handley 227b4315306SDan Handley /* 228b4315306SDan Handley * Optional functions required in ARM standard platforms 229b4315306SDan Handley */ 230b4315306SDan Handley void plat_arm_io_setup(void); 231b4315306SDan Handley int plat_arm_get_alt_image_source( 23216948ae1SJuan Castillo unsigned int image_id, 23316948ae1SJuan Castillo uintptr_t *dev_handle, 23416948ae1SJuan Castillo uintptr_t *image_spec); 23538dce70fSSoby Mathew unsigned int plat_arm_calc_core_pos(u_register_t mpidr); 236b4315306SDan Handley 237b4315306SDan Handley 238b4315306SDan Handley #endif /* __PLAT_ARM_H__ */ 239