Unverified Commit ebd17fa4 authored by Antonio Niño Díaz's avatar Antonio Niño Díaz Committed by GitHub
Browse files

Merge pull request #1660 from antonio-nino-diaz-arm/an/misra

Several MISRA defect fixes
parents 3c1fb7a7 f8b30ca8
/* /*
* Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -49,9 +49,9 @@ void bl1_prepare_next_image(unsigned int image_id) ...@@ -49,9 +49,9 @@ void bl1_prepare_next_image(unsigned int image_id)
* Ensure that the build flag to save AArch32 system registers in CPU * Ensure that the build flag to save AArch32 system registers in CPU
* context is not set for AArch64-only platforms. * context is not set for AArch64-only platforms.
*/ */
if (EL_IMPLEMENTED(1) == EL_IMPL_A64ONLY) { if (el_implemented(1) == EL_IMPL_A64ONLY) {
ERROR("EL1 supports AArch64-only. Please set build flag " ERROR("EL1 supports AArch64-only. Please set build flag "
"CTX_INCLUDE_AARCH32_REGS = 0"); "CTX_INCLUDE_AARCH32_REGS = 0\n");
panic(); panic();
} }
#endif #endif
...@@ -76,7 +76,7 @@ void bl1_prepare_next_image(unsigned int image_id) ...@@ -76,7 +76,7 @@ void bl1_prepare_next_image(unsigned int image_id)
DISABLE_ALL_EXCEPTIONS); DISABLE_ALL_EXCEPTIONS);
} else { } else {
/* Use EL2 if supported; else use EL1. */ /* Use EL2 if supported; else use EL1. */
if (EL_IMPLEMENTED(2)) { if (el_implemented(2) != EL_IMPL_NONE) {
next_bl_ep->spsr = SPSR_64(MODE_EL2, MODE_SP_ELX, next_bl_ep->spsr = SPSR_64(MODE_EL2, MODE_SP_ELX,
DISABLE_ALL_EXCEPTIONS); DISABLE_ALL_EXCEPTIONS);
} else { } else {
......
...@@ -159,9 +159,9 @@ void __init bl31_prepare_next_image_entry(void) ...@@ -159,9 +159,9 @@ void __init bl31_prepare_next_image_entry(void)
* Ensure that the build flag to save AArch32 system registers in CPU * Ensure that the build flag to save AArch32 system registers in CPU
* context is not set for AArch64-only platforms. * context is not set for AArch64-only platforms.
*/ */
if (EL_IMPLEMENTED(1) == EL_IMPL_A64ONLY) { if (el_implemented(1) == EL_IMPL_A64ONLY) {
ERROR("EL1 supports AArch64-only. Please set build flag " ERROR("EL1 supports AArch64-only. Please set build flag "
"CTX_INCLUDE_AARCH32_REGS = 0"); "CTX_INCLUDE_AARCH32_REGS = 0\n");
panic(); panic();
} }
#endif #endif
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#define PARAM_EP_SECURITY_MASK U(0x1) #define PARAM_EP_SECURITY_MASK U(0x1)
/* Secure or Non-secure image */ /* Secure or Non-secure image */
#define GET_SECURITY_STATE(x) (x & PARAM_EP_SECURITY_MASK) #define GET_SECURITY_STATE(x) ((x) & PARAM_EP_SECURITY_MASK)
#define SET_SECURITY_STATE(x, security) \ #define SET_SECURITY_STATE(x, security) \
((x) = ((x) & ~PARAM_EP_SECURITY_MASK) | (security)) ((x) = ((x) & ~PARAM_EP_SECURITY_MASK) | (security))
......
...@@ -73,10 +73,10 @@ ...@@ -73,10 +73,10 @@
/* Macros for allowing Non-Secure access to a region based on NSAID */ /* Macros for allowing Non-Secure access to a region based on NSAID */
#define TZC_REGION_ACCESS_RD(nsaid) \ #define TZC_REGION_ACCESS_RD(nsaid) \
((U(1) << (nsaid & TZC_REGION_ACCESS_ID_MASK)) << \ ((U(1) << ((nsaid) & TZC_REGION_ACCESS_ID_MASK)) << \
TZC_REGION_ACCESS_RD_EN_SHIFT) TZC_REGION_ACCESS_RD_EN_SHIFT)
#define TZC_REGION_ACCESS_WR(nsaid) \ #define TZC_REGION_ACCESS_WR(nsaid) \
((U(1) << (nsaid & TZC_REGION_ACCESS_ID_MASK)) << \ ((U(1) << ((nsaid) & TZC_REGION_ACCESS_ID_MASK)) << \
TZC_REGION_ACCESS_WR_EN_SHIFT) TZC_REGION_ACCESS_WR_EN_SHIFT)
#define TZC_REGION_ACCESS_RDWR(nsaid) \ #define TZC_REGION_ACCESS_RDWR(nsaid) \
(TZC_REGION_ACCESS_RD(nsaid) | \ (TZC_REGION_ACCESS_RD(nsaid) | \
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#ifndef __ARCH_HELPERS_H__ #ifndef ARCH_HELPERS_H
#define __ARCH_HELPERS_H__ #define ARCH_HELPERS_H
#include <arch.h> /* for additional register definitions */ #include <arch.h> /* for additional register definitions */
#include <cdefs.h> #include <cdefs.h>
...@@ -381,4 +381,4 @@ static inline unsigned int get_current_el(void) ...@@ -381,4 +381,4 @@ static inline unsigned int get_current_el(void)
#define write_icc_sgi0r_el1(_v) \ #define write_icc_sgi0r_el1(_v) \
write64_icc_sgi0r_el1(_v) write64_icc_sgi0r_el1(_v)
#endif /* __ARCH_HELPERS_H__ */ #endif /* ARCH_HELPERS_H */
...@@ -4,11 +4,12 @@ ...@@ -4,11 +4,12 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#ifndef __ARCH_HELPERS_H__ #ifndef ARCH_HELPERS_H
#define __ARCH_HELPERS_H__ #define ARCH_HELPERS_H
#include <arch.h> /* for additional register definitions */ #include <arch.h> /* for additional register definitions */
#include <cdefs.h> /* For __dead2 */ #include <cdefs.h> /* For __dead2 */
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
...@@ -363,12 +364,22 @@ static inline unsigned int get_current_el(void) ...@@ -363,12 +364,22 @@ static inline unsigned int get_current_el(void)
} }
/* /*
* Check if an EL is implemented from AA64PFR0 register fields. 'el' argument * Check if an EL is implemented from AA64PFR0 register fields.
* must be one of 1, 2 or 3.
*/ */
#define EL_IMPLEMENTED(el) \ static inline uint64_t el_implemented(unsigned int el)
((read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL##el##_SHIFT) \ {
& ID_AA64PFR0_ELX_MASK) if (el > 3U) {
return EL_IMPL_NONE;
} else {
unsigned int shift = ID_AA64PFR0_EL1_SHIFT * el;
return (read_id_aa64pfr0_el1() >> shift) & ID_AA64PFR0_ELX_MASK;
}
}
#if !ERROR_DEPRECATED
#define EL_IMPLEMENTED(_el) el_implemented(_el)
#endif
/* Previously defined accesor functions with incomplete register names */ /* Previously defined accesor functions with incomplete register names */
...@@ -389,4 +400,4 @@ static inline unsigned int get_current_el(void) ...@@ -389,4 +400,4 @@ static inline unsigned int get_current_el(void)
#define read_cpacr() read_cpacr_el1() #define read_cpacr() read_cpacr_el1()
#define write_cpacr(_v) write_cpacr_el1(_v) #define write_cpacr(_v) write_cpacr_el1(_v)
#endif /* __ARCH_HELPERS_H__ */ #endif /* ARCH_HELPERS_H */
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#ifndef __BAKERY_LOCK_H__ #ifndef BAKERY_LOCK_H
#define __BAKERY_LOCK_H__ #define BAKERY_LOCK_H
#include <platform_def.h> #include <platform_def.h>
...@@ -13,21 +13,39 @@ ...@@ -13,21 +13,39 @@
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#include <cdefs.h> #include <cdefs.h>
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <utils_def.h>
/***************************************************************************** /*****************************************************************************
* Internal helper macros used by the bakery lock implementation. * Internal helpers used by the bakery lock implementation.
****************************************************************************/ ****************************************************************************/
/* Convert a ticket to priority */ /* Convert a ticket to priority */
#define PRIORITY(t, pos) (((t) << 8) | (pos)) static inline unsigned int bakery_get_priority(unsigned int t, unsigned int pos)
{
return (t << 8) | pos;
}
#define CHOOSING_TICKET U(0x1)
#define CHOSEN_TICKET U(0x0)
static inline bool bakery_is_choosing(unsigned int info)
{
return (info & 1U) == CHOOSING_TICKET;
}
static inline unsigned int bakery_ticket_number(unsigned int info)
{
return (info >> 1) & 0x7FFFU;
}
#define CHOOSING_TICKET 0x1 static inline uint16_t make_bakery_data(unsigned int choosing, unsigned int num)
#define CHOSEN_TICKET 0x0 {
unsigned int val = (choosing & 0x1U) | (num << 1);
#define bakery_is_choosing(info) (info & 0x1) return (uint16_t) val;
#define bakery_ticket_number(info) ((info >> 1) & 0x7FFF) }
#define make_bakery_data(choosing, number) \
(((choosing & 0x1) | (number << 1)) & 0xFFFF)
/***************************************************************************** /*****************************************************************************
* External bakery lock interface. * External bakery lock interface.
...@@ -83,4 +101,4 @@ void bakery_lock_release(bakery_lock_t *bakery); ...@@ -83,4 +101,4 @@ void bakery_lock_release(bakery_lock_t *bakery);
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __BAKERY_LOCK_H__ */ #endif /* BAKERY_LOCK_H */
/* /*
* Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#ifndef __CONTEXT_H__ #ifndef CONTEXT_H
#define __CONTEXT_H__ #define CONTEXT_H
#include <utils_def.h>
/******************************************************************************* /*******************************************************************************
* Constants that allow assembler code to access members of and the 'regs' * Constants that allow assembler code to access members of and the 'regs'
* structure at their correct offsets. * structure at their correct offsets.
******************************************************************************/ ******************************************************************************/
#define CTX_REGS_OFFSET 0x0 #define CTX_REGS_OFFSET U(0x0)
#define CTX_GPREG_R0 0x0 #define CTX_GPREG_R0 U(0x0)
#define CTX_GPREG_R1 0x4 #define CTX_GPREG_R1 U(0x4)
#define CTX_GPREG_R2 0x8 #define CTX_GPREG_R2 U(0x8)
#define CTX_GPREG_R3 0xC #define CTX_GPREG_R3 U(0xC)
#define CTX_LR 0x10 #define CTX_LR U(0x10)
#define CTX_SCR 0x14 #define CTX_SCR U(0x14)
#define CTX_SPSR 0x18 #define CTX_SPSR U(0x18)
#define CTX_NS_SCTLR 0x1C #define CTX_NS_SCTLR U(0x1C)
#define CTX_REGS_END 0x20 #define CTX_REGS_END U(0x20)
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
...@@ -31,7 +33,7 @@ ...@@ -31,7 +33,7 @@
* Common constants to help define the 'cpu_context' structure and its * Common constants to help define the 'cpu_context' structure and its
* members below. * members below.
*/ */
#define WORD_SHIFT 2 #define WORD_SHIFT U(2)
#define DEFINE_REG_STRUCT(name, num_regs) \ #define DEFINE_REG_STRUCT(name, num_regs) \
typedef struct name { \ typedef struct name { \
uint32_t _regs[num_regs]; \ uint32_t _regs[num_regs]; \
...@@ -64,4 +66,4 @@ CASSERT(CTX_REGS_OFFSET == __builtin_offsetof(cpu_context_t, regs_ctx), \ ...@@ -64,4 +66,4 @@ CASSERT(CTX_REGS_OFFSET == __builtin_offsetof(cpu_context_t, regs_ctx), \
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __CONTEXT_H__ */ #endif /* CONTEXT_H */
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#ifndef __CONTEXT_H__ #ifndef CONTEXT_H
#define __CONTEXT_H__ #define CONTEXT_H
#include <utils_def.h> #include <utils_def.h>
...@@ -347,4 +347,4 @@ void fpregs_context_restore(fp_regs_t *regs); ...@@ -347,4 +347,4 @@ void fpregs_context_restore(fp_regs_t *regs);
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __CONTEXT_H__ */ #endif /* CONTEXT_H */
/* /*
* Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#ifndef __CM_H__ #ifndef CONTEXT_MGMT_H
#define __CM_H__ #define CONTEXT_MGMT_H
#include <arch.h> #include <arch.h>
#include <assert.h> #include <assert.h>
#include <context.h> #include <context.h>
#include <context_mgmt.h>
#include <stdint.h> #include <stdint.h>
/******************************************************************************* /*******************************************************************************
...@@ -80,4 +79,4 @@ void *cm_get_next_context(void); ...@@ -80,4 +79,4 @@ void *cm_get_next_context(void);
void cm_set_next_context(void *context); void cm_set_next_context(void *context);
#endif /* AARCH32 */ #endif /* AARCH32 */
#endif /* __CM_H__ */ #endif /* CONTEXT_MGMT_H */
...@@ -144,9 +144,9 @@ void init_cpu_data_ptr(void); ...@@ -144,9 +144,9 @@ void init_cpu_data_ptr(void);
void init_cpu_ops(void); void init_cpu_ops(void);
#define get_cpu_data(_m) _cpu_data()->_m #define get_cpu_data(_m) _cpu_data()->_m
#define set_cpu_data(_m, _v) _cpu_data()->_m = _v #define set_cpu_data(_m, _v) _cpu_data()->_m = (_v)
#define get_cpu_data_by_index(_ix, _m) _cpu_data_by_index(_ix)->_m #define get_cpu_data_by_index(_ix, _m) _cpu_data_by_index(_ix)->_m
#define set_cpu_data_by_index(_ix, _m, _v) _cpu_data_by_index(_ix)->_m = _v #define set_cpu_data_by_index(_ix, _m, _v) _cpu_data_by_index(_ix)->_m = (_v)
/* ((cpu_data_t *)0)->_m is a dummy to get the sizeof the struct member _m */ /* ((cpu_data_t *)0)->_m is a dummy to get the sizeof the struct member _m */
#define flush_cpu_data(_m) flush_dcache_range((uintptr_t) \ #define flush_cpu_data(_m) flush_dcache_range((uintptr_t) \
&(_cpu_data()->_m), \ &(_cpu_data()->_m), \
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#ifndef __SPINLOCK_H__ #ifndef SPINLOCK_H
#define __SPINLOCK_H__ #define SPINLOCK_H
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
...@@ -26,4 +26,4 @@ void spin_unlock(spinlock_t *lock); ...@@ -26,4 +26,4 @@ void spin_unlock(spinlock_t *lock);
#endif #endif
#endif /* __SPINLOCK_H__ */ #endif /* SPINLOCK_H */
...@@ -48,9 +48,9 @@ ...@@ -48,9 +48,9 @@
#define V2M_SYS_LED_EL_SHIFT 0x1 #define V2M_SYS_LED_EL_SHIFT 0x1
#define V2M_SYS_LED_EC_SHIFT 0x3 #define V2M_SYS_LED_EC_SHIFT 0x3
#define V2M_SYS_LED_SS_MASK 0x1 #define V2M_SYS_LED_SS_MASK U(0x1)
#define V2M_SYS_LED_EL_MASK 0x3 #define V2M_SYS_LED_EL_MASK U(0x3)
#define V2M_SYS_LED_EC_MASK 0x1f #define V2M_SYS_LED_EC_MASK U(0x1f)
/* V2M sysid register bits */ /* V2M sysid register bits */
#define V2M_SYS_ID_REV_SHIFT 28 #define V2M_SYS_ID_REV_SHIFT 28
...@@ -59,28 +59,28 @@ ...@@ -59,28 +59,28 @@
#define V2M_SYS_ID_ARCH_SHIFT 8 #define V2M_SYS_ID_ARCH_SHIFT 8
#define V2M_SYS_ID_FPGA_SHIFT 0 #define V2M_SYS_ID_FPGA_SHIFT 0
#define V2M_SYS_ID_REV_MASK 0xf #define V2M_SYS_ID_REV_MASK U(0xf)
#define V2M_SYS_ID_HBI_MASK 0xfff #define V2M_SYS_ID_HBI_MASK U(0xfff)
#define V2M_SYS_ID_BLD_MASK 0xf #define V2M_SYS_ID_BLD_MASK U(0xf)
#define V2M_SYS_ID_ARCH_MASK 0xf #define V2M_SYS_ID_ARCH_MASK U(0xf)
#define V2M_SYS_ID_FPGA_MASK 0xff #define V2M_SYS_ID_FPGA_MASK U(0xff)
#define V2M_SYS_ID_BLD_LENGTH 4 #define V2M_SYS_ID_BLD_LENGTH 4
/* NOR Flash */ /* NOR Flash */
#define V2M_FLASH0_BASE 0x08000000 #define V2M_FLASH0_BASE UL(0x08000000)
#define V2M_FLASH0_SIZE 0x04000000 #define V2M_FLASH0_SIZE UL(0x04000000)
#define V2M_FLASH_BLOCK_SIZE 0x00040000 /* 256 KB */ #define V2M_FLASH_BLOCK_SIZE UL(0x00040000) /* 256 KB */
#define V2M_IOFPGA_BASE 0x1c000000 #define V2M_IOFPGA_BASE UL(0x1c000000)
#define V2M_IOFPGA_SIZE 0x03000000 #define V2M_IOFPGA_SIZE UL(0x03000000)
/* PL011 UART related constants */ /* PL011 UART related constants */
#define V2M_IOFPGA_UART0_BASE 0x1c090000 #define V2M_IOFPGA_UART0_BASE UL(0x1c090000)
#define V2M_IOFPGA_UART1_BASE 0x1c0a0000 #define V2M_IOFPGA_UART1_BASE UL(0x1c0a0000)
#define V2M_IOFPGA_UART2_BASE 0x1c0b0000 #define V2M_IOFPGA_UART2_BASE UL(0x1c0b0000)
#define V2M_IOFPGA_UART3_BASE 0x1c0c0000 #define V2M_IOFPGA_UART3_BASE UL(0x1c0c0000)
#define V2M_IOFPGA_UART0_CLK_IN_HZ 24000000 #define V2M_IOFPGA_UART0_CLK_IN_HZ 24000000
#define V2M_IOFPGA_UART1_CLK_IN_HZ 24000000 #define V2M_IOFPGA_UART1_CLK_IN_HZ 24000000
...@@ -88,15 +88,15 @@ ...@@ -88,15 +88,15 @@
#define V2M_IOFPGA_UART3_CLK_IN_HZ 24000000 #define V2M_IOFPGA_UART3_CLK_IN_HZ 24000000
/* SP804 timer related constants */ /* SP804 timer related constants */
#define V2M_SP804_TIMER0_BASE 0x1C110000 #define V2M_SP804_TIMER0_BASE UL(0x1C110000)
#define V2M_SP804_TIMER1_BASE 0x1C120000 #define V2M_SP804_TIMER1_BASE UL(0x1C120000)
/* SP810 controller */ /* SP810 controller */
#define V2M_SP810_BASE 0x1c020000 #define V2M_SP810_BASE UL(0x1c020000)
#define V2M_SP810_CTRL_TIM0_SEL (1 << 15) #define V2M_SP810_CTRL_TIM0_SEL BIT_32(15)
#define V2M_SP810_CTRL_TIM1_SEL (1 << 17) #define V2M_SP810_CTRL_TIM1_SEL BIT_32(17)
#define V2M_SP810_CTRL_TIM2_SEL (1 << 19) #define V2M_SP810_CTRL_TIM2_SEL BIT_32(19)
#define V2M_SP810_CTRL_TIM3_SEL (1 << 21) #define V2M_SP810_CTRL_TIM3_SEL BIT_32(21)
/* /*
* The flash can be mapped either as read-only or read-write. * The flash can be mapped either as read-only or read-write.
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
*****************************************************************************/ *****************************************************************************/
/* Special value used to verify platform parameters from BL2 to BL31 */ /* Special value used to verify platform parameters from BL2 to BL31 */
#define ARM_BL31_PLAT_PARAM_VAL 0x0f1e2d3c4b5a6978ULL #define ARM_BL31_PLAT_PARAM_VAL ULL(0x0f1e2d3c4b5a6978)
#define ARM_SYSTEM_COUNT 1 #define ARM_SYSTEM_COUNT 1
...@@ -350,8 +350,8 @@ ...@@ -350,8 +350,8 @@
* To enable TB_FW_CONFIG to be loaded by BL1, define the corresponding base * To enable TB_FW_CONFIG to be loaded by BL1, define the corresponding base
* and limit. Leave enough space of BL2 meminfo. * and limit. Leave enough space of BL2 meminfo.
*/ */
#define ARM_TB_FW_CONFIG_BASE ARM_BL_RAM_BASE + sizeof(meminfo_t) #define ARM_TB_FW_CONFIG_BASE (ARM_BL_RAM_BASE + sizeof(meminfo_t))
#define ARM_TB_FW_CONFIG_LIMIT ARM_BL_RAM_BASE + PAGE_SIZE #define ARM_TB_FW_CONFIG_LIMIT (ARM_BL_RAM_BASE + PAGE_SIZE)
/******************************************************************************* /*******************************************************************************
* BL1 specific defines. * BL1 specific defines.
...@@ -482,7 +482,7 @@ ...@@ -482,7 +482,7 @@
# define TSP_SEC_MEM_SIZE PLAT_ARM_TRUSTED_DRAM_SIZE # define TSP_SEC_MEM_SIZE PLAT_ARM_TRUSTED_DRAM_SIZE
# define BL32_BASE PLAT_ARM_TRUSTED_DRAM_BASE # define BL32_BASE PLAT_ARM_TRUSTED_DRAM_BASE
# define BL32_LIMIT (PLAT_ARM_TRUSTED_DRAM_BASE \ # define BL32_LIMIT (PLAT_ARM_TRUSTED_DRAM_BASE \
+ (1 << 21)) + (UL(1) << 21))
# elif ARM_TSP_RAM_LOCATION_ID == ARM_DRAM_ID # elif ARM_TSP_RAM_LOCATION_ID == ARM_DRAM_ID
# define TSP_SEC_MEM_BASE ARM_AP_TZC_DRAM1_BASE # define TSP_SEC_MEM_BASE ARM_AP_TZC_DRAM1_BASE
# define TSP_SEC_MEM_SIZE ARM_AP_TZC_DRAM1_SIZE # define TSP_SEC_MEM_SIZE ARM_AP_TZC_DRAM1_SIZE
...@@ -511,7 +511,7 @@ ...@@ -511,7 +511,7 @@
#define BL2U_LIMIT BL2_LIMIT #define BL2U_LIMIT BL2_LIMIT
#define NS_BL2U_BASE ARM_NS_DRAM1_BASE #define NS_BL2U_BASE ARM_NS_DRAM1_BASE
#define NS_BL1U_BASE (PLAT_ARM_NVM_BASE + 0x03EB8000) #define NS_BL1U_BASE (PLAT_ARM_NVM_BASE + UL(0x03EB8000))
/* /*
* ID of the secure physical generic timer interrupt used by the TSP. * ID of the secure physical generic timer interrupt used by the TSP.
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#ifndef __ARM_DYN_CFG_HELPERS_H__ #ifndef ARM_DYN_CFG_HELPERS_H
#define __ARM_DYN_CFG_HELPERS_H__ #define ARM_DYN_CFG_HELPERS_H
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
...@@ -19,4 +19,4 @@ int arm_get_dtb_mbedtls_heap_info(void *dtb, void **heap_addr, ...@@ -19,4 +19,4 @@ int arm_get_dtb_mbedtls_heap_info(void *dtb, void **heap_addr,
int arm_set_dtb_mbedtls_heap_info(void *dtb, void *heap_addr, int arm_set_dtb_mbedtls_heap_info(void *dtb, void *heap_addr,
size_t heap_size); size_t heap_size);
#endif /* __ARM_DYN_CFG_HELPERS_H__ */ #endif /* ARM_DYN_CFG_HELPERS_H */
...@@ -57,7 +57,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep) ...@@ -57,7 +57,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep)
uint32_t scr, sctlr; uint32_t scr, sctlr;
regs_t *reg_ctx; regs_t *reg_ctx;
assert(ctx); assert(ctx != NULL);
security_state = GET_SECURITY_STATE(ep->h.attr); security_state = GET_SECURITY_STATE(ep->h.attr);
...@@ -97,7 +97,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep) ...@@ -97,7 +97,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep)
assert(((ep->spsr >> SPSR_E_SHIFT) & SPSR_E_MASK) == assert(((ep->spsr >> SPSR_E_SHIFT) & SPSR_E_MASK) ==
(EP_GET_EE(ep->h.attr) >> EP_EE_SHIFT)); (EP_GET_EE(ep->h.attr) >> EP_EE_SHIFT));
sctlr = EP_GET_EE(ep->h.attr) ? SCTLR_EE_BIT : 0; sctlr = (EP_GET_EE(ep->h.attr) != 0U) ? SCTLR_EE_BIT : 0U;
sctlr |= (SCTLR_RESET_VAL & ~(SCTLR_TE_BIT | SCTLR_V_BIT)); sctlr |= (SCTLR_RESET_VAL & ~(SCTLR_TE_BIT | SCTLR_V_BIT));
write_ctx_reg(reg_ctx, CTX_NS_SCTLR, sctlr); write_ctx_reg(reg_ctx, CTX_NS_SCTLR, sctlr);
} }
...@@ -178,11 +178,11 @@ void cm_prepare_el3_exit(uint32_t security_state) ...@@ -178,11 +178,11 @@ void cm_prepare_el3_exit(uint32_t security_state)
cpu_context_t *ctx = cm_get_context(security_state); cpu_context_t *ctx = cm_get_context(security_state);
bool el2_unused = false; bool el2_unused = false;
assert(ctx); assert(ctx != NULL);
if (security_state == NON_SECURE) { if (security_state == NON_SECURE) {
scr = read_ctx_reg(get_regs_ctx(ctx), CTX_SCR); scr = read_ctx_reg(get_regs_ctx(ctx), CTX_SCR);
if (scr & SCR_HCE_BIT) { if ((scr & SCR_HCE_BIT) != 0U) {
/* Use SCTLR value to initialize HSCTLR */ /* Use SCTLR value to initialize HSCTLR */
hsctlr = read_ctx_reg(get_regs_ctx(ctx), hsctlr = read_ctx_reg(get_regs_ctx(ctx),
CTX_NS_SCTLR); CTX_NS_SCTLR);
...@@ -199,8 +199,8 @@ void cm_prepare_el3_exit(uint32_t security_state) ...@@ -199,8 +199,8 @@ void cm_prepare_el3_exit(uint32_t security_state)
write_scr(read_scr() & ~SCR_NS_BIT); write_scr(read_scr() & ~SCR_NS_BIT);
isb(); isb();
} else if (read_id_pfr1() & } else if ((read_id_pfr1() &
(ID_PFR1_VIRTEXT_MASK << ID_PFR1_VIRTEXT_SHIFT)) { (ID_PFR1_VIRTEXT_MASK << ID_PFR1_VIRTEXT_SHIFT)) != 0U) {
el2_unused = true; el2_unused = true;
/* /*
......
...@@ -68,7 +68,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep) ...@@ -68,7 +68,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep)
gp_regs_t *gp_regs; gp_regs_t *gp_regs;
unsigned long sctlr_elx, actlr_elx; unsigned long sctlr_elx, actlr_elx;
assert(ctx); assert(ctx != NULL);
security_state = GET_SECURITY_STATE(ep->h.attr); security_state = GET_SECURITY_STATE(ep->h.attr);
...@@ -84,7 +84,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep) ...@@ -84,7 +84,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep)
* the required value depending on the state of the SPSR_EL3 and the * the required value depending on the state of the SPSR_EL3 and the
* Security state and entrypoint attributes of the next EL. * Security state and entrypoint attributes of the next EL.
*/ */
scr_el3 = read_scr(); scr_el3 = (uint32_t)read_scr();
scr_el3 &= ~(SCR_NS_BIT | SCR_RW_BIT | SCR_FIQ_BIT | SCR_IRQ_BIT | scr_el3 &= ~(SCR_NS_BIT | SCR_RW_BIT | SCR_FIQ_BIT | SCR_IRQ_BIT |
SCR_ST_BIT | SCR_HCE_BIT); SCR_ST_BIT | SCR_HCE_BIT);
/* /*
...@@ -103,7 +103,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep) ...@@ -103,7 +103,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep)
* Secure timer registers to EL3, from AArch64 state only, if specified * Secure timer registers to EL3, from AArch64 state only, if specified
* by the entrypoint attributes. * by the entrypoint attributes.
*/ */
if (EP_GET_ST(ep->h.attr)) if (EP_GET_ST(ep->h.attr) != 0U)
scr_el3 |= SCR_ST_BIT; scr_el3 |= SCR_ST_BIT;
#if !HANDLE_EA_EL3_FIRST #if !HANDLE_EA_EL3_FIRST
...@@ -133,10 +133,9 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep) ...@@ -133,10 +133,9 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep)
* AArch64 and next EL is EL2, or if next execution state is AArch32 and * AArch64 and next EL is EL2, or if next execution state is AArch32 and
* next mode is Hyp. * next mode is Hyp.
*/ */
if ((GET_RW(ep->spsr) == MODE_RW_64 if (((GET_RW(ep->spsr) == MODE_RW_64) && (GET_EL(ep->spsr) == MODE_EL2))
&& GET_EL(ep->spsr) == MODE_EL2) || ((GET_RW(ep->spsr) != MODE_RW_64)
|| (GET_RW(ep->spsr) != MODE_RW_64 && (GET_M32(ep->spsr) == MODE32_hyp))) {
&& GET_M32(ep->spsr) == MODE32_hyp)) {
scr_el3 |= SCR_HCE_BIT; scr_el3 |= SCR_HCE_BIT;
} }
...@@ -151,7 +150,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep) ...@@ -151,7 +150,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep)
* SCTLR.M, SCTLR.C and SCTLR.I: These fields must be zero (as * SCTLR.M, SCTLR.C and SCTLR.I: These fields must be zero (as
* required by PSCI specification) * required by PSCI specification)
*/ */
sctlr_elx = EP_GET_EE(ep->h.attr) ? SCTLR_EE_BIT : 0; sctlr_elx = (EP_GET_EE(ep->h.attr) != 0U) ? SCTLR_EE_BIT : 0U;
if (GET_RW(ep->spsr) == MODE_RW_64) if (GET_RW(ep->spsr) == MODE_RW_64)
sctlr_elx |= SCTLR_EL1_RES1; sctlr_elx |= SCTLR_EL1_RES1;
else { else {
...@@ -291,20 +290,21 @@ void cm_prepare_el3_exit(uint32_t security_state) ...@@ -291,20 +290,21 @@ void cm_prepare_el3_exit(uint32_t security_state)
uint32_t sctlr_elx, scr_el3, mdcr_el2; uint32_t sctlr_elx, scr_el3, mdcr_el2;
cpu_context_t *ctx = cm_get_context(security_state); cpu_context_t *ctx = cm_get_context(security_state);
bool el2_unused = false; bool el2_unused = false;
uint64_t hcr_el2 = 0; uint64_t hcr_el2 = 0U;
assert(ctx); assert(ctx != NULL);
if (security_state == NON_SECURE) { if (security_state == NON_SECURE) {
scr_el3 = read_ctx_reg(get_el3state_ctx(ctx), CTX_SCR_EL3); scr_el3 = (uint32_t)read_ctx_reg(get_el3state_ctx(ctx),
if (scr_el3 & SCR_HCE_BIT) { CTX_SCR_EL3);
if ((scr_el3 & SCR_HCE_BIT) != 0U) {
/* Use SCTLR_EL1.EE value to initialise sctlr_el2 */ /* Use SCTLR_EL1.EE value to initialise sctlr_el2 */
sctlr_elx = read_ctx_reg(get_sysregs_ctx(ctx), sctlr_elx = (uint32_t)read_ctx_reg(get_sysregs_ctx(ctx),
CTX_SCTLR_EL1); CTX_SCTLR_EL1);
sctlr_elx &= SCTLR_EE_BIT; sctlr_elx &= SCTLR_EE_BIT;
sctlr_elx |= SCTLR_EL2_RES1; sctlr_elx |= SCTLR_EL2_RES1;
write_sctlr_el2(sctlr_elx); write_sctlr_el2(sctlr_elx);
} else if (EL_IMPLEMENTED(2)) { } else if (el_implemented(2) != EL_IMPL_NONE) {
el2_unused = true; el2_unused = true;
/* /*
...@@ -314,7 +314,7 @@ void cm_prepare_el3_exit(uint32_t security_state) ...@@ -314,7 +314,7 @@ void cm_prepare_el3_exit(uint32_t security_state)
* Set EL2 register width appropriately: Set HCR_EL2 * Set EL2 register width appropriately: Set HCR_EL2
* field to match SCR_EL3.RW. * field to match SCR_EL3.RW.
*/ */
if (scr_el3 & SCR_RW_BIT) if ((scr_el3 & SCR_RW_BIT) != 0U)
hcr_el2 |= HCR_RW_BIT; hcr_el2 |= HCR_RW_BIT;
/* /*
...@@ -470,7 +470,7 @@ void cm_el1_sysregs_context_save(uint32_t security_state) ...@@ -470,7 +470,7 @@ void cm_el1_sysregs_context_save(uint32_t security_state)
cpu_context_t *ctx; cpu_context_t *ctx;
ctx = cm_get_context(security_state); ctx = cm_get_context(security_state);
assert(ctx); assert(ctx != NULL);
el1_sysregs_context_save(get_sysregs_ctx(ctx)); el1_sysregs_context_save(get_sysregs_ctx(ctx));
...@@ -487,7 +487,7 @@ void cm_el1_sysregs_context_restore(uint32_t security_state) ...@@ -487,7 +487,7 @@ void cm_el1_sysregs_context_restore(uint32_t security_state)
cpu_context_t *ctx; cpu_context_t *ctx;
ctx = cm_get_context(security_state); ctx = cm_get_context(security_state);
assert(ctx); assert(ctx != NULL);
el1_sysregs_context_restore(get_sysregs_ctx(ctx)); el1_sysregs_context_restore(get_sysregs_ctx(ctx));
...@@ -509,7 +509,7 @@ void cm_set_elr_el3(uint32_t security_state, uintptr_t entrypoint) ...@@ -509,7 +509,7 @@ void cm_set_elr_el3(uint32_t security_state, uintptr_t entrypoint)
el3_state_t *state; el3_state_t *state;
ctx = cm_get_context(security_state); ctx = cm_get_context(security_state);
assert(ctx); assert(ctx != NULL);
/* Populate EL3 state so that ERET jumps to the correct entry */ /* Populate EL3 state so that ERET jumps to the correct entry */
state = get_el3state_ctx(ctx); state = get_el3state_ctx(ctx);
...@@ -527,7 +527,7 @@ void cm_set_elr_spsr_el3(uint32_t security_state, ...@@ -527,7 +527,7 @@ void cm_set_elr_spsr_el3(uint32_t security_state,
el3_state_t *state; el3_state_t *state;
ctx = cm_get_context(security_state); ctx = cm_get_context(security_state);
assert(ctx); assert(ctx != NULL);
/* Populate EL3 state so that ERET jumps to the correct entry */ /* Populate EL3 state so that ERET jumps to the correct entry */
state = get_el3state_ctx(ctx); state = get_el3state_ctx(ctx);
...@@ -549,21 +549,21 @@ void cm_write_scr_el3_bit(uint32_t security_state, ...@@ -549,21 +549,21 @@ void cm_write_scr_el3_bit(uint32_t security_state,
uint32_t scr_el3; uint32_t scr_el3;
ctx = cm_get_context(security_state); ctx = cm_get_context(security_state);
assert(ctx); assert(ctx != NULL);
/* Ensure that the bit position is a valid one */ /* Ensure that the bit position is a valid one */
assert((1 << bit_pos) & SCR_VALID_BIT_MASK); assert(((1U << bit_pos) & SCR_VALID_BIT_MASK) != 0U);
/* Ensure that the 'value' is only a bit wide */ /* Ensure that the 'value' is only a bit wide */
assert(value <= 1); assert(value <= 1U);
/* /*
* Get the SCR_EL3 value from the cpu context, clear the desired bit * Get the SCR_EL3 value from the cpu context, clear the desired bit
* and set it to its new value. * and set it to its new value.
*/ */
state = get_el3state_ctx(ctx); state = get_el3state_ctx(ctx);
scr_el3 = read_ctx_reg(state, CTX_SCR_EL3); scr_el3 = (uint32_t)read_ctx_reg(state, CTX_SCR_EL3);
scr_el3 &= ~(1 << bit_pos); scr_el3 &= ~(1U << bit_pos);
scr_el3 |= value << bit_pos; scr_el3 |= value << bit_pos;
write_ctx_reg(state, CTX_SCR_EL3, scr_el3); write_ctx_reg(state, CTX_SCR_EL3, scr_el3);
} }
...@@ -578,11 +578,11 @@ uint32_t cm_get_scr_el3(uint32_t security_state) ...@@ -578,11 +578,11 @@ uint32_t cm_get_scr_el3(uint32_t security_state)
el3_state_t *state; el3_state_t *state;
ctx = cm_get_context(security_state); ctx = cm_get_context(security_state);
assert(ctx); assert(ctx != NULL);
/* Populate EL3 state so that ERET jumps to the correct entry */ /* Populate EL3 state so that ERET jumps to the correct entry */
state = get_el3state_ctx(ctx); state = get_el3state_ctx(ctx);
return read_ctx_reg(state, CTX_SCR_EL3); return (uint32_t)read_ctx_reg(state, CTX_SCR_EL3);
} }
/******************************************************************************* /*******************************************************************************
...@@ -595,7 +595,7 @@ void cm_set_next_eret_context(uint32_t security_state) ...@@ -595,7 +595,7 @@ void cm_set_next_eret_context(uint32_t security_state)
cpu_context_t *ctx; cpu_context_t *ctx;
ctx = cm_get_context(security_state); ctx = cm_get_context(security_state);
assert(ctx); assert(ctx != NULL);
cm_set_next_context(ctx); cm_set_next_context(ctx);
} }
...@@ -35,9 +35,9 @@ ...@@ -35,9 +35,9 @@
*/ */
#define assert_bakery_entry_valid(_entry, _bakery) do { \ #define assert_bakery_entry_valid(_entry, _bakery) do { \
assert(_bakery); \ assert((_bakery) != NULL); \
assert(_entry < BAKERY_LOCK_MAX_CPUS); \ assert((_entry) < BAKERY_LOCK_MAX_CPUS); \
} while (0) } while (false)
/* Obtain a ticket for a given CPU */ /* Obtain a ticket for a given CPU */
static unsigned int bakery_get_ticket(bakery_lock_t *bakery, unsigned int me) static unsigned int bakery_get_ticket(bakery_lock_t *bakery, unsigned int me)
...@@ -46,7 +46,7 @@ static unsigned int bakery_get_ticket(bakery_lock_t *bakery, unsigned int me) ...@@ -46,7 +46,7 @@ static unsigned int bakery_get_ticket(bakery_lock_t *bakery, unsigned int me)
unsigned int they; unsigned int they;
/* Prevent recursive acquisition */ /* Prevent recursive acquisition */
assert(!bakery_ticket_number(bakery->lock_data[me])); assert(bakery_ticket_number(bakery->lock_data[me]) == 0U);
/* /*
* Flag that we're busy getting our ticket. All CPUs are iterated in the * Flag that we're busy getting our ticket. All CPUs are iterated in the
...@@ -58,9 +58,9 @@ static unsigned int bakery_get_ticket(bakery_lock_t *bakery, unsigned int me) ...@@ -58,9 +58,9 @@ static unsigned int bakery_get_ticket(bakery_lock_t *bakery, unsigned int me)
* ticket value. That's OK as the lock is acquired based on the priority * ticket value. That's OK as the lock is acquired based on the priority
* value, not the ticket value alone. * value, not the ticket value alone.
*/ */
my_ticket = 0; my_ticket = 0U;
bakery->lock_data[me] = make_bakery_data(CHOOSING_TICKET, my_ticket); bakery->lock_data[me] = make_bakery_data(CHOOSING_TICKET, my_ticket);
for (they = 0; they < BAKERY_LOCK_MAX_CPUS; they++) { for (they = 0U; they < BAKERY_LOCK_MAX_CPUS; they++) {
their_ticket = bakery_ticket_number(bakery->lock_data[they]); their_ticket = bakery_ticket_number(bakery->lock_data[they]);
if (their_ticket > my_ticket) if (their_ticket > my_ticket)
my_ticket = their_ticket; my_ticket = their_ticket;
...@@ -105,8 +105,8 @@ void bakery_lock_get(bakery_lock_t *bakery) ...@@ -105,8 +105,8 @@ void bakery_lock_get(bakery_lock_t *bakery)
* Now that we got our ticket, compute our priority value, then compare * Now that we got our ticket, compute our priority value, then compare
* with that of others, and proceed to acquire the lock * with that of others, and proceed to acquire the lock
*/ */
my_prio = PRIORITY(my_ticket, me); my_prio = bakery_get_priority(my_ticket, me);
for (they = 0; they < BAKERY_LOCK_MAX_CPUS; they++) { for (they = 0U; they < BAKERY_LOCK_MAX_CPUS; they++) {
if (me == they) if (me == they)
continue; continue;
...@@ -120,7 +120,8 @@ void bakery_lock_get(bakery_lock_t *bakery) ...@@ -120,7 +120,8 @@ void bakery_lock_get(bakery_lock_t *bakery)
* (valid) ticket value. If they do, compare priorities * (valid) ticket value. If they do, compare priorities
*/ */
their_ticket = bakery_ticket_number(their_bakery_data); their_ticket = bakery_ticket_number(their_bakery_data);
if (their_ticket && (PRIORITY(their_ticket, they) < my_prio)) { if ((their_ticket != 0U) &&
(bakery_get_priority(their_ticket, they) < my_prio)) {
/* /*
* They have higher priority (lower value). Wait for * They have higher priority (lower value). Wait for
* their ticket value to change (either release the lock * their ticket value to change (either release the lock
...@@ -148,7 +149,7 @@ void bakery_lock_release(bakery_lock_t *bakery) ...@@ -148,7 +149,7 @@ void bakery_lock_release(bakery_lock_t *bakery)
unsigned int me = plat_my_core_pos(); unsigned int me = plat_my_core_pos();
assert_bakery_entry_valid(me, bakery); assert_bakery_entry_valid(me, bakery);
assert(bakery_ticket_number(bakery->lock_data[me])); assert(bakery_ticket_number(bakery->lock_data[me]) != 0U);
/* /*
* Ensure that other observers see any stores in the critical section * Ensure that other observers see any stores in the critical section
...@@ -156,7 +157,7 @@ void bakery_lock_release(bakery_lock_t *bakery) ...@@ -156,7 +157,7 @@ void bakery_lock_release(bakery_lock_t *bakery)
* Then signal other waiting contenders. * Then signal other waiting contenders.
*/ */
dmbst(); dmbst();
bakery->lock_data[me] = 0; bakery->lock_data[me] = 0U;
dsb(); dsb();
sev(); sev();
} }
...@@ -53,21 +53,31 @@ CASSERT((PLAT_PERCPU_BAKERY_LOCK_SIZE & (CACHE_WRITEBACK_GRANULE - 1)) == 0, \ ...@@ -53,21 +53,31 @@ CASSERT((PLAT_PERCPU_BAKERY_LOCK_SIZE & (CACHE_WRITEBACK_GRANULE - 1)) == 0, \
IMPORT_SYM(uintptr_t, __PERCPU_BAKERY_LOCK_SIZE__, PERCPU_BAKERY_LOCK_SIZE); IMPORT_SYM(uintptr_t, __PERCPU_BAKERY_LOCK_SIZE__, PERCPU_BAKERY_LOCK_SIZE);
#endif #endif
#define get_bakery_info(_cpu_ix, _lock) \ static inline bakery_lock_t *get_bakery_info(unsigned int cpu_ix,
(bakery_info_t *)((uintptr_t)_lock + _cpu_ix * PERCPU_BAKERY_LOCK_SIZE) bakery_lock_t *lock)
{
return (bakery_info_t *)((uintptr_t)lock +
cpu_ix * PERCPU_BAKERY_LOCK_SIZE);
}
#define write_cache_op(_addr, _cached) \ static inline void write_cache_op(uintptr_t addr, bool cached)
do { \ {
(_cached ? dccvac((uintptr_t)_addr) :\ if (cached)
dcivac((uintptr_t)_addr));\ dccvac(addr);
dsbish();\ else
} while (0) dcivac(addr);
#define read_cache_op(_addr, _cached) if (_cached) \ dsbish();
dccivac((uintptr_t)_addr) }
static inline void read_cache_op(uintptr_t addr, bool cached)
{
if (cached)
dccivac(addr);
}
/* Helper function to check if the lock is acquired */ /* Helper function to check if the lock is acquired */
static inline int is_lock_acquired(const bakery_info_t *my_bakery_info, static inline bool is_lock_acquired(const bakery_info_t *my_bakery_info,
int is_cached) int is_cached)
{ {
/* /*
...@@ -78,8 +88,8 @@ static inline int is_lock_acquired(const bakery_info_t *my_bakery_info, ...@@ -78,8 +88,8 @@ static inline int is_lock_acquired(const bakery_info_t *my_bakery_info,
* operations were not propagated to all the caches in the system. * operations were not propagated to all the caches in the system.
* Hence do a `read_cache_op()` prior to read. * Hence do a `read_cache_op()` prior to read.
*/ */
read_cache_op(my_bakery_info, is_cached); read_cache_op((uintptr_t)my_bakery_info, is_cached);
return !!(bakery_ticket_number(my_bakery_info->lock_data)); return bakery_ticket_number(my_bakery_info->lock_data) != 0U;
} }
static unsigned int bakery_get_ticket(bakery_lock_t *lock, static unsigned int bakery_get_ticket(bakery_lock_t *lock,
...@@ -94,7 +104,7 @@ static unsigned int bakery_get_ticket(bakery_lock_t *lock, ...@@ -94,7 +104,7 @@ static unsigned int bakery_get_ticket(bakery_lock_t *lock,
* it is not NULL. * it is not NULL.
*/ */
my_bakery_info = get_bakery_info(me, lock); my_bakery_info = get_bakery_info(me, lock);
assert(my_bakery_info); assert(my_bakery_info != NULL);
/* Prevent recursive acquisition.*/ /* Prevent recursive acquisition.*/
assert(!is_lock_acquired(my_bakery_info, is_cached)); assert(!is_lock_acquired(my_bakery_info, is_cached));
...@@ -103,16 +113,16 @@ static unsigned int bakery_get_ticket(bakery_lock_t *lock, ...@@ -103,16 +113,16 @@ static unsigned int bakery_get_ticket(bakery_lock_t *lock,
* Tell other contenders that we are through the bakery doorway i.e. * Tell other contenders that we are through the bakery doorway i.e.
* going to allocate a ticket for this cpu. * going to allocate a ticket for this cpu.
*/ */
my_ticket = 0; my_ticket = 0U;
my_bakery_info->lock_data = make_bakery_data(CHOOSING_TICKET, my_ticket); my_bakery_info->lock_data = make_bakery_data(CHOOSING_TICKET, my_ticket);
write_cache_op(my_bakery_info, is_cached); write_cache_op((uintptr_t)my_bakery_info, is_cached);
/* /*
* Iterate through the bakery information of each contender to allocate * Iterate through the bakery information of each contender to allocate
* the highest ticket number for this cpu. * the highest ticket number for this cpu.
*/ */
for (they = 0; they < BAKERY_LOCK_MAX_CPUS; they++) { for (they = 0U; they < BAKERY_LOCK_MAX_CPUS; they++) {
if (me == they) if (me == they)
continue; continue;
...@@ -121,9 +131,9 @@ static unsigned int bakery_get_ticket(bakery_lock_t *lock, ...@@ -121,9 +131,9 @@ static unsigned int bakery_get_ticket(bakery_lock_t *lock,
* ensure that a stale copy is not read. * ensure that a stale copy is not read.
*/ */
their_bakery_info = get_bakery_info(they, lock); their_bakery_info = get_bakery_info(they, lock);
assert(their_bakery_info); assert(their_bakery_info != NULL);
read_cache_op(their_bakery_info, is_cached); read_cache_op((uintptr_t)their_bakery_info, is_cached);
/* /*
* Update this cpu's ticket number if a higher ticket number is * Update this cpu's ticket number if a higher ticket number is
...@@ -141,7 +151,7 @@ static unsigned int bakery_get_ticket(bakery_lock_t *lock, ...@@ -141,7 +151,7 @@ static unsigned int bakery_get_ticket(bakery_lock_t *lock,
++my_ticket; ++my_ticket;
my_bakery_info->lock_data = make_bakery_data(CHOSEN_TICKET, my_ticket); my_bakery_info->lock_data = make_bakery_data(CHOSEN_TICKET, my_ticket);
write_cache_op(my_bakery_info, is_cached); write_cache_op((uintptr_t)my_bakery_info, is_cached);
return my_ticket; return my_ticket;
} }
...@@ -167,8 +177,8 @@ void bakery_lock_get(bakery_lock_t *lock) ...@@ -167,8 +177,8 @@ void bakery_lock_get(bakery_lock_t *lock)
* Now that we got our ticket, compute our priority value, then compare * Now that we got our ticket, compute our priority value, then compare
* with that of others, and proceed to acquire the lock * with that of others, and proceed to acquire the lock
*/ */
my_prio = PRIORITY(my_ticket, me); my_prio = bakery_get_priority(my_ticket, me);
for (they = 0; they < BAKERY_LOCK_MAX_CPUS; they++) { for (they = 0U; they < BAKERY_LOCK_MAX_CPUS; they++) {
if (me == they) if (me == they)
continue; continue;
...@@ -177,11 +187,11 @@ void bakery_lock_get(bakery_lock_t *lock) ...@@ -177,11 +187,11 @@ void bakery_lock_get(bakery_lock_t *lock)
* ensure that a stale copy is not read. * ensure that a stale copy is not read.
*/ */
their_bakery_info = get_bakery_info(they, lock); their_bakery_info = get_bakery_info(they, lock);
assert(their_bakery_info); assert(their_bakery_info != NULL);
/* Wait for the contender to get their ticket */ /* Wait for the contender to get their ticket */
do { do {
read_cache_op(their_bakery_info, is_cached); read_cache_op((uintptr_t)their_bakery_info, is_cached);
their_bakery_data = their_bakery_info->lock_data; their_bakery_data = their_bakery_info->lock_data;
} while (bakery_is_choosing(their_bakery_data)); } while (bakery_is_choosing(their_bakery_data));
...@@ -190,7 +200,7 @@ void bakery_lock_get(bakery_lock_t *lock) ...@@ -190,7 +200,7 @@ void bakery_lock_get(bakery_lock_t *lock)
* (valid) ticket value. If they do, compare priorities * (valid) ticket value. If they do, compare priorities
*/ */
their_ticket = bakery_ticket_number(their_bakery_data); their_ticket = bakery_ticket_number(their_bakery_data);
if (their_ticket && (PRIORITY(their_ticket, they) < my_prio)) { if (their_ticket && (bakery_get_priority(their_ticket, they) < my_prio)) {
/* /*
* They have higher priority (lower value). Wait for * They have higher priority (lower value). Wait for
* their ticket value to change (either release the lock * their ticket value to change (either release the lock
...@@ -199,7 +209,7 @@ void bakery_lock_get(bakery_lock_t *lock) ...@@ -199,7 +209,7 @@ void bakery_lock_get(bakery_lock_t *lock)
*/ */
do { do {
wfe(); wfe();
read_cache_op(their_bakery_info, is_cached); read_cache_op((uintptr_t)their_bakery_info, is_cached);
} while (their_ticket } while (their_ticket
== bakery_ticket_number(their_bakery_info->lock_data)); == bakery_ticket_number(their_bakery_info->lock_data));
} }
...@@ -231,7 +241,7 @@ void bakery_lock_release(bakery_lock_t *lock) ...@@ -231,7 +241,7 @@ void bakery_lock_release(bakery_lock_t *lock)
* Then signal other waiting contenders. * Then signal other waiting contenders.
*/ */
dmbst(); dmbst();
my_bakery_info->lock_data = 0; my_bakery_info->lock_data = 0U;
write_cache_op(my_bakery_info, is_cached); write_cache_op((uintptr_t)my_bakery_info, is_cached);
sev(); sev();
} }
...@@ -31,70 +31,70 @@ ...@@ -31,70 +31,70 @@
* FVP memory map related constants * FVP memory map related constants
******************************************************************************/ ******************************************************************************/
#define FLASH1_BASE 0x0c000000 #define FLASH1_BASE UL(0x0c000000)
#define FLASH1_SIZE 0x04000000 #define FLASH1_SIZE UL(0x04000000)
#define PSRAM_BASE 0x14000000 #define PSRAM_BASE UL(0x14000000)
#define PSRAM_SIZE 0x04000000 #define PSRAM_SIZE UL(0x04000000)
#define VRAM_BASE 0x18000000 #define VRAM_BASE UL(0x18000000)
#define VRAM_SIZE 0x02000000 #define VRAM_SIZE UL(0x02000000)
/* Aggregate of all devices in the first GB */ /* Aggregate of all devices in the first GB */
#define DEVICE0_BASE 0x20000000 #define DEVICE0_BASE UL(0x20000000)
#define DEVICE0_SIZE 0x0c200000 #define DEVICE0_SIZE UL(0x0c200000)
/* /*
* In case of FVP models with CCN, the CCN register space overlaps into * In case of FVP models with CCN, the CCN register space overlaps into
* the NSRAM area. * the NSRAM area.
*/ */
#if FVP_INTERCONNECT_DRIVER == FVP_CCN #if FVP_INTERCONNECT_DRIVER == FVP_CCN
#define DEVICE1_BASE 0x2e000000 #define DEVICE1_BASE UL(0x2e000000)
#define DEVICE1_SIZE 0x1A00000 #define DEVICE1_SIZE UL(0x1A00000)
#else #else
#define DEVICE1_BASE 0x2f000000 #define DEVICE1_BASE UL(0x2f000000)
#define DEVICE1_SIZE 0x200000 #define DEVICE1_SIZE UL(0x200000)
#define NSRAM_BASE 0x2e000000 #define NSRAM_BASE UL(0x2e000000)
#define NSRAM_SIZE 0x10000 #define NSRAM_SIZE UL(0x10000)
#endif #endif
/* Devices in the second GB */ /* Devices in the second GB */
#define DEVICE2_BASE 0x7fe00000 #define DEVICE2_BASE UL(0x7fe00000)
#define DEVICE2_SIZE 0x00200000 #define DEVICE2_SIZE UL(0x00200000)
#define PCIE_EXP_BASE 0x40000000 #define PCIE_EXP_BASE UL(0x40000000)
#define TZRNG_BASE 0x7fe60000 #define TZRNG_BASE UL(0x7fe60000)
/* Non-volatile counters */ /* Non-volatile counters */
#define TRUSTED_NVCTR_BASE 0x7fe70000 #define TRUSTED_NVCTR_BASE UL(0x7fe70000)
#define TFW_NVCTR_BASE (TRUSTED_NVCTR_BASE + 0x0000) #define TFW_NVCTR_BASE (TRUSTED_NVCTR_BASE + UL(0x0000))
#define TFW_NVCTR_SIZE 4 #define TFW_NVCTR_SIZE UL(4)
#define NTFW_CTR_BASE (TRUSTED_NVCTR_BASE + 0x0004) #define NTFW_CTR_BASE (TRUSTED_NVCTR_BASE + UL(0x0004))
#define NTFW_CTR_SIZE 4 #define NTFW_CTR_SIZE UL(4)
/* Keys */ /* Keys */
#define SOC_KEYS_BASE 0x7fe80000 #define SOC_KEYS_BASE UL(0x7fe80000)
#define TZ_PUB_KEY_HASH_BASE (SOC_KEYS_BASE + 0x0000) #define TZ_PUB_KEY_HASH_BASE (SOC_KEYS_BASE + UL(0x0000))
#define TZ_PUB_KEY_HASH_SIZE 32 #define TZ_PUB_KEY_HASH_SIZE UL(32)
#define HU_KEY_BASE (SOC_KEYS_BASE + 0x0020) #define HU_KEY_BASE (SOC_KEYS_BASE + UL(0x0020))
#define HU_KEY_SIZE 16 #define HU_KEY_SIZE UL(16)
#define END_KEY_BASE (SOC_KEYS_BASE + 0x0044) #define END_KEY_BASE (SOC_KEYS_BASE + UL(0x0044))
#define END_KEY_SIZE 32 #define END_KEY_SIZE UL(32)
/* Constants to distinguish FVP type */ /* Constants to distinguish FVP type */
#define HBI_BASE_FVP 0x020 #define HBI_BASE_FVP U(0x020)
#define REV_BASE_FVP_V0 0x0 #define REV_BASE_FVP_V0 U(0x0)
#define REV_BASE_FVP_REVC 0x2 #define REV_BASE_FVP_REVC U(0x2)
#define HBI_FOUNDATION_FVP 0x010 #define HBI_FOUNDATION_FVP U(0x010)
#define REV_FOUNDATION_FVP_V2_0 0x0 #define REV_FOUNDATION_FVP_V2_0 U(0x0)
#define REV_FOUNDATION_FVP_V2_1 0x1 #define REV_FOUNDATION_FVP_V2_1 U(0x1)
#define REV_FOUNDATION_FVP_v9_1 0x2 #define REV_FOUNDATION_FVP_v9_1 U(0x2)
#define REV_FOUNDATION_FVP_v9_6 0x3 #define REV_FOUNDATION_FVP_v9_6 U(0x3)
#define BLD_GIC_VE_MMAP 0x0 #define BLD_GIC_VE_MMAP U(0x0)
#define BLD_GIC_A53A57_MMAP 0x1 #define BLD_GIC_A53A57_MMAP U(0x1)
#define ARCH_MODEL 0x1 #define ARCH_MODEL U(0x1)
/* FVP Power controller base address*/ /* FVP Power controller base address*/
#define PWRC_BASE UL(0x1c100000) #define PWRC_BASE UL(0x1c100000)
...@@ -104,26 +104,26 @@ ...@@ -104,26 +104,26 @@
#define SP804_TIMER_CLKDIV 35 #define SP804_TIMER_CLKDIV 35
/* SP810 controller. FVP specific flags */ /* SP810 controller. FVP specific flags */
#define FVP_SP810_CTRL_TIM0_OV (1 << 16) #define FVP_SP810_CTRL_TIM0_OV BIT_32(16)
#define FVP_SP810_CTRL_TIM1_OV (1 << 18) #define FVP_SP810_CTRL_TIM1_OV BIT_32(18)
#define FVP_SP810_CTRL_TIM2_OV (1 << 20) #define FVP_SP810_CTRL_TIM2_OV BIT_32(20)
#define FVP_SP810_CTRL_TIM3_OV (1 << 22) #define FVP_SP810_CTRL_TIM3_OV BIT_32(22)
/******************************************************************************* /*******************************************************************************
* GIC-400 & interrupt handling related constants * GIC-400 & interrupt handling related constants
******************************************************************************/ ******************************************************************************/
/* VE compatible GIC memory map */ /* VE compatible GIC memory map */
#define VE_GICD_BASE 0x2c001000 #define VE_GICD_BASE UL(0x2c001000)
#define VE_GICC_BASE 0x2c002000 #define VE_GICC_BASE UL(0x2c002000)
#define VE_GICH_BASE 0x2c004000 #define VE_GICH_BASE UL(0x2c004000)
#define VE_GICV_BASE 0x2c006000 #define VE_GICV_BASE UL(0x2c006000)
/* Base FVP compatible GIC memory map */ /* Base FVP compatible GIC memory map */
#define BASE_GICD_BASE 0x2f000000 #define BASE_GICD_BASE UL(0x2f000000)
#define BASE_GICR_BASE 0x2f100000 #define BASE_GICR_BASE UL(0x2f100000)
#define BASE_GICC_BASE 0x2c000000 #define BASE_GICC_BASE UL(0x2c000000)
#define BASE_GICH_BASE 0x2c010000 #define BASE_GICH_BASE UL(0x2c010000)
#define BASE_GICV_BASE 0x2c02f000 #define BASE_GICV_BASE UL(0x2c02f000)
#define FVP_IRQ_TZ_WDOG 56 #define FVP_IRQ_TZ_WDOG 56
#define FVP_IRQ_SEC_SYS_TIMER 57 #define FVP_IRQ_SEC_SYS_TIMER 57
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment