Remove some MISRA defects in common code

No functional changes.

Change-Id: I9638e02acb9b22eb794ebf45aad84348a710287e
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
diff --git a/include/common/bl_common.h b/include/common/bl_common.h
index bfe1d8c..af598d0 100644
--- a/include/common/bl_common.h
+++ b/include/common/bl_common.h
@@ -11,26 +11,26 @@
 #include <param_header.h>
 #include <utils_def.h>
 
-#define UP	1
-#define DOWN	0
+#define UP	U(1)
+#define DOWN	U(0)
 
 /*******************************************************************************
  * Constants to identify the location of a memory region in a given memory
  * layout.
 ******************************************************************************/
-#define TOP	0x1
-#define BOTTOM	!TOP
+#define TOP	U(0x1)
+#define BOTTOM	U(0x0)
 
 /*
  * The following are used for image state attributes.
  * Image can only be in one of the following state.
  */
-#define IMAGE_STATE_RESET			0
-#define IMAGE_STATE_COPIED			1
-#define IMAGE_STATE_COPYING			2
-#define IMAGE_STATE_AUTHENTICATED		3
-#define IMAGE_STATE_EXECUTED			4
-#define IMAGE_STATE_INTERRUPTED			5
+#define IMAGE_STATE_RESET		U(0)
+#define IMAGE_STATE_COPIED		U(1)
+#define IMAGE_STATE_COPYING		U(2)
+#define IMAGE_STATE_AUTHENTICATED	U(3)
+#define IMAGE_STATE_EXECUTED		U(4)
+#define IMAGE_STATE_INTERRUPTED		U(5)
 
 #define IMAGE_ATTRIB_SKIP_LOADING	U(0x02)
 #define IMAGE_ATTRIB_PLAT_SETUP		U(0x04)
@@ -40,22 +40,22 @@
 /*******************************************************************************
  * Constants to indicate type of exception to the common exception handler.
  ******************************************************************************/
-#define SYNC_EXCEPTION_SP_EL0		0x0
-#define IRQ_SP_EL0			0x1
-#define FIQ_SP_EL0			0x2
-#define SERROR_SP_EL0			0x3
-#define SYNC_EXCEPTION_SP_ELX		0x4
-#define IRQ_SP_ELX			0x5
-#define FIQ_SP_ELX			0x6
-#define SERROR_SP_ELX			0x7
-#define SYNC_EXCEPTION_AARCH64		0x8
-#define IRQ_AARCH64			0x9
-#define FIQ_AARCH64			0xa
-#define SERROR_AARCH64			0xb
-#define SYNC_EXCEPTION_AARCH32		0xc
-#define IRQ_AARCH32			0xd
-#define FIQ_AARCH32			0xe
-#define SERROR_AARCH32			0xf
+#define SYNC_EXCEPTION_SP_EL0		U(0x0)
+#define IRQ_SP_EL0			U(0x1)
+#define FIQ_SP_EL0			U(0x2)
+#define SERROR_SP_EL0			U(0x3)
+#define SYNC_EXCEPTION_SP_ELX		U(0x4)
+#define IRQ_SP_ELX			U(0x5)
+#define FIQ_SP_ELX			U(0x6)
+#define SERROR_SP_ELX			U(0x7)
+#define SYNC_EXCEPTION_AARCH64		U(0x8)
+#define IRQ_AARCH64			U(0x9)
+#define FIQ_AARCH64			U(0xa)
+#define SERROR_AARCH64			U(0xb)
+#define SYNC_EXCEPTION_AARCH32		U(0xc)
+#define IRQ_AARCH32			U(0xd)
+#define FIQ_AARCH32			U(0xe)
+#define SERROR_AARCH32			U(0xf)
 
 #ifndef __ASSEMBLY__
 #include <cassert.h>
diff --git a/include/common/fdt_wrappers.h b/include/common/fdt_wrappers.h
index 18a6d10..3eae944 100644
--- a/include/common/fdt_wrappers.h
+++ b/include/common/fdt_wrappers.h
@@ -10,7 +10,7 @@
 #define __FDT_WRAPPERS__
 
 /* Number of cells, given total length in bytes. Each cell is 4 bytes long */
-#define NCELLS(len) ((len) / 4)
+#define NCELLS(len) ((len) / 4U)
 
 int fdtw_read_cells(const void *dtb, int node, const char *prop,
 		unsigned int cells, void *value);
diff --git a/include/common/runtime_svc.h b/include/common/runtime_svc.h
index b8cf8de..6fe0a94 100644
--- a/include/common/runtime_svc.h
+++ b/include/common/runtime_svc.h
@@ -21,15 +21,15 @@
  * descriptor
  */
 #ifdef AARCH32
-#define RT_SVC_SIZE_LOG2	4
-#define RT_SVC_DESC_INIT	8
-#define RT_SVC_DESC_HANDLE	12
+#define RT_SVC_SIZE_LOG2	U(4)
+#define RT_SVC_DESC_INIT	U(8)
+#define RT_SVC_DESC_HANDLE	U(12)
 #else
-#define RT_SVC_SIZE_LOG2	5
-#define RT_SVC_DESC_INIT	16
-#define RT_SVC_DESC_HANDLE	24
+#define RT_SVC_SIZE_LOG2	U(5)
+#define RT_SVC_DESC_INIT	U(16)
+#define RT_SVC_DESC_HANDLE	U(24)
 #endif /* AARCH32 */
-#define SIZEOF_RT_SVC_DESC	(1 << RT_SVC_SIZE_LOG2)
+#define SIZEOF_RT_SVC_DESC	(U(1) << RT_SVC_SIZE_LOG2)
 
 
 /*
@@ -43,9 +43,9 @@
  * handler and so the total number of runtime services is 32.
  */
 #if SMCCC_MAJOR_VERSION == 1
-#define MAX_RT_SVCS		128
+#define MAX_RT_SVCS		U(128)
 #elif SMCCC_MAJOR_VERSION == 2
-#define MAX_RT_SVCS		32
+#define MAX_RT_SVCS		U(32)
 #endif
 
 #ifndef __ASSEMBLY__
@@ -146,35 +146,42 @@
 
 #if SMCCC_MAJOR_VERSION == 1
 /*
- * This macro combines the call type and the owning entity number corresponding
- * to a runtime service to generate a unique owning entity number. This unique
- * oen is used to access an entry in the 'rt_svc_descs_indices' array. The entry
- * contains the index of the service descriptor in the 'rt_svc_descs' array.
+ * This function combines the call type and the owning entity number
+ * corresponding to a runtime service to generate a unique owning entity number.
+ * This unique oen is used to access an entry in the 'rt_svc_descs_indices'
+ * array. The entry contains the index of the service descriptor in the
+ * 'rt_svc_descs' array.
  */
-#define get_unique_oen(oen, call_type)				\
-	(((uint32_t)(oen) & FUNCID_OEN_MASK) |			\
-	(((uint32_t)(call_type) & FUNCID_TYPE_MASK) << FUNCID_OEN_WIDTH))
+static inline uint32_t get_unique_oen(uint32_t oen, uint32_t call_type)
+{
+	return ((call_type & FUNCID_TYPE_MASK) << FUNCID_OEN_WIDTH) |
+		(oen & FUNCID_OEN_MASK);
+}
 
 /*
- * This macro generates the unique owning entity number from the SMC Function
+ * This function generates the unique owning entity number from the SMC Function
  * ID. This unique oen is used to access an entry in the 'rt_svc_descs_indices'
  * array to invoke the corresponding runtime service handler during SMC
  * handling.
  */
-#define get_unique_oen_from_smc_fid(fid)			\
-	get_unique_oen(GET_SMC_OEN(fid), GET_SMC_TYPE(fid))
+static inline uint32_t get_unique_oen_from_smc_fid(uint32_t fid)
+{
+	return get_unique_oen(GET_SMC_OEN(fid), GET_SMC_TYPE(fid));
+}
 
 #elif SMCCC_MAJOR_VERSION == 2
 
 /*
- * This macro combines the owning entity number corresponding to a runtime
+ * This function combines the owning entity number corresponding to a runtime
  * service with one extra bit for the vendor namespace to generate an index into
  * the 'rt_svc_descs_indices' array. The entry contains the index of the service
  * descriptor in the 'rt_svc_descs' array.
  */
-#define get_rt_desc_idx(oen, is_vendor)				\
-	(((uint32_t)(oen) & FUNCID_OEN_MASK) |			\
-	(((uint32_t)(is_vendor) & 1U) << FUNCID_OEN_WIDTH))
+static inline uint32_t get_rt_desc_idx(uint32_t oen, uint32_t is_vendor)
+{
+	return ((is_vendor & 1U) << FUNCID_OEN_WIDTH) |
+		(oen & FUNCID_OEN_MASK);
+}
 
 #endif
 
diff --git a/include/lib/aarch32/smccc_helpers.h b/include/lib/aarch32/smccc_helpers.h
index d6e525f..5eeb204 100644
--- a/include/lib/aarch32/smccc_helpers.h
+++ b/include/lib/aarch32/smccc_helpers.h
@@ -10,19 +10,19 @@
 #include <smccc.h>
 
 /* These are offsets to registers in smc_ctx_t */
-#define SMC_CTX_GPREG_R0	0x0
-#define SMC_CTX_GPREG_R1	0x4
-#define SMC_CTX_GPREG_R2	0x8
-#define SMC_CTX_GPREG_R3	0xC
-#define SMC_CTX_GPREG_R4	0x10
-#define SMC_CTX_GPREG_R5	0x14
-#define SMC_CTX_SP_USR		0x34
-#define SMC_CTX_SPSR_MON	0x78
-#define SMC_CTX_SP_MON		0x7C
-#define SMC_CTX_LR_MON		0x80
-#define SMC_CTX_SCR		0x84
-#define SMC_CTX_PMCR		0x88
-#define SMC_CTX_SIZE		0x90
+#define SMC_CTX_GPREG_R0	U(0x0)
+#define SMC_CTX_GPREG_R1	U(0x4)
+#define SMC_CTX_GPREG_R2	U(0x8)
+#define SMC_CTX_GPREG_R3	U(0xC)
+#define SMC_CTX_GPREG_R4	U(0x10)
+#define SMC_CTX_GPREG_R5	U(0x14)
+#define SMC_CTX_SP_USR		U(0x34)
+#define SMC_CTX_SPSR_MON	U(0x78)
+#define SMC_CTX_SP_MON		U(0x7C)
+#define SMC_CTX_LR_MON		U(0x80)
+#define SMC_CTX_SCR		U(0x84)
+#define SMC_CTX_PMCR		U(0x88)
+#define SMC_CTX_SIZE		U(0x90)
 
 #ifndef __ASSEMBLY__
 #include <cassert.h>
@@ -105,7 +105,7 @@
 CASSERT(SMC_CTX_SPSR_MON == __builtin_offsetof(smc_ctx_t, spsr_mon), \
 	assert_smc_ctx_spsr_mon_offset_mismatch);
 
-CASSERT((sizeof(smc_ctx_t) & 0x7) == 0, assert_smc_ctx_not_aligned);
+CASSERT((sizeof(smc_ctx_t) & 0x7U) == 0U, assert_smc_ctx_not_aligned);
 CASSERT(SMC_CTX_SIZE == sizeof(smc_ctx_t), assert_smc_ctx_size_mismatch);
 
 /* Convenience macros to return from SMC handler */
diff --git a/include/lib/aarch64/smccc_helpers.h b/include/lib/aarch64/smccc_helpers.h
index 4d9217b..c76faf5 100644
--- a/include/lib/aarch64/smccc_helpers.h
+++ b/include/lib/aarch64/smccc_helpers.h
@@ -11,6 +11,7 @@
 
 #ifndef __ASSEMBLY__
 #include <context.h>
+#include <stdbool.h>
 
 /* Convenience macros to return from SMC handler */
 #define SMC_RET0(_h)	{					\
@@ -77,7 +78,7 @@
 		_x2 = read_ctx_reg(regs, CTX_GPREG_X2);		\
 		_x3 = read_ctx_reg(regs, CTX_GPREG_X3);		\
 		_x4 = read_ctx_reg(regs, CTX_GPREG_X4);		\
-	} while (0)
+	} while (false)
 
 #endif /*__ASSEMBLY__*/
 
diff --git a/include/lib/pmf/pmf_asm_macros.S b/include/lib/pmf/pmf_asm_macros.S
index 9ee8199..d58829e 100644
--- a/include/lib/pmf/pmf_asm_macros.S
+++ b/include/lib/pmf/pmf_asm_macros.S
@@ -1,5 +1,5 @@
 /*
- * 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
  */
@@ -14,7 +14,7 @@
 	 * for the given service name and local timestamp id.
 	 * Clobbers: x0 - x9
 	 */
-	.macro pmf_calc_timestamp_addr _name _tid
+	.macro pmf_calc_timestamp_addr _name, _tid
 	mov	x9, x30
 	bl	plat_my_core_pos
 	mov	x30, x9
diff --git a/include/lib/runtime_instr.h b/include/lib/runtime_instr.h
index b2f1a69..ed564e2 100644
--- a/include/lib/runtime_instr.h
+++ b/include/lib/runtime_instr.h
@@ -1,5 +1,5 @@
 /*
- * 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
  */
@@ -7,13 +7,15 @@
 #ifndef __RUNTIME_INSTR_H__
 #define __RUNTIME_INSTR_H__
 
-#define RT_INSTR_ENTER_PSCI		0
-#define RT_INSTR_EXIT_PSCI		1
-#define RT_INSTR_ENTER_HW_LOW_PWR	2
-#define RT_INSTR_EXIT_HW_LOW_PWR	3
-#define RT_INSTR_ENTER_CFLUSH		4
-#define RT_INSTR_EXIT_CFLUSH		5
-#define RT_INSTR_TOTAL_IDS		6
+#include <utils_def.h>
+
+#define RT_INSTR_ENTER_PSCI		U(0)
+#define RT_INSTR_EXIT_PSCI		U(1)
+#define RT_INSTR_ENTER_HW_LOW_PWR	U(2)
+#define RT_INSTR_EXIT_HW_LOW_PWR	U(3)
+#define RT_INSTR_ENTER_CFLUSH		U(4)
+#define RT_INSTR_EXIT_CFLUSH		U(5)
+#define RT_INSTR_TOTAL_IDS		U(6)
 
 #ifndef __ASSEMBLY__
 PMF_DECLARE_CAPTURE_TIMESTAMP(rt_instr_svc)
diff --git a/include/plat/common/common_def.h b/include/plat/common/common_def.h
index 64807fd..5d76d6e 100644
--- a/include/plat/common/common_def.h
+++ b/include/plat/common/common_def.h
@@ -8,6 +8,7 @@
 
 #include <bl_common.h>
 #include <platform_def.h>
+#include <utils_def.h>
 #include <xlat_tables_defs.h>
 
 /******************************************************************************
@@ -73,12 +74,12 @@
 #define BL2_RO_DATA_END		round_up(BL2_ROM_END, PAGE_SIZE)
 #endif /* BL2_IN_XIP_MEM */
 #else
-#define BL_RO_DATA_BASE		0
-#define BL_RO_DATA_END		0
+#define BL_RO_DATA_BASE		UL(0)
+#define BL_RO_DATA_END		UL(0)
 #define BL1_CODE_END		round_up(BL1_ROM_END, PAGE_SIZE)
 #if BL2_IN_XIP_MEM
-#define BL2_RO_DATA_BASE	0
-#define BL2_RO_DATA_END		0
+#define BL2_RO_DATA_BASE	UL(0)
+#define BL2_RO_DATA_END		UL(0)
 #define BL2_CODE_END		round_up(BL2_ROM_END, PAGE_SIZE)
 #endif /* BL2_IN_XIP_MEM */
 #endif /* SEPARATE_CODE_AND_RODATA */